// // ------------------------------------------------------------------------ // // 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) { $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; return $ret; } /* Methods below will be moved to maybe another class? */ function printNavBar($item_id, $mode="flat", $order=1) { global $xoopsConfig, $xoopsUser; echo "
"; if ( $xoopsConfig['anonpost'] == 1 || $xoopsUser ) { if ($mode != "flat" || $mode != "nocomments" || $mode != "thread" ) { $mode = "flat"; } echo " "; } echo "
"; } function showThreadHead() { openThread(); } function showThreadPost($order, $mode, $adminview=0, $color_num=1) { global $xoopsConfig, $xoopsUser; $edit_image = ""; $reply_image = ""; $delete_image = ""; $post_date = formatTimestamp($this->getVar("date"),"m"); if ( $this->getVar("user_id") != 0 ) { $poster = new XoopsUser($this->getVar("user_id")); if ( !$poster->isActive() ) { $poster = 0; } } else { $poster = 0; } if ( $this->getVar("icon") != null && $this->getVar("icon") != "" ) { $subject_image = ""; } else { $subject_image = ""; } if ( $adminview ) { $ip_image = "".$this->getVar("ip").""; } else { $ip_image = ""; } if ( $adminview || ($xoopsUser && $this->getVar("user_id") == $xoopsUser->getVar("uid")) ) { $edit_image = ""._EDIT.""; } if ( $xoopsConfig['anonpost'] || $xoopsUser ) { $reply_image = ""._REPLY.""; } if ( $adminview ) { $delete_image = ""._DELETE.""; } if ( $poster ) { $text = $this->getVar("comment"); if ( $poster->getVar("attachsig") ) { $text .= "


_________________
". $poster->user_sig()."

"; } $reg_date = _CM_JOINED; $reg_date .= formatTimestamp($poster->getVar("user_regdate"),"s"); $posts = _CM_POSTS; $posts .= $poster->getVar("posts"); $user_from = _CM_FROM; $user_from .= $poster->getVar("user_from"); $rank = $poster->rank(); if ( $rank['image'] != "" ) { $rank['image'] = ""; } $avatar_image = ""; if ( $poster->isOnline() ) { $online_image = ""._ONLINE.""; } else { $online_image = ""; } $profile_image = ""._PROFILE.""; if ( $xoopsUser ) { $pm_image = "".sprintf(_SENDPMTO,$poster->getVar("uname", "E")).""; } else { $pm_image = ""; } if ( $poster->getVar("user_viewemail") ) { $email_image = "".sprintf(_SENDEMAILTO,$poster->getVar("uname", "E")).""; } else { $email_image = ""; } $posterurl = $poster->getVar("url"); if ( $posterurl != "" ) { $www_image = ""._VISITWEBSITE.""; } else { $www_image = ""; } if ( $poster->getVar("user_icq") != "" ) { $icq_image = ""._ADD.""; } else { $icq_image = ""; } if ( $poster->getVar("user_aim") != "" ) { $aim_image = "aim"; } else { $aim_image = ""; } if ( $poster->getVar("user_yim") != "" ) { $yim_image = "yim"; } else { $yim_image = ""; } if ( $poster->getVar("user_msnm") != "" ) { $msnm_image = "msnm"; } else { $msnm_image = ""; } 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); } else { showThread($color_num, $subject_image, $this->getVar("subject"), $this->getVar("comment"), $post_date, $ip_image, $reply_image, $edit_image, $delete_image, $xoopsConfig['anonymous']); } } function showThreadFoot() { closeThread(); } function showTreeHead($width="100%") { echo ""; } function showTreeItem($order, $mode, $color_num) { if ( $color_num == 1 ) { $bg = 'even'; } else { $bg = 'odd'; } $prefix = str_replace(".", "    ", $this->getVar("prefix")); $date = formatTimestamp($this->getVar("date"),"m"); if ( $this->getVar("icon") != "" ) { $icon = "subject/".$this->getVar("icon", "E"); } else { $icon = "icons/no_posticon.gif"; } echo ""; } function showTreeFoot() { echo "
". _CM_REPLIES ."
". _CM_TITLE ."". _CM_POSTER ."". _CM_POSTED ."
".$prefix." getVar("comment_id")."'>".$this->getVar("subject")."".XoopsUser::getUnameFromId($this->getVar("user_id"))."".$date."

"; } } ?>