PageRenderTime 64ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/source/function/cache/cache_setting.php

https://github.com/kuaileshike/upload
PHP | 991 lines | 975 code | 10 blank | 6 comment | 31 complexity | 245c90843db731759b69f3e1a2a93091 MD5 | raw file
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: cache_setting.php 30309 2012-05-21 03:47:30Z zhengqingpeng $
  7. */
  8. if(!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. function build_cache_setting() {
  12. global $_G;
  13. $skipkeys = array('posttableids', 'mastermobile', 'masterqq', 'masteremail', 'closedreason',
  14. 'creditsnotify', 'backupdir', 'custombackup', 'jswizard', 'maxonlines', 'modreasons', 'newsletter',
  15. 'postno', 'postnocustom', 'customauthorinfo', 'domainwhitelist', 'ipregctrl',
  16. 'ipverifywhite', 'fastsmiley', 'defaultdoing',
  17. );
  18. $serialized = array('reginput', 'memory', 'search', 'creditspolicy', 'ftp', 'secqaa', 'ec_credit', 'qihoo', 'spacedata',
  19. 'infosidestatus', 'uc', 'indexhot', 'relatedtag', 'sitemessage', 'uchome', 'heatthread', 'recommendthread',
  20. 'disallowfloat', 'allowviewuserthread', 'advtype', 'click', 'card', 'rewritestatus', 'rewriterule', 'privacy', 'focus',
  21. 'forumkeys', 'article_tags', 'verify', 'seotitle', 'seodescription', 'seokeywords', 'domain', 'ranklist', 'my_search_data',
  22. 'seccodedata', 'inviteconfig', 'advexpiration', 'allowpostcomment', /*(IN_MOBILE)*/ 'mobile', 'connect', 'upgrade', 'patch', 'strongpw',
  23. 'posttable_info', 'threadtable_info', 'profilegroup'
  24. );
  25. $data = array();
  26. foreach(C::t('common_setting')->fetch_all_not_key($skipkeys) as $setting) {
  27. if($setting['skey'] == 'extcredits') {
  28. if(is_array($setting['svalue'] = dunserialize($setting['svalue']))) {
  29. foreach($setting['svalue'] as $key => $value) {
  30. if($value['available']) {
  31. unset($setting['svalue'][$key]['available']);
  32. } else {
  33. unset($setting['svalue'][$key]);
  34. }
  35. }
  36. }
  37. } elseif($setting['skey'] == 'creditsformula') {
  38. if(!checkformulacredits($setting['svalue'])) {
  39. $setting['svalue'] = '$member[\'extcredits1\']';
  40. } else {
  41. $setting['svalue'] = preg_replace("/(friends|doings|blogs|albums|polls|sharings|digestposts|posts|threads|oltime|extcredits[1-8])/", "\$member['\\1']", $setting['svalue']);
  42. }
  43. } elseif($setting['skey'] == 'maxsmilies') {
  44. $setting['svalue'] = $setting['svalue'] <= 0 ? -1 : $setting['svalue'];
  45. } elseif($setting['skey'] == 'threadsticky') {
  46. $setting['svalue'] = explode(',', $setting['svalue']);
  47. } elseif($setting['skey'] == 'attachdir') {
  48. $setting['svalue'] = preg_replace("/\.asp|\\0/i", '0', $setting['svalue']);
  49. $setting['svalue'] = str_replace('\\', '/', substr($setting['svalue'], 0, 2) == './' ? DISCUZ_ROOT.$setting['svalue'] : $setting['svalue']);
  50. $setting['svalue'] .= substr($setting['svalue'], -1, 1) != '/' ? '/' : '';
  51. } elseif($setting['skey'] == 'attachurl') {
  52. $setting['svalue'] .= substr($setting['svalue'], -1, 1) != '/' ? '/' : '';
  53. } elseif($setting['skey'] == 'onlinehold') {
  54. $setting['svalue'] = $setting['svalue'] * 60;
  55. } elseif(in_array($setting['skey'], $serialized)) {
  56. $setting['svalue'] = @dunserialize($setting['svalue'], $setting['skey']);
  57. if($setting['skey'] == 'search') {
  58. foreach($setting['svalue'] as $key => $val) {
  59. foreach($val as $k => $v) {
  60. $setting['svalue'][$key][$k] = max(0, intval($v));
  61. }
  62. }
  63. } elseif($setting['skey'] == 'ftp') {
  64. $setting['svalue']['attachurl'] .= substr($setting['svalue']['attachurl'], -1, 1) != '/' ? '/' : '';
  65. } elseif($setting['skey'] == 'inviteconfig') {
  66. $setting['svalue']['invitecodeprompt'] = stripslashes($setting['svalue']['invitecodeprompt']);
  67. } elseif($setting['skey'] == 'profilegroup') {
  68. $profile_settings = C::t('common_member_profile_setting')->fetch_all_by_available(1);
  69. foreach($setting['svalue'] as $key => $val) {
  70. $temp = array();
  71. foreach($profile_settings as $pval) {
  72. if(in_array($pval['fieldid'], $val['field'])) {
  73. $temp[$pval['fieldid']] = $pval['fieldid'];
  74. }
  75. }
  76. foreach($val['field'] as $fieldid) {
  77. if(!in_array($fieldid, $temp)) {
  78. $temp[$fieldid] = $fieldid;
  79. }
  80. }
  81. $setting['svalue'][$key]['field'] = $temp;
  82. }
  83. C::t('common_setting')->update('profilegroup', $setting['svalue']);
  84. }
  85. }
  86. $_G['setting'][$setting['skey']] = $data[$setting['skey']] = $setting['svalue'];
  87. }
  88. $usergroup = C::t('common_usergroup')->fetch_by_credits($data['initcredits'], '');
  89. $data['newusergroupid'] = $usergroup['groupid'];
  90. if($data['srchhotkeywords']) {
  91. $data['srchhotkeywords'] = explode("\n", $data['srchhotkeywords']);
  92. }
  93. if($data['search']) {
  94. $searchstatus = 0;
  95. foreach($data['search'] as $item) {
  96. if($item['status']) {
  97. $searchstatus = 1;
  98. break;
  99. }
  100. }
  101. if(!$searchstatus) {
  102. $data['search'] = array();
  103. }
  104. }
  105. $data['creditspolicy'] = array_merge($data['creditspolicy'], get_cachedata_setting_creditspolicy());
  106. if($data['heatthread']['iconlevels']) {
  107. $data['heatthread']['iconlevels'] = explode(',', $data['heatthread']['iconlevels']);
  108. arsort($data['heatthread']['iconlevels']);
  109. } else {
  110. $data['heatthread']['iconlevels'] = array();
  111. }
  112. if($data['verify']) {
  113. foreach($data['verify'] as $key => $value) {
  114. if($value['available']) {
  115. if(!empty($value['unverifyicon'])) {
  116. $icourl = parse_url($value['unverifyicon']);
  117. if(!$icourl['host'] && !file_exists($value['unverifyicon'])) {
  118. $data['verify'][$key]['unverifyicon'] = $data['attachurl'].'common/'.$value['unverifyicon'];
  119. }
  120. }
  121. if(!empty($value['icon'])) {
  122. $icourl = parse_url($value['icon']);
  123. if(!$icourl['host'] && !file_exists($value['icon'])) {
  124. $data['verify'][$key]['icon'] = $data['attachurl'].'common/'.$value['icon'];
  125. }
  126. }
  127. }
  128. }
  129. }
  130. if($data['recommendthread']['status']) {
  131. if($data['recommendthread']['iconlevels']) {
  132. $data['recommendthread']['iconlevels'] = explode(',', $data['recommendthread']['iconlevels']);
  133. arsort($data['recommendthread']['iconlevels']);
  134. } else {
  135. $data['recommendthread']['iconlevels'] = array();
  136. }
  137. } else {
  138. $data['recommendthread'] = array('allow' => 0);
  139. }
  140. if($data['commentnumber'] && !$data['allowpostcomment']) {
  141. $data['commentnumber'] = 0;
  142. }
  143. if(!empty($data['ftp'])) {
  144. if(!empty($data['ftp']['allowedexts'])) {
  145. $data['ftp']['allowedexts'] = str_replace(array("\r\n", "\r"), array("\n", "\n"), $data['ftp']['allowedexts']);
  146. $data['ftp']['allowedexts'] = explode("\n", strtolower($data['ftp']['allowedexts']));
  147. array_walk($data['ftp']['allowedexts'], 'trim');
  148. }
  149. if(!empty($data['ftp']['disallowedexts'])) {
  150. $data['ftp']['disallowedexts'] = str_replace(array("\r\n", "\r"), array("\n", "\n"), $data['ftp']['disallowedexts']);
  151. $data['ftp']['disallowedexts'] = explode("\n", strtolower($data['ftp']['disallowedexts']));
  152. array_walk($data['ftp']['disallowedexts'], 'trim');
  153. }
  154. $data['ftp']['connid'] = 0;
  155. }
  156. if(!empty($data['forumkeys'])) {
  157. $data['forumfids'] = array_flip($data['forumkeys']);
  158. } else {
  159. $data['forumfids'] = array();
  160. }
  161. $data['commentitem'] = explode("\t", $data['commentitem']);
  162. $commentitem = array();
  163. foreach($data['commentitem'] as $k => $v) {
  164. $tmp = explode(chr(0).chr(0).chr(0), $v);
  165. if(count($tmp) > 1) {
  166. $commentitem[$tmp[0]] = $tmp[1];
  167. } else {
  168. $commentitem[$k] = $v;
  169. }
  170. }
  171. $data['commentitem'] = $commentitem;
  172. if($data['allowviewuserthread']['allow']) {
  173. $data['allowviewuserthread'] = is_array($data['allowviewuserthread']['fids']) && $data['allowviewuserthread']['fids'] && !in_array('', $data['allowviewuserthread']['fids']) ? dimplode($data['allowviewuserthread']['fids']) : '';
  174. } else {
  175. $data['allowviewuserthread'] = -1;
  176. }
  177. include_once DISCUZ_ROOT.'./source/discuz_version.php';
  178. $_G['setting']['version'] = $data['version'] = DISCUZ_VERSION;
  179. $data['sitemessage']['time'] = !empty($data['sitemessage']['time']) ? $data['sitemessage']['time'] * 1000 : 0;
  180. foreach (array('register', 'login', 'newthread', 'reply') as $type) {
  181. $data['sitemessage'][$type] = !empty($data['sitemessage'][$type]) ? explode("\n", $data['sitemessage'][$type]) : array();
  182. }
  183. $data['cachethreadon'] = C::t('forum_forum')->fetch_threadcacheon_num() ? 1 : 0;
  184. $data['disallowfloat'] = is_array($data['disallowfloat']) ? implode('|', $data['disallowfloat']) : '';
  185. if(!$data['imagelib']) unset($data['imageimpath']);
  186. if(is_array($data['relatedtag']['order'])) {
  187. asort($data['relatedtag']['order']);
  188. $relatedtag = array();
  189. foreach($data['relatedtag']['order'] AS $k => $v) {
  190. $relatedtag['status'][$k] = $data['relatedtag']['status'][$k];
  191. $relatedtag['name'][$k] = $data['relatedtag']['name'][$k];
  192. $relatedtag['limit'][$k] = $data['relatedtag']['limit'][$k];
  193. $relatedtag['template'][$k] = $data['relatedtag']['template'][$k];
  194. }
  195. $data['relatedtag'] = $relatedtag;
  196. foreach((array)$data['relatedtag']['status'] AS $appid => $status) {
  197. if(!$status) {
  198. unset($data['relatedtag']['limit'][$appid]);
  199. }
  200. }
  201. unset($data['relatedtag']['status'], $data['relatedtag']['order'], $relatedtag);
  202. }
  203. $data['domain']['defaultindex'] = isset($data['defaultindex']) && $data['defaultindex'] != '#' ? $data['defaultindex'] : '';
  204. $data['domain']['holddomain'] = isset($data['holddomain']) ? $data['holddomain'] : '';
  205. $data['domain']['list'] = array();
  206. foreach(C::t('common_domain')->fetch_all_by_idtype(array('subarea', 'forum', 'topic', 'channel')) as $value) {
  207. $data['domain']['list'][$value['domain'].'.'.$value['domainroot']] = array('id' => $value['id'], 'idtype' => $value['idtype']);
  208. }
  209. writetocache('domain', getcachevars(array('domain' => $data['domain'])));
  210. $data['seccodedata'] = is_array($data['seccodedata']) ? $data['seccodedata'] : array();
  211. if($data['seccodedata']['type'] == 2) {
  212. if(extension_loaded('ming')) {
  213. unset($data['seccodedata']['background'], $data['seccodedata']['adulterate'],
  214. $data['seccodedata']['ttf'], $data['seccodedata']['angle'],
  215. $data['seccodedata']['color'], $data['seccodedata']['size'],
  216. $data['seccodedata']['animator']);
  217. } else {
  218. $data['seccodedata']['animator'] = 0;
  219. }
  220. } elseif($data['seccodedata']['type'] == 99) {
  221. $data['seccodedata']['width'] = 32;
  222. $data['seccodedata']['height'] = 24;
  223. }
  224. $data['watermarktype'] = !empty($data['watermarktype']) ? dunserialize($data['watermarktype']) : array();
  225. $data['watermarktext'] = !empty($data['watermarktext']) ? dunserialize($data['watermarktext']) : array();
  226. foreach($data['watermarktype'] as $k => $v) {
  227. if($data['watermarktype'][$k] == 'text' && $data['watermarktext']['text'][$k]) {
  228. if($data['watermarktext']['text'][$k] && strtoupper(CHARSET) != 'UTF-8') {
  229. $data['watermarktext']['text'][$k] = diconv($data['watermarktext']['text'][$k], CHARSET, 'UTF-8', true);
  230. }
  231. $data['watermarktext']['text'][$k] = bin2hex($data['watermarktext']['text'][$k]);
  232. if(file_exists('static/image/seccode/font/en/'.$data['watermarktext']['fontpath'][$k])) {
  233. $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/en/'.$data['watermarktext']['fontpath'][$k];
  234. } elseif(file_exists('static/image/seccode/font/ch/'.$data['watermarktext']['fontpath'][$k])) {
  235. $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/ch/'.$data['watermarktext']['fontpath'][$k];
  236. } else {
  237. $data['watermarktext']['fontpath'][$k] = 'static/image/seccode/font/'.$data['watermarktext']['fontpath'][$k];
  238. }
  239. $data['watermarktext']['color'][$k] = preg_replace('/#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/e', "hexdec('\\1').','.hexdec('\\2').','.hexdec('\\3')", $data['watermarktext']['color'][$k]);
  240. $data['watermarktext']['shadowcolor'][$k] = preg_replace('/#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})/e', "hexdec('\\1').','.hexdec('\\2').','.hexdec('\\3')", $data['watermarktext']['shadowcolor'][$k]);
  241. } else {
  242. $data['watermarktext']['text'][$k] = '';
  243. $data['watermarktext']['fontpath'][$k] = '';
  244. $data['watermarktext']['color'][$k] = '';
  245. $data['watermarktext']['shadowcolor'][$k] = '';
  246. }
  247. }
  248. $data['styles'] = array();
  249. foreach(C::t('common_style')->fetch_all_data(false, 1) as $style) {
  250. $data['styles'][$style['styleid']] = dhtmlspecialchars($style['name']);
  251. }
  252. $exchcredits = array();
  253. $allowexchangein = $allowexchangeout = FALSE;
  254. foreach((array)$data['extcredits'] as $id => $credit) {
  255. $data['extcredits'][$id]['img'] = $credit['img'] ? '<img style="vertical-align:middle" src="'.$credit['img'].'" />' : '';
  256. if(!empty($credit['ratio'])) {
  257. $exchcredits[$id] = $credit;
  258. $credit['allowexchangein'] && $allowexchangein = TRUE;
  259. $credit['allowexchangeout'] && $allowexchangeout = TRUE;
  260. }
  261. $data['creditnotice'] && $data['creditnames'][] = str_replace("'", "\'", dhtmlspecialchars($id.'|'.$credit['title'].'|'.$credit['unit']));
  262. }
  263. $data['creditnames'] = $data['creditnotice'] ? @implode(',', $data['creditnames']) : '';
  264. $creditstranssi = explode(',', $data['creditstrans']);
  265. $data['creditstrans'] = $creditstranssi[0];
  266. unset($creditstranssi[0]);
  267. $data['creditstransextra'] = $creditstranssi;
  268. for($i = 1;$i < 11;$i++) {
  269. $data['creditstransextra'][$i] = $data['creditstrans'] ? (!$data['creditstransextra'][$i] ? $data['creditstrans'] : $data['creditstransextra'][$i]) : 0;
  270. }
  271. $data['exchangestatus'] = $allowexchangein && $allowexchangeout;
  272. $data['transferstatus'] = isset($data['extcredits'][$data['creditstrans']]);
  273. list($data['zoomstatus'], $data['imagemaxwidth']) = explode("\t", $data['zoomstatus']);
  274. $data['imagemaxwidth'] = intval($data['imagemaxwidth']);
  275. require_once DISCUZ_ROOT.'./config/config_ucenter.php';
  276. $data['ucenterurl'] = UC_API;
  277. foreach(C::t('common_magic')->fetch_all_data(1) as $magic) {
  278. $data['magics'][$magic['identifier']] = $magic['name'];
  279. }
  280. $data['tradeopen'] = C::t('common_usergroup_field')->count_by_field('allowposttrade', 1) ? 1 : 0;
  281. $data['medalstatus'] = intval(C::t('forum_medal')->count_by_available());
  282. $focus = array();
  283. if($data['focus']['data']) {
  284. foreach($data['focus']['data'] as $k => $v) {
  285. if($v['available'] && $v['position']) {
  286. foreach($v['position'] as $position) {
  287. $focus[$position][$k] = $k;
  288. }
  289. }
  290. }
  291. }
  292. $data['focus'] = $focus;
  293. list($data['plugins'], $data['pluginlinks'], $data['hookscript'], $data['hookscriptmobile'], $data['threadplugins'], $data['specialicon']) = get_cachedata_setting_plugin();
  294. if(empty($data['defaultindex'])) $data['defaultindex'] = array();
  295. list($data['navs'], $data['subnavs'], $data['menunavs'], $data['navmns'], $data['navmn'], $data['navdms'], $data['navlogos']) = get_cachedata_mainnav();
  296. $data['footernavs'] = get_cachedata_footernav();
  297. $data['spacenavs'] = get_cachedata_spacenavs();
  298. $data['mynavs'] = get_cachedata_mynavs();
  299. $data['topnavs'] = get_cachedata_topnav();
  300. require_once DISCUZ_ROOT.'./uc_client/client.php';
  301. $ucapparray = uc_app_ls();
  302. $data['allowsynlogin'] = isset($ucapparray[UC_APPID]['synlogin']) ? $ucapparray[UC_APPID]['synlogin'] : 1;
  303. $appnamearray = array('UCHOME','XSPACE','DISCUZ','SUPESITE','SUPEV','ECSHOP','ECMALL','OTHER');
  304. $data['ucapp'] = $data['ucappopen'] = array();
  305. $data['uchomeurl'] = '';
  306. $data['discuzurl'] = $_G['siteurl'];
  307. $appsynlogins = 0;
  308. foreach($ucapparray as $apparray) {
  309. if($apparray['appid'] != UC_APPID) {
  310. if(!empty($apparray['synlogin'])) {
  311. $appsynlogins = 1;
  312. }
  313. if($data['uc']['navlist'][$apparray['appid']] && $data['uc']['navopen']) {
  314. $data['ucapp'][$apparray['appid']]['name'] = $apparray['name'];
  315. $data['ucapp'][$apparray['appid']]['url'] = $apparray['url'];
  316. }
  317. } else {
  318. $data['discuzurl'] = $apparray['url'];
  319. }
  320. if(!empty($apparray['viewprourl'])) {
  321. $data['ucapp'][$apparray['appid']]['viewprourl'] = $apparray['url'].$apparray['viewprourl'];
  322. }
  323. foreach($appnamearray as $name) {
  324. if($apparray['type'] == $name && $apparray['appid'] != UC_APPID) {
  325. $data['ucappopen'][$name] = 1;
  326. if($name == 'UCHOME') {
  327. $data['uchomeurl'] = $apparray['url'];
  328. } elseif($name == 'XSPACE') {
  329. $data['xspaceurl'] = $apparray['url'];
  330. }
  331. }
  332. }
  333. }
  334. $data['allowsynlogin'] = $data['allowsynlogin'] && $appsynlogins ? 1 : 0;
  335. $data['homeshow'] = $data['uchomeurl'] && $data['uchome']['homeshow'] ? $data['uchome']['homeshow'] : '0';
  336. unset($data['allowthreadplugin']);
  337. if($data['jspath'] == 'data/cache/') {
  338. writetojscache();
  339. } elseif(!$data['jspath']) {
  340. $data['jspath'] = 'static/js/';
  341. }
  342. if($data['cacheindexlife']) {
  343. $cachedir = DISCUZ_ROOT.'./'.$data['cachethreaddir'];
  344. $tidmd5 = substr(md5(0), 3);
  345. @unlink($cachedir.'/'.$tidmd5[0].'/'.$tidmd5[1].'/'.$tidmd5[2].'/0.htm');
  346. }
  347. $reginputbwords = array('username', 'password', 'password2', 'email');
  348. if(in_array($data['reginput']['username'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['username'])) {
  349. $data['reginput']['username'] = random(6);
  350. }
  351. if(in_array($data['reginput']['password'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['password'])) {
  352. $data['reginput']['password'] = random(6);
  353. }
  354. if(in_array($data['reginput']['password2'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['password2'])) {
  355. $data['reginput']['password2'] = random(6);
  356. }
  357. if(in_array($data['reginput']['email'], $reginputbwords) || !preg_match('/^[A-z]\w+?$/', $data['reginput']['email'])) {
  358. $data['reginput']['email'] = random(6);
  359. }
  360. $defaultcurhost = empty($_G['setting']['domain']['app']['default']) ? '{CURHOST}' : $_G['setting']['domain']['app']['default'];
  361. $output = array('str'=>array(), 'preg' => array()); //str为二级域名的查找和替换,preg为rewrite和默认域名的查找和替换
  362. $_G['domain'] = array();
  363. if(is_array($_G['setting']['domain']['app'])) {
  364. $apps = $_G['setting']['domain']['app'];
  365. $repflag = $apps['portal'] || $apps['forum'] || $apps['group'] || $apps['home'] || $apps['default'];
  366. foreach($apps as $app => $domain) {
  367. if(in_array($app, array('default', 'mobile'))) {
  368. continue;
  369. }
  370. $appphp = "{$app}.php";
  371. if(!$domain) {
  372. $domain = $defaultcurhost;
  373. }
  374. if($domain != '{CURHOST}') {
  375. $domain = 'http://'.$domain.$_G['siteport'].'/';
  376. }
  377. if($repflag) {
  378. $output['str']['search'][$app] = "<a href=\"{$app}.php";
  379. $output['str']['replace'][$app] = '<a href="'.$domain.$appphp;
  380. $_G['domain']['pregxprw'][$app] = '<a href\="('.preg_quote($domain, '/').')'.$appphp;
  381. } else {
  382. $_G['domain']['pregxprw'][$app] = '<a href\="()'.$appphp;
  383. }
  384. }
  385. }
  386. if($_G['setting']['rewritestatus'] || $output['str']['search']) {
  387. if($_G['setting']['rewritestatus']) {
  388. require_once libfile('function/admincp');
  389. $output['preg'] = rewritedata(0);
  390. }
  391. if($output['preg']) {
  392. foreach($data['footernavs'] as $id => $nav) {
  393. $data['footernavs'][$id]['code'] = preg_replace($output['preg']['search'], $output['preg']['replace'], $nav['code']);
  394. }
  395. foreach($data['spacenavs'] as $id => $nav) {
  396. $data['spacenavs'][$id]['code'] = preg_replace($output['preg']['search'], $output['preg']['replace'], $nav['code']);
  397. }
  398. foreach($data['mynavs'] as $id => $nav) {
  399. $data['mynavs'][$id]['code'] = preg_replace($output['preg']['search'], $output['preg']['replace'], $nav['code']);
  400. }
  401. foreach($data['topnavs'] as $id => $nav) {
  402. $data['topnavs'][$id]['code'] = preg_replace($output['preg']['search'], $output['preg']['replace'], $nav['code']);
  403. }
  404. foreach($data['plugins']['jsmenu'] as $key => $nav) {
  405. $data['plugins']['jsmenu'][$key]['url'] = preg_replace($output['preg']['search'], $output['preg']['replace'], $nav['url']);
  406. }
  407. }
  408. }
  409. $data['output'] = $output;
  410. $data['connect'] = in_array('qqconnect', $data['plugins']['available']) ? $data['connect'] : array();
  411. savecache('setting', $data);
  412. $_G['setting'] = $data;
  413. }
  414. function get_cachedata_setting_creditspolicy() {
  415. $data = array();
  416. foreach(C::t('common_credit_rule')->fetch_all_by_action(array('promotion_visit', 'promotion_register')) as $creditrule) {
  417. $ruleexist = false;
  418. for($i = 1; $i <= 8; $i++) {
  419. if($creditrule['extcredits'.$i]) {
  420. $ruleexist = true;
  421. }
  422. }
  423. $data[$creditrule['action']] = $ruleexist;
  424. }
  425. return $data;
  426. }
  427. function get_cachedata_setting_plugin($method = '') {
  428. global $_G;
  429. $hookfuncs = array('common', 'discuzcode', 'deletemember', 'deletethread', 'deletepost', 'avatar', 'savebanlog', 'cacheuserstats', 'undeletethreads', 'recyclebinpostundelete', 'threadpubsave');
  430. $data = $adminmenu = array();
  431. $data['plugins'] = $data['pluginlinks'] = $data['hookscript'] = $data['hookscriptmobile'] = $data['threadplugins'] = $data['specialicon'] = array();
  432. $data['plugins']['func'] = $data['plugins']['available'] = array();
  433. foreach(C::t('common_plugin')->fetch_all_data() as $plugin) {
  434. $available = !$method && $plugin['available'] || $method && ($plugin['available'] || $method == $plugin['identifier']);
  435. $addadminmenu = $plugin['available'] && C::t('common_pluginvar')->count_by_pluginid($plugin['pluginid']) ? TRUE : FALSE;
  436. $plugin['modules'] = dunserialize($plugin['modules']);
  437. if($available) {
  438. $data['plugins']['available'][] = $plugin['identifier'];
  439. $data['plugins']['version'][$plugin['identifier']] = $plugin['version'];
  440. }
  441. $plugin['directory'] = $plugin['directory'].((!empty($plugin['directory']) && substr($plugin['directory'], -1) != '/') ? '/' : '');
  442. if(is_array($plugin['modules'])) {
  443. unset($plugin['modules']['extra']);
  444. foreach($plugin['modules'] as $k => $module) {
  445. if($available && isset($module['name'])) {
  446. $module['displayorder'] = $plugin['modules']['system'] ? ($module['displayorder'] < 1000 ? $module['displayorder'] : 999) : $module['displayorder'] + 1000;
  447. $k = '';
  448. switch($module['type']) {
  449. case 1:
  450. $navtype = 0;
  451. case 23:
  452. if($module['type'] == 23) $navtype = 1;
  453. case 24:
  454. if($module['type'] == 24) $navtype = 2;
  455. case 25:
  456. if($module['type'] == 25) $navtype = 3;
  457. case 27:
  458. if($module['type'] == 27) $navtype = 4;
  459. $module['url'] = $module['url'] ? $module['url'] : 'plugin.php?id='.$plugin['identifier'].':'.$module['name'];
  460. if(!(C::t('common_nav')->count_by_navtype_type_identifier($navtype, 3, $plugin['identifier']))) {
  461. C::t('common_nav')->insert(array(
  462. 'name' => $module['menu'],
  463. 'title' => $module['navtitle'],
  464. 'url' => $module['url'],
  465. 'type' => 3,
  466. 'identifier' => $plugin['identifier'],
  467. 'navtype' => $navtype,
  468. 'available' => 1,
  469. 'icon' => $module['navicon'],
  470. 'subname' => $module['navsubname'],
  471. 'suburl' => $module['navsuburl'],
  472. ));
  473. }
  474. break;
  475. case 5:
  476. $k = 'jsmenu';
  477. $module['url'] = $module['url'] ? $module['url'] : 'plugin.php?id='.$plugin['identifier'].':'.$module['name'];
  478. list($module['menu'], $module['title']) = explode('/', $module['menu']);
  479. $module['menu'] = $module['type'] == 1 ? ($module['menu'].($module['title'] ? '<span>'.$module['title'].'</span>' : '')) : $module['menu'];
  480. $data['plugins'][$k][] = array('displayorder' => $module['displayorder'], 'adminid' => $module['adminid'], 'url' => "<a href=\"$module[url]\" id=\"mn_plink_$module[name]\">$module[menu]</a>");
  481. break;
  482. case 14:
  483. $k = 'faq';
  484. case 15:
  485. $k = !$k ? 'modcp_base' : $k;
  486. case 16:
  487. $k = !$k ? 'modcp_tools' : $k;
  488. case 7:
  489. $k = !$k ? 'spacecp' : $k;
  490. case 17:
  491. $k = !$k ? 'spacecp_profile' : $k;
  492. case 19:
  493. $k = !$k ? 'spacecp_credit' : $k;
  494. case 21:
  495. $k = !$k ? 'portalcp' : $k;
  496. case 26:
  497. $k = !$k ? 'space_thread' : $k;
  498. $data['plugins'][$k][$plugin['identifier'].':'.$module['name']] = array('displayorder' => $module['displayorder'], 'adminid' => $module['adminid'], 'name' => $module['menu'], 'url' => $module['url'], 'directory' => $plugin['directory']);
  499. break;
  500. case 3:
  501. $addadminmenu = TRUE;
  502. break;
  503. case 4:
  504. $data['plugins']['include'][$plugin['identifier']] = array('displayorder' => $module['displayorder'], 'adminid' => $module['adminid'], 'script' => $plugin['directory'].$module['name']);
  505. break;
  506. case 11:
  507. $k = 'hookscript';
  508. case 28:
  509. $k = !$k ? 'hookscriptmobile' : $k;
  510. $script = $plugin['directory'].$module['name'];
  511. @include_once DISCUZ_ROOT.'./source/plugin/'.$script.'.class.php';
  512. $classes = get_declared_classes();
  513. $classnames = array();
  514. $namekey = ($k == 'hookscriptmobile' ? 'mobile' : '').'plugin_'.$plugin['identifier'];
  515. $cnlen = strlen($namekey);
  516. foreach($classes as $classname) {
  517. if(substr($classname, 0, $cnlen) == $namekey) {
  518. $hscript = substr($classname, $cnlen + 1);
  519. $classnames[$hscript ? $hscript : 'global'] = $classname;
  520. }
  521. }
  522. foreach($classnames as $hscript => $classname) {
  523. $hookmethods = get_class_methods($classname);
  524. foreach($hookmethods as $funcname) {
  525. if($hscript == 'global' && in_array($funcname, $hookfuncs)) {
  526. $data['plugins']['func'][$k][$funcname] = true;
  527. }
  528. $v = explode('_', $funcname);
  529. $curscript = $v[0];
  530. if(!$curscript || $classname == $funcname) {
  531. continue;
  532. }
  533. if($hscript == 'home' && in_array($curscript, array('space', 'spacecp'))) {
  534. $curscript .= '_'.$v[1];
  535. }
  536. if(!@in_array($script, $data[$k][$hscript][$curscript]['module'])) {
  537. $data[$k][$hscript][$curscript]['module'][$plugin['identifier']] = $script;
  538. $data[$k][$hscript][$curscript]['adminid'][$plugin['identifier']] = $module['adminid'];
  539. }
  540. if(preg_match('/\_output$/', $funcname)) {
  541. $varname = preg_replace('/\_output$/', '', $funcname);
  542. $data[$k][$hscript][$curscript]['outputfuncs'][$varname][] = array('displayorder' => $module['displayorder'], 'func' => array($plugin['identifier'], $funcname));
  543. } elseif(preg_match('/\_message$/', $funcname)) {
  544. $varname = preg_replace('/\_message$/', '', $funcname);
  545. $data[$k][$hscript][$curscript]['messagefuncs'][$varname][] = array('displayorder' => $module['displayorder'], 'func' => array($plugin['identifier'], $funcname));
  546. } else {
  547. $data[$k][$hscript][$curscript]['funcs'][$funcname][] = array('displayorder' => $module['displayorder'], 'func' => array($plugin['identifier'], $funcname));
  548. }
  549. }
  550. }
  551. break;
  552. case 12:
  553. $script = $plugin['directory'].$module['name'];
  554. @include_once DISCUZ_ROOT.'./source/plugin/'.$script.'.class.php';
  555. if(class_exists('threadplugin_'.$plugin['identifier'])) {
  556. $classname = 'threadplugin_'.$plugin['identifier'];
  557. $hookclass = new $classname;
  558. if($hookclass->name) {
  559. $data['threadplugins'][$plugin['identifier']]['name'] = $hookclass->name;
  560. $data['threadplugins'][$plugin['identifier']]['icon'] = $hookclass->iconfile;
  561. $data['threadplugins'][$plugin['identifier']]['module'] = $script;
  562. }
  563. }
  564. break;
  565. }
  566. }
  567. }
  568. }
  569. if($addadminmenu) {
  570. $adminmenu[] = array('url' => "plugins&operation=config&do=$plugin[pluginid]", 'action' => 'plugins_config_'.$plugin['pluginid'], 'name' => $plugin['name']);
  571. }
  572. }
  573. if(!$method) {
  574. $_G['setting']['plugins']['available'] = $data['plugins']['available'];
  575. savecache('adminmenu', $adminmenu);
  576. }
  577. $data['pluginhooks'] = array();
  578. foreach(array('hookscript', 'hookscriptmobile') as $hooktype) {
  579. foreach($data[$hooktype] as $hscript => $hookscript) {
  580. foreach($hookscript as $curscript => $scriptdata) {
  581. if(is_array($scriptdata['funcs'])) {
  582. foreach($scriptdata['funcs'] as $funcname => $funcs) {
  583. usort($funcs, 'pluginmodulecmp');
  584. $tmp = array();
  585. foreach($funcs as $k => $v) {
  586. $tmp[$k] = $v['func'];
  587. }
  588. $data[$hooktype][$hscript][$curscript]['funcs'][$funcname] = $tmp;
  589. }
  590. }
  591. if(is_array($scriptdata['outputfuncs'])) {
  592. foreach($scriptdata['outputfuncs'] as $funcname => $funcs) {
  593. usort($funcs, 'pluginmodulecmp');
  594. $tmp = array();
  595. foreach($funcs as $k => $v) {
  596. $tmp[$k] = $v['func'];
  597. }
  598. $data[$hooktype][$hscript][$curscript]['outputfuncs'][$funcname] = $tmp;
  599. }
  600. }
  601. if(is_array($scriptdata['messagefuncs'])) {
  602. foreach($scriptdata['messagefuncs'] as $funcname => $funcs) {
  603. usort($funcs, 'pluginmodulecmp');
  604. $tmp = array();
  605. foreach($funcs as $k => $v) {
  606. $tmp[$k] = $v['func'];
  607. }
  608. $data[$hooktype][$hscript][$curscript]['messagefuncs'][$funcname] = $tmp;
  609. }
  610. }
  611. }
  612. }
  613. }
  614. foreach(array('links', 'spacecp', 'include', 'jsmenu', 'space', 'spacecp', 'spacecp_profile', 'spacecp_credit', 'faq', 'modcp_base', 'modcp_member', 'modcp_forum') as $pluginkey) {
  615. if(is_array($data['plugins'][$pluginkey])) {
  616. if(in_array($pluginkey, array('space', 'spacecp', 'spacecp_profile', 'spacecp_credit', 'faq', 'modcp_base', 'modcp_tools'))) {
  617. uasort($data['plugins'][$pluginkey], 'pluginmodulecmp');
  618. } else {
  619. usort($data['plugins'][$pluginkey], 'pluginmodulecmp');
  620. }
  621. }
  622. }
  623. return array($data['plugins'], $data['pluginlinks'], $data['hookscript'], $data['hookscriptmobile'], $data['threadplugins'], $data['specialicon']);
  624. }
  625. function get_cachedata_mainnav() {
  626. global $_G;
  627. $data['navs'] = $data['subnavs'] = $data['menunavs'] = $data['navmns'] = $data['navmn'] = $data['navdms'] = $navids = array();
  628. foreach(C::t('common_nav')->fetch_all_mainnav() as $nav) {
  629. if($nav['available'] < 0) {
  630. continue;
  631. }
  632. $id = $nav['type'] == 0 ? $nav['identifier'] : 100 + $nav['id'];
  633. if($nav['identifier'] == 1 && $nav['type'] == 0 && !helper_access::check_module('portal')) {
  634. $nav['available'] = 0;
  635. }
  636. if($nav['identifier'] == 3 && $nav['type'] == 0 && !helper_access::check_module('group')) {
  637. $nav['available'] = 0;
  638. }
  639. if($nav['identifier'] == 4 && $nav['type'] == 0 && !helper_access::check_module('feed')) {
  640. $nav['available'] = 0;
  641. }
  642. if($nav['type'] == 3) {
  643. if(!in_array($nav['identifier'], $_G['setting']['plugins']['available'])) {
  644. continue;
  645. }
  646. }
  647. if($nav['identifier'] == 5 && $nav['type'] == 0 && !$_G['setting']['my_app_status']) {
  648. $nav['available'] = 0;
  649. }
  650. if($nav['identifier'] == 8 && $nav['type'] == 0 && !$_G['setting']['ranklist']['status']) {
  651. $nav['available'] = 0;
  652. }
  653. $nav['style'] = parsehighlight($nav['highlight']);
  654. $data['navs'][$id]['navname'] = $nav['name'];
  655. $data['navs'][$id]['filename'] = $nav['url'];
  656. $data['navs'][$id]['available'] = $nav['available'];
  657. $nav['name'] = $nav['name'].($nav['title'] ? '<span>'.$nav['title'].'</span>' : '');
  658. $subnavs = '';
  659. foreach(C::t('common_nav')->fetch_all_subnav($nav['id']) as $subnav) {
  660. $item = "<a href=\"$subnav[url]\" hidefocus=\"true\" ".($subnav['title'] ? "title=\"$subnav[title]\" " : '').($subnav['target'] == 1 ? "target=\"_blank\" " : '').parsehighlight($subnav['highlight']).">$subnav[name]</a>";
  661. $liparam = !$nav['subtype'] || !$nav['subcols'] ? '' : ' style="width:'.sprintf('%1.1f', (1 / $nav['subcols']) * 100).'%"';
  662. $subnavs .= '<li'.$liparam.'>'.$item.'</li>';
  663. }
  664. list($navid) = explode('.', basename($nav['url']));
  665. if($nav['type'] || $navid == 'misc' || $nav['identifier'] == 6) {
  666. if($nav['type'] == 4) {
  667. $navid = 'P'.$nav['identifier'];
  668. } else {
  669. $navid = 'N'.substr(md5(($nav['url'] != '#' ? $nav['url'] : $nav['name'])), 0, 4);
  670. }
  671. }
  672. $navid = 'mn_'.$navid;
  673. if(in_array($navid, $navids)) {
  674. $navid .= '_'.$nav['identifier'];
  675. }
  676. $navids[] = $navid;
  677. $onmouseover = '';
  678. if($subnavs) {
  679. if($nav['subtype']) {
  680. $onmouseover = 'navShow(\''.substr($navid, 3).'\')';
  681. $data['subnavs'][$navid] = $subnavs;
  682. } else {
  683. $onmouseover = 'showMenu({\'ctrlid\':this.id,\'ctrlclass\':\'hover\',\'duration\':2})';
  684. $data['menunavs'][] = '<ul class="p_pop h_pop" id="'.$navid.'_menu" style="display: none">'.$subnavs.'</ul>';
  685. }
  686. }
  687. if($nav['identifier'] == 6 && $nav['type'] == 0) {
  688. if(!empty($_G['setting']['plugins']['jsmenu'])) {
  689. $onmouseover .= "showMenu({'ctrlid':this.id,'ctrlclass':'hover','menuid':'plugin_menu'})";
  690. } else {
  691. $data['navs'][$id]['available'] = 0;
  692. continue;
  693. }
  694. }
  695. if($nav['logo']) {
  696. $navlogo = str_replace('{STATICURL}', STATICURL, $nav['logo']);
  697. if(!preg_match("/^".preg_quote(STATICURL, '/')."/i", $navlogo) && !(($valueparse = parse_url($navlogo)) && isset($valueparse['host']))) {
  698. $navlogo = $_G['setting']['attachurl'].'common/'.$nav['logo'];
  699. }
  700. $data['navlogos'][$navid] = '<a href="'.$nav['url'].'" title="'.$_G['setting']['bbname'].'"><img src="'.$navlogo.'" alt="'.$_G['setting']['bbname'].'" border="0" /></a>';
  701. }
  702. $purl = parse_url($nav['url']);
  703. $getvars = array();
  704. if($purl['query']) {
  705. parse_str($purl['query'], $getvars);
  706. $data['navmns'][$purl['path']][] = array($getvars, $navid);
  707. } elseif($purl['host']) {
  708. $data['navdms'][strtolower($purl['host'].$purl['path'])] = $navid;
  709. } elseif($purl['path']) {
  710. $data['navmn'][$purl['path']] = $navid;
  711. }
  712. if($nav['type'] == 0) {
  713. $domainkey = substr($purl['path'], 0, -strlen(strrchr($purl['path'], '.')));
  714. if(!empty($_G['setting']['domain']['app'][$domainkey]) && !in_array(strtolower($nav['title']), array('follow', 'guide', 'collection'))) {
  715. $nav['url'] = 'http://'.$_G['setting']['domain']['app'][$domainkey];
  716. }
  717. }
  718. $data['navs'][$id]['navid'] = $navid;
  719. $data['navs'][$id]['level'] = $nav['level'];
  720. $data['navs'][$id]['nav'] = "id=\"$navid\" ".($onmouseover ? 'onmouseover="'.$onmouseover.'"' : '')."><a href=\"$nav[url]\" hidefocus=\"true\" ".($nav['title'] ? "title=\"$nav[title]\" " : '').($nav['target'] == 1 ? "target=\"_blank\" " : '')." $nav[style]>$nav[name]</a";
  721. }
  722. $data['menunavs'] = implode('', $data['menunavs']);
  723. return array($data['navs'], $data['subnavs'], $data['menunavs'], $data['navmns'], $data['navmn'], $data['navdms'], $data['navlogos']);
  724. }
  725. function get_cachedata_footernav() {
  726. global $_G;
  727. $data['footernavs'] = array();
  728. foreach(C::t('common_nav')->fetch_all_by_navtype(1) as $nav) {
  729. $nav['extra'] = '';
  730. if(!$nav['type']) {
  731. if($nav['identifier'] == 'report') {
  732. $nav['url'] = 'javascript:;';
  733. $nav['extra'] = ' onclick="showWindow(\'miscreport\', \'misc.php?mod=report&url=\'+REPORTURL);return false;"';
  734. } elseif($nav['identifier'] == 'archiver') {
  735. if(!$_G['setting']['archiver']) {
  736. continue;
  737. } else {
  738. $domain = $_G['setting']['domain']['app']['forum'] ? $_G['setting']['domain']['app']['forum'] : ($_G['setting']['domain']['app']['default'] ? $_G['setting']['domain']['app']['default'] : '');
  739. $nav['url'] = ($domain ? 'http://'.$domain.'/' : '').$nav['url'];
  740. }
  741. }
  742. }
  743. $nav['code'] = '<a href="'.$nav['url'].'"'.($nav['title'] ? ' title="'.$nav['title'].'"' : '').($nav['target'] == 1 ? ' target="_blank"' : '').' '.parsehighlight($nav['highlight']).$nav['extra'].'>'.$nav['name'].'</a>';
  744. $id = $nav['type'] == 0 ? $nav['identifier'] : 100 + $nav['id'];
  745. $data['footernavs'][$id] = array('available' => $nav['available'], 'navname' => $nav['name'], 'code' => $nav['code'], 'type' => $nav['type'], 'level' => $nav['level'], 'id' => $nav['identifier']);
  746. }
  747. return $data['footernavs'];
  748. }
  749. function get_cachedata_spacenavs() {
  750. global $_G;
  751. $data['spacenavs'] = array();
  752. foreach(C::t('common_nav')->fetch_all_by_navtype(2) as $nav) {
  753. if($nav['available'] < 0) {
  754. continue;
  755. }
  756. if($nav['icon']) {
  757. $navicon = str_replace('{STATICURL}', STATICURL, $nav['icon']);
  758. if(!preg_match("/^".preg_quote(STATICURL, '/')."/i", $navicon) && !(($valueparse = parse_url($navicon)) && isset($valueparse['host']))) {
  759. $navicon = $_G['setting']['attachurl'].'common/'.$nav['icon'].'?'.random(6);
  760. }
  761. $nav['icon'] = '<img src="'.$navicon.'" width="16" height="16" />';
  762. }
  763. $nav['allowsubnew'] = 1;
  764. if(!$nav['subname'] || !$nav['suburl'] || substr($nav['subname'], 0, 1) == "\t") {
  765. $nav['allowsubnew'] = 0;
  766. $nav['subname'] = substr($nav['subname'], 1);
  767. }
  768. $nav['extra'] = '';
  769. if(!$nav['type'] && ($nav['identifier'] == 'magic' && !$_G['setting']['magicstatus'] || $nav['identifier'] == 'medal' && !$_G['setting']['medalstatus'])) {
  770. continue;
  771. }
  772. if(!$nav['type'] && $nav['allowsubnew']) {
  773. if($nav['identifier'] == 'share') {
  774. $nav['extra'] = ' onclick="showWindow(\'share\', this.href, \'get\', 0);return false;"';
  775. } elseif($nav['identifier'] == 'thread') {
  776. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  777. } elseif($nav['identifier'] == 'thread') {
  778. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  779. } elseif($nav['identifier'] == 'activity') {
  780. if($_G['setting']['activityforumid']) {
  781. $nav['suburl'] = 'forum.php?mod=post&action=newthread&fid='.$_G['setting']['activityforumid'].'&special=4';
  782. } else {
  783. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  784. }
  785. } elseif($nav['identifier'] == 'poll') {
  786. if($_G['setting']['pollforumid']) {
  787. $nav['suburl'] = 'forum.php?mod=post&action=newthread&fid='.$_G['setting']['pollforumid'].'&special=1';
  788. } else {
  789. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  790. }
  791. } elseif($nav['identifier'] == 'reward') {
  792. if($_G['setting']['rewardforumid']) {
  793. $nav['suburl'] = 'forum.php?mod=post&action=newthread&fid='.$_G['setting']['rewardforumid'].'&special=3';
  794. } else {
  795. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  796. }
  797. } elseif($nav['identifier'] == 'debate') {
  798. if($_G['setting']['debateforumid']) {
  799. $nav['suburl'] = 'forum.php?mod=post&action=newthread&fid='.$_G['setting']['debateforumid'].'&special=5';
  800. } else {
  801. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  802. }
  803. } elseif($nav['identifier'] == 'trade') {
  804. if($_G['setting']['tradeforumid']) {
  805. $nav['suburl'] = 'forum.php?mod=post&action=newthread&fid='.$_G['setting']['tradeforumid'].'&special=2';
  806. } else {
  807. $nav['extra'] = ' onclick="showWindow(\'nav\', this.href);return false;"';
  808. }
  809. } elseif($nav['identifier'] == 'credit') {
  810. $nav['allowsubnew'] = $_G['setting']['ec_ratio'] && ($_G['setting']['ec_account'] || $_G['setting']['ec_tenpay_opentrans_chnid'] || $_G['setting']['ec_tenpay_bargainor']);
  811. }
  812. }
  813. $nav['subcode'] = $nav['allowsubnew'] ? '<span><a href="'.$nav['suburl'].'"'.($nav['target'] == 1 ? ' target="_blank"' : '').$nav['extra'].'>'.$nav['subname'].'</a></span>' : '';
  814. if($nav['name'] != '{hr}') {
  815. if(in_array($nav['name'], array('{userpanelarea1}', '{userpanelarea2}'))) {
  816. $nav['code'] = str_replace(array('{', '}'), '', $nav['name']);
  817. } else {
  818. $nav['code'] = '<li>'.$nav['subcode'].'<a href="'.$nav['url'].'"'.($nav['title'] ? ' title="'.$nav['title'].'"' : '').($nav['target'] == 1 ? ' target="_blank"' : '').'>'.$nav['icon'].$nav['name'].'</a></li>';
  819. }
  820. } else {
  821. $nav['code'] = '</ul><hr class="da" /><ul>';
  822. }
  823. $id = $nav['type'] == 0 && !in_array($nav['name'], array('{userpanelarea1}', '{userpanelarea2}')) ? $nav['identifier'] : 100 + $nav['id'];
  824. $data['spacenavs'][$id] = array('available' => $nav['available'], 'navname' => $nav['name'], 'code' => $nav['code'], 'level' => $nav['level']);
  825. }
  826. return $data['spacenavs'];
  827. }
  828. function get_cachedata_mynavs() {
  829. global $_G;
  830. $data['mynavs'] = array();
  831. foreach(C::t('common_nav')->fetch_all_by_navtype(3) as $nav) {
  832. if($nav['available'] < 0) {
  833. continue;
  834. }
  835. if($nav['icon']) {
  836. $navicon = str_replace('{STATICURL}', STATICURL, $nav['icon']);
  837. if(!preg_match("/^".preg_quote(STATICURL, '/')."/i", $navicon) && !(($valueparse = parse_url($navicon)) && isset($valueparse['host']))) {
  838. $navicon = $_G['setting']['attachurl'].'common/'.$nav['icon'].'?'.random(6);
  839. }
  840. $navicon = preg_match('/^http:\/\//i', $navicon) ? $navicon : $_G['siteurl'].$navicon;
  841. $nav['icon'] = ' style="background-image:url('.$navicon.') !important"';
  842. }
  843. $nav['code'] = '<a href="'.$nav['url'].'"'.($nav['title'] ? ' title="'.$nav['title'].'"' : '').($nav['target'] == 1 ? ' target="_blank"' : '').$nav['icon'].'>'.$nav['name'].'</a>';
  844. $id = $nav['type'] == 0 ? $nav['identifier'] : 100 + $nav['id'];
  845. $data['mynavs'][$id] = array('available' => $nav['available'], 'navname' => $nav['name'], 'code' => $nav['code'], 'level' => $nav['level']);
  846. }
  847. return $data['mynavs'];
  848. }
  849. function get_cachedata_topnav() {
  850. global $_G;
  851. $data['topnavs'] = array();
  852. foreach(C::t('common_nav')->fetch_all_by_navtype(4) as $nav) {
  853. $nav['extra'] = '';
  854. if(!$nav['type']) {
  855. if($nav['identifier'] == 'sethomepage') {
  856. $nav['url'] = 'javascript:;';
  857. $nav['extra'] = ' onclick="setHomepage(\''.$_G['siteurl'].'\');"';
  858. } elseif($nav['identifier'] == 'setfavorite') {
  859. $nav['url'] = $_G['siteurl'];
  860. $nav['extra'] = ' onclick="addFavorite(this.href, \''.addslashes($_G['setting']['bbname']).'\');return false;"';
  861. }
  862. }
  863. $nav['code'] = '<a href="'.$nav['url'].'"'.($nav['title'] ? ' title="'.$nav['title'].'"' : '').($nav['target'] == 1 ? ' target="_blank"' : '').' '.parsehighlight($nav['highlight']).$nav['extra'].'>'.$nav['name'].'</a>';
  864. $id = $nav['type'] == 0 ? $nav['identifier'] : 100 + $nav['id'];
  865. $data['topnavs'][$nav['subtype']][$id] = array('available' => $nav['available'], 'navname' => $nav['name'], 'code' => $nav['code'], 'type' => $nav['type'], 'level' => $nav['level'], 'id' => $nav['identifier']);
  866. }
  867. return $data['topnavs'];
  868. }
  869. function writetojscache() {
  870. $dir = DISCUZ_ROOT.'static/js/';
  871. $dh = opendir($dir);
  872. $remove = array(
  873. array(
  874. '/(^|\r|\n)\/\*.+?\*\/(\r|\n)/is',
  875. "/([^\\\:]{1})\/\/.+?(\r|\n)/",
  876. '/\/\/note.+?(\r|\n)/i',
  877. '/\/\/debug.+?(\r|\n)/i',
  878. '/(^|\r|\n)(\s|\t)+/',
  879. '/(\r|\n)/',
  880. ), array(
  881. '',
  882. '\1',
  883. '',
  884. '',
  885. '',
  886. '',
  887. ));
  888. while(($entry = readdir($dh)) !== false) {
  889. if(fileext($entry) == 'js') {
  890. $jsfile = $dir.$entry;
  891. $fp = fopen($jsfile, 'r');
  892. $jsdata = @fread($fp, filesize($jsfile));
  893. fclose($fp);
  894. $jsdata = preg_replace($remove[0], $remove[1], $jsdata);
  895. if(@$fp = fopen(DISCUZ_ROOT.'./data/cache/'.$entry, 'w')) {
  896. fwrite($fp, $jsdata);
  897. fclose($fp);
  898. } else {
  899. exit('Can not write to cache files, please check directory ./data/ and ./data/cache/ .');
  900. }
  901. }
  902. }
  903. }
  904. function pluginmodulecmp($a, $b) {
  905. return $a['displayorder'] > $b['displayorder'] ? 1 : -1;
  906. }
  907. function parsehighlight($highlight) {
  908. if($highlight) {
  909. $colorarray = array('', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'gray');
  910. $string = sprintf('%02d', $highlight);
  911. $stylestr = sprintf('%03b', $string[0]);
  912. $style = ' style="';
  913. $style .= $stylestr[0] ? 'font-weight: bold;' : '';
  914. $style .= $stylestr[1] ? 'font-style: italic;' : '';
  915. $style .= $stylestr[2] ? 'text-decoration: underline;' : '';
  916. $style .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
  917. $style .= '"';
  918. } else {
  919. $style = '';
  920. }
  921. return $style;
  922. }
  923. ?>