[ Index ] |
|
Code source de XOOPS 2.0.17.1 |
1 <?php 2 // $Id: comment.php 506 2006-05-26 23:10:37Z skalpa $ 3 // ------------------------------------------------------------------------ // 4 // XOOPS - PHP Content Management System // 5 // Copyright (c) 2000 XOOPS.org // 6 // <http://www.xoops.org/> // 7 // ------------------------------------------------------------------------ // 8 // This program is free software; you can redistribute it and/or modify // 9 // it under the terms of the GNU General Public License as published by // 10 // the Free Software Foundation; either version 2 of the License, or // 11 // (at your option) any later version. // 12 // // 13 // You may not change or alter any portion of this comment or credits // 14 // of supporting developers from this source code or any supporting // 15 // source code which is considered copyrighted (c) material of the // 16 // original comment or credit authors. // 17 // // 18 // This program is distributed in the hope that it will be useful, // 19 // but WITHOUT ANY WARRANTY; without even the implied warranty of // 20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // 21 // GNU General Public License for more details. // 22 // // 23 // You should have received a copy of the GNU General Public License // 24 // along with this program; if not, write to the Free Software // 25 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // 26 // ------------------------------------------------------------------------ // 27 // Author: Kazumi Ono (AKA onokazu) // 28 // URL: http://www.xoops.org/ http://jp.xoops.org/ http://www.myweb.ne.jp/ // 29 // Project: The XOOPS Project (http://www.xoops.org/) // 30 // ------------------------------------------------------------------------- // 31 32 if (!defined('XOOPS_ROOT_PATH')) { 33 exit(); 34 } 35 36 /** 37 * 38 * 39 * @package kernel 40 * 41 * @author Kazumi Ono <onokazu@xoops.org> 42 * @copyright copyright (c) 2000-2003 XOOPS.org 43 */ 44 45 /** 46 * A Comment 47 * 48 * @package kernel 49 * 50 * @author Kazumi Ono <onokazu@xoops.org> 51 * @copyright copyright (c) 2000-2003 XOOPS.org 52 */ 53 class XoopsComment extends XoopsObject 54 { 55 56 /** 57 * Constructor 58 **/ 59 function XoopsComment() 60 { 61 $this->XoopsObject(); 62 $this->initVar('com_id', XOBJ_DTYPE_INT, null, false); 63 $this->initVar('com_pid', XOBJ_DTYPE_INT, 0, false); 64 $this->initVar('com_modid', XOBJ_DTYPE_INT, null, false); 65 $this->initVar('com_icon', XOBJ_DTYPE_OTHER, null, false); 66 $this->initVar('com_title', XOBJ_DTYPE_TXTBOX, null, true, 255, true); 67 $this->initVar('com_text', XOBJ_DTYPE_TXTAREA, null, true, null, true); 68 $this->initVar('com_created', XOBJ_DTYPE_INT, 0, false); 69 $this->initVar('com_modified', XOBJ_DTYPE_INT, 0, false); 70 $this->initVar('com_uid', XOBJ_DTYPE_INT, 0, true); 71 $this->initVar('com_ip', XOBJ_DTYPE_OTHER, null, false); 72 $this->initVar('com_sig', XOBJ_DTYPE_INT, 0, false); 73 $this->initVar('com_itemid', XOBJ_DTYPE_INT, 0, false); 74 $this->initVar('com_rootid', XOBJ_DTYPE_INT, 0, false); 75 $this->initVar('com_status', XOBJ_DTYPE_INT, 0, false); 76 $this->initVar('com_exparams', XOBJ_DTYPE_OTHER, null, false, 255); 77 $this->initVar('dohtml', XOBJ_DTYPE_INT, 0, false); 78 $this->initVar('dosmiley', XOBJ_DTYPE_INT, 0, false); 79 $this->initVar('doxcode', XOBJ_DTYPE_INT, 0, false); 80 $this->initVar('doimage', XOBJ_DTYPE_INT, 0, false); 81 $this->initVar('dobr', XOBJ_DTYPE_INT, 0, false); 82 } 83 84 /** 85 * Is this comment on the root level? 86 * 87 * @return bool 88 **/ 89 function isRoot() 90 { 91 return ($this->getVar('com_id') == $this->getVar('com_rootid')); 92 } 93 } 94 95 /** 96 * XOOPS comment handler class. 97 * 98 * This class is responsible for providing data access mechanisms to the data source 99 * of XOOPS comment class objects. 100 * 101 * 102 * @package kernel 103 * @subpackage comment 104 * 105 * @author Kazumi Ono <onokazu@xoops.org> 106 * @copyright copyright (c) 2000-2003 XOOPS.org 107 */ 108 class XoopsCommentHandler extends XoopsObjectHandler 109 { 110 111 /** 112 * Create a {@link XoopsComment} 113 * 114 * @param bool $isNew Flag the object as "new"? 115 * 116 * @return object 117 */ 118 function &create($isNew = true) 119 { 120 $comment = new XoopsComment(); 121 if ($isNew) { 122 $comment->setNew(); 123 } 124 return $comment; 125 } 126 127 /** 128 * Retrieve a {@link XoopsComment} 129 * 130 * @param int $id ID 131 * 132 * @return object {@link XoopsComment}, FALSE on fail 133 **/ 134 function &get($id) 135 { 136 $comment = false; 137 $id = intval($id); 138 if ($id > 0) { 139 $sql = 'SELECT * FROM '.$this->db->prefix('xoopscomments').' WHERE com_id='.$id; 140 if (!$result = $this->db->query($sql)) { 141 return $comment; 142 } 143 $numrows = $this->db->getRowsNum($result); 144 if ($numrows == 1) { 145 $comment = new XoopsComment(); 146 $comment->assignVars($this->db->fetchArray($result)); 147 } 148 } 149 return $comment; 150 } 151 152 /** 153 * Write a comment to database 154 * 155 * @param object &$comment 156 * 157 * @return bool 158 **/ 159 function insert(&$comment) 160 { 161 if (strtolower(get_class($comment)) != 'xoopscomment') { 162 return false; 163 } 164 if (!$comment->isDirty()) { 165 return true; 166 } 167 if (!$comment->cleanVars()) { 168 return false; 169 } 170 foreach ($comment->cleanVars as $k => $v) { 171 ${$k} = $v; 172 } 173 if ($comment->isNew()) { 174 $com_id = $this->db->genId('xoopscomments_com_id_seq'); 175 $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); 176 } else { 177 $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); 178 } 179 if (!$result = $this->db->query($sql)) { 180 return false; 181 } 182 if (empty($com_id)) { 183 $com_id = $this->db->getInsertId(); 184 } 185 $comment->assignVar('com_id', $com_id); 186 return true; 187 } 188 189 /** 190 * Delete a {@link XoopsComment} from the database 191 * 192 * @param object &$comment 193 * 194 * @return bool 195 **/ 196 function delete(&$comment) 197 { 198 if (strtolower(get_class($comment)) != 'xoopscomment') { 199 return false; 200 } 201 $sql = sprintf("DELETE FROM %s WHERE com_id = %u", $this->db->prefix('xoopscomments'), $comment->getVar('com_id')); 202 if (!$result = $this->db->query($sql)) { 203 return false; 204 } 205 return true; 206 } 207 208 /** 209 * Get some {@link XoopsComment}s 210 * 211 * @param object $criteria 212 * @param bool $id_as_key Use IDs as keys into the array? 213 * 214 * @return array Array of {@link XoopsComment} objects 215 **/ 216 function getObjects($criteria = null, $id_as_key = false) 217 { 218 $ret = array(); 219 $limit = $start = 0; 220 $sql = 'SELECT * FROM '.$this->db->prefix('xoopscomments'); 221 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 222 $sql .= ' '.$criteria->renderWhere(); 223 $sort = ($criteria->getSort() != '') ? $criteria->getSort() : 'com_id'; 224 $sql .= ' ORDER BY '.$sort.' '.$criteria->getOrder(); 225 $limit = $criteria->getLimit(); 226 $start = $criteria->getStart(); 227 } 228 $result = $this->db->query($sql, $limit, $start); 229 if (!$result) { 230 return $ret; 231 } 232 while ($myrow = $this->db->fetchArray($result)) { 233 $comment = new XoopsComment(); 234 $comment->assignVars($myrow); 235 if (!$id_as_key) { 236 $ret[] =& $comment; 237 } else { 238 $ret[$myrow['com_id']] =& $comment; 239 } 240 unset($comment); 241 } 242 return $ret; 243 } 244 245 /** 246 * Count Comments 247 * 248 * @param object $criteria {@link CriteriaElement} 249 * 250 * @return int Count 251 **/ 252 function getCount($criteria = null) 253 { 254 $sql = 'SELECT COUNT(*) FROM '.$this->db->prefix('xoopscomments'); 255 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 256 $sql .= ' '.$criteria->renderWhere(); 257 } 258 if (!$result =& $this->db->query($sql)) { 259 return 0; 260 } 261 list($count) = $this->db->fetchRow($result); 262 return $count; 263 } 264 265 /** 266 * Delete multiple comments 267 * 268 * @param object $criteria {@link CriteriaElement} 269 * 270 * @return bool 271 **/ 272 function deleteAll($criteria = null) 273 { 274 $sql = 'DELETE FROM '.$this->db->prefix('xoopscomments'); 275 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 276 $sql .= ' '.$criteria->renderWhere(); 277 } 278 if (!$result = $this->db->query($sql)) { 279 return false; 280 } 281 return true; 282 } 283 284 /** 285 * Get a list of comments 286 * 287 * @param object $criteria {@link CriteriaElement} 288 * 289 * @return array Array of raw database records 290 **/ 291 function getList($criteria = null) 292 { 293 $comments = $this->getObjects($criteria, true); 294 $ret = array(); 295 foreach (array_keys($comments) as $i) { 296 $ret[$i] = $comments[$i]->getVar('com_title'); 297 } 298 return $ret; 299 } 300 301 /** 302 * Retrieves comments for an item 303 * 304 * @param int $module_id Module ID 305 * @param int $item_id Item ID 306 * @param string $order Sort order 307 * @param int $status Status of the comment 308 * @param int $limit Max num of comments to retrieve 309 * @param int $start Start offset 310 * 311 * @return array Array of {@link XoopsComment} objects 312 **/ 313 function getByItemId($module_id, $item_id, $order = null, $status = null, $limit = null, $start = 0) 314 { 315 $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id))); 316 $criteria->add(new Criteria('com_itemid', intval($item_id))); 317 if (isset($status)) { 318 $criteria->add(new Criteria('com_status', intval($status))); 319 } 320 if (isset($order)) { 321 $criteria->setOrder($order); 322 } 323 if (isset($limit)) { 324 $criteria->setLimit($limit); 325 $criteria->setStart($start); 326 } 327 return $this->getObjects($criteria); 328 } 329 330 /** 331 * Gets total number of comments for an item 332 * 333 * @param int $module_id Module ID 334 * @param int $item_id Item ID 335 * @param int $status Status of the comment 336 * 337 * @return array Array of {@link XoopsComment} objects 338 **/ 339 function getCountByItemId($module_id, $item_id, $status = null) 340 { 341 $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id))); 342 $criteria->add(new Criteria('com_itemid', intval($item_id))); 343 if (isset($status)) { 344 $criteria->add(new Criteria('com_status', intval($status))); 345 } 346 return $this->getCount($criteria); 347 } 348 349 350 /** 351 * Get the top {@link XoopsComment}s 352 * 353 * @param int $module_id 354 * @param int $item_id 355 * @param strint $order 356 * @param int $status 357 * 358 * @return array Array of {@link XoopsComment} objects 359 **/ 360 function getTopComments($module_id, $item_id, $order, $status = null) 361 { 362 $criteria = new CriteriaCompo(new Criteria('com_modid', intval($module_id))); 363 $criteria->add(new Criteria('com_itemid', intval($item_id))); 364 $criteria->add(new Criteria('com_pid', 0)); 365 if (isset($status)) { 366 $criteria->add(new Criteria('com_status', intval($status))); 367 } 368 $criteria->setOrder($order); 369 return $this->getObjects($criteria); 370 } 371 372 /** 373 * Retrieve a whole thread 374 * 375 * @param int $comment_rootid 376 * @param int $comment_id 377 * @param int $status 378 * 379 * @return array Array of {@link XoopsComment} objects 380 **/ 381 function getThread($comment_rootid, $comment_id, $status = null) 382 { 383 $criteria = new CriteriaCompo(new Criteria('com_rootid', intval($comment_rootid))); 384 $criteria->add(new Criteria('com_id', intval($comment_id), '>=')); 385 if (isset($status)) { 386 $criteria->add(new Criteria('com_status', intval($status))); 387 } 388 return $this->getObjects($criteria); 389 } 390 391 /** 392 * Update 393 * 394 * @param object &$comment {@link XoopsComment} object 395 * @param string $field_name Name of the field 396 * @param mixed $field_value Value to write 397 * 398 * @return bool 399 **/ 400 function updateByField(&$comment, $field_name, $field_value) 401 { 402 $comment->unsetNew(); 403 $comment->setVar($field_name, $field_value); 404 return $this->insert($comment); 405 } 406 407 /** 408 * Delete all comments for one whole module 409 * 410 * @param int $module_id ID of the module 411 * @return bool 412 **/ 413 function deleteByModule($module_id) 414 { 415 return $this->deleteAll(new Criteria('com_modid', intval($module_id))); 416 } 417 418 /** 419 * Change a value in multiple comments 420 * 421 * @param string $fieldname Name of the field 422 * @param string $fieldvalue Value to write 423 * @param object $criteria {@link CriteriaElement} 424 * 425 * @return bool 426 **/ 427 /* 428 function updateAll($fieldname, $fieldvalue, $criteria = null) 429 { 430 $set_clause = is_numeric($fieldvalue) ? $filedname.' = '.$fieldvalue : $filedname.' = '.$this->db->quoteString($fieldvalue); 431 $sql = 'UPDATE '.$this->db->prefix('xoopscomments').' SET '.$set_clause; 432 if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) { 433 $sql .= ' '.$criteria->renderWhere(); 434 } 435 if (!$result = $this->db->query($sql)) { 436 return false; 437 } 438 return true; 439 } 440 */ 441 } 442 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Nov 25 11:44:32 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |