| [ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements Comment handling functions. 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-2007 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 * @todo implement CommentCache based on LinkCache 22 * 23 * {@internal Below is a list of authors who have contributed to design/coding of this file: }} 24 * @author cafelog (team) 25 * @author blueyed: Daniel HAHLER. 26 * @author fplanque: Francois PLANQUE. 27 * 28 * @version $Id: _comment.funcs.php,v 1.1 2007/06/25 10:59:41 fplanque Exp $ 29 */ 30 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 31 32 load_class('comments/model/_comment.class.php'); 33 34 /** 35 * Generic comments/trackbacks/pingbacks counting 36 * 37 * @todo check this in a multiblog page... 38 * @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()}). 39 * 40 * @param integer 41 * @param string what to count 42 */ 43 function generic_ctp_number( $post_id, $mode = 'comments', $status = 'published' ) 44 { 45 global $DB, $debug, $postdata, $cache_ctp_number, $preview; 46 47 if( $preview ) 48 { // we are in preview mode, no comments yet! 49 return 0; 50 } 51 52 /* 53 * Make sure cache is loaded for current display list: 54 */ 55 if( !isset($cache_ctp_number) ) 56 { 57 global $postIDlist, $postIDarray; 58 59 // if( $debug ) echo "LOADING generic_ctp_number CACHE for posts: $postIDlist<br />"; 60 61 foreach( $postIDarray as $tmp_post_id) 62 { // Initializes each post to nocount! 63 $cache_ctp_number[$tmp_post_id] = array( 64 'comments' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ), 65 'trackbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ), 66 'pingbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ), 67 'feedbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ) 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 /* else 92 { 93 echo "cache set"; 94 }*/ 95 96 97 if( !isset($cache_ctp_number[$post_id]) ) 98 { // this should be extremely rare... 99 // echo "CACHE not set for $post_id"; 100 101 // Initializes post to nocount! 102 $cache_ctp_number[intval($post_id)] = array( 103 'comments' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ), 104 'trackbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ), 105 'pingbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ), 106 'feedbacks' => array( 'published' => 0, 'draft' => 0, 'deprecated' => 0, 'total' => 0 ) 107 ); 108 109 $query = 'SELECT comment_post_ID, comment_type, comment_status, COUNT(*) AS type_count 110 FROM T_comments 111 WHERE comment_post_ID = '.intval($post_id).' 112 GROUP BY comment_post_ID, comment_type, comment_status'; 113 114 foreach( $DB->get_results( $query ) as $row ) 115 { 116 // detail by status, tyep and post: 117 $cache_ctp_number[$row->comment_post_ID][$row->comment_type.'s'][$row->comment_status] = $row->type_count; 118 119 // Total for type on post: 120 $cache_ctp_number[$row->comment_post_ID][$row->comment_type.'s']['total'] += $row->type_count; 121 122 // Total for status on post: 123 $cache_ctp_number[$row->comment_post_ID]['feedbacks'][$row->comment_status] += $row->type_count; 124 125 // Total for post: 126 $cache_ctp_number[$row->comment_post_ID]['feedbacks']['total'] += $row->type_count; 127 } 128 } 129 130 if( ($mode != 'comments') && ($mode != 'trackbacks') && ($mode != 'pingbacks') ) 131 { 132 $mode = 'feedbacks'; 133 } 134 135 if( ($status != 'published') && ($status != 'draft') && ($status != 'deprecated') ) 136 { 137 $status = 'total'; 138 } 139 140 // pre_dump( $cache_ctp_number[$post_id] ); 141 142 return $cache_ctp_number[$post_id][$mode][$status]; 143 } 144 145 146 /** 147 * Get a Comment by ID. Exits if the requested comment does not exist! 148 * 149 * @param integer 150 * @return Comment 151 */ 152 function Comment_get_by_ID( $comment_ID ) 153 { 154 global $DB, $cache_Comments; 155 156 if( empty($cache_Comments[$comment_ID]) ) 157 { // Load this entry into cache: 158 $query = "SELECT * 159 FROM T_comments 160 WHERE comment_ID = $comment_ID"; 161 if( $row = $DB->get_row( $query, ARRAY_A ) ) 162 { 163 $cache_Comments[$comment_ID] = new Comment( $row ); // COPY ! 164 } 165 } 166 167 if( empty( $cache_Comments[ $comment_ID ] ) ) die('Requested comment does not exist!'); 168 169 return $cache_Comments[ $comment_ID ]; 170 } 171 172 173 /* 174 * last_comments_title(-) 175 * 176 * @movedTo _obsolete092.php 177 */ 178 179 180 /***** Comment tags *****/ 181 182 /** 183 * comments_number(-) 184 * 185 * @deprecated deprecated by {@link Item::feedback_link()}, used in _edit_showposts.php 186 */ 187 function comments_number( $zero='#', $one='#', $more='#', $post_ID = NULL ) 188 { 189 if( $zero == '#' ) $zero = T_('Leave a comment'); 190 if( $one == '#' ) $one = T_('1 comment'); 191 if( $more == '#' ) $more = T_('%d comments'); 192 193 // original hack by dodo@regretless.com 194 if( empty( $post_ID ) ) 195 { 196 global $id; 197 $post_ID = $id; 198 } 199 $number = generic_ctp_number( $post_ID, 'comments' ); 200 if ($number == 0) 201 { 202 $blah = $zero; 203 } 204 elseif ($number == 1) 205 { 206 $blah = $one; 207 } 208 elseif ($number > 1) 209 { 210 $n = $number; 211 $more = str_replace('%d', $n, $more); 212 $blah = $more; 213 } 214 echo $blah; 215 } 216 217 218 /* 219 * $Log: _comment.funcs.php,v $ 220 * Revision 1.1 2007/06/25 10:59:41 fplanque 221 * MODULES (refactored MVC) 222 * 223 * Revision 1.11 2007/05/09 00:58:55 fplanque 224 * massive cleanup of old functions 225 * 226 * Revision 1.10 2007/04/26 00:11:08 fplanque 227 * (c) 2007 228 * 229 * Revision 1.9 2007/01/26 04:49:17 fplanque 230 * cleanup 231 * 232 * Revision 1.8 2006/08/21 16:07:43 fplanque 233 * refactoring 234 * 235 * Revision 1.7 2006/08/19 02:15:07 fplanque 236 * Half kille dthe pingbacks 237 * Still supported in DB in case someone wants to write a plugin. 238 * 239 * Revision 1.6 2006/07/04 17:32:29 fplanque 240 * no message 241 * 242 * Revision 1.5 2006/06/22 21:58:34 fplanque 243 * enhanced comment moderation 244 * 245 * Revision 1.4 2006/05/04 03:08:12 blueyed 246 * todo 247 * 248 * Revision 1.3 2006/04/22 16:30:00 blueyed 249 * cleanup 250 * 251 * Revision 1.2 2006/03/12 23:08:58 fplanque 252 * doc cleanup 253 * 254 * Revision 1.1 2006/02/23 21:11:57 fplanque 255 * File reorganization to MVC (Model View Controller) architecture. 256 * See index.hml files in folders. 257 * (Sorry for all the remaining bugs induced by the reorg... :/) 258 */ 259 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Thu Nov 29 23:58:50 2007 | par Balluche grâce à PHPXref 0.7 |
|