[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/comments/model/ -> _commentlist.class.php (source)

   1  <?php
   2  /**

   3   * This file implements the CommentList class.

   4   *

   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}.

   6   * See also {@link http://sourceforge.net/projects/evocms/}.

   7   *

   8   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}.

   9   * Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.

  10   *

  11   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)

  12   *

  13   * {@internal Open Source relicensing agreement:

  14   * Daniel HAHLER grants Francois PLANQUE the right to license

  15   * Daniel HAHLER's contributions to this file and the b2evolution project

  16   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  17   * }}

  18   *

  19   * @package evocore

  20   *

  21   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  22   * @author blueyed: Daniel HAHLER.

  23   * @author fplanque: Francois PLANQUE

  24   *

  25   * @version $Id: _commentlist.class.php,v 1.2 2007/11/03 21:04:26 fplanque Exp $

  26   */
  27  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  28  
  29  load_class('_core/model/dataobjects/_dataobjectlist.class.php');
  30  
  31  /**

  32   * CommentList Class

  33   *

  34   * @package evocore

  35   */
  36  class CommentList extends DataObjectList
  37  {
  38      /**

  39       * Constructor

  40       *

  41       * @param Blog can pass NULL if $p is passed

  42       */
  43  	function CommentList(
  44          $Blog,
  45          $comment_types = "'comment'",
  46          $show_statuses = array( 'published' ),    // Restrict to these statuses
  47          $p = '',                                                            // Restrict to specific post
  48          $author = '',                                                    // Not used yet
  49          $order = 'DESC',                                            // ASC or DESC
  50          $orderby = '',                                                // list of fields to order by
  51          $limit = ''                                                     // # of comments to display on the page
  52          )
  53      {
  54          global $DB;
  55          global $cache_categories;
  56          global $pagenow;        // Bleh !

  57  
  58          // Call parent constructor:

  59          parent::DataObjectList( 'T_comments', 'comment_', 'comment_ID', 'Item', NULL, $limit );
  60  
  61          $this->sql = 'SELECT DISTINCT T_comments.*
  62                                      FROM T_comments INNER JOIN T_items__item ON comment_post_ID = post_ID ';
  63  
  64          if( !empty( $p ) )
  65          {    // Restrict to comments on selected post
  66              $this->sql .= 'WHERE comment_post_ID = '.$p;
  67          }
  68          else
  69          {
  70              $this->sql .= 'INNER JOIN T_postcats ON post_ID = postcat_post_ID
  71                                          INNER JOIN T_categories othercats ON postcat_cat_ID = othercats.cat_ID ';
  72  
  73              $aggregate_coll_IDs = $Blog->get_setting('aggregate_coll_IDs');
  74              if( empty( $aggregate_coll_IDs ) )
  75              {    // We only want posts from the current blog:
  76                  $this->sql .= 'WHERE othercats.cat_blog_ID = '.$Blog->ID;
  77              }
  78              else
  79              {    // We are aggregating posts from several blogs:
  80                  $this->sql .= 'WHERE othercats.cat_blog_ID IN ('.$aggregate_coll_IDs.')';
  81              }
  82          }
  83  
  84          $this->sql .= ' AND comment_type IN ('.$comment_types.') ';
  85  
  86          /*

  87           * ----------------------------------------------------

  88           *  Restrict to the statuses we want to show:

  89           * ----------------------------------------------------

  90           */
  91          if( ! empty( $show_statuses ) )
  92          {
  93              $this->sql .= ' AND comment_status IN (\''.implode( "', '", $show_statuses ).'\')';
  94          }
  95  
  96          // This one restricts to post statuses, but it doesn't work completely right:

  97          // TODO: handle status dependencies with post

  98          $this->sql .= ' AND '.statuses_where_clause();
  99  
 100  
 101          // order by stuff

 102          if( (!empty($order)) && ((strtoupper($order) != 'ASC') && (strtoupper($order) != 'DESC')))
 103          {
 104              $order='DESC';
 105          }
 106  
 107          if(empty($orderby))
 108          {
 109              $orderby = 'comment_date '.$order;
 110          }
 111          else
 112          {
 113              $orderby_array = explode(' ',$orderby);
 114              $orderby = $orderby_array[0].' '.$order;
 115              if (count($orderby_array)>1)
 116              {
 117                  for($i = 1; $i < (count($orderby_array)); $i++)
 118                  {
 119                      $orderby .= ', comment_'.$orderby_array[$i].' '.$order;
 120                  }
 121              }
 122          }
 123  
 124  
 125          $this->sql .= "ORDER BY $orderby";
 126          if( !empty( $this->limit ) )
 127          {
 128              $this->sql .= ' LIMIT '.$this->limit;
 129          }
 130  
 131          // echo $this->sql;

 132  
 133          $this->rows = $DB->get_results( $this->sql, ARRAY_A );
 134  
 135          // Prebuild and cache objects:

 136          if( $this->result_num_rows = $DB->num_rows )
 137          {    // fplanque>> why this test??
 138  
 139              $i = 0;
 140              foreach( $this->rows as $row )
 141              {
 142                  // Prebuild object:

 143                  $this->Obj[$i] = new Comment( $row ); // COPY (function)

 144  
 145                  // To avoid potential future waste, cache this object:

 146                  // $this->DataObjectCache->add( $this->Obj[$i] );

 147  
 148                  $i++;
 149              }
 150          }
 151      }
 152  
 153  
 154      /**

 155       * Template function: display message if list is empty

 156       *

 157       * @return boolean true if empty

 158       */
 159  	function display_if_empty( $params = array() )
 160      {
 161          // Make sure we are not missing any param:

 162          $params = array_merge( array(
 163                  'msg_empty'   => T_('No comment yet...'),
 164              ), $params );
 165  
 166          return parent::display_if_empty( $params );
 167      }
 168  
 169  }
 170  
 171  /*

 172   * $Log: _commentlist.class.php,v $

 173   * Revision 1.2  2007/11/03 21:04:26  fplanque

 174   * skin cleanup

 175   *

 176   * Revision 1.1  2007/06/25 10:59:42  fplanque

 177   * MODULES (refactored MVC)

 178   *

 179   * Revision 1.9  2007/06/20 23:00:14  blueyed

 180   * doc fixes

 181   *

 182   * Revision 1.8  2007/05/14 02:43:04  fplanque

 183   * Started renaming tables. There probably won't be a better time than 2.0.

 184   *

 185   * Revision 1.7  2007/04/26 00:11:08  fplanque

 186   * (c) 2007

 187   *

 188   * Revision 1.6  2006/12/17 23:42:38  fplanque

 189   * Removed special behavior of blog #1. Any blog can now aggregate any other combination of blogs.

 190   * Look into Advanced Settings for the aggregating blog.

 191   * There may be side effects and new bugs created by this. Please report them :]

 192   *

 193   * Revision 1.5  2006/07/04 17:32:29  fplanque

 194   * no message

 195   *

 196   * Revision 1.4  2006/04/20 16:31:30  fplanque

 197   * comment moderation (finished for 1.8)

 198   *

 199   * Revision 1.3  2006/04/18 19:29:51  fplanque

 200   * basic comment status implementation

 201   *

 202   * Revision 1.2  2006/03/12 23:08:58  fplanque

 203   * doc cleanup

 204   *

 205   * Revision 1.1  2006/02/23 21:11:57  fplanque

 206   * File reorganization to MVC (Model View Controller) architecture.

 207   * See index.hml files in folders.

 208   * (Sorry for all the remaining bugs induced by the reorg... :/)

 209   *

 210   * Revision 1.14  2005/12/19 19:30:14  fplanque

 211   * minor

 212   *

 213   * Revision 1.13  2005/12/12 19:21:21  fplanque

 214   * big merge; lots of small mods; hope I didn't make to many mistakes :]

 215   *

 216   * Revision 1.12  2005/11/21 20:37:39  fplanque

 217   * Finished RSS skins; turned old call files into stubs.

 218   *

 219   * Revision 1.11  2005/11/18 22:05:41  fplanque

 220   * no message

 221   *

 222   * Revision 1.10  2005/10/03 18:10:07  fplanque

 223   * renamed post_ID field

 224   *

 225   * Revision 1.9  2005/09/06 17:13:54  fplanque

 226   * stop processing early if referer spam has been detected

 227   *

 228   * Revision 1.8  2005/08/25 16:06:45  fplanque

 229   * Isolated compilation of categories to use in an ItemList.

 230   * This was one of the oldest bugs on the list! :>

 231   *

 232   * Revision 1.7  2005/04/07 17:55:50  fplanque

 233   * minor changes

 234   *

 235   * Revision 1.6  2005/03/14 20:22:19  fplanque

 236   * refactoring, some cacheing optimization

 237   *

 238   * Revision 1.5  2005/03/09 20:29:39  fplanque

 239   * added 'unit' param to allow choice between displaying x days or x posts

 240   * deprecated 'paged' mode (ultimately, everything should be pageable)

 241   *

 242   * Revision 1.4  2005/03/06 16:30:40  blueyed

 243   * deprecated global table names.

 244   *

 245   * Revision 1.3  2005/02/28 09:06:32  blueyed

 246   * removed constants for DB config (allows to override it from _config_TEST.php), introduced EVO_CONFIG_LOADED

 247   *

 248   * Revision 1.2  2004/10/14 18:31:25  blueyed

 249   * granting copyright

 250   *

 251   * Revision 1.1  2004/10/13 22:46:32  fplanque

 252   * renamed [b2]evocore/*

 253   *

 254   * Revision 1.20  2004/10/11 19:13:14  fplanque

 255   * Edited code documentation.

 256   *

 257   */
 258  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics