[ Index ]
 

Code source de XOOPS 2.0.17.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/htdocs/class/ -> commentrenderer.php (source)

   1  <?php
   2  // $Id: commentrenderer.php 2 2005-11-02 18:23:29Z 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   * Display comments

  33   *

  34   * @package        kernel

  35   * @subpackage    comment

  36   *

  37   * @author        Kazumi Ono     <onokazu@xoops.org>

  38   * @copyright    (c) 2000-2003 The Xoops Project - www.xoops.org

  39   */
  40  class XoopsCommentRenderer {
  41  
  42      /**#@+

  43       * @access    private

  44       */
  45      var $_tpl;
  46      var $_comments = null;
  47      var $_useIcons = true;
  48      var $_doIconCheck = false;
  49      var $_memberHandler;
  50      var $_statusText;
  51      /**#@-*/

  52  
  53      /**

  54       * Constructor

  55       * 

  56       * @param   object  &$tpl   

  57       * @param   boolean $use_icons

  58       * @param   boolean $do_iconcheck

  59       **/
  60  	function XoopsCommentRenderer(&$tpl, $use_icons = true, $do_iconcheck = false)
  61      {
  62          $this->_tpl =& $tpl;
  63          $this->_useIcons = $use_icons;
  64          $this->_doIconCheck = $do_iconcheck;
  65          $this->_memberHandler =& xoops_gethandler('member');
  66          $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>');
  67      }
  68  
  69      /**

  70       * Access the only instance of this class

  71       * 

  72       * @param   object  $tpl        reference to a {@link Smarty} object

  73       * @param   boolean $use_icons

  74       * @param   boolean $do_iconcheck

  75       * @return 

  76       **/
  77      function &instance(&$tpl, $use_icons = true, $do_iconcheck = false)
  78      {
  79          static $instance;
  80          if (!isset($instance)) {
  81              $instance = new XoopsCommentRenderer($tpl, $use_icons, $do_iconcheck);
  82          }
  83          return $instance;
  84      }
  85  
  86      /**

  87       * Accessor

  88       * 

  89       * @param   object  &$comments_arr  array of {@link XoopsComment} objects

  90       **/
  91  	function setComments(&$comments_arr)
  92      {
  93          if (isset($this->_comments)) {
  94              unset($this->_comments);
  95          }
  96          $this->_comments =& $comments_arr;
  97      }
  98  
  99      /**

 100       * Render the comments in flat view

 101       * 

 102       * @param boolean $admin_view

 103       **/
 104  	function renderFlatView($admin_view = false)
 105      {
 106          $count = count($this->_comments);
 107          for ($i = 0; $i < $count; $i++) {
 108              if (false != $this->_useIcons) {
 109                  $title = $this->_getTitleIcon($this->_comments[$i]->getVar('com_icon')).'&nbsp;'.$this->_comments[$i]->getVar('com_title');
 110              } else {
 111                  $title = $this->_comments[$i]->getVar('com_title');
 112              }
 113              $poster = $this->_getPosterArray($this->_comments[$i]->getVar('com_uid'));
 114              if (false != $admin_view) {
 115                  $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>';
 116              } else {
 117                  // hide comments that are not active

 118                  if (XOOPS_COMMENT_ACTIVE != $this->_comments[$i]->getVar('com_status')) {
 119                      continue;
 120                  } else {
 121                      $text = $this->_comments[$i]->getVar('com_text');
 122                  }
 123              }
 124              $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));
 125          }
 126      }
 127  
 128      /**

 129       * Render the comments in thread view

 130       * 

 131       * This method calls itself recursively

 132       * 

 133       * @param integer $comment_id   Should be "0" when called by client

 134       * @param boolean $admin_view

 135       * @param boolean $show_nav

 136       **/
 137  	function renderThreadView($comment_id = 0, $admin_view = false, $show_nav = true)
 138      {
 139          include_once XOOPS_ROOT_PATH.'/class/tree.php';
 140          // construct comment tree

 141          $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
 142          $tree =& $xot->getTree();
 143  
 144          if (false != $this->_useIcons) {
 145              $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')).'&nbsp;'.$tree[$comment_id]['obj']->getVar('com_title');
 146          } else {
 147              $title = $tree[$comment_id]['obj']->getVar('com_title');
 148          }
 149          if (false != $show_nav && $tree[$comment_id]['obj']->getVar('com_pid') != 0) {
 150              $this->_tpl->assign('lang_top', _CM_TOP);
 151              $this->_tpl->assign('lang_parent', _CM_PARENT);
 152              $this->_tpl->assign('show_threadnav', true);
 153          } else {
 154              $this->_tpl->assign('show_threadnav', false);
 155          }
 156          if (false != $admin_view) {
 157              // admins can see all

 158              $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>';
 159          } else {
 160              // hide comments that are not active

 161              if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
 162                  // if there are any child comments, display them as root comments

 163                  if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
 164                      foreach ($tree[$comment_id]['child'] as $child_id) {
 165                          $this->renderThreadView($child_id, $admin_view, false);
 166                      }
 167                  }
 168                  return;
 169              } else {
 170                  $text = $tree[$comment_id]['obj']->getVar('com_text');
 171              }
 172          }
 173          $replies = array();
 174          $this->_renderThreadReplies($tree, $comment_id, $replies, '&nbsp;&nbsp;', $admin_view);
 175          $show_replies = (count($replies) > 0) ? true : false;
 176          $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));
 177      }
 178  
 179      /**

 180       * Render replies to a thread

 181       * 

 182       * @param   array   &$thread

 183       * @param   int     $key

 184       * @param   array   $replies

 185       * @param   string  $prefix

 186       * @param   bool    $admin_view

 187       * @param   integer $depth

 188       * @param   string  $current_prefix

 189       * 

 190       * @access    private

 191       **/
 192  	function _renderThreadReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0, $current_prefix = '')
 193      {
 194          if ($depth > 0) {
 195              if (false != $this->_useIcons) {
 196                  $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')).'&nbsp;'.$thread[$key]['obj']->getVar('com_title');
 197              } else {
 198                  $title = $thread[$key]['obj']->getVar('com_title');
 199              }
 200              $title = (false != $admin_view) ? $title.' '.$this->_statusText[$thread[$key]['obj']->getVar('com_status')] : $title;
 201              $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')));
 202              $current_prefix .= $prefix;
 203          }
 204          if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) {
 205              $depth++;
 206              foreach ($thread[$key]['child'] as $childkey) {
 207                  if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
 208                      // skip this comment if it is not active and continue on processing its child comments instead

 209                      if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
 210                          foreach ($thread[$childkey]['child'] as $childchildkey) {
 211                              $this->_renderThreadReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
 212                          }
 213                      }
 214                  } else {
 215                      $this->_renderThreadReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth, $current_prefix);
 216                  }
 217              }
 218          }
 219      }
 220  
 221      /**

 222       * Render comments in nested view

 223       * 

 224       * Danger: Recursive!

 225       * 

 226       * @param integer $comment_id   Always "0" when called by client.

 227       * @param boolean $admin_view

 228       **/
 229  	function renderNestView($comment_id = 0, $admin_view = false)
 230      {
 231          include_once XOOPS_ROOT_PATH.'/class/tree.php';
 232          $xot = new XoopsObjectTree($this->_comments, 'com_id', 'com_pid', 'com_rootid');
 233          $tree =& $xot->getTree();
 234          if (false != $this->_useIcons) {
 235              $title = $this->_getTitleIcon($tree[$comment_id]['obj']->getVar('com_icon')).'&nbsp;'.$tree[$comment_id]['obj']->getVar('com_title');
 236          } else {
 237              $title = $tree[$comment_id]['obj']->getVar('com_title');
 238          }
 239          if (false != $admin_view) {
 240              $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>';
 241          } else {
 242              // skip this comment if it is not active and continue on processing its child comments instead

 243              if (XOOPS_COMMENT_ACTIVE != $tree[$comment_id]['obj']->getVar('com_status')) {
 244                  // if there are any child comments, display them as root comments

 245                  if (isset($tree[$comment_id]['child']) && !empty($tree[$comment_id]['child'])) {
 246                      foreach ($tree[$comment_id]['child'] as $child_id) {
 247                          $this->renderNestView($child_id, $admin_view);
 248                      }
 249                  }
 250                  return;
 251              } else {
 252                  $text = $tree[$comment_id]['obj']->getVar('com_text');
 253              }
 254          }
 255          $replies = array();
 256          $this->_renderNestReplies($tree, $comment_id, $replies, 25, $admin_view);
 257          $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));
 258      }
 259  
 260      /**

 261       * Render replies in nested view

 262       * 

 263       * @param   array   $thread

 264       * @param   int     $key

 265       * @param   array   $replies

 266       * @param   string  $prefix

 267       * @param   bool    $admin_view

 268       * @param   integer $depth

 269       * 

 270       * @access    private 

 271       **/
 272  	function _renderNestReplies(&$thread, $key, &$replies, $prefix, $admin_view, $depth = 0)
 273      {
 274          if ($depth > 0) {
 275              if (false != $this->_useIcons) {
 276                  $title = $this->_getTitleIcon($thread[$key]['obj']->getVar('com_icon')).'&nbsp;'.$thread[$key]['obj']->getVar('com_title');
 277              } else {
 278                  $title = $thread[$key]['obj']->getVar('com_title');
 279              }
 280              $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');
 281              $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')));
 282  
 283              $prefix = $prefix + 25;
 284          }
 285          if (isset($thread[$key]['child']) && !empty($thread[$key]['child'])) {
 286              $depth++;
 287              foreach ($thread[$key]['child'] as $childkey) {
 288                  if (!$admin_view && $thread[$childkey]['obj']->getVar('com_status') != XOOPS_COMMENT_ACTIVE) {
 289                      // skip this comment if it is not active and continue on processing its child comments instead

 290                      if (isset($thread[$childkey]['child']) && !empty($thread[$childkey]['child'])) {
 291                          foreach ($thread[$childkey]['child'] as $childchildkey) {
 292                              $this->_renderNestReplies($thread, $childchildkey, $replies, $prefix, $admin_view, $depth);
 293                          }
 294                      }
 295                  } else {
 296                      $this->_renderNestReplies($thread, $childkey, $replies, $prefix, $admin_view, $depth);
 297                  }
 298              }
 299          }
 300      }
 301  
 302  
 303      /**

 304       * Get the name of the poster

 305       * 

 306       * @param   int $poster_id

 307       * @return  string

 308       * 

 309       * @access    private

 310       **/
 311  	function _getPosterName($poster_id)
 312      {
 313          $poster['id'] = intval($poster_id);
 314          if ($poster['id'] > 0) {
 315              $com_poster =& $this->_memberHandler->getUser($poster_id);
 316              if (is_object($com_poster)) {
 317                  $poster['uname'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster['id'].'">'.$com_poster->getVar('uname').'</a>';
 318                  return $poster;
 319              }
 320          }
 321          $poster['id'] = 0; // to cope with deleted user accounts

 322          $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
 323          return $poster;
 324      }
 325  
 326      /**

 327       * Get an array with info about the poster

 328       * 

 329       * @param   int $poster_id

 330       * @return  array

 331       * 

 332       * @access    private

 333       **/
 334  	function _getPosterArray($poster_id)
 335      {
 336          $poster['id'] = intval($poster_id);
 337          if ($poster['id'] > 0) {
 338              $com_poster =& $this->_memberHandler->getUser($poster['id']);
 339              if (is_object($com_poster)) {
 340                  $poster['uname'] = '<a href="'.XOOPS_URL.'/userinfo.php?uid='.$poster['id'].'">'.$com_poster->getVar('uname').'</a>';
 341                  $poster_rank = $com_poster->rank();
 342                  $poster['rank_image'] = ($poster_rank['image'] != '') ? $poster_rank['image'] : 'blank.gif'; 
 343                  $poster['rank_title'] = $poster_rank['title'];
 344                  $poster['avatar'] = $com_poster->getVar('user_avatar');
 345                  $poster['regdate'] = formatTimestamp($com_poster->getVar('user_regdate'), 's');
 346                  $poster['from'] = $com_poster->getVar('user_from');
 347                  $poster['postnum'] = $com_poster->getVar('posts');
 348                  $poster['status'] = $com_poster->isOnline() ? _CM_ONLINE : '';
 349                  return $poster;
 350              }
 351          }
 352          $poster['id'] = 0; // to cope with deleted user accounts

 353          $poster['uname'] = $GLOBALS['xoopsConfig']['anonymous'];
 354          $poster['rank_title'] = '';
 355          $poster['avatar'] = 'blank.gif';
 356          $poster['regdate'] = '';
 357          $poster['from'] = '';
 358          $poster['postnum'] = 0;
 359          $poster['status'] = '';
 360          return $poster;
 361      }
 362  
 363      /**

 364       * Get the IMG tag for the title icon

 365       * 

 366       * @param   string  $icon_image

 367       * @return  string  HTML IMG tag

 368       * 

 369       * @access    private

 370       **/
 371  	function _getTitleIcon($icon_image)
 372      {
 373          $icon_image = htmlspecialchars( trim( $icon_image ) );
 374          if ($icon_image != '') {
 375              if (false != $this->_doIconCheck) {
 376                  if (!file_exists(XOOPS_URL.'/images/subject/'.$icon_image)) {
 377                      return '<img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />';
 378                  } else {
 379                      return '<img src="'.XOOPS_URL.'/images/subject/'.$icon_image.'" alt="" />';
 380                  }
 381              } else {
 382                  return '<img src="'.XOOPS_URL.'/images/subject/'.$icon_image.'" alt="" />';
 383              }
 384          }
 385          return '<img src="'.XOOPS_URL.'/images/icons/no_posticon.gif" alt="" />';
 386      }
 387  }
 388  ?>


Généré le : Sun Nov 25 11:44:32 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics