Index.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\home\controller;
  3. use think\Lang;
  4. use think\Cache;
  5. use think\Request;
  6. use think\Controller;
  7. /**
  8. * 主页管理类
  9. */
  10. class Index extends Controller
  11. {
  12. /**
  13. * 构造函数
  14. *
  15. * @access public
  16. */
  17. public function __construct()
  18. {
  19. parent::__construct();
  20. }// end__construct()
  21. /**
  22. * 主页管理
  23. *
  24. * @access public
  25. * @return array JsonString
  26. */
  27. public function index()
  28. {
  29. $navigationField = [
  30. 'navigation_zhName',
  31. 'navigation_enName',
  32. 'navigation_id',
  33. ];
  34. $getNavigation = model('Navigation')->getSelect($navigationField);
  35. $this->assign('navigation', $getNavigation);
  36. $navigationId = [
  37. 'home',
  38. 'service',
  39. 'portfolio',
  40. 'about',
  41. 'pricing',
  42. 'contact',
  43. ];
  44. $this->assign('navigationId', $navigationId);
  45. $this->assign('admin_info', 11);
  46. return $this->fetch();
  47. }
  48. /**
  49. * 修改密码
  50. */
  51. public function modifypw()
  52. {
  53. if (request()->isPost()) {
  54. $new_pw = trim(input('post.new_pw'));
  55. $new_pw2 = trim(input('post.new_pw2'));
  56. $old_pw = trim(input('post.old_pw'));
  57. if ($new_pw !== $new_pw2) {
  58. $this->error(lang('index_modifypw_repeat_error'));
  59. }
  60. $admininfo = $this->getAdminInfo();
  61. //查询管理员信息
  62. $service_model = model('service');
  63. $admininfo = $service_model->getserviceInfo(array('service_id' => $admininfo['service_id']));
  64. if (!is_array($admininfo) || count($admininfo) <= 0) {
  65. $this->error(lang('index_modifypw_admin_error'));
  66. }
  67. //旧密码是否正确
  68. if ($admininfo['service_password'] != md5($old_pw)) {
  69. $this->error(lang('index_modifypw_oldpw_error'));
  70. }
  71. $new_pw = md5($new_pw);
  72. $result = $service_model->editService(array('service_id' => $admininfo['service_id']), array('service_password' => $new_pw));
  73. if ($result) {
  74. session(null);
  75. dsLayerOpenSuccess(lang('index_modifypw_succ'));
  76. } else {
  77. $this->error(lang('index_modifypw_fail'));
  78. }
  79. } else {
  80. $this->setAdminCurItem('modifypw');
  81. return $this->fetch();
  82. }
  83. }
  84. /**
  85. * 首页
  86. * @return mixed
  87. */
  88. // public function welCome()
  89. // {
  90. // $setup_date = config('setup_date');
  91. // $statistics['os'] = PHP_OS;
  92. // $statistics['web_server'] = $_SERVER['SERVER_SOFTWARE'];
  93. // $statistics['php_version'] = PHP_VERSION;
  94. // $statistics['sql_version'] = $this->_mysql_version();
  95. // $statistics['setup_date'] = substr($setup_date, 0, 10);
  96. // $statistics['domain'] = $_SERVER['HTTP_HOST'];
  97. // $statistics['ip'] = GetHostByName($_SERVER['SERVER_NAME']);
  98. // $statistics['zlib'] = function_exists('gzclose') ? 'YES' : 'NO'; //zlib
  99. // $statistics['safe_mode'] = (boolean)ini_get('safe_mode') ? 'YES' : 'NO'; //safe_mode = Off
  100. // $statistics['timezone'] = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
  101. // $statistics['curl'] = function_exists('curl_init') ? 'YES' : 'NO';
  102. // $statistics['fileupload'] = @ini_get('file_uploads') ? ini_get('upload_max_filesize') : 'unknown';
  103. // $statistics['max_ex_time'] = @ini_get("max_execution_time") . 's'; //脚本最大执行时间
  104. // $statistics['set_time_limit'] = function_exists("set_time_limit") ? true : false;
  105. // $statistics['memory_limit'] = ini_get('memory_limit');
  106. // $statistics['version'] = file_get_contents(APP_PATH . 'version.php');
  107. // if (function_exists("gd_info")) {
  108. // $gd = gd_info();
  109. // $statistics['gdinfo'] = $gd['GD Version'];
  110. // } else {
  111. // $statistics['gdinfo'] = lang('Unknown');
  112. // }
  113. // $this->assign('statistics', $statistics);
  114. // return $this->fetch('welcome');
  115. // }
  116. private function _mysql_version()
  117. {
  118. $version = db()->query("select version() as ver");
  119. return $version[0]['ver'];
  120. }
  121. /**
  122. * 修改当前语言
  123. */
  124. public function setLanguageCookie()
  125. {
  126. $language = input('param.language');
  127. if ($language == config('default_lang')) {
  128. $this->error(\lang('ds_language_repetition'), url('Index/index'));
  129. exit();
  130. }
  131. setcookie("ds_admin_lang", $language, 0, '/');
  132. $this->success(\lang('ds_language_switching'), url('Index/index'));
  133. exit();
  134. }
  135. /**
  136. * 删除缓存
  137. */
  138. function clear()
  139. {
  140. $this->delCacheFile('temp');
  141. $this->delCacheFile('cache');
  142. Cache::clear();
  143. ds_json_encode(10000, lang('eliminate_succ'));
  144. exit();
  145. }
  146. /**
  147. * 删除缓存目录下的文件或子目录文件
  148. *
  149. * @param string $dir 目录名或文件名
  150. * @return boolean
  151. */
  152. function delCacheFile($dir)
  153. {
  154. //防止删除cache以外的文件
  155. if (strpos($dir, '..') !== false)
  156. return false;
  157. $path = RUNTIME_PATH . '/' . $dir;
  158. if (is_dir($path)) {
  159. $file_list = array();
  160. read_file_list($path, $file_list);
  161. if (!empty($file_list)) {
  162. foreach ($file_list as $v) {
  163. if (basename($v) != 'index.html')
  164. @unlink($v);
  165. }
  166. }
  167. } else {
  168. if (basename($path) != 'index.html')
  169. @unlink($path);
  170. }
  171. return true;
  172. }
  173. }