cache_setting.php 46 KB

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