topic.php
来自「php 开发的内容管理系统」· PHP 代码 · 共 516 行 · 第 1/2 页
PHP
516 行
<?php
// $Id: topic.php,v 1.3 2005/10/19 17:20:32 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 //
// ------------------------------------------------------------------------ //
// Author: phppp (D.J., infomax@gmail.com) //
// URL: http://xoopsforge.com, http://xoops.org.cn //
// Project: Article Project //
// ------------------------------------------------------------------------ //
if (!defined("XOOPS_ROOT_PATH")) {
exit();
}
defined("NEWBB_FUNCTIONS_INI") || include XOOPS_ROOT_PATH.'/modules/newbb/include/functions.ini.php';
newbb_load_object();
class Topic extends ArtObject
{
function Topic()
{
$this->ArtObject("bb_topics");
$this->initVar('topic_id', XOBJ_DTYPE_INT);
$this->initVar('topic_title', XOBJ_DTYPE_TXTBOX);
$this->initVar('topic_poster', XOBJ_DTYPE_INT);
$this->initVar('topic_time', XOBJ_DTYPE_INT);
$this->initVar('topic_views', XOBJ_DTYPE_INT);
$this->initVar('topic_replies', XOBJ_DTYPE_INT);
$this->initVar('topic_last_post_id', XOBJ_DTYPE_INT);
$this->initVar('forum_id', XOBJ_DTYPE_INT);
$this->initVar('topic_status', XOBJ_DTYPE_INT);
$this->initVar('topic_subject', XOBJ_DTYPE_INT);
$this->initVar('topic_sticky', XOBJ_DTYPE_INT);
$this->initVar('topic_digest', XOBJ_DTYPE_INT);
$this->initVar('digest_time', XOBJ_DTYPE_INT);
$this->initVar('approved', XOBJ_DTYPE_INT);
$this->initVar('poster_name', XOBJ_DTYPE_TXTBOX);
$this->initVar('rating', XOBJ_DTYPE_OTHER);
$this->initVar('votes', XOBJ_DTYPE_INT);
$this->initVar('topic_haspoll', XOBJ_DTYPE_INT);
$this->initVar('poll_id', XOBJ_DTYPE_INT);
}
function incrementCounter()
{
$sql = 'UPDATE ' . $GLOBALS["xoopsDB"]->prefix('bb_topics') . ' SET topic_views = topic_views + 1 WHERE topic_id =' . $this->getVar('topic_id');
$GLOBALS["xoopsDB"]->queryF($sql);
}
}
class NewbbTopicHandler extends ArtObjectHandler
{
function NewbbTopicHandler(&$db) {
$this->ArtObjectHandler($db, 'bb_topics', 'Topic', 'topic_id', 'topic_title');
}
function &get($id, $var = null)
{
$ret = null;
if(!empty($var) && is_string($var)) {
$tags = array($var);
}else{
$tags = $var;
}
if(!$topic_obj = parent::get($id, $tags)){
return $ret;
}
if(!empty($var) && is_string($var)) {
$ret = @$topic_obj->getVar($var);
}else{
$ret =& $topic_obj;
}
return $ret;
}
function approve($topic_id)
{
$sql = "UPDATE " . $this->db->prefix("bb_topics") . " SET approved = 1 WHERE topic_id = $topic_id";
if (!$result = $this->db->queryF($sql)) {
newbb_message("NewbbTopicHandler::approve error:" . $sql);
return false;
}
$post_handler =& xoops_getmodulehandler('post', 'newbb');
$posts_obj =& $post_handler->getAll(new Criteria('topic_id', $topic_id));
foreach(array_keys($posts_obj) as $post_id){
$post_handler->approve($posts_obj[$post_id]);
}
unset($posts_obj);
return true;
}
/**
* get previous/next topic
*
* @param integer $topic_id current topic ID
* @param integer $action
* <ul>
* <li> -1: previous </li>
* <li> 0: current </li>
* <li> 1: next </li>
* </ul>
* @param integer $forum_id the scope for moving
* <ul>
* <li> >0 : inside the forum </li>
* <li> <= 0: global </li>
* </ul>
* @access public
*/
function &getByMove($topic_id, $action, $forum_id = 0)
{
$topic = null;
if(!empty($action)):
$sql = "SELECT * FROM " . $this->table.
" WHERE 1=1".
(($forum_id>0)?" AND forum_id=".intval($forum_id):"").
" AND topic_id ".(($action>0)?">":"<").intval($topic_id).
" ORDER BY topic_id ".(($action>0)?"ASC":"DESC")." LIMIT 1";
if($result = $this->db->query($sql)){
if($row = $this->db->fetchArray($result)):
$topic =& $this->create(false);
$topic->assignVars($row);
return $topic;
endif;
}
endif;
$topic =& $this->get($topic_id);
return $topic;
}
function &getByPost($post_id)
{
$topic = null;
$sql = "SELECT t.* FROM " . $this->db->prefix('bb_topics') . " t, " . $this->db->prefix('bb_posts') . " p
WHERE t.topic_id = p.topic_id AND p.post_id = " . intval($post_id);
$result = $this->db->query($sql);
if (!$result) {
newbb_message("NewbbTopicHandler::getByPost error:" . $sql);
return $topic;
}
$row = $this->db->fetchArray($result);
$topic =& $this->create(false);
$topic->assignVars($row);
return $topic;
}
function getPostCount(&$topic, $type ="")
{
switch($type){
case "pending":
$approved = 0;
break;
case "deleted":
$approved = -1;
break;
default:
$approved = 1;
break;
}
$criteria =& new CriteriaCompo(new Criteria("topic_id", $topic->getVar('topic_id')));
$criteria->add(new Criteria("approved", $approved));
$post_handler =& xoops_getmodulehandler("post", "newbb");
$count = $post_handler->getCount($criteria);
return $count;
}
function &getTopPost($topic_id)
{
$post = null;
$sql = "SELECT p.*, t.* FROM " . $this->db->prefix('bb_posts') . " p,
" . $this->db->prefix('bb_posts_text') . " t
WHERE
p.topic_id = " . $topic_id . " AND p.pid = 0
AND t.post_id = p.post_id";
$result = $this->db->query($sql);
if (!$result) {
newbb_message("NewbbTopicHandler::getTopPost error:" . $sql);
return $post;
}
$post_handler =& xoops_getmodulehandler('post', 'newbb');
$myrow = $this->db->fetchArray($result);
$post =& $post_handler->create(false);
$post->assignVars($myrow);
return $post;
}
function getTopPostId($topic_id)
{
$sql = "SELECT MIN(post_id) AS post_id FROM " . $this->db->prefix('bb_posts') . " WHERE topic_id = " . $topic_id . " AND pid = 0";
$result = $this->db->query($sql);
if (!$result) {
newbb_message("NewbbTopicHandler::getTopPostId error:" . $sql);
return false;
}
list($post_id) = $this->db->fetchRow($result);
return $post_id;
}
function &getAllPosts(&$topic, $order = "ASC", $perpage = 10, &$start, $post_id = 0, $type = "")
{
global $xoopsModuleConfig;
$ret = array();
$perpage = (intval($perpage)>0) ? intval($perpage) : (empty($xoopsModuleConfig['posts_per_page']) ? 10 : $xoopsModuleConfig['posts_per_page']);
$start = intval($start);
switch($type){
case "pending":
$approve_criteria = ' AND p.approved = 0';
break;
case "deleted":
$approve_criteria = ' AND p.approved = -1';
break;
default:
$approve_criteria = ' AND p.approved = 1';
break;
}
if ($post_id) {
if ($order == "DESC") {
$operator_for_position = '>' ;
} else {
$order = "ASC" ;
$operator_for_position = '<' ;
}
//$approve_criteria = ' AND approved = 1'; // any others?
$sql = "SELECT COUNT(*) FROM " . $this->db->prefix('bb_posts') . " AS p WHERE p.topic_id=" . intval($topic->getVar('topic_id')) . $approve_criteria . " AND p.post_id $operator_for_position $post_id";
$result = $this->db->query($sql);
if (!$result) {
newbb_message("NewbbTopicHandler::getAllPosts:post-count error:" . $sql);
return $ret;
}
list($position) = $this->db->fetchRow($result);
$start = intval($position / $perpage) * $perpage;
}
$sql = 'SELECT p.*, t.* FROM ' . $this->db->prefix('bb_posts') . ' p, ' . $this->db->prefix('bb_posts_text') . " t WHERE p.topic_id=" . $topic->getVar('topic_id') . " AND p.post_id = t.post_id" . $approve_criteria . " ORDER BY p.post_id $order";
$result = $this->db->query($sql, $perpage, $start);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?