b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/views/_stats_robots.view.php - 175 lines - 5068 bytes - Text - Print

Description: This file implements the UI view for the robot stats. This file is part of the evoCore framework - {@link http://evocore.net/} See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the UI view for the robot stats.
   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_robots.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  /**
  29   * View funcs
  30   */
  31  require_once dirname(__FILE__).'/_stats_view.funcs.php';
  32  
  33  
  34  global $blog, $admin_url, $rsc_url, $AdminUI, $agent_type_color;
  35  
  36  echo '<h2>'.T_('Hits from indexing robots / spiders / crawlers - Summary').get_manual_link( 'robots-hits-summary' ).'</h2>';
  37  
  38  echo '<p class="notes">'.T_('In order to be detected, robots must be listed in /conf/_stats.php.').'</p>';
  39  
  40  $SQL = new SQL();
  41  $SQL->SELECT( 'SQL_NO_CACHE COUNT(*) AS hits, EXTRACT(YEAR FROM hit_datetime) AS year,'
  42      . 'EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day' );
  43  $SQL->FROM( 'T_hitlog' );
  44  $SQL->WHERE( 'hit_agent_type = "robot"' );
  45  if( $blog > 0 )
  46  {
  47      $SQL->WHERE_and( 'hit_blog_ID = ' . $blog );
  48  }
  49  $SQL->GROUP_BY( 'year, month, day' );
  50  $SQL->ORDER_BY( 'year DESC, month DESC, day DESC' );
  51  $res_hits = $DB->get_results( $SQL->get(), ARRAY_A, 'Get robot summary' );
  52  
  53  
  54  /*
  55   * Chart
  56   */
  57  if( count($res_hits) )
  58  {
  59      $last_date = 0;
  60  
  61      $chart[ 'chart_data' ][ 0 ] = array();
  62      $chart[ 'chart_data' ][ 1 ] = array();
  63  
  64      $count = 0;
  65      foreach( $res_hits as $row_stats )
  66      {
  67          $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
  68          if( $last_date != $this_date )
  69          { // We just hit a new day, let's display the previous one:
  70                  $last_date = $this_date;    // that'll be the next one
  71                  $count ++;
  72                  array_unshift( $chart[ 'chart_data' ][ 0 ], date( locale_datefmt(), $last_date ) );
  73                  array_unshift( $chart[ 'chart_data' ][ 1 ], 0 );
  74          }
  75          $chart [ 'chart_data' ][1][0] = $row_stats['hits'];
  76      }
  77  
  78      array_unshift( $chart[ 'chart_data' ][ 0 ], '' );
  79      array_unshift( $chart[ 'chart_data' ][ 1 ], 'Robot hits' );    // Translations need to be UTF-8
  80  
  81      // Include common chart properties:
  82      require dirname(__FILE__).'/inc/_bar_chart.inc.php';
  83  
  84      $chart[ 'series_color' ] = array (
  85              $agent_type_color['robot'],
  86          );
  87  
  88  
  89      echo '<div class="center">';
  90      load_funcs('_ext/_swfcharts.php');
  91      DrawChart( $chart );
  92      echo '</div>';
  93  
  94  }
  95  
  96  
  97  
  98  // TOP INDEXING ROBOTS
  99  /* put this back when we have a CONCISE table of robots
 100  // Create result set:
 101  $SQL = new SQL();
 102  $SQL->SELECT( 'SQL_NO_CACHE COUNT(*) AS hit_count, agnt_signature' );
 103  $SQL->FROM( 'T_hitlog' );
 104  $SQL->WHERE( 'hit_agent_type = "robot"' );
 105  if( ! empty( $blog ) )
 106      $SQL->WHERE_and( 'hit_blog_ID = ' . $blog );
 107  $SQL->GROUP_BY( 'agnt_signature' );
 108  
 109  $CountSQL = new SQL();
 110  $CountSQL->SELECT( 'SQL_NO_CACHE COUNT( DISTINCT agnt_signature )' );
 111  $CountSQL->FROM( $SQL->get_from( '' ) );
 112  $CountSQL->WHERE( $SQL->get_where( '' ) );
 113  
 114  $Results = new Results( $SQL->get(), 'topidx', '-D', 20, $CountSQL->get() );
 115  
 116  $CountSQL->SELECT( 'SQL_NO_CACHE COUNT(*)' );
 117  $total_hit_count = $DB->get_var( $CountSQL->get() );
 118  
 119  $Results->title = T_('Top Indexing Robots');
 120  
 121  /**
 122   * Helper function to translate agnt_signature to a "human-friendly" version from {@link $user_agents}.
 123   * @return string
 124   *
 125  function translate_user_agent( $agnt_signature )
 126  {
 127      global $user_agents;
 128  
 129      $html_signature = htmlspecialchars( $agnt_signature );
 130      $format = '<span title="'.$html_signature.'">%s</span>';
 131  
 132      foreach ($user_agents as $curr_user_agent)
 133      {
 134          if( strpos($agnt_signature, $curr_user_agent[1]) !== false )
 135          {
 136              return sprintf( $format, htmlspecialchars($curr_user_agent[2]) );
 137          }
 138      }
 139  
 140      if( ( $browscap = @get_browser( $agnt_signature ) ) && $browscap->browser != 'Default Browser' )
 141      {
 142          return sprintf( $format, htmlspecialchars( $browscap->browser ) );
 143      }
 144  
 145      return $html_signature;
 146  }
 147  
 148  // User agent:
 149  $Results->cols[] = array(
 150          'th' => T_('Robot'),
 151          'order' => 'agnt_signature',
 152          'td' => '%translate_user_agent(\'$agnt_signature$\')%',
 153      );
 154  
 155  // Hit count:
 156  $Results->cols[] = array(
 157          'th' => T_('Hit count'),
 158          'order' => 'hit_count',
 159          'td_class' => 'right',
 160          'td' => '$hit_count$',
 161      );
 162  
 163  // Hit %
 164  $Results->cols[] = array(
 165          'th' => T_('Hit %'),
 166          'order' => 'hit_count',
 167          'td_class' => 'right',
 168          'td' => '%percentage( #hit_count#, '.$total_hit_count.' )%',
 169      );
 170  
 171  // Display results:
 172  $Results->display();
 173  */
 174  
 175  ?>

title

Description

title

Description

title

Description

title

title

Body