forum.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 811 行 · 第 1/3 页
PHP
811 行
$criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
}elseif($xoopsModuleConfig["read_mode"] == 1){
$topics = array();
$topic_lastread = newbb_getcookie('LT', true);
if(count($topic_lastread)>0) foreach($topic_lastread as $id=>$time){
if($time > $time_criterion) $topics[] = $id;
}
if(count($topics)>0){
$criteria_extra = ' AND t.topic_id NOT IN ('.implode(",", $topics).')';
}
$criteria_post = ' p.post_time > ' . max($GLOBALS['last_visit'], $startdate);
}
break;
case 'pending':
$post_on = ' p.topic_id = t.topic_id';
$criteria_post .= ' AND p.pid=0';
$criteria_approve = ' AND t.approved = 0';
break;
case 'deleted':
$criteria_approve = ' AND t.approved = -1';
break;
case 'all': // For viewall.php; do not display sticky topics at first
case 'active': // same as "all"
//$criteria_post = ' p.post_time > ' . $startdate;
break;
default:
$criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
$sort[] = 't.topic_sticky DESC';
break;
}
$select = 't.*, '.
' p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id, p.uid';
$from = $this->db->prefix("bb_topics") . ' t '.$leftjoin;
$where = $criteria_post. $criteria_forum . $criteria_extra . $criteria_approve;
if($excerpt){
$select .=', p.post_karma, p.require_reply, pt.post_text';
$from .= ' LEFT JOIN ' . $this->db->prefix('bb_posts_text') . ' pt ON pt.post_id = t.topic_last_post_id';
}
if($sortname == "u.uname"){
$sortname = "t.topic_poster";
}
$sort[] = trim($sortname.' '.$sortorder);
$sort = implode(", ", $sort);
if(empty($sort)) $sort = 'p.post_time DESC';
$sql = 'SELECT '.$select.
' FROM '.$from.
' WHERE '.$where.
' ORDER BY '.$sort;
if (!$result = $this->db->query($sql, $xoopsModuleConfig['topics_per_page'], $start)) {
redirect_header('index.php', 2, _MD_ERROROCCURED . '<br />' . $sql);
exit();
}
$subject_array = array();
if(!empty($allow_subject_prefix) && !empty($xoopsModuleConfig['subject_prefix'])):
$subjectpres = explode(',', $xoopsModuleConfig['subject_prefix']);
if (count($subjectpres) > 1) {
foreach($subjectpres as $subjectpre) {
$subject_array[] = $subjectpre." ";
}
}
endif;
$subject_array[0] = null;
$sticky = 0;
$topics = array();
$posters = array();
$reads = array();
while ($myrow = $this->db->fetchArray($result)) {
if ($myrow['topic_sticky']) {
$sticky++;
}
// ------------------------------------------------------
// topic_icon: priority: sticky -> digest -> regular
if ($myrow['topic_haspoll']) {
if ($myrow['topic_sticky']) {
$topic_icon = newbb_displayImage($forumImage['folder_sticky'], _MD_TOPICSTICKY) . '<br />' . newbb_displayImage($forumImage['poll'], _MD_TOPICHASPOLL);
}else{
$topic_icon = newbb_displayImage($forumImage['poll'], _MD_TOPICHASPOLL);
}
}elseif($myrow['topic_sticky']) {
$topic_icon = newbb_displayImage($forumImage['folder_sticky'], _MD_TOPICSTICKY);
}elseif (!empty($myrow['icon'])) {
$topic_icon = '<img src="' . XOOPS_URL . '/images/subject/' . htmlspecialchars($myrow['icon']) . '" alt="" />';
} else {
$topic_icon = '<img src="' . XOOPS_URL . '/images/icons/no_posticon.gif" alt="" />';
}
// ------------------------------------------------------
// rating_img
$rating = number_format($myrow['rating'] / 2, 0);
$rating_img = newbb_displayImage($forumImage[($rating < 1)?'blank':'rate' . $rating]);
// ------------------------------------------------------
// topic_page_jump
$topic_page_jump = '';
$topic_page_jump_icon = '';
$totalpages = ceil(($myrow['topic_replies'] + 1) / $xoopsModuleConfig['posts_per_page']);
if ($totalpages > 1) {
$topic_page_jump .= ' ';
$append = false;
for ($i = 1; $i <= $totalpages; $i++) {
if ($i > 3 && $i < $totalpages) {
if(!$append){
$topic_page_jump .= "...";
$append = true;
}
} else {
$topic_page_jump .= '[<a href="viewtopic.php?topic_id=' . $myrow['topic_id'] . '&start=' . (($i - 1) * $xoopsModuleConfig['posts_per_page']) . '">' . $i . '</a>]';
$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "&start=" . (($i - 1) * $xoopsModuleConfig['posts_per_page']) . "#forumpost" . $myrow['post_id'] . "'>" . newbb_displayImage($forumImage['docicon']) . "</a>";
}
}
}
else {
$topic_page_jump_icon = "<a href='" . XOOPS_URL . "/modules/newbb/viewtopic.php?topic_id=" . $myrow['topic_id'] . "#forumpost" . $myrow['post_id'] . "'>" . newbb_displayImage($forumImage['docicon']) . "</a>";
}
// ------------------------------------------------------
// => topic array
if (is_object($viewall_forums[$myrow['forum_id']])){
$forum_link = '<a href="' . XOOPS_URL . '/modules/newbb/viewforum.php?forum=' . $myrow['forum_id'] . '">' . $viewall_forums[$myrow['forum_id']]->getVar('forum_name') . '</a>';
}else {
$forum_link = '';
}
$topic_title = $myts->htmlSpecialChars($myrow['topic_title']);
if ($myrow['topic_digest']) $topic_title = "<span class='digest'>" . $topic_title . "</span>";
if( $excerpt == 0 ){
$topic_excerpt = "";
}elseif( ($myrow['post_karma']>0 || $myrow['require_reply']>0) && !newbb_isAdmin($forum) ){
$topic_excerpt = "";
}else{
$topic_excerpt = xoops_substr(newbb_html2text($myts->displayTarea($myrow['post_text'])), 0, $excerpt);
$topic_excerpt = str_replace("[", "[", $myts->htmlSpecialChars($topic_excerpt));
}
$topic_subject = ($allow_subject_prefix)?$subject_array[$myrow['topic_subject']]:"";
$topics[$myrow['topic_id']] = array(
'topic_id' => $myrow['topic_id'],
'topic_icon' => $topic_icon,
//'topic_folder' => newbb_displayImage($topic_folder),
'topic_title' => $topic_subject.$topic_title,
'topic_link' => 'viewtopic.php?topic_id=' . $myrow['topic_id'] . '&forum=' . $myrow['forum_id'],
'rating_img' => $rating_img,
'topic_page_jump' => $topic_page_jump,
'topic_page_jump_icon' => $topic_page_jump_icon,
'topic_replies' => $myrow['topic_replies'],
'topic_poster_uid' => $myrow['topic_poster'],
'topic_poster_name' => $myts->htmlSpecialChars( ($myrow['poster_name'])?$myrow['poster_name']:$xoopsConfig['anonymous']),
'topic_views' => $myrow['topic_views'],
'topic_time' => newbb_formatTimestamp($myrow['topic_time']),
'topic_last_posttime' => newbb_formatTimestamp($myrow['last_post_time']),
'topic_last_poster_uid' => $myrow['uid'],
'topic_last_poster_name' => $myts->htmlSpecialChars( ($myrow['last_poster_name'])?$myrow['last_poster_name']:$xoopsConfig['anonymous']),
'topic_forum_link' => $forum_link,
'topic_excerpt' => $topic_excerpt,
'stick' => empty($myrow['topic_sticky']),
"stats" => array($myrow['topic_status'], $myrow['topic_digest'], $myrow['topic_replies']),
);
/* users */
$posters[$myrow['topic_poster']] = 1;
$posters[$myrow['uid']] = 1;
// reads
if(!empty($xoopsModuleConfig["read_mode"])){
$reads[$myrow['topic_id']] = ($xoopsModuleConfig["read_mode"] == 1)?$myrow['last_post_time']:$myrow["topic_last_post_id"];
}
}
$posters_name =& newbb_getUnameFromIds(array_keys($posters), $xoopsModuleConfig['show_realname'], true);
$topic_isRead = newbb_isRead("topic", $reads);
foreach(array_keys($topics) as $id){
$topics[$id]["topic_poster"] = !empty($posters_name[$topics[$id]["topic_poster_uid"]])?
$posters_name[$topics[$id]["topic_poster_uid"]]
:$topics[$id]["topic_poster_name"];
$topics[$id]["topic_last_poster"] = !empty($posters_name[$topics[$id]["topic_last_poster_uid"]])?
$posters_name[$topics[$id]["topic_last_poster_uid"]]
:$topics[$id]["topic_last_poster_name"];
// ------------------------------------------------------
// topic_folder: priority: newhot -> hot/new -> regular
list($topic_status, $topic_digest, $topic_replies) = $topics[$id]["stats"];
if ($topic_status == 1) {
$topic_folder = $forumImage['locked_topic'];
} else {
if ($topic_digest) $topic_folder = $forumImage['folder_digest'];
elseif ($topic_replies >= $hot_threshold) {
if(empty($topic_isRead[$id])){
$topic_folder = $forumImage['hot_newposts_topic'];
} else {
$topic_folder = $forumImage['hot_folder_topic'];
}
} else {
if(empty($topic_isRead[$id])){
$topic_folder = $forumImage['newposts_topic'];
} else {
$topic_folder = $forumImage['folder_topic'];
}
}
}
$topics[$id]['topic_folder'] = newbb_displayImage($topic_folder);
unset($topics[$id]["topic_poster_name"], $topics[$id]["topic_last_poster_name"], $topics[$id]["stats"]);
}
if ( count($topics) > 0) {
$sql = " SELECT DISTINCT topic_id FROM " . $this->db->prefix("bb_posts").
" WHERE attachment != ''".
" AND topic_id IN (" . implode(',', array_keys($topics)) . ")";
if($result = $this->db->query($sql)) {
while (list($topic_id) = $this->db->fetchRow($result)) {
$topics[$topic_id]['attachment'] = ' ' . newbb_displayImage($forumImage['clip'], _MD_TOPICSHASATT);
}
}
}
return array($topics, $sticky);
}
function getTopicCount(&$forum, $startdate, $type)
{
global $xoopsModuleConfig;
include_once XOOPS_ROOT_PATH.'/modules/newbb/include/functions.php';
$criteria_extra = '';
$criteria_approve = ' AND t.approved = 1'; // any others?
$leftjoin = ' LEFT JOIN ' . $this->db->prefix('bb_posts') . ' p ON p.post_id = t.topic_last_post_id';
$criteria_post = ' p.post_time > ' . $startdate;
switch ($type) {
case 'digest':
$criteria_extra = ' AND topic_digest = 1';
break;
case 'unreplied':
$criteria_extra = ' AND topic_replies < 1';
break;
case 'unread':
if(empty($xoopsModuleConfig["read_mode"])){
}elseif($xoopsModuleConfig["read_mode"] ==2){
$leftjoin .= ' LEFT JOIN ' . $this->db->prefix('bb_reads_topic') . ' r ON r.read_item = t.topic_id';
$criteria_post .= ' AND (r.read_id IS NULL OR r.post_id < t.topic_last_post_id)';
}elseif($xoopsModuleConfig["read_mode"] == 1){
$criteria_post = ' p.post_time > ' . max($GLOBALS['last_visit'], $startdate);
$topics = array();
$topic_lastread = newbb_getcookie('LT', true);
if(count($topic_lastread)>0) foreach($topic_lastread as $id=>$time){
if($time > $time_criterion) $topics[] = $id;
}
if(count($topics)>0){
$criteria_extra = ' AND t.topic_id NOT IN ('.implode(",", $topics).')';
}
}
break;
case 'pending':
$criteria_approve = ' AND t.approved = 0';
break;
case 'deleted':
$criteria_approve = ' AND t.approved = -1';
break;
case 'all':
break;
default:
$criteria_post = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
break;
}
if (is_object($forum)) $criteria_forum = ' AND t.forum_id = ' . $forum->getVar('forum_id');
else {
if (is_array($forum) && count($forum) > 0){
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?