discuz X3.2 forum_index.php详解

  1. <?php  
  2.   
  3. /** 
  4.  *      [Discuz!] (C)2001-2099 Comsenz Inc. 
  5.  *      This is NOT a freeware, use is subject to license terms 
  6.  * 
  7.  *      $Id: forum_index.php 29580 2012-04-20 02:53:59Z svn_project_zhangjie $ 
  8.  */  
  9.   
  10. //mod文件只能被入口文件引用,不能直接访问  
  11. if(!defined('IN_DISCUZ')) {  
  12.     exit('Access Denied');  
  13. }  
  14.   
  15. /** 
  16. * 返回库文件的全路径 
  17. * @param string $libname 库文件分类及名称 
  18. * @param string $folder 模块目录'module','include','class' 
  19. * @return string 
  20. * @example require DISCUZ_ROOT.'./source/function/function_cache.php' 
  21. * @example 我们可以利用此函数简写为:require libfile('function/cache'); 
  22. * 再如:require_once libfile('space/'.$do, 'include');//包含 "/source/include/space/space_profile.php" 文件 
  23. * 1、libfile函数返回库文件的全路径 
  24. * 2、包含文件路径格式:"/source/include/space/space_$do.php" 
  25. * 3、require_once "返回的库文件的全路径",这样就可以将库文件包含进来 
  26. */  
  27. require_once libfile('function/forumlist');//引入"/source/function/function_forumlist.php"函数库文件  
  28.   
  29. $gid = intval(getgpc('gid'));//默认值为0:分区id;何为分区?简单说,就是凌驾与版块之上的一个分类  
  30. $showoldetails = get_index_online_details();//默认情况下为空值,不知道怎么回事  
  31.   
  32. //论坛首页缓存更细时间,0-不开启  
  33. //uid-管理员id   gid-分区id   cacheindexlife-首页缓存时间  
  34. //gid为空的情况  
  35. if(!$_G['uid'] && !$gid && $_G['setting']['cacheindexlife'] && !defined('IN_ARCHIVER') && !defined('IN_MOBILE')) {  
  36.     get_index_page_guest_cache();//此代码只针对游客  
  37. }  
  38.   
  39. $newthreads = round((TIMESTAMP - $_G['member']['lastvisit'] + 600) / 1000) * 1000;  
  40. //初始化数组变量  
  41. $catlist = $forumlist = $sublist = $forumname = $collapse = $favforumlist = array();  
  42. //初始化普通变量:主题、帖子、今日帖子、短消息  
  43. $threads = $posts = $todayposts = $announcepm = 0;  
  44. //定义发帖数量  
  45. $postdata = $_G['cache']['historyposts'] ? explode(" ", $_G['cache']['historyposts']) : array(0,0);  
  46. $postdata[0] = intval($postdata[0]);//昨日发帖  
  47. $postdata[1] = intval($postdata[1]);//历史最高发帖  
  48.   
  49. //创建站点栏目名称、描述、关键字  
  50. list($navtitle, $metadescription, $metakeywords) = get_seosetting('forum');  
  51. if(!$navtitle) {//$navtitle-默认值为“论坛”  
  52.     $navtitle = $_G['setting']['navs'][2]['navname'];  
  53.     $nobbname = false;  
  54. else {  
  55.         //默认执行  
  56.     $nobbname = true;  
  57. }  
  58. //描述  
  59. if(!$metadescription) {  
  60.     $metadescription = $navtitle;  
  61. }  
  62. //关键字  
  63. if(!$metakeywords) {  
  64.     $metakeywords = $navtitle;  
  65. }  
  66.   
  67. //heatthread:热帖  
  68. if($_G['setting']['indexhot']['status'] && $_G['cache']['heats']['expiration'] < TIMESTAMP) {  
  69.     require_once libfile('function/cache');//引入"/source/function/function_cache.php"函数库文件  
  70.     updatecache('heats');  
  71. }  
  72.   
  73. if($_G['uid'] && empty($_G['cookie']['nofavfid'])) {  
  74.     $favfids = array();  
  75.     $forum_favlist = C::t('home_favorite')->fetch_all_by_uid_idtype($_G['uid'], 'fid');  
  76.     if(!$forum_favlist) {  
  77.         dsetcookie('nofavfid', 1, 31536000);  
  78.     }  
  79.     foreach($forum_favlist as $key => $favorite) {  
  80.         if(defined('IN_MOBILE')) {  
  81.             $forum_favlist[$key]['title'] = strip_tags($favorite['title']);  
  82.         }  
  83.         $favfids[] = $favorite['id'];  
  84.     }  
  85.     if($favfids) {  
  86.         $favforumlist = C::t('forum_forum')->fetch_all($favfids);  
  87.         foreach($favforumlist as $id => $forum) {  
  88.             forum($favforumlist[$id]);  
  89.         }  
  90.     }  
  91. }  
  92.   
  93.   
  94. //默认情况下不执行,即:直接跳过这段if代码段  
  95. if(empty($gid) && empty($_G['member']['accessmasks']) && empty($showoldetails)) {  
  96.     extract(get_index_memory_by_groupid($_G['member']['groupid']));  
  97.     if(defined('FORUM_INDEX_PAGE_MEMORY') && FORUM_INDEX_PAGE_MEMORY) {  
  98.         categorycollapse();  
  99.         if(!defined('IN_ARCHIVER')) {  
  100.             include template('diy:forum/discuz');//引入模板文件的方式  
  101.         } else {  
  102.             include loadarchiver('forum/discuz');  
  103.         }  
  104.         dexit();  
  105.     }  
  106. }  
  107.   
  108. //默认情况下执行此if代码段;FORUM_INDEX_PAGE_MEMORY是首页所有缓存数据的一个常量  
  109. //gid为空的情况             FORUM_INDEX_PAGE_MEMORY常量  
  110. if(!$gid && (!defined('FORUM_INDEX_PAGE_MEMORY') || !FORUM_INDEX_PAGE_MEMORY)) {  
  111.     /*格式: 
  112.          * <li><span><a href="">公告1</a></span></li> 
  113.          * <li><span><a href="">公告2</a></span></li> 
  114.          */  
  115.         $announcements = get_index_announcements();//首页公告,此函数的定义在当前文件底部  
  116.   
  117.         //通过状态值查询所有开启的版块或分区相关信息,可查看桌面$forums = Ct('forum_forum')-fetch_all_by_status(1).txt文件  
  118.     //对应pre_forum_forum数据表中的记录  
  119.         $forums = C::t('forum_forum')->fetch_all_by_status(1);  
  120.     //初始化一个数组变量  
  121.         $fids = array();  
  122.     foreach($forums as $forum) {//$forum-代表每一个开启的分区或版块相关的信息数组,一般为一维数组  
  123.             //分区或版块id数组,格式:$fid[分区或版块id]=分区或版块id;$fids[1]=1  
  124.             $fids[$forum['fid']] = $forum['fid'];//启用的分区id或版块id  
  125.     }  
  126.   
  127.         //初始化一个版块访问权限数组变量  
  128.     $forum_access = array();  
  129.     if(!empty($_G['member']['accessmasks'])) {//用户访问权限标志,默认值为1  
  130.         $forum_access = C::t('forum_access')->fetch_all_by_fid_uid($fids, $_G['uid']);  
  131.     }  
  132.         //获取版块扩展字段信息,对应数据表:pre_forum_forumfield,查看桌面 $forum_fields.txt文件  
  133.     $forum_fields = C::t('forum_forumfield')->fetch_all($fids);  
  134.     foreach($forums as $forum) {  
  135.         if($forum_fields[$forum['fid']]['fid']) {//分区或版块id  
  136.                         //将分区或版块的通用信息字段或扩展字段信息合并在一起  
  137.                         //即将pre_forum_forum表的字段与pre_forum_fields表的字段合并在一起  
  138.             $forum = array_merge($forum, $forum_fields[$forum['fid']]);//一维数组  
  139.         }  
  140.         if($forum_access['fid']) {  
  141.             $forum = array_merge($forum, $forum_access[$forum['fid']]);  
  142.         }  
  143.                 //版块或分区的名称  
  144.         $forumname[$forum['fid']] = strip_tags($forum['name']);  
  145.                 //反序列化的pre_forum_forumfields表中extra字段的值  
  146.         $forum['extra'] = empty($forum['extra']) ? array() : dunserialize($forum['extra']);  
  147.         if(!is_array($forum['extra'])) {  
  148.             $forum['extra'] = array();//数组  
  149.         }  
  150.                   
  151.                 //版块的情况,不包括分区的情况  
  152.         if($forum['type'] != 'group') {//版块数组信息的情况   group-分区  forum-版块  
  153.                       
  154.             $threads += $forum['threads'];//主题数量  
  155.             $posts += $forum['posts'];//帖子数量  
  156.             $todayposts += $forum['todayposts'];//今日发帖数量  
  157.   
  158.                         //版块的情况  
  159.             if($forum['type'] == 'forum' && isset($catlist[$forum['fup']])) {//版块存在上级分区的情况  
  160.                                 //forum函数的定义位置:"/source/function/function_forumlist.php"函数库文件  
  161.                 if(forum($forum)) {  
  162.                     $catlist[$forum['fup']]['forums'][] = $forum['fid'];//分区下的所有的版块id  
  163.                                         /*如下形式: 
  164.                                          * [forums] => Array         //当前分区下版块id数组,即是fid数组 
  165.                                             ( 
  166.                                                 [0] => 2         //娱乐 
  167.                                                 [1] => 36        //文化 
  168.                                                 [2] => 37        //体育 
  169.                                                 [3] => 38        //艺术 
  170.                                                 [4] => 39        //商界 
  171.                                             ) 
  172.                                          */  
  173.                                         //排序id  
  174.                     $forum['orderid'] = $catlist[$forum['fup']]['forumscount']++;  
  175.                     //子版块  
  176.                                         $forum['subforums'] = '';  
  177.                     $forumlist[$forum['fid']] = $forum;//仅版块数组 $forumlist,可查看桌面$forumlist.txt文件  
  178.                 }  
  179.   
  180.             } elseif(isset($forumlist[$forum['fup']])) {//$forum['fup']=64 的情况,即:女装版块  
  181.                                 //女装版块下的子版块数组信息  
  182.                 $forumlist[$forum['fup']]['threads'] += $forum['threads'];//主题数量  
  183.                 $forumlist[$forum['fup']]['posts'] += $forum['posts'];//帖子数量  
  184.                 $forumlist[$forum['fup']]['todayposts'] += $forum['todayposts'];//今日发帖数  
  185.                 if($_G['setting']['subforumsindex'] && $forumlist[$forum['fup']]['permission'] == 2 && !($forumlist[$forum['fup']]['simple'] & 16) || ($forumlist[$forum['fup']]['simple'] & 8)) {  
  186.                     //绑定的域名  
  187.                                         $forumurl = !empty($forum['domain']) && !empty($_G['setting']['domain']['root']['forum']) ? 'http://'.$forum['domain'].'.'.$_G['setting']['domain']['root']['forum'] : 'forum.php?mod=forumdisplay&fid='.$forum['fid'];  
  188.                     $forumlist[$forum['fup']]['subforums'] .= (empty($forumlist[$forum['fup']]['subforums']) ? '' : ', ').'<a href="'.$forumurl.'" '.(!empty($forum['extra']['namecolor']) ? ' style="color: ' . $forum['extra']['namecolor'].';"' : '') . '>'.$forum['name'].'</a>';  
  189.                 }  
  190.             }  
  191.   
  192.         } else {//分区的情况,不包含版块的情况  
  193.   
  194.             if($forum['moderators']) {//版主  
  195.                 $forum['moderators'] = moddisplay($forum['moderators'], 'flat');  
  196.             }  
  197.             $forum['forumscount']   = 0;  
  198.             $catlist[$forum['fid']] = $forum;//分区数组信息  
  199.   
  200.         }  
  201.     }  
  202.         //销毁不用的数组变量  
  203.     unset($forum_access, $forum_fields);  
  204.   
  205.         //循环分区二维数组信息   分区id  一维数组分区信息  
  206.     foreach($catlist as $catid => $category) {  
  207.         $catlist[$catid]['collapseimg'] = 'collapsed_no.gif';//伸张或收缩图片  
  208.         if($catlist[$catid]['forumscount'] && $category['forumcolumns']) {  
  209.             $catlist[$catid]['forumcolwidth'] = (floor(100 / $category['forumcolumns']) - 0.1).'%';  
  210.             $catlist[$catid]['endrows'] = '';  
  211.             if($colspan = $category['forumscount'] % $category['forumcolumns']) {  
  212.                 while(($category['forumcolumns'] - $colspan) > 0) {  
  213.                     $catlist[$catid]['endrows'] .= '<td width="'.$catlist[$catid]['forumcolwidth'].'"> </td>';  
  214.                     $colspan ++;  
  215.                 }  
  216.                 $catlist[$catid]['endrows'] .= '</tr>';  
  217.             }  
  218.         } elseif(empty($category['forumscount'])) {  
  219.             unset($catlist[$catid]);  
  220.         }  
  221.     }  
  222.     unset($catid, $category);  
  223.   
  224.     if(isset($catlist[0]) && $catlist[0]['forumscount']) {  
  225.         $catlist[0]['fid'] = 0;  
  226.         $catlist[0]['type'] = 'group';  
  227.         $catlist[0]['name'] = $_G['setting']['bbname'];  
  228.         $catlist[0]['collapseimg'] = 'collapsed_no.gif';  
  229.     } else {  
  230.         unset($catlist[0]);  
  231.     }  
  232.   
  233.     if(!IS_ROBOT && ($_G['setting']['whosonlinestatus'] == 1 || $_G['setting']['whosonlinestatus'] == 3)) {  
  234.         $_G['setting']['whosonlinestatus'] = 1;  
  235.   
  236.         $onlineinfo = explode(" ", $_G['cache']['onlinerecord']);//在线访问记录.Array ( [0] => 2 [1] => 1378968576 )  
  237.               
  238.         if(empty($_G['cookie']['onlineusernum'])) {//在线用户数  
  239.             $onlinenum = C::app()->session->count();  
  240.             if($onlinenum > $onlineinfo[0]) {  
  241.                 $onlinerecord = "$onlinenum ".TIMESTAMP;  
  242.                 C::t('common_setting')->update('onlinerecord', $onlinerecord);  
  243.                 savecache('onlinerecord', $onlinerecord);  
  244.                 $onlineinfo = array($onlinenum, TIMESTAMP);  
  245.             }  
  246.             dsetcookie('onlineusernum', intval($onlinenum), 300);  
  247.         } else {  
  248.             $onlinenum = intval($_G['cookie']['onlineusernum']);  
  249.         }  
  250.         $onlineinfo[1] = dgmdate($onlineinfo[1], 'd');  
  251.   
  252.         $detailstatus = $showoldetails == 'yes' || (((!isset($_G['cookie']['onlineindex']) && !$_G['setting']['whosonline_contract']) || $_G['cookie']['onlineindex']) && $onlinenum < 500 && !$showoldetails);  
  253.   
  254.         $guestcount = $membercount = 0;  
  255.         if(!empty($_G['setting']['sessionclose'])) {  
  256.             $detailstatus = false;  
  257.             $membercount = C::app()->session->count(1);  
  258.             $guestcount = $onlinenum - $membercount;  
  259.         }  
  260.   
  261.         if($detailstatus) {  
  262.             $actioncode = lang('action');  
  263.   
  264.             $_G['uid'] && updatesession();  
  265.             $whosonline = array();  
  266.   
  267.             $_G['setting']['maxonlinelist'] = $_G['setting']['maxonlinelist'] ? $_G['setting']['maxonlinelist'] : 500;  
  268.             foreach(C::app()->session->fetch_member(1, 0, $_G['setting']['maxonlinelist']) as $online){  
  269.                 $membercount ++;  
  270.                 if($online['invisible']) {  
  271.                     $invisiblecount++;  
  272.                     continue;  
  273.                 } else {  
  274.                     $online['icon'] = !empty($_G['cache']['onlinelist'][$online['groupid']]) ? $_G['cache']['onlinelist'][$online['groupid']] : $_G['cache']['onlinelist'][0];  
  275.                 }  
  276.                 $online['lastactivity'] = dgmdate($online['lastactivity'], 't');  
  277.                 $whosonline[] = $online;  
  278.             }  
  279.             if(isset($_G['cache']['onlinelist'][7]) && $_G['setting']['maxonlinelist'] > $membercount) {  
  280.                 foreach(C::app()->session->fetch_member(2, 0, $_G['setting']['maxonlinelist'] - $membercount) as $online){  
  281.                     $online['icon'] = $_G['cache']['onlinelist'][7];  
  282.                     $online['username'] = $_G['cache']['onlinelist']['guest'];  
  283.                     $online['lastactivity'] = dgmdate($online['lastactivity'], 't');  
  284.                     $whosonline[] = $online;  
  285.                 }  
  286.             }  
  287.             unset($actioncode, $online);  
  288.   
  289.             if($onlinenum > $_G['setting']['maxonlinelist']) {  
  290.                 $membercount = C::app()->session->count(1);  
  291.                 $invisiblecount = C::app()->session->count_invisible();  
  292.             }  
  293.   
  294.             if($onlinenum < $membercount) {  
  295.                 $onlinenum = C::app()->session->count();  
  296.                 dsetcookie('onlineusernum', intval($onlinenum), 300);  
  297.             }  
  298.   
  299.             $invisiblecount = intval($invisiblecount);  
  300.             $guestcount = $onlinenum - $membercount;  
  301.   
  302.             unset($online);  
  303.         }  
  304.   
  305.     } else {  
  306.         $_G['setting']['whosonlinestatus'] = 0;  
  307.     }  
  308.   
  309.     if(defined('FORUM_INDEX_PAGE_MEMORY') && !FORUM_INDEX_PAGE_MEMORY) {  
  310.         $key = !IS_ROBOT ? $_G['member']['groupid'] : 'for_robot';  
  311.         memory('set', 'forum_index_page_'.$key, array(  
  312.             'catlist' => $catlist,//分区数组列表,不包含版块,此数组对应版块扩展表及版块表-pre_forum_forumfield、pre_forum_forum的字段  
  313.             'forumlist' => $forumlist,//无下级版块的版块信息数组  
  314.             'sublist' => $sublist,//子版块列表  
  315.             'whosonline' => $whosonline,//谁在线  
  316.             'onlinenum' => $onlinenum,//在线人数  
  317.             'membercount' => $membercount,//会员数  
  318.             'guestcount' => $guestcount,//游客数  
  319.             'announcements' => $announcements,//公告  
  320.             'threads' => $threads,//主题数  
  321.             'posts' => $posts,//帖子数  
  322.             'todayposts' => $todayposts,//今天发表帖子数  
  323.             'onlineinfo' => $onlineinfo,//在线信息  
  324.             'announcepm' => $announcepm), getglobal('setting/memory/forumindex'));  
  325.     }  
  326.   
  327. else {  
  328.     require_once DISCUZ_ROOT.'./source/include/misc/misc_category.php';  
  329. }  
  330.   
  331.   
  332. if(defined('IN_ARCHIVER')) {  
  333.     include loadarchiver('forum/discuz');  
  334.     exit();  
  335. }  
  336.   
  337. //版块伸张或收缩  
  338. categorycollapse();  
  339.   
  340. /* 
  341.  * 1、gid-分区id不为空的情况,如果gid为空时,不会执行下面if...else...中的代码段 
  342.  * 2、$catlist:查看桌面 
  343.         echo "<pre>"; 
  344.         print_r($catlist); 
  345.         exit; 
  346.  * 3、$_G['category']全局变量的生成 
  347.  * 4、$_G['fid']全局变量的生成 
  348.  */  
  349. //gid不为空的情况  
  350. if($gid && !empty($catlist)) {//当前分区版块  
  351.     $_G['category'] = $catlist[$gid];//gid-分区id        当前分区数组数据,包括所有的子版块fid  
  352.     $forumseoset = array(//当前分区的SEO设置  
  353.         'seotitle' => $catlist[$gid]['seotitle'],//分区SEO标题  
  354.         'seokeywords' => $catlist[$gid]['keywords'],//分区SEO关键字  
  355.         'seodescription' => $catlist[$gid]['seodescription']//分区SEO描述  
  356.     );  
  357.     $seodata = array('fgroup' => $catlist[$gid]['name']);//当前分区名称  
  358.         //生成当前分区的SEO信息  
  359.     list($navtitle, $metadescription, $metakeywords) = get_seosetting('threadlist', $seodata, $forumseoset);  
  360.     if(empty($navtitle)) {  
  361.         $navtitle = $navtitle_g;  
  362.         $nobbname = false;  
  363.     } else {//默认执行  
  364.         $nobbname = true;  
  365.     }  
  366.     $_G['fid'] = $gid;//当前分区id  
  367. }  
  368.   
  369. /* 
  370.  * 1、对应模板文件:/data/diy/forum/discuz.htm  或者 /template/default/forum/discuz.htm,两者选其一 
  371.  * 2、使用template()函数显示已经存在的模板 
  372.  * 3、格式 include template("模板文件夹/模板名称无后缀");的方式进行解析 
  373.  * 4、在 source/function/function_core.php文件中定义 
  374.  * 5、如:include template('forum/mytest'); //使用自定义模板套系中的forum目录的mytest.htm 
  375.  */  
  376. include template('diy:forum/discuz:'.$gid);//结果:template("diy:forum/discuz:0")  
  377.   
  378. /* 
  379.  * 1、获取首页公告 
  380.  */  
  381. function get_index_announcements() {  
  382.     global $_G;//超级全局变量  
  383.     $announcements = '';//公告变量  
  384.     if($_G['cache']['announcements']) {//公告数组  
  385.         $readapmids = !empty($_G['cookie']['readapmid']) ? explode('D', $_G['cookie']['readapmid']) : array();  
  386.         foreach($_G['cache']['announcements'] as $announcement) {  
  387.                         //公告结束时间不为空,公告结束时间大于当前时间  
  388.             if(!$announcement['endtime'] || $announcement['endtime'] > TIMESTAMP && (empty($announcement['groups']) || in_array($_G['member']['groupid'], $announcement['groups']))) {  
  389.                 if(empty($announcement['type'])) {//公告类型为空的情况  
  390.                     $announcements .= '<li><span><a href="forum.php?mod=announcement&id='.$announcement['id'].'" target="_blank" class="xi2">'.$announcement['subject'].  
  391.                         '</a></span><em>('.dgmdate($announcement['starttime'], 'd').')</em></li>';  
  392.                 } elseif($announcement['type'] == 1) {//公告类型为1的情况  
  393.                     $announcements .= '<li><span><a href="'.$announcement['message'].'" target="_blank" class="xi2">'.$announcement['subject'].  
  394.                         '</a></span><em>('.dgmdate($announcement['starttime'], 'd').')</em></li>';  
  395.                 }  
  396.             }  
  397.         }  
  398.     }  
  399.     return $announcements;  
  400. }  
  401.   
  402. /* 
  403.  * 1、获取游客数据缓存 
  404.  */  
  405. function get_index_page_guest_cache() {  
  406.     global $_G;  
  407.     $indexcache = getcacheinfo(0);  
  408.     if(TIMESTAMP - $indexcache['filemtime'] > $_G['setting']['cacheindexlife']) {  
  409.         @unlink($indexcache['filename']);  
  410.         define('CACHE_FILE', $indexcache['filename']);  
  411.     } elseif($indexcache['filename']) {  
  412.         @readfile($indexcache['filename']);  
  413.         $updatetime = dgmdate($indexcache['filemtime'], 'H:i:s');  
  414.         $gzip = $_G['gzipcompress'] ? ', Gzip enabled' : '';  
  415.         echo "<script type="text/javascript">  
  416.             if($('debuginfo')) {  
  417.                 $('debuginfo').innerHTML = '. This page is cached  at $updatetime $gzip .';  
  418.             }  
  419.             </script>";  
  420.         exit();  
  421.     }  
  422. }  
  423.   
  424. /* 
  425.  * 1、获取论坛首页缓存 
  426.  */  
  427. function get_index_memory_by_groupid($key) {  
  428.     $enable = getglobal('setting/memory/forumindex');  
  429.     if($enable !== null && memory('check')) {  
  430.         if(IS_ROBOT) {  
  431.             $key = 'for_robot';  
  432.         }  
  433.         $ret = memory('get', 'forum_index_page_'.$key);  
  434.         define('FORUM_INDEX_PAGE_MEMORY', $ret ? 1 : 0);  
  435.         if($ret) {  
  436.             return $ret;  
  437.         }  
  438.     }  
  439.     return array('none' => null);  
  440. }  
  441.   
  442. /* 
  443.  * 1、获取首页在线信息详情 
  444.  */  
  445. function get_index_online_details() {  
  446.     $showoldetails = getgpc('showoldetails');  
  447.     switch($showoldetails) {  
  448.         case 'no': dsetcookie('onlineindex', ''); break;  
  449.         case 'yes': dsetcookie('onlineindex', 1, 86400 * 365); break;  
  450.     }  
  451.     return $showoldetails;  
  452. }  
  453.   
  454. /* 
  455.  * 1、版块绑定的域名 
  456.  */  
  457. function do_forum_bind_domains() {  
  458.     global $_G;  
  459.     if($_G['setting']['binddomains'] && $_G['setting']['forumdomains']) {  
  460.         $loadforum = isset($_G['setting']['binddomains'][$_SERVER['HTTP_HOST']]) ? max(0, intval($_G['setting']['binddomains'][$_SERVER['HTTP_HOST']])) : 0;  
  461.         if($loadforum) {  
  462.             dheader('Location: '.$_G['setting']['siteurl'].'/forum.php?mod=forumdisplay&fid='.$loadforum);  
  463.         }  
  464.     }  
  465. }  
  466.   
  467. //版块伸张或收缩功能函数  
  468. function categorycollapse() {  
  469.     global $_G, $collapse, $catlist;  
  470.     if(!$_G['uid']) {  
  471.         return;  
  472.     }  
  473.         //此时 fid-分区id   forum-可以查看桌面  
  474.         //如果是首页,那么就会有多个分区  
  475.     foreach($catlist as $fid => $forum) {  
  476.         if(!isset($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], '_category_'.$fid.'_') === FALSE) {  
  477.             $catlist[$fid]['collapseimg'] = 'collapsed_no.gif';  
  478.             $collapse['category_'.$fid] = '';  
  479.         } else {  
  480.             $catlist[$fid]['collapseimg'] = 'collapsed_yes.gif';//伸展或收缩图片  
  481.             $collapse['category_'.$fid] = 'display: none';//跟html标签的id属性值有关  
  482.         }  
  483.     }  
  484.     if(!isset($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], '_category_0_') === FALSE) {  
  485.         $collapse['collapseimg_0'] = 'collapsed_no.gif';//伸展或收缩图片  
  486.         $collapse['category_0'] = '';  
  487.     } else {  
  488.         $collapse['collapseimg_0'] = 'collapsed_yes.gif';//伸展或收缩图片  
  489.         $collapse['category_0'] = 'display: none';  
  490.     }  
  491. }  
  492. ?>  
原文地址:https://www.cnblogs.com/wuhaonihao/p/4949830.html