common.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  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. if (!function_exists('is_adminlogin'))
  14. {
  15. /**
  16. * 检验登陆
  17. * @param
  18. * @return bool
  19. */
  20. function is_adminlogin(){
  21. $admin_id = session('admin_id');
  22. if(isset($admin_id) && $admin_id > 0){
  23. return $admin_id;
  24. }else{
  25. return false;
  26. }
  27. }
  28. }
  29. if (!function_exists('adminLog'))
  30. {
  31. /**
  32. * 管理员操作记录
  33. * @param $log_url 操作URL
  34. * @param $log_info 记录信息
  35. */
  36. function adminLog($log_info = ''){
  37. $admin_id = session('admin_id');
  38. $admin_id = !empty($admin_id) ? $admin_id : -1;
  39. $add['log_time'] = getTime();
  40. $add['admin_id'] = $admin_id;
  41. $add['log_info'] = $log_info;
  42. $add['log_ip'] = clientIP();
  43. $add['log_url'] = request()->baseUrl() ;
  44. M('admin_log')->add($add);
  45. }
  46. }
  47. if (!function_exists('getAdminInfo'))
  48. {
  49. /**
  50. * 获取管理员登录信息
  51. */
  52. function getAdminInfo($admin_id = 0)
  53. {
  54. $admin_info = [];
  55. $admin_id = empty($admin_id) ? session('admin_id') : $admin_id;
  56. if (0 < intval($admin_id)) {
  57. $admin_info = \think\Db::name('admin')
  58. ->field('a.*, b.name AS role_name')
  59. ->alias('a')
  60. ->join('__AUTH_ROLE__ b', 'b.id = a.role_id', 'LEFT')
  61. ->where("a.admin_id", $admin_id)
  62. ->find();
  63. if (!empty($admin_info)) {
  64. // 头像
  65. empty($admin_info['head_pic']) && $admin_info['head_pic'] = get_head_pic($admin_info['head_pic'], true);
  66. // 权限组
  67. $admin_info['role_id'] = !empty($admin_info['role_id']) ? $admin_info['role_id'] : -1;
  68. if (-1 == $admin_info['role_id']) {
  69. if (!empty($admin_info['parent_id'])) {
  70. $role_name = '超级管理员';
  71. } else {
  72. $role_name = '创始人';
  73. }
  74. } else {
  75. $role_name = $admin_info['role_name'];
  76. }
  77. $admin_info['role_name'] = $role_name;
  78. }
  79. }
  80. return $admin_info;
  81. }
  82. }
  83. if (!function_exists('get_conf'))
  84. {
  85. /**
  86. * 获取conf配置文件
  87. */
  88. function get_conf($name = 'global')
  89. {
  90. $arr = include APP_PATH.MODULE_NAME.'/conf/'.$name.'.php';
  91. return $arr;
  92. }
  93. }
  94. if (!function_exists('get_auth_rule'))
  95. {
  96. /**
  97. * 获取权限列表文件
  98. */
  99. function get_auth_rule($where = [])
  100. {
  101. $auth_rule = include APP_PATH.MODULE_NAME.'/conf/auth_rule.php';
  102. // 排序号排序
  103. // $sort_order_arr = array();
  104. // foreach($auth_rule as $key => $val){
  105. // $sort_order_arr[]['sort_order'] = $val['sort_order'];
  106. // }
  107. // array_multisort($sort_order_arr,SORT_ASC,$auth_rule);
  108. if (!empty($where)) {
  109. foreach ($auth_rule as $k1 => $rules) {
  110. foreach ($where as $k2 => $v2) {
  111. if ($rules[$k2] != $v2) {
  112. unset($auth_rule[$k1]);
  113. }
  114. }
  115. }
  116. }
  117. return $auth_rule;
  118. }
  119. }
  120. if (!function_exists('is_check_access'))
  121. {
  122. /**
  123. * 检测是否有该权限
  124. */
  125. function is_check_access($str = 'Index@index') {
  126. $bool_flag = 1;
  127. $role_id = session('admin_info.role_id');
  128. if (0 < intval($role_id)) {
  129. $ctl_act = strtolower($str);
  130. $arr = explode('@', $ctl_act);
  131. $ctl = !empty($arr[0]) ? $arr[0] : '';
  132. $act = !empty($arr[1]) ? $arr[1] : '';
  133. $ctl_all = $ctl.'@*';
  134. $auth_role_info = session('admin_info.auth_role_info');
  135. $permission = $auth_role_info['permission'];
  136. $permission_rules = !empty($permission['rules']) ? $permission['rules'] : [];
  137. $auth_rule = get_auth_rule();
  138. $all_auths = []; // 系统全部权限对应的菜单ID
  139. $admin_auths = []; // 用户当前拥有权限对应的菜单ID
  140. $diff_auths = []; // 用户没有被授权的权限对应的菜单ID
  141. foreach($auth_rule as $key => $val){
  142. $all_auths = array_merge($all_auths, explode(',', strtolower($val['auths'])));
  143. if (in_array($val['id'], $permission_rules)) {
  144. $admin_auths = array_merge($admin_auths, explode(',', strtolower($val['auths'])));
  145. }
  146. }
  147. $all_auths = array_unique($all_auths);
  148. $admin_auths = array_unique($admin_auths);
  149. $diff_auths = array_diff($all_auths, $admin_auths);
  150. if (in_array($ctl_act, $diff_auths) || in_array($ctl_all, $diff_auths)) {
  151. $bool_flag = false;
  152. }
  153. }
  154. return $bool_flag;
  155. }
  156. }
  157. if (!function_exists('getMenuList'))
  158. {
  159. /**
  160. * 根据角色权限过滤菜单
  161. */
  162. function getMenuList() {
  163. $menuArr = getAllMenu();
  164. // return $menuArr;
  165. $role_id = session('admin_info.role_id');
  166. if (0 < intval($role_id)) {
  167. $auth_role_info = session('admin_info.auth_role_info');
  168. $permission = $auth_role_info['permission'];
  169. $permission_rules = !empty($permission['rules']) ? $permission['rules'] : [];
  170. $auth_rule = get_auth_rule();
  171. $all_auths = []; // 系统全部权限对应的菜单ID
  172. $admin_auths = []; // 用户当前拥有权限对应的菜单ID
  173. $diff_auths = []; // 用户没有被授权的权限对应的菜单ID
  174. foreach($auth_rule as $key => $val){
  175. $all_auths = array_merge($all_auths, explode(',', $val['menu_id']), explode(',', $val['menu_id2']));
  176. if (in_array($val['id'], $permission_rules)) {
  177. $admin_auths = array_merge($admin_auths, explode(',', $val['menu_id']), explode(',', $val['menu_id2']));
  178. }
  179. }
  180. $all_auths = array_unique($all_auths);
  181. $admin_auths = array_unique($admin_auths);
  182. $diff_auths = array_diff($all_auths, $admin_auths);
  183. /*过滤三级数组菜单*/
  184. foreach($menuArr as $k=>$val){
  185. foreach ($val['child'] as $j=>$v){
  186. foreach ($v['child'] as $s=>$son){
  187. if (in_array($son['id'], $diff_auths)) {
  188. unset($menuArr[$k]['child'][$j]['child'][$s]);//过滤菜单
  189. }
  190. }
  191. }
  192. }
  193. /*--end*/
  194. /*过滤二级数组菜单*/
  195. foreach ($menuArr as $mk=>$mr){
  196. foreach ($mr['child'] as $nk=>$nrr){
  197. if (in_array($nrr['id'], $diff_auths)) {
  198. unset($menuArr[$mk]['child'][$nk]);//过滤菜单
  199. }
  200. }
  201. }
  202. /*--end*/
  203. }
  204. return $menuArr;
  205. }
  206. }
  207. if (!function_exists('getAllMenu'))
  208. {
  209. /**
  210. * 获取左侧菜单
  211. */
  212. function getAllMenu() {
  213. $menuArr = false;//extra_cache('admin_all_menu');
  214. if (!$menuArr) {
  215. $menuArr = get_conf('menu');
  216. extra_cache('admin_all_menu', $menuArr);
  217. }
  218. return $menuArr;
  219. }
  220. }
  221. if ( ! function_exists('getChanneltypeList'))
  222. {
  223. /**
  224. * 获取全部的模型
  225. */
  226. function getChanneltypeList()
  227. {
  228. $result = extra_cache('admin_channeltype_list_logic');
  229. if ($result == false)
  230. {
  231. $result = model('Channeltype')->getAll('*', array(), 'id');
  232. extra_cache('admin_channeltype_list_logic', $result);
  233. }
  234. return $result;
  235. }
  236. }
  237. if (!function_exists('tpversion'))
  238. {
  239. function tpversion($timeout = 5)
  240. {
  241. if(!empty($_SESSION['isset_push']))
  242. return false;
  243. $_SESSION['isset_push'] = 1;
  244. error_reporting(0);//关闭所有错误报告
  245. $install_time = DEFAULT_INSTALL_DATE;
  246. $serial_number = DEFAULT_SERIALNUMBER;
  247. $constsant_path = APP_PATH.'admin/conf/constant.php';
  248. if (file_exists($constsant_path)) {
  249. require_once($constsant_path);
  250. defined('INSTALL_DATE') && $install_time = INSTALL_DATE;
  251. defined('SERIALNUMBER') && $serial_number = SERIALNUMBER;
  252. }
  253. $curent_version = getCmsVersion();
  254. $mysqlinfo = \think\Db::query("SELECT VERSION() as version");
  255. $mysql_version = $mysqlinfo[0]['version'];
  256. $global_config = tpCache('global');
  257. $users_config = getUsersConfigData('all');
  258. $vaules = array(
  259. 'domain'=>$_SERVER['HTTP_HOST'],
  260. 'key_num'=>$curent_version,
  261. 'install_time'=>$install_time,
  262. 'serial_number'=>$serial_number,
  263. 'ip' => GetHostByName($_SERVER['SERVER_NAME']),
  264. 'global_config' => base64_encode(json_encode($global_config)),
  265. 'users_config' => base64_encode(json_encode($users_config)),
  266. 'phpv' => urlencode(phpversion()),
  267. 'mysql_version' => urlencode($mysql_version),
  268. 'web_server' => urlencode($_SERVER['SERVER_SOFTWARE']),
  269. 'web_title' => tpCache('web.web_title'),
  270. );
  271. // api_Service_user_push
  272. $service_ey = config('service_ey');
  273. $tmp_str = 'L2luZGV4LnBocD9tPWFwaSZjPVNlcnZpY2UmYT11c2VyX3B1c2gm';
  274. $url = base64_decode($service_ey).base64_decode($tmp_str);
  275. @httpRequest($url, 'POST', $vaules, [], $timeout);
  276. }
  277. }
  278. if (!function_exists('push_zzbaidu'))
  279. {
  280. /**
  281. * 将新链接推送给百度蜘蛛
  282. */
  283. function push_zzbaidu($type = 'urls', $aid = '', $typeid = '')
  284. {
  285. // 获取token的值:http://ziyuan.baidu.com/linksubmit/index?site=http://www.eyoucms.com/
  286. $aid = intval($aid);
  287. $typeid = intval($typeid);
  288. $sitemap_zzbaidutoken = tpCache('sitemap.sitemap_zzbaidutoken');
  289. if (empty($sitemap_zzbaidutoken) || (empty($aid) && empty($typeid)) || !function_exists('curl_init')) {
  290. return '';
  291. }
  292. $urlsArr = array();
  293. $channeltype_list = model('Channeltype')->getAll('id, ctl_name', array(), 'id');
  294. if ($aid > 0) {
  295. $res = M('archives')->field('b.*, a.*, a.aid, b.id as typeid')
  296. ->alias('a')
  297. ->join('__ARCTYPE__ b', 'b.id = a.typeid', 'LEFT')
  298. ->find($aid);
  299. $arcurl = get_arcurl($res, false);
  300. array_push($urlsArr, $arcurl);
  301. }
  302. if (0 < $typeid) {
  303. $res = M('arctype')->field('a.*')
  304. ->alias('a')
  305. ->find($typeid);
  306. $typeurl = get_typeurl($res, false);
  307. array_push($urlsArr, $typeurl);
  308. }
  309. $type = ('edit' == $type) ? 'update' : 'urls';
  310. $api = 'http://data.zz.baidu.com/'.$type.'?site='.request()->host(true).'&token='.$sitemap_zzbaidutoken;
  311. $ch = curl_init();
  312. $options = array(
  313. CURLOPT_URL => $api,
  314. CURLOPT_POST => true,
  315. CURLOPT_RETURNTRANSFER => true,
  316. CURLOPT_POSTFIELDS => implode("\n", $urlsArr),
  317. CURLOPT_HTTPHEADER => array('Content-Type: text/plain'),
  318. );
  319. curl_setopt_array($ch, $options);
  320. $result = curl_exec($ch);
  321. return $result;
  322. }
  323. }
  324. if (!function_exists('sitemap_auto'))
  325. {
  326. /**
  327. * 自动生成引擎sitemap
  328. */
  329. function sitemap_auto()
  330. {
  331. $sitemap_config = tpCache('sitemap');
  332. if (isset($sitemap_config['sitemap_auto']) && $sitemap_config['sitemap_auto'] > 0) {
  333. sitemap_all();
  334. }
  335. }
  336. }
  337. if (!function_exists('sitemap_all'))
  338. {
  339. /**
  340. * 生成全部引擎sitemap
  341. */
  342. function sitemap_all()
  343. {
  344. sitemap_xml();
  345. }
  346. }
  347. if (!function_exists('sitemap_xml'))
  348. {
  349. /**
  350. * 生成xml形式的sitemap
  351. */
  352. function sitemap_xml()
  353. {
  354. $globalConfig = tpCache('global');
  355. if (!isset($globalConfig['sitemap_xml']) || empty($globalConfig['sitemap_xml'])) {
  356. return '';
  357. }
  358. $modelu_name = 'home';
  359. $filename = ROOT_PATH . "sitemap.xml";
  360. $main_lang = get_main_lang();
  361. /* 分类列表(用于生成列表链接的sitemap) */
  362. $map = array(
  363. 'status' => 1,
  364. 'is_del' => 0,
  365. 'lang' => $main_lang,
  366. );
  367. if (is_array($globalConfig)) {
  368. // 过滤隐藏栏目
  369. if (isset($globalConfig['sitemap_not1']) && $globalConfig['sitemap_not1'] > 0) {
  370. $map['is_hidden'] = 0;
  371. }
  372. // 过滤外部模块
  373. if (isset($globalConfig['sitemap_not2']) && $globalConfig['sitemap_not2'] > 0) {
  374. $map['is_part'] = 0;
  375. }
  376. }
  377. $result_arctype = M('arctype')->field("*, id AS loc, add_time AS lastmod, 'hourly' AS changefreq, '0.8' AS priority")
  378. ->where($map)
  379. ->order('sort_order asc, id asc')
  380. ->getAllWithIndex('id');
  381. /* 文章列表(用于生成文章详情链接的sitemap) */
  382. $map = array(
  383. 'channel' => ['IN', config('global.allow_release_channel')],
  384. 'arcrank' => array('gt', -1),
  385. 'status' => 1,
  386. 'is_del' => 0,
  387. 'lang' => $main_lang,
  388. );
  389. if (is_array($globalConfig)) {
  390. // 过滤外部模块
  391. if (isset($globalConfig['sitemap_not2']) && $globalConfig['sitemap_not2'] > 0) {
  392. $map['is_jump'] = 0;
  393. }
  394. }
  395. /*定时文档显示插件*/
  396. if (is_dir('./weapp/TimingTask/')) {
  397. $TimingTaskRow = model('Weapp')->getWeappList('TimingTask');
  398. if (!empty($TimingTaskRow['status']) && 1 == $TimingTaskRow['status']) {
  399. $map['add_time'] = ['elt', getTime()]; // 只显当天或之前的文档
  400. }
  401. }
  402. /*end*/
  403. if (!isset($globalConfig['sitemap_archives_num']) || $globalConfig['sitemap_archives_num'] == '') {
  404. $sitemap_archives_num = 100;
  405. } else {
  406. $sitemap_archives_num = intval($globalConfig['sitemap_archives_num']);
  407. }
  408. $field = "aid, channel, is_jump, jumplinks, add_time, update_time, typeid, aid AS loc, add_time AS lastmod, 'daily' AS changefreq, '0.5' AS priority";
  409. $result_archives = M('archives')->field($field)
  410. ->where($map)
  411. ->order('aid desc')
  412. ->limit($sitemap_archives_num)
  413. ->select();
  414. // header('Content-Type: text/xml');//这行很重要,php默认输出text/html格式的文件,所以这里明确告诉浏览器输出的格式为xml,不然浏览器显示不出xml的格式
  415. $xml_wrapper = <<<XML
  416. <?xml version='1.0' encoding='utf-8'?>
  417. <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  418. </urlset>
  419. XML;
  420. if (function_exists('simplexml_load_string')) {
  421. $xml = @simplexml_load_string($xml_wrapper);
  422. } else if (class_exists('SimpleXMLElement')) {
  423. $xml = new SimpleXMLElement($xml_wrapper);
  424. }
  425. if (!$xml) {
  426. return true;
  427. }
  428. // 更新频率
  429. $sitemap_changefreq_index = !empty($globalConfig['sitemap_changefreq_index']) ? $globalConfig['sitemap_changefreq_index'] : 'always';
  430. $sitemap_changefreq_list = !empty($globalConfig['sitemap_changefreq_list']) ? $globalConfig['sitemap_changefreq_list'] : 'hourly';
  431. $sitemap_changefreq_view = !empty($globalConfig['sitemap_changefreq_view']) ? $globalConfig['sitemap_changefreq_view'] : 'daily';
  432. // 优先级别
  433. $sitemap_priority_index = !empty($globalConfig['sitemap_priority_index']) ? $globalConfig['sitemap_priority_index'] : '1.0';
  434. $sitemap_priority_list = !empty($globalConfig['sitemap_priority_list']) ? $globalConfig['sitemap_priority_list'] : '0.8';
  435. $sitemap_priority_view = !empty($globalConfig['sitemap_priority_view']) ? $globalConfig['sitemap_priority_view'] : '0.5';
  436. $langRow = \think\Db::name('language')
  437. ->where(['status'=>1])
  438. ->order('id asc')
  439. ->cache(true, EYOUCMS_CACHE_TIME, 'language')
  440. ->select();
  441. /*去掉入口文件*/
  442. $inletStr = '/index.php';
  443. $seo_inlet = config('ey_config.seo_inlet');
  444. 1 == intval($seo_inlet) && $inletStr = '';
  445. /*--end*/
  446. /*首页*/
  447. foreach ($langRow as $key => $val) {
  448. /*关闭多语言*/
  449. if (empty($globalConfig['web_language_switch']) && 1 != $val['is_home_default']) {
  450. continue;
  451. }
  452. /*end*/
  453. /*单独域名*/
  454. $mark = $val['mark'];
  455. $url = $val['url'];
  456. if (empty($url)) {
  457. if (1 == $val['is_home_default']) {
  458. $url = request()->domain().ROOT_DIR.'/'; // 支持子目录
  459. } else {
  460. $seoConfig = tpCache('seo', [], $mark);
  461. $seo_pseudo = !empty($seoConfig['seo_pseudo']) ? $seoConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  462. if (1 == $seo_pseudo) {
  463. $url = request()->domain().ROOT_DIR.$inletStr; // 支持子目录
  464. if (!empty($inletStr)) {
  465. $url .= '?';
  466. } else {
  467. $url .= '/?';
  468. }
  469. $url .= http_build_query(['lang'=>$mark]);
  470. } else {
  471. $url = request()->domain().ROOT_DIR.$inletStr.'/'.$mark; // 支持子目录
  472. }
  473. }
  474. }
  475. /*--end*/
  476. $item = $xml->addChild('url'); //使用addChild添加节点
  477. foreach (['loc','lastmod','changefreq','priority'] as $key1) {
  478. if ('loc' == $key1) {
  479. $row = $url;
  480. } else if ('lastmod' == $key1) {
  481. $row = date('Y-m-d');
  482. } else if ('changefreq' == $key1) {
  483. $row = $sitemap_changefreq_index;
  484. } else if ('priority' == $key1) {
  485. $row = $sitemap_priority_index;
  486. }
  487. try {
  488. $node = $item->addChild($key1, $row);
  489. } catch (\Exception $e) {}
  490. if (isset($attribute_array[$key1]) && is_array($attribute_array[$key1])) {
  491. foreach ($attribute_array[$key1] as $akey => $aval) {//设置属性值,我这里为空
  492. $node->addAttribute($akey, $aval);
  493. }
  494. }
  495. }
  496. }
  497. /*--end*/
  498. /*所有栏目*/
  499. foreach ($result_arctype as $sub) {
  500. if (is_array($sub)) {
  501. $item = $xml->addChild('url'); //使用addChild添加节点
  502. foreach ($sub as $key => $row) {
  503. if (in_array($key, array('loc','lastmod','changefreq','priority'))) {
  504. if ($key == 'loc') {
  505. if ($sub['is_part'] == 1) {
  506. $row = $sub['typelink'];
  507. } else {
  508. $row = get_typeurl($sub, false);
  509. }
  510. $row = str_replace('&amp;', '&', $row);
  511. $row = str_replace('&', '&amp;', $row);
  512. } else if ($key == 'lastmod') {
  513. $row = date('Y-m-d');
  514. } else if ($key == 'changefreq') {
  515. $row = $sitemap_changefreq_list;
  516. } else if ($key == 'priority') {
  517. $row = $sitemap_priority_list;
  518. }
  519. try {
  520. $node = $item->addChild($key, $row);
  521. } catch (\Exception $e) {}
  522. if (isset($attribute_array[$key]) && is_array($attribute_array[$key])) {
  523. foreach ($attribute_array[$key] as $akey => $aval) {//设置属性值,我这里为空
  524. $node->addAttribute($akey, $aval);
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. /*--end*/
  532. /*所有文档*/
  533. foreach ($result_archives as $val) {
  534. if (is_array($val) && isset($result_arctype[$val['typeid']])) {
  535. $item = $xml->addChild('url'); //使用addChild添加节点
  536. $val = array_merge($result_arctype[$val['typeid']], $val);
  537. foreach ($val as $key => $row) {
  538. if (in_array($key, array('loc','lastmod','changefreq','priority'))) {
  539. if ($key == 'loc') {
  540. if ($val['is_jump'] == 1) {
  541. $row = $val['jumplinks'];
  542. } else {
  543. $row = get_arcurl($val, false);
  544. }
  545. $row = str_replace('&amp;', '&', $row);
  546. $row = str_replace('&', '&amp;', $row);
  547. } else if ($key == 'lastmod') {
  548. $lastmod_time = empty($val['update_time']) ? $val['add_time'] : $val['update_time'];
  549. $row = date('Y-m-d', $lastmod_time);
  550. } else if ($key == 'changefreq') {
  551. $row = $sitemap_changefreq_view;
  552. } else if ($key == 'priority') {
  553. $row = $sitemap_priority_view;
  554. }
  555. try {
  556. $node = $item->addChild($key, $row);
  557. } catch (\Exception $e) {}
  558. if (isset($attribute_array[$key]) && is_array($attribute_array[$key])) {
  559. foreach ($attribute_array[$key] as $akey => $aval) {//设置属性值,我这里为空
  560. $node->addAttribute($akey, $aval);
  561. }
  562. }
  563. }
  564. }
  565. }
  566. }
  567. /*--end*/
  568. $content = $xml->asXML(); //用asXML方法输出xml,默认只构造不输出。
  569. @file_put_contents($filename, $content);
  570. }
  571. }
  572. if (!function_exists('get_typeurl'))
  573. {
  574. /**
  575. * 获取栏目链接
  576. *
  577. * @param array $arctype_info 栏目信息
  578. * @param boolean $admin 后台访问链接,还是前台链接
  579. */
  580. function get_typeurl($arctype_info = array(), $admin = true)
  581. {
  582. static $domain = null;
  583. null === $domain && $domain = request()->domain();
  584. /*兼容采集没有归属栏目的文档*/
  585. if (empty($arctype_info['current_channel'])) {
  586. $channelRow = \think\Db::name('channeltype')->field('id as channel')
  587. ->where('id',1)
  588. ->find();
  589. $arctype_info = array_merge($arctype_info, $channelRow);
  590. }
  591. /*--end*/
  592. static $result = null;
  593. null === $result && $result = model('Channeltype')->getAll('id, ctl_name', array(), 'id');
  594. $ctl_name = '';
  595. if ($result) {
  596. $ctl_name = $result[$arctype_info['current_channel']]['ctl_name'];
  597. }
  598. static $seo_pseudo = null;
  599. static $seo_dynamic_format = null;
  600. if (null === $seo_pseudo || null === $seo_dynamic_format) {
  601. $seoConfig = tpCache('seo');
  602. $seo_pseudo = !empty($seoConfig['seo_pseudo']) ? $seoConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  603. $seo_dynamic_format = !empty($seoConfig['seo_dynamic_format']) ? $seoConfig['seo_dynamic_format'] : config('ey_config.seo_dynamic_format');
  604. }
  605. if (2 == $seo_pseudo && $admin) {
  606. static $lang = null;
  607. null === $lang && $lang = input('param.lang/s', 'cn');
  608. $typeurl = ROOT_DIR."/index.php?m=home&c=Lists&a=index&tid={$arctype_info['id']}&lang={$lang}&t=".getTime();
  609. } else {
  610. $typeurl = typeurl("home/{$ctl_name}/lists", $arctype_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  611. // 自动隐藏index.php入口文件
  612. $typeurl = auto_hide_index($typeurl);
  613. }
  614. return $typeurl;
  615. }
  616. }
  617. if (!function_exists('get_arcurl'))
  618. {
  619. /**
  620. * 获取文档链接
  621. *
  622. * @param array $arctype_info 栏目信息
  623. * @param boolean $admin 后台访问链接,还是前台链接
  624. */
  625. function get_arcurl($arcview_info = array(), $admin = true)
  626. {
  627. static $domain = null;
  628. null === $domain && $domain = request()->domain();
  629. /*兼容采集没有归属栏目的文档*/
  630. if (empty($arcview_info['channel'])) {
  631. $channelRow = \think\Db::name('channeltype')->field('id as channel')
  632. ->where('id',1)
  633. ->find();
  634. $arcview_info = array_merge($arcview_info, $channelRow);
  635. }
  636. /*--end*/
  637. static $result = null;
  638. null === $result && $result = model('Channeltype')->getAll('id, ctl_name', array(), 'id');
  639. $ctl_name = '';
  640. if ($result) {
  641. $ctl_name = $result[$arcview_info['channel']]['ctl_name'];
  642. }
  643. static $seo_pseudo = null;
  644. static $seo_dynamic_format = null;
  645. if (null === $seo_pseudo || null === $seo_dynamic_format) {
  646. $seoConfig = tpCache('seo');
  647. $seo_pseudo = !empty($seoConfig['seo_pseudo']) ? $seoConfig['seo_pseudo'] : config('ey_config.seo_pseudo');
  648. $seo_dynamic_format = !empty($seoConfig['seo_dynamic_format']) ? $seoConfig['seo_dynamic_format'] : config('ey_config.seo_dynamic_format');
  649. }
  650. if ($admin) {
  651. if (2 == $seo_pseudo) {
  652. static $lang = null;
  653. null === $lang && $lang = input('param.lang/s', 'cn');
  654. $arcurl = ROOT_DIR."/index.php?m=home&c=View&a=index&aid={$arcview_info['aid']}&lang={$lang}&admin_id=".session('admin_id')."&t=".getTime();
  655. } else {
  656. $arcurl = arcurl("home/{$ctl_name}/view", $arcview_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  657. // 自动隐藏index.php入口文件
  658. $arcurl = auto_hide_index($arcurl);
  659. if (stristr($arcurl, '?')) {
  660. $arcurl .= '&admin_id='.session('admin_id')."&t=".getTime();
  661. } else {
  662. $arcurl .= '?admin_id='.session('admin_id')."&t=".getTime();
  663. }
  664. }
  665. } else {
  666. $arcurl = arcurl("home/{$ctl_name}/view", $arcview_info, true, $domain, $seo_pseudo, $seo_dynamic_format);
  667. // 自动隐藏index.php入口文件
  668. $arcurl = auto_hide_index($arcurl);
  669. }
  670. return $arcurl;
  671. }
  672. }
  673. if (!function_exists('get_total_arc'))
  674. {
  675. /**
  676. * 获取指定栏目的文档数
  677. */
  678. function get_total_arc($typeid)
  679. {
  680. $total = 0;
  681. $current_channel = M('arctype')->where('id', $typeid)->getField('current_channel');
  682. $allow_release_channel = config('global.allow_release_channel');
  683. if (in_array($current_channel, $allow_release_channel)) { // 能发布文档的模型
  684. $result = model('Arctype')->getHasChildren($typeid);
  685. $typeidArr = get_arr_column($result, 'id');
  686. $map = array(
  687. 'typeid' => array('IN', $typeidArr),
  688. 'channel' => array('eq', $current_channel),
  689. 'is_del' => 0, // 回收站功能
  690. );
  691. /*权限控制 by 小虎哥*/
  692. $admin_info = session('admin_info');
  693. if (0 < intval($admin_info['role_id'])) {
  694. $auth_role_info = $admin_info['auth_role_info'];
  695. if(! empty($auth_role_info)){
  696. if(isset($auth_role_info['only_oneself']) && 1 == $auth_role_info['only_oneself']){
  697. $map['admin_id'] = $admin_info['admin_id'];
  698. }
  699. }
  700. }
  701. /*--end*/
  702. $total = M('archives')->where($map)->count();
  703. } elseif ($current_channel == 8) { // 留言模型
  704. $total = M('guestbook')->where(array('typeid'=>array('eq', $typeid)))->count();
  705. }
  706. return $total;
  707. }
  708. }
  709. if (!function_exists('replace_path'))
  710. {
  711. /**
  712. * 将路径斜杆、反斜杠替换为冒号符,适用于IIS服务器在URL上的双重转义限制
  713. * @param string $filepath 相对路径
  714. * @param string $replacement 目标字符
  715. * @param boolean $is_back false为替换,true为还原
  716. */
  717. function replace_path($filepath = '', $replacement = ':', $is_back = false)
  718. {
  719. if (false == $is_back) {
  720. $filepath = str_replace(DIRECTORY_SEPARATOR, $replacement, $filepath);
  721. $filepath = preg_replace('#\/#', $replacement, $filepath);
  722. } else {
  723. $filepath = preg_replace('#'.$replacement.'#', '/', $filepath);
  724. $filepath = str_replace('//', ':/', $filepath);
  725. }
  726. return $filepath;
  727. }
  728. }
  729. if (!function_exists('get_seo_pseudo_list'))
  730. {
  731. /**
  732. * URL模式下拉列表
  733. */
  734. function get_seo_pseudo_list($key = '')
  735. {
  736. $data = array(
  737. 1 => '动态URL',
  738. 3 => '伪静态化',
  739. 2 => '静态页面',
  740. );
  741. return isset($data[$key]) ? $data[$key] : $data;
  742. }
  743. }
  744. if (!function_exists('get_chown_pathinfo'))
  745. {
  746. /**
  747. * 对指定的操作系统获取目录的所有组与所有者
  748. * @param string $path 目录路径
  749. * @return array
  750. */
  751. function get_chown_pathinfo($path = '')
  752. {
  753. $pathinfo = true;
  754. if (function_exists('stat')) {
  755. /*指定操作系统,在列表内才进行后续获取*/
  756. $isValidate = false;
  757. $os = PHP_OS;
  758. $osList = array('linux','unix');
  759. foreach ($osList as $key => $val) {
  760. if (stristr($os, $val)) {
  761. $isValidate = true;
  762. continue;
  763. }
  764. }
  765. /*--end*/
  766. if (true === $isValidate) {
  767. $path = !empty($path) ? $path : ROOT_PATH;
  768. $stat = stat($path);
  769. if (function_exists('posix_getpwuid')) {
  770. $pathinfo = posix_getpwuid($stat['uid']);
  771. } else {
  772. $pathinfo = array(
  773. 'name' => (0 == $stat['uid']) ? 'root' : '',
  774. 'uid' => $stat['uid'],
  775. 'gid' => $stat['gid'],
  776. );
  777. }
  778. }
  779. }
  780. return $pathinfo;
  781. }
  782. }
  783. if (!function_exists('menu_select'))
  784. {
  785. /*组装成层级下拉列表框*/
  786. function menu_select($selected = 0)
  787. {
  788. $select_html = '';
  789. $menuArr = getAllMenu();
  790. if (!empty($menuArr)) {
  791. foreach ($menuArr AS $key => $val)
  792. {
  793. $select_html .= '<option value="' . $val['id'] . '" data-grade="' . $val['grade'] . '"';
  794. $select_html .= ($selected == $val['id']) ? ' selected="ture"' : '';
  795. if (!empty($val['child'])) {
  796. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  797. }
  798. $select_html .= '>';
  799. if ($val['grade'] > 0)
  800. {
  801. $select_html .= str_repeat('&nbsp;', $val['grade'] * 4);
  802. }
  803. $name = !empty($val['name']) ? $val['name'] : '默认';
  804. $select_html .= htmlspecialchars(addslashes($name)) . '</option>';
  805. if (empty($val['child'])) {
  806. continue;
  807. }
  808. foreach ($menuArr[$key]['child'] as $key2 => $val2) {
  809. $select_html .= '<option value="' . $val2['id'] . '" data-grade="' . $val2['grade'] . '"';
  810. $select_html .= ($selected == $val2['id']) ? ' selected="ture"' : '';
  811. if (!empty($val2['child'])) {
  812. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  813. }
  814. $select_html .= '>';
  815. if ($val2['grade'] > 0)
  816. {
  817. $select_html .= str_repeat('&nbsp;', $val2['grade'] * 4);
  818. }
  819. $select_html .= htmlspecialchars(addslashes($val2['name'])) . '</option>';
  820. if (empty($val2['child'])) {
  821. continue;
  822. }
  823. foreach ($menuArr[$key]['child'][$key2]['child'] as $key3 => $val3) {
  824. $select_html .= '<option value="' . $val3['id'] . '" data-grade="' . $val3['grade'] . '"';
  825. $select_html .= ($selected == $val3['id']) ? ' selected="ture"' : '';
  826. if (!empty($val3['child'])) {
  827. $select_html .= ' disabled="true" style="background-color:#f5f5f5;"';
  828. }
  829. $select_html .= '>';
  830. if ($val3['grade'] > 0)
  831. {
  832. $select_html .= str_repeat('&nbsp;', $val3['grade'] * 4);
  833. }
  834. $select_html .= htmlspecialchars(addslashes($val3['name'])) . '</option>';
  835. }
  836. }
  837. }
  838. }
  839. return $select_html;
  840. }
  841. }
  842. if (!function_exists('schemaTable'))
  843. {
  844. /**
  845. * 重新生成数据表缓存字段文件
  846. */
  847. function schemaTable($name)
  848. {
  849. $table = $name;
  850. $prefix = \think\Config::get('database.prefix');
  851. if (!preg_match('/^'.$prefix.'/i', $name)) {
  852. $table = $prefix.$name;
  853. }
  854. /*调用命令行的指令*/
  855. \think\Console::call('optimize:schema', ['--table', $table]);
  856. /*--end*/
  857. }
  858. }
  859. if (!function_exists('testWriteAble'))
  860. {
  861. /**
  862. * 测试目录路径是否有写入权限
  863. * @param string $d 目录路劲
  864. * @return boolean
  865. */
  866. function testWriteAble($filepath)
  867. {
  868. $tfile = '_eyout.txt';
  869. $fp = @fopen($filepath.$tfile,'w');
  870. if(!$fp) {
  871. return false;
  872. }
  873. else {
  874. fclose($fp);
  875. $rs = @unlink($filepath.$tfile);
  876. return true;
  877. }
  878. }
  879. }
  880. if (!function_exists('getArchivesSortUrl'))
  881. {
  882. /**
  883. * 在文档列表拼接排序URL
  884. * @param string $orderby 排序字段
  885. * @param string $orderwayDefault 默认为空时升序
  886. * @return string
  887. */
  888. function getArchivesSortUrl($orderby = '', $orderwayDefault = '')
  889. {
  890. $parseArr = parse_url(request()->url());
  891. $query_str = '';
  892. if (!empty($parseArr['query'])) {
  893. parse_str($parseArr['query'], $output);
  894. $output['orderby'] = $orderby;
  895. $orderway = input('param.orderway/s', $orderwayDefault);
  896. $orderway = !empty($orderway) ? $orderway : 'desc';
  897. if ('desc' == $orderway) {
  898. $orderway = 'asc';
  899. } else {
  900. $orderway = 'desc';
  901. // 再次点击恢复到默认排序
  902. // if ('arcrank' == $orderby) {
  903. // $output['orderby'] = '';
  904. // }
  905. }
  906. $output['orderway'] = $orderway;
  907. $query_str = http_build_query($output);
  908. }
  909. $url = $parseArr['path'];
  910. !empty($query_str) && $url .= '?'.$query_str;
  911. return $url;
  912. }
  913. }
  914. if (!function_exists('showArchivesFlagStr'))
  915. {
  916. /**
  917. * 在文档列表显示文档属性标识
  918. * @param array $archivesInfo 文档信息
  919. * @return string
  920. */
  921. function showArchivesFlagStr($archivesInfo = [])
  922. {
  923. $arr = [];
  924. if (!empty($archivesInfo['is_head'])) {
  925. $arr['is_head'] = [
  926. 'small_name' => '头条',
  927. ];
  928. }
  929. if (!empty($archivesInfo['is_recom'])) {
  930. $arr['is_recom'] = [
  931. 'small_name' => '推荐',
  932. ];
  933. }
  934. if (!empty($archivesInfo['is_special'])) {
  935. $arr['is_special'] = [
  936. 'small_name' => '特荐',
  937. ];
  938. }
  939. if (!empty($archivesInfo['is_b'])) {
  940. $arr['is_b'] = [
  941. 'small_name' => '加粗',
  942. ];
  943. }
  944. if (!empty($archivesInfo['is_litpic'])) {
  945. $arr['is_litpic'] = [
  946. 'small_name' => '图片',
  947. ];
  948. }
  949. if (!empty($archivesInfo['is_jump'])) {
  950. $arr['is_jump'] = [
  951. 'small_name' => '跳转',
  952. ];
  953. }
  954. return $arr;
  955. }
  956. }
  957. if (!function_exists('checkPasswordLevel'))
  958. {
  959. /**
  960. * 检查密码复杂度
  961. * @param string $strPassword 密码
  962. * @return string
  963. */
  964. function checkPasswordLevel($strPassword = '')
  965. {
  966. $result = 0;
  967. $pwdlen = strlen($strPassword);
  968. if ( $pwdlen == 0) {
  969. $result += 0;
  970. }
  971. else if ( $pwdlen<8 && $pwdlen >0 ) {
  972. $result += 5;
  973. }
  974. else if ($pwdlen>10) {
  975. $result += 25;
  976. }
  977. else {
  978. $result += 10;
  979. }
  980. //check letter
  981. $bHave = false;
  982. $bAll = false;
  983. $capital = preg_match('/[A-Z]{1}/', $strPassword);//找大写字母
  984. $small = preg_match('/[a-z]{1}/', $strPassword);//找小写字母
  985. if ( empty($capital) && empty($small) )
  986. {
  987. $result += 0; //没有字母
  988. $bHave = false;
  989. }
  990. else if ( !empty($capital) && !empty($small) )
  991. {
  992. $result += 20;
  993. $bAll = true;
  994. }
  995. else
  996. {
  997. $result += 10;
  998. $bAll = true;
  999. }
  1000. //检查数字
  1001. $bDigi = false;
  1002. $digitalLen = 0;
  1003. for ( $i=0; $i<$pwdlen; $i++)
  1004. {
  1005. if ( $strPassword[$i] <= '9' && $strPassword[$i] >= '0' )
  1006. {
  1007. $bDigi = true;
  1008. $digitalLen += 1;
  1009. }
  1010. }
  1011. if ( $digitalLen==0 )//没有数字
  1012. {
  1013. $result += 0;
  1014. $bDigi = false;
  1015. }
  1016. else if ($digitalLen>2)//2个数字以上
  1017. {
  1018. $result += 20 ;
  1019. $bDigi = true;
  1020. }
  1021. else
  1022. {
  1023. $result += 10;
  1024. $bDigi = true;
  1025. }
  1026. //检查非单词字符
  1027. $bOther = false;
  1028. $otherLen = 0;
  1029. for ($i=0; $i<$pwdlen; $i++)
  1030. {
  1031. if ( ($strPassword[$i]>='0' && $strPassword[$i]<='9') ||
  1032. ($strPassword[$i]>='A' && $strPassword[$i]<='Z') ||
  1033. ($strPassword[$i]>='a' && $strPassword[$i]<='z')) {
  1034. continue;
  1035. }
  1036. $otherLen += 1;
  1037. $bOther = true;
  1038. }
  1039. if ( $otherLen == 0 )//没有非单词字符
  1040. {
  1041. $result += 0;
  1042. $bOther = false;
  1043. }
  1044. else if ( $otherLen >1)//1个以上非单词字符
  1045. {
  1046. $result +=25 ;
  1047. $bOther = true;
  1048. }
  1049. else
  1050. {
  1051. $result +=10;
  1052. $bOther = true;
  1053. }
  1054. //检查额外奖励
  1055. if ( $bAll && $bDigi && $bOther) {
  1056. $result += 5;
  1057. }
  1058. else if ($bHave && $bDigi && $bOther) {
  1059. $result += 3;
  1060. }
  1061. else if ($bHave && $bDigi ) {
  1062. $result += 2;
  1063. }
  1064. $level = 0;
  1065. //根据分数来算密码强度的等级
  1066. if ( $result >=80 )
  1067. $level = 7;
  1068. else if ( $result>=70)
  1069. $level = 6;
  1070. else if ( $result>=60)
  1071. $level = 5;
  1072. else if ( $result>=50)
  1073. $level = 4;
  1074. else if ( $result>=40)
  1075. $level = 3;
  1076. else if ( $result>20)
  1077. $level = 2;
  1078. else if ( $result>0)
  1079. $level = 1;
  1080. else
  1081. $level = 0;
  1082. return $level;
  1083. }
  1084. }
  1085. if (!function_exists('getPasswordLevelTitle'))
  1086. {
  1087. /**
  1088. * 获取密码复杂度名称
  1089. * @param string $level 复杂程度
  1090. * @return string
  1091. */
  1092. function getPasswordLevelTitle($level = 0)
  1093. {
  1094. $title = '弱';
  1095. //根据分数来算密码强度的等级
  1096. if ( $level == 7 ) {
  1097. $title = '极佳';
  1098. }
  1099. else if ( $level == 6) {
  1100. $title = '非常强';
  1101. }
  1102. else if ( $level == 5) {
  1103. $title = '强';
  1104. }
  1105. else if ( $level == 4) {
  1106. $title = '较强';
  1107. }
  1108. else if ( $level == 3) {
  1109. $title = '一般';
  1110. }
  1111. else if ( $level == 2) {
  1112. $title = '较弱';
  1113. }
  1114. else if ( $level == 1) {
  1115. $title = '非常弱';
  1116. }
  1117. else {
  1118. $title = '弱';
  1119. }
  1120. return $title;
  1121. }
  1122. }
  1123. if (!function_exists('downloadExcel')) {
  1124. /**
  1125. * 下载excel
  1126. * @param $strTable 表格内容
  1127. * @param $filename 文件名
  1128. */
  1129. function downloadExcel($strTable, $filename)
  1130. {
  1131. ob_end_clean();
  1132. header("Content-type: application/vnd.ms-excel");
  1133. header("Content-Type: application/force-download");
  1134. header("Content-Disposition: attachment; filename=" . $filename . "_" . date('Y-m-d') . ".xls");
  1135. header('Expires:0');
  1136. header('Pragma:public');
  1137. echo '<html><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />' . $strTable . '</html>';
  1138. }
  1139. }