[ Index ] |
|
Code source de b2evolution 2.1.0-beta |
1 <?php 2 /** 3 * This file implements the UI view for the browser hits summary. 4 * 5 * This file is part of the evoCore framework - {@link http://evocore.net/} 6 * See also {@link http://sourceforge.net/projects/evocms/}. 7 * 8 * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/} 9 * 10 * {@internal License choice 11 * - If you have received this file as part of a package, please find the license.txt file in 12 * the same folder or the closest folder above for complete license terms. 13 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/) 14 * then you must choose one of the following licenses before using the file: 15 * - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php 16 * - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php 17 * }} 18 * 19 * {@internal Open Source relicensing agreement: 20 * }} 21 * 22 * @package admin 23 * 24 * @version $Id: _stats_browserhits.view.php,v 1.2 2007/09/03 19:36:06 fplanque Exp $ 25 */ 26 if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' ); 27 28 global $blog, $admin_url; 29 30 31 echo '<h2>'.T_('Browser hits summary').'</h2>'; 32 33 34 echo '<p>'.sprintf( T_('This page only includes hits identified as made by a <a %s>web browser</a>.'), ' href="?ctrl=stats&tab=useragents&agnt_browser=1&blog='.$blog.'"' ).'</p>'; 35 36 37 // fplanque>> I don't get it, it seems that GROUP BY on the referer type ENUM fails pathetically!! 38 // Bug report: http://lists.mysql.com/bugs/36 39 // Solution : CAST to string 40 // waltercruz >> MySQL sorts ENUM columns according to the order in which the enumeration 41 // members were listed in the column specification, not the lexical order. Solution: CAST to string using using CONCAT 42 // or CAST (but CAST only works from MySQL 4.0.2) 43 // References: 44 // http://dev.mysql.com/doc/refman/5.0/en/enum.html 45 // http://dev.mysql.com/doc/refman/4.1/en/cast-functions.html 46 // TODO: I've also limited this to agnt_type "browser" here, according to the change for "referers" (Rev 1.6) 47 // -> an RSS service that sends a referer is not a real referer (though it should be listed in the robots list)! (blueyed) 48 $sql = ' 49 SELECT COUNT(*) AS hits, CONCAT(hit_referer_type) AS referer_type, EXTRACT(YEAR FROM hit_datetime) AS year, 50 EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day 51 FROM T_hitlog INNER JOIN T_useragents ON hit_agnt_ID = agnt_ID 52 WHERE agnt_type = "browser"'; 53 if( $blog > 0 ) 54 { 55 $sql .= ' AND hit_blog_ID = '.$blog; 56 } 57 $sql .= ' GROUP BY year, month, day, referer_type 58 ORDER BY year DESC, month DESC, day DESC, referer_type'; 59 $res_hits = $DB->get_results( $sql, ARRAY_A, 'Get hit summary' ); 60 61 62 /* 63 * Chart 64 */ 65 if( count($res_hits) ) 66 { 67 $last_date = 0; 68 69 $col_mapping = array( 70 'search' => 1, 71 'referer' => 2, 72 'direct' => 3, 73 'self' => 4, 74 'blacklist' => 5, 75 'spam' => 6, 76 'admin' => 7, 77 ); 78 79 $chart[ 'chart_data' ][ 0 ] = array(); 80 $chart[ 'chart_data' ][ 1 ] = array(); 81 $chart[ 'chart_data' ][ 2 ] = array(); 82 $chart[ 'chart_data' ][ 3 ] = array(); 83 $chart[ 'chart_data' ][ 4 ] = array(); 84 $chart[ 'chart_data' ][ 5 ] = array(); 85 $chart[ 'chart_data' ][ 6 ] = array(); 86 $chart[ 'chart_data' ][ 7 ] = array(); 87 88 $count = 0; 89 foreach( $res_hits as $row_stats ) 90 { 91 $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] ); 92 if( $last_date != $this_date ) 93 { // We just hit a new day, let's display the previous one: 94 $last_date = $this_date; // that'll be the next one 95 $count ++; 96 array_unshift( $chart[ 'chart_data' ][ 0 ], date( locale_datefmt(), $last_date ) ); 97 array_unshift( $chart[ 'chart_data' ][ 1 ], 0 ); 98 array_unshift( $chart[ 'chart_data' ][ 2 ], 0 ); 99 array_unshift( $chart[ 'chart_data' ][ 3 ], 0 ); 100 array_unshift( $chart[ 'chart_data' ][ 4 ], 0 ); 101 array_unshift( $chart[ 'chart_data' ][ 5 ], 0 ); 102 array_unshift( $chart[ 'chart_data' ][ 6 ], 0 ); 103 array_unshift( $chart[ 'chart_data' ][ 7 ], 0 ); 104 } 105 $col = $col_mapping[$row_stats['referer_type']]; 106 $chart [ 'chart_data' ][$col][0] = $row_stats['hits']; 107 } 108 109 array_unshift( $chart[ 'chart_data' ][ 0 ], '' ); 110 array_unshift( $chart[ 'chart_data' ][ 1 ], 'Refering searches' ); 111 array_unshift( $chart[ 'chart_data' ][ 2 ], 'Referers' ); 112 array_unshift( $chart[ 'chart_data' ][ 3 ], 'Direct accesses' ); // Translations need to be UTF-8 113 array_unshift( $chart[ 'chart_data' ][ 4 ], 'Self referred' ); 114 array_unshift( $chart[ 'chart_data' ][ 5 ], 'Special referrers' ); 115 array_unshift( $chart[ 'chart_data' ][ 6 ], 'Referer spam' ); 116 array_unshift( $chart[ 'chart_data' ][ 7 ], 'Admin' ); 117 118 $chart[ 'canvas_bg' ] = array ( 119 'width' => 780, 120 'height' => 400, 121 'color' => 'efede0' 122 ); 123 124 $chart[ 'chart_rect' ] = array ( 125 'x' => 50, 126 'y' => 50, 127 'width' => 700, 128 'height' => 250 129 ); 130 131 $chart[ 'legend_rect' ] = array ( 132 'x' => 50, 133 'y' => 365, 134 'width' => 700, 135 'height' => 8, 136 'margin' => 6 137 ); 138 139 $chart[ 'draw_text' ] = array ( 140 array ( 141 'color' => '9e9286', 142 'alpha' => 75, 143 'font' => "arial", 144 'rotation' => 0, 145 'bold' => true, 146 'size' => 42, 147 'x' => 50, 148 'y' => 6, 149 'width' => 700, 150 'height' => 50, 151 'text' => 'Browser hits', // Needs UTF-8 152 'h_align' => "right", 153 'v_align' => "bottom" ), 154 ); 155 156 $chart[ 'chart_bg' ] = array ( 157 'positive_color' => "ffffff", 158 // 'negative_color' => string, 159 'positive_alpha' => 20, 160 // 'negative_alpha' => int 161 ); 162 163 $chart [ 'legend_bg' ] = array ( 164 'bg_color' => "ffffff", 165 'bg_alpha' => 20, 166 // 'border_color' => "000000", 167 // 'border_alpha' => 100, 168 // 'border_thickness' => 1 169 ); 170 171 $chart [ 'legend_label' ] = array( 172 // 'layout' => "horizontal", 173 // 'font' => string, 174 // 'bold' => boolean, 175 'size' => 10, 176 // 'color' => string, 177 // 'alpha' => int 178 ); 179 180 $chart[ 'chart_border' ] = array ( 181 'color'=>"000000", 182 'top_thickness'=>1, 183 'bottom_thickness'=>1, 184 'left_thickness'=>1, 185 'right_thickness'=>1 186 ); 187 188 $chart[ 'chart_type' ] = 'stacked column'; 189 190 // $chart[ 'series_color' ] = array ( "4e627c", "c89341" ); 191 192 $chart[ 'series_gap' ] = array ( 'set_gap'=>0, 'bar_gap'=>0 ); 193 194 195 $chart[ 'axis_category' ] = array ( 196 'font' =>"arial", 197 'bold' =>true, 198 'size' =>11, 199 'color' =>'000000', 200 'alpha' =>75, 201 'orientation' => 'diagonal_up', 202 // 'skip'=>2 203 ); 204 205 $chart[ 'axis_value' ] = array ( 206 // 'font' =>"arial", 207 // 'bold' =>true, 208 'size' => 11, 209 'color' => '000000', 210 'alpha' => 75, 211 'steps' => 4, 212 'prefix' => "", 213 'suffix' => "", 214 'decimals'=> 0, 215 'separator'=> "", 216 'show_min'=> false ); 217 218 $chart [ 'chart_value' ] = array ( 219 // 'prefix' => string, 220 // 'suffix' => " views", 221 // 'decimals' => int, 222 // 'separator' => string, 223 'position' => "cursor", 224 'hide_zero' => true, 225 // 'as_percentage' => boolean, 226 'font' => "arial", 227 'bold' => true, 228 'size' => 20, 229 'color' => "ffffff", 230 'alpha' => 75 231 ); 232 233 echo '<div class="center">'; 234 DrawChart( $chart ); 235 echo '</div>'; 236 237 238 /* 239 * Table: 240 */ 241 $hits = array( 242 'direct' => 0, 243 'referer' => 0, 244 'search' => 0, 245 'self' => 0, 246 'blacklist' => 0, 247 'spam' => 0, 248 'admin' => 0, 249 ); 250 $hits_total = $hits; 251 252 $last_date = 0; 253 254 ?> 255 256 <table class="grouped" cellspacing="0"> 257 <tr> 258 <th class="firstcol"><?php echo T_('Date') ?></th> 259 <th><?php echo T_('Refering searches') ?></th> 260 <th><?php echo T_('Referers') ?></th> 261 <th><?php echo T_('Direct accesses') ?></th> 262 <th><?php echo T_('Self referred') ?></th> 263 <th><?php echo T_('Special referrers') ?></th> 264 <th><?php echo T_('Referer spam') ?></th> 265 <th><?php echo T_('Admin') ?></th> 266 <th class="lastcol"><?php echo T_('Total') ?></th> 267 </tr> 268 <?php 269 $count = 0; 270 foreach( $res_hits as $row_stats ) 271 { 272 $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] ); 273 if( $last_date == 0 ) $last_date = $this_date; // that'll be the first one 274 if( $last_date != $this_date ) 275 { // We just hit a new day, let's display the previous one: 276 ?> 277 <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even'; ?>"> 278 <td class="firstcol"><?php if( $current_User->check_perm( 'stats', 'edit' ) ) 279 { 280 echo action_icon( T_('Prune hits for this date!'), 'delete', url_add_param( $admin_url, 'ctrl=stats&action=prune&date='.$last_date.'&show=summary&blog='.$blog ) ); 281 } 282 echo date( locale_datefmt(), $last_date ) ?> 283 </td> 284 <td class="right"><?php echo $hits['search'] ?></td> 285 <td class="right"><?php echo $hits['referer'] ?></td> 286 <td class="right"><?php echo $hits['direct'] ?></td> 287 <td class="right"><?php echo $hits['self'] ?></td> 288 <td class="right"><?php echo $hits['blacklist'] ?></td> 289 <td class="right"><?php echo $hits['spam'] ?></td> 290 <td class="right"><?php echo $hits['admin'] ?></td> 291 <td class="lastcol right"><?php echo array_sum($hits) ?></td> 292 </tr> 293 <?php 294 $hits = array( 295 'direct' => 0, 296 'referer' => 0, 297 'search' => 0, 298 'self' => 0, 299 'blacklist' => 0, 300 'spam' => 0, 301 'admin' => 0, 302 ); 303 $last_date = $this_date; // that'll be the next one 304 $count ++; 305 } 306 307 // Increment hitcounter: 308 $hits[$row_stats['referer_type']] = $row_stats['hits']; 309 $hits_total[$row_stats['referer_type']] += $row_stats['hits']; 310 } 311 312 if( $last_date != 0 ) 313 { // We had a day pending: 314 ?> 315 <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even'; ?>"> 316 <td class="firstcol"><?php if( $current_User->check_perm( 'stats', 'edit' ) ) 317 { 318 echo action_icon( T_('Prune hits for this date!'), 'delete', url_add_param( $admin_url, 'ctrl=stats&action=prune&date='.$last_date.'&show=summary&blog='.$blog ) ); 319 } 320 echo date( locale_datefmt(), $this_date ) ?> 321 </td> 322 <td class="right"><?php echo $hits['search'] ?></td> 323 <td class="right"><?php echo $hits['referer'] ?></td> 324 <td class="right"><?php echo $hits['direct'] ?></td> 325 <td class="right"><?php echo $hits['self'] ?></td> 326 <td class="right"><?php echo $hits['blacklist'] ?></td> 327 <td class="right"><?php echo $hits['spam'] ?></td> 328 <td class="right"><?php echo $hits['admin'] ?></td> 329 <td class="lastcol right"><?php echo array_sum($hits) ?></td> 330 </tr> 331 <?php 332 } 333 334 // Total numbers: 335 ?> 336 337 <tr class="total"> 338 <td class="firstcol"><?php echo T_('Total') ?></td> 339 <td class="right"><?php echo $hits_total['search'] ?></td> 340 <td class="right"><?php echo $hits_total['referer'] ?></td> 341 <td class="right"><?php echo $hits_total['direct'] ?></td> 342 <td class="right"><?php echo $hits_total['self'] ?></td> 343 <td class="right"><?php echo $hits_total['blacklist'] ?></td> 344 <td class="right"><?php echo $hits_total['spam'] ?></td> 345 <td class="right"><?php echo $hits_total['admin'] ?></td> 346 <td class="lastcol right"><?php echo array_sum($hits_total) ?></td> 347 </tr> 348 349 </table> 350 351 <img src="'.$rsc_url.'/img/blank.gif" width="1" height="1" /><!-- for IE --> 352 <?php 353 } 354 355 /* 356 * $Log: _stats_browserhits.view.php,v $ 357 * Revision 1.2 2007/09/03 19:36:06 fplanque 358 * chicago admin skin 359 * 360 * Revision 1.1 2007/06/25 11:01:00 fplanque 361 * MODULES (refactored MVC) 362 * 363 * Revision 1.10 2007/04/27 09:11:37 fplanque 364 * saving "spam" referers again (instead of buggy empty referers) 365 * 366 * Revision 1.9 2007/04/26 00:11:12 fplanque 367 * (c) 2007 368 * 369 * Revision 1.8 2007/02/25 01:31:34 fplanque 370 * minor 371 * 372 * Revision 1.7 2007/02/14 11:39:18 waltercruz 373 * Reverting the reverted query and adding a comment about the sorting of ENUMS 374 * 375 * Revision 1.6 2007/02/11 15:19:58 fplanque 376 * rollback of non equivalent query 377 * 378 * Revision 1.4 2006/11/26 01:42:10 fplanque 379 * doc 380 */ 381 ?>
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 |
![]() |