📄 forum.php
字号:
<?php
// $Id: forum.php,v 1.1.1.89 2004/11/26 04:59:47 phppp Exp $
// ------------------------------------------------------------------------ //
// XOOPS - PHP Content Management System //
// Copyright (c) 2000 XOOPS.org //
// <http://www.xoops.org/> //
// ------------------------------------------------------------------------ //
// This program is free software; you can redistribute it and/or modify //
// it under the terms of the GNU General Public License as published by //
// the Free Software Foundation; either version 2 of the License, or //
// (at your option) any later version. //
// //
// You may not change or alter any portion of this comment or credits //
// of supporting developers from this source code or any supporting //
// source code which is considered copyrighted (c) material of the //
// original comment or credit authors. //
// //
// This program is distributed in the hope that it will be useful, //
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
// GNU General Public License for more details. //
// //
// You should have received a copy of the GNU General Public License //
// along with this program; if not, write to the Free Software //
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA //
// ------------------------------------------------------------------------ //
class Forum extends XoopsObject {
var $db;
var $table;
var $groups_forum_access;
var $groups_forum_can_post;
var $groups_forum_can_view;
var $groups_forum_can_reply;
var $groups_forum_can_edit;
var $groups_forum_can_delete;
var $groups_forum_can_addpoll;
var $groups_forum_can_attach;
var $groups_forum_can_noapprove;
function Forum()
{
$this->db = &Database::getInstance();
$this->table = $this->db->prefix("bb_forums");
$this->initVar('forum_id', XOBJ_DTYPE_INT);
$this->initVar('forum_name', XOBJ_DTYPE_TXTBOX);
$this->initVar('forum_desc', XOBJ_DTYPE_TXTAREA);
$this->initVar('forum_moderator', XOBJ_DTYPE_TXTBOX);
$this->initVar('forum_topics', XOBJ_DTYPE_INT);
$this->initVar('forum_posts', XOBJ_DTYPE_INT);
$this->initVar('forum_last_post_id', XOBJ_DTYPE_INT);
$this->initVar('cat_id', XOBJ_DTYPE_INT);
$this->initVar('forum_type', XOBJ_DTYPE_INT);
$this->initVar('parent_forum', XOBJ_DTYPE_INT);
$this->initVar('allow_html', XOBJ_DTYPE_INT);
$this->initVar('allow_sig', XOBJ_DTYPE_INT);
$this->initVar('allow_subject_prefix', XOBJ_DTYPE_INT);
$this->initVar('hot_threshold', XOBJ_DTYPE_INT);
$this->initVar('allow_polls', XOBJ_DTYPE_INT);
$this->initVar('allow_attachments', XOBJ_DTYPE_INT);
$this->initVar('attach_maxkb', XOBJ_DTYPE_INT);
$this->initVar('attach_ext', XOBJ_DTYPE_TXTAREA);
$this->initVar('forum_order', XOBJ_DTYPE_INT);
}
function updateModerators($modertators)
{
$sql = "UPDATE " . $this->db->prefix('bb_forums') . " SET forum_moderator=" . $this->db->quoteString($modertators) . " WHERE forum_id=" . $this->getVar('forum_id');
if (!$result = $this->db->query($sql)) {
echo "<br />Forum::updateModerators error::" . $sql;
return false;
}
return true;
}
// Get moderators in uname or in uid
function &getModerators($asUname = false)
{
static $_cachedModerators = array();
$moderators = array();
$forum_moderators = trim($this->getVar('forum_moderator'));
$forum_moderators = explode(' ', $forum_moderators);
foreach ($forum_moderators as $key => $moderatorid) {
if ($moderatorid > 0) $moderators[$moderatorid] = 1;
}
$moderators = array_keys($moderators);
if(!$asUname) return $moderators;
$moderators_return = array();
$moderators_new = array();
foreach($moderators as $id){
if($id ==0) continue;
if(isset($_cachedModerators[$id])) $moderators_return[$id] = &$_cachedModerators[$id];
else $moderators_new[]=$id;
}
if(count($moderators_new)>0){
$moderators_new = "(" . implode(',', $moderators_new) . ")";
$member_handler = &xoops_gethandler('member');
$moderators_new = &$member_handler->getUserList(new Criteria('uid', $moderators_new, 'IN'), true);
foreach($moderators_new as $id => $name){
$_cachedModerators[$id] = $name;
$moderators_return[$id] = $name;
}
}
return $moderators_return;
}
function isSubForum()
{
return ($this->getVar('parent_forum') > 0);
}
function getSubForums()
{
global $xoopsConfig, $xoopsModule, $xoopsTpl, $myts;
$sql = 'SELECT f.*, u.uname, u.name, u.uid, p.topic_id, p.post_time, p.poster_name, p.subject, p.icon FROM ' . $this->db->prefix('bb_forums') . ' f LEFT JOIN ' . $this->db->prefix('bb_posts') . ' p ON p.post_id = f.forum_last_post_id LEFT JOIN ' . $this->db->prefix('users') . ' u ON u.uid = p.uid';
$sql .= ' WHERE f.parent_forum = ' . $this->getVar('forum_id') . ' ORDER BY f.forum_order';
$xoopsTpl->assign('forum_index_title', sprintf(_MD_FORUMINDEX, $xoopsConfig['sitename']));
if (!$result = $this->db->query($sql)) {
echo "<br />Forum::getSubForums error::" . $sql;
return false;
}
$forums = array(); // RMV-FIX
$ret = array();
$forum_handler = &xoops_getmodulehandler('forum', 'newbb');
while ($forum_data = $this->db->fetchArray($result)) {
$forums = array_merge(
array('forum_id' => $forum_data['forum_id'],
'forum_name' => $forum_data['forum_name'],
'forum_desc' => $myts->displayTarea($forum_data['forum_desc'], 1, 1, 1, 1, 1),
'forum_posts' => $forum_data['forum_posts'],
'forum_topics' => $forum_data['forum_topics'],
'forum_type' => $forum_data['forum_type'],
),
$this->disp_forumIndex($forum_data),
array('forum_moderators' => $this->disp_forumModerators(trim($forum_data['forum_moderator']))
),
array('forum_permission' => $forum_handler->getPermission($this)
)
);
$ret[] = $forums;
}
return $ret;
}
function disp_forumIndex(&$forum_data)
{
global $xoopsConfig, $forumImage, $xoopsModule, $xoopsModuleConfig, $myts;
$disp_array = array();
if (!$forum_data['post_time'])
return array("forum_lastpost_time" => "",
"forum_lastpost_icon" => "",
"forum_lastpost_user" => "",
"forum_folder" => ($this->getVar('forum_type') == 1) ? newbb_displayImage($forumImage['locked_forum']) : newbb_displayImage($forumImage['folder_forum'])
);
$forum_lastview = newbb_getcookie('LF', true);
$forum_lastview = (isset($forum_lastview[$forum_data['forum_id']]))?$forum_lastview[$forum_data['forum_id']]:0;
$disp_array['forum_lastpost_time'] = formatTimestamp($forum_data['post_time']);
$last_post_icon = '<a href="' . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/viewtopic.php?post_id=' . $forum_data['forum_last_post_id'] . '&topic_id=' . $forum_data['topic_id'] . '#forumpost' . $forum_data['forum_last_post_id'] . '">';
if ($forum_data['icon']) {
$last_post_icon .= '<img src="' . XOOPS_URL . '/images/subject/' . $forum_data['icon'] . '" alt="" />';
} else {
$last_post_icon .= '<img src="' . XOOPS_URL . '/images/subject/icon1.gif" alt="" />';
}
$last_post_icon .= '</a>';
$disp_array['forum_lastpost_icon'] = $last_post_icon;
if ($forum_data['uid'] != 0 && $forum_data['uname']) {
if ($xoopsModuleConfig['show_realname'] && $forum_data['name']) {
$forum_lastpost_user = '' . _MD_BY . ' <a href="' . XOOPS_URL . '/userinfo.php?uid=' . $forum_data['uid'] . '">' . $myts->htmlSpecialChars(@$forum_data['name']) . '</a>';
} else {
$forum_lastpost_user = '' . _MD_BY . ' <a href="' . XOOPS_URL . '/userinfo.php?uid=' . $forum_data['uid'] . '">' . $myts->htmlSpecialChars($forum_data['uname']) . '</a>';
}
} else {
$forum_lastpost_user = !empty($forum_data['poster_name'])?$forum_data['poster_name']:$xoopsConfig['anonymous'];
}
$disp_array['forum_lastpost_user'] = $forum_lastpost_user;
if ($GLOBALS['last_visit'] < $forum_data['post_time'] && $forum_lastview < $forum_data['post_time']) {
$forum_folder = ($this->getVar('forum_type') == 1) ? $forumImage['locked_forum_newposts'] : $forumImage['newposts_forum'];
} else {
$forum_folder = ($this->getVar('forum_type') == 1) ? $forumImage['locked_forum'] : $forumImage['folder_forum'];
}
$disp_array['forum_folder'] = newbb_displayImage($forum_folder);
return $disp_array;
}
function disp_forumModerators($valid_moderators = 0)
{
global $xoopsDB, $xoopsModuleConfig;
$ret = "";
if ($valid_moderators === 0) {
$forum_handler = &xoops_getmodulehandler('forum', 'newbb');
$valid_moderators = $this->getModerators(true);
} elseif (empty($valid_moderators)) {
return $ret;
} elseif (!is_array($valid_moderators)) {
$moderators = array();
$criteira = "(" . implode(',', explode(' ', $valid_moderators)) . ")";
$member_handler = &xoops_gethandler('member');
$valid_moderators = &$member_handler->getUserList(new Criteria('uid', $criteira, 'IN'), true);
}
if ($xoopsModuleConfig['show_realname']){
if (!$valid_moderators || count($valid_moderators) < 1) return false;
foreach ($valid_moderators as $uid => $uname) {
$sql = "SELECT uid, name FROM ".$xoopsDB->prefix("users")." WHERE uid=$uid ";
if ( !$result = $xoopsDB->query($sql) ) {
return array();
}
if ( !$myrow = $xoopsDB->fetchArray($result) ) {
return array();
}
$ret .= "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $uid . "'>" . $myrow['name'] . "</a> ";
}
}
else {
if (!$valid_moderators || count($valid_moderators) < 1) return false;
foreach ($valid_moderators as $uid => $uname) {
$ret .= "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $uid . "'>" . $uname . "</a> ";
}
}
return $ret;
}
}
class NewbbForumHandler extends XoopsObjectHandler
{
function &create($isNew = true)
{
$forum = new Forum();
if ($isNew) {
$forum->setNew();
}
return $forum;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -