phpDocumentor pond
[ class tree: pond ] [ index: pond ] [ all elements ]

Source for file _comment.funcs.php

Documentation is available at _comment.funcs.php

  1. <?php
  2. /**
  3.  * This file implements Comment handling functions.
  4.   *
  5.  * This file is part of the Quam Plures project - {@link http://quamplures.net/}.
  6.  * See also {@link https://launchpad.net/quam-plures}.
  7.  *
  8.  * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
  9.  * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
  10.  *  Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
  11.  *
  12.  * @license http://quamplures.net/license.html GNU General Public License (GPL)
  13.  *
  14.  *  {@internal Open Source relicensing agreement:
  15.  *  Daniel HAHLER grants Francois PLANQUE the right to license
  16.  *  Daniel HAHLER's contributions to this file and the b2evolution project
  17.  *  under any OSI approved OSS license (http://www.opensource.org/licenses/).
  18.  *  }}}
  19.  *
  20.  * @todo implement CommentCache based on LinkCache
  21.  *
  22.  *  {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  23.  * @author cafelog (team)
  24.  * @author blueyed: Daniel HAHLER.
  25.  * @author fplanque: Francois PLANQUE.
  26.  *
  27.  * @package pond
  28.  */
  29. if!defined('QP_MAIN_INIT') ) die'Please, do not access this page directly.' );
  30.  
  31. load_class('comments/model/_comment.class.php');
  32.  
  33. /**
  34.  * Generic comments/trackbacks counting
  35.  *
  36.  * @todo check this in a multiblog page...
  37.  * @todo This should support visibility: at least in the default front office (_feedback.php), there should only the number of visible comments/trackbacks get used ({@link Item::feedback_link()}).
  38.  *
  39.  * @param integer 
  40.  * @param string what to count
  41.  */
  42. function generic_ctp_number$post_id$mode 'comments'$status 'published' )
  43. {
  44.     global $DB$debug$postdata$cache_ctp_number$preview;
  45.  
  46.     if$preview )
  47.     // we are in preview mode, no comments yet!
  48.         return 0;
  49.     }
  50.  
  51.     /*
  52.      * Make sure cache is loaded for current display list:
  53.      */
  54.     if!isset($cache_ctp_number) )
  55.     {
  56.         global $postIDlist$postIDarray;
  57.  
  58.         // if( $debug ) echo "LOADING generic_ctp_number CACHE for posts: $postIDlist<br />";
  59.  
  60.         ifempty$postIDlist ) )    // This can happen when displaying a featured post of something that's not in the MainList
  61.         {
  62.             foreach$postIDarray as $tmp_post_id)
  63.             {    // Initializes each post to nocount!
  64.                 $cache_ctp_number[$tmp_post_idarray(
  65.                         'comments' => array'published' => 0'draft' => 0'deprecated' => 0'total' => ),
  66.                         'trackbacks' => array'published' => 0'draft' => 0'deprecated' => 0'total' => ),
  67.                         'feedbacks' => array'published' => 0'draft' => 0'deprecated' => 0'total' => )
  68.                     );
  69.             }
  70.  
  71.             $query 'SELECT comment_post_ID, comment_type, comment_status, COUNT(*) AS type_count
  72.                                  FROM T_comments
  73.                                  WHERE comment_post_ID IN ('.$postIDlist.')
  74.                                  GROUP BY comment_post_ID, comment_type, comment_status';
  75.  
  76.             foreach$DB->get_results$query as $row )
  77.             {
  78.                 // detail by status, tyep and post:
  79.                 $cache_ctp_number[$row->comment_post_ID][$row->comment_type.'s'][$row->comment_status$row->type_count;
  80.  
  81.                 // Total for type on post:
  82.                 $cache_ctp_number[$row->comment_post_ID][$row->comment_type.'s']['total'+= $row->type_count;
  83.  
  84.                 // Total for status on post:
  85.                 $cache_ctp_number[$row->comment_post_ID]['feedbacks'][$row->comment_status+= $row->type_count;
  86.  
  87.                 // Total for post:
  88.                 $cache_ctp_number[$row->comment_post_ID]['feedbacks']['total'+= $row->type_count;
  89.             }
  90.         }
  91.     }
  92.     /*    else
  93.     {
  94.         echo "cache set";
  95.     }*/
  96.  
  97.  
  98.     if!isset($cache_ctp_number[$post_id]) )
  99.     // this should be extremely rare...
  100.         // Initializes post to nocount!
  101.         $cache_ctp_number[intval($post_id)array(
  102.                 'comments' => array'published' => 0'draft' => 0'deprecated' => 0'total' => ),
  103.                 'trackbacks' => array'published' => 0'draft' => 0'deprecated' => 0'total' => ),
  104.                 'feedbacks' => array'published' => 0'draft' => 0'deprecated' => 0'total' => )
  105.             );
  106.  
  107.         $query 'SELECT comment_post_ID, comment_type, comment_status, COUNT(*) AS type_count
  108.                               FROM T_comments
  109.                              WHERE comment_post_ID = '.intval($post_id).'
  110.                              GROUP BY comment_post_ID, comment_type, comment_status';
  111.  
  112.         foreach$DB->get_results$query as $row )
  113.         {
  114.             // detail by status, tyep and post:
  115.             $cache_ctp_number[$row->comment_post_ID][$row->comment_type.'s'][$row->comment_status$row->type_count;
  116.  
  117.             // Total for type on post:
  118.             $cache_ctp_number[$row->comment_post_ID][$row->comment_type.'s']['total'+= $row->type_count;
  119.  
  120.             // Total for status on post:
  121.             $cache_ctp_number[$row->comment_post_ID]['feedbacks'][$row->comment_status+= $row->type_count;
  122.  
  123.             // Total for post:
  124.             $cache_ctp_number[$row->comment_post_ID]['feedbacks']['total'+= $row->type_count;
  125.         }
  126.     }
  127.  
  128.     if( ($mode != 'comments'&& ($mode != 'trackbacks') )
  129.     {
  130.         $mode 'feedbacks';
  131.     }
  132.  
  133.     if( ($status != 'published'&& ($status != 'draft'&& ($status != 'deprecated') )
  134.     {
  135.         $status 'total';
  136.     }
  137.  
  138.     return $cache_ctp_number[$post_id][$mode][$status];
  139. }
  140.  
  141.  
  142. /**
  143.  * Get a Comment by ID. Exits if the requested comment does not exist!
  144.  *
  145.  * @param integer 
  146.  * @return Comment 
  147.  */
  148. function Comment_get_by_ID$comment_ID )
  149. {
  150.     global $DB$cache_Comments;
  151.  
  152.     ifempty($cache_Comments[$comment_ID]) )
  153.     // Load this entry into cache:
  154.         $query "SELECT *
  155.                             FROM T_comments
  156.                             WHERE comment_ID = $comment_ID";
  157.         if$row $DB->get_row$queryARRAY_A ) )
  158.         {
  159.             $cache_Comments[$comment_IDnew Comment$row )// COPY !
  160.         }
  161.     }
  162.  
  163.     ifempty$cache_Comments$comment_ID ) ) die('Requested comment does not exist!');
  164.  
  165.     return $cache_Comments$comment_ID ];
  166. }
  167.  
  168.  
  169. /*
  170.  * last_comments_title(-)
  171.  *
  172.  * @movedTo _obsolete092.php
  173.  */
  174.  
  175.  
  176. /***** Comment tags *****/
  177.  
  178. /**
  179.  * comments_number(-)
  180.  *
  181.  * @deprecated deprecated by {@link Item::feedback_link()}
  182.  * @todo EdB: this is used by qp_inc/items/views/_item_list_full.view.php in v0.0.0 (EdB)
  183.  */
  184. function comments_number$zero='#'$one='#'$more='#'$post_ID NULL )
  185. {
  186.     if$zero == '#' $zero T_('Leave a comment');
  187.     if$one == '#' $one T_('1 comment');
  188.     if$more == '#' $more T_('%d comments');
  189.  
  190.     // original hack by dodo@regretless.com
  191.     ifempty$post_ID ) )
  192.     {
  193.         global $id;
  194.         $post_ID $id;
  195.     }
  196.     $number generic_ctp_number$post_ID'comments' );
  197.     if ($number == 0)
  198.     {
  199.         $blah $zero;
  200.     }
  201.     elseif ($number == 1)
  202.     {
  203.         $blah $one;
  204.     }
  205.     elseif ($number  1)
  206.     {
  207.         $n $number;
  208.         $more str_replace('%d'$n$more);
  209.         $blah $more;
  210.     }
  211.     echo $blah;
  212. }
  213.  
  214.  
  215. ?>