b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/views/_stats_view.funcs.php - 503 lines - 13857 bytes - Summary - Text - Print

Description: This file implements the UI view for the browser hits summary. 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 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_view.funcs.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  /**
  30   * Initialize Results object for hits list
  31   *
  32   * @param object Results
  33   * @param array Params
  34   */
  35  function hits_results( & $Results, $params = array() )
  36  {
  37      $params = array_merge( array(
  38              'default_order' => '--D'
  39          ), $params );
  40  
  41      global $blog, $Session, $sess_ID;
  42      global $preset_results_title, $preset_referer_type, $preset_filter_all_url;
  43      global $hide_columns, $admin_url;
  44  
  45      $hide_columns = explode( ',', $hide_columns );
  46  
  47      $Results->title = isset( $preset_results_title ) ? $preset_results_title : T_('Recent hits').get_manual_link( 'recent-hits-list' );
  48  
  49      $param_prefix = 'results_'.$Results->param_prefix;
  50      $tab = get_param( 'tab' );
  51  
  52      $filter_presets = array();
  53      $filter_presets['all'] = array( T_('All'), isset( $preset_filter_all_url ) ? $preset_filter_all_url : $admin_url.'?ctrl=stats&amp;tab='.$tab.'&amp;blog='.$blog.'&amp;'.$param_prefix.'order='.$params['default_order'] );
  54      if( !isset( $preset_referer_type ) )
  55      {    // Show these presets only when referer type is not set
  56          $filter_presets['all_but_curr'] = array( T_('All but current session'), $admin_url.'?ctrl=stats&amp;tab='.$tab.'&amp;blog='.$blog.'&amp;sess_ID='.$Session->ID.'&amp;exclude=1&amp;'.$param_prefix.'order='.$params['default_order'] );
  57          $filter_presets['direct_hits'] = array( T_('Direct hits'), $admin_url.'?ctrl=stats&amp;agent_type=browser&amp;tab='.$tab.'&amp;blog='.$blog.'&amp;referer_type=direct&amp;exclude=0&amp;'.$param_prefix.'order='.$params['default_order'] );
  58          $filter_presets['refered_hits'] = array( T_('Refered hits'), $admin_url.'?ctrl=stats&amp;agent_type=browser&amp;tab='.$tab.'&amp;blog='.$blog.'&amp;referer_type=referer&amp;exclude=0&amp;'.$param_prefix.'order='.$params['default_order'] );
  59      }
  60  
  61      $Results->filter_area = array(
  62          'callback' => 'filter_hits',
  63          'url_ignore' => $param_prefix.'page,exclude,sess_ID,remote_IP',
  64          'presets' => $filter_presets
  65          );
  66  
  67      if( $sess_ID == NULL )
  68      {
  69          $session_link = '%stat_session_hits( #sess_ID#, #sess_ID# )%';
  70      }
  71      else
  72      {
  73          $session_link = '<a href="?ctrl=stats&amp;tab='.$tab.'&amp;blog='.$blog.'" title="'.T_( 'Show all sessions' ).'">$sess_ID$</a>';
  74      }
  75  
  76      $Results->cols[] = array(
  77              'th' => T_('Session'),
  78              'order' => 'hit_sess_ID, hit_ID',
  79              'td_class' => 'right compact_data',
  80              'td' => $session_link,
  81          );
  82  
  83      $Results->cols[] = array(
  84              'th' => T_('User'),
  85              'order' => 'user_login, hit_ID',
  86              'td_class' => 'shrinkwrap compact_data',
  87              'td' => '%stat_session_login( #user_login# )%',
  88          );
  89  
  90      $Results->cols[] = array(
  91              'th' => T_('Date Time'),
  92              'order' => 'hit_ID',
  93              'default_dir' => 'D',
  94              'td_class' => 'timestamp compact_data',
  95              'td' => '%mysql2localedatetime_spans( #hit_datetime#, "M-d" )%',
  96          );
  97  
  98      $Results->cols[] = array(
  99              'th' => T_('Agent'),
 100              'order' => 'hit_agent_type, hit_ID',
 101              'td_class' => 'shrinkwrap compact_data',
 102              'td' => '$hit_agent_type$',
 103              'extra' => array ( 'style' => 'background-color: %hit_agent_type_color( "#hit_agent_type#" )%;',
 104              'format_to_output'    => false)
 105          );
 106  
 107      $Results->cols[] = array(
 108              'th' => T_('Device'),
 109              'order' => 'sess_device, hit_ID',
 110              'td_class' => 'shrinkwrap compact_data',
 111              'td' => '$sess_device$',
 112              'extra' => array ( 'style' => 'background-color: %hit_device_color( "#sess_device#" )%;', 'format_to_output' => false )
 113          );
 114  
 115      if( !in_array( 'referer', $hide_columns ) )
 116      { // Referer Type & Domain
 117          $Results->cols[] = array(
 118                  'th_group' => T_('Referer'),
 119                  'th' => T_('Type'),
 120                  'order' => 'hit_referer_type, hit_ID',
 121                  'td_class' => 'shrinkwrap compact_data',
 122                  'td' => '$hit_referer_type$',
 123                  'extra' => array ( 'style' => 'background-color: %hit_referer_type_color( "#hit_referer_type#" )%;',
 124                      'format_to_output' => false )
 125              );
 126  
 127          $Results->cols[] = array(
 128                  'th_group' => T_('Referer'),
 129                  'th' => T_('Domain'),
 130                  'order' => 'dom_name, hit_ID',
 131                  'td_class' => 'nowrap compact_data',
 132                  'td' => '<a href="$hit_referer$">$dom_name$</a>',
 133              );
 134      }
 135  
 136      // Keywords:
 137      $Results->cols[] = array(
 138              'th' => T_('Search keywords'),
 139              'order' => 'hit_keyphrase, hit_ID',
 140              'td' => '%stats_search_keywords( #hit_keyphrase#, 45 )%',
 141              'td_class' => 'compact_data'
 142          );
 143  
 144      // Serp Rank:
 145      $Results->cols[] = array(
 146              'th' => T_('SR'),
 147              'th_title' => T_('Serp rank'),
 148              'order' => 'hit_serprank, hit_ID',
 149              'td_class' => 'center compact_data',
 150              'td' => '$hit_serprank$',
 151          );
 152  
 153      $Results->cols[] = array(
 154              'th' => T_('Goal'),
 155              'order' => 'goal_name, hit_ID',
 156              'default_dir' => 'D',
 157              'td' => '$goal_name$',
 158              'td_class' => 'compact_data'
 159          );
 160  
 161      $Results->cols[] = array(
 162              'th' => T_('Blog'),
 163              'order' => 'hit_blog_ID, hit_ID',
 164              'td' => '$blog_shortname$',
 165              'td_class' => 'compact_data'
 166          );
 167      $Results->cols[] = array(
 168              'th' => T_('Hit type'),
 169              'order' => 'hit_type, hit_ID',
 170              'td_class' => 'shrinkwrap compact_data',
 171              'td' => '$hit_type$',
 172              'extra' => array (    'style'                => 'background-color: %hit_type_color( "#hit_type#" )%',
 173                                  'format_to_output'    => false)
 174          );
 175      // Requested URI (linked to blog's baseurlroot+URI):
 176      $Results->cols[] = array(
 177              'th' => T_('Requested URI'),
 178              'order' => 'hit_uri, hit_ID',
 179              'td' => '%stats_format_req_URI( #hit_blog_ID#, #hit_uri#, 40, #hit_disp#, #hit_ctrl#, #hit_action# )%',
 180              'td_class' => 'compact_data'
 181          );
 182      $Results->cols[] = array(
 183              'th' => T_('Resp Code'),
 184              'order' => 'hit_response_code, hit_ID',
 185              'td' => '$hit_response_code$',
 186              'td_class' => '%hit_response_code_class( #hit_response_code# )% shrinkwrap compact_data'
 187          );
 188  
 189      $Results->cols[] = array(
 190              'th' => T_('Remote IP'),
 191              'order' => 'hit_remote_addr, hit_ID',
 192              'td' => '%disp_clickable_log_IP( #hit_remote_addr# )%',
 193              'td_class' => 'compact_data'
 194          );
 195  }
 196  
 197  
 198  /**
 199   * Callback to add filters on top of the result set
 200   *
 201   * @param Form
 202   */
 203  function filter_hits( & $Form )
 204  {
 205      global $referer_type_color, $referer_type_array;
 206      global $agent_type_color, $agent_type_array;
 207      global $user_devices_color, $user_devices;
 208      global $hit_type_color, $hit_type_array;
 209      global $datestart, $datestop;
 210      global $preset_referer_type, $preset_agent_type;
 211  
 212      $Form->checkbox_basic_input( 'exclude', get_param('exclude'), T_('Exclude').' &mdash; ' );
 213      $Form->text_input( 'sess_ID', get_param('sess_ID'), 15, T_('Session ID'), '', array( 'maxlength'=>20 ) );
 214      $Form->text_input( 'remote_IP', get_param('remote_IP'), 15, T_('Remote IP'), '', array( 'maxlength'=>23 ) );
 215  
 216      $Form->date_input( 'datestartinput', $datestart, T_('From date') );
 217      $Form->date_input( 'datestopinput', $datestop, T_('To date') );
 218      
 219      if( !isset( $preset_agent_type ) )
 220      {
 221          $Form->select_input_array( 'agent_type', get_param('agent_type'), $agent_type_array, 'Agent type', '', array('force_keys_as_values' => true, 'background_color' => $agent_type_color) );
 222      }
 223  
 224      $devices_array = array_keys( $user_devices );
 225      $devices_array = array_merge(
 226              array( '0' => T_('All') ),
 227              array_combine( $devices_array, $devices_array ),
 228              array( 'other' => T_('Other') )
 229          );
 230      $Form->select_input_array( 'device', get_param('device'), $devices_array , 'Device', '', array('force_keys_as_values' => true, 'background_color' => $user_devices_color) );
 231  
 232      if( !isset( $preset_referer_type ) )
 233      {
 234          $Form->select_input_array( 'referer_type', get_param('referer_type'), $referer_type_array, 'Referer type', '', array('force_keys_as_values' => true, 'background_color' => $referer_type_color) );
 235      }
 236      $Form->select_input_array( 'hit_type', get_param('hit_type'), $hit_type_array, 'Hit type', '', array('force_keys_as_values' => true, 'background_color' => $hit_type_color) );
 237  
 238      $Form->text_input( 'reqURI', get_param('reqURI'), 15, T_('Requested URI'), '', array( 'maxlength'=>250 ) );
 239  }
 240  
 241  
 242  /**
 243   * Helper function for "Requested URI" column
 244   * @param integer Blog ID
 245   * @param string Requested URI
 246   * @param integer Output string lenght
 247   * @param string Display
 248   * @param string Controller
 249   * @return string
 250   */
 251  function stats_format_req_URI( $hit_blog_ID, $hit_uri, $max_len = 40, $hit_disp = NULL, $hit_ctrl = NULL, $hit_action = NULL)
 252  {
 253      if( !empty( $hit_blog_ID ) )
 254      {
 255          $BlogCache = & get_BlogCache();
 256          $tmp_Blog = & $BlogCache->get_by_ID( $hit_blog_ID );
 257          $full_url = $tmp_Blog->get_baseurl_root().$hit_uri;
 258      }
 259      else
 260      {
 261          $full_url = $hit_uri;
 262      }
 263  
 264      $int_search_uri = urldecode($hit_uri);
 265      if( ( evo_strpos( $int_search_uri , '?s=' ) !== false )
 266       || ( evo_strpos( $int_search_uri , '&s=' ) !== false ) )
 267      {    // This is an internal search:
 268          preg_match( '~[?&]s=([^&#]*)~', $int_search_uri, $res );
 269          $hit_uri = 'Internal search : '.$res[1];
 270      }
 271      elseif( evo_strlen($hit_uri) > $max_len )
 272      {
 273          $hit_uri = '...'.evo_substr( $hit_uri, -$max_len );
 274      }
 275  
 276      if( $hit_disp != NULL || $hit_ctrl != NULL || $hit_action != NULL)
 277      {
 278          $hit_uri = '';
 279  
 280          if($hit_disp != NULL)
 281          {
 282              $hit_uri = '[disp=<a href="'.$full_url.'">'.$hit_disp.'</a>]';
 283          }
 284          if($hit_ctrl != NULL)
 285          {
 286              $hit_uri =$hit_uri.' [ctrl=<a href="'.$full_url.'">'.$hit_ctrl.'</a>]';
 287          }
 288          if($hit_action != NULL)
 289          {
 290              $hit_uri =$hit_uri.' [action=<a href="'.$full_url.'">'.$hit_action.'</a>]';
 291          }
 292  
 293  
 294          return $hit_uri;
 295      }
 296  
 297      return '<a href="'.$full_url.'">'.$hit_uri.'</a>';
 298  }
 299  
 300  
 301  /**
 302   * display avatar and login linking to sessions list for user
 303   *
 304   * @param mixed $login
 305   */
 306  function stat_session_login( $login )
 307  {
 308      if( empty($login) )
 309      {
 310          return '<span class="note">'.T_('Anon.').'</span>';
 311      }
 312  
 313      return get_user_identity_link( $login, NULL, 'admin' );
 314  }
 315  
 316  
 317  /**
 318   * Display session hits
 319   *
 320   * @param string session ID
 321   * @param string link text
 322   */
 323  function stat_session_hits( $sess_ID,  $link_text )
 324  {
 325      global $blog;
 326      return '<strong><a href="?ctrl=stats&tab='.get_param( 'tab' ).'&colselect_submit=Filter+list&sess_ID='.$sess_ID.'&remote_IP=&blog='.$blog.'">'.$link_text.'</a></strong>';
 327  }
 328  
 329  
 330  /**
 331   * Display clickable log IP address
 332   *
 333   * @param string remote adress IP
 334   */
 335  function disp_clickable_log_IP( $hit_remote_addr )
 336  {
 337      global $current_User, $blog;
 338      static $perm = NULL;
 339  
 340      if( empty( $perm ) )
 341      {
 342          $perm = $current_User->check_perm( 'stats', 'view' );
 343      }
 344  
 345      if( $perm == true )
 346      {
 347          return '<a href="?ctrl=stats&tab='.get_param( 'tab' ).'&colselect_submit=Filter+list&sess_ID=&remote_IP='.$hit_remote_addr.'&blog='.$blog.'">'.$hit_remote_addr.'</a>';
 348      }
 349      else
 350      {
 351          return "$hit_remote_addr";
 352      }
 353  
 354  }
 355  
 356  
 357  /**
 358   * Display color referer
 359   *
 360   * @param hit referer type
 361   */
 362  function disp_color_referer( $hit_referer_type )
 363  {
 364      global $referer_type_color;
 365      if(!empty ($referer_type_color[$hit_referer_type]))
 366      {
 367          return '<span style="background-color: #'.$referer_type_color[$hit_referer_type].'" >'.$hit_referer_type.'</span>';
 368      }
 369      else
 370      {
 371          return "$hit_referer_type";
 372      }
 373  
 374  }
 375  
 376  /**
 377   * Display color agent type
 378   *
 379   * @param hit agent type
 380   */
 381  function disp_color_agent( $hit_agent_type )
 382  {
 383      global $agent_type_color;
 384      if(!empty ($agent_type_color[$hit_agent_type]))
 385      {
 386          return '<span style="background-color: #'.$agent_type_color[$hit_agent_type].'" >'.$hit_agent_type.'</span>';
 387      }
 388      else
 389      {
 390          return "$hit_agent_type";
 391      }
 392  
 393  }
 394  
 395  /**
 396   * Generate html response code class
 397   * @param integer response code
 398   * @return string class
 399   */
 400  function hit_response_code_class($hit_response_code)
 401  {
 402      $class = '';
 403  
 404      if($hit_response_code >= 200 && $hit_response_code < 300)
 405      {
 406          $class =  "code_2xx";
 407      }
 408      if($hit_response_code >= 300 && $hit_response_code < 400)
 409      {
 410          $class =  "code_3xx";
 411      }
 412  
 413      if($hit_response_code == 304)
 414      {
 415          $class =  "code_304";
 416      }
 417  
 418      if ($hit_response_code >= 400)
 419      {
 420          $class =  "code_4xx";
 421      }
 422  
 423  
 424      return $class;
 425  }
 426  
 427  
 428  
 429  /**
 430   * Generate color
 431   * @param string hit_type
 432   * @return string color in hex format #FFFFFF
 433   */
 434  function hit_type_color($hit_type)
 435  {
 436      global $hit_type_color;
 437      $color = '#FFFFFF';
 438  
 439      if( ! empty ( $hit_type_color[$hit_type] ) )
 440      {
 441          $color ='#'.$hit_type_color[$hit_type];
 442      }
 443  
 444      return $color;
 445  }
 446  
 447  
 448  /**
 449   * Generate color
 450   * @param string hit_agent_type
 451   * @return string color in hex format #FFFFFF
 452   */
 453  function hit_agent_type_color($hit_agent_type)
 454  {
 455      global $agent_type_color;
 456      $color = '#FFFFFF';
 457  
 458      if( ! empty ( $agent_type_color[$hit_agent_type] ) )
 459      {
 460          $color ='#'.$agent_type_color[$hit_agent_type];
 461      }
 462  
 463      return $color;
 464  }
 465  
 466  
 467  /**
 468   * Generate color
 469   * @param string hit_device
 470   * @return string color in hex format #FFFFFF
 471   */
 472  function hit_device_color( $hit_device )
 473  {
 474      global $user_devices_color;
 475      $color = '#FFFFFF';
 476  
 477      if( !empty( $user_devices_color[ $hit_device ] ) )
 478      {
 479          $color ='#'.$user_devices_color[ $hit_device ];
 480      }
 481  
 482      return $color;
 483  }
 484  
 485  
 486  /**
 487   * Generate color
 488   * @param string hit_referer_type
 489   * @return string color in hex format #FFFFFF
 490   */
 491  function hit_referer_type_color($hit_referer_type)
 492  {
 493      global $referer_type_color;
 494      $color = '#FFFFFF';
 495  
 496      if( ! empty ( $referer_type_color[$hit_referer_type] ) )
 497      {
 498          $color ='#'.$referer_type_color[$hit_referer_type];
 499      }
 500  
 501      return $color;
 502  }
 503  ?>

title

Description

title

Description

title

Description

title

title

Body