From: <ok...@us...> - 2003-01-07 21:32:59
|
Update of /cvsroot/xoops/xoops2/kernel/comment/manager In directory sc8-pr-cvs1:/tmp/cvs-serv14503/kernel/comment/manager Added Files: comment.php Log Message: added global comments feature --- NEW FILE: comment.php --- <?php // $Id: comment.php,v 1.1 2003/01/07 21:32:53 okazu 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: 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/) // // ------------------------------------------------------------------------- // include_once XOOPS_ROOT_PATH.'/kernel/comment/object/comment.php'; /** * XOOPS comment manager class. * This class is responsible for providing data access mechanisms to the data source * of XOOPS comment class objects. * * * @author Kazumi Ono <on...@xo...> */ class XoopsCommentManager extends XoopsObjectManager { function XoopsCommentManager(&$db, &$mf) { $this->XoopsObjectManager($db, $mf); } function &instance(&$db, &$mf) { static $instance; if (!isset($instance)) { $instance = new XoopsCommentManager($db, $mf); } return $instance; } function &create($isNew = true) { $comment = new XoopsComment(); if ($isNew) { $comment->setNew(); } return $comment; } function &get($id) { $id = intval($id); if ($id > 0) { $sql = 'SELECT * FROM '.$this->db->prefix('comments').' WHERE com_id='.$id; if (!$result = $this->db->query($sql)) { return false; } $numrows = $this->db->getRowsNum($result); if ($numrows == 1) { $comment = new XoopsComment(); $comment->assignVars($this->db->fetchArray($result)); return $comment; } } return false; } function insert(&$comment) { if (get_class($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('comments_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, dohtml, dosmiley, doxcode, doimage, dobr) VALUES (%u, %u, %u, '%s', '%s', '%s', %u, %u, %u, '%s', %u, %u, %u, %u, %u, %u, %u, %u, %u)", $this->db->prefix('comments'), $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, $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, dohtml = %u, dosmiley = %u, doxcode = %u, doimage = %u, dobr = %u WHERE com_id = %u", $this->db->prefix('comments'), $com_pid, $com_icon, $com_title, $com_text, $com_created, $com_modified, $com_uid, $com_ip, $com_sig, $com_itemid, $com_rootid, $com_status, $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; } function delete(&$comment) { if (get_class($comment) != 'xoopscomment') { return false; } $sql = sprintf("DELETE FROM %s WHERE com_id = %u", $this->db->prefix('comments'), $comment->getVar('com_id')); if (!$result = $this->db->query($sql)) { return false; } return true; } function &getObjects($criteria = null) { $ret = array(); $limit = $start = 0; $sql = 'SELECT * FROM '.$this->db->prefix('comments'); if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' '.$criteria->renderWhere(); $sql .= ' ORDER BY com_id '.$criteria->getOrder(); $limit = $criteria->getLimit(); $start = $criteria->getStart(); } $result = $this->db->query($sql, $limit, $start); if (!$result) { return false; } while ($myrow = $this->db->fetchArray($result)) { $comment = new XoopsComment(); $comment->assignVars($myrow); $ret[] =& $comment; unset($comment); } return $ret; } function getCount($criteria = null) { $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('comments'); if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' '.$criteria->renderWhere(); } if (!$result =& $this->db->query($sql)) { return false; } list($count) = $this->db->fetchRow($result); return $count; } function deleteAll($criteria = null) { $sql = 'DELETE FROM '.$this->db->prefix('comments'); if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' '.$criteria->renderWhere(); } if (!$result = $this->db->query($sql)) { return false; } return true; } /* function updateAll($fieldname, $fieldvalue, $criteria = null) { $set_clause = is_numeric($fieldvalue) ? $filedname.' = '.$fieldvalue : $filedname." = '".$fieldvalue."'"; $sql = 'UPDATE '.$this->db->prefix('comments').' SET '.$set_clause; if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { $sql .= ' '.$criteria->renderWhere(); } if (!$result = $this->db->query($sql)) { return false; } return true; } */ } ?> |