route.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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. $home_rewrite = array();
  14. $route = array(
  15. '__pattern__' => array(
  16. 'tid' => '\w+',
  17. 'aid' => '\d+',
  18. ),
  19. '__alias__' => array(),
  20. '__domain__' => array(),
  21. );
  22. $globalTpCache = tpCache('global');
  23. config('tpcache', $globalTpCache);
  24. $goto = input('param.goto/s');
  25. $goto = trim($goto, '/');
  26. /*辨识响应式模板,还是PC与移动的分离模板*/
  27. $num = 0;
  28. $response_type = 0; // 默认是响应式
  29. $tpldirList = ['template/pc','template/mobile'];
  30. foreach ($tpldirList as $key => $val) {
  31. if (is_dir($val)) {
  32. $num++;
  33. if ($num >= 2) {
  34. $response_type = 1; // PC与移动端分离
  35. }
  36. }
  37. }
  38. // 分离式模板的手机端以动态URL访问
  39. $separate_mobile = 0;
  40. if (1 == $response_type && empty($globalTpCache['web_mobile_domain']) && isMobile()) {
  41. $separate_mobile = 1;
  42. }
  43. config('ey_config.response_type', $response_type);
  44. config('ey_config.separate_mobile', $separate_mobile);
  45. /*end*/
  46. // mysql的sql-mode模式参数
  47. $system_sql_mode = !empty($globalTpCache['system_sql_mode']) ? $globalTpCache['system_sql_mode'] : config('ey_config.system_sql_mode');
  48. config('ey_config.system_sql_mode', $system_sql_mode);
  49. // 多语言数量
  50. $system_langnum = !empty($globalTpCache['system_langnum']) ? intval($globalTpCache['system_langnum']) : config('ey_config.system_langnum');
  51. config('ey_config.system_langnum', $system_langnum);
  52. // 前台默认语言
  53. $system_home_default_lang = !empty($globalTpCache['system_home_default_lang']) ? $globalTpCache['system_home_default_lang'] : config('ey_config.system_home_default_lang');
  54. config('ey_config.system_home_default_lang', $system_home_default_lang);
  55. // 是否https链接
  56. $is_https = !empty($globalTpCache['web_is_https']) ? true : config('is_https');
  57. config('is_https', $is_https);
  58. $uiset = input('param.uiset/s', 'off');
  59. if ('on' == trim($uiset, '/')) { // 可视化页面必须是兼容模式的URL
  60. config('ey_config.seo_inlet', 0);
  61. config('ey_config.seo_pseudo', 1);
  62. config('ey_config.seo_dynamic_format', 1);
  63. } else {
  64. // URL模式
  65. $seo_pseudo = !empty($globalTpCache['seo_pseudo']) ? intval($globalTpCache['seo_pseudo']) : config('ey_config.seo_pseudo');
  66. $seo_dynamic_format = !empty($globalTpCache['seo_dynamic_format']) ? intval($globalTpCache['seo_dynamic_format']) : config('ey_config.seo_dynamic_format');
  67. // 分离式的手机端以动态URL模式访问
  68. if (1 == $separate_mobile) {
  69. // 当前配置是动态或者静态模式
  70. if (in_array($seo_pseudo, [1,2])) {
  71. $seo_pseudo = 1;
  72. $seo_dynamic_format = 1;
  73. }
  74. }
  75. // URL格式
  76. config('ey_config.seo_pseudo', $seo_pseudo);
  77. config('ey_config.seo_dynamic_format', $seo_dynamic_format);
  78. // 伪静态格式
  79. $seo_rewrite_format = !empty($globalTpCache['seo_rewrite_format']) ? intval($globalTpCache['seo_rewrite_format']) : config('ey_config.seo_rewrite_format');
  80. config('ey_config.seo_rewrite_format', $seo_rewrite_format);
  81. // 是否隐藏入口文件
  82. $seo_inlet = !empty($globalTpCache['seo_inlet']) ? $globalTpCache['seo_inlet'] : config('ey_config.seo_inlet');
  83. config('ey_config.seo_inlet', $seo_inlet);
  84. if (3 == $seo_pseudo) {
  85. $lang_rewrite = [];
  86. $lang_rewrite_str = '';
  87. /*多语言*/
  88. $lang = input('param.lang/s');
  89. if (is_language()) {
  90. if (!stristr($request->baseFile(), 'index.php')) {
  91. if (!empty($lang) && $lang != $system_home_default_lang) {
  92. $lang_rewrite_str = '<lang>/';
  93. }
  94. } else {
  95. if (get_current_lang() != get_default_lang()) {
  96. $lang_rewrite_str .= '<lang>/';
  97. }
  98. }
  99. }
  100. if (!empty($lang_rewrite_str)) {
  101. $lang_rewrite = [
  102. // 首页
  103. $lang_rewrite_str.'$' => array('home/Index/index',array('method' => 'get', 'ext' => ''), 'cache'=>1),
  104. ];
  105. }
  106. /*--end*/
  107. if (1 == $seo_rewrite_format || 3 == $seo_rewrite_format) { // 精简伪静态
  108. $home_rewrite = array(
  109. // 会员中心
  110. $lang_rewrite_str.'user$' => array('user/Users/login',array('ext' => ''), 'cache'=>1),
  111. $lang_rewrite_str.'reg$' => array('user/Users/reg',array('ext' => ''), 'cache'=>1),
  112. $lang_rewrite_str.'centre$' => array('user/Users/centre',array('ext' => ''), 'cache'=>1),
  113. $lang_rewrite_str.'user/index$' => array('user/Users/index',array('ext' => ''), 'cache'=>1),
  114. $lang_rewrite_str.'cart$' => array('user/Shop/shop_cart_list',array('ext' => ''), 'cache'=>1),
  115. // 标签伪静态
  116. $lang_rewrite_str.'tags$' => array('home/Tags/index',array('method' => 'get', 'ext' => ''), 'cache'=>1),
  117. $lang_rewrite_str.'tags/<tagid>$' => array('home/Tags/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  118. // 搜索伪静态
  119. $lang_rewrite_str.'search$' => array('home/Search/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  120. // 列表页
  121. $lang_rewrite_str.'<tid>$' => array('home/Lists/index',array('method' => 'get', 'ext' => ''), 'cache'=>1),
  122. // 内容页
  123. $lang_rewrite_str.'<dirname>/<aid>$' => array('home/View/index',array('method' => 'get', 'ext' => 'html'),'cache'=>1),
  124. );
  125. } else {
  126. $home_rewrite = array(
  127. // 会员中心
  128. $lang_rewrite_str.'Users/login$' => array('user/Users/login',array('ext' => 'html'), 'cache'=>1),
  129. $lang_rewrite_str.'Users/reg$' => array('user/Users/reg',array('ext' => 'html'), 'cache'=>1),
  130. $lang_rewrite_str.'Users/centre$' => array('user/Users/centre',array('ext' => 'html'), 'cache'=>1),
  131. $lang_rewrite_str.'Users/index$' => array('user/Users/index',array('ext' => 'html'), 'cache'=>1),
  132. $lang_rewrite_str.'Users/cart$' => array('user/Shop/shop_cart_list',array('ext' => 'html'), 'cache'=>1),
  133. // 文章模型伪静态
  134. $lang_rewrite_str.'article/<tid>$' => array('home/Article/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  135. $lang_rewrite_str.'article/<dirname>/<aid>$' => array('home/Article/view',array('method' => 'get', 'ext' => 'html'),'cache'=>1),
  136. // 产品模型伪静态
  137. $lang_rewrite_str.'product/<tid>$' => array('home/Product/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  138. $lang_rewrite_str.'product/<dirname>/<aid>$' => array('home/Product/view',array('method' => 'get', 'ext' => 'html'),'cache'=>1),
  139. // 图集模型伪静态
  140. $lang_rewrite_str.'images/<tid>$' => array('home/Images/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  141. $lang_rewrite_str.'images/<dirname>/<aid>$' => array('home/Images/view',array('method' => 'get', 'ext' => 'html'),'cache'=>1),
  142. // 下载模型伪静态
  143. $lang_rewrite_str.'download/<tid>$' => array('home/Download/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  144. $lang_rewrite_str.'download/<dirname>/<aid>$' => array('home/Download/view',array('method' => 'get', 'ext' => 'html'),'cache'=>1),
  145. // 单页模型伪静态
  146. $lang_rewrite_str.'single/<tid>$' => array('home/Single/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  147. // 标签伪静态
  148. $lang_rewrite_str.'tags$' => array('home/Tags/index',array('method' => 'get', 'ext' => ''), 'cache'=>1),
  149. $lang_rewrite_str.'tags/<tagid>$' => array('home/Tags/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  150. // 搜索伪静态
  151. $lang_rewrite_str.'search$' => array('home/Search/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  152. // 留言模型
  153. $lang_rewrite_str.'guestbook/<tid>$' => array('home/Guestbook/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  154. );
  155. /*自定义模型*/
  156. $cacheKey = "application_route_channeltype";
  157. $channeltype_row = \think\Cache::get($cacheKey);
  158. if (empty($channeltype_row)) {
  159. $channeltype_row = \think\Db::name('channeltype')->field('nid,ctl_name')
  160. ->where([
  161. 'ifsystem' => 0,
  162. ])
  163. ->select();
  164. \think\Cache::set($cacheKey, $channeltype_row, EYOUCMS_CACHE_TIME, "channeltype");
  165. }
  166. foreach ($channeltype_row as $value) {
  167. $home_rewrite += array(
  168. $lang_rewrite_str.$value['nid'].'/<tid>$' => array('home/'.$value['ctl_name'].'/lists',array('method' => 'get', 'ext' => 'html'), 'cache'=>1),
  169. $lang_rewrite_str.$value['nid'].'/<dirname>/<aid>$' => array('home/'.$value['ctl_name'].'/view',array('method' => 'get', 'ext' => 'html'),'cache'=>1),
  170. );
  171. }
  172. /*--end*/
  173. }
  174. $home_rewrite = array_merge($lang_rewrite, $home_rewrite);
  175. }
  176. /*插件模块路由*/
  177. $weapp_route_file = 'plugins/route.php';
  178. if (file_exists(APP_PATH.$weapp_route_file)) {
  179. $weapp_route = include_once $weapp_route_file;
  180. $route = array_merge($weapp_route, $route);
  181. }
  182. /*--end*/
  183. }
  184. $route = array_merge($route, $home_rewrite);
  185. return $route;