DiscuzX 论坛 forum_forumdisplay.php 分析
2020-4-28
5002
<?php
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: forum_forumdisplay.php 19151 2010-12-20 06:40:34Z monkey $
*/
/*
注:分析了一部分,没分析的都是一些设置方面的
核心文件就不分析了,网上的不少。也挺好。一会说说缓存是怎么调用和使用的
能力有限,有错请指正。希望有所帮助。
*/
/*
* 根据forum.php的传递的操作方式 调用下列的缓存
* 'forumdisplay' => array('smilies', 'announcements_forum', 'globalstick', 'forums',
'icons', 'onlinelist', 'forumstick','threadtable_info', 'threadtableids', 'stamps'),
*
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
//调用forum函数文件
require_once libfile('function/forumlist');
//判断是否合法,跳转和提示
if($_G['forum']['redirect']) {
dheader("Location: {$_G[forum][redirect]}");
} elseif($_G['forum']['type'] == 'group') {
dheader("Location: forum.php?gid=$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]");
} elseif(empty($_G['forum']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'])) {
showmessage('forum_nonexistence', NULL);
}
//栏目id
$_G['action']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'] = $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'];
//获取排序的各种参数
$_G['gp_specialtype'] = isset($_G['gp_specialtype']) ? $_G['gp_specialtype'] : '';
$_G['gp_dateline'] = isset($_G['gp_dateline']) ? intval($_G['gp_dateline']) : 0;
$_G['gp_digest'] = isset($_G['gp_digest']) ? 1 : '';//精华
$_G['gp_archiveid'] = isset($_G['gp_archiveid']) ? intval($_G['gp_archiveid']) : 0;
//是否列出详细的在线会员列表(下面还有一大堆的设置只有满足以后才可以开启)
$showoldetails = isset($_G['gp_showoldetails']) ? $_G['gp_showoldetails'] : '';
switch($showoldetails) {
case 'no': dsetcookie('onlineforum', ''); break;
case 'yes': dsetcookie('onlineforum', 1, 31536000); break;
}
//过滤分类名称 与 扩展
$_G['forum']['name'] = strip_tags($_G['forum']['name']) ? strip_tags($_G['forum']['name']) : $_G['forum']['name'];
$_G['forum']['extra'] = unserialize($_G['forum']['extra']);
if(!is_array($_G['forum']['extra'])) {
$_G['forum']['extra'] = array();
}
//获取上面提到的缓存主题表信息
$threadtable_info = !empty($_G['cache']['threadtable_info']) ? $_G['cache']['threadtable_info'] : array();
$forumarchive = array();
//判断如果存在该怎 有存档表那么调用下面的信息
if($_G['forum']['archive']) {
$query = DB::query("SELECT * FROM ".DB::table('forum_forum_threadtable')." WHERE ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='{$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']}'");
while($archive = DB::fetch($query)) {
$forumarchive[$archive['threadtableid']] = array(
'displayname' => htmlspecialchars($threadtable_info[$archive['threadtableid']]['displayname']),
'threads' => $archive['threads'],
'posts' => $archive['posts'],
);
if(empty($forumarchive[$archive['threadtableid']]['displayname'])) {
$forumarchive[$archive['threadtableid']]['displayname'] = lang('forum/template', 'forum_archive').' '.$archive['threadtableid'];
}
}
}
//位置与关键字与标题之类的
if($_G['forum']['type'] == 'forum') {
if(empty($_G['gp_archiveid'])) {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> <a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['forum']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'">'.$_G['forum']['name'].'</a>';
} else {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> '.'<a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'">'.$_G['forum']['name'].'</a> <em>›</em> '.$forumarchive[$_G['gp_archiveid']]['displayname'];
}
$navtitle = $_G['forum']['name'];
} else {
$forumup = $_G['forum']['status'] == 3 ? '' : $_G['cache']['forums'][$_G['forum']['fup']]['name'];
if(empty($_G['gp_archiveid'])) {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> <a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['forum']['fup'].'">'.$forumup.'</a> <em>›</em> '.$_G['forum']['name'];
} else {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> <a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['forum']['fup'].'">'.$forumup.'</a> <em>›</em> '.'<a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'">'.$_G['forum']['name'].'</a> <em>›</em> '.$forumarchive[$_G['gp_archiveid']]['displayname'];
}
$navtitle = $_G['forum']['name'].' - '.strip_tags($forumup);
}
$metakeywords = $_G['forum']['keywords'];
if(!$metakeywords) {
$metakeywords = $_G['forum']['name'];
}
$metadescription = $_G['forum']['description'];
if(!$metadescription) {
$metadescription = $_G['forum']['name'];
}
//rss
$rssauth = $_G['rssauth'];
$rsshead = $_G['setting']['rssstatus'] ? ('<link rel="alternate" type="application/rss+xml" title="'.$_G['setting']['bbname'].' - '.$navtitle.'" href="'.$_G['siteurl'].'forum.php?mod=rss&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'&auth='.$rssauth."\" />\n") : '';
$metakeywords = !$_G['forum']['keywords'] ? $_G['forum']['name'] : $_G['forum']['keywords'];
$metadescription = !$_G['forum']['description'] ? $_G['forum']['name'] : strip_tags($_G['forum']['description']);
//论坛版块的状态 如果等于3的话,说明该怎为群组
if($_G['forum']['status'] == 3) {
$navtitle = $_G['forum']['name'].' - '.$_G['setting']['navs'][3]['navname'];
$metakeywords = $_G['forum']['metakeywords'];
$metadescription = $_G['forum']['description'];
$_G['seokeywords'] = $_G['setting']['seokeywords']['group'];
$_G['seodescription'] = $_G['setting']['seodescription']['group'];
$action = getgpc('action') ? $_G['gp_action'] : 'list';
require_once libfile('function/group');
$status = groupperm($_G['forum'], $_G['uid']);
if($status == -1) {
showmessage('forum_not_group', 'group.php');
} elseif($status == 1) {
showmessage('forum_group_status_off');
} elseif($status == 2) {
showmessage('forum_group_noallowed', 'forum.php?mod=group&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
} elseif($status == 3) {
showmessage('forum_group_moderated', 'forum.php?mod=group&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
}
$_G['forum']['icon'] = get_groupimg($_G['forum']['icon'], 'icon');
$_G['grouptypeid'] = $_G['forum']['fup'];
$_G['forum']['dateline'] = dgmdate($_G['forum']['dateline'], 'd');
$groupnav = get_groupnav($_G['forum']);
$onlinemember = grouponline($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
$groupmanagers = $_G['forum']['moderators'];
$groupcache = getgroupcache($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], array('replies', 'views', 'digest', 'lastpost', 'ranking', 'activityuser', 'newuserlist'));
}
$_G['forum']['banner'] = get_forumimg($_G['forum']['banner']);
//版块权限
if($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm']) && !$_G['forum']['allowview']) {
showmessagenoperm('viewperm', $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], $_G['forum']['formulaperm']);
} elseif($_G['forum']['formulaperm']) {
formulaperm($_G['forum']['formulaperm']);
}
//版块密码
if($_G['forum']['password']) {
if($_G['gp_action'] == 'pwverify') {
if($_G['gp_pw'] != $_G['forum']['password']) {
showmessage('forum_passwd_incorrect', NULL);
} else {
dsetcookie('="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fidpw'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], $_G['gp_pw']);
showmessage('forum_passwd_correct', "forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]");
}
} elseif($_G['forum']['password'] != $_G['cookie']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fidpw'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]) {
include template('forum/forumdisplay_passwd');
exit();
}
}
if(!isset($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], 'forum_rules_'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']) === FALSE) {
$collapse['forum_rules'] = '';
$collapse['forum_rulesimg'] = 'no';
} else {
$collapse['forum_rules'] = 'display: none';
$collapse['forum_rulesimg'] = 'yes';
}
//? DX的主题分表功能 主题分表:主题分表功能可将 forum_thread 表(包含主题标题、创建时间等信息,但不包含主题及回复内容)分在多个数据表中。
// 具体的信息可查看 后台->站长->主题分表->分表管理 当中查看和设置
$threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
//得到最后该版块主题所属哪个表当中
$threadtable = $_G['gp_archiveid'] && in_array($_G['gp_archiveid'], $threadtableids) ? "forum_thread_{$_G['gp_archiveid']}" : 'forum_thread';
if($_G['setting']['allowmoderatingthread'] && $_G['uid']) {
$threadmodcount = DB::result_first("SELECT COUNT(*) FROM ".DB::table($threadtable)." WHERE ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='{$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']}' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND displayorder='-2' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND authorid='{$_G['uid']}'");
}
if($_G['forum']['modworks'] || $_G['forum']['modnewposts']) {
$_G['forum']['modnewposts'] && $_G['forum']['modworks'] = 1;
$modnum = $_G['group']['allowmodpost'] ? getcountofposts(DB::table('forum_post'), "invisible='-2' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]'") : 0;
$modusernum = $_G['group']['allowmoduser'] ? DB::result_first("SELECT COUNT(*) FROM ".DB::table('common_member_validate')." WHERE status='0'") : 0;
}
$optionadd = $filterurladd = $searchsorton = '';
$quicksearchlist = array();
if(!empty($_G['forum']['threadsorts']['types'])) {
require_once libfile('function/threadsort');
$showpic = intval($_G['gp_showpic']);
$templatearray = $sortoptionarray = array();
foreach($_G['forum']['threadsorts']['types'] as $stid => $sortname) {
loadcache(array('threadsort_option_'.$stid, 'threadsort_template_'.$stid));
$templatearray[$stid] = $_G['cache']['threadsort_template_'.$stid]['subject'];
$sortoptionarray[$stid] = $_G['cache']['threadsort_option_'.$stid];
}
if(!empty($_G['forum']['threadsorts']['defaultshow']) && empty($_G['gp_sortid']) && empty($_G['gp_sortall'])) {
$_G['gp_sortid'] = $_G['forum']['threadsorts']['defaultshow'];
$filterurladd = '&filter=sort';
}
$_G['gp_sortid'] = $_G['gp_sortid'] ? $_G['gp_sortid'] : $_G['gp_searchsortid'];
if(isset($_G['gp_sortid']) && $_G['forum']['threadsorts']['types'][$_G['gp_sortid']]) {
$searchsortoption = $sortoptionarray[$_G['gp_sortid']];
$quicksearchlist = quicksearch($searchsortoption);
}
}
//版主用户名列表 即:版主信息
$moderatedby = $_G['forum']['status'] != 3 ? moddisplay($_G['forum']['moderators'], 'forumdisplay') : '';
//高亮
$_G['gp_highlight'] = empty($_G['gp_highlight']) ? '' : htmlspecialchars($_G['gp_highlight']);
//判断该版块主题是否在起用自动关闭的功能 后台有设置 论坛-》版块管理-》帖子选项
if($_G['forum']['autoclose']) {
$closedby = $_G['forum']['autoclose'] > 0 ? 'dateline' : 'lastpost';
$_G['forum']['autoclose'] = abs($_G['forum']['autoclose']) * 86400;
}
//调用子版块 如果存在
$subexists = 0;
foreach($_G['cache']['forums'] as $sub) {
if($sub['type'] == 'sub' && $sub['fup'] == $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'] && (!$_G['setting']['hideprivate'] || !$sub['viewperm'] || forumperm($sub['viewperm']) || strstr($sub['users'], "\t$_G[uid]\t"))) {
if(!$sub['status']) {
continue;
}
$subexists = 1;
$sublist = array();
$sql = !empty($_G['member']['accessmasks']) ? "SELECT f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid, f.fup, f.type, f.name, f.threads, f.posts, f.todayposts, f.lastpost, f.domain, ff.description, ff.moderators, ff.icon, ff.viewperm, ff.extra, ff.redirect, a.allowview FROM ".DB::table('forum_forum')." f
LEFT JOIN ".DB::table('forum_forumfield')." ff ON ff.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid
LEFT JOIN ".DB::table('forum_access')." a ON a.uid='$_G[uid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND a.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid
WHERE fup='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND status>'0' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND type='sub' ORDER BY f.displayorder"
: "SELECT f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid, f.fup, f.type, f.name, f.threads, f.posts, f.todayposts, f.lastpost, f.domain, ff.description, ff.moderators, ff.icon, ff.viewperm, ff.extra, ff.redirect FROM ".DB::table('forum_forum')." f
LEFT JOIN ".DB::table('forum_forumfield')." ff USING(="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid)
WHERE f.fup='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND f.status>'0' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND f.type='sub' ORDER BY f.displayorder";
$query = DB::query($sql);
while($sub = DB::fetch($query)) {
$sub['extra'] = unserialize($sub['extra']);
if(!is_array($sub['extra'])) {
$sub['extra'] = array();
}
if(forum($sub)) {
$sub['orderid'] = count($sublist);
$sublist[] = $sub;
}
}
break;
}
}
if(!empty($_G['gp_archiveid']) && in_array($_G['gp_archiveid'], $threadtableids)) {
$subexists = 0;
}
if($subexists) {
//设置显示的宽度和一行显示几个的问题
if($_G['forum']['forumcolumns']) {
$_G['forum']['forumcolwidth'] = (floor(100 / $_G['forum']['forumcolumns']) - 0.1).'%';
$_G['forum']['subscount'] = count($sublist);
$_G['forum']['endrows'] = '';
if($colspan = $_G['forum']['subscount'] % $_G['forum']['forumcolumns']) {
while(($_G['forum']['forumcolumns'] - $colspan) > 0) {
$_G['forum']['endrows'] .= '<td> </td>';
$colspan ++;
}
$_G['forum']['endrows'] .= '</tr>';
}
}
//折叠的图标
if(empty($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], 'subforum_'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']) === FALSE) {
$collapse['subforum'] = '';
$collapseimg['subforum'] = 'collapsed_no.gif';
} else {
$collapse['subforum'] = 'display: none';
$collapseimg['subforum'] = 'collapsed_yes.gif';
}
}
//分页
$page = $_G['page'];
$subforumonly = $_G['forum']['simple'] & 1;
$simplestyle = !$_G['forum']['allowside'] || $page > 1 ? true : false;
if($subforumonly) {
$_G['setting']['fastpost'] = false;
$forummenu = '';
if($_G['setting']['forumjump']) {
$forummenu = forumselect(FALSE, 1);
}
if($_G['gp_archiver']) {
include loadarchiver('forum/forumdisplay');
} else {
include template('diy:forum/forumdisplay:'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
}
exit();
}
$page = $_G['setting']['threadmaxpages'] && $page > $_G['setting']['threadmaxpages'] ? 1 : $page;
$start_limit = ($page - 1) * $_G['tpp'];
if($_G['forum']['modrecommend'] && $_G['forum']['modrecommend']['open']) {
$_G['forum']['recommendlist'] = recommendupdate($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], $_G['forum']['modrecommend'], '', 1);
}
$recommendgroups = array();
if($_G['forum']['status'] != 3) {
loadcache('forumrecommend');
$recommendgroups = $_G['cache']['forumrecommend'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']];
}
if(!$simplestyle || !$_G['forum']['allowside'] && $page == 1) {
if($_G['cache']['announcements_forum']) {
$announcement = $_G['cache']['announcements_forum'];
$announcement['starttime'] = dgmdate($announcement['starttime'], 'd');
} else {
$announcement = NULL;
}
}
$filteradd = $sortoptionurl = $sp = '';
$sorturladdarray = $selectadd = array();
$forumdisplayadd = array('orderby' => '');
$specialtype = array('poll' => 1, 'trade' => 2, 'reward' => 3, 'activity' => 4, 'debate' => 5);
//筛选字段
$filterfield = array('digest', 'recommend', 'typeid', 'sortid', 'special', 'dateline', 'specialtype', 'author', 'reply', 'view', 'lastpost', 'heat', 'page', 'moderate');
foreach ($filterfield as $v) {
$forumdisplayadd[$v] = '';
}
//获取的筛选字段信息
$filter = isset($_G['gp_filter']) && in_array($_G['gp_filter'], $filterfield) ? $_G['gp_filter'] : '';
if($filter) {
if($query_string = $_SERVER['QUERY_STRING']) {
$query_string = substr($query_string, (strpos($query_string, "&") + 1));
parse_str($query_string, $geturl);
$geturl = daddslashes($geturl, 1);
if($geturl && is_array($geturl)) {
$issort = isset($_G['gp_sortid']) && isset($_G['forum']['threadsorts']['types'][$_G['gp_sortid']]) && $quicksearchlist ? TRUE : FALSE;
$selectadd = $issort ? $geturl : array();
foreach($filterfield as $option) {
foreach($geturl as $field => $value) {
if(in_array($field, $filterfield) && $option != $field && $field != 'page') {
$forumdisplayadd[$option] .= '&'.$field.'='.rawurlencode($value);
}
}
if($issort) {
$sfilterfield = array_merge(array('filter', 'sortid', 'orderby', '="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'), $filterfield);
foreach($geturl as $soption => $value) {
$forumdisplayadd[$soption] .= !in_array($soption, $sfilterfield) ? "&$soption=".rawurlencode($value) : '';
}
}
}
if($issort && is_array($quicksearchlist)) {
foreach($quicksearchlist as $option) {
$identifier = $option['identifier'];
foreach($geturl as $option => $value) {
$sorturladdarray[$identifier] .= !in_array($option, array('filter', 'sortid', 'orderby', '="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid', 'searchsort', $identifier)) ? "&$option=$value" : '';
}
}
}
foreach($geturl as $field => $value) {
if($field != 'page' && $field != '="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid') {
$multiadd[] = $field.'='.rawurlencode($value);
if(in_array($field, $filterfield)) {
$filteradd .= $sp;
if($field == 'digest') {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND digest>'0'";
} elseif($field == 'recommend' && $_G['setting']['recommendthread']['status']) {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND recommends>'".intval($_G['setting']['recommendthread']['iconlevels'][0])."'";
} elseif($field == 'specialtype') {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND special='$specialtype[$value]'";
} elseif($field == 'dateline') {
$filteradd .= $value ? "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND lastpost>='".(TIMESTAMP - $value)."'" : '';
} else {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND $field='$value'";
}
$sp = ' ';
}
}
}
}
}
$simplestyle = true;
}
//排序方式 以时间、ID等
if(!empty($_G['gp_orderby']) && in_array($_G['gp_orderby'], array('lastpost', 'dateline', 'replies', 'views', 'recommends', 'heats'))) {
$forumdisplayadd['orderby'] .= '&orderby='.$_G['gp_orderby'];
} else {
$_G['gp_orderby'] = isset($_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['orderby']) ? $_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['orderby'] : 'lastpost';
}
//是倒序还是正序排序
if(!empty($_G['gp_ascdesc']) && in_array($ascdesc, array('ASC', 'DESC'))) {
$forumdisplayadd['ascdesc'] .= '&ascdesc='.$_G['gp_ascdesc'];
} else {
$_G['gp_ascdesc'] = isset($_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['ascdesc']) ? $_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['ascdesc'] : 'DESC';
}
$check = array();
$check[$filter] = $check[$_G['gp_orderby']] = $check[$_G['gp_ascdesc']] = 'selected="selected"';
//print_r($_G['forum']);
//判断如果不是群组的版块的话 同时 判断 是否显示边栏
//统计和计算在线用户信息
if(($_G['forum']['status'] != 3) || !empty($_G['forum']['threadsorts']['templatelist'])) {
echo 'ddd';updatesession();
$onlinenum = getonlinenum($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
if(!IS_ROBOT && ($_G['setting']['whosonlinestatus'] == 2 || $_G['setting']['whosonlinestatus'] == 3)) {
$_G['setting']['whosonlinestatus'] = 1;
//详细状态
/*
* $_G['setting']['whosonline_contract']
* 后台->界面->界面设置->论坛首页设置->缩略显示在线列表
*/
$detailstatus = $showoldetails == 'yes' || (((!isset($_G['cookie']['onlineforum']) && !$_G['setting']['whosonline_contract']) || $_G['cookie']['onlineforum']) && !$showoldetails);
if($detailstatus) {
$actioncode = lang('forum/action');
$whosonline = array();
$forumname = strip_tags($_G['forum']['name']);
$query = DB::query("SELECT uid, groupid, username, invisible, lastactivity FROM ".DB::table('common_session')." WHERE uid>'0' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND invisible='0' ORDER BY lastactivity DESC LIMIT 12");
$_G['setting']['whosonlinestatus'] = 1;
while($online = DB::fetch($query)) {
if($online['uid']) {
$online['icon'] = isset($_G['cache']['onlinelist'][$online['groupid']]) ? $_G['cache']['onlinelist'][$online['groupid']] : $_G['cache']['onlinelist'][0];
} else {
$online['icon'] = $_G['cache']['onlinelist'][7];
$online['username'] = $_G['cache']['onlinelist']['guest'];
}
$online['lastactivity'] = dgmdate($online['lastactivity'], 't');
$whosonline[] = $online;
}
unset($online);
}
} else {
$_G['setting']['whosonlinestatus'] = 0;
}
}
$forumdisplayadd['page'] = '';
if($_G['forum']['threadsorts']['types'] && $sortoptionarray && ($_G['gp_searchoption'] || $_G['gp_searchsort'])) {
$sortid = intval($_G['gp_sortid']);
if($_G['gp_searchoption']){
$forumdisplayadd['page'] = '&sortid='.$sortid;
foreach($_G['gp_searchoption'] as $optionid => $option) {
$identifier = $sortoptionarray[$sortid][$optionid]['identifier'];
$forumdisplayadd['page'] .= $option['value'] ? "&searchoption[$optionid][value]=$option[value]&searchoption[$optionid][type]=$option[type]" : '';
}
}
if($searchsorttids = sortsearch($_G['gp_sortid'], $sortoptionarray, $_G['gp_searchoption'], $selectadd, $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'])) {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND t.tid IN (".dimplode($searchsorttids).")";
}
}
//判断是否有 筛选条件、??是否有存档表
if(empty($filter) && empty($_G['gp_sortid']) && empty($_G['gp_archiveid']) && empty($_G['forum']['archive'])) {
$_G['forum_threadcount'] = $_G['forum']['threads'];
} elseif(!$_G['gp_moderate']) {
$indexadd = '';
if(strexists($filteradd, "t.digest>'0'")) {
$indexadd = " FORCE INDEX (digest) ";
}
$_G['forum_threadcount'] = DB::result_first("SELECT COUNT(*) FROM ".DB::table($threadtable)." t $indexadd WHERE t.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='{$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']}' $filteradd ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND t.displayorder>='0'");
}
$thisgid = $_G['forum']['type'] == 'forum' ? $_G['forum']['fup'] : (!empty($_G['cache']['forums'][$_G['forum']['fup']]['fup']) ? $_G['cache']['forums'][$_G['forum']['fup']]['fup'] : 0);
$forumstickycount = $stickycount = $stickytids = 0;
if($_G['setting']['globalstick'] && $_G['forum']['allowglobalstick']) {
$stickytids = $_G['cache']['globalstick']['global']['tids'].(empty($_G['cache']['globalstick']['categories'][$thisgid]['count']) ? '' : ','.$_G['cache']['globalstick']['categories'][$thisgid]['tids']);
$stickytids = trim($stickytids, ', ');
if ($stickytids === ''){
$stickytids = '0';
}
if($_G['forum']['status'] != 3) {
$stickycount = $_G['cache']['globalstick']['global']['count'];
if(!empty($_G['cache']['globalstick']['categories'][$thisgid])) {
$stickycount += $_G['cache']['globalstick']['categories'][$thisgid]['count'];
}
}
}
//该版块论坛 帖子置顶 主题id
$forumstickytids = array();
//加载论坛置顶帖子缓存信息
loadcache('forumstick');
$_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']] = isset($_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]) ? $_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']] : array();
$forumstickycount = count($_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]);
foreach($_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']] as $forumstickthread) {
$forumstickytids[] = $forumstickthread['tid'];
}
if(!empty($forumstickytids)) {
$forumstickytids = dimplode($forumstickytids);
$stickytids .= ", $forumstickytids";
}
$stickycount += $forumstickycount;
//判断是否进行筛选
$filterbool = !empty($filter) && in_array($filter, $filterfield);
//统计主题个数包含 置顶主题
$_G['forum_threadcount'] += $filterbool ? 0 : $stickycount;
$forumdisplayadd['page'] = !empty($forumdisplayadd['page']) ? $forumdisplayadd['page'] : '';
$multipage_archive = $_G['gp_archiveid'] && in_array($_G['gp_archiveid'], $threadtableids) ? "&archiveid={$_G['gp_archiveid']}" : '';
$multipage = multi($_G['forum_threadcount'], $_G['tpp'], $page, "forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]".($multiadd ? '&'.implode('&', $multiadd) : '')."$multipage_archive", $_G['setting']['threadmaxpages']);
$extra = rawurlencode(!IS_ROBOT ? 'page='.$page.($forumdisplayadd['page'] ? '&filter='.$filter.$forumdisplayadd['page'] : '').($forumdisplayadd['orderby'] ? $forumdisplayadd['orderby'] : '') : 'page=1');
//放不下,40000个字符。下面的都是一些主题显示和配置的信息,不讨论了。
核心文件的分析可参考:
[url]http://www.woniu.us/discuzx/350.html[/url]
[url]http://jackchen0227.javaeye.com/blog/827389[/url]
数据字典:
[url]http://www.discuz.net/thread-2051314-1-1.html[/url]
?>
/**
* [Discuz!] (C)2001-2099 Comsenz Inc.
* This is NOT a freeware, use is subject to license terms
*
* $Id: forum_forumdisplay.php 19151 2010-12-20 06:40:34Z monkey $
*/
/*
注:分析了一部分,没分析的都是一些设置方面的
核心文件就不分析了,网上的不少。也挺好。一会说说缓存是怎么调用和使用的
能力有限,有错请指正。希望有所帮助。
*/
/*
* 根据forum.php的传递的操作方式 调用下列的缓存
* 'forumdisplay' => array('smilies', 'announcements_forum', 'globalstick', 'forums',
'icons', 'onlinelist', 'forumstick','threadtable_info', 'threadtableids', 'stamps'),
*
*/
if(!defined('IN_DISCUZ')) {
exit('Access Denied');
}
//调用forum函数文件
require_once libfile('function/forumlist');
//判断是否合法,跳转和提示
if($_G['forum']['redirect']) {
dheader("Location: {$_G[forum][redirect]}");
} elseif($_G['forum']['type'] == 'group') {
dheader("Location: forum.php?gid=$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]");
} elseif(empty($_G['forum']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'])) {
showmessage('forum_nonexistence', NULL);
}
//栏目id
$_G['action']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'] = $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'];
//获取排序的各种参数
$_G['gp_specialtype'] = isset($_G['gp_specialtype']) ? $_G['gp_specialtype'] : '';
$_G['gp_dateline'] = isset($_G['gp_dateline']) ? intval($_G['gp_dateline']) : 0;
$_G['gp_digest'] = isset($_G['gp_digest']) ? 1 : '';//精华
$_G['gp_archiveid'] = isset($_G['gp_archiveid']) ? intval($_G['gp_archiveid']) : 0;
//是否列出详细的在线会员列表(下面还有一大堆的设置只有满足以后才可以开启)
$showoldetails = isset($_G['gp_showoldetails']) ? $_G['gp_showoldetails'] : '';
switch($showoldetails) {
case 'no': dsetcookie('onlineforum', ''); break;
case 'yes': dsetcookie('onlineforum', 1, 31536000); break;
}
//过滤分类名称 与 扩展
$_G['forum']['name'] = strip_tags($_G['forum']['name']) ? strip_tags($_G['forum']['name']) : $_G['forum']['name'];
$_G['forum']['extra'] = unserialize($_G['forum']['extra']);
if(!is_array($_G['forum']['extra'])) {
$_G['forum']['extra'] = array();
}
//获取上面提到的缓存主题表信息
$threadtable_info = !empty($_G['cache']['threadtable_info']) ? $_G['cache']['threadtable_info'] : array();
$forumarchive = array();
//判断如果存在该怎 有存档表那么调用下面的信息
if($_G['forum']['archive']) {
$query = DB::query("SELECT * FROM ".DB::table('forum_forum_threadtable')." WHERE ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='{$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']}'");
while($archive = DB::fetch($query)) {
$forumarchive[$archive['threadtableid']] = array(
'displayname' => htmlspecialchars($threadtable_info[$archive['threadtableid']]['displayname']),
'threads' => $archive['threads'],
'posts' => $archive['posts'],
);
if(empty($forumarchive[$archive['threadtableid']]['displayname'])) {
$forumarchive[$archive['threadtableid']]['displayname'] = lang('forum/template', 'forum_archive').' '.$archive['threadtableid'];
}
}
}
//位置与关键字与标题之类的
if($_G['forum']['type'] == 'forum') {
if(empty($_G['gp_archiveid'])) {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> <a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['forum']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'">'.$_G['forum']['name'].'</a>';
} else {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> '.'<a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'">'.$_G['forum']['name'].'</a> <em>›</em> '.$forumarchive[$_G['gp_archiveid']]['displayname'];
}
$navtitle = $_G['forum']['name'];
} else {
$forumup = $_G['forum']['status'] == 3 ? '' : $_G['cache']['forums'][$_G['forum']['fup']]['name'];
if(empty($_G['gp_archiveid'])) {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> <a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['forum']['fup'].'">'.$forumup.'</a> <em>›</em> '.$_G['forum']['name'];
} else {
$navigation = '<em>›</em> <a href="forum.php">'.$_G['setting']['navs'][2]['navname'].'</a> <em>›</em> <a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['forum']['fup'].'">'.$forumup.'</a> <em>›</em> '.'<a href="forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'">'.$_G['forum']['name'].'</a> <em>›</em> '.$forumarchive[$_G['gp_archiveid']]['displayname'];
}
$navtitle = $_G['forum']['name'].' - '.strip_tags($forumup);
}
$metakeywords = $_G['forum']['keywords'];
if(!$metakeywords) {
$metakeywords = $_G['forum']['name'];
}
$metadescription = $_G['forum']['description'];
if(!$metadescription) {
$metadescription = $_G['forum']['name'];
}
//rss
$rssauth = $_G['rssauth'];
$rsshead = $_G['setting']['rssstatus'] ? ('<link rel="alternate" type="application/rss+xml" title="'.$_G['setting']['bbname'].' - '.$navtitle.'" href="'.$_G['siteurl'].'forum.php?mod=rss&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'].'&auth='.$rssauth."\" />\n") : '';
$metakeywords = !$_G['forum']['keywords'] ? $_G['forum']['name'] : $_G['forum']['keywords'];
$metadescription = !$_G['forum']['description'] ? $_G['forum']['name'] : strip_tags($_G['forum']['description']);
//论坛版块的状态 如果等于3的话,说明该怎为群组
if($_G['forum']['status'] == 3) {
$navtitle = $_G['forum']['name'].' - '.$_G['setting']['navs'][3]['navname'];
$metakeywords = $_G['forum']['metakeywords'];
$metadescription = $_G['forum']['description'];
$_G['seokeywords'] = $_G['setting']['seokeywords']['group'];
$_G['seodescription'] = $_G['setting']['seodescription']['group'];
$action = getgpc('action') ? $_G['gp_action'] : 'list';
require_once libfile('function/group');
$status = groupperm($_G['forum'], $_G['uid']);
if($status == -1) {
showmessage('forum_not_group', 'group.php');
} elseif($status == 1) {
showmessage('forum_group_status_off');
} elseif($status == 2) {
showmessage('forum_group_noallowed', 'forum.php?mod=group&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
} elseif($status == 3) {
showmessage('forum_group_moderated', 'forum.php?mod=group&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
}
$_G['forum']['icon'] = get_groupimg($_G['forum']['icon'], 'icon');
$_G['grouptypeid'] = $_G['forum']['fup'];
$_G['forum']['dateline'] = dgmdate($_G['forum']['dateline'], 'd');
$groupnav = get_groupnav($_G['forum']);
$onlinemember = grouponline($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
$groupmanagers = $_G['forum']['moderators'];
$groupcache = getgroupcache($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], array('replies', 'views', 'digest', 'lastpost', 'ranking', 'activityuser', 'newuserlist'));
}
$_G['forum']['banner'] = get_forumimg($_G['forum']['banner']);
//版块权限
if($_G['forum']['viewperm'] && !forumperm($_G['forum']['viewperm']) && !$_G['forum']['allowview']) {
showmessagenoperm('viewperm', $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], $_G['forum']['formulaperm']);
} elseif($_G['forum']['formulaperm']) {
formulaperm($_G['forum']['formulaperm']);
}
//版块密码
if($_G['forum']['password']) {
if($_G['gp_action'] == 'pwverify') {
if($_G['gp_pw'] != $_G['forum']['password']) {
showmessage('forum_passwd_incorrect', NULL);
} else {
dsetcookie('="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fidpw'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], $_G['gp_pw']);
showmessage('forum_passwd_correct', "forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]");
}
} elseif($_G['forum']['password'] != $_G['cookie']['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fidpw'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]) {
include template('forum/forumdisplay_passwd');
exit();
}
}
if(!isset($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], 'forum_rules_'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']) === FALSE) {
$collapse['forum_rules'] = '';
$collapse['forum_rulesimg'] = 'no';
} else {
$collapse['forum_rules'] = 'display: none';
$collapse['forum_rulesimg'] = 'yes';
}
//? DX的主题分表功能 主题分表:主题分表功能可将 forum_thread 表(包含主题标题、创建时间等信息,但不包含主题及回复内容)分在多个数据表中。
// 具体的信息可查看 后台->站长->主题分表->分表管理 当中查看和设置
$threadtableids = !empty($_G['cache']['threadtableids']) ? $_G['cache']['threadtableids'] : array();
//得到最后该版块主题所属哪个表当中
$threadtable = $_G['gp_archiveid'] && in_array($_G['gp_archiveid'], $threadtableids) ? "forum_thread_{$_G['gp_archiveid']}" : 'forum_thread';
if($_G['setting']['allowmoderatingthread'] && $_G['uid']) {
$threadmodcount = DB::result_first("SELECT COUNT(*) FROM ".DB::table($threadtable)." WHERE ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='{$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']}' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND displayorder='-2' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND authorid='{$_G['uid']}'");
}
if($_G['forum']['modworks'] || $_G['forum']['modnewposts']) {
$_G['forum']['modnewposts'] && $_G['forum']['modworks'] = 1;
$modnum = $_G['group']['allowmodpost'] ? getcountofposts(DB::table('forum_post'), "invisible='-2' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]'") : 0;
$modusernum = $_G['group']['allowmoduser'] ? DB::result_first("SELECT COUNT(*) FROM ".DB::table('common_member_validate')." WHERE status='0'") : 0;
}
$optionadd = $filterurladd = $searchsorton = '';
$quicksearchlist = array();
if(!empty($_G['forum']['threadsorts']['types'])) {
require_once libfile('function/threadsort');
$showpic = intval($_G['gp_showpic']);
$templatearray = $sortoptionarray = array();
foreach($_G['forum']['threadsorts']['types'] as $stid => $sortname) {
loadcache(array('threadsort_option_'.$stid, 'threadsort_template_'.$stid));
$templatearray[$stid] = $_G['cache']['threadsort_template_'.$stid]['subject'];
$sortoptionarray[$stid] = $_G['cache']['threadsort_option_'.$stid];
}
if(!empty($_G['forum']['threadsorts']['defaultshow']) && empty($_G['gp_sortid']) && empty($_G['gp_sortall'])) {
$_G['gp_sortid'] = $_G['forum']['threadsorts']['defaultshow'];
$filterurladd = '&filter=sort';
}
$_G['gp_sortid'] = $_G['gp_sortid'] ? $_G['gp_sortid'] : $_G['gp_searchsortid'];
if(isset($_G['gp_sortid']) && $_G['forum']['threadsorts']['types'][$_G['gp_sortid']]) {
$searchsortoption = $sortoptionarray[$_G['gp_sortid']];
$quicksearchlist = quicksearch($searchsortoption);
}
}
//版主用户名列表 即:版主信息
$moderatedby = $_G['forum']['status'] != 3 ? moddisplay($_G['forum']['moderators'], 'forumdisplay') : '';
//高亮
$_G['gp_highlight'] = empty($_G['gp_highlight']) ? '' : htmlspecialchars($_G['gp_highlight']);
//判断该版块主题是否在起用自动关闭的功能 后台有设置 论坛-》版块管理-》帖子选项
if($_G['forum']['autoclose']) {
$closedby = $_G['forum']['autoclose'] > 0 ? 'dateline' : 'lastpost';
$_G['forum']['autoclose'] = abs($_G['forum']['autoclose']) * 86400;
}
//调用子版块 如果存在
$subexists = 0;
foreach($_G['cache']['forums'] as $sub) {
if($sub['type'] == 'sub' && $sub['fup'] == $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'] && (!$_G['setting']['hideprivate'] || !$sub['viewperm'] || forumperm($sub['viewperm']) || strstr($sub['users'], "\t$_G[uid]\t"))) {
if(!$sub['status']) {
continue;
}
$subexists = 1;
$sublist = array();
$sql = !empty($_G['member']['accessmasks']) ? "SELECT f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid, f.fup, f.type, f.name, f.threads, f.posts, f.todayposts, f.lastpost, f.domain, ff.description, ff.moderators, ff.icon, ff.viewperm, ff.extra, ff.redirect, a.allowview FROM ".DB::table('forum_forum')." f
LEFT JOIN ".DB::table('forum_forumfield')." ff ON ff.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid
LEFT JOIN ".DB::table('forum_access')." a ON a.uid='$_G[uid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND a.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid
WHERE fup='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND status>'0' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND type='sub' ORDER BY f.displayorder"
: "SELECT f.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid, f.fup, f.type, f.name, f.threads, f.posts, f.todayposts, f.lastpost, f.domain, ff.description, ff.moderators, ff.icon, ff.viewperm, ff.extra, ff.redirect FROM ".DB::table('forum_forum')." f
LEFT JOIN ".DB::table('forum_forumfield')." ff USING(="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid)
WHERE f.fup='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND f.status>'0' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND f.type='sub' ORDER BY f.displayorder";
$query = DB::query($sql);
while($sub = DB::fetch($query)) {
$sub['extra'] = unserialize($sub['extra']);
if(!is_array($sub['extra'])) {
$sub['extra'] = array();
}
if(forum($sub)) {
$sub['orderid'] = count($sublist);
$sublist[] = $sub;
}
}
break;
}
}
if(!empty($_G['gp_archiveid']) && in_array($_G['gp_archiveid'], $threadtableids)) {
$subexists = 0;
}
if($subexists) {
//设置显示的宽度和一行显示几个的问题
if($_G['forum']['forumcolumns']) {
$_G['forum']['forumcolwidth'] = (floor(100 / $_G['forum']['forumcolumns']) - 0.1).'%';
$_G['forum']['subscount'] = count($sublist);
$_G['forum']['endrows'] = '';
if($colspan = $_G['forum']['subscount'] % $_G['forum']['forumcolumns']) {
while(($_G['forum']['forumcolumns'] - $colspan) > 0) {
$_G['forum']['endrows'] .= '<td> </td>';
$colspan ++;
}
$_G['forum']['endrows'] .= '</tr>';
}
}
//折叠的图标
if(empty($_G['cookie']['collapse']) || strpos($_G['cookie']['collapse'], 'subforum_'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']) === FALSE) {
$collapse['subforum'] = '';
$collapseimg['subforum'] = 'collapsed_no.gif';
} else {
$collapse['subforum'] = 'display: none';
$collapseimg['subforum'] = 'collapsed_yes.gif';
}
}
//分页
$page = $_G['page'];
$subforumonly = $_G['forum']['simple'] & 1;
$simplestyle = !$_G['forum']['allowside'] || $page > 1 ? true : false;
if($subforumonly) {
$_G['setting']['fastpost'] = false;
$forummenu = '';
if($_G['setting']['forumjump']) {
$forummenu = forumselect(FALSE, 1);
}
if($_G['gp_archiver']) {
include loadarchiver('forum/forumdisplay');
} else {
include template('diy:forum/forumdisplay:'.$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
}
exit();
}
$page = $_G['setting']['threadmaxpages'] && $page > $_G['setting']['threadmaxpages'] ? 1 : $page;
$start_limit = ($page - 1) * $_G['tpp'];
if($_G['forum']['modrecommend'] && $_G['forum']['modrecommend']['open']) {
$_G['forum']['recommendlist'] = recommendupdate($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'], $_G['forum']['modrecommend'], '', 1);
}
$recommendgroups = array();
if($_G['forum']['status'] != 3) {
loadcache('forumrecommend');
$recommendgroups = $_G['cache']['forumrecommend'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']];
}
if(!$simplestyle || !$_G['forum']['allowside'] && $page == 1) {
if($_G['cache']['announcements_forum']) {
$announcement = $_G['cache']['announcements_forum'];
$announcement['starttime'] = dgmdate($announcement['starttime'], 'd');
} else {
$announcement = NULL;
}
}
$filteradd = $sortoptionurl = $sp = '';
$sorturladdarray = $selectadd = array();
$forumdisplayadd = array('orderby' => '');
$specialtype = array('poll' => 1, 'trade' => 2, 'reward' => 3, 'activity' => 4, 'debate' => 5);
//筛选字段
$filterfield = array('digest', 'recommend', 'typeid', 'sortid', 'special', 'dateline', 'specialtype', 'author', 'reply', 'view', 'lastpost', 'heat', 'page', 'moderate');
foreach ($filterfield as $v) {
$forumdisplayadd[$v] = '';
}
//获取的筛选字段信息
$filter = isset($_G['gp_filter']) && in_array($_G['gp_filter'], $filterfield) ? $_G['gp_filter'] : '';
if($filter) {
if($query_string = $_SERVER['QUERY_STRING']) {
$query_string = substr($query_string, (strpos($query_string, "&") + 1));
parse_str($query_string, $geturl);
$geturl = daddslashes($geturl, 1);
if($geturl && is_array($geturl)) {
$issort = isset($_G['gp_sortid']) && isset($_G['forum']['threadsorts']['types'][$_G['gp_sortid']]) && $quicksearchlist ? TRUE : FALSE;
$selectadd = $issort ? $geturl : array();
foreach($filterfield as $option) {
foreach($geturl as $field => $value) {
if(in_array($field, $filterfield) && $option != $field && $field != 'page') {
$forumdisplayadd[$option] .= '&'.$field.'='.rawurlencode($value);
}
}
if($issort) {
$sfilterfield = array_merge(array('filter', 'sortid', 'orderby', '="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'), $filterfield);
foreach($geturl as $soption => $value) {
$forumdisplayadd[$soption] .= !in_array($soption, $sfilterfield) ? "&$soption=".rawurlencode($value) : '';
}
}
}
if($issort && is_array($quicksearchlist)) {
foreach($quicksearchlist as $option) {
$identifier = $option['identifier'];
foreach($geturl as $option => $value) {
$sorturladdarray[$identifier] .= !in_array($option, array('filter', 'sortid', 'orderby', '="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid', 'searchsort', $identifier)) ? "&$option=$value" : '';
}
}
}
foreach($geturl as $field => $value) {
if($field != 'page' && $field != '="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid') {
$multiadd[] = $field.'='.rawurlencode($value);
if(in_array($field, $filterfield)) {
$filteradd .= $sp;
if($field == 'digest') {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND digest>'0'";
} elseif($field == 'recommend' && $_G['setting']['recommendthread']['status']) {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND recommends>'".intval($_G['setting']['recommendthread']['iconlevels'][0])."'";
} elseif($field == 'specialtype') {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND special='$specialtype[$value]'";
} elseif($field == 'dateline') {
$filteradd .= $value ? "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND lastpost>='".(TIMESTAMP - $value)."'" : '';
} else {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND $field='$value'";
}
$sp = ' ';
}
}
}
}
}
$simplestyle = true;
}
//排序方式 以时间、ID等
if(!empty($_G['gp_orderby']) && in_array($_G['gp_orderby'], array('lastpost', 'dateline', 'replies', 'views', 'recommends', 'heats'))) {
$forumdisplayadd['orderby'] .= '&orderby='.$_G['gp_orderby'];
} else {
$_G['gp_orderby'] = isset($_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['orderby']) ? $_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['orderby'] : 'lastpost';
}
//是倒序还是正序排序
if(!empty($_G['gp_ascdesc']) && in_array($ascdesc, array('ASC', 'DESC'))) {
$forumdisplayadd['ascdesc'] .= '&ascdesc='.$_G['gp_ascdesc'];
} else {
$_G['gp_ascdesc'] = isset($_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['ascdesc']) ? $_G['cache']['forums'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]['ascdesc'] : 'DESC';
}
$check = array();
$check[$filter] = $check[$_G['gp_orderby']] = $check[$_G['gp_ascdesc']] = 'selected="selected"';
//print_r($_G['forum']);
//判断如果不是群组的版块的话 同时 判断 是否显示边栏
//统计和计算在线用户信息
if(($_G['forum']['status'] != 3) || !empty($_G['forum']['threadsorts']['templatelist'])) {
echo 'ddd';updatesession();
$onlinenum = getonlinenum($_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']);
if(!IS_ROBOT && ($_G['setting']['whosonlinestatus'] == 2 || $_G['setting']['whosonlinestatus'] == 3)) {
$_G['setting']['whosonlinestatus'] = 1;
//详细状态
/*
* $_G['setting']['whosonline_contract']
* 后台->界面->界面设置->论坛首页设置->缩略显示在线列表
*/
$detailstatus = $showoldetails == 'yes' || (((!isset($_G['cookie']['onlineforum']) && !$_G['setting']['whosonline_contract']) || $_G['cookie']['onlineforum']) && !$showoldetails);
if($detailstatus) {
$actioncode = lang('forum/action');
$whosonline = array();
$forumname = strip_tags($_G['forum']['name']);
$query = DB::query("SELECT uid, groupid, username, invisible, lastactivity FROM ".DB::table('common_session')." WHERE uid>'0' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND ="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]' ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND invisible='0' ORDER BY lastactivity DESC LIMIT 12");
$_G['setting']['whosonlinestatus'] = 1;
while($online = DB::fetch($query)) {
if($online['uid']) {
$online['icon'] = isset($_G['cache']['onlinelist'][$online['groupid']]) ? $_G['cache']['onlinelist'][$online['groupid']] : $_G['cache']['onlinelist'][0];
} else {
$online['icon'] = $_G['cache']['onlinelist'][7];
$online['username'] = $_G['cache']['onlinelist']['guest'];
}
$online['lastactivity'] = dgmdate($online['lastactivity'], 't');
$whosonline[] = $online;
}
unset($online);
}
} else {
$_G['setting']['whosonlinestatus'] = 0;
}
}
$forumdisplayadd['page'] = '';
if($_G['forum']['threadsorts']['types'] && $sortoptionarray && ($_G['gp_searchoption'] || $_G['gp_searchsort'])) {
$sortid = intval($_G['gp_sortid']);
if($_G['gp_searchoption']){
$forumdisplayadd['page'] = '&sortid='.$sortid;
foreach($_G['gp_searchoption'] as $optionid => $option) {
$identifier = $sortoptionarray[$sortid][$optionid]['identifier'];
$forumdisplayadd['page'] .= $option['value'] ? "&searchoption[$optionid][value]=$option[value]&searchoption[$optionid][type]=$option[type]" : '';
}
}
if($searchsorttids = sortsearch($_G['gp_sortid'], $sortoptionarray, $_G['gp_searchoption'], $selectadd, $_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid'])) {
$filteradd .= "="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND t.tid IN (".dimplode($searchsorttids).")";
}
}
//判断是否有 筛选条件、??是否有存档表
if(empty($filter) && empty($_G['gp_sortid']) && empty($_G['gp_archiveid']) && empty($_G['forum']['archive'])) {
$_G['forum_threadcount'] = $_G['forum']['threads'];
} elseif(!$_G['gp_moderate']) {
$indexadd = '';
if(strexists($filteradd, "t.digest>'0'")) {
$indexadd = " FORCE INDEX (digest) ";
}
$_G['forum_threadcount'] = DB::result_first("SELECT COUNT(*) FROM ".DB::table($threadtable)." t $indexadd WHERE t.="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid='{$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']}' $filteradd ="redTag" style="COLOR:#000000;BACKGROUND-COLOR:#ffff00">AND t.displayorder>='0'");
}
$thisgid = $_G['forum']['type'] == 'forum' ? $_G['forum']['fup'] : (!empty($_G['cache']['forums'][$_G['forum']['fup']]['fup']) ? $_G['cache']['forums'][$_G['forum']['fup']]['fup'] : 0);
$forumstickycount = $stickycount = $stickytids = 0;
if($_G['setting']['globalstick'] && $_G['forum']['allowglobalstick']) {
$stickytids = $_G['cache']['globalstick']['global']['tids'].(empty($_G['cache']['globalstick']['categories'][$thisgid]['count']) ? '' : ','.$_G['cache']['globalstick']['categories'][$thisgid]['tids']);
$stickytids = trim($stickytids, ', ');
if ($stickytids === ''){
$stickytids = '0';
}
if($_G['forum']['status'] != 3) {
$stickycount = $_G['cache']['globalstick']['global']['count'];
if(!empty($_G['cache']['globalstick']['categories'][$thisgid])) {
$stickycount += $_G['cache']['globalstick']['categories'][$thisgid]['count'];
}
}
}
//该版块论坛 帖子置顶 主题id
$forumstickytids = array();
//加载论坛置顶帖子缓存信息
loadcache('forumstick');
$_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']] = isset($_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]) ? $_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']] : array();
$forumstickycount = count($_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']]);
foreach($_G['cache']['forumstick'][$_G['="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid']] as $forumstickthread) {
$forumstickytids[] = $forumstickthread['tid'];
}
if(!empty($forumstickytids)) {
$forumstickytids = dimplode($forumstickytids);
$stickytids .= ", $forumstickytids";
}
$stickycount += $forumstickycount;
//判断是否进行筛选
$filterbool = !empty($filter) && in_array($filter, $filterfield);
//统计主题个数包含 置顶主题
$_G['forum_threadcount'] += $filterbool ? 0 : $stickycount;
$forumdisplayadd['page'] = !empty($forumdisplayadd['page']) ? $forumdisplayadd['page'] : '';
$multipage_archive = $_G['gp_archiveid'] && in_array($_G['gp_archiveid'], $threadtableids) ? "&archiveid={$_G['gp_archiveid']}" : '';
$multipage = multi($_G['forum_threadcount'], $_G['tpp'], $page, "forum.php?mod=forumdisplay&="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid=$_G[="redTag" style="COLOR:#941f20;BACKGROUND-COLOR:#4ae2f7">fid]".($multiadd ? '&'.implode('&', $multiadd) : '')."$multipage_archive", $_G['setting']['threadmaxpages']);
$extra = rawurlencode(!IS_ROBOT ? 'page='.$page.($forumdisplayadd['page'] ? '&filter='.$filter.$forumdisplayadd['page'] : '').($forumdisplayadd['orderby'] ? $forumdisplayadd['orderby'] : '') : 'page=1');
//放不下,40000个字符。下面的都是一些主题显示和配置的信息,不讨论了。
核心文件的分析可参考:
[url]http://www.woniu.us/discuzx/350.html[/url]
[url]http://jackchen0227.javaeye.com/blog/827389[/url]
数据字典:
[url]http://www.discuz.net/thread-2051314-1-1.html[/url]
?>
上一篇:您是组播用户,无法通过单播网络登录怎么解决?
下一篇:什么程序生成C:\WINDOWS\xzcsad目录
注册/登录/发贴 (0)