Nav apraksta

Common.php 13KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海口快推科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\common\controller;
  14. use think\Controller;
  15. use think\Session;
  16. use think\Db;
  17. class Common extends Controller {
  18. public $session_id;
  19. public $theme_style = '';
  20. public $theme_style_path = '';
  21. public $view_suffix = 'html';
  22. public $eyou = array();
  23. public $users_id = 0;
  24. public $users = array();
  25. public $usersConfig = [];
  26. public $usersTplVersion = '';
  27. /**
  28. * 析构函数
  29. */
  30. function __construct()
  31. {
  32. /*是否隐藏或显示应用入口index.php*/
  33. if (tpCache('seo.seo_inlet') == 0) {
  34. \think\Url::root('/index.php');
  35. } else {
  36. // \think\Url::root('/');
  37. }
  38. /*--end*/
  39. parent::__construct();
  40. }
  41. /*
  42. * 初始化操作
  43. */
  44. public function _initialize()
  45. {
  46. $assignData = [];
  47. // 解决PHP套用Iframe访问导致cookie跨域session失效
  48. if (in_array($this->request->rootDomain(), ['kuaituiyun.cn'])) {
  49. // IE浏览器cookie跨域
  50. header("P3P:CP=CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE GOV");
  51. // Chrome等浏览器cookie跨域(一定要加上secure,否则SameSite无效)
  52. @ini_set('session.cookie_samesite', "None;secure");
  53. }
  54. session('admin_info'); // 传后台信息到前台,此处可视化用到
  55. if (!session_id()) {
  56. Session::start();
  57. }
  58. header("Cache-control: private"); // history.back返回后输入框值丢失问题
  59. $this->session_id = session_id(); // 当前的 session_id
  60. !defined('SESSION_ID') && define('SESSION_ID', $this->session_id); //将当前的session_id保存为常量,供其它方法调用
  61. // 全局配置
  62. $global = tpCache('global');
  63. /*站点状态关闭时,所关闭的终端口(pc、mobile)*/
  64. // $webClosePort = !empty($global['web_close_port']) ? unserialize($global['web_close_port']) : [];
  65. // $close = 0;
  66. // if (!empty($webClosePort)) {
  67. // if (0 === intval($this->is_mobile) && in_array('pc', $webClosePort)) {
  68. // $close = 1;
  69. // } else if (1 === intval($this->is_mobile) && in_array('mobile', $webClosePort)) {
  70. // $close = 1;
  71. // }
  72. // }
  73. // if (in_array(MODULE_NAME, ['home']) && !empty($global['web_status']) && $global['web_status'] == 1 && !empty($close)) {}
  74. /*end*/
  75. /*关闭网站*/
  76. if (in_array(MODULE_NAME, ['home']) && !empty($global['web_status']) && $global['web_status'] == 1) {
  77. if ($global['web_status_mode'] == 1) {
  78. if (!empty($global['web_status_url'])) {
  79. $this->redirect($global['web_status_url']);
  80. exit;
  81. } else {
  82. die("<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>网站暂时关闭,没有找到跳转的URL</div>");
  83. }
  84. } else if ($global['web_status_mode'] == 2) {
  85. $web_status_tpl = !empty($global['web_status_tpl']) ? $global['web_status_tpl'] : 'public/close.html';
  86. $web_status_tpl = preg_replace('/^(([^\:\.]+):)?(\/\/)?([^\/\:]*)(\:\d+)?(.*)$/i', '${6}', $web_status_tpl);
  87. if (!empty($this->root_dir)) {
  88. $web_status_tpl = preg_replace('/^'.str_replace('/', '\/', $this->root_dir).'\//i', '', $web_status_tpl);
  89. }
  90. $filesize = @filesize($web_status_tpl);
  91. if (file_exists($web_status_tpl) && !empty($filesize)) {
  92. $fp = fopen($web_status_tpl, 'r');
  93. $html = fread($fp, $filesize);
  94. fclose($fp);
  95. exit($html);
  96. }
  97. }
  98. $web_status_text = isset($global['web_status_text']) ? $global['web_status_text'] : '网站暂时关闭,维护中……';
  99. die("<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>{$web_status_text}</div>");
  100. }
  101. /*--end*/
  102. // 会员中心相关逻辑
  103. if (!empty($global['web_users_switch'])) {
  104. $this->usersConfig = getUsersConfigData('all');
  105. $this->usersTplVersion = getUsersTplVersion();
  106. $times = getTime();
  107. /*会员登录有效期逻辑*/
  108. $users_login_expire = 0;
  109. if (session('?users_id')) {
  110. $users_login_expiretime = !empty($this->usersConfig['users_login_expiretime']) ? intval($this->usersConfig['users_login_expiretime']) : 3600;
  111. $users_login_expire = (int)session('users_login_expire'); //最后登录时间
  112. if (empty($users_login_expire)) {
  113. $users_login_expire = $times;
  114. session('users_login_expire', $users_login_expire);
  115. }
  116. // 招聘插件会员中心导航内置代码 start
  117. if (file_exists('./weapp/Recruits/model/RecruitsModel.php')) {
  118. $recruitsModel = new \weapp\Recruits\model\RecruitsModel;
  119. $recruitsModel->common_initialize($assignData, $this->usersConfig);
  120. }
  121. // 招聘插件会员中心导航内置代码 end
  122. }
  123. /*end*/
  124. if ( !session('?users_id') || (!empty($users_login_expire) && ($times - $users_login_expire) >= $users_login_expiretime) ) {
  125. session('users_id', null);
  126. session('users', null);
  127. cookie('users_id', null);
  128. } else if ( session('?users_id') && ($times - $users_login_expire) < $users_login_expiretime ) {
  129. session('users_login_expire', getTime()); // 登录有效期
  130. }
  131. }
  132. $this->assign('usersConfig', $this->usersConfig);
  133. $this->assign('usersTplVersion',$this->usersTplVersion);
  134. /*强制微信模式,仅允许微信端访问*/
  135. $shop_force_use_wechat = getUsersConfigData('shop.shop_force_use_wechat');
  136. if (!empty($shop_force_use_wechat) && 1 == $shop_force_use_wechat && !isWeixin() && in_array(MODULE_NAME, ['home'])) {
  137. $html = "<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>网站仅微信端可访问</div>";
  138. $WeChatLoginConfig = getUsersConfigData('wechat.wechat_login_config') ? unserialize(getUsersConfigData('wechat.wechat_login_config')) : [];
  139. if (!empty($WeChatLoginConfig['wechat_name'])) $html .= "<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'>关注微信公众号:".$WeChatLoginConfig['wechat_name']."</div>";
  140. if (!empty($WeChatLoginConfig['wechat_pic'])) $html .= "<div style='text-align:center; font-size:20px; font-weight:bold; margin:50px 0px;'><img style='width: 400px; height: 400px;' src='".$WeChatLoginConfig['wechat_pic']."'></div>";
  141. die($html);
  142. }
  143. /*END*/
  144. $this->global_assign($global); // 获取网站全局变量值
  145. $this->view_suffix = config('template.view_suffix'); // 模板后缀htm
  146. $this->theme_style = THEME_STYLE; // 模板标识
  147. $this->theme_style_path = THEME_STYLE_PATH; // 模板目录
  148. //全局变量
  149. $this->eyou['global'] = $global;
  150. $sub_doman = request()->subDomain();
  151. $site = input('param.site/s');
  152. if($sub_doman == 'www' && $site == 'shandong'){
  153. //如果是shandong.zc10000.com 则不匹配
  154. $site_info = [];
  155. }else{
  156. // 多城市站点
  157. $site_info = [];
  158. if (config('city_switch_on')) {
  159. $where = [];
  160. $site = input('param.site/s');
  161. if (!empty($site)) {
  162. $where = ['domain'=>$site];
  163. } else if (!empty($global['site_default_home'])) {
  164. $where = ['id'=>$global['site_default_home']];
  165. } else {
  166. $site = get_home_site();
  167. if (!empty($site)) {
  168. $where = ['domain'=>$site];
  169. }
  170. }
  171. if (!empty($where)) {
  172. $site_info = Db::name('citysite')->field('add_time,update_time,sort_order', true)->where($where)->find();
  173. if (empty($site_info['status'])) {
  174. //to_index();
  175. to_index();
  176. }
  177. if (!empty($site_info['seoset'])) { // 分站自定义seo信息
  178. $site_info['seo_title'] = str_replace(['{region}','{区域}'], $site_info['name'], $site_info['seo_title']);
  179. $site_info['seo_keywords'] = str_replace(['{region}','{区域}'], $site_info['name'], $site_info['seo_keywords']);
  180. $site_info['seo_description'] = str_replace(['{region}','{区域}'], $site_info['name'], $site_info['seo_description']);
  181. } else if (!empty($global['site_seoset'])) { // 分站引用系统默认seo信息
  182. $site_info['seo_title'] = !empty($global['site_seo_title']) ? site_seo_handle($global['site_seo_title'], $site_info) : '';
  183. $site_info['seo_keywords'] = !empty($global['site_seo_keywords']) ? site_seo_handle($global['site_seo_keywords'], $site_info) : '';
  184. $site_info['seo_description'] = !empty($global['site_seo_description']) ? site_seo_handle($global['site_seo_description'], $site_info) : '';
  185. }
  186. cookie('site_info', json_encode($site_info));
  187. }
  188. }
  189. }
  190. empty($site_info) && cookie('site_info', null);
  191. $this->eyou['site'] = $site_info;
  192. // 多语言变量
  193. if (config('lang_switch_on')) {
  194. try {
  195. $langArr = include_once APP_PATH."lang/{$this->home_lang}.php";
  196. } catch (\Exception $e) {
  197. $this->home_lang = $this->main_lang;
  198. $langCookieVar = \think\Config::get('global.home_lang');
  199. \think\Cookie::set($langCookieVar, $this->home_lang);
  200. $langArr = include_once APP_PATH."lang/{$this->home_lang}.php";
  201. }
  202. $this->eyou['lang'] = !empty($langArr) ? $langArr : [];
  203. $lang_info = cookie('lang_info');
  204. if (!empty($lang_info)) {
  205. $this->eyou['global'] = array_merge($this->eyou['global'], $lang_info);
  206. }
  207. }
  208. /*电脑版与手机版的切换*/
  209. $v = I('param.v/s', 'pc');
  210. $v = trim($v, '/');
  211. $this->assign('v', $v);
  212. /*--end*/
  213. /*多语言开关限制 - 不开某个语言情况下,报404 */
  214. if ($this->main_lang != $this->home_lang) {
  215. if (isset($global['web_language_switch']) && 1 != $global['web_language_switch']) {
  216. to_index();
  217. } else {
  218. $langInfo = Db::name('language')->field('id')
  219. ->where([
  220. 'mark' => $this->home_lang,
  221. 'status' => 1,
  222. ])->find();
  223. if (empty($langInfo)) {
  224. to_index();
  225. }
  226. }
  227. }
  228. /*--end*/
  229. $assignName2 = $this->arrJoinStr(['cGhwX3Nlcn','ZpY2VtZWFs']);
  230. $assignValue2 = tpCache('php.'.$assignName2);
  231. $this->assign($assignName2, $assignValue2);
  232. // 判断是否开启注册入口
  233. $users_open_register = getUsersConfigData('users.users_open_register');
  234. $this->assign('users_open_register', $users_open_register);
  235. // 默认主题颜色
  236. if (!empty($this->usersConfig['theme_color'])) {
  237. $theme_color = $this->usersConfig['theme_color'];
  238. } else {
  239. if ($this->usersTplVersion == 'v1') {
  240. $theme_color = '#ff6565';
  241. } else {
  242. $theme_color = '#fd8a27';
  243. }
  244. }
  245. $this->usersConfig['theme_color'] = $theme_color;
  246. $this->assign('theme_color', $theme_color);
  247. // 存在游客免登录查询则执行
  248. if (is_dir('./weapp/FreeLogin/')) {
  249. // 未登录 且 存在指定访问的控制器和方法 则执行
  250. $freeLoginRow = model('Weapp')->getWeappList('FreeLogin');
  251. if (!empty($freeLoginRow['status']) && 1 == $freeLoginRow['status']) {
  252. $unifyController = new \weapp\FreeLogin\controller\FreeLogin;
  253. $unifyController->freeLoginHandle($this->usersConfig);
  254. }
  255. }
  256. $this->assign($assignData);
  257. }
  258. /**
  259. * 获取系统内置变量
  260. */
  261. public function global_assign($globalParams = [])
  262. {
  263. if (empty($globalParams)) {
  264. $globalParams = tpCache('global');
  265. }
  266. $this->assign('global', $globalParams);
  267. }
  268. }