b2evolution PHP Cross Reference Blogging Systems

Source: /inc/comments/model/_commentlist.class.php - 757 lines - 29037 bytes - Summary - Text - Print

Description: This file implements the CommentList2 class. This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the CommentList2 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-2014 by Francois Planque - {@link http://fplanque.com/}.
   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 asimo: Evo Factory - Attila Simo
  23   * @author blueyed: Daniel HAHLER
  24   * @author fplanque: Francois PLANQUE
  25   *
  26   * @version $Id: _commentlist.class.php 6136 2014-03-08 07:59:48Z manuel $
  27   */
  28  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  29  
  30  load_class( '_core/model/dataobjects/_dataobjectlist2.class.php', 'DataObjectList2' );
  31  
  32  /**
  33   * CommentList Class 2
  34   *
  35   * @package evocore
  36   */
  37  /**
  38   * @author asimo
  39   *
  40   */
  41  class CommentList2 extends DataObjectList2
  42  {
  43      /**
  44       * SQL object for the Query
  45       */
  46      var $CommentQuery;
  47  
  48      /**
  49       * SQL object for the ItemQuery
  50       *
  51       * This will be used to get those item Ids which comments should be listed
  52       */
  53      var $ItemQuery;
  54  
  55      /**
  56       * Blog object this CommentList refers to
  57       */
  58      var $Blog;
  59  
  60      /**
  61       * Constructor
  62       *
  63       * @param Blog This may be NULL only when must select comments from all Blog. Use NULL carefully, because it may generate very long queries!
  64       * @param integer|NULL Limit
  65       * @param string name of cache to be used
  66       * @param string prefix to differentiate page/order params when multiple Results appear one same page
  67       * @param string Name to be used when saving the filterset (leave empty to use default for collection)
  68       */
  69  	function CommentList2(
  70          $Blog,
  71          $limit = 1000,
  72          $cache_name = 'CommentCache',    // name of cache to be used
  73          $param_prefix = '',
  74          $filterset_name = ''            // Name to be used when saving the filterset (leave empty to use default for collection)
  75          )
  76      {
  77          global $Settings;
  78  
  79          // Call parent constructor:
  80          parent::DataObjectList2( get_Cache($cache_name), $limit, $param_prefix, NULL );
  81  
  82          // Set Blog. Note: It can be NULL on ?disp=usercomments
  83          $this->Blog = $Blog;
  84  
  85          // The SQL Query object:
  86          $this->CommentQuery = new CommentQuery(/* $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname*/ );
  87          $this->CommentQuery->Blog = $this->Blog;
  88  
  89          // The Item filter SQL Query object:
  90          $this->ItemQuery = new ItemQuery( 'T_items__item', 'post_', 'post_ID' );
  91          // Blog can be NULL on ?disp=usercomments, in this case ItemQuery blog must be set to 0, which means all blog
  92          $this->ItemQuery->blog = empty( $this->Blog ) ? 0 : $this->Blog->ID;
  93  
  94          if( !empty( $filterset_name ) )
  95          {    // Set the filterset_name with the filterset_name param
  96              $this->filterset_name = 'CommentList_filters_'.$filterset_name;
  97          }
  98          else
  99          {    // Set a generic filterset_name
 100              $this->filterset_name = 'CommentList_filters_coll'.( !is_null( $this->Blog ) ? $this->Blog->ID : '0' );
 101          }
 102  
 103          $this->page_param = $param_prefix.'paged';
 104  
 105          // Initialize the default filter set:
 106          $this->set_default_filters( array(
 107                  'filter_preset' => NULL,
 108                  'author_IDs' => NULL,
 109                  'author' => NULL,
 110                  'author_email' => NULL,
 111                  'author_url' => NULL,
 112                  'url_match' => '=',
 113                  'include_emptyurl' => NULL,
 114                  'author_IP' => NULL,
 115                  'post_ID' => NULL,
 116                  'comment_ID' => NULL,
 117                  'comment_ID_list' => NULL,
 118                  'rating_toshow' => NULL,
 119                  'rating_turn' => 'above',
 120                  'rating_limit' => 1,
 121                  'keywords' => NULL,
 122                  'phrase' => 'AND',
 123                  'exact' => 0,
 124                  'statuses' => NULL,
 125                  'expiry_statuses' => array( 'active' ), // Show active/expired comments
 126                  'types' => array( 'comment','trackback','pingback' ),
 127                  'orderby' => 'date',
 128                  'order' => !is_null( $this->Blog ) ? $this->Blog->get_setting('comments_orderdir') : 'DESC',
 129                  //'order' => 'DESC',
 130                  'comments' => $this->limit,
 131                  'page' => 1,
 132                  'featured' => NULL,
 133                  'timestamp_min' => NULL, // Do not show comments from posts before this timestamp
 134                  'timestamp_max' => NULL, // Do not show comments from posts after this timestamp
 135                  'threaded_comments' => false, // Mode to display the comment replies
 136                  'user_perm' => NULL,
 137          ) );
 138      }
 139  
 140  
 141      /**
 142       * Reset the query -- EXPERIMENTAL
 143       *
 144       * Useful to requery with a slighlty moidified filterset
 145       */
 146  	function reset()
 147      {
 148          // The SQL Query object:
 149          $this->CommentQuery = new CommentQuery( $this->Cache->dbtablename, $this->Cache->dbprefix, $this->Cache->dbIDname );
 150          $this->CommentQuery->Blog = $this->Blog;
 151          $this->ItemQuery = new ItemQuery( 'T_items__item', 'post_', 'post_ID' );
 152          $this->ItemQuery->blog = empty( $this->Blog ) ? 0 : $this->Blog->ID;
 153  
 154          parent::reset();
 155      }
 156  
 157  
 158      /**
 159       * Set/Activate filterset
 160       *
 161       * This will also set back the GLOBALS !!! needed for regenerate_url().
 162       *
 163       * @param array
 164       * @param boolean
 165       */
 166  	function set_filters( $filters, $memorize = true )
 167      {
 168          if( !empty( $filters ) )
 169          { // Activate the filterset (fallback to default filter when a value is not set):
 170              $this->filters = array_merge( $this->default_filters, $filters );
 171          }
 172  
 173          // Activate preset filters if necessary:
 174          $this->activate_preset_filters();
 175  
 176          // Funky oldstyle params:
 177          $this->limit = $this->filters['comments']; // for compatibility with parent class
 178          $this->page = $this->filters['page'];
 179  
 180          // asimo> memorize is always false for now, because is not fully implemented
 181          if( $memorize )
 182          {    // set back the GLOBALS !!! needed for regenerate_url() :
 183  
 184              /*
 185               * Selected filter preset:
 186               */
 187              memorize_param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], $this->filters['filter_preset'] );  // List of authors to restrict to
 188  
 189              /*
 190               * Restrict to selected authors attribute:
 191               */
 192              memorize_param( $this->param_prefix.'author_IDs', 'string', $this->default_filters['author_IDs'], $this->filters['author_IDs'] );  // List of authors ID to restrict to
 193              memorize_param( $this->param_prefix.'author', 'string', $this->default_filters['author'], $this->filters['author'] );  // List of authors ID to restrict to
 194              memorize_param( $this->param_prefix.'author_email', 'string', $this->default_filters['author_email'], $this->filters['author_email'] );  // List of authors email to restrict to
 195              memorize_param( $this->param_prefix.'author_url', 'string', $this->default_filters['author_url'], $this->filters['author_url'] );  // List of authors url to restrict to
 196              memorize_param( $this->param_prefix.'url_match', 'string', $this->default_filters['url_match'], $this->filters['url_match'] );  // List of authors url to restrict to
 197              memorize_param( $this->param_prefix.'include_emptyurl', 'string', $this->default_filters['include_emptyurl'], $this->filters['include_emptyurl'] );  // List of authors url to restrict to
 198              memorize_param( $this->param_prefix.'author_IP', 'string', $this->default_filters['author_IP'], $this->filters['author_IP'] );  // List of authors ip to restrict to
 199  
 200              /*
 201               * Restrict to selected rating:
 202               */
 203              memorize_param( $this->param_prefix.'rating_toshow', 'array', $this->default_filters['rating_toshow'], $this->filters['rating_toshow'] );  // Rating to restrict to
 204              memorize_param( $this->param_prefix.'rating_turn', 'string', $this->default_filters['rating_turn'], $this->filters['rating_turn'] );  // Rating to restrict to
 205              memorize_param( $this->param_prefix.'rating_limit', 'integer', $this->default_filters['rating_limit'], $this->filters['rating_limit'] );  // Rating to restrict to
 206  
 207              /*
 208               * Restrict by keywords
 209               */
 210              memorize_param( $this->param_prefix.'s', 'string', $this->default_filters['keywords'], $this->filters['keywords'] );             // Search string
 211              memorize_param( $this->param_prefix.'sentence', 'string', $this->default_filters['phrase'], $this->filters['phrase'] ); // Search for sentence or for words
 212              memorize_param( $this->param_prefix.'exact', 'integer', $this->default_filters['exact'], $this->filters['exact'] );     // Require exact match of title or contents
 213  
 214              /*
 215               * Restrict to selected statuses:
 216               */
 217              memorize_param( $this->param_prefix.'show_statuses', 'array', $this->default_filters['statuses'], $this->filters['statuses'] );  // List of statuses to restrict to
 218  
 219              /*
 220               * Restrict to not active/expired comments:
 221               */
 222              memorize_param( $this->param_prefix.'expiry_statuses', 'array', $this->default_filters['expiry_statuses'], $this->filters['expiry_statuses'] );  // List of expiry statuses to restrict to
 223  
 224              /*
 225               * Restrict to selected comment type:
 226               */
 227              memorize_param( $this->param_prefix.'type', 'string', $this->default_filters['types'], $this->filters['types'] );  // List of comment types to restrict to
 228  
 229              /*
 230               * Restrict to current User specific permission:
 231               */
 232              memorize_param( $this->param_prefix.'user_perm', 'string', $this->default_filters['user_perm'], $this->filters['user_perm'] );  // Restrict to comments with permitted action for the current User
 233  
 234              /*
 235               * Restrict to the statuses we want to show:
 236               */
 237              // Note: oftentimes, $show_statuses will have been preset to a more restrictive set of values
 238              //memorize_param( $this->param_prefix.'show_statuses', 'array', $this->default_filters['visibility_array'], $this->filters['visibility_array'] );    // Array of sharings to restrict to
 239  
 240              /*
 241               * OLD STYLE orders:
 242               */
 243              memorize_param( $this->param_prefix.'order', 'string', $this->default_filters['order'], $this->filters['order'] );           // ASC or DESC
 244              // This order style is OK, because sometimes the commentList is not displayed on a table so we cannot say we want to order by a specific column.
 245              memorize_param( $this->param_prefix.'orderby', 'string', $this->default_filters['orderby'], $this->filters['orderby'] );  // list of fields to order by (TODO: change that crap)
 246  
 247              /*
 248               * Paging limits:
 249               */
 250              memorize_param( $this->param_prefix.'comments', 'integer', $this->default_filters['comments'], $this->filters['comments'] );             // # of units to display on the page
 251  
 252              // 'paged'
 253              memorize_param( $this->page_param, 'integer', 1, $this->filters['page'] );      // List page number in paged display
 254          }
 255      }
 256  
 257  
 258      /**
 259       * Init filter params from request params
 260       *
 261       * @param boolean do we want to use saved filters ?
 262       * @return boolean true if we could apply a filterset based on Request params (either explicit or reloaded)
 263       */
 264  	function load_from_Request( $use_filters = true )
 265      {
 266          $this->filters = $this->default_filters;
 267  
 268          if( $use_filters )
 269          {
 270              // Do we want to restore filters or do we want to create a new filterset
 271              $filter_action = param( /*$this->param_prefix.*/'filter', 'string', 'save' );
 272              switch( $filter_action )
 273              {
 274                  case 'restore':
 275                      return $this->restore_filterset();
 276                      /* BREAK */
 277  
 278                  case 'reset':
 279                      // We want to reset the memorized filterset:
 280                      global $Session;
 281                      $Session->delete( $this->filterset_name );
 282  
 283                      // Memorize global variables:
 284                      $this->set_filters( array(), true );
 285  
 286                      // We have applied no filterset:
 287                      return false;
 288                      /* BREAK */
 289              }
 290  
 291              /**
 292               * Filter preset
 293               */
 294              $this->filters['filter_preset'] = param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], true );
 295  
 296              // Activate preset default filters if necessary:
 297              $this->activate_preset_filters();
 298          }
 299  
 300          /*
 301           * Restrict to selected author:
 302           */
 303          $this->filters['author_IDs'] = param( $this->param_prefix.'author_IDs', '/^-?[0-9]+(,[0-9]+)*$/', $this->default_filters['author_IDs'], true );      // List of authors ID to restrict to
 304          $this->filters['author'] = param( $this->param_prefix.'author', '/^-?[0-9]+(,[0-9]+)*$/', $this->default_filters['author'], true );      // List of authors to restrict to
 305          $this->filters['author_email'] = param( $this->param_prefix.'author_email', 'string', $this->default_filters['author_email'], true );
 306          $this->filters['author_url'] = param( $this->param_prefix.'author_url', 'string', $this->default_filters['author_url'], true );
 307          $this->filters['url_match'] = param( $this->param_prefix.'url_match', 'string', $this->default_filters['url_match'], true );
 308          $this->filters['include_emptyurl'] = param( $this->param_prefix.'include_emptyurl', 'string', $this->default_filters['include_emptyurl'], true );
 309          $this->filters['author_IP'] = param( $this->param_prefix.'author_IP', 'string', $this->default_filters['author_IP'], true );
 310  
 311          /*
 312           * Restrict to selected statuses:
 313           */
 314          $this->filters['statuses'] = param( $this->param_prefix.'show_statuses', 'array/string', $this->default_filters['statuses'], true );      // List of statuses to restrict to
 315  
 316          /*
 317           * Restrict to active/expired comments:
 318           */
 319          $this->filters['expiry_statuses'] = param( $this->param_prefix.'expiry_statuses', 'array/string', $this->default_filters['expiry_statuses'], true );      // List of expiry statuses to restrict to
 320  
 321          /*
 322           * Restrict to selected types:
 323           */
 324          $this->filters['types'] = param( $this->param_prefix.'types', 'array/string', $this->default_filters['types'], true );      // List of types to restrict to
 325  
 326          /*
 327           * Restrict to selected user perm:
 328           */
 329          $this->filters['user_perm'] = param( $this->param_prefix.'user_perm', 'string', $this->default_filters['user_perm'], true );      // A specific user perm to restrict to
 330  
 331          /*
 332           * Restrict by keywords
 333           */
 334          $this->filters['keywords'] = param( $this->param_prefix.'s', 'string', $this->default_filters['keywords'], true );         // Search string
 335          $this->filters['phrase'] = param( $this->param_prefix.'sentence', 'string', $this->default_filters['phrase'], true );         // Search for sentence or for words
 336          $this->filters['exact'] = param( $this->param_prefix.'exact', 'integer', $this->default_filters['exact'], true );        // Require exact match of title or contents
 337  
 338          /*
 339           * Restrict to selected rating:
 340           */
 341          $this->filters['rating_toshow'] = param( $this->param_prefix.'rating_toshow', 'array/string', $this->default_filters['rating_toshow'], true );      // Rating to restrict to
 342          $this->filters['rating_turn'] = param( $this->param_prefix.'rating_turn', 'string', $this->default_filters['rating_turn'], true );      // Rating to restrict to
 343          $this->filters['rating_limit'] = param( $this->param_prefix.'rating_limit', 'integer', $this->default_filters['rating_limit'], true );     // Rating to restrict to
 344  
 345          // 'limit'
 346          $this->filters['comments'] = param( $this->param_prefix.'comments', 'integer', $this->default_filters['comments'], true );             // # of units to display on the page
 347          $this->limit = $this->filters['comments']; // for compatibility with parent class
 348          $this->filters['limit'] = $this->limit;
 349  
 350          // 'paged'
 351          $this->filters['page'] = param( $this->page_param, 'integer', 1, true );      // List page number in paged display
 352          $this->page = $this->filters['page'];
 353  
 354          $this->filters['order'] = param( $this->param_prefix.'order', 'string', $this->default_filters['order'], true );           // ASC or DESC
 355          // This order style is OK, because sometimes the commentList is not displayed on a table so we cannot say we want to order by a specific column. It's not a crap.
 356          $this->filters['orderby'] = param( $this->param_prefix.'orderby', 'string', $this->default_filters['orderby'], true );  // list of fields to order by (TODO: change that crap)
 357  
 358          if( $use_filters && $filter_action == 'save' )
 359          {
 360              $this->save_filterset();
 361          }
 362  
 363          return ! param_errors_detected();
 364      }
 365  
 366  
 367      /**
 368       *
 369       *
 370       * @todo count?
 371       */
 372  	function query_init()
 373      {
 374          global $DB;
 375  
 376          if( empty( $this->filters ) )
 377          {    // Filters have not been set before, we'll use the default filterset:
 378              // If there is a preset filter, we need to activate its specific defaults:
 379              $this->filters['filter_preset'] = param( $this->param_prefix.'filter_preset', 'string', $this->default_filters['filter_preset'], true );
 380              $this->activate_preset_filters();
 381  
 382              // Use the default filters:
 383              $this->set_filters( $this->default_filters );
 384          }
 385  
 386          // GENERATE THE QUERY:
 387  
 388          /*
 389           * Resrict to selected blog
 390           */
 391          // If we dont have specific comment or post ids, we have to restric to blog
 392          if( !is_null( $this->Blog ) &&
 393              ( $this->filters['post_ID'] == NULL || ( ! empty($this->filters['post_ID']) && substr( $this->filters['post_ID'], 0, 1 ) == '-') ) &&
 394              ( $this->filters['comment_ID'] == NULL || ( ! empty($this->filters['comment_ID']) && substr( $this->filters['comment_ID'], 0, 1 ) == '-') ) &&
 395              ( $this->filters['comment_ID_list'] == NULL || ( ! empty($this->filters['comment_ID_list']) && substr( $this->filters['comment_ID_list'], 0, 1 ) == '-') ) )
 396          { // restriction for blog
 397              $this->ItemQuery->where_chapter( $this->Blog->ID );
 398          }
 399  
 400          /*
 401           * filtering stuff:
 402           */
 403          $this->CommentQuery->where_author( $this->filters['author_IDs'] );
 404          $this->CommentQuery->where_author_email( $this->filters['author_email'] );
 405          $this->CommentQuery->where_author_url( $this->filters['author_url'], $this->filters['url_match'], $this->filters['include_emptyurl'] );
 406          $this->CommentQuery->where_author_IP( $this->filters['author_IP'] );
 407          $this->ItemQuery->where_ID( $this->filters['post_ID'] );
 408          $this->CommentQuery->where_ID( $this->filters['comment_ID'], $this->filters['author'] );
 409          $this->CommentQuery->where_ID_list( $this->filters['comment_ID_list'] );
 410          $this->CommentQuery->where_rating( $this->filters['rating_toshow'], $this->filters['rating_turn'], $this->filters['rating_limit'] );
 411          $this->CommentQuery->where_keywords( $this->filters['keywords'], $this->filters['phrase'], $this->filters['exact'] );
 412          $this->CommentQuery->where_statuses( $this->filters['statuses'] );
 413          $this->CommentQuery->where_types( $this->filters['types'] );
 414          $this->ItemQuery->where_datestart( '', '', '', '', $this->filters['timestamp_min'], $this->filters['timestamp_max'] );
 415  
 416          if( !is_null( $this->Blog ) && isset( $this->filters['user_perm'] ) )
 417          { // If Blog and required user permission is set, add the corresponding restriction
 418              $this->CommentQuery->user_perm_restrict( $this->filters['user_perm'], $this->Blog->ID );
 419          }
 420  
 421  
 422          /*
 423           * ORDER BY stuff:
 424           */
 425          $order_by = gen_order_clause( $this->filters['orderby'], $this->filters['order'], $this->Cache->dbprefix, $this->Cache->dbIDname );
 426  
 427          if( $this->filters['threaded_comments'] )
 428          {    // In mode "Threaded comments" we should get all replies in the begining of the list
 429              $order_by = $this->Cache->dbprefix.'in_reply_to_cmt_ID DESC, '.$order_by;
 430          }
 431  
 432          $this->CommentQuery->order_by( $order_by );
 433  
 434          // GET Item IDs, this way we don't have to JOIN two times the items and the categories table into the comment query
 435          if( isset( $this->filters['post_statuses'] ) )
 436          { // Set post statuses by filters
 437              $post_show_statuses = $this->filters['post_statuses'];
 438          }
 439          elseif( isset( $this->filters['post_ID'] ) && is_admin_page() )
 440          { // Allow all kind of post status ( This statuses will be filtered later by user perms )
 441              $post_show_statuses = get_visibility_statuses( 'keys' );
 442          }
 443          else
 444          { // Allow only inskin statuses for posts
 445              $post_show_statuses = get_inskin_statuses();
 446          }
 447          // Restrict post filters to available statuses. When blog = 0 we will check visibility statuses for each blog separately ( on the same query ).
 448          $this->ItemQuery->where_visibility( $post_show_statuses );
 449          $sql_item_IDs = 'SELECT DISTINCT post_ID'
 450                          .$this->ItemQuery->get_from()
 451                          .$this->ItemQuery->get_where();
 452          $item_IDs = $DB->get_col( $sql_item_IDs, 0, 'Get CommentQuery Item IDs' );
 453          if( empty( $item_IDs ) )
 454          { // There is no item which belongs to the given blog and user may view it, so there are no comments either
 455              parent::count_total_rows( 0 );
 456              $this->CommentQuery->WHERE_and( 'FALSE' );
 457              return;
 458          }
 459          $this->CommentQuery->where_post_ID( implode( ',', $item_IDs ) );
 460  
 461          /*
 462           * Restrict to active comments by default, show expired comments only if it was requested
 463           * Note: This condition makes the CommentQuery a lot slower!
 464           */
 465          $this->CommentQuery->expiry_restrict( $this->filters['expiry_statuses'] );
 466  
 467          /*
 468           * GET TOTAL ROW COUNT:
 469           */
 470          $sql_count = '
 471                  SELECT COUNT( '.$this->Cache->dbIDname.') '
 472                      .$this->CommentQuery->get_from()
 473                      .$this->CommentQuery->get_where();
 474  
 475          parent::count_total_rows( $sql_count );
 476  
 477          /*
 478           * Page set up:
 479           */
 480          if( $this->page > 1 )
 481          { // We have requested a specific page number
 482              if( $this->limit > 0 )
 483              {
 484                  $pgstrt = '';
 485                  $pgstrt = (intval($this->page) -1) * $this->limit. ', ';
 486                  $this->CommentQuery->LIMIT( $pgstrt.$this->limit );
 487              }
 488          }
 489          else
 490          {
 491              $this->CommentQuery->LIMIT( $this->limit );
 492          }
 493      }
 494  
 495  
 496      /**
 497       * Run Query: GET DATA ROWS *** HEAVY ***
 498       */
 499  	function query()
 500      {
 501          global $DB;
 502  
 503          if( !is_null( $this->rows ) )
 504          { // Query has already executed:
 505              return;
 506          }
 507  
 508          // INIT THE QUERY:
 509          $this->query_init();
 510  
 511          // Results style orders:
 512          // $this->CommentQuery->ORDER_BY_prepend( $this->get_order_field_list() );
 513  
 514  
 515          // We are going to proceed in two steps (we simulate a subquery)
 516          // 1) we get the IDs we need
 517          // 2) we get all the other fields matching these IDs
 518          // This is more efficient than manipulating all fields at once.
 519  
 520          // *** STEP 1 ***
 521          // walter> Accordding to the standart, to DISTINCT queries, all columns used
 522          // in ORDER BY must appear in the query. This make que query work with PostgreSQL and
 523          // other databases.
 524          // fp> That can dramatically fatten the returned data. You must handle this in the postgres class (check that order fields are in select)
 525          // asimo> Note: DISTINCT was removed from the query because we should use DISTINCT only in those cases when the same field value may occur more then one times ( This is not the case )
 526          $step1_sql = 'SELECT '.$this->Cache->dbIDname // .', '.implode( ', ', $order_cols_to_select )
 527                                      .$this->CommentQuery->get_from()
 528                                      .$this->CommentQuery->get_where()
 529                                      .$this->CommentQuery->get_group_by()
 530                                      .$this->CommentQuery->get_order_by()
 531                                      .$this->CommentQuery->get_limit();
 532  
 533          // Get list of the IDs we need:
 534          $ID_list = implode( ',', $DB->get_col( $step1_sql, 0, 'CommentList2::Query() Step 1: Get ID list' ) );
 535  
 536          // *** STEP 2 ***
 537          $this->sql = 'SELECT *
 538                            FROM '.$this->Cache->dbtablename;
 539          if( !empty($ID_list) )
 540          {
 541              $this->sql .= ' WHERE '.$this->Cache->dbIDname.' IN ('.$ID_list.') '
 542                                          .$this->CommentQuery->get_order_by();
 543          }
 544          else
 545          {
 546              $this->sql .= ' WHERE 0';
 547          }
 548  
 549          // ATTENTION: we skip the parent on purpose here!! fp> refactor
 550          DataObjectList2::query( false, false, false, 'CommentList2::Query() Step 2' );
 551      }
 552  
 553  
 554      /**
 555       * Generate a title for the current list, depending on its filtering params
 556       *
 557       * @return array List of titles to display, which are escaped for HTML display
 558       */
 559  	function get_filter_titles( $ignore = array(), $params = array() )
 560      {
 561          $title_array = array();
 562  
 563          if( empty ($this->filters) )
 564          { // Filters have no been set before, we'll use the default filterset
 565              $this->set_filters( $this->default_filters );
 566          }
 567  
 568          if( isset( $this->filters['statuses'] ) )
 569          {
 570              $visibility_statuses = get_visibility_statuses( '', array( 'redirected' ) );
 571  
 572              $visibility_array = array();
 573              foreach( $this->filters['statuses'] as $status )
 574              {
 575                  $visibility_array[] = $visibility_statuses[ $status ];
 576              }
 577              $title_array['statuses'] = T_('Visibility').': '.implode( ', ', $visibility_array );
 578          }
 579  
 580          if( !empty($this->filters['keywords']) )
 581          {
 582              $title_array['keywords'] = T_('Keywords').': '.$this->filters['keywords'];
 583          }
 584  
 585          return $title_array;
 586      }
 587  
 588  
 589      /**
 590       * If the list is sorted by category...
 591        *
 592        * This is basically just a stub for backward compatibility
 593       */
 594      function & get_Comment()
 595      {
 596          $Comment = & parent::get_next();
 597  
 598          if( empty($Comment) )
 599          {
 600              $r = false;
 601              return $r;
 602          }
 603  
 604          //pre_dump( $Comment );
 605  
 606          return $Comment;
 607      }
 608  
 609  
 610      /**
 611       * Template function: display message if list is empty
 612       *
 613       * @return boolean true if empty
 614       */
 615  	function display_if_empty( $params = array() )
 616      {
 617          // Make sure we are not missing any param:
 618          $params = array_merge( array(
 619                  'msg_empty'   => T_('No comment yet...'),
 620              ), $params );
 621  
 622          return parent::display_if_empty( $params );
 623      }
 624  
 625  
 626      /**
 627       * Template tag
 628       *
 629       * Display page links (when paginated comments are enabled)
 630       */
 631  	function page_links( $params = array() )
 632      {
 633          $default_params = array(
 634                  'block_start' => '<p class="center">',
 635                  'block_end' => '</p>',
 636                  'block_single' => '',
 637                  'links_format' => '#',
 638                  'page_url' => '', // All generated links will refer to the current page
 639                  'prev_text' => '&lt;&lt;',
 640                  'next_text' => '&gt;&gt;',
 641                  'no_prev_text' => '',
 642                  'no_next_text' => '',
 643                  'list_prev_text' => '...',
 644                  'list_next_text' => '...',
 645                  'list_span' => 11,
 646                  'scroll_list_range' => 5,
 647              );
 648  
 649          // Use defaults + overrides:
 650          $params = array_merge( $default_params, $params );
 651  
 652          if( $this->total_pages <= 1 || $this->page > $this->total_pages )
 653          {    // Single page:
 654              echo $params['block_single'];
 655              return;
 656          }
 657  
 658          if( $params['links_format'] == '#' )
 659          {
 660              $params['links_format'] = '$prev$ $first$ $list_prev$ $list$ $list_next$ $last$ $next$';
 661          }
 662  
 663          if( !is_null( $this->Blog ) && $this->Blog->get_setting( 'paged_nofollowto' ) )
 664          {    // We prefer robots not to follow to pages:
 665              $this->nofollow_pagenav = true;
 666          }
 667  
 668          echo $params['block_start'];
 669          echo $this->replace_vars( $params['links_format'], $params );
 670          echo $params['block_end'];
 671      }
 672  
 673  
 674      /**
 675       * Returns values needed to make sort links for a given column
 676       * This is needed because the order is not handled by the result class.
 677       * Reason: Sometimes the comment list needs to be ordered without having a display table, and columns. The result class order is based on columns.
 678       *
 679       * Returns an array containing the following values:
 680       *  - current_order : 'ASC', 'DESC' or ''
 681       *  - order_asc : url needed to order in ascending order
 682       *  - order_desc
 683       *  - order_toggle : url needed to toggle sort order
 684       *
 685       * @param integer column to sort
 686       * @return array
 687       */
 688  	function get_col_sort_values( $col_idx )
 689      {
 690          $col_order_fields = $this->cols[$col_idx]['order'];
 691  
 692          // Current order:
 693          if( $this->filters['orderby'] == $col_order_fields || $this->param_prefix.$this->filters['orderby'] == $col_order_fields  )
 694          {
 695              $col_sort_values['current_order'] = $this->filters['order'];
 696          }
 697          else
 698          {
 699              $col_sort_values['current_order'] = '';
 700          }
 701  
 702  
 703          // Generate sort values to use for sorting on the current column:
 704          $col_sort_values['order_asc'] = regenerate_url( array($this->param_prefix.'order',$this->param_prefix.'orderby'),
 705                                                                              $this->param_prefix.'order=ASC&amp;'.$this->param_prefix.'orderby='.$col_order_fields );
 706          $col_sort_values['order_desc'] = regenerate_url(  array($this->param_prefix.'order',$this->param_prefix.'orderby'),
 707                                                                              $this->param_prefix.'order=DESC&amp;'.$this->param_prefix.'orderby='.$col_order_fields );
 708  
 709          if( !$col_sort_values['current_order'] && isset( $this->cols[$col_idx]['default_dir'] ) )
 710          {    // There is no current order on this column and a default order direction is set for it
 711              // So set a default order direction for it
 712  
 713              if( $this->cols[$col_idx]['default_dir'] == 'A' )
 714              {    // The default order direction is A, so set its toogle  order to the order_asc
 715                  $col_sort_values['order_toggle'] = $col_sort_values['order_asc'];
 716              }
 717              else
 718              { // The default order direction is A, so set its toogle order to the order_desc
 719                  $col_sort_values['order_toggle'] = $col_sort_values['order_desc'];
 720              }
 721          }
 722          elseif( $col_sort_values['current_order'] == 'ASC' )
 723          {    // There is an ASC current order on this column, so set its toogle order to the order_desc
 724              $col_sort_values['order_toggle'] = $col_sort_values['order_desc'];
 725          }
 726          else
 727          { // There is a DESC or NO current order on this column,  so set its toogle order to the order_asc
 728              $col_sort_values['order_toggle'] = $col_sort_values['order_asc'];
 729          }
 730  
 731          // pre_dump( $col_sort_values );
 732  
 733          return $col_sort_values;
 734      }
 735  
 736  
 737      /**
 738       * Checks if currently selected filter contains comments with trash status
 739       *
 740       * @param boolean set true to check if the filter contains only recycled comments, set false to check if the filter contains the recycled comments
 741       * @return boolean
 742       */
 743  	function is_trashfilter( $only_trash = true )
 744      {
 745          if( ! $only_trash )
 746          { // Check if statuses filter contains the 'trash' value
 747              return in_array( 'trash', $this->filters['statuses'] );
 748          }
 749          if( count( $this->filters['statuses'] ) == 1 )
 750          { // Check if statuses filter contains only the 'trash' value
 751              return $this->filters['statuses'][0] == 'trash';
 752          }
 753          return false;
 754      }
 755  }
 756  
 757  ?>

title

Description

title

Description

title

Description

title

title

Body