city.inc.php 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * DZAPP Haodai City Switcher
  4. *
  5. * @copyright (c) 2013-2014 DZAPP. (http://www.dzapp.cn)
  6. * @author BranchZero <branchzero@gmail.com>
  7. */
  8. !defined('IN_DISCUZ') && exit('Access Denied');
  9. include_once DISCUZ_ROOT.'./data/dzapp_haodai_config.php';
  10. include_once DISCUZ_ROOT.'./source/plugin/dzapp_haodai/haodai.api.class.php';
  11. include_once DISCUZ_ROOT.'./source/plugin/dzapp_haodai/dzapp_haodai.func.php';
  12. @include_once DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_setting.php';
  13. if(!@include_once DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_city.php' || TIMESTAMP - filemtime(DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_city.php') > $var['refreshtime']){
  14. $client = new HaoDaiClient(HD_AKEY, HD_SKEY, $hd_token['access_token']);
  15. $client->set_debug(0);
  16. $result = $client->get_xindai_zones();
  17. $zonelist = $result['items'];
  18. if(count($zonelist) > 0){
  19. $zones = array();
  20. foreach($zonelist as $value){
  21. if($value['s_EN'] == 'www') continue;
  22. $value['zone_name'] = diconv($value['zone_name'], 'UTF-8', CHARSET);
  23. $value['Province'] = diconv($value['Province'], 'UTF-8', CHARSET);
  24. $value['area'] = diconv($value['area'], 'UTF-8', CHARSET);
  25. $zones[$value['s_EN']] = $value['zone_name'];
  26. $zonesort['provinces'][$value['Province']][$value['s_EN']] = $value['zone_name'];
  27. $zonesort['letter_raw'][$value['letter']][$value['s_EN']] = $value['zone_name'];
  28. $zonesort['area'][$value['area']][$value['s_EN']] = $value['zone_name'];
  29. }
  30. foreach(range('A', 'Z') as $letter) {
  31. if(!empty($zonesort['letter_raw'][$letter])) $zonesort['letter'][$letter] = $zonesort['letter_raw'][$letter];
  32. }
  33. require_once libfile('function/cache');
  34. writetocache('dzapp_haodai_city', getcachevars(array('zones' => $zones)));
  35. writetocache('dzapp_haodai_city_sort', getcachevars(array('zonesort' => $zonesort)));
  36. }else{
  37. showmessage('dzapp_haodai:callback_error_admin');
  38. }
  39. }else{
  40. @include_once DISCUZ_ROOT.'./data/sysdata/cache_dzapp_haodai_city_sort.php';
  41. }
  42. if(!$_GET['city']){
  43. include template('dzapp_haodai:city');
  44. }else{
  45. if(!$_GET['city'] || $_GET['formhash'] != FORMHASH || !$zones[$_GET['city']]) showmessage('dzapp_haodai:city_choose_wrong');
  46. dsetcookie('HD_CITY', $_GET['city']);
  47. showmessage('dzapp_haodai:city_choose_ok', 'plugin.php?id=dzapp_haodai');
  48. }
  49. ?>