Source for file _comment.funcs.php
Documentation is available at _comment.funcs.php
* This file implements Comment handling functions.
* This file is part of the Quam Plures project - {@link http://quamplures.net/}.
* See also {@link https://launchpad.net/quam-plures}.
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}.
* Parts of this file are copyright (c)2004-2005 by Daniel HAHLER - {@link http://thequod.de/contact}.
* @license http://quamplures.net/license.html GNU General Public License (GPL)
* {@internal Open Source relicensing agreement:
* Daniel HAHLER grants Francois PLANQUE the right to license
* Daniel HAHLER's contributions to this file and the b2evolution project
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
* @todo implement CommentCache based on LinkCache
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
* @author blueyed: Daniel HAHLER.
* @author fplanque: Francois PLANQUE.
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
* Generic comments/trackbacks counting
* @todo check this in a multiblog page...
* @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()}).
* @param string what to count
global $DB, $debug, $postdata, $cache_ctp_number, $preview;
{ // we are in preview mode, no comments yet!
* Make sure cache is loaded for current display list:
if( !isset ($cache_ctp_number) )
global $postIDlist, $postIDarray;
// if( $debug ) echo "LOADING generic_ctp_number CACHE for posts: $postIDlist<br />";
if( ! empty( $postIDlist ) ) // This can happen when displaying a featured post of something that's not in the MainList
foreach( $postIDarray as $tmp_post_id)
{ // Initializes each post to nocount!
$cache_ctp_number[$tmp_post_id] = array(
'comments' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ),
'trackbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ),
'feedbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 )
$query = 'SELECT comment_post_ID, comment_type, comment_status, COUNT(*) AS type_count
WHERE comment_post_ID IN ('. $postIDlist. ')
GROUP BY comment_post_ID, comment_type, comment_status';
foreach( $DB->get_results( $query ) as $row )
// detail by status, tyep and post:
$cache_ctp_number[$row->comment_post_ID][$row->comment_type. 's'][$row->comment_status] = $row->type_count;
// Total for type on post:
$cache_ctp_number[$row->comment_post_ID][$row->comment_type. 's']['total'] += $row->type_count;
// Total for status on post:
$cache_ctp_number[$row->comment_post_ID]['feedbacks'][$row->comment_status] += $row->type_count;
$cache_ctp_number[$row->comment_post_ID]['feedbacks']['total'] += $row->type_count;
if( !isset ($cache_ctp_number[$post_id]) )
{ // this should be extremely rare...
// Initializes post to nocount!
$cache_ctp_number[intval($post_id)] = array(
'comments' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ),
'trackbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ),
'feedbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 )
$query = 'SELECT comment_post_ID, comment_type, comment_status, COUNT(*) AS type_count
WHERE comment_post_ID = '. intval($post_id). '
GROUP BY comment_post_ID, comment_type, comment_status';
foreach( $DB->get_results( $query ) as $row )
// detail by status, tyep and post:
$cache_ctp_number[$row->comment_post_ID][$row->comment_type. 's'][$row->comment_status] = $row->type_count;
// Total for type on post:
$cache_ctp_number[$row->comment_post_ID][$row->comment_type. 's']['total'] += $row->type_count;
// Total for status on post:
$cache_ctp_number[$row->comment_post_ID]['feedbacks'][$row->comment_status] += $row->type_count;
$cache_ctp_number[$row->comment_post_ID]['feedbacks']['total'] += $row->type_count;
if( ($mode != 'comments') && ($mode != 'trackbacks') )
if( ($status != 'published') && ($status != 'draft') && ($status != 'deprecated') )
return $cache_ctp_number[$post_id][$mode][$status];
* Get a Comment by ID. Exits if the requested comment does not exist!
global $DB, $cache_Comments;
if( empty($cache_Comments[$comment_ID]) )
{ // Load this entry into cache:
WHERE comment_ID = $comment_ID";
if( $row = $DB->get_row( $query, ARRAY_A ) )
$cache_Comments[$comment_ID] = new Comment( $row ); // COPY !
if( empty( $cache_Comments[ $comment_ID ] ) ) die('Requested comment does not exist!');
return $cache_Comments[ $comment_ID ];
* @movedTo _obsolete092.php
/***** Comment tags *****/
* @deprecated deprecated by {@link Item::feedback_link()}
* @todo EdB: this is used by qp_inc/items/views/_item_list_full.view.php in v0.0.0 (EdB)
function comments_number( $zero= '#', $one= '#', $more= '#', $post_ID = NULL )
if( $zero == '#' ) $zero = T_('Leave a comment');
if( $one == '#' ) $one = T_('1 comment');
if( $more == '#' ) $more = T_('%d comments');
// original hack by dodo@regretless.com
|