PageRenderTime 49ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/source/function/cache/cache_setting.php

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