无限星辰工作室-客户无限互联网动力之源

标题: Discuz! X缓存扩展机制说明 [打印本页]

作者: crx349    时间: 2019-6-4 15:13
标题: Discuz! X缓存扩展机制说明

Discuz! X系列中加入了全新的缓存机制,我们在开发插件或者是增加新的功能的时候可以很方便的为系统增加一个全新的缓存,并在任何页面中使用。
下面以一个 名为 example 的缓存为例,详细说一下这个机制。
新建一个文件:
  1. <?php
  2. if(!defined('IN_DISCUZ')) {
  3. &#160; &#160;&#160; &#160;&#160;&#160;exit('Access Denied');
  4. }

  5. function build_cache_example() {
  6. &#160; &#160;&#160; &#160;&#160;&#160;$data = array();
  7. &#160; &#160; $data[] = 'Hello World';
  8. &#160; &#160; $data[] = 'Hello Discuz!';
  9. &#160; &#160;&#160; &#160;&#160;&#160;save_syscache('example', $data);
  10. }

  11. ?>
复制代码

这就是一个标准的生成缓存的文件。其中有几点重要的为:
需要生成名字为 example 的缓存,那么这个文件的名字需要命名为:cache_example.php
文件中的 build_cache_xxxx 类似的这个函数名应为 build_cache_example
save_syscache('xxxx', $data);  应该为  save_syscache('example', $data);
为了安全性,文件头部必须增加
  1. if(!defined('IN_DISCUZ')) {
  2. &#160; &#160;&#160; &#160;&#160;&#160;exit('Access Denied');
  3. }
复制代码


其中 build_cache_example 函数就是主要的对需要缓存的数据做处理的函数,所有的组织数据,都可以放到这个函数里面执行,或者放到多个小函数,然后统一在这个函数中执行。而且结尾必须要以  save_syscache('example', $data); 结尾,才能写入缓存数据。

现在缓存文件有了,我们可以把 cache_example.php 文件放到 source/function/cache 目录中。这样在的 Discuz! 文件中就可以调用这个缓存了。
更新缓存的方法:
  1. require_once libfile('function/cache');
  2. updatecache('example');
复制代码

调用缓存的方法:
  1. require_once libfile('function/cache');
  2. loadcache('example');
复制代码

执行后,缓存在:$_G['cache']['example']  变量中;
测试代码:
  1. require_once libfile('function/cache');
  2. updatecache('example');
  3. loadcache('example');
  4. print_r($_G['cache']['example']);exit;
复制代码

输出结果:
  1. Array ( [0] => Hello World [1] => Hello Discuz! )
复制代码

作者: crx349    时间: 2019-6-4 15:20
例子:
example.php
  1. <?php
  2. require_once './include/common.inc.php';
  3. require_once './include/cache.func.php';

  4. //参数说明:  缓存标识名, 内置数据取得标识, 缓存数据(string), 缓存前缀.
  5. //writetocache('文件名', $cachenames, $cachedata = '', $prefix = 'cache_')

  6. // 第一种模式. 指针转成变量,写入到test.php当中, 目录在forundata/cache/
  7. writetocache('test','',getcachevars(array('var'=>'变量值','phps'=>'discuz.net')), $prefix = 'caches_');

  8. //第二种模式,这种比较好, 生成一个数组, 写在文件test2.php中.
  9. writetocache('test2', '', '$_DCACHE[\'settings\'] = '.arrayeval(range(1,20)).";\n\n", $prefix = 'caches_');

  10. //第三种模式,$cachedata内容是什么, 就写入是什么, 很强悍.
  11. writetocache('test3', '',"array('var1'=>'mysql php','var2'=>'fenanr')", $prefix = 'caches_');

  12. //第四种模式,当没有$prefix值时, 默认生成cache_xxxx.php的缓存命名.
  13. writetocache('test4', '',"array('var1'=>'php 6','var2'=>'discuz')");
  14. ?>
复制代码

cache.func.php文件详解
  1. <?php

  2. /*
  3. &#160; &#160;&#160; &#160;&#160;&#160;[Discuz!] (C)2001-2009 Comsenz Inc.
  4. &#160; &#160;&#160; &#160;&#160;&#160;This is NOT a freeware, use is subject to license terms

  5. &#160; &#160;&#160; &#160;&#160;&#160;$Id: cache.func.php 21311 2009-11-26 01:35:43Z liulanbo $
  6. */

  7. define('DISCUZ_KERNEL_VERSION', '7.2');
  8. define('DISCUZ_KERNEL_RELEASE', '20091126');


  9. function updatecache($cachename = '') {
  10. &#160; &#160;&#160; &#160;&#160;&#160;//分别引入 mysql操作库存,论坛名称,数据库前缀,最大论坛时间(估计是授权用户专用)
  11. &#160; &#160;&#160; &#160;&#160;&#160;global $db, $bbname, $tablepre, $maxbdays;
  12. &#160; &#160;&#160; &#160;&#160;&#160;//静态化一下数组,比如$cachename = setings&#160; &#160;&#160;&#160;就读到这个数组&#160;&#160;'settings'&#160; &#160;&#160; &#160;&#160;&#160;=> array('settings'),
  13. &#160; &#160;&#160; &#160;&#160;&#160;static $cachescript = array
  14. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; (

  15. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'settings'&#160; &#160;&#160; &#160;&#160;&#160;=> array('settings'),
  16. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'forums'&#160; &#160;&#160; &#160;&#160;&#160;=> array('forums'),
  17. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'icons'&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; => array('icons'),
  18. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'stamps'&#160; &#160;&#160; &#160;&#160;&#160;=> array('stamps'),
  19. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'ranks'&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; => array('ranks'),
  20. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'usergroups'&#160; &#160;&#160; &#160;&#160;&#160;=> array('usergroups'),
  21. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'request'&#160; &#160;&#160; &#160;&#160;&#160;=> array('request'),
  22. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'medals'&#160; &#160;&#160; &#160;&#160;&#160;=> array('medals'),
  23. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'magics'&#160; &#160;&#160; &#160;&#160;&#160;=> array('magics'),
  24. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'topicadmin'&#160; &#160;&#160; &#160;&#160;&#160;=> array('modreasons', 'stamptypeid'),
  25. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'archiver'&#160; &#160;&#160; &#160;&#160;&#160;=> array('advs_archiver'),
  26. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'register'&#160; &#160;&#160; &#160;&#160;&#160;=> array('advs_register', 'ipctrl'),
  27. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'faqs'&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; => array('faqs'),
  28. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'secqaa'&#160; &#160;&#160; &#160;&#160;&#160;=> array('secqaa'),
  29. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'censor'&#160; &#160;&#160; &#160;&#160;&#160;=> array('censor'),
  30. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'ipbanned'&#160; &#160;&#160; &#160;&#160;&#160;=> array('ipbanned'),
  31. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'smilies'&#160; &#160;&#160; &#160;&#160;&#160;=> array('smilies_js'),
  32. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'forumstick' => array('forumstick'),

  33. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'index'&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; => array('announcements', 'onlinelist', 'forumlinks', 'advs_index', 'heats'),
  34. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'forumdisplay'&#160; &#160;&#160; &#160;&#160;&#160;=> array('smilies', 'announcements_forum', 'globalstick', 'forums', 'icons', 'onlinelist', 'advs_forumdisplay', 'forumstick'),
  35. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'viewthread'&#160; &#160;&#160; &#160;&#160;&#160;=> array('smilies', 'smileytypes', 'forums', 'usergroups', 'ranks', 'stamps', 'bbcodes', 'smilies', 'advs_viewthread', 'tags_viewthread', 'custominfo', 'groupicon', 'focus', 'stamps'),
  36. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'post'&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; => array('bbcodes_display', 'bbcodes', 'smileycodes', 'smilies', 'smileytypes', 'icons', 'domainwhitelist'),
  37. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'profilefields'&#160; &#160;&#160; &#160;&#160;&#160;=> array('fields_required', 'fields_optional'),
  38. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'viewpro'&#160; &#160;&#160; &#160;&#160;&#160;=> array('fields_required', 'fields_optional', 'custominfo'),
  39. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; 'bbcodes'&#160; &#160;&#160; &#160;&#160;&#160;=> array('bbcodes', 'smilies', 'smileytypes'),
  40. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; );
  41. &#160; &#160;&#160; &#160;&#160;&#160;//当最大时间有值时,就将在$cachescript 增加两段
  42. &#160; &#160;&#160; &#160;&#160;&#160;if($maxbdays) {
  43. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cachescript['birthdays'] = array('birthdays');
  44. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cachescript['index'][]&#160; &#160;= 'birthdays_index';
  45. &#160; &#160;&#160; &#160;&#160;&#160;}
  46. &#160; &#160;&#160; &#160;&#160;&#160;// 组成更新数组.
  47. &#160; &#160;&#160; &#160;&#160;&#160;$updatelist = empty($cachename) ? array_values($cachescript) : (is_array($cachename) ? array('0' => $cachename) : array(array('0' => $cachename)));
  48. &#160; &#160;&#160; &#160;&#160;&#160;$updated = array();
  49. &#160; &#160;&#160; &#160;&#160;&#160;// 现在循环. 由于是二维数组, 所以循环两次.
  50. &#160; &#160;&#160; &#160;&#160;&#160;foreach($updatelist as $value) {
  51. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach($value as $cname) {
  52. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;//判断如果$updated数组为假,或者$updated中没有$cname的值,就进入, 目的是为了防止重复
  53. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(empty($updated) || !in_array($cname, $updated)) {
  54. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$updated[] = $cname;&#160;&#160;//进来一次, 就丢进数组, 以便循环中再次使用.
  55. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;getcachearray($cname);&#160; &#160;// 取得相应的值,并且生成缓存.
  56. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  57. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  58. &#160; &#160;&#160; &#160;&#160;&#160;}
  59. &#160; &#160;&#160; &#160;&#160;&#160;
  60. &#160; &#160;&#160; &#160;&#160;&#160;// 假如是空参数进入, 就对所有的缓存标识作判断.
  61. &#160; &#160;&#160; &#160;&#160;&#160;foreach($cachescript as $script => $cachenames) {
  62. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if(empty($cachename) || (!is_array($cachename) && in_array($cachename, $cachenames)) || (is_array($cachename) && array_intersect($cachename, $cachenames))) {
  63. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$cachedata = '';
  64. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$query = $db->query("SELECT data FROM {$tablepre}caches WHERE cachename in(".implodeids($cachenames).")");
  65. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;while($data = $db->fetch_array($query)) {
  66. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$cachedata .= $data['data'];
  67. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  68. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocache($script, $cachenames, $cachedata);
  69. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  70. &#160; &#160;&#160; &#160;&#160;&#160;}
  71. &#160; &#160;&#160; &#160;&#160;&#160;
  72. &#160; &#160;&#160; &#160;&#160;&#160;//假如参数为空,或者参数为styles 就处理模板风格等缓存
  73. &#160; &#160;&#160; &#160;&#160;&#160;if(!$cachename || $cachename == 'styles') {
  74. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $stylevars = $styledata = $styleicons = array();
  75. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $defaultstyleid = $db->result_first("SELECT value FROM {$tablepre}settings WHERE variable = 'styleid'");
  76. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; list(, $imagemaxwidth) = explode("\t", $db->result_first("SELECT value FROM {$tablepre}settings WHERE variable = 'zoomstatus'"));
  77. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $imagemaxwidth = $imagemaxwidth ? $imagemaxwidth : 600;
  78. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $imagemaxwidthint = intval($imagemaxwidth);
  79. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT sv.* FROM {$tablepre}stylevars sv LEFT JOIN {$tablepre}styles s ON s.styleid = sv.styleid AND (s.available=1 OR s.styleid='$defaultstyleid')");
  80. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($var = $db->fetch_array($query)) {
  81. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$stylevars[$var['styleid']][$var['variable']] = $var['substitute'];
  82. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  83. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT s.*, t.directory AS tpldir FROM {$tablepre}styles s LEFT JOIN {$tablepre}templates t ON s.templateid=t.templateid WHERE s.available=1 OR s.styleid='$defaultstyleid'");
  84. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($data = $db->fetch_array($query)) {
  85. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data = array_merge($data, $stylevars[$data['styleid']]);
  86. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$datanew = array();
  87. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['imgdir'] = $data['imgdir'] ? $data['imgdir'] : 'images/default';
  88. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['styleimgdir'] = $data['styleimgdir'] ? $data['styleimgdir'] : $data['imgdir'];
  89. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;foreach($data as $k => $v) {
  90. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if(substr($k, -7, 7) == 'bgcolor') {
  91. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $newkey = substr($k, 0, -7).'bgcode';
  92. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $datanew[$newkey] = setcssbackground($data, $k);
  93. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  94. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  95. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data = array_merge($data, $datanew);
  96. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$styleicons[$data['styleid']] = $data['menuhover'];
  97. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(strstr($data['boardimg'], ',')) {
  98. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$flash = explode(",", $data['boardimg']);
  99. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$flash[0] = trim($flash[0]);
  100. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$flash[0] = preg_match('/^http:\/\//i', $flash[0]) ? $flash[0] : $data['styleimgdir'].'/'.$flash[0];
  101. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$data['boardlogo'] = "<embed src="".$flash[0]."" width="".trim($flash[1])."" height="".trim($flash[2])."" type="application/x-shockwave-flash" wmode="transparent"></embed>";
  102. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} else {
  103. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$data['boardimg'] = preg_match('/^http:\/\//i', $data['boardimg']) ? $data['boardimg'] : $data['styleimgdir'].'/'.$data['boardimg'];
  104. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$data['boardlogo'] = "<img src="$data[boardimg]" alt="$bbname" border="0" />";
  105. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  106. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['bold'] = $data['nobold'] ? 'normal' : 'bold';
  107. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$contentwidthint = intval($data['contentwidth']);
  108. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$contentwidthint = $contentwidthint ? $contentwidthint : 600;
  109. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(substr(trim($data['contentwidth']), -1, 1) != '%') {
  110. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if(substr(trim($imagemaxwidth), -1, 1) != '%') {
  111. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $data['imagemaxwidth'] = $imagemaxwidthint > $contentwidthint ? $contentwidthint : $imagemaxwidthint;
  112. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} else {
  113. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $data['imagemaxwidth'] = intval($contentwidthint * $imagemaxwidthint / 100);
  114. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  115. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} else {
  116. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if(substr(trim($imagemaxwidth), -1, 1) != '%') {
  117. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $data['imagemaxwidth'] = '%'.$imagemaxwidthint;
  118. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} else {
  119. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $data['imagemaxwidth'] = ($imagemaxwidthint > $contentwidthint ? $contentwidthint : $imagemaxwidthint).'%';
  120. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  121. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  122. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['verhash'] = random(3);
  123. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$styledata[] = $data;
  124. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  125. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach($styledata as $data) {
  126. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['styleicons'] = $styleicons;
  127. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocache($data['styleid'], '', getcachevars($data, 'CONST'), 'style_');
  128. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocsscache($data);
  129. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  130. &#160; &#160;&#160; &#160;&#160;&#160;}
  131. &#160; &#160;&#160; &#160;&#160;&#160;//假如参数为空,或者参数为usergroups 就处理用户组等缓存
  132. &#160; &#160;&#160; &#160;&#160;&#160;if(!$cachename || $cachename == 'usergroups') {
  133. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; @include_once DISCUZ_ROOT.'forumdata/cache/cache_settings.php';
  134. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $threadplugins = !isset($_DCACHE['settings']) ? $GLOBALS['threadplugins'] : $_DCACHE['settings'];
  135. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $allowthreadplugin = $threadplugins ? unserialize($db->result_first("SELECT value FROM {$tablepre}settings WHERE variable='allowthreadplugin'")) : array();

  136. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT * FROM {$tablepre}usergroups u
  137. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; LEFT JOIN {$tablepre}admingroups a ON u.groupid=a.admingid");
  138. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($data = $db->fetch_array($query)) {
  139. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$ratearray = array();
  140. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if($data['raterange']) {
  141. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;foreach(explode("\n", $data['raterange']) as $rating) {
  142. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $rating = explode("\t", $rating);
  143. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $ratearray[$rating[0]] = array('min' => $rating[1], 'max' => $rating[2], 'mrpd' => $rating[3]);
  144. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  145. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  146. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['raterange'] = $ratearray;
  147. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['grouptitle'] = $data['color'] ? '<font color="'.$data['color'].'">'.$data['grouptitle'].'</font>' : $data['grouptitle'];
  148. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['grouptype'] = $data['type'];
  149. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['grouppublic'] = $data['system'] != 'private';
  150. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['groupcreditshigher'] = $data['creditshigher'];
  151. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['groupcreditslower'] = $data['creditslower'];
  152. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['allowthreadplugin'] = $threadplugins ? $allowthreadplugin[$data['groupid']] : array();
  153. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;unset($data['type'], $data['system'], $data['creditshigher'], $data['creditslower'], $data['color'], $data['groupavatar'], $data['admingid']);
  154. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocache($data['groupid'], '', getcachevars($data), 'usergroup_');
  155. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  156. &#160; &#160;&#160; &#160;&#160;&#160;}

  157. &#160; &#160;&#160; &#160;&#160;&#160;//假如参数为空,或者参数为admingroups 就处理管理用户组等缓存
  158. &#160; &#160;&#160; &#160;&#160;&#160;if(!$cachename || $cachename == 'admingroups') {
  159. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT * FROM {$tablepre}admingroups");
  160. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($data = $db->fetch_array($query)) {
  161. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocache($data['admingid'], '', getcachevars($data), 'admingroup_');
  162. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  163. &#160; &#160;&#160; &#160;&#160;&#160;}

  164. &#160; &#160;&#160; &#160;&#160;&#160;if(!$cachename || $cachename == 'plugins') {
  165. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT pluginid, available, adminid, name, identifier, datatables, directory, copyright, modules FROM {$tablepre}plugins");
  166. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($plugin = $db->fetch_array($query)) {
  167. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data = array_merge($plugin, array('modules' => array()), array('vars' => array()));
  168. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$plugin['modules'] = unserialize($plugin['modules']);
  169. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(is_array($plugin['modules'])) {
  170. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;foreach($plugin['modules'] as $module) {
  171. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $data['modules'][$module['name']] = $module;
  172. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  173. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  174. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$queryvars = $db->query("SELECT variable, value FROM {$tablepre}pluginvars WHERE pluginid='$plugin[pluginid]'");
  175. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;while($var = $db->fetch_array($queryvars)) {
  176. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$data['vars'][$var['variable']] = $var['value'];
  177. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  178. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocache($plugin['identifier'], '', "\$_DPLUGIN['$plugin[identifier]'] = ".arrayeval($data), 'plugin_');
  179. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  180. &#160; &#160;&#160; &#160;&#160;&#160;}
  181. &#160; &#160;&#160; &#160;&#160;&#160;//假如参数为空,或者参数为threadsorts 就处理主题信息等缓存
  182. &#160; &#160;&#160; &#160;&#160;&#160;if(!$cachename || $cachename == 'threadsorts') {
  183. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $sortlist = $templatedata = array();
  184. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT t.typeid AS sortid, tt.optionid, tt.title, tt.type, tt.unit, tt.rules, tt.identifier, tt.description, tv.required, tv.unchangeable, tv.search, tv.subjectshow
  185. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;FROM {$tablepre}threadtypes t
  186. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;LEFT JOIN {$tablepre}typevars tv ON t.typeid=tv.sortid
  187. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;LEFT JOIN {$tablepre}typeoptions tt ON tv.optionid=tt.optionid
  188. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;WHERE t.special='1' AND tv.available='1'
  189. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;ORDER BY tv.displayorder");
  190. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($data = $db->fetch_array($query)) {
  191. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$data['rules'] = unserialize($data['rules']);
  192. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$sortid = $data['sortid'];
  193. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$optionid = $data['optionid'];
  194. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$sortlist[$sortid][$optionid] = array(
  195. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'title' => dhtmlspecialchars($data['title']),
  196. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'type' => dhtmlspecialchars($data['type']),
  197. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'unit' => dhtmlspecialchars($data['unit']),
  198. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'identifier' => dhtmlspecialchars($data['identifier']),
  199. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'description' => dhtmlspecialchars($data['description']),
  200. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'required' => intval($data['required']),
  201. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'unchangeable' => intval($data['unchangeable']),
  202. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'search' => intval($data['search']),
  203. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;'subjectshow' => intval($data['subjectshow']),
  204. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;);

  205. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(in_array($data['type'], array('select', 'checkbox', 'radio'))) {
  206. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if($data['rules']['choices']) {
  207. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $choices = array();
  208. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach(explode("\n", $data['rules']['choices']) as $item) {
  209. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;list($index, $choice) = explode('=', $item);
  210. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$choices[trim($index)] = trim($choice);
  211. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  212. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $sortlist[$sortid][$optionid]['choices'] = $choices;
  213. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} else {
  214. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $typelist[$sortid][$optionid]['choices'] = array();
  215. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  216. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} elseif(in_array($data['type'], array('text', 'textarea'))) {
  217. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$sortlist[$sortid][$optionid]['maxlength'] = intval($data['rules']['maxlength']);
  218. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} elseif($data['type'] == 'image') {
  219. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$sortlist[$sortid][$optionid]['maxwidth'] = intval($data['rules']['maxwidth']);
  220. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$sortlist[$sortid][$optionid]['maxheight'] = intval($data['rules']['maxheight']);
  221. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} elseif($data['type'] == 'number') {
  222. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$sortlist[$sortid][$optionid]['maxnum'] = intval($data['rules']['maxnum']);
  223. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$sortlist[$sortid][$optionid]['minnum'] = intval($data['rules']['minnum']);
  224. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  225. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  226. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $query = $db->query("SELECT typeid, description, template, stemplate FROM {$tablepre}threadtypes WHERE special='1'");
  227. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($data = $db->fetch_array($query)) {
  228. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$templatedata[$data['typeid']] = $data['template'];
  229. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$stemplatedata[$data['typeid']] = $data['stemplate'];
  230. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$threaddesc[$data['typeid']] = dhtmlspecialchars($data['description']);
  231. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }

  232. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach($sortlist as $sortid => $option) {
  233. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;writetocache($sortid, '', "\$_DTYPE = ".arrayeval($option).";\n\n\$_DTYPETEMPLATE = "".str_replace('"', '"', $templatedata[$sortid])."";\n\n\$_DSTYPETEMPLATE = "".str_replace('"', '"', $stemplatedata[$sortid])."";\n", 'threadsort_');
  234. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  235. &#160; &#160;&#160; &#160;&#160;&#160;}

  236. }

  237. // 这是css缓存文件生成需要的处理css背景颜色函数
  238. function setcssbackground(&$data, $code) {
  239. &#160; &#160;&#160; &#160;&#160;&#160;$codes = explode(' ', $data[$code]);
  240. &#160; &#160;&#160; &#160;&#160;&#160;$css = $codevalue = '';
  241. &#160; &#160;&#160; &#160;&#160;&#160;for($i = 0; $i < count($codes); $i++) {
  242. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if($i < 2) {
  243. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if($codes[$i] != '') {
  244. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if($codes[$i]{0} == '#') {
  245. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $css .= strtoupper($codes[$i]).' ';
  246. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $codevalue = strtoupper($codes[$i]);
  247. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} elseif(preg_match('/^http:\/\//i', $codes[$i])) {
  248. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $css .= 'url("'.$codes[$i].'") ';
  249. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} else {
  250. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $css .= 'url("'.$data['styleimgdir'].'/'.$codes[$i].'") ';
  251. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  252. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  253. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; } else {
  254. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$css .= $codes[$i].' ';
  255. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  256. &#160; &#160;&#160; &#160;&#160;&#160;}
  257. &#160; &#160;&#160; &#160;&#160;&#160;$data[$code] = $codevalue;
  258. &#160; &#160;&#160; &#160;&#160;&#160;$css = trim($css);
  259. &#160; &#160;&#160; &#160;&#160;&#160;return $css ? 'background: '.$css : '';
  260. }
  261. // 更新系统配置缓存
  262. function updatesettings() {
  263. &#160; &#160;&#160; &#160;&#160;&#160;global $_DCACHE;
  264. &#160; &#160;&#160; &#160;&#160;&#160;if(isset($_DCACHE['settings']) && is_array($_DCACHE['settings'])) {
  265. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; writetocache('settings', '', '$_DCACHE[\'settings\'] = '.arrayeval($_DCACHE['settings']).";\n\n");
  266. &#160; &#160;&#160; &#160;&#160;&#160;}
  267. }

  268. // 写入缓存文件, 详解一下.
  269. function writetocache($script, $cachenames, $cachedata = '', $prefix = 'cache_') {
  270. &#160; &#160;&#160; &#160;&#160;&#160;global $authkey;
  271. &#160; &#160;&#160; &#160;&#160;&#160;//假如$cachenames是数组,并且$cachedata为假
  272. &#160; &#160;&#160; &#160;&#160;&#160;if(is_array($cachenames) && !$cachedata) {
  273. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach($cachenames as $name) {
  274. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;//赋予内置函数的指定标识, 即可有数据返回
  275. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$cachedata .= getcachearray($name, $script);
  276. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  277. &#160; &#160;&#160; &#160;&#160;&#160;}
  278. &#160; &#160;&#160; &#160;&#160;&#160;$dir = DISCUZ_ROOT.'./forumdata/cache/';
  279. &#160; &#160;&#160; &#160;&#160;&#160;//如果缓存目录不存在, 就生成一个.
  280. &#160; &#160;&#160; &#160;&#160;&#160;if(!is_dir($dir)) {
  281. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; @mkdir($dir, 0777);
  282. &#160; &#160;&#160; &#160;&#160;&#160;}
  283. &#160; &#160;&#160; &#160;&#160;&#160;if($fp = @fopen("$dir$prefix$script.php", 'wb')) {
  284. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; fwrite($fp, "<?php\n//Discuz! cache file, DO NOT modify me!".
  285. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;"\n//Created: ".date("M j, Y, G:i").
  286. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;"\n//Identify: ".md5($prefix.$script.'.php'.$cachedata.$authkey)."\n\n$cachedata?>");
  287. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; fclose($fp);
  288. &#160; &#160;&#160; &#160;&#160;&#160;} else {
  289. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; exit('Can not write to cache files, please check directory ./forumdata/ and ./forumdata/cache/ .');
  290. &#160; &#160;&#160; &#160;&#160;&#160;}
  291. }
  292. // 更新css缓存生成过程中, 里面的路径问题, 参数为css.htm的内容.
  293. function writetocsscache($data) {
  294. &#160; &#160;&#160; &#160;&#160;&#160;$cssdata = '';
  295. &#160; &#160;&#160; &#160;&#160;&#160;foreach(array('_common' => array('css_common', 'css_append'),
  296. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_special' => array('css_special', 'css_special_append'),
  297. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_wysiwyg' => array('css_wysiwyg', '_wysiwyg_append'),
  298. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_seditor' => array('css_seditor', 'css_seditor_append'),
  299. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_calendar' => array('css_calendar', 'css_calendar_append'),
  300. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_moderator' => array('css_moderator', 'css_moderator_append'),
  301. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_script' => array('css_script', 'css_script_append'),
  302. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;'_task_newbie' => array('css_task_newbie', 'css_task_newbie_append')
  303. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; ) as $extra => $cssfiles) {
  304. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = '';
  305. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach($cssfiles as $css) {
  306. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$cssfile = DISCUZ_ROOT.'./'.$data['tpldir'].'/'.$css.'.htm';
  307. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;!file_exists($cssfile) && $cssfile = DISCUZ_ROOT.'./templates/default/'.$css.'.htm';
  308. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(file_exists($cssfile)) {
  309. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$fp = fopen($cssfile, 'r');
  310. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$cssdata .= @fread($fp, filesize($cssfile))."\n\n";
  311. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;fclose($fp);
  312. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  313. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  314. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = preg_replace("/\{([A-Z0-9]+)\}/e", '\$data[strtolower(\'\1\')]', $cssdata);
  315. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = preg_replace("/<\?.+?\?>\s*/", '', $cssdata);
  316. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = !preg_match('/^http:\/\//i', $data['styleimgdir']) ? str_replace("url("$data[styleimgdir]", "url("../../$data[styleimgdir]", $cssdata) : $cssdata;
  317. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = !preg_match('/^http:\/\//i', $data['styleimgdir']) ? str_replace("url($data[styleimgdir]", "url(../../$data[styleimgdir]", $cssdata) : $cssdata;
  318. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = !preg_match('/^http:\/\//i', $data['imgdir']) ? str_replace("url("$data[imgdir]", "url("../../$data[imgdir]", $cssdata) : $cssdata;
  319. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $cssdata = !preg_match('/^http:\/\//i', $data['imgdir']) ? str_replace("url($data[imgdir]", "url(../../$data[imgdir]", $cssdata) : $cssdata;
  320. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if($extra != '_script') {
  321. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$cssdata = preg_replace(array('/\s*([,;:\{\}])\s*/', '/[\t\n\r]/', '/\/\*.+?\*\//'), array('\\1', '',''), $cssdata);
  322. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  323. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if(@$fp = fopen(DISCUZ_ROOT.'./forumdata/cache/style_'.$data['styleid'].$extra.'.css', 'w')) {
  324. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;fwrite($fp, $cssdata);
  325. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;fclose($fp);
  326. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; } else {
  327. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;exit('Can not write to cache files, please check directory ./forumdata/ and ./forumdata/cache/ .');
  328. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  329. &#160; &#160;&#160; &#160;&#160;&#160;}

  330. }

  331. // 将js文件复制到缓存目录.
  332. function writetojscache() {
  333. &#160; &#160;&#160; &#160;&#160;&#160;$dir = DISCUZ_ROOT.'include/js/';
  334. &#160; &#160;&#160; &#160;&#160;&#160;$dh = opendir($dir);
  335. &#160; &#160;&#160; &#160;&#160;&#160;$remove = array(
  336. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; '/(^|\r|\n)\/\*.+?(\r|\n)\*\/(\r|\n)/is',
  337. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; '/\/\/note.+?(\r|\n)/i',
  338. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; '/\/\/debug.+?(\r|\n)/i',
  339. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; '/(^|\r|\n)(\s|\t)+/',
  340. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; '/(\r|\n)/',
  341. &#160; &#160;&#160; &#160;&#160;&#160;);
  342. &#160; &#160;&#160; &#160;&#160;&#160;while(($entry = readdir($dh)) !== false) {
  343. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if(fileext($entry) == 'js') {
  344. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$jsfile = $dir.$entry;
  345. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$fp = fopen($jsfile, 'r');
  346. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$jsdata = @fread($fp, filesize($jsfile));
  347. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;fclose($fp);
  348. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$jsdata = preg_replace($remove, '', $jsdata);
  349. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(@$fp = fopen(DISCUZ_ROOT.'./forumdata/cache/'.$entry, 'w')) {
  350. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;fwrite($fp, $jsdata);
  351. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;fclose($fp);
  352. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} else {
  353. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;exit('Can not write to cache files, please check directory ./forumdata/ and ./forumdata/cache/ .');
  354. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  355. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  356. &#160; &#160;&#160; &#160;&#160;&#160;}
  357. }

  358. //取得缓存数组, 内置.&#160;&#160;标识名,及文件名.
  359. function getcachearray($cachename, $script = '') {
  360. &#160; &#160;&#160; &#160;&#160;&#160;global $db, $timestamp, $tablepre, $timeoffset, $maxbdays, $smcols, $smrows, $charset, $scriptlang;
  361. &#160; &#160;&#160; &#160;&#160;&#160;//省略上千代码.
  362. }

  363. //组成缓存文件需要的数据数组.
  364. function getcachevars($data, $type = 'VAR') {
  365. &#160; &#160;&#160; &#160;&#160;&#160;$evaluate = '';
  366. &#160; &#160;&#160; &#160;&#160;&#160;foreach($data as $key => $val) {
  367. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if(!preg_match("/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/", $key)) {
  368. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;continue;
  369. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  370. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if(is_array($val)) {
  371. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$evaluate .= "\$key = ".arrayeval($val).";\n";
  372. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; } else {
  373. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$val = addcslashes($val, '\'\\');
  374. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$evaluate .= $type == 'VAR' ? "\$key = '$val';\n" : "define('".strtoupper($key)."', '$val');\n";
  375. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  376. &#160; &#160;&#160; &#160;&#160;&#160;}
  377. &#160; &#160;&#160; &#160;&#160;&#160;return $evaluate;
  378. }

  379. //取得广告设置的内容数组.
  380. function advertisement($range) {
  381. &#160; &#160;&#160; &#160;&#160;&#160;global $db, $tablepre, $timestamp;

  382. &#160; &#160;&#160; &#160;&#160;&#160;$advs = array();
  383. &#160; &#160;&#160; &#160;&#160;&#160;$query = $db->query("SELECT * FROM {$tablepre}advertisements WHERE available>'0' AND starttime<='$timestamp' ORDER BY displayorder");
  384. &#160; &#160;&#160; &#160;&#160;&#160;if($db->num_rows($query)) {
  385. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; while($adv = $db->fetch_array($query)) {
  386. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(in_array($adv['type'], array('footerbanner', 'thread'))) {
  387. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$parameters = unserialize($adv['parameters']);
  388. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$position = isset($parameters['position']) && in_array($parameters['position'], array(2, 3)) ? $parameters['position'] : 1;
  389. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$type = $adv['type'].$position;
  390. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} else {
  391. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$type = $adv['type'];
  392. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  393. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$adv['targets'] = in_array($adv['targets'], array('', 'all')) ? ($type == 'text' ? 'forum' : (substr($type, 0, 6) == 'thread' ? 'forum' : 'all')) : $adv['targets'];
  394. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;foreach(explode("\t", $adv['targets']) as $target) {
  395. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if($range == 'index' && substr($target, 0, 3) == 'gid') {
  396. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs['cat'][$type][substr($target, 3)][] = $adv['advid'];
  397. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs['items'][$adv['advid']] = $adv['code'];
  398. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  399. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$target = $target == '0' || $type == 'intercat' ? 'index' : (in_array($target, array('all', 'index', 'forumdisplay', 'viewthread', 'register', 'redirect', 'archiver')) ? $target : ($target == 'forum' ? 'forum_all' : 'forum_'.$target));
  400. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;if((($range == 'forumdisplay' && !in_array($adv['type'], array('thread', 'interthread'))) || $range == 'viewthread') &&&#160;&#160;substr($target, 0, 6) == 'forum_') {
  401. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; if($adv['type'] == 'thread') {
  402. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;foreach(isset($parameters['displayorder']) ? explode("\t", $parameters['displayorder']) : array('0') as $postcount) {
  403. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$advs['type'][$type.'_'.$postcount][$target][] = $adv['advid'];
  404. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  405. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; } else {
  406. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$advs['type'][$type][$target][] = $adv['advid'];
  407. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  408. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs['items'][$adv['advid']] = $adv['code'];
  409. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} elseif($range == 'all' && in_array($target, array('all', 'redirect'))) {
  410. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs[$target]['type'][$type][] = $adv['advid'];
  411. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs[$target]['items'][$adv['advid']] = $adv['code'];
  412. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} elseif($range == 'index' && $type == 'intercat') {
  413. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $parameters = unserialize($adv['parameters']);
  414. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach(is_array($parameters['position']) ? $parameters['position'] : array('0') as $position) {
  415. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$advs['type'][$type][$position][] = $adv['advid'];
  416. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$advs['items'][$adv['advid']] = $adv['code'];
  417. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  418. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;} elseif($target == $range || ($range == 'index' && $target == 'forum_all' && $type == 'text')) {
  419. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs['type'][$type][] = $adv['advid'];
  420. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $advs['items'][$adv['advid']] = $adv['code'];
  421. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;}
  422. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  423. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  424. &#160; &#160;&#160; &#160;&#160;&#160;}

  425. &#160; &#160;&#160; &#160;&#160;&#160;return $advs;
  426. }

  427. // 简单判断.
  428. function pluginmodulecmp($a, $b) {
  429. &#160; &#160;&#160; &#160;&#160;&#160;return $a['displayorder'] > $b['displayorder'] ? 1 : -1;
  430. }
  431. // 计算长宽的函数
  432. function smthumb($size, $smthumb = 50) {
  433. &#160; &#160;&#160; &#160;&#160;&#160;if($size[0] <= $smthumb && $size[1] <= $smthumb) {
  434. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; return array('w' => $size[0], 'h' => $size[1]);
  435. &#160; &#160;&#160; &#160;&#160;&#160;}
  436. &#160; &#160;&#160; &#160;&#160;&#160;$sm = array();
  437. &#160; &#160;&#160; &#160;&#160;&#160;$x_ratio = $smthumb / $size[0];
  438. &#160; &#160;&#160; &#160;&#160;&#160;$y_ratio = $smthumb / $size[1];
  439. &#160; &#160;&#160; &#160;&#160;&#160;if(($x_ratio * $size[1]) < $smthumb) {
  440. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $sm['h'] = ceil($x_ratio * $size[1]);
  441. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $sm['w'] = $smthumb;
  442. &#160; &#160;&#160; &#160;&#160;&#160;} else {
  443. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $sm['w'] = ceil($y_ratio * $size[0]);
  444. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $sm['h'] = $smthumb;
  445. &#160; &#160;&#160; &#160;&#160;&#160;}
  446. &#160; &#160;&#160; &#160;&#160;&#160;return $sm;
  447. }

  448. // 处理缓存生成时部分内容样式的解析
  449. function parsehighlight($highlight) {
  450. &#160; &#160;&#160; &#160;&#160;&#160;if($highlight) {
  451. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $colorarray = array('', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'gray');
  452. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $string = sprintf('%02d', $highlight);
  453. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $stylestr = sprintf('%03b', $string[0]);

  454. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style = ' style="';
  455. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style .= $stylestr[0] ? 'font-weight: bold;' : '';
  456. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style .= $stylestr[1] ? 'font-style: italic;' : '';
  457. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style .= $stylestr[2] ? 'text-decoration: underline;' : '';
  458. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style .= $string[1] ? 'color: '.$colorarray[$string[1]] : '';
  459. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style .= '"';
  460. &#160; &#160;&#160; &#160;&#160;&#160;} else {
  461. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $style = '';
  462. &#160; &#160;&#160; &#160;&#160;&#160;}
  463. &#160; &#160;&#160; &#160;&#160;&#160;return $style;
  464. }
  465. //&#160;&#160;这就是传说的array的立体型输出.
  466. function arrayeval($array, $level = 0) {
  467. &#160; &#160;&#160; &#160;&#160;&#160;if(!is_array($array)) {
  468. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; return "'".$array."'";
  469. &#160; &#160;&#160; &#160;&#160;&#160;}
  470. &#160; &#160;&#160; &#160;&#160;&#160;if(is_array($array) && function_exists('var_export')) {
  471. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; return var_export($array, true);
  472. &#160; &#160;&#160; &#160;&#160;&#160;}

  473. &#160; &#160;&#160; &#160;&#160;&#160;$space = '';
  474. &#160; &#160;&#160; &#160;&#160;&#160;for($i = 0; $i <= $level; $i++) {
  475. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; $space .= "\t";
  476. &#160; &#160;&#160; &#160;&#160;&#160;}
  477. &#160; &#160;&#160; &#160;&#160;&#160;$evaluate = "Array\n$space(\n";
  478. &#160; &#160;&#160; &#160;&#160;&#160;$comma = $space;
  479. &#160; &#160;&#160; &#160;&#160;&#160;if(is_array($array)) {
  480. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; foreach($array as $key => $val) {
  481. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$key = is_string($key) ? '\''.addcslashes($key, '\'\\').'\'' : $key;
  482. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$val = !is_array($val) && (!preg_match("/^\-?[1-9]\d*$/", $val) || strlen($val) > 12) ? '\''.addcslashes($val, '\'\\').'\'' : $val;
  483. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;if(is_array($val)) {
  484. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$evaluate .= "$comma$key => ".arrayeval($val, $level + 1);
  485. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;} else {
  486. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160;&#160;$evaluate .= "$comma$key => $val";
  487. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;}
  488. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;$comma = ",\n$space";
  489. &#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160;&#160; &#160; }
  490. &#160; &#160;&#160; &#160;&#160;&#160;}
  491. &#160; &#160;&#160; &#160;&#160;&#160;$evaluate .= "\n$space)";
  492. &#160; &#160;&#160; &#160;&#160;&#160;return $evaluate;
  493. }

  494. ?>
复制代码






欢迎光临 无限星辰工作室-客户无限互联网动力之源 (https://www.xmspace.net/) Powered by Discuz! X3.4