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