📄 xoopscomments.php
字号:
<?php
// $Id: xoopscomments.php 1099 2007-10-19 01:08:14Z dugris $
// ------------------------------------------------------------------------ //
// 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: Kazumi Ono (AKA onokazu) //
// URL: http://www.myweb.ne.jp/, http://www.xoops.org/, http://jp.xoops.org/ //
// Project: The XOOPS Project //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
require_once XOOPS_ROOT_PATH.'/class/xoopsobject.php';
include_once XOOPS_ROOT_PATH.'/language/'.$GLOBALS['xoopsConfig']['language'].'/comment.php';
class XoopsComments extends XoopsObject
{
var $ctable;
var $db;
function XoopsComments($ctable, $id=null)
{
$this->ctable = $ctable;
$this->db =& Database::getInstance();
$this->XoopsObject();
$this->initVar('comment_id', XOBJ_DTYPE_INT, null, false);
$this->initVar('item_id', XOBJ_DTYPE_INT, null, false);
$this->initVar('order', XOBJ_DTYPE_INT, null, false);
$this->initVar('mode', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, false, 255);
$this->initVar('comment', XOBJ_DTYPE_TXTAREA, null, false, null);
$this->initVar('ip', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('pid', XOBJ_DTYPE_INT, 0, false);
$this->initVar('date', XOBJ_DTYPE_INT, null, false);
$this->initVar('nohtml', XOBJ_DTYPE_INT, 1, false);
$this->initVar('nosmiley', XOBJ_DTYPE_INT, 0, false);
$this->initVar('noxcode', XOBJ_DTYPE_INT, 0, false);
$this->initVar('user_id', XOBJ_DTYPE_INT, null, false);
$this->initVar('icon', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('prefix', XOBJ_DTYPE_OTHER, null, false);
if ( !empty($id) ) {
if ( is_array($id) ) {
$this->assignVars($id);
} else {
$this->load(intval($id));
}
}
}
function load($id)
{
$id = intval($id);
$sql = "SELECT * FROM ".$this->ctable." WHERE comment_id=".$id."";
$arr = $this->db->fetchArray($this->db->query($sql));
$this->assignVars($arr);
}
function store()
{
if ( !$this->cleanVars() ) {
return false;
}
foreach ( $this->cleanVars as $k=>$v ) {
$$k = $v;
}
$isnew = false;
if ( empty($comment_id ) ) {
$isnew = true;
$comment_id = $this->db->genId($this->ctable."_comment_id_seq");
$sql = sprintf("INSERT INTO %s (comment_id, pid, item_id, date, user_id, ip, subject, comment, nohtml, nosmiley, noxcode, icon) VALUES (%u, %u, %u, %u, %u, '%s', '%s', '%s', %u, %u, %u, '%s')", $this->ctable, $comment_id, $pid, $item_id, time(), $user_id, $ip, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon);
} else {
$sql = sprintf("UPDATE %s SET subject = '%s', comment = '%s', nohtml = %u, nosmiley = %u, noxcode = %u, icon = '%s' WHERE comment_id = %u", $this->ctable, $subject, $comment, $nohtml, $nosmiley, $noxcode, $icon, $comment_id);
}
if ( !$result = $this->db->query($sql) ) {
//echo $sql;
return false;
}
if ( empty($comment_id) ) {
$comment_id = $this->db->getInsertId();
}
if ( $isnew != false ) {
$sql = sprintf("UPDATE %s SET posts = posts+1 WHERE uid = %u", $this->db->prefix("users"), $user_id);
if (!$result = $this->db->query($sql)) {
echo "Could not update user posts.";
}
}
return $comment_id;
}
function delete()
{
$sql = sprintf("DELETE FROM %s WHERE comment_id = %u", $this->ctable, $this->getVar('comment_id'));
if ( !$result = $this->db->query($sql) ) {
return false;
}
$sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $this->getVar("user_id"));
if ( !$result = $this->db->query($sql) ) {
echo "Could not update user posts.";
}
$mytree = new XoopsTree($this->ctable, "comment_id", "pid");
$arr = $mytree->getAllChild($this->getVar("comment_id"), "comment_id");
$size = count($arr);
if ( $size > 0 ) {
for ( $i = 0; $i < $size; $i++ ) {
$sql = sprintf("DELETE FROM %s WHERE comment_bid = %u", $this->ctable, $arr[$i]['comment_id']);
if ( !$result = $this->db->query($sql) ) {
echo "Could not delete comment.";
}
$sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $arr[$i]['user_id']);
if ( !$result = $this->db->query($sql) ) {
echo "Could not update user posts.";
}
}
}
return ($size + 1);
}
function getCommentTree()
{
$mytree = new XoopsTree($this->ctable, "comment_id", "pid");
$ret = array();
$tarray = $mytree->getChildTreeArray($this->getVar("comment_id"), "comment_id");
foreach ( $tarray as $ele ) {
$ret[] = new XoopsComments($this->ctable,$ele);
}
return $ret;
}
function getAllComments($criteria=array(), $asobject=true, $orderby="comment_id ASC", $limit=0, $start=0)
{
$ret = array();
$where_query = "";
if ( is_array($criteria) && count($criteria) > 0 ) {
$where_query = " WHERE";
foreach ( $criteria as $c ) {
$where_query .= " $c AND";
}
$where_query = substr($where_query, 0, -4);
}
if ( !$asobject ) {
$sql = "SELECT comment_id FROM ".$this->ctable."$where_query ORDER BY $orderby";
$result = $this->db->query($sql,$limit,$start);
while ( $myrow = $this->db->fetchArray($result) ) {
$ret[] = $myrow['comment_id'];
}
} else {
$sql = "SELECT * FROM ".$this->ctable."".$where_query." ORDER BY $orderby";
$result = $this->db->query($sql,$limit,$start);
while ( $myrow = $this->db->fetchArray($result) ) {
$ret[] = new XoopsComments($this->ctable,$myrow);
}
}
//echo $sql;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -