b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/views/_stats_summary.view.php - 301 lines - 14291 bytes - Text - Print

Description: This file implements the UI view for the general hit summary.

   1  <?php
   2  /**
   3   * This file implements the UI view for the general hit 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_summary.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, $agent_type_color, $hit_type_color;
  29  
  30  echo '<h2>'.T_('Global hits - Summary').get_manual_link('global_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  // TODO: I've also limited this to hit_agent_type "browser" here, according to the change for "referers" (Rev 1.6)
  36  //       -> an RSS service that sends a referer is not a real referer (though it should be listed in the robots list)! (blueyed)
  37  $sql = '
  38      SELECT SQL_NO_CACHE COUNT(*) AS hits, hit_agent_type, hit_type, EXTRACT(YEAR FROM hit_datetime) AS year,
  39                 EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day
  40          FROM T_hitlog';
  41  if( $blog > 0 )
  42  {
  43      $sql .= ' WHERE hit_blog_ID = '.$blog;
  44  }
  45  $sql .= ' GROUP BY year, month, day, hit_agent_type, hit_type
  46                      ORDER BY year DESC, month DESC, day DESC, hit_agent_type, hit_type';
  47  $res_hits = $DB->get_results( $sql, ARRAY_A, 'Get hit summary' );
  48  
  49  
  50  /*
  51   * Chart
  52   */
  53  if( count($res_hits) )
  54  {
  55      $last_date = 0;
  56  
  57      // This defines what hits will go where
  58      // This maps a 'hit_type' (from any agent type that is 'browser' or 'robot') to a column
  59      // OR it can also map 'hit_type'_'hit_agent_type' (concatenated with _ ) to a column
  60      // OR the 'unknown' column will get ANY hits from an unknown user agent (this will go to the "other" column)
  61      $col_mapping = array(
  62              'rss'        => 1,                            // Dark orange
  63              'standard_robot' => 2,        // Orange
  64              'standard_browser' => 3,    // Yello
  65              'ajax'        => 4,                        // green
  66              'service'    => 5,                        // dark blue
  67              'admin'        => 6,                        // light blue
  68              'unknown'    => 7,                        // Grey - "Other column"
  69          );
  70  
  71      $chart[ 'chart_data' ][ 0 ] = array();
  72      $chart[ 'chart_data' ][ 1 ] = array();
  73      $chart[ 'chart_data' ][ 2 ] = array();
  74      $chart[ 'chart_data' ][ 3 ] = array();
  75      $chart[ 'chart_data' ][ 4 ] = array();
  76      $chart[ 'chart_data' ][ 5 ] = array();
  77      $chart[ 'chart_data' ][ 6 ] = array();
  78      $chart[ 'chart_data' ][ 7 ] = array();
  79  
  80      $count = 0;
  81      foreach( $res_hits as $row_stats )
  82      {
  83          $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
  84          if( $last_date != $this_date )
  85          { // We just hit a new day, let's display the previous one:
  86                  $last_date = $this_date;    // that'll be the next one
  87                  $count ++;
  88                  array_unshift( $chart[ 'chart_data' ][ 0 ], date( locale_datefmt(), $last_date ) );
  89                  array_unshift( $chart[ 'chart_data' ][ 1 ], 0 );
  90                  array_unshift( $chart[ 'chart_data' ][ 2 ], 0 );
  91                  array_unshift( $chart[ 'chart_data' ][ 3 ], 0 );
  92                  array_unshift( $chart[ 'chart_data' ][ 4 ], 0 );
  93                  array_unshift( $chart[ 'chart_data' ][ 5 ], 0 );
  94                  array_unshift( $chart[ 'chart_data' ][ 6 ], 0 );
  95                  array_unshift( $chart[ 'chart_data' ][ 7 ], 0 );
  96  
  97          }
  98          if ($row_stats['hit_agent_type'] == 'unknown')
  99          {    // only those hits are calculated which hit_agent_type = unknown
 100              $col = $col_mapping[$row_stats['hit_agent_type']];
 101              $chart['chart_data'][$col][0] += $row_stats['hits'];
 102          }
 103          else
 104          {
 105              if (! empty ( $col_mapping[$row_stats['hit_type'].'_'.$row_stats['hit_agent_type']] ) )
 106              {    // those hits are calculated here if hit_type = standard and hit_agent_type = browser, robot
 107                  $col = $col_mapping[$row_stats['hit_type'].'_'.$row_stats['hit_agent_type']];
 108                  $chart['chart_data'][$col][0] += $row_stats['hits'];
 109              }
 110              if (! empty ( $col_mapping[$row_stats['hit_type']]) )
 111              {    // those hits are calculated here which did not match either of the above rules
 112                  $col = $col_mapping[$row_stats['hit_type']];
 113                  $chart['chart_data'][$col][0] += $row_stats['hits'];
 114              }
 115  
 116          }
 117      }
 118  
 119      /*
 120      ONE COLOR for hit_type = ajax
 121      ONE COLOR for hit_type = service
 122      ONE COLOR for hit_type = rss
 123      ONE COLOR for hit_type = admin
 124      ONE COLOR for hit_type = standard AND agent_type = robots
 125      ONE COLOR for hit_type = standard AND agent_type <> robots
 126      ONE COLOR (grey) for hit_type = anything that is not above
 127      */
 128      array_unshift( $chart[ 'chart_data' ][ 0 ], '' );
 129      array_unshift( $chart[ 'chart_data' ][ 1 ], 'XML (RSS/Atom)' );
 130      array_unshift( $chart[ 'chart_data' ][ 2 ], 'Standard/Robots' );
 131      array_unshift( $chart[ 'chart_data' ][ 3 ], 'Standard/Browsers' );
 132      array_unshift( $chart[ 'chart_data' ][ 4 ], 'Ajax' );
 133      array_unshift( $chart[ 'chart_data' ][ 5 ], 'Service' );
 134      array_unshift( $chart[ 'chart_data' ][ 6 ], 'Admin' );
 135      array_unshift( $chart[ 'chart_data' ][ 7 ], 'Other' );
 136  
 137      // Include common chart properties:
 138      require dirname(__FILE__).'/inc/_bar_chart.inc.php';
 139  
 140      $chart[ 'series_color' ] = array (
 141              $hit_type_color['rss'],
 142              $hit_type_color['standard_robot'],
 143              $hit_type_color['standard_browser'],
 144              $hit_type_color['ajax'],
 145              $hit_type_color['service'],
 146              $hit_type_color['admin'],
 147              $agent_type_color['unknown'],
 148          );
 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  
 161      $hits = array(
 162              'ajax'        => 0,
 163              'service'    => 0,
 164              'rss'        => 0,
 165              'admin'        => 0,
 166              'standard_robot' => 0,
 167              'standard_browser' => 0,
 168              'unknown'    => 0,
 169          );
 170  
 171      $hits_total = $hits;
 172  
 173      $last_date = 0;
 174  
 175  
 176      echo '<table class="grouped" cellspacing="0">';
 177      echo '<tr>';
 178      echo '<th class="firstcol">'.T_('Date').'</th>';
 179      echo '<th style="background-color: #'.$hit_type_color['rss'].'"><a href="?ctrl=stats&amp;tab=hits&amp;hit_type=rss&amp;blog='.$blog.'">'.T_('RSS/Atom').'</a></th>';
 180      echo '<th style="background-color: #'.$hit_type_color['standard_robot'].'"><a href="?ctrl=stats&amp;tab=hits&amp;hit_type=standard&amp;agent_type=robot&amp;blog='.$blog.'">'.T_('Standard/Robots').'</a></th>';
 181      echo '<th style="background-color: #'.$hit_type_color['standard_browser'].'"><a href="?ctrl=stats&amp;tab=hits&amp;hit_type=standard&amp;agent_type=browser&amp;blog='.$blog.'">'.T_('Standard/Browsers').'</a></th>';
 182      echo '<th style="background-color: #'.$hit_type_color['ajax'].'"><a href="?ctrl=stats&amp;tab=hits&amp;hit_type=ajax&amp;blog='.$blog.'">'.T_('Ajax').'</a></th>';
 183      echo '<th style="background-color: #'.$hit_type_color['service'].'"><a href="?ctrl=stats&amp;tab=hits&amp;hit_type=service&amp;blog='.$blog.'">'.T_('Service').'</a></th>';
 184      echo '<th style="background-color: #'.$hit_type_color['admin'].'"><a href="?ctrl=stats&amp;tab=hits&amp;hit_type=admin&amp;blog='.$blog.'">'.T_('Admin').'</a></th>';
 185      echo '<th style="background-color: #'.$agent_type_color['unknown'].'"><a href="?ctrl=stats&amp;tab=hits&amp;agent_type=unknown&amp;blog='.$blog.'">'.T_('Other').'</a></th>';
 186      echo '<th class="lastcol">'.T_('Total').'</th>';
 187      echo '</tr>';
 188  
 189      $count = 0;
 190      foreach( $res_hits as $row_stats )
 191      {
 192          $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
 193          if( $last_date == 0 ) $last_date = $this_date;    // that'll be the first one
 194  
 195          $link_text = $admin_url.'?ctrl=stats&tab=hits&datestartinput='.urlencode( date( locale_datefmt() , $last_date ) ).'&datestopinput='.urlencode( date( locale_datefmt(), $last_date ) ).'&blog='.$blog;
 196          $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;
 197  
 198  
 199          if( $last_date != $this_date )
 200          { // We just hit a new day, let's display the previous one:
 201              ?>
 202              <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even'; ?>">
 203                  <td class="firstcol"><?php if( $current_User->check_perm( 'stats', 'edit' ) )
 204                      {
 205                          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') ) );
 206                      }
 207                      echo date( locale_datefmt(), $last_date ) ?>
 208                  </td>
 209  
 210                  <td class="right"><a href="<?php echo $link_text.'&hit_type=rss'?>"><?php echo $hits['rss'] ?></a></td>
 211                  <td class="right"><a href="<?php echo $link_text.'&hit_type=standard&agent_type=robot'?>"><?php echo $hits['standard_robot'] ?></a></td>
 212                  <td class="right"><a href="<?php echo $link_text.'&hit_type=standard&agent_type=browser'?>"><?php echo $hits['standard_browser'] ?></a></td>
 213                  <td class="right"><a href="<?php echo $link_text.'&hit_type=ajax'?>"><?php echo $hits['ajax'] ?></a></td>
 214                  <td class="right"><a href="<?php echo $link_text.'&hit_type=service'?>"><?php echo $hits['service'] ?></a></td>
 215                  <td class="right"><a href="<?php echo $link_text.'&hit_type=admin'?>"><?php echo $hits['admin'] ?></a></td>
 216                  <td class="right"><a href="<?php echo $link_text.'&agent_type=unknown'?>"><?php echo $hits['unknown'] ?></a></td>
 217                  <td class="lastcol right"><a href="<?php echo $link_text_total_day ?>"><?php echo array_sum($hits) ?></a></td>
 218              </tr>
 219              <?php
 220                  $hits = array(
 221                      'ajax'        => 0,
 222                      'service'    => 0,
 223                      'rss'        => 0,
 224                      'admin'        => 0,
 225                      'standard_robot' => 0,
 226                      'standard_browser' => 0,
 227                      'unknown'    => 0,
 228                  );
 229                  $last_date = $this_date;    // that'll be the next one
 230                  $count ++;
 231          }
 232  
 233          // Increment hitcounter:
 234          if( ! empty( $col_mapping[$row_stats['hit_type'].'_'.$row_stats['hit_agent_type']] ) )
 235          {    // We have a column for this narrow type:
 236              $hits[$row_stats['hit_type'].'_'.$row_stats['hit_agent_type']] += $row_stats['hits'];
 237              $hits_total[$row_stats['hit_type'].'_'.$row_stats['hit_agent_type']] += $row_stats['hits'];
 238          }
 239          elseif( !empty( $col_mapping[$row_stats['hit_type']]) )
 240          {    // We have a column for this broad type:
 241              $hits[$row_stats['hit_type']] += $row_stats['hits'];
 242              $hits_total[$row_stats['hit_type']] += $row_stats['hits'];
 243          }
 244          else
 245          { // We have no column for this hit_type, This will go to the "Other" column.
 246              // Note: this will never happen if all hit_types are properly defined in  $col_mapping
 247              $hits[$row_stats['hit_agent_type']] += $row_stats['hits'];
 248              $hits_total[$row_stats['hit_agent_type']] += $row_stats['hits'];
 249          }
 250  
 251      }
 252  
 253      if( $last_date != 0 )
 254      { // We had a day pending:
 255          $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
 256  
 257          $link_text = $admin_url.'?ctrl=stats&tab=hits&datestartinput='.urlencode( date( locale_datefmt() , $last_date ) ).'&datestopinput='.urlencode( date( locale_datefmt(), $last_date ) ).'&blog='.$blog;
 258          $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;
 259          ?>
 260              <tr class="<?php echo ( $count%2 == 1 ) ? 'odd' : 'even'; ?>">
 261              <td class="firstcol"><?php if( $current_User->check_perm( 'stats', 'edit' ) )
 262                  {
 263                      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') ) );
 264                  }
 265                  echo date( locale_datefmt(), $this_date ) ?>
 266              </td>
 267                  <td class="right"><a href="<?php echo $link_text.'&hit_type=rss'?>"><?php echo $hits['rss'] ?></a></td>
 268                  <td class="right"><a href="<?php echo $link_text.'&hit_type=standard&agent_type=robot'?>"><?php echo $hits['standard_robot'] ?></a></td>
 269                  <td class="right"><a href="<?php echo $link_text.'&hit_type=standard&agent_type=browser'?>"><?php echo $hits['standard_browser'] ?></a></td>
 270                  <td class="right"><a href="<?php echo $link_text.'&hit_type=ajax'?>"><?php echo $hits['ajax'] ?></a></td>
 271                  <td class="right"><a href="<?php echo $link_text.'&hit_type=service'?>"><?php echo $hits['service'] ?></a></td>
 272                  <td class="right"><a href="<?php echo $link_text.'&hit_type=admin'?>"><?php echo $hits['admin'] ?></a></td>
 273                  <td class="right"><a href="<?php echo $link_text.'&agent_type=unknown'?>"><?php echo $hits['unknown'] ?></a></td>
 274                  <td class="lastcol right"><a href="<?php echo $link_text_total_day ?>"><?php echo array_sum($hits) ?></a></td>
 275          </tr>
 276          <?php
 277      }
 278  
 279      // Total numbers:
 280  
 281      $link_text_total = $admin_url.'?ctrl=stats&tab=hits&blog='.$blog;
 282      ?>
 283  
 284      <tr class="total">
 285      <td class="firstcol"><?php echo T_('Total') ?></td>
 286      <td class="right"><a href="<?php echo $link_text_total.'&hit_type=rss'?>"><?php echo $hits_total['rss'] ?></a></td>
 287      <td class="right"><a href="<?php echo $link_text_total.'&hit_type=standard&agent_type=robot'?>"><?php echo $hits_total['standard_robot'] ?></a></td>
 288      <td class="right"><a href="<?php echo $link_text_total.'&hit_type=standard&agent_type=browser'?>"><?php echo $hits_total['standard_browser'] ?></a></td>
 289      <td class="right"><a href="<?php echo $link_text_total.'&hit_type=ajax'?>"><?php echo $hits_total['ajax'] ?></a></td>
 290      <td class="right"><a href="<?php echo $link_text_total.'&hit_type=service'?>"><?php echo $hits_total['service'] ?></a></td>
 291      <td class="right"><a href="<?php echo $link_text_total.'&hit_type=admin'?>"><?php echo $hits_total['admin'] ?></a></td>
 292      <td class="right"><a href="<?php echo $link_text_total.'&agent_type=unknown'?>"><?php echo $hits_total['unknown'] ?></a></td>
 293      <td class="lastcol right"><a href="<?php echo $link_text_total ?>"><?php echo array_sum($hits_total) ?></a></td>
 294      </tr>
 295  
 296      </table>
 297  
 298      <!--[if IE]><?php echo get_icon( 'pixel' ); ?><![endif]-->
 299      <?php
 300  }
 301  ?>

title

Description

title

Description

title

Description

title

title

Body