From: <ok...@us...> - 2003-01-07 21:33:02
|
Update of /cvsroot/xoops/xoops2/class In directory sc8-pr-cvs1:/tmp/cvs-serv14503/class Modified Files: xoopsstory.php Added Files: commentrenderer.php tree.php Log Message: added global comments feature --- NEW FILE: commentrenderer.php --- <?php // $Id: commentrenderer.php,v 1.1 2003/01/07 21:31:56 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/) // // ------------------------------------------------------------------------- // class XoopsCommentRenderer { var $_tpl; var $_comments = null; var $_useIcons = true; var $_doIconCheck = false; var $_memberHandler; var $_statusText; function XoopsCommentRenderer(&$tpl, $use_icons = true, $do_iconcheck = false) { $this->_tpl =& $tpl; $this->_useIcons = $use_icons; $this->_doIconCheck = $do_iconcheck; $this->_memberHandler =& xoops_gethandler('member'); $this->_statusText = array(XOOPS_COMMENT_PENDING => '<span style="text-decoration: none; font-weight: bold; color: #00ff00;">'._CM_PENDING.'</span>', XOOPS_COMMENT_ACTIVE => '<span style="text-decoration: none; font-weight: bold; color: #ff0000;">'._CM_ACTIVE.'</span>', XOOPS_COMMENT_HIDDEN => '<span style="text-decoration: none; font-weight: bold; color: #0000ff;">'._CM_HIDDEN.'</span>'); } function &instance(&$tpl, $use_icons = true, $do_iconcheck = false) { static $instance; if (!isset($instance)) { $instance = new XoopsCommentRenderer($tpl, $use_icons, $do_iconcheck); } return $instance; } function setComments(&$comments_arr) { if (isset($this->_comments)) { unset($this->_comments); } $this->_comments =& $comments_arr; } function renderFlatView($admin_view = false) { $count = count($this->_comments); for ($i = 0; $i < $count; $i++) { if (false != $this->_useIcons) { $title = $this->_getTitleIcon($this->_comments[$i]->getVar('com_icon')).' '.$this->_comments[$i]->getVar('com_title'); } else { $title = $this->_comments[$i]->getVar('com_title'); } $poster = $this->_getPosterArray($this->_comments[$i]->getVar('com_uid')); if (false != $admin_view) { $text = $this->_comments[$i]->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$this->_comments[$i]->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$this->_comments[$i]->getVar('com_ip').'</span></div>'; } else { // hide comments that are not active if (XOOPS_COMMENT_ACTIVE != $this->_comments[$i]->getVar('com_status')) { continue; } else { $text = $this->_comments[$i]->getVar('com_text'); } } $this->_tpl->append('comments', array('id' => $this->_comments[$i]->getVar('com_id'), 'title' => $title, 'text' => $text, 'date_posted' => formatTimestamp($this->_comments[$i]->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($this->_comments[$i]->getVar('com_modified'), 'm'), 'poster' => $poster)); } } function renderThreadView($comment_id = 0, $admin_view = false, $show_nav = true) { include_once XOOPS_ROOT_PATH.'/class/tree.php'; // construct comment tree $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid'); $tree =& $xot->getTree(); if (false != $this->_useIcons) { $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')).' '.$tree[$comment_id]['obj']->getVar('com_title'); } else { $title = $tree[$comment_id]['obj']->getVar('com_title'); } if (false != $show_nav && $tree[$comment_id]['obj']->getVar('com_pid') != 0) { $this->_tpl->assign('lang_top', _CM_TOP); $this->_tpl->assign('lang_parent', _CM_PARENT); $this->_tpl->assign('show_threadnav', true); } else { $this->_tpl->assign('show_threadnav', false); } if (false != $admin_view) { // admins can see all $text = $tree[$comment_id]['obj']->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$tree[$comment_id]['obj']->getVar('com_ip').'</span></div>'; } else { // hide comments that are not active if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) { // if there are any child comments, display them as root comments if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) { foreach ($tree[$comment_id]['child'] as $child_id) { $this->renderThreadView($child_id, $admin_view, false); } } return; } else { $text = $tree[$comment_id]['obj']->getVar('com_text'); } } $replies = array(); $this->_renderThreadReplies($tree, $comment_id, $replies, ' ', $admin_view); $show_replies = (count($replies) > 0) ? true : false; $this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid'), 'id' => $tree[$comment_id]['obj']->getVar('com_id'), 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid'), 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid'), 'title' => $title, 'text' => $text, 'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid')), 'replies' => $replies, 'show_replies' => $show_replies)); } function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix = '') { if ($depth > 0) { if (false != $this->_useIcons) { $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')).' '.$thread[$key]['obj']->getVar('com_title'); } else { $title = $thread[$key]['obj']->getVar('com_title'); } $title = (false != $admin_view) ? $title.' '.$this->_statusText[$thread[$key]['obj']->getVar('com_status')] : $title; $replies[] = array('id' => $key, 'prefix' => $current_prefix, 'date_posted' => formatTimestamp($thread[$key]['obj']->getVar('com_created'), 'm'), 'title' => $title, 'root_id' => $thread[$key]['obj']->getVar('com_rootid'), 'status' => $this->_statusText[$thread[$key]['obj']->getVar('com_status')], 'poster' => $this->_getPosterName($thread[$key]['obj']->getVar('com_uid'))); $current_prefix .= $prefix; } if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) { $depth++; foreach ($thread[$key]['child'] as $childkey) { if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) { // skip this comment if it is not active and continue on processing its child comments instead if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) { foreach ($thread[$childkey]['child'] as $childchildkey) { $this->_renderThreadReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth); } } } else { $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix); } } } } function renderNestView($comment_id = 0, $admin_view = false) { include_once XOOPS_ROOT_PATH.'/class/tree.php'; $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid'); $tree =& $xot->getTree(); if (false != $this->_useIcons) { $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')).' '.$tree[$comment_id]['obj']->getVar('com_title'); } else { $title = $tree[$comment_id]['obj']->getVar('com_title'); } if (false != $admin_view) { $text = $tree[$comment_id]['obj']->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-bottom: 0px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$tree[$comment_id]['obj']->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$tree[$comment_id]['obj']->getVar('com_ip').'</span></div>'; } else { // skip this comment if it is not active and continue on processing its child comments instead if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) { // if there are any child comments, display them as root comments if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) { foreach ($tree[$comment_id]['child'] as $child_id) { $this->renderNestView($child_id, $admin_view); } } return; } else { $text = $tree[$comment_id]['obj']->getVar('com_text'); } } $replies = array(); $this->_renderNestReplies($tree, $comment_id, $replies, 25, $admin_view); $this->_tpl->append('comments', array('pid' => $tree[$comment_id]['obj']->getVar('com_pid'), 'id' => $tree[$comment_id]['obj']->getVar('com_id'), 'itemid' => $tree[$comment_id]['obj']->getVar('com_itemid'), 'rootid' => $tree[$comment_id]['obj']->getVar('com_rootid'), 'title' => $title, 'text' => $text, 'date_posted' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($tree[$comment_id]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($tree[$comment_id]['obj']->getVar('com_uid')), 'replies' => $replies)); } function _renderNestReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0) { if ($depth > 0) { if (false != $this->_useIcons) { $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')).' '.$thread[$key]['obj']->getVar('com_title'); } else { $title = $thread[$key]['obj']->getVar('com_title'); } $text = (false != $admin_view) ? $thread[$key]['obj']->getVar('com_text').'<div style="text-align:right; margin-top: 2px; margin-right: 2px;">'._CM_STATUS.': '.$this->_statusText[$thread[$key]['obj']->getVar('com_status')].'<br />IP: <span style="font-weight: bold;">'.$thread[$key]['obj']->getVar('com_ip').'</span></div>' : $thread[$key]['obj']->getVar('com_text'); $replies[] = array('id' => $key, 'prefix' => $prefix, 'pid' => $thread[$key]['obj']->getVar('com_pid'), 'itemid' => $thread[$key]['obj']->getVar('com_itemid'), 'rootid' => $thread[$key]['obj']->getVar('com_rootid'), 'title' => $title, 'text' => $text, 'date_posted' => formatTimestamp($thread[$key]['obj']->getVar('com_created'), 'm'), 'date_modified' => formatTimestamp($thread[$key]['obj']->getVar('com_modified'), 'm'), 'poster' => $this->_getPosterArray($thread[$key]['obj']->getVar('com_uid'))); $prefix = $prefix + 25; } if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) { $depth++; foreach ($thread[$key]['child'] as $childkey) { if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) { // skip this comment if it is not active and continue on processing its child comments instead if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) { foreach ($thread[$childkey]['child'] as $childchildkey) { $this->_renderNestReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth); } } } else { $this->_renderNestReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth); } } } } function _getPosterName($poster_id) { $poster['id'] = intval($poster_id); if ($poster['id'] > 0) { $com_poster =& $this->_memberHandler->getUser($poster_id); $poster['uname'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster['id'].'">'.$com_poster->getVar('uname').'</a>'; } else { $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous']; } return $poster; } function _getPosterArray($poster_id) { $poster['id'] = intval($poster_id); if ($poster['id'] > 0) { $com_poster =& $this->_memberHandler->getUser($poster_id); $poster['uname'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster['id'].'">'.$com_poster->getVar('uname').'</a>'; $poster_rank = $com_poster->rank(); if ( $poster_rank['image'] != '' ) { $poster['rank_image'] = $poster_rank['image']; } $poster['rank_title'] = $poster_rank['title']; $poster['avatar'] = $com_poster->getVar('user_avatar'); $poster['regdate'] = formatTimestamp($com_poster->getVar('user_regdate'), 's'); $poster['from'] = $com_poster->getVar('user_from'); $poster['postnum'] = $com_poster->getVar('posts'); $poster['status'] = $com_poster->isOnline() ? _CM_ONLINE : ''; } else { $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous']; $poster['rank_title'] = ''; $poster['avatar'] = 'blank.gif'; $poster['regdate'] = ''; $poster['from'] = ''; $poster['postnum'] = 0; $poster['status'] = ''; } return $poster; } function _getTitleIcon($icon_image) { if ($icon_image != '') { if (false != $this->_doIconCheck) { if (!file_exists(XOOPS_URL.'/images/subject/'.$icon_image)) { return '<img src="'.XOOPS_URL.'/images/icons/posticon.gif" alt="" />'; } else { return '<img src="'.XOOPS_URL.'/images/subject/'.$icon_image.'" alt="" />'; } } else { return '<img src="'.XOOPS_URL.'/images/subject/'.$icon_image.'" alt="" />'; } } return '<img src="'.XOOPS_URL.'/images/icons/posticon.gif" alt="" />'; } } ?> --- NEW FILE: tree.php --- <?php // $Id: tree.php,v 1.1 2003/01/07 21:31:58 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/) // // ------------------------------------------------------------------------- // class XoopsObjectTree { var $_parentId; var $_myId; var $_rootId = null; var $_tree = array(); var $_objects; function XoopsObjectTree(&$objectArr, $myId, $parentId, $rootId = null) { $this->_objects =& $objectArr; $this->_myId = $myId; $this->_parentId = $parentId; if (isset($rootId)) { $this->_rootId = $rootId; } $this->_initialize(); } function _initialize() { $count = count($this->_objects); for ($i = 0; $i < $count; $i++) { $key1 = $this->_objects[$i]->getVar($this->_myId); $this->_tree[$key1]['obj'] =& $this->_objects[$i]; $key2 = $this->_objects[$i]->getVar($this->_parentId); $this->_tree[$key1]['parent'] = $key2; $this->_tree[$key2]['child'][] = $key1; if (isset($this->_rootId)) { $this->_tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId); } } } function &getTree() { return $this->_tree; } function &getFirstChild($key) { $ret = array(); if (isset($this->_tree[$key]['child'])) { foreach ($this->_tree[$key]['child'] as $childkey) { $ret[$childkey] =& $this->_tree[$childkey]['obj']; } } return $ret; } function &getAllChild($key, $ret = array()) { if (isset($this->_tree[$key]['child'])) { foreach ($this->_tree[$key]['child'] as $childkey) { $ret[$childkey] =& $this->_tree[$childkey]['obj']; $children =& $this->getAllChild($childkey, $ret); $count = count($children); foreach (array_keys($children) as $newkey) { $ret[$newkey] =& $children[$newkey]; } } } return $ret; } function _makeSelBoxOptions($fieldName, $key, &$ret, $prefix, $original=null) { $original = !isset($original) ? $prefix : $original; if ($key > 0) { $ret .= '<option value="'.$this->_tree[$key]['obj']->getVar($this->_myId).'">'.$prefix.$this->_tree[$key]['obj']->getVar($fieldName).'</option>'; $prefix .= $original; } if (isset($this->_tree[$key]['child']) && !empty($this->_tree[$key]['child'])) { foreach ($this->_tree[$key]['child'] as $childkey) { $this->_makeSelBoxOptions($fieldName, $childkey, $ret, $prefix, $original); } } } function &makeSelBox($name, $fieldName, $key=0, $prefix='-') { $ret = '<select name='.$name.'>'; $this->_makeSelBoxOptions($fieldName, $key, $ret, $prefix); return $ret.'</select>'; } } ?> Index: xoopsstory.php =================================================================== RCS file: /cvsroot/xoops/xoops2/class/xoopsstory.php,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** xoopsstory.php 2 Jan 2003 15:15:24 -0000 1.1 --- xoopsstory.php 7 Jan 2003 21:31:54 -0000 1.2 *************** *** 30,34 **** // ------------------------------------------------------------------------- // - include_once XOOPS_ROOT_PATH."/class/xoopscomments.php"; include_once XOOPS_ROOT_PATH."/class/xoopstopic.php"; include_once XOOPS_ROOT_PATH."/class/xoopsuser.php"; --- 30,33 ---- *************** *** 56,60 **** var $topicalign; var $db; - var $commentstable; var $topicstable; --- 55,58 ---- *************** *** 63,67 **** $this->db =& Database::getInstance(); $this->table = ""; - $this->commentstable = ""; $this->topicstable = ""; if ( is_array($storyid) ) { --- 61,64 ---- *************** *** 220,232 **** return false; } - if ( isset($this->commentstable) && $this->commentstable != "" ) { - $commentsarray = array(); - $com = new XoopsComments($this->commentstable,"storyid"); - $criteria = array("item_id=".$this->storyid."", "pid=0"); - $commentsarray = $com->getAllComments($criteria); - foreach($commentsarray as $comment){ - $comment->delete(); - } - } return true; } --- 217,220 ---- *************** *** 409,419 **** } return $this->topicalign; - } - - function getCommentsCount() - { - $result = $this->db->query("SELECT COUNT(*) FROM ".$this->commentstable." WHERE item_id=".$this->storyid.""); - list($count) = $this->db->fetchRow($result); - return $count; } } --- 397,400 ---- |