b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (CVS HEAD) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _commentlist.class.php

Documentation is available at _commentlist.class.php

  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-2010 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.15 2010/02/08 17:52:13 efy-yury 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''DataObjectList' );
  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.      * @param string 
  43.      * @param array 
  44.      * @param integer Restrict to specific post
  45.      * @param string Order ("ASC"/"DESC")
  46.      * @param string List of fields to order by (separated by " ")
  47.      * @param integer Limit
  48.      */
  49.     function CommentList(
  50.         $Blog,
  51.         $comment_types "'comment'",
  52.         $show_statuses array'published' ),    // Restrict to these statuses
  53.         $p '',                                                            // Restrict to specific post
  54.         $author '',                                                    // Not used yet
  55.         $order 'DESC',                                            // ASC or DESC
  56.         $orderby '',                                                // list of fields to order by
  57.         $limit '',                                                    // # of comments to display on the page
  58.         $exclude array()                                            
  59.         )
  60.     {
  61.         global $DB;
  62.  
  63.         // Call parent constructor:
  64.         parent::DataObjectList'T_comments''comment_''comment_ID''Item'NULL$limit );
  65.  
  66.         $this->sql = 'SELECT DISTINCT T_comments.*
  67.                                     FROM T_comments INNER JOIN T_items__item ON comment_post_ID = post_ID ';
  68.  
  69.         if!empty$p ) )
  70.         {    // Restrict to comments on selected post
  71.             $this->sql .= 'WHERE comment_post_ID = '.$p;
  72.         }
  73.         else
  74.         {
  75.             $this->sql .= 'INNER JOIN T_postcats ON post_ID = postcat_post_ID
  76.                                         INNER JOIN T_categories othercats ON postcat_cat_ID = othercats.cat_ID ';
  77.  
  78.             $this->sql .= 'WHERE '.$Blog->get_sql_where_aggregate_coll_IDs('othercats.cat_blog_ID');
  79.         }
  80.  
  81.         $this->sql .= ' AND comment_type IN ('.$comment_types.') ';
  82.  
  83.         /*
  84.          * ----------------------------------------------------
  85.          *  Restrict to the statuses we want to show:
  86.          * ----------------------------------------------------
  87.          */
  88.         ifempty$show_statuses ) )
  89.         {
  90.             $this->sql .= ' AND comment_status IN (\''.implode"', '"$show_statuses ).'\')';
  91.         }
  92.  
  93.         // This one restricts to post statuses, but it doesn't work completely right:
  94.         // TODO: handle status dependencies with post
  95.         $this->sql .= ' AND '.statuses_where_clause();
  96.  
  97.         // Exclude comments
  98.         if!empty$exclude ) )
  99.         {
  100.             $this->sql .= ' AND comment_ID NOT IN ('.implode","$exclude ).')';
  101.         }
  102.  
  103.         // order by stuff
  104.         if( (!empty($order)) && !in_arraystrtoupper($order)array'ASC''DESC''RAND' ) ) )
  105.         {
  106.             $order='DESC';
  107.         }
  108.  
  109.         if(empty($orderby))
  110.         {
  111.             $orderby 'comment_date '.$order.', comment_ID '.$order;
  112.         }
  113.         else
  114.         {
  115.             $orderby_array explode(' ',$orderby);
  116.             $orderby $orderby_array[0].' '.$order;
  117.             if (count($orderby_array)>1)
  118.             {
  119.                 for($i 1$i (count($orderby_array))$i++)
  120.                 {
  121.                     $orderby .= ', comment_'.$orderby_array[$i].' '.$order;
  122.                 }
  123.             }
  124.         }
  125.  
  126.         if$order == 'RAND' $orderby 'RAND()';
  127.  
  128.         $this->sql .= "ORDER BY $orderby";
  129.         if!empty$this->limit ) )
  130.         {
  131.             $this->sql .= ' LIMIT '.$this->limit;
  132.         }
  133.  
  134.         // echo $this->sql;
  135.  
  136.         $this->rows = $DB->get_results$this->sqlARRAY_A );
  137.  
  138.         // Prebuild and cache objects:
  139.         if$this->result_num_rows = $DB->num_rows )
  140.         {    // fplanque>> why this test??
  141.  
  142.             $i 0;
  143.             foreach$this->rows as $row )
  144.             {
  145.                 // Prebuild object:
  146.                 $this->Obj[$inew Comment$row )// COPY (function)
  147.  
  148.                 // To avoid potential future waste, cache this object:
  149.                 // $this->DataObjectCache->add( $this->Obj[$i] );
  150.  
  151.                 $i++;
  152.             }
  153.         }
  154.     }
  155.  
  156.  
  157.     /**
  158.      * Template function: display message if list is empty
  159.      *
  160.      * @return boolean true if empty
  161.      */
  162.     function display_if_empty$params array() )
  163.     {
  164.         // Make sure we are not missing any param:
  165.         $params array_mergearray(
  166.                 'msg_empty'   => T_('No comment yet...'),
  167.             )$params );
  168.  
  169.         return parent::display_if_empty$params );
  170.     }
  171.  
  172. }
  173.  
  174. /*
  175.  * $Log: _commentlist.class.php,v $
  176.  * Revision 1.15  2010/02/08 17:52:13  efy-yury
  177.  * copyright 2009 -> 2010
  178.  *
  179.  * Revision 1.14  2009/11/30 00:22:05  fplanque
  180.  * clean up debug info
  181.  * show more timers in view of block caching
  182.  *
  183.  * Revision 1.13  2009/11/25 16:05:02  efy-maxim
  184.  * comments awaiting moderation improvements
  185.  *
  186.  * Revision 1.12  2009/09/14 12:46:36  efy-arrin
  187.  * Included the ClassName in load_class() call with proper UpperCase
  188.  *
  189.  * Revision 1.11  2009/03/08 23:57:42  fplanque
  190.  * 2009
  191.  *
  192.  * Revision 1.10  2009/03/03 20:45:07  blueyed
  193.  * Drop unnecessary global assignments in CommentList.
  194.  *
  195.  * Revision 1.9  2009/01/25 19:09:32  blueyed
  196.  * phpdoc fixes
  197.  *
  198.  * Revision 1.8  2009/01/23 00:05:24  blueyed
  199.  * Add Blog::get_sql_where_aggregate_coll_IDs, which adds support for '*' in list of aggregated blogs.
  200.  *
  201.  * Revision 1.7  2008/09/24 08:46:45  fplanque
  202.  * Fixed random order
  203.  *
  204.  * Revision 1.6  2008/01/21 09:35:27  fplanque
  205.  * (c) 2008
  206.  *
  207.  * Revision 1.5  2008/01/10 19:56:58  fplanque
  208.  * moved to v-3-0
  209.  *
  210.  * Revision 1.4  2008/01/09 00:25:51  blueyed
  211.  * Vastly improve performance in CommentList for large number of comments:
  212.  * - add index comment_date_ID; and force it in the SQL (falling back to comment_date)
  213.  *
  214.  * Revision 1.3  2007/12/24 10:36:07  yabs
  215.  * adding random order
  216.  *
  217.  * Revision 1.2  2007/11/03 21:04:26  fplanque
  218.  * skin cleanup
  219.  *
  220.  * Revision 1.1  2007/06/25 10:59:42  fplanque
  221.  * MODULES (refactored MVC)
  222.  *
  223.  * Revision 1.9  2007/06/20 23:00:14  blueyed
  224.  * doc fixes
  225.  *
  226.  * Revision 1.8  2007/05/14 02:43:04  fplanque
  227.  * Started renaming tables. There probably won't be a better time than 2.0.
  228.  *
  229.  * Revision 1.7  2007/04/26 00:11:08  fplanque
  230.  * (c) 2007
  231.  *
  232.  * Revision 1.6  2006/12/17 23:42:38  fplanque
  233.  * Removed special behavior of blog #1. Any blog can now aggregate any other combination of blogs.
  234.  * Look into Advanced Settings for the aggregating blog.
  235.  * There may be side effects and new bugs created by this. Please report them :]
  236.  *
  237.  * Revision 1.5  2006/07/04 17:32:29  fplanque
  238.  * no message
  239.  *
  240.  * Revision 1.4  2006/04/20 16:31:30  fplanque
  241.  * comment moderation (finished for 1.8)
  242.  *
  243.  * Revision 1.3  2006/04/18 19:29:51  fplanque
  244.  * basic comment status implementation
  245.  *
  246.  * Revision 1.2  2006/03/12 23:08:58  fplanque
  247.  * doc cleanup
  248.  *
  249.  * Revision 1.1  2006/02/23 21:11:57  fplanque
  250.  * File reorganization to MVC (Model View Controller) architecture.
  251.  * See index.hml files in folders.
  252.  * (Sorry for all the remaining bugs induced by the reorg... :/)
  253.  *
  254.  * Revision 1.14  2005/12/19 19:30:14  fplanque
  255.  * minor
  256.  *
  257.  * Revision 1.13  2005/12/12 19:21:21  fplanque
  258.  * big merge; lots of small mods; hope I didn't make to many mistakes :]
  259.  *
  260.  * Revision 1.12  2005/11/21 20:37:39  fplanque
  261.  * Finished RSS skins; turned old call files into stubs.
  262.  *
  263.  * Revision 1.11  2005/11/18 22:05:41  fplanque
  264.  * no message
  265.  *
  266.  * Revision 1.10  2005/10/03 18:10:07  fplanque
  267.  * renamed post_ID field
  268.  *
  269.  * Revision 1.9  2005/09/06 17:13:54  fplanque
  270.  * stop processing early if referer spam has been detected
  271.  *
  272.  * Revision 1.8  2005/08/25 16:06:45  fplanque
  273.  * Isolated compilation of categories to use in an ItemList.
  274.  * This was one of the oldest bugs on the list! :>
  275.  *
  276.  * Revision 1.7  2005/04/07 17:55:50  fplanque
  277.  * minor changes
  278.  *
  279.  * Revision 1.6  2005/03/14 20:22:19  fplanque
  280.  * refactoring, some cacheing optimization
  281.  *
  282.  * Revision 1.5  2005/03/09 20:29:39  fplanque
  283.  * added 'unit' param to allow choice between displaying x days or x posts
  284.  * deprecated 'paged' mode (ultimately, everything should be pageable)
  285.  *
  286.  * Revision 1.4  2005/03/06 16:30:40  blueyed
  287.  * deprecated global table names.
  288.  *
  289.  * Revision 1.3  2005/02/28 09:06:32  blueyed
  290.  * removed constants for DB config (allows to override it from _config_TEST.php), introduced EVO_CONFIG_LOADED
  291.  *
  292.  * Revision 1.2  2004/10/14 18:31:25  blueyed
  293.  * granting copyright
  294.  *
  295.  * Revision 1.1  2004/10/13 22:46:32  fplanque
  296.  * renamed [b2]evocore/*
  297.  *
  298.  * Revision 1.20  2004/10/11 19:13:14  fplanque
  299.  * Edited code documentation.
  300.  *
  301.  */
  302. ?>

Documentation generated on Sat, 06 Mar 2010 04:06:41 +0100 by phpDocumentor 1.4.2. This site is hosted and maintained by Daniel HAHLER (Contact).