Ei kuvausta
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

common.php 8.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. // 模板错误提示
  14. switch_exception();
  15. if (!function_exists('set_home_url_mode'))
  16. {
  17. // 设置前台URL模式
  18. function set_home_url_mode() {
  19. $uiset = I('param.uiset/s', 'off');
  20. $uiset = trim($uiset, '/');
  21. $seo_pseudo = tpCache('seo.seo_pseudo');
  22. if ($seo_pseudo == 1 || $uiset == 'on') {
  23. config('url_common_param', true);
  24. config('url_route_on', false);
  25. } elseif ($seo_pseudo == 2 && $uiset != 'on') {
  26. config('url_common_param', false);
  27. config('url_route_on', true);
  28. } elseif ($seo_pseudo == 3 && $uiset != 'on') {
  29. config('url_common_param', false);
  30. config('url_route_on', true);
  31. }
  32. }
  33. }
  34. if (!function_exists('set_arcseotitle'))
  35. {
  36. /**
  37. * 设置内容标题
  38. */
  39. function set_arcseotitle($title = '', $seo_title = '', $typename = '', $typeid = 0, $site_info = [])
  40. {
  41. /*针对没有自定义SEO标题的文档*/
  42. $title = trim($title);
  43. $seo_title = trim($seo_title);
  44. $typename = trim($typename);
  45. if (empty($seo_title)) {
  46. static $web_name = null;
  47. if (null === $web_name) {
  48. $web_name = tpCache('web.web_name');
  49. $web_name = trim($web_name);
  50. }
  51. static $seoConfig = null;
  52. null === $seoConfig && $seoConfig = tpCache('seo');
  53. $seo_viewtitle_format = !empty($seoConfig['seo_viewtitle_format']) ? intval($seoConfig['seo_viewtitle_format']) : 0;
  54. $seo_title_symbol = isset($seoConfig['seo_title_symbol']) ? htmlspecialchars_decode($seoConfig['seo_title_symbol']) : '_';
  55. switch ($seo_viewtitle_format) {
  56. case '1':
  57. $seo_title = $title;
  58. break;
  59. case '3':
  60. $seo_title = $title;
  61. if (!empty($typename)) {
  62. $seo_title .= $seo_title_symbol.$typename;
  63. }
  64. $seo_title .= $seo_title_symbol.$web_name;
  65. break;
  66. case '2':
  67. default:
  68. $opencodetype = config('global.opencodetype');
  69. if (1 == $opencodetype && in_array($typeid, [3,9,10])) {
  70. $seo_title = '';
  71. } else {
  72. $seo_title = $title.$seo_title_symbol.$web_name;
  73. }
  74. break;
  75. }
  76. }
  77. /*--end*/
  78. // 城市分站的seo
  79. if (empty($site_info)) {
  80. $site_info = cookie('site_info');
  81. $site_info = json_decode($site_info, true);
  82. }
  83. $seo_title = site_seo_handle($seo_title, $site_info);
  84. return $seo_title;
  85. }
  86. }
  87. if (!function_exists('set_typeseotitle'))
  88. {
  89. /**
  90. * 设置栏目标题
  91. */
  92. function set_typeseotitle($typename = '', $seo_title = '', $site_info = [])
  93. {
  94. static $lang = null;
  95. $lang === null && $lang = get_home_lang();
  96. static $seoConfig = null;
  97. null === $seoConfig && $seoConfig = tpCache('seo');
  98. $seo_liststitle_format = !empty($seoConfig['seo_liststitle_format']) ? intval($seoConfig['seo_liststitle_format']) : 0;
  99. $seo_title_symbol = isset($seoConfig['seo_title_symbol']) ? htmlspecialchars_decode($seoConfig['seo_title_symbol']) : '_';
  100. static $web_name = null;
  101. $web_name === null && $web_name = tpCache('web.web_name');
  102. if (empty($seo_title)) { // 针对没有自定义SEO标题的列表
  103. $old_typename = $typename;
  104. $page = I('param.page/d', 1);
  105. if ($page > 1) {
  106. $typename .= $seo_title_symbol . sprintf(foreign_lang('page6', $lang), $page);
  107. }
  108. switch ($seo_liststitle_format) {
  109. case '1':
  110. $seo_title = $old_typename.$seo_title_symbol.$web_name;
  111. break;
  112. case '3':
  113. $seo_title = $old_typename;
  114. break;
  115. case '4':
  116. $seo_title = $typename;
  117. break;
  118. case '2':
  119. default:
  120. $seo_title = $typename.$seo_title_symbol.$web_name;
  121. break;
  122. }
  123. } else {
  124. if (!in_array($seo_liststitle_format, [1,3])) {
  125. $page = I('param.page/d', 1);
  126. if ($page > 1) {
  127. $seo_title .= $seo_title_symbol . sprintf(foreign_lang('page6', $lang), $page);
  128. }
  129. }
  130. }
  131. // 城市分站的seo
  132. if (empty($site_info)) {
  133. $site_info = cookie('site_info');
  134. $site_info = json_decode($site_info, true);
  135. }
  136. $seo_title = site_seo_handle($seo_title, $site_info);
  137. return $seo_title;
  138. }
  139. }
  140. if (!function_exists('getArcLevelName'))
  141. {
  142. /**
  143. * 获取文档会员权限对应的名称
  144. */
  145. function getArcLevelName($arc_level_id = 0)
  146. {
  147. $level_name = '';
  148. static $users_level_list = null;
  149. if (null === $users_level_list) {
  150. $users_level_list = model('UsersLevel')->getList('level_id, level_name', [], 'level_id');
  151. }
  152. if (!empty($users_level_list[$arc_level_id])) {
  153. $level_name = $users_level_list[$arc_level_id]['level_name'];
  154. }
  155. return $level_name;
  156. }
  157. }
  158. if (!function_exists('get_list_only_pageurl'))
  159. {
  160. /**
  161. * 获取列表及分页的唯一url
  162. */
  163. function get_list_only_pageurl(&$pageurl = '', $typeid = 0, $rulelist = '', $page = null)
  164. {
  165. $param = input('param.');
  166. if (null === $page) {
  167. $page = empty($param['page']) ? 1 : $param['page'];
  168. }
  169. if (1 < $page) {
  170. // URL模式
  171. static $seo_pseudo = null;
  172. null === $seo_pseudo && $seo_pseudo = config('ey_config.seo_pseudo');
  173. // 筛选标识
  174. static $url_screen_var = null;
  175. null === $url_screen_var && $url_screen_var = config('global.url_screen_var');
  176. if (preg_match("#\?m=(\w+)&c=(\w+)&a=(\w+)#i", $pageurl)) {
  177. $pageurl = preg_replace('/\&page=(\d+)/i', '', $pageurl);
  178. $pageurl .= "&page={$page}";
  179. } else {
  180. if (3 == $seo_pseudo) { // 伪静态模式 by 小虎哥
  181. if (stristr($pageurl, '.html')) {
  182. $pageurl = preg_replace('/\/list_(\d+)_(\d+)\.html$/i', '.html', $pageurl);
  183. $pageurl = preg_replace('/\.html$/i', "/list_{$typeid}_{$page}.html", $pageurl);
  184. } else {
  185. $pageurl = preg_replace('/\/list_(\d+)_(\d+)\/$/i', '/', $pageurl);
  186. $pageurl .= "list_{$typeid}_{$page}/";
  187. }
  188. } else if (2 == $seo_pseudo) {
  189. $pageurl = preg_replace('/\/([^\/]+)$/i', '/', $pageurl);
  190. // PC端访问是静态页面
  191. static $seo_html_listname = null;
  192. null === $seo_html_listname && $seo_html_listname = tpCache('seo.seo_html_listname');
  193. if ($seo_html_listname == 4) { // 自定义存放目录
  194. $rulelist = preg_replace('/^((.*)\/)?([^\/]*)$/i', '${3}', $rulelist);
  195. $rulelist = empty($rulelist) ? 'list_{tid}_{page}.html' : $rulelist;
  196. $rulelist = str_replace("{tid}", $typeid, $rulelist);
  197. $rulelist = str_replace("{page}", $page, $rulelist);
  198. $pageurl = preg_replace('/\/lists_(\d+)_(\d+)\.html$/i', '', $pageurl);
  199. $pageurl .= $rulelist;
  200. } else {
  201. $pageurl = preg_replace('/\/lists_(\d+)_(\d+)\.html$/i', '.html', $pageurl);
  202. $pageurl = preg_replace('/\.html$/i', "/lists_{$typeid}_{$page}.html", $pageurl);
  203. }
  204. }
  205. }
  206. }
  207. return $pageurl;
  208. }
  209. }