b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/views/_stats_browserhits.view.php - 309 lines - 13668 bytes - Text - Print

Description: This file implements the UI view for the browser hits summary.

   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-2014 by Francois Planque - {@link http://fplanque.com/}
   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 6136 2014-03-08 07:59:48Z manuel $
  25   */
  26  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  27  
  28  global $blog, $admin_url, $AdminUI, $referer_type_color, $hit_type_color;
  29  
  30  echo '<h2>'.T_('Hits from web browsers - Summary').get_manual_link('browser_hits_summary').'</h2>';
  31  
  32  // fplanque>> I don't get it, it seems that GROUP BY on the referer type ENUM fails pathetically!!
  33  // Bug report: http://lists.mysql.com/bugs/36
  34  // Solution : CAST to string
  35  // waltercruz >> MySQL sorts ENUM columns according to the order in which the enumeration
  36  // members were listed in the column specification, not the lexical order. Solution: CAST to string using using CONCAT
  37  // or CAST (but CAST only works from MySQL 4.0.2)
  38  // References:
  39  // http://dev.mysql.com/doc/refman/5.0/en/enum.html
  40  // http://dev.mysql.com/doc/refman/4.1/en/cast-functions.html
  41  // TODO: I've also limited this to agent_type "browser" here, according to the change for "referers" (Rev 1.6)
  42  //       -> an RSS service that sends a referer is not a real referer (though it should be listed in the robots list)! (blueyed)
  43  $sql = '
  44      SELECT SQL_NO_CACHE COUNT(*) AS hits, CONCAT(hit_referer_type) AS referer_type, hit_type,  EXTRACT(YEAR FROM hit_datetime) AS year,
  45                 EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day
  46          FROM T_hitlog
  47       WHERE hit_agent_type = "browser"';
  48  
  49  if( $blog > 0 )
  50  {
  51      $sql .= ' AND hit_blog_ID = '.$blog;
  52  }
  53  $sql .= ' GROUP BY year, month, day, referer_type, hit_type
  54                      ORDER BY year DESC, month DESC, day DESC, referer_type, hit_type';
  55  $res_hits = $DB->get_results( $sql, ARRAY_A, 'Get hit summary' );
  56  
  57  /*
  58   * Chart
  59   */
  60  if( count($res_hits) )
  61  {
  62      $last_date = 0;
  63  
  64      $col_mapping = array(
  65              'search'  => 1,
  66              'referer' => 2,
  67              'direct'  => 3,
  68              'self'    => 4,
  69              'ajax'    => 5,
  70              'special' => 6,
  71              'spam'    => 7,
  72              'admin'   => 8,
  73          );
  74  
  75      $chart[ 'chart_data' ][ 0 ] = array();
  76      $chart[ 'chart_data' ][ 1 ] = array();
  77      $chart[ 'chart_data' ][ 2 ] = array();
  78      $chart[ 'chart_data' ][ 3 ] = array();
  79      $chart[ 'chart_data' ][ 4 ] = array();
  80      $chart[ 'chart_data' ][ 5 ] = array();
  81      $chart[ 'chart_data' ][ 6 ] = array();
  82      $chart[ 'chart_data' ][ 7 ] = array();
  83      $chart[ 'chart_data' ][ 8 ] = array();
  84  
  85      $count = 0;
  86      foreach( $res_hits as $row_stats )
  87      {
  88          $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
  89          if( $last_date != $this_date )
  90          { // We just hit a new day, let's display the previous one:
  91                  $last_date = $this_date;    // that'll be the next one
  92                  $count ++;
  93                  array_unshift( $chart[ 'chart_data' ][ 0 ], date( locale_datefmt(), $last_date ) );
  94                  array_unshift( $chart[ 'chart_data' ][ 1 ], 0 );
  95                  array_unshift( $chart[ 'chart_data' ][ 2 ], 0 );
  96                  array_unshift( $chart[ 'chart_data' ][ 3 ], 0 );
  97                  array_unshift( $chart[ 'chart_data' ][ 4 ], 0 );
  98                  array_unshift( $chart[ 'chart_data' ][ 5 ], 0 );
  99                  array_unshift( $chart[ 'chart_data' ][ 6 ], 0 );
 100                  array_unshift( $chart[ 'chart_data' ][ 7 ], 0 );
 101                  array_unshift( $chart[ 'chart_data' ][ 8 ], 0 );
 102          }
 103  
 104          if ( $row_stats['hit_type'] == 'ajax' )
 105          {    // hit_type = ajax is the highest priority. If hit_type = ajax, then hit gets only to this column.
 106              $col = $col_mapping['ajax'];
 107              $chart [ 'chart_data' ][$col][0] += $row_stats['hits'];
 108          }
 109          else
 110          {
 111              if ( $row_stats['hit_type'] == 'admin' )
 112              {    // if hit_type = admin, then hits get only to this column.
 113                  $col = $col_mapping['admin'];
 114                  $chart [ 'chart_data' ][$col][0] += $row_stats['hits'];
 115              }
 116              else
 117              {    // all other hits come to this column
 118                  $col = $col_mapping[$row_stats['referer_type']];
 119                  $chart [ 'chart_data' ][$col][0] += $row_stats['hits'];
 120              }
 121          }
 122  
 123  
 124      }
 125  
 126      array_unshift( $chart[ 'chart_data' ][ 0 ], '' );
 127      array_unshift( $chart[ 'chart_data' ][ 1 ], 'Refering searches' );
 128      array_unshift( $chart[ 'chart_data' ][ 2 ], 'Referers' );
 129      array_unshift( $chart[ 'chart_data' ][ 3 ], 'Direct accesses' );    // Translations need to be UTF-8
 130      array_unshift( $chart[ 'chart_data' ][ 4 ], 'Self referred' );
 131      array_unshift( $chart[ 'chart_data' ][ 5 ], 'Ajax' );
 132      array_unshift( $chart[ 'chart_data' ][ 6 ], 'Special referrers' );
 133      array_unshift( $chart[ 'chart_data' ][ 7 ], 'Referer spam' );
 134      array_unshift( $chart[ 'chart_data' ][ 8 ], 'Admin' );
 135  
 136      // Include common chart properties:
 137      require dirname(__FILE__).'/inc/_bar_chart.inc.php';
 138  
 139  
 140      $chart[ 'series_color' ] = array (
 141              $referer_type_color['search'],
 142              $referer_type_color['referer'],
 143              $referer_type_color['direct'],
 144              $referer_type_color['self'],
 145              $hit_type_color['ajax'],
 146              $referer_type_color['special'],
 147              $referer_type_color['spam'],
 148              $referer_type_color['admin'],
 149          );
 150  
 151      echo '<div class="center">';
 152      load_funcs('_ext/_swfcharts.php');
 153      DrawChart( $chart );
 154      echo '</div>';
 155  
 156  
 157      /*
 158       * Table:
 159       */
 160      $hits = array(
 161          'direct' => 0,
 162          'referer' => 0,
 163          'search' => 0,
 164          'self' => 0,
 165          'ajax' => 0,
 166          'special' => 0,
 167          'spam' => 0,
 168          'admin' => 0,
 169      );
 170      $hits_total = $hits;
 171  
 172      $last_date = 0;
 173  
 174      ?>
 175  
 176      <table class="grouped" cellspacing="0">
 177          <tr>
 178              <th class="firstcol"><?php echo T_('Date') ?></th>
 179              <th style="background-color: #<?php echo $referer_type_color['search'] ?>"><?php echo T_('Refering searches') ?></th>
 180              <th style="background-color: #<?php echo $referer_type_color['referer'] ?>"><?php echo T_('Referers') ?></th>
 181              <th style="background-color: #<?php echo $referer_type_color['direct'] ?>"><?php echo T_('Direct accesses') ?></th>
 182              <th style="background-color: #<?php echo $referer_type_color['self'] ?>"><?php echo T_('Self referred') ?></th>
 183              <th style="background-color: #<?php echo $hit_type_color['ajax'] ?>"><?php echo T_('Ajax') ?></th>
 184              <th style="background-color: #<?php echo $referer_type_color['special'] ?>"><?php echo T_('Special referrers') ?></th>
 185              <th style="background-color: #<?php echo $referer_type_color['spam'] ?>"><?php echo T_('Referer spam') ?></th>
 186              <th style="background-color: #<?php echo $referer_type_color['admin'] ?>"><?php echo T_('Admin') ?></th>
 187              <th class="lastcol"><?php echo T_('Total') ?></th>
 188          </tr>
 189          <?php
 190          $count = 0;
 191          foreach( $res_hits as $row_stats )
 192          {
 193              $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
 194  
 195              if( $last_date == 0 ) $last_date = $this_date;    // that'll be the first one
 196  
 197              $link_text = $admin_url.'?ctrl=stats&tab=hits&datestartinput='.urlencode( date( locale_datefmt() , $last_date ) ).'&datestopinput='.urlencode( date( locale_datefmt(), $last_date ) ).'&blog='.$blog.'&agent_type=browser';
 198              $link_text_total_day = $admin_url.'?ctrl=stats&tab=hits&datestartinput='.urlencode( date( locale_datefmt() , $last_date ) ).'&datestopinput='.urlencode( date( locale_datefmt(), $last_date ) ).'&blog='.$blog.'&agent_type=browser';
 199  
 200              if( $last_date != $this_date )
 201              { // We just hit a new day, let's display the previous one:
 202                  ?>
 203                  <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even'; ?>">
 204                      <td class="firstcol"><?php if( $current_User->check_perm( 'stats', 'edit' ) )
 205                          {
 206                              echo action_icon( T_('Prune hits for this date!'), 'delete', url_add_param( $admin_url, 'ctrl=stats&amp;action=prune&amp;date='.$last_date.'&amp;show=summary&amp;blog='.$blog.'&amp;'.url_crumb('stats') ) );
 207                          }
 208                          echo date( locale_datefmt(), $last_date ) ?>
 209                      </td>
 210                  <td class="right"><a href="<?php echo $link_text.'&referer_type=search'?>"><?php echo $hits['search'] ?></a></td>
 211                  <td class="right"><a href="<?php echo $link_text.'&referer_type=referer'?>"><?php echo $hits['referer'] ?></a></td>
 212                  <td class="right"><a href="<?php echo $link_text.'&referer_type=direct'?>"><?php echo $hits['direct'] ?></a></td>
 213                  <td class="right"><a href="<?php echo $link_text.'&referer_type=self'?>"><?php echo $hits['self'] ?></a></td>
 214                  <td class="right"><a href="<?php echo $link_text.'&hit_type=ajax'?>"><?php echo $hits['ajax'] ?></a></td>
 215                  <td class="right"><a href="<?php echo $link_text.'&referer_type=special'?>"><?php echo $hits['special'] ?></a></td>
 216                  <td class="right"><a href="<?php echo $link_text.'&referer_type=spam'?>"><?php echo $hits['spam'] ?></a></td>
 217                  <td class="right"><a href="<?php echo $link_text.'&hit_type=admin'?>"><?php echo $hits['admin'] ?></a></td>
 218                  <td class="lastcol right"><a href="<?php echo $link_text_total_day ?>"><?php echo array_sum($hits) ?></a></td>
 219                  </tr>
 220                  <?php
 221                      $hits = array(
 222                          'direct' => 0,
 223                          'referer' => 0,
 224                          'search' => 0,
 225                          'self' => 0,
 226                          'ajax' => 0,
 227                          'special' => 0,
 228                          'spam' => 0,
 229                          'admin' => 0,
 230                      );
 231                      $last_date = $this_date;    // that'll be the next one
 232                      $count ++;
 233              }
 234  
 235              // Increment hitcounter:
 236  
 237              if ( $row_stats['hit_type'] == 'ajax' )
 238              {
 239                  $hits['ajax'] += $row_stats['hits'];
 240                  $hits_total['ajax'] += $row_stats['hits'];
 241              }
 242              else
 243              {
 244                  if ( $row_stats['hit_type'] == 'admin' )
 245                  {
 246                      $hits['admin'] += $row_stats['hits'];
 247                      $hits_total['admin'] += $row_stats['hits'];
 248                  }
 249                  else
 250                  {
 251                      $hits[$row_stats['referer_type']] += $row_stats['hits'];
 252                      $hits_total[$row_stats['referer_type']] += $row_stats['hits'];
 253                  }
 254              }
 255  
 256          }
 257  
 258          if( $last_date != 0 )
 259          { // We had a day pending:
 260              $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
 261  
 262              $link_text = $admin_url.'?ctrl=stats&tab=hits&datestartinput='.urlencode( date( locale_datefmt() , $last_date ) ).'&datestopinput='.urlencode( date( locale_datefmt(), $last_date ) ).'&blog='.$blog.'&agent_type=browser';
 263              $link_text_total_day = $admin_url.'?ctrl=stats&tab=hits&datestartinput='.urlencode( date( locale_datefmt() , $last_date ) ).'&datestopinput='.urlencode( date( locale_datefmt(), $last_date ) ).'&blog='.$blog.'&agent_type=browser';
 264              ?>
 265                  <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even'; ?>">
 266                  <td class="firstcol"><?php if( $current_User->check_perm( 'stats', 'edit' ) )
 267                      {
 268                          echo action_icon( T_('Prune hits for this date!'), 'delete', url_add_param( $admin_url, 'ctrl=stats&amp;action=prune&amp;date='.$last_date.'&amp;show=summary&amp;blog='.$blog.'&amp;'.url_crumb('stats') ) );
 269                      }
 270                      echo date( locale_datefmt(), $this_date ) ?>
 271                  </td>
 272                  <td class="right"><a href="<?php echo $link_text.'&referer_type=search'?>"><?php echo $hits['search'] ?></a></td>
 273                  <td class="right"><a href="<?php echo $link_text.'&referer_type=referer'?>"><?php echo $hits['referer'] ?></a></td>
 274                  <td class="right"><a href="<?php echo $link_text.'&referer_type=direct'?>"><?php echo $hits['direct'] ?></a></td>
 275                  <td class="right"><a href="<?php echo $link_text.'&referer_type=self'?>"><?php echo $hits['self'] ?></a></td>
 276                  <td class="right"><a href="<?php echo $link_text.'&hit_type=ajax'?>"><?php echo $hits['ajax'] ?></a></td>
 277                  <td class="right"><a href="<?php echo $link_text.'&referer_type=special'?>"><?php echo $hits['special'] ?></a></td>
 278                  <td class="right"><a href="<?php echo $link_text.'&referer_type=spam'?>"><?php echo $hits['spam'] ?></a></td>
 279                  <td class="right"><a href="<?php echo $link_text.'&hit_type=admin'?>"><?php echo $hits['admin'] ?></a></td>
 280                  <td class="lastcol right"><a href="<?php echo $link_text_total_day ?>"><?php echo array_sum($hits) ?></a></td>
 281              </tr>
 282              <?php
 283          }
 284  
 285          // Total numbers:
 286  
 287          $link_text_total = $admin_url.'?ctrl=stats&tab=hits&blog='.$blog.'&agent_type=browser';
 288          ?>
 289  
 290          <tr class="total">
 291          <td class="firstcol"><?php echo T_('Total') ?></td>
 292          <td class="right"><a href="<?php echo $link_text_total.'&referer_type=search'?>"><?php echo $hits_total['search'] ?></a></td>
 293          <td class="right"><a href="<?php echo $link_text_total.'&referer_type=referer'?>"><?php echo $hits_total['referer'] ?></a></td>
 294          <td class="right"><a href="<?php echo $link_text_total.'&referer_type=direct'?>"><?php echo $hits_total['direct'] ?></a></td>
 295          <td class="right"><a href="<?php echo $link_text_total.'&referer_type=self'?>"><?php echo $hits_total['self'] ?></a></td>
 296          <td class="right"><a href="<?php echo $link_text_total.'&hit_type=ajax'?>"><?php echo $hits_total['ajax'] ?></a></td>
 297          <td class="right"><a href="<?php echo $link_text_total.'&referer_type=special'?>"><?php echo $hits_total['special'] ?></a></td>
 298          <td class="right"><a href="<?php echo $link_text_total.'&referer_type=spam'?>"><?php echo $hits_total['spam'] ?></a></td>
 299          <td class="right"><a href="<?php echo $link_text_total.'&hit_type=admin'?>"><?php echo $hits_total['admin'] ?></a></td>
 300          <td class="lastcol right"><a href="<?php echo $link_text_total?>"><?php echo array_sum($hits_total) ?></a></td>
 301          </tr>
 302  
 303      </table>
 304  
 305      <!--[if IE]><?php echo get_icon( 'pixel' ); ?><![endif]-->
 306      <?php
 307  }
 308  
 309  ?>

title

Description

title

Description

title

Description

title

title

Body