| [ Index ] |
PHP Cross Reference of Xoops v2.4.5 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * XOOPS comments 4 * 5 * You may not change or alter any portion of this comment or credits 6 * of supporting developers from this source code or any supporting source code 7 * which is considered copyrighted (c) material of the original comment or credit authors. 8 * This program is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 11 * 12 * @copyright The XOOPS Project http://sourceforge.net/projects/xoops/ 13 * @license http://www.fsf.org/copyleft/gpl.html GNU public license 14 * @package kernel 15 * @since 2.0.0 16 * @author Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/ 17 * @version $Id: xoopscomments.php 4897 2010-06-19 02:55:48Z phppp $ 18 */ 19 20 defined('XOOPS_ROOT_PATH') or die('Restricted access'); 21 22 include_once XOOPS_ROOT_PATH . '/class/xoopstree.php'; 23 require_once XOOPS_ROOT_PATH . '/class/xoopsobject.php'; 24 include_once XOOPS_ROOT_PATH . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/comment.php'; 25 26 /** 27 * Xoops Comments Object Class 28 * 29 * @author Kazumi Ono <onokazu@xoops.org> 30 * @author John Neill <catzwolf@xoops.org> 31 * @copyright copyright (c) XOOPS.org 32 * @package kernel 33 * @subpackage comments 34 * @access public 35 */ 36 37 class XoopsComments extends XoopsObject 38 { 39 var $ctable; 40 var $db; 41 42 function XoopsComments($ctable, $id = null) 43 { 44 $this->ctable = $ctable; 45 $this->db =& XoopsDatabaseFactory::getDatabaseConnection();; 46 $this->XoopsObject(); 47 $this->initVar('comment_id', XOBJ_DTYPE_INT, null, false); 48 $this->initVar('item_id', XOBJ_DTYPE_INT, null, false); 49 $this->initVar('order', XOBJ_DTYPE_INT, null, false); 50 $this->initVar('mode', XOBJ_DTYPE_OTHER, null, false); 51 $this->initVar('subject', XOBJ_DTYPE_TXTBOX, null, false, 255); 52 $this->initVar('comment', XOBJ_DTYPE_TXTAREA, null, false, null); 53 $this->initVar('ip', XOBJ_DTYPE_OTHER, null, false); 54 $this->initVar('pid', XOBJ_DTYPE_INT, 0, false); 55 $this->initVar('date', XOBJ_DTYPE_INT, null, false); 56 $this->initVar('nohtml', XOBJ_DTYPE_INT, 1, false); 57 $this->initVar('nosmiley', XOBJ_DTYPE_INT, 0, false); 58 $this->initVar('noxcode', XOBJ_DTYPE_INT, 0, false); 59 $this->initVar('user_id', XOBJ_DTYPE_INT, null, false); 60 $this->initVar('icon', XOBJ_DTYPE_OTHER, null, false); 61 $this->initVar('prefix', XOBJ_DTYPE_OTHER, null, false); 62 if (!empty($id)) { 63 if (is_array($id)) { 64 $this->assignVars($id); 65 } else { 66 $this->load(intval($id)); 67 } 68 } 69 } 70 71 /** 72 * Load Comment by ID 73 * 74 * @param int $id 75 */ 76 function load($id) 77 { 78 $id = intval($id); 79 $sql = "SELECT * FROM " . $this->ctable . " WHERE comment_id=" . $id; 80 $arr = $this->db->fetchArray($this->db->query($sql)); 81 $this->assignVars($arr); 82 } 83 84 /** 85 * Save Comment 86 * 87 * @return int 88 */ 89 function store() 90 { 91 if (!$this->cleanVars()) { 92 return false; 93 } 94 foreach ($this->cleanVars as $k => $v) { 95 $$k = $v; 96 } 97 $isnew = false; 98 if (empty($comment_id)) { 99 $isnew = true; 100 $comment_id = $this->db->genId($this->ctable . "_comment_id_seq"); 101 $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); 102 } else { 103 $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); 104 } 105 if (! $result = $this->db->query($sql)) { 106 //echo $sql; 107 return false; 108 } 109 if (empty($comment_id)) { 110 $comment_id = $this->db->getInsertId(); 111 } 112 if ($isnew != false) { 113 $sql = sprintf("UPDATE %s SET posts = posts+1 WHERE uid = %u", $this->db->prefix("users"), $user_id); 114 if (!$result = $this->db->query($sql)) { 115 echo "Could not update user posts."; 116 } 117 } 118 return $comment_id; 119 } 120 121 /** 122 * Enter description here... 123 * 124 * @return int 125 */ 126 function delete() 127 { 128 $sql = sprintf("DELETE FROM %s WHERE comment_id = %u", $this->ctable, $this->getVar('comment_id')); 129 if (!$result = $this->db->query($sql)) { 130 return false; 131 } 132 $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $this->getVar("user_id")); 133 if (!$result = $this->db->query($sql)) { 134 echo "Could not update user posts."; 135 } 136 $mytree = new XoopsTree($this->ctable, "comment_id", "pid"); 137 $arr = $mytree->getAllChild($this->getVar("comment_id"), "comment_id"); 138 $size = count($arr); 139 if ($size > 0) { 140 for ($i = 0; $i < $size; $i++) { 141 $sql = sprintf("DELETE FROM %s WHERE comment_bid = %u", $this->ctable, $arr[$i]['comment_id']); 142 if (!$result = $this->db->query($sql)) { 143 echo "Could not delete comment."; 144 } 145 $sql = sprintf("UPDATE %s SET posts = posts-1 WHERE uid = %u", $this->db->prefix("users"), $arr[$i]['user_id']); 146 if (!$result = $this->db->query($sql)) { 147 echo "Could not update user posts."; 148 } 149 } 150 } 151 return ($size + 1); 152 } 153 154 /** 155 * Get Comments Tree 156 * 157 * @return unknown 158 */ 159 function getCommentTree() 160 { 161 $mytree = new XoopsTree($this->ctable, "comment_id", "pid"); 162 $ret = array(); 163 $tarray = $mytree->getChildTreeArray($this->getVar("comment_id"), "comment_id"); 164 foreach ($tarray as $ele) { 165 $ret[] = new XoopsComments($this->ctable, $ele); 166 } 167 return $ret; 168 } 169 170 /** 171 * Get All Comments using criteria match 172 * 173 * @param array $criteria 174 * @param bool $asobject 175 * @param string $orderby 176 * @param int $limit 177 * @param int $start 178 * @return array 179 */ 180 function getAllComments($criteria = array(), $asobject = true, $orderby = "comment_id ASC", $limit = 0, $start = 0) 181 { 182 $ret = array(); 183 $where_query = ""; 184 if (is_array($criteria) && count($criteria) > 0) { 185 $where_query = " WHERE"; 186 foreach ($criteria as $c) { 187 $where_query .= " $c AND"; 188 } 189 $where_query = substr($where_query, 0, - 4); 190 } 191 if (!$asobject) { 192 $sql = "SELECT comment_id FROM " . $this->ctable . "$where_query ORDER BY $orderby"; 193 $result = $this->db->query($sql, $limit, $start); 194 while ($myrow = $this->db->fetchArray($result)) { 195 $ret[] = $myrow['comment_id']; 196 } 197 } else { 198 $sql = "SELECT * FROM " . $this->ctable . "" . $where_query . " ORDER BY $orderby"; 199 $result = $this->db->query($sql, $limit, $start); 200 while ($myrow = $this->db->fetchArray($result)) { 201 $ret[] = new XoopsComments($this->ctable, $myrow); 202 } 203 } 204 //echo $sql; 205 return $ret; 206 } 207 208 /** 209 * Enter printNavBar 210 * 211 * @param int $item_id 212 * @param string type $mode 213 * @param int type $order 214 */ 215 function printNavBar($item_id, $mode = "flat", $order = 1) 216 { 217 global $xoopsConfig, $xoopsUser; 218 echo "<form method='get' action='" . $_SERVER['PHP_SELF'] . "'><table width='100%' border='0' cellspacing='1' cellpadding='2'><tr><td class='bg1' align='center'><select name='mode'><option value='nocomments'"; 219 if ($mode == "nocomments") { 220 echo " selected='selected'"; 221 } 222 echo ">" . _NOCOMMENTS . "</option><option value='flat'"; 223 if ($mode == 'flat') { 224 echo " selected='selected'"; 225 } 226 echo ">" . _FLAT . "</option><option value='thread'"; 227 if ($mode == "thread" || $mode == "") { 228 echo " selected='selected'"; 229 } 230 echo ">" . _THREADED . "</option></select><select name='order'><option value='0'"; 231 if ($order != 1) { 232 echo " selected='selected'"; 233 } 234 echo ">" . _OLDESTFIRST . "</option><option value='1'"; 235 if ($order == 1) { 236 echo " selected='selected'"; 237 } 238 echo ">" . _NEWESTFIRST . "</option></select><input type='hidden' name='item_id' value='" . intval($item_id) . "' /><input type='submit' value='" . _CM_REFRESH . "' />"; 239 if ($xoopsConfig['anonpost'] == 1 || $xoopsUser) { 240 if ($mode != "flat" || $mode != "nocomments" || $mode != "thread") { 241 $mode = "flat"; 242 } 243 echo " <input type='button' onclick='location=\"newcomment.php?item_id=" . intval($item_id) . "&order=" . intval($order) . "&mode=" . $mode . "\"' value='" . _CM_POSTCOMMENT . "' />"; 244 } 245 echo "</td></tr></table></form>"; 246 } 247 248 /** 249 * Show Thread 250 * 251 */ 252 function showThreadHead() 253 { 254 openThread(); 255 } 256 257 /** 258 * Enter description here... 259 * 260 * @param string $order 261 * @param string $mode 262 * @param int $adminview 263 * @param int $color_num 264 */ 265 function showThreadPost($order, $mode, $adminview = 0, $color_num = 1) 266 { 267 global $xoopsConfig, $xoopsUser; 268 $edit_image = ""; 269 $reply_image = ""; 270 $delete_image = ""; 271 $post_date = formatTimestamp($this->getVar("date"), "m"); 272 if ($this->getVar("user_id") != 0) { 273 $poster = new XoopsUser($this->getVar("user_id")); 274 if (!$poster->isActive()) { 275 $poster = 0; 276 } 277 } else { 278 $poster = 0; 279 } 280 if ($this->getVar("icon") != null && $this->getVar("icon") != "") { 281 $subject_image = "<a name='" . $this->getVar("comment_id") . "' id='" . $this->getVar("comment_id") . "'></a><img src='" . XOOPS_URL . "/images/subject/" . $this->getVar("icon") . "' alt='' />"; 282 } else { 283 $subject_image = "<a name='" . $this->getVar("comment_id") . "' id='" . $this->getVar("comment_id") . "'></a><img src='" . XOOPS_URL . "/images/icons/no_posticon.gif' alt='' />"; 284 } 285 if ($adminview) { 286 $ip_image = "<img src='" . XOOPS_URL . "/images/icons/ip.gif' alt='" . $this->getVar("ip") . "' />"; 287 } else { 288 $ip_image = "<img src='" . XOOPS_URL . "/images/icons/ip.gif' alt='' />"; 289 } 290 if ($adminview || ($xoopsUser && $this->getVar("user_id") == $xoopsUser->getVar("uid"))) { 291 $edit_image = "<a href='editcomment.php?comment_id=" . $this->getVar("comment_id") . "&mode=" . $mode . "&order=" . intval($order) . "'><img src='" . XOOPS_URL . "/images/icons/edit.gif' alt='" . _EDIT . "' /></a>"; 292 } 293 if ($xoopsConfig['anonpost'] || $xoopsUser) { 294 $reply_image = "<a href='replycomment.php?comment_id=" . $this->getVar("comment_id") . "&mode=" . $mode . "&order=" . intval($order) . "'><img src='" . XOOPS_URL . "/images/icons/reply.gif' alt='" . _REPLY . "' /></a>"; 295 } 296 if ($adminview) { 297 $delete_image = "<a href='deletecomment.php?comment_id=" . $this->getVar("comment_id") . "&mode=" . $mode . "&order=" . intval($order) . "'><img src='" . XOOPS_URL . "/images/icons/delete.gif' alt='" . _DELETE . "' /></a>"; 298 } 299 300 if ($poster) { 301 $text = $this->getVar("comment"); 302 if ($poster->getVar("attachsig")) { 303 $text .= "<p><br />_________________<br />" . $poster->user_sig() . "</p>"; 304 } 305 $reg_date = _CM_JOINED; 306 $reg_date .= formatTimestamp($poster->getVar("user_regdate"), "s"); 307 $posts = _CM_POSTS; 308 $posts .= $poster->getVar("posts"); 309 $user_from = _CM_FROM; 310 $user_from .= $poster->getVar("user_from"); 311 $rank = $poster->rank(); 312 if ($rank['image'] != "") { 313 $rank['image'] = "<img src='" . XOOPS_UPLOAD_URL . "/" . $rank['image'] . "' alt='' />"; 314 } 315 $avatar_image = "<img src='" . XOOPS_UPLOAD_URL . "/" . $poster->getVar("user_avatar") . "' alt='' />"; 316 if ($poster->isOnline()) { 317 $online_image = "<span style='color:#ee0000;font-weight:bold;'>" . _ONLINE . "</span>"; 318 } else { 319 $online_image = ""; 320 } 321 $profile_image = "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $poster->getVar("uid") . "'><img src='" . XOOPS_URL . "/images/icons/profile.gif' alt='" . _PROFILE . "' /></a>"; 322 if ($xoopsUser) { 323 $pm_image = "<a href='javascript:openWithSelfMain(\"" . XOOPS_URL . "/pmlite.php?send2=1&to_userid=" . $poster->getVar("uid") . "\",\"pmlite\",450,370);'><img src='" . XOOPS_URL . "/images/icons/pm.gif' alt='" . sprintf(_SENDPMTO, $poster->getVar("uname", "E")) . "' /></a>"; 324 } else { 325 $pm_image = ""; 326 } 327 if ($poster->getVar("user_viewemail")) { 328 $email_image = "<a href='mailto:" . $poster->getVar("email", "E") . "'><img src='" . XOOPS_URL . "/images/icons/email.gif' alt='" . sprintf(_SENDEMAILTO, $poster->getVar("uname", "E")) . "' /></a>"; 329 } else { 330 $email_image = ""; 331 } 332 $posterurl = $poster->getVar("url"); 333 if ($posterurl != "") { 334 $www_image = "<a href='$posterurl' rel='external'><img src='" . XOOPS_URL . "/images/icons/www.gif' alt='" . _VISITWEBSITE . "' /></a>"; 335 } else { 336 $www_image = ""; 337 } 338 if ($poster->getVar("user_icq") != "") { 339 $icq_image = "<a href='http://wwp.icq.com/scripts/search.dll?to=" . $poster->getVar("user_icq", "E") . "'><img src='" . XOOPS_URL . "/images/icons/icq_add.gif' alt='" . _ADD . "' /></a>"; 340 } else { 341 $icq_image = ""; 342 } 343 if ($poster->getVar("user_aim") != "") { 344 $aim_image = "<a href='aim:goim?screenname=" . $poster->getVar("user_aim", "E") . "&message=Hi+" . $poster->getVar("user_aim") . "+Are+you+there?'><img src='" . XOOPS_URL . "/images/icons/aim.gif' alt='aim' /></a>"; 345 } else { 346 $aim_image = ""; 347 } 348 if ($poster->getVar("user_yim") != "") { 349 $yim_image = "<a href='http://edit.yahoo.com/config/send_webmesg?.target=" . $poster->getVar("user_yim", "E") . "&.src=pg'><img src='" . XOOPS_URL . "/images/icons/yim.gif' alt='yim' /></a>"; 350 } else { 351 $yim_image = ""; 352 } 353 if ($poster->getVar("user_msnm") != "") { 354 $msnm_image = "<a href='" . XOOPS_URL . "/userinfo.php?uid=" . $poster->getVar("uid") . "'><img src='" . XOOPS_URL . "/images/icons/msnm.gif' alt='msnm' /></a>"; 355 } else { 356 $msnm_image = ""; 357 } 358 showThread($color_num, $subject_image, $this->getVar("subject"), $text, $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $poster->getVar("uname"), $rank['title'], $rank['image'], $avatar_image, $reg_date, $posts, $user_from, $online_image, $profile_image, $pm_image, $email_image, $www_image, $icq_image, $aim_image, $yim_image, $msnm_image); 359 } else { 360 showThread($color_num, $subject_image, $this->getVar("subject"), $this->getVar("comment"), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig['anonymous']); 361 } 362 } 363 364 /** 365 * Show Thread Footer 366 * 367 */ 368 function showThreadFoot() 369 { 370 closeThread(); 371 } 372 373 /** 374 * Show Thread Head 375 * 376 * @param int $width 377 */ 378 function showTreeHead($width = "100%") 379 { 380 echo "<table border='0' class='outer' cellpadding='0' cellspacing='0' align='center' width='$width'><tr class='bg3' align='center'><td colspan='3'>" . _CM_REPLIES . "</td></tr><tr class='bg3' align='left'><td width='60%' class='fg2'>" . _CM_TITLE . "</td><td width='20%' class='fg2'>" . _CM_POSTER . "</td><td class='fg2'>" . _CM_POSTED . "</td></tr>"; 381 } 382 383 /** 384 * Show Tree Items 385 * 386 * @param string $order 387 * @param string $mode 388 * @param int $color_num 389 */ 390 function showTreeItem($order, $mode, $color_num) 391 { 392 if ($color_num == 1) { 393 $bg = 'even'; 394 } else { 395 $bg = 'odd'; 396 } 397 $prefix = str_replace(".", " ", $this->getVar("prefix")); 398 $date = formatTimestamp($this->getVar("date"), "m"); 399 if ($this->getVar("icon") != "") { 400 $icon = "subject/" . $this->getVar("icon", "E"); 401 } else { 402 $icon = "icons/no_posticon.gif"; 403 } 404 echo "<tr class='$bg' align='left'><td>" . $prefix . "<img src='" . XOOPS_URL . "/images/" . $icon . "'> <a href='" . $_SERVER['PHP_SELF'] . "?item_id=" . $this->getVar("item_id") . "&comment_id=" . $this->getVar("comment_id") . "&mode=" . $mode . "&order=" . $order . "#" . $this->getVar("comment_id") . "'>" . $this->getVar("subject") . "</a></td><td><a href='" . XOOPS_URL . "/userinfo.php?uid=" . $this->getVar("user_id") . "'>" . XoopsUser::getUnameFromId($this->getVar("user_id")) . "</a></td><td>" . $date . "</td></tr>"; 405 } 406 407 /** 408 * Show Thread Foot 409 * 410 */ 411 function showTreeFoot() 412 { 413 echo "</table><br />"; 414 } 415 } 416 417 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 01:39:09 2010 |