b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/views/_stats_search_keywords.view.php - 291 lines - 8995 bytes - Summary - Text - Print

Description: This file implements the UI view for the referering searches 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 referering searches 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_search_keywords.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  load_class( '/sessions/model/_goal.class.php', 'Goal' );
  34  load_funcs('/cron/_cron.funcs.php');
  35  
  36  global $blog, $admin_url, $rsc_url, $goal_ID, $localtimenow;
  37  global $datestartinput, $datestart, $datestopinput, $datestop;
  38  
  39  if( param_date( 'datestartinput', T_('Invalid date'), false,  NULL ) !== NULL )
  40  {    // We have a user provided localized date:
  41      memorize_param( 'datestart', 'string', NULL, trim(form_date($datestartinput)) );
  42  }
  43  else
  44  {    // We may have an automated param transmission date:
  45      param( 'datestart', 'string', '', true );
  46  }
  47  if( param_date( 'datestopinput', T_('Invalid date'), false, NULL ) !== NULL )
  48  {    // We have a user provided localized date:
  49      memorize_param( 'datestop', 'string', NULL, trim(form_date($datestopinput)) );
  50  }
  51  else
  52  {    // We may have an automated param transmission date:
  53      param( 'datestop', 'string', '', true );
  54  }
  55  //pre_dump( $datestart, $datestop );
  56  
  57  if( $current_User->check_perm( 'stats', 'view' ) )
  58  {    // Permission to view stats for ALL blogs:
  59      param( 'goal_ID', 'integer', 0, true );
  60      $goal_name = param( 'goal_name', 'string', NULL, true );
  61  }
  62  else
  63  {
  64      $goal_ID = 0;
  65      $goal_name = NULL;
  66  }
  67  
  68  $split_engines = param( 'split_engines', 'integer', 0, true );
  69  
  70  if( param_errors_detected() )
  71  {
  72      $sql = 'SELECT 0 AS count';
  73      $sql_count = 0;
  74      $total = 0;
  75  }
  76  else
  77  {
  78      // Extract keyphrases from the hitlog:
  79      keyphrase_job();
  80  
  81      $SQL = new SQL();
  82      if( empty( $goal_ID ) && empty($goal_name)  )
  83      {    // We're not restricting to one or more Goals, get ALL possible keyphrases:
  84          $SQL->FROM( 'T_track__keyphrase INNER JOIN T_hitlog ON keyp_ID = hit_keyphrase_keyp_ID' );
  85          // Date param applies to serach hit
  86          if( !empty($datestart) )
  87          {
  88              $SQL->WHERE_and( 'T_hitlog.hit_datetime >= '.$DB->quote($datestart.' 00:00:00') );
  89          }
  90          if( !empty($datestop) )
  91          {
  92              $SQL->WHERE_and( 'T_hitlog.hit_datetime <= '.$DB->quote($datestop.' 23:59:59') );
  93          }
  94      }
  95      else
  96      {    // We ARE restricting to a Goal, start off with IPs and Sessions IDs that hit that goal
  97          // then find marching hits
  98          // then keywords
  99          // fp> Note: so far we only join on remote IP because MySQL can only use a single index. Solution: probably UNION 2 results
 100          // INNER JOIN T_hitlog ON (goalhit_hit.hit_sess_ID = T_hitlog.hit_sess_ID OR goalhit_hit.hit_remote_addr = T_hitlog.hit_remote_addr )
 101          $SQL->FROM( 'T_track__goalhit INNER JOIN T_hitlog AS goalhit_hit ON ghit_hit_ID = goalhit_hit.hit_ID
 102                                  INNER JOIN T_hitlog ON goalhit_hit.hit_remote_addr = T_hitlog.hit_remote_addr
 103                                  INNER JOIN T_track__keyphrase ON T_hitlog.hit_keyphrase_keyp_ID = keyp_ID' );
 104          if( !empty( $goal_ID ) )
 105          {
 106              $SQL->WHERE( 'ghit_goal_ID = '.$goal_ID );
 107          }
 108          else
 109          {
 110              $SQL->FROM_add( 'INNER JOIN T_track__goal ON goal_ID = ghit_goal_ID' );
 111              $SQL->WHERE_and( 'goal_name LIKE '.$DB->quote($goal_name.'%') );
 112          }
 113  
 114          // Date param applies to goal hit
 115          if( !empty($datestart) )
 116          {
 117              $SQL->WHERE_and( 'goalhit_hit.hit_datetime >= '.$DB->quote($datestart.' 00:00:00') );
 118          }
 119          if( !empty($datestop) )
 120          {
 121              $SQL->WHERE_and( 'goalhit_hit.hit_datetime <= '.$DB->quote($datestop.' 23:59:59') );
 122          }
 123      }
 124      $SQL->WHERE_and( 'hit_agent_type = "browser"' );
 125      if( $split_engines )
 126      {
 127          $SQL->GROUP_BY( 'keyp_ID, T_hitlog.hit_referer_dom_ID' );
 128      }
 129      else
 130      {
 131          $SQL->GROUP_BY( 'keyp_ID' );
 132      }
 133  
 134      if( ! empty($blog) )
 135      {
 136          $SQL->WHERE_and( 'T_hitlog.hit_blog_ID = '.$blog );
 137      }
 138  
 139      // COUNT:
 140      $SQL->SELECT( 'keyp_ID' );
 141      if( empty( $goal_ID ) && empty($goal_name) )
 142      {    // We're not restricting to a Goal
 143          $SQL->SELECT_add( ', COUNT(DISTINCT hit_remote_addr) as count' );
 144      }
 145      else
 146      { // We ARE retsrticting to a Goal
 147          $SQL->SELECT_add( ', COUNT(DISTINCT goalhit_hit.hit_ID, T_hitlog.hit_remote_addr) as count' );
 148      }
 149      $vars = $DB->get_row( 'SELECT COUNT(keyp_ID) AS count, SUM(count) AS total
 150                                                      FROM ('.$SQL->get().') AS dummy', OBJECT, 0, 'Count rows + total for stats' );
 151      $sql_count = (int)$vars->count;
 152      $total = (int)$vars->total;
 153  
 154      // DATA:
 155      $SQL->SELECT_add( ', keyp_phrase' );
 156      $SQL->SELECT_add( ', keyp_count_refered_searches, keyp_count_internal_searches' );
 157  
 158      if( $split_engines )
 159      {
 160          $SQL->SELECT_add( ', dom_name, T_hitlog.hit_referer ' );
 161          $SQL->FROM_add( 'LEFT JOIN T_basedomains ON dom_ID = T_hitlog.hit_referer_dom_ID' );
 162          $SQL->ORDER_BY( '*, keyp_phrase, dom_name' );
 163      }
 164      else
 165      {
 166          $SQL->ORDER_BY( '*, keyp_phrase' );
 167      }
 168      $sql = $SQL->get();
 169  }
 170  
 171  // Create result set:
 172  $Results = new Results( $sql, 'keywords_', $split_engines ? '--D' : '-D' , NULL, $sql_count );
 173  
 174  $Results->title = T_('Keyphrases').get_manual_link( 'search-keywords-list' );
 175  
 176  /**
 177   * Callback to add filters on top of the result set
 178   *
 179   * @param Form
 180   */
 181  function filter_keyphrases( & $Form )
 182  {
 183      global $current_User, $datestart, $datestop;
 184  
 185      $Form->date_input( 'datestartinput', $datestart, T_('From') );
 186      $Form->date_input( 'datestopinput', $datestop, T_('to') );
 187  
 188      if( $current_User->check_perm( 'stats', 'view' ) )
 189      {    // Permission to view stats for ALL blogs:
 190          global $goal_ID;
 191          $GoalCache = & get_GoalCache();
 192          $GoalCache->load_all();
 193          $Form->select_object( 'goal_ID', $goal_ID, $GoalCache, T_('Goal'), '', true );
 194      }
 195  
 196      $Form->text_input( 'goal_name', get_param('goal_name'), 20, T_('Goal names starting with'), '', array( 'maxlength'=>50 ) );
 197  
 198       $Form->checkbox_basic_input( 'split_engines', get_param('split_engines'), /* TRANS: split search engines in results table */ T_('Split search engines') );
 199  }
 200  $today = date( 'Y-m-d', $localtimenow );
 201  $Results->filter_area = array(
 202      'callback' => 'filter_keyphrases',
 203      'url_ignore' => 'goal_ID,datestartinput,datestart,datestopinput,datestop,goal_name,split_engines',
 204      'presets' => array(
 205          'all' => array( T_('All'), '?ctrl=stats&amp;tab=refsearches&amp;tab3=keywords&amp;blog='.$blog ),
 206          'today' => array( T_('Today'), '?ctrl=stats&amp;tab=refsearches&amp;tab3=keywords&amp;blog='.$blog
 207                                                                      .'&amp;datestart='.$today.'&amp;datestop='.$today ),
 208          )
 209      );
 210  
 211  if( $split_engines )
 212  {    // Search engine:
 213      $Results->cols[] = array(
 214              'th' => T_('Search engine'),
 215              'order' => 'dom_name',
 216              'td_class' => 'nowrap',
 217              'td' => '<a href="$hit_referer$">$dom_name$</a>',
 218              'total' => T_('TOTAL'),
 219          );
 220  }
 221  
 222  // Keywords:
 223  $Results->cols[] = array(
 224          'th' => T_('Search keywords'),
 225          'order' => 'keyp_phrase',
 226          'td' => '%stats_search_keywords( #keyp_phrase#, 45 )%',
 227          'total' => $sql_count.' '.T_('keyphrases'),
 228      );
 229  
 230  // Count:
 231  if( empty( $goal_ID ) )
 232  {    // We're not restricting to a Goal
 233      $Results->cols[] = array(
 234              'th' => T_('Unique IP hits'),
 235              'order' => 'count',
 236              'default_dir' => 'D',
 237              'td_class' => 'right',
 238              'td' => '$count$',
 239              'total_class' => 'right',
 240              'total' => $total,
 241          );
 242  }
 243  else
 244  { // We ARE retsrticting to a Goal
 245      $Results->cols[] = array(
 246              'th' => T_('Goal hits'),
 247              'order' => 'count',
 248              'default_dir' => 'D',
 249              'td_class' => 'right',
 250              'td' => '$count$',
 251              'total_class' => 'right',
 252              'total' => $total,
 253          );
 254  
 255  }
 256  
 257  $Results->cols[] = array(
 258          'th' => T_('Refered searches'),
 259          'order' => 'keyp_count_refered_searches',
 260          'td' => '$keyp_count_refered_searches$',
 261          'td_class' => 'nowrap right',
 262  );
 263  
 264  $Results->cols[] = array(
 265          'th' => T_('Internal searches'),
 266          'order' => 'keyp_count_internal_searches',
 267          'td' => '$keyp_count_internal_searches$',
 268          'td_class' => 'nowrap right',
 269  );
 270  
 271  $Results->cols[] = array(
 272          'th' => '%',
 273          'order' => 'count',
 274          'default_dir' => 'D',
 275          'td_class' => 'right',
 276          'td' => '%percentage( #count#, '.$total.' )%',
 277          'total_class' => 'right',
 278          'total' => '100.0 %',
 279      );
 280  
 281  $Results->cols[] = array(
 282          'th' => T_('Cumulative'),
 283          'td_class' => 'right',
 284          'td' => '%addup_percentage( #count#, '.$total.' )%',
 285      );
 286  
 287  $Results->global_icon( T_('Reset counters'), 'file_delete', regenerate_url( 'action', 'action=reset_counters' ), T_('Reset counters').' &raquo;', 3, 4  );
 288  // Display results:
 289  $Results->display();
 290  
 291  ?>

title

Description

title

Description

title

Description

title

title

Body