📄 forum.php
字号:
function &get($id)
{
$forum = &$this->create(false);
if ($id > 0) {
$sql = "SELECT * FROM " . $this->db->prefix("bb_forums") . " WHERE forum_id = " . intval($id);
if (!$result = $this->db->query($sql)) {
echo "<br />NewbbForumHandler::get error::" . $sql;
return false;
} while ($row = $this->db->fetchArray($result)) {
$forum->assignVars($row);
}
}
return $forum;
}
function insert(&$forum)
{
if (!$forum->isDirty()) {
return true;
}
if (!$forum->cleanVars()) {
echo "<br />NewbbForumHandler::cleanVars error";
return false;
}
foreach ($forum->cleanVars as $k => $v) {
${$k} = $v;
}
if ($forum->isNew()) {
$forum->setVar('forum_id', $this->db->genId($forum->table . "_forum_id_seq"));
$sql = "INSERT INTO " . $forum->table . " (forum_id, forum_name, forum_desc,parent_forum,
forum_moderator, forum_topics,forum_posts,forum_last_post_id, cat_id, forum_type, allow_html, allow_sig, allow_subject_prefix,
hot_threshold, forum_order, allow_attachments,attach_maxkb, attach_ext, allow_polls,subforum_count)
VALUES
(" . $forum->getVar('forum_id') . ", " . $this->db->quoteString($forum_name) . ", " . $this->db->quoteString($forum_desc) . ", " . intval($parent_forum) . ",
" . $this->db->quoteString($forum_moderator) . ",0,0,0, " . $cat_id . ",
" . $forum_type . ", " . $allow_html . ", " . $allow_sig . "," . $allow_subject_prefix . ",
" . $hot_threshold . ", " . $forum_order . ", " . $allow_attachments . ", " . $attach_maxkb . ", " . $this->db->quoteString($attach_ext) . ", " . $allow_polls . ",0 )";
} else {
$sql = "UPDATE " . $forum->table . " SET forum_name=" . $this->db->quoteString($forum_name) . ", forum_desc=" . $this->db->quoteString($forum_desc) . ",
forum_moderator=" . $this->db->quoteString($forum_moderator) . ",
cat_id=" . $cat_id . ", forum_type=" . $forum_type . ", allow_html=" . $allow_html . ",
allow_sig=" . $allow_sig . ",allow_subject_prefix=" . $allow_subject_prefix . ",
hot_threshold=" . $hot_threshold . ", forum_order=" . $forum_order . ", allow_attachments=" . $allow_attachments . ",
attach_maxkb=" . $attach_maxkb . ", attach_ext=" . $this->db->quoteString($attach_ext) . ", allow_polls=" . $allow_polls . "
WHERE forum_id=" . $forum_id . " ";
}
if (!$this->db->query($sql)) {
echo "<br />NewbbForumHandler::insert error::" . $sql;
return false;
}
if (!($forum->getVar('forum_id'))) $forum->setVar('forum_id', $this->db->getInsertId());
$perm = &xoops_getmodulehandler('permission', 'newbb');
$perm->saveCategory_Permissions($forum->groups_forum_access, $forum->getVar('forum_id'), 'global_forum_access');
$perm->saveCategory_Permissions($forum->groups_forum_can_post, $forum->getVar('forum_id'), 'forum_can_post');
$perm->saveCategory_Permissions($forum->groups_forum_can_view, $forum->getVar('forum_id'), 'forum_can_view');
$perm->saveCategory_Permissions($forum->groups_forum_can_reply, $forum->getVar('forum_id'), 'forum_can_reply');
$perm->saveCategory_Permissions($forum->groups_forum_can_edit, $forum->getVar('forum_id'), 'forum_can_edit');
$perm->saveCategory_Permissions($forum->groups_forum_can_delete, $forum->getVar('forum_id'), 'forum_can_delete');
$perm->saveCategory_Permissions($forum->groups_forum_can_addpoll, $forum->getVar('forum_id'), 'forum_can_addpoll');
$perm->saveCategory_Permissions($forum->groups_forum_can_vote, $forum->getVar('forum_id'), 'forum_can_vote');
$perm->saveCategory_Permissions($forum->groups_forum_can_attach, $forum->getVar('forum_id'), 'forum_can_attach');
$perm->saveCategory_Permissions($forum->groups_forum_can_noapprove, $forum->getVar('forum_id'), 'forum_can_noapprove');
return true;
}
function delete(&$forum)
{
global $xoopsModule;
$sql = "SELECT post_id FROM " . $this->db->prefix("bb_posts") . " WHERE forum_id = " . $forum->getVar('forum_id');
if (!$r = $this->db->query($sql)) {
echo "<br />NewbbForumHandler::delete error::" . $sql;
return false;
}
if ($this->db->getRowsNum($r) > 0) {
$sql = "DELETE FROM " . $this->db->prefix("bb_posts_text") . " WHERE ";
$looped = false;
while ($ids = $this->db->fetchArray($r)) {
if ($looped == true) {
$sql .= " OR ";
}
$sql .= "post_id = " . $ids["post_id"] . " ";
$looped = true;
}
if (!$r = $this->db->query($sql)) {
echo "<br />NewbbForumHandler::delete error::" . $sql;
return false;
}
$sql = sprintf("DELETE FROM %s WHERE forum_id = %u", $this->db->prefix("bb_posts"), $_POST['forum_id']);
if (!$r = $this->db->query($sql)) {
echo "<br />NewbbForumHandler::delete error::" . $sql;
return false;
}
}
// RMV-NOTIFY
xoops_notification_deletebyitem ($xoopsModule->getVar('mid'), 'forum', $_POST['forum_id']);
// Get list of all topics in forum, to delete them too
$sql = sprintf("SELECT topic_id FROM %s WHERE forum_id = %u", $this->db->prefix("bb_topics"), $_POST['forum_id']);
if ($r = $this->db->query($sql)) {
while ($row = $this->db->fetchArray($r)) {
xoops_notification_deletebyitem ($xoopsModule->getVar('mid'), 'thread', $row['topic_id']);
}
}
$sql = sprintf("DELETE FROM %s WHERE forum_id = %u", $this->db->prefix("bb_topics"), $_POST['forum_id']);
if (!$r = $this->db->query($sql)) {
return false;
}
$sql = "DELETE FROM " . $forum->table . " WHERE forum_id=" . $forum->getVar('forum_id') . "";
if (!$this->db->query($sql)) {
echo "<br />NewbbForumHandler::delete error::" . $sql;
return false;
}
// Delete group permissions
$gperm_handler = &xoops_gethandler('groupperm');
$gperm_names = "('forum_can_post', 'forum_can_view', 'forum_can_reply', 'forum_can_edit', 'forum_can_delete', 'forum_can_addpoll', 'forum_can_vote', 'forum_can_attach', 'global_forum_access')";
$criteria = new CriteriaCompo(new Criteria('gperm_modid', intval($xoopsModule->getVar('mid'))));
$criteria->add(new Criteria('gperm_name', $gperm_names, 'IN'));
$criteria->add(new Criteria('gperm_itemid', intval($_POST['forum_id'])));
return $gperm_handler->deleteAll($criteria);
}
function getForums($cat = 0, $permission = false)
{
static $_cachedForums=array();
$perm_string = (empty($permission))?'all':$permission;
if(isset($_cachedForums[$cat][$perm_string])) return $_cachedForums[$cat][$perm_string];
$sql = "SELECT * FROM " . $this->db->prefix('bb_forums');
if ($cat != 0) {
$sql .= " WHERE cat_id=" . intval($cat);
}
$sql .= " ORDER BY forum_order";
if (!$result = $this->db->query($sql)){
echo "<br />NewbbForumHandler::getForums error::" . $sql;
return false;
}
//$ret = array();
$forum_handler = &xoops_getmodulehandler('forum', 'newbb');
while ($row = $this->db->fetchArray($result)) {
$thisforum = $this->create(false);
$thisforum->assignVars($row);
if ($permission && !$this->getPermission($thisforum, $permission)) continue;
$_cachedForums[$cat][$perm_string][$row['forum_id']] = $thisforum;
unset($thisforum);
}
// TODO: Retrieve subforums
return $_cachedForums[$cat][$perm_string];
}
function getForumsByCat($cat = 0)
{
$sql = "SELECT * FROM " . $this->db->prefix('bb_forums');
if ($cat != 0) {
$sql .= " WHERE cat_id=" . intval($cat);
}
$sql .= " ORDER BY forum_order, forum_id=parent_forum";
if (!$result = $this->db->query($sql)) {
echo "<br />NewbbForumHandler::getForumsByCat error::" . $sql;
return false;
}
$ret = array();
while ($row = $this->db->fetchArray($result)) {
$thisforum = $this->create(false);
$thisforum->assignVars($row);
$ret[$row['cat_id']][$row['forum_id']] = $thisforum;
unset($thisforum);
}
// TODO: Retrieve subforums
return $ret;
}
// Get moderators of multi-forums
function &getModerators($forums = 0, $asUname = false)
{
if ($forums == 0) $forums = $this->getForums();
$moderators = array();
if (is_array($forums)) {
foreach ($forums as $forumid => $forum) {
$moderators = array_merge($moderators, $forum->getModerators($asUname));
}
} elseif (is_object($forums)) {
$moderators = &$forums->getModerators($asUname);
}
if (count($moderators) < 1) return array();
return $moderators;
}
function getAllTopics($forum, $startdate, $start, $sortname, $sortorder, $type = '')
{
global $xoopsModule, $xoopsConfig, $xoopsModuleConfig, $forumImage, $forumUrl, $myts, $xoopsUser, $viewall_forums;
$UserUid = is_object($xoopsUser) ? $xoopsUser->getVar('uid') : null;
$topic_lastread = newbb_getcookie('LT', true);
if (is_object($forum)) {
$forum_criteria = ' AND t.forum_id = ' . $forum->getVar('forum_id');
$hot_threshold = $forum->getVar('hot_threshold');
$allow_subject_prefix = $forum->getVar('allow_subject_prefix');
} else {
$hot_threshold = 10;
$allow_subject_prefix = 0;
if (is_array($viewall_forums) && count($viewall_forums) > 0)
$forum_criteria = ' AND t.forum_id IN (' . implode(',', array_keys($viewall_forums)) . ')';
else
$forum_criteria = '';
}
$sort_sticky = '';
switch ($type) {
case 'digest':
$post_time = ' p.post_time > ' . $startdate;
$extra_criteria = ' AND topic_digest = 1';
break;
case 'unreplied':
$post_time = ' p.post_time > ' . $startdate;
$extra_criteria = ' AND topic_replies < 1';
break;
case 'unread':
$post_time = ' p.post_time > ' . $GLOBALS['last_visit'];
$extra_criteria = '';
break;
case 'all': // For viewall.php; do not display sticky topics at first
$post_time = ' p.post_time > ' . $startdate;
$extra_criteria = '';
break;
default:
$post_time = ' (p.post_time > ' . $startdate . ' OR t.topic_sticky=1)';
$sort_sticky = ' t.topic_sticky DESC';
$extra_criteria = '';
break;
}
$sort = $sort_sticky;
$sort_in = trim($sortname.' '.$sortorder);
if($sort) {
if($sort_in) $sort .= ', '.$sort_in;
}elseif($sort_in){
$sort = $sort_in;
}
if(!empty($sort)) $sort = ' ORDER BY '. $sort;
$approve_criteria = ' AND t.approved = 1 AND p.approved = 1';
$sql = 'SELECT t.*, u.name, u.uname,u2.name as last_post_name, u2.uname as last_poster, p.post_time as last_post_time, p.poster_name as last_poster_name, p.icon, p.post_id FROM ' . $this->db->prefix("bb_topics") . ' t LEFT JOIN ' . $this->db->prefix("users") . ' u ON u.uid = t.topic_poster LEFT JOIN ' . $this->db->prefix('bb_posts') . ' p ON p.post_id = t.topic_last_post_id LEFT JOIN ' . $this->db->prefix("users") . ' u2 ON u2.uid = p.uid WHERE ';
$sql .= $post_time . $forum_criteria . $extra_criteria . $approve_criteria . $sort;
if (!$result = $this->db->query($sql, $xoopsModuleConfig['topics_per_page'], $start)) {
redirect_header('index.php', 2, _MD_ERROROCCURED . '<br />' . $sql);
exit();
}
$sticky = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -