📄 comment.php
字号:
<?php
// $Id: comment.php 1102 2007-10-19 02:55:52Z 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.xoops.org/ http://jp.xoops.org/ http://www.myweb.ne.jp/ //
// Project: The XOOPS Project (http://www.xoops.org/) //
// ------------------------------------------------------------------------- //
if (!defined('XOOPS_ROOT_PATH')) {
exit();
}
/**
*
*
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
/**
* A Comment
*
* @package kernel
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
class XoopsComment extends XoopsObject
{
/**
* Constructor
**/
function XoopsComment()
{
$this->XoopsObject();
$this->initVar('com_id', XOBJ_DTYPE_INT, null, false);
$this->initVar('com_pid', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_modid', XOBJ_DTYPE_INT, null, false);
$this->initVar('com_icon', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('com_title', XOBJ_DTYPE_TXTBOX, null, true, 255, true);
$this->initVar('com_text', XOBJ_DTYPE_TXTAREA, null, true, null, true);
$this->initVar('com_created', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_modified', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_uid', XOBJ_DTYPE_INT, 0, true);
$this->initVar('com_ip', XOBJ_DTYPE_OTHER, null, false);
$this->initVar('com_sig', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_itemid', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_rootid', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_status', XOBJ_DTYPE_INT, 0, false);
$this->initVar('com_exparams', XOBJ_DTYPE_OTHER, null, false, 255);
$this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false);
$this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false);
$this->initVar('doxcode', XOBJ_DTYPE_INT, 0, false);
$this->initVar('doimage', XOBJ_DTYPE_INT, 0, false);
$this->initVar('dobr', XOBJ_DTYPE_INT, 0, false);
}
/**
* Is this comment on the root level?
*
* @return bool
**/
function isRoot()
{
return ($this->getVar('com_id') == $this->getVar('com_rootid'));
}
}
/**
* XOOPS comment handler class.
*
* This class is responsible for providing data access mechanisms to the data source
* of XOOPS comment class objects.
*
*
* @package kernel
* @subpackage comment
*
* @author Kazumi Ono <onokazu@xoops.org>
* @copyright copyright (c) 2000-2003 XOOPS.org
*/
class XoopsCommentHandler extends XoopsObjectHandler
{
/**
* Create a {@link XoopsComment}
*
* @param bool $isNew Flag the object as "new"?
*
* @return object
*/
function &create($isNew = true)
{
$comment = new XoopsComment();
if ($isNew) {
$comment->setNew();
}
return $comment;
}
/**
* Retrieve a {@link XoopsComment}
*
* @param int $id ID
*
* @return object {@link XoopsComment}, FALSE on fail
**/
function &get($id)
{
$comment = false;
$id = intval($id);
if ($id > 0) {
$sql = 'SELECT * FROM '.$this->db->prefix('xoopscomments').' WHERE com_id='.$id;
if (!$result = $this->db->query($sql)) {
return $comment;
}
$numrows = $this->db->getRowsNum($result);
if ($numrows == 1) {
$comment = new XoopsComment();
$comment->assignVars($this->db->fetchArray($result));
}
}
return $comment;
}
/**
* Write a comment to database
*
* @param object &$comment
*
* @return bool
**/
function insert(&$comment)
{
/**
* @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
*/
if (!is_a($comment, 'xoopscomment')) {
return false;
}
if (!$comment->isDirty()) {
return true;
}
if (!$comment->cleanVars()) {
return false;
}
foreach ($comment->cleanVars as $k => $v) {
${$k} = $v;
}
if ($comment->isNew()) {
$com_id = $this->db->genId('xoopscomments_com_id_seq');
$sql = sprintf("INSERT INTO %s (com_id, com_pid, com_modid, com_icon, com_title, com_text, com_created, com_modified, com_uid, com_ip, com_sig, com_itemid, com_rootid, com_status, com_exparams, dohtml, dosmiley, doxcode, doimage, dobr) VALUES (%u, %u, %u, %s, %s, %s, %u, %u, %u, %s, %u, %u, %u, %u, %s, %u, %u, %u, %u, %u)", $this->db->prefix('xoopscomments'), $com_id, $com_pid, $com_modid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_ip), $com_sig, $com_itemid, $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr);
} else {
$sql = sprintf("UPDATE %s SET com_pid = %u, com_icon = %s, com_title = %s, com_text = %s, com_created = %u, com_modified = %u, com_uid = %u, com_ip = %s, com_sig = %u, com_itemid = %u, com_rootid = %u, com_status = %u, com_exparams = %s, dohtml = %u, dosmiley = %u, doxcode = %u, doimage = %u, dobr = %u WHERE com_id = %u", $this->db->prefix('xoopscomments'), $com_pid, $this->db->quoteString($com_icon), $this->db->quoteString($com_title), $this->db->quoteString($com_text), $com_created, $com_modified, $com_uid, $this->db->quoteString($com_ip), $com_sig, $com_itemid, $com_rootid, $com_status, $this->db->quoteString($com_exparams), $dohtml, $dosmiley, $doxcode, $doimage, $dobr, $com_id);
}
if (!$result = $this->db->query($sql)) {
return false;
}
if (empty($com_id)) {
$com_id = $this->db->getInsertId();
}
$comment->assignVar('com_id', $com_id);
return true;
}
/**
* Delete a {@link XoopsComment} from the database
*
* @param object &$comment
*
* @return bool
**/
function delete(&$comment)
{
/**
* @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
*/
if (!is_a($comment, 'xoopscomment')) {
return false;
}
$sql = sprintf("DELETE FROM %s WHERE com_id = %u", $this->db->prefix('xoopscomments'), $comment->getVar('com_id'));
if (!$result = $this->db->query($sql)) {
return false;
}
return true;
}
/**
* Get some {@link XoopsComment}s
*
* @param object $criteria
* @param bool $id_as_key Use IDs as keys into the array?
*
* @return array Array of {@link XoopsComment} objects
**/
function getObjects($criteria = null, $id_as_key = false)
{
$ret = array();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -