b2evolution

Multilingual multiuser multiblog engine

b2evolution Technical Documentation (0.9.x) [ class tree: evocore ] [ index: evocore ] [ all elements ]

Source for file _class_commentlist.php

Documentation is available at _class_commentlist.php

  1. <?php
  2. /**
  3.  * This file implements comment lists
  4.  *
  5.  * b2evolution - {@link http://b2evolution.net/}
  6.  * Released under GNU GPL License - {@link http://b2evolution.net/about/license.html}
  7.  * @copyright (c)2003-2005 by Francois PLANQUE - {@link http://fplanque.net/}
  8.  *
  9.  * @package evocore
  10.  */
  11. if!defined('DB_USER') ) die'Please, do not access this page directly.' );
  12.  
  13. /**
  14.  * Includes:
  15.  */
  16. require_once dirname(__FILE__).'/_class_dataobjectlist.php';
  17.  
  18. /**
  19.  * Comment List Class
  20.  *
  21.  * @package evocore
  22.  */
  23. class CommentList extends DataObjectList
  24. {
  25.     var $blog;
  26.     
  27.     /** 
  28.      * {@internal CommentList::CommentList(-)}}
  29.      *
  30.      * Constructor
  31.      */
  32.     function CommentList
  33.         $blog 1
  34.         $comment_types "'comment'",
  35.         $show_statuses array(),                            // Not used yet                    
  36.         $p '',                                                            // Restrict to specific post
  37.         $author '',                                                    // Not used yet
  38.         $order 'DESC',                                            // ASC or DESC
  39.         $orderby '',                                                // list of fields to order by
  40.         $posts '',                                                     // # of comments to display on the page
  41.         $paged '',                                                    // Not used yet
  42.         $poststart '',                                            // Not used yet
  43.         $postend '',                                                // Not used yet
  44.         $s '',                                                            // Not used yet
  45.         $sentence '',                                                // Not used yet
  46.         $exact '',                                                    // Not used yet
  47.         $default_posts_per_page ''
  48.         $init_what_to_show ''  )
  49.     {
  50.         global $DB;
  51.         global $tablecomments$tableposts$tablecategories$tableblogs$tablepostcats;
  52.         global $cache_categories;
  53.         global $cat_array// communication with recursive callback funcs
  54.         global $pagenow;        // Bleh !
  55.         
  56.         // Call parent constructor:
  57.         parent::DataObjectList$tablecomments'comment_''comment_ID' );
  58.  
  59.         $this->blog = $blog;
  60.         
  61.         if!empty($posts) )
  62.             $this->posts_per_page $posts;
  63.         else $this->posts_per_page $default_posts_per_page;
  64.  
  65.         $this->request "SELECT DISTINCT $tablecomments.*
  66.                                             FROM (($tablecomments INNER JOIN $tableposts ON comment_post_ID = ID) ";
  67.                 
  68.         if!empty$p ) )
  69.         {    // Restrict to comments on selected post
  70.             $this->request .= ") WHERE comment_post_ID = $p AND ";
  71.         }
  72.         elseif$blog )
  73.         {    // Restrict to viewable posts/cats on current blog
  74.             $this->request .= "INNER JOIN $tablepostcats ON ID = postcat_post_ID) INNER JOIN $tablecategories othercats ON postcat_cat_ID = othercats.cat_ID WHERE othercats.cat_blog_ID = $blog AND ";
  75.         }
  76.         else
  77.         {    // This is blog 1, we don't care, we can include all comments:
  78.             $this->request .= ') WHERE ';
  79.         }
  80.         
  81.         $this->request .= "comment_type IN ($comment_types";
  82.  
  83.         /*
  84.          * ----------------------------------------------------
  85.          *  Restrict to the statuses we want to show:
  86.          * ----------------------------------------------------
  87.          */
  88.         $this->request .= ' AND '.statuses_where_clause$show_statuses );
  89.  
  90.         
  91.         // order by stuff
  92.         if( (!empty($order)) && ((strtoupper($order!= 'ASC'&& (strtoupper($order!= 'DESC'))) 
  93.         {
  94.             $order='DESC';
  95.         }
  96.     
  97.         if(empty($orderby))
  98.         {
  99.             $orderby='comment_date '.$order;
  100.         }
  101.         else
  102.         {
  103.             $orderby_array explode(' ',$orderby);
  104.             $orderby $orderby_array[0].' '.$order;
  105.             if (count($orderby_array)>1
  106.             {
  107.                 for($i 1$i (count($orderby_array))$i++
  108.                 {
  109.                     $orderby .= ', comment_'.$orderby_array[$i].' '.$order;
  110.                 }
  111.             }
  112.         }
  113.  
  114.  
  115.         $this->request .= "ORDER BY $orderby";
  116.         if$this->posts_per_page $this->request .= " LIMIT $this->posts_per_page";
  117.  
  118.         // echo $this->request;
  119.             
  120.         $this->result $DB->get_results$this->requestARRAY_A );
  121.     
  122.         if$this->result_num_rows $DB->num_rows )
  123.         {
  124.             foreach$this->result as $row )
  125.             {
  126.                 $this->Obj[new Comment$row );
  127.             }
  128.         }
  129.     }
  130.  
  131.     
  132.     /**
  133.      * Template function: display message if list is empty
  134.      *
  135.      * {@internal Comment::display_if_empty(-) }}
  136.      *
  137.      * @param string String to display if list is empty
  138.    * @return true if empty
  139.      */
  140.     function display_if_empty$message '' )
  141.     {
  142.         ifempty($message) )
  143.         {    // Default message:
  144.             $message T_('No comment yet...');
  145.         }
  146.  
  147.         return parent::display_if_empty$message );
  148.     }
  149.  
  150. }
  151.  
  152. ?>

Documentation generated on Tue, 20 May 2008 01:52:44 +0200 by phpDocumentor 1.4.2