b2evolution PHP Cross Reference Blogging Systems

Source: /inc/sessions/stats.ctrl.php - 420 lines - 12280 bytes - Text - Print

Description: This file implements the UI controller for browsing the (hitlog) statistics. This file is part of the b2evolution/evocms project - {@link http://b2evolution.net/}. See also {@link http://sourceforge.net/projects/evocms/}.

   1  <?php
   2  /**
   3   * This file implements the UI controller for browsing the (hitlog) statistics.
   4   *
   5   * This file is part of the b2evolution/evocms project - {@link http://b2evolution.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   * @license http://b2evolution.net/about/license.html GNU General Public License (GPL)
  11   *
  12   * {@internal Open Source relicensing agreement:
  13   * Vegar BERG GULDAL grants Francois PLANQUE the right to license
  14   * Vegar BERG GULDAL's contributions to this file and the b2evolution project
  15   * under any OSI approved OSS license (http://www.opensource.org/licenses/).
  16   * }}
  17   *
  18   * @package admin
  19   *
  20   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}
  21   * @author blueyed: Daniel HAHLER
  22   * @author fplanque: Francois PLANQUE
  23   * @author vegarg: Vegar BERG GULDAL
  24   *
  25   * @version $Id: stats.ctrl.php 6136 2014-03-08 07:59:48Z manuel $
  26   */
  27  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  28  
  29  load_class('sessions/model/_hitlist.class.php', 'Hitlist' );
  30  load_class('sessions/model/_internal_searches.class.php', 'Internalsearches' );
  31  load_funcs('sessions/model/_hitlog.funcs.php');
  32  
  33  /**
  34   * @var User
  35   */
  36  global $current_User;
  37  
  38  global $dispatcher;
  39  
  40  global $collections_Module, $DB;
  41  param_action();
  42  
  43  // Do we have permission to view all stats (aggregated stats) ?
  44  $perm_view_all = $current_User->check_perm( 'stats', 'view' );
  45  
  46  // We set the default to -1 so that blog=0 will make its way into regenerate_url()s whenever watching global stats.
  47  memorize_param( 'blog', 'integer', -1 );
  48  
  49  $tab = param( 'tab', 'string', 'summary', true );
  50  $tab3 = param( 'tab3', 'string', '', true );
  51  
  52  param( 'action', 'string' );
  53  
  54  if( ($tab=='refsearches') && ($tab3=='intsearches') ) 
  55  {
  56  
  57      if( param( 'isrch_ID', 'integer', '', true) )
  58      { 
  59          $ISCache = & get_InternalSearchesCache();
  60          if( ($edited_intsearch = & $ISCache->get_by_ID( $isrch_ID, false )) === false )
  61          {    // We could not find the internal search to edit:
  62              unset( $edited_intsearch );
  63              forget_param( 'isrch_ID' );
  64              $Messages->add( sprintf( T_('Requested &laquo;%s&raquo; object does not exist any longer.'), T_('Internal Search') ), 'error' );
  65              $action = 'nil';
  66          }
  67      }
  68      
  69      switch( $action )
  70      {
  71      
  72          case 'delete':
  73              // Delete file type:
  74      
  75              // Check that this action request is not a CSRF hacked request:
  76              $Session->assert_received_crumb( 'internalsearches' );
  77      
  78              // Check permission:
  79              $current_User->check_perm( 'stats', 'edit', true );
  80      
  81              // Make sure we got an isrch_ID:
  82              param( 'isrch_ID', 'integer', true );
  83              
  84                  
  85                  $msg = sprintf( T_('Internal search &laquo;%s&raquo; deleted.'), $edited_intsearch->dget('name') );
  86                  $edited_intsearch->dbdelete( true );
  87                  unset( $edited_intsearch );
  88                  forget_param( 'isrch_ID' );
  89                  $Messages->add( $msg, 'success' );
  90                  // Redirect so that a reload doesn't write to the DB twice:
  91                  header_redirect( '?ctrl=stats&tab=refsearches&tab3=intsearches', 303 ); // Will EXIT
  92                  // We have EXITed already at this point!!
  93              break;
  94      
  95      }
  96      
  97  }
  98  else
  99  {
 100  
 101  if ($tab == 'domains' && $current_User->check_perm( 'stats', 'edit' ))
 102  {
 103      require_js( 'jquery/jquery.jeditable.js', 'rsc_url' );
 104  }
 105  
 106  if( $blog == 0 )
 107  {
 108      if( (!$perm_view_all) && isset($collections_Module) )
 109      {    // Find a blog we can view stats for:
 110          if( ! $selected = autoselect_blog( 'stats', 'view' ) )
 111          { // No blog could be selected
 112              $Messages->add( T_('Sorry, there is no blog you have permission to view stats for.'), 'error' );
 113              $action = 'nil';
 114          }
 115          elseif( set_working_blog( $selected ) )    // set $blog & memorize in user prefs
 116          {    // Selected a new blog:
 117              $BlogCache = & get_BlogCache();
 118              $Blog = & $BlogCache->get_by_ID( $blog );
 119          }
 120      }
 121  }
 122  
 123  switch( $action )
 124  {
 125      case 'changetype': // Change the type of a hit
 126          // Check permission:
 127          $current_User->check_perm( 'stats', 'edit', true );
 128  
 129          param( 'hit_ID', 'integer', true );      // Required!
 130          param( 'new_hit_type', 'string', true ); // Required!
 131  
 132          Hitlist::change_type( $hit_ID, $new_hit_type );
 133          $Messages->add( sprintf( T_('Changed hit #%d type to: %s.'), $hit_ID, $new_hit_type), 'success' );
 134          break;
 135  
 136  
 137      case 'prune': // PRUNE hits for a certain date
 138          // Check that this action request is not a CSRF hacked request:
 139          $Session->assert_received_crumb( 'stats' );
 140          
 141          // Check permission:
 142          $current_User->check_perm( 'stats', 'edit', true );
 143  
 144          param( 'date', 'integer', true ); // Required!
 145          if( $r = Hitlist::prune( $date ) )
 146          {
 147              $Messages->add( sprintf( /* TRANS: %s is a date */ T_('Deleted %d hits for %s.'), $r, date( locale_datefmt(), $date) ), 'success' );
 148          }
 149          else
 150          {
 151              $Messages->add( sprintf( /* TRANS: %s is a date */ T_('No hits deleted for %s.'), date( locale_datefmt(), $date) ), 'note' );
 152          }
 153          // Redirect so that a reload doesn't write to the DB twice:
 154          header_redirect( '?ctrl=stats', 303 ); // Will EXIT
 155          // We have EXITed already at this point!!
 156          break;
 157  
 158      case 'reset_counters':
 159  
 160          $current_User->check_perm( 'stats', 'edit', true );
 161  
 162          $sql = 'UPDATE T_track__keyphrase
 163                  SET keyp_count_refered_searches = 0,
 164                      keyp_count_internal_searches = 0';
 165          $DB->query( $sql, ' Reset keyphrases counters' );
 166          break;
 167  
 168  }
 169  }
 170  
 171  if( isset($collections_Module) )
 172  { // Display list of blogs:
 173      if( $perm_view_all )
 174      {
 175          $AdminUI->set_coll_list_params( 'stats', 'view', array( 'ctrl' => 'stats', 'tab' => $tab, 'tab3' => $tab3 ), T_('All'),
 176                          $dispatcher.'?ctrl=stats&amp;tab='.$tab.'&amp;tab3='.$tab3.'&amp;blog=0' );
 177      }
 178      else
 179      {    // No permission to view aggregated stats:
 180          $AdminUI->set_coll_list_params( 'stats', 'view', array( 'ctrl' => 'stats', 'tab' => $tab, 'tab3' => $tab3 ) );
 181      }
 182  }
 183  
 184  $AdminUI->breadcrumbpath_init();
 185  switch( $tab )
 186  {
 187      case 'summary':
 188          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 189          $AdminUI->breadcrumbpath_add( T_('Hits'), '?ctrl=stats&amp;blog=$blog$' );
 190          $AdminUI->breadcrumbpath_add( T_('Summary'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 191          if( empty($tab3) )
 192          {
 193              $tab3 = 'global';
 194          }
 195          switch( $tab3 )
 196          {
 197              case 'global':
 198                  $AdminUI->breadcrumbpath_add( T_('All'), '?ctrl=stats&amp;blog=$blog$&amp;tab='.$tab.'&amp;tab3='.$tab3 );
 199                  break;
 200  
 201              case 'browser':
 202                  $AdminUI->breadcrumbpath_add( T_('Browsers'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab.'&amp;tab3='.$tab3 );
 203                  break;
 204  
 205              case 'robot':
 206                  $AdminUI->breadcrumbpath_add( T_('Robots'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab.'&amp;tab3='.$tab3 );
 207                  break;
 208  
 209              case 'feed':
 210                  $AdminUI->breadcrumbpath_add( T_('RSS/Atom'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab.'&amp;tab3='.$tab3 );
 211                  break;
 212          }
 213          break;
 214  
 215      case 'other':
 216          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 217          $AdminUI->breadcrumbpath_add( T_('Hits'), '?ctrl=stats&amp;blog=$blog$' );
 218          $AdminUI->breadcrumbpath_add( T_('Direct hits'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 219          break;
 220  
 221      case 'hits':
 222          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 223          $AdminUI->breadcrumbpath_add( T_('Hits'), '?ctrl=stats&amp;blog=$blog$' );
 224          $AdminUI->breadcrumbpath_add( T_('All Hits'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 225          break;
 226  
 227      case 'referers':
 228          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 229          $AdminUI->breadcrumbpath_add( T_('Hits'), '?ctrl=stats&amp;blog=$blog$' );
 230          $AdminUI->breadcrumbpath_add( T_('Referred by other sites'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 231          break;
 232  
 233      case 'refsearches':
 234          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 235          $AdminUI->breadcrumbpath_add( T_('Hits'), '?ctrl=stats&amp;blog=$blog$' );
 236          $AdminUI->breadcrumbpath_add( T_('Incoming searches'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 237          if( empty($tab3) )
 238          {
 239              $tab3 = 'hits';
 240          }
 241          switch( $tab3 )
 242          {
 243              case 'hits':
 244                  // $AdminUI->breadcrumbpath_add( T_('Latest'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab.'&amp;tab3='.$tab3 );
 245                  break;
 246  
 247              case 'keywords':
 248                  $AdminUI->breadcrumbpath_add( T_('Searched keywords'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab.'&amp;tab3='.$tab3 );
 249                  break;
 250  
 251              case 'topengines':
 252                  $AdminUI->breadcrumbpath_add( T_('Top search engines'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab.'&amp;tab3='.$tab3 );
 253                  break;
 254                  
 255          }
 256          break;
 257  
 258      case 'domains':
 259          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 260          $AdminUI->breadcrumbpath_add( T_('Referring domains'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 261          break;
 262  
 263      case 'goals':
 264          $AdminUI->breadcrumbpath_add( T_('Analytics'), '?ctrl=stats&amp;blog=$blog$' );
 265          $AdminUI->breadcrumbpath_add( T_('Goal tracking'), '?ctrl=goals' );
 266          switch( $tab3 )
 267          {
 268              case 'hits':
 269                  $AdminUI->breadcrumbpath_add( T_('Goal hits'), '?ctrl=stats&amp;blog=$blog$&tab='.$tab );
 270                  break;
 271          }
 272          break;
 273  
 274  }
 275  
 276  $AdminUI->set_path( 'stats', $tab, $tab3 );
 277  
 278  if( in_array( $tab , array( 'hits', 'other', 'referers' ) ) ||
 279      ( $tab == 'refsearches' && in_array( $tab3 , array( 'hits', 'keywords' ) ) ) ||
 280      ( $tab == 'goals' && $tab3 == 'hits' ) )
 281  { // Load the data picker style for _stats_search_keywords.view.php and _stats_goalhits.view.php
 282      require_css( 'ui.datepicker.css' );
 283  }
 284  
 285  // Display <html><head>...</head> section! (Note: should be done early if actions do not redirect)
 286  $AdminUI->disp_html_head();
 287  
 288  // Display title, menu, messages, etc. (Note: messages MUST be displayed AFTER the actions)
 289  $AdminUI->disp_body_top();
 290  
 291  // Begin payload block:
 292  $AdminUI->disp_payload_begin();
 293  
 294  evo_flush();
 295  
 296  if( ($tab=="refsearches") && ($tab3=="intsearches") ) 
 297  {
 298      
 299      switch( $action )
 300      {
 301          case 'nil':
 302              // Do nothing
 303              break;
 304  
 305  
 306          case 'delete':
 307              // We need to ask for confirmation:
 308              $edited_Goal->confirm_delete(
 309                      sprintf( T_('Delete internal search item &laquo;%s&raquo;?'), $edited_intsearch->dget('keywords') ),
 310                      'internalsearch', $action, get_memorized( 'action' ) );
 311              /* no break */
 312          case 'new':
 313          case 'copy':
 314          case 'create':    // we return in this state after a validation error
 315          case 'create_new':    // we return in this state after a validation error
 316          case 'create_copy':    // we return in this state after a validation error
 317          case 'edit':
 318          case 'update':    // we return in this state after a validation error
 319              $AdminUI->disp_view( 'sessions/views/_internal_search.form.php' );
 320              break;
 321  
 322  
 323          default:
 324              // No specific request, list all file types:
 325              switch( $tab3 )
 326              {
 327                  case 'intsearches':
 328                      // Cleanup context:
 329                      forget_param( 'isrch_ID' );
 330                      // Display goals list:
 331                      $AdminUI->disp_view( 'sessions/views/_stats_internal_searches.view.php' );
 332                      break;
 333  
 334              }
 335  
 336      }
 337  
 338  } 
 339  else 
 340  {
 341      
 342  switch( $AdminUI->get_path(1) )
 343  {
 344      case 'summary':
 345          // Display VIEW:
 346          switch( $tab3 )
 347          {
 348              case 'browser':
 349                  $AdminUI->disp_view( 'sessions/views/_stats_browserhits.view.php' );
 350                  break;
 351  
 352              case 'robot':
 353                  $AdminUI->disp_view( 'sessions/views/_stats_robots.view.php' );
 354                  break;
 355  
 356              case 'feed':
 357                  $AdminUI->disp_view( 'sessions/views/_stats_syndication.view.php' );
 358                  break;
 359  
 360              case 'global':
 361              default:
 362                  $AdminUI->disp_view( 'sessions/views/_stats_summary.view.php' );
 363          }
 364          break;
 365  
 366      case 'other':
 367      case 'hits':
 368      case 'referers':
 369          // Display hits results table:
 370          hits_results_block();
 371          break;
 372  
 373      case 'refsearches':
 374          // Display VIEW:
 375          switch( $tab3 )
 376          {
 377              case 'hits':
 378                  // Display hits results table:
 379                  hits_results_block();
 380                  break;
 381  
 382              case 'keywords':
 383                  $AdminUI->disp_view( 'sessions/views/_stats_search_keywords.view.php' );
 384                  break;
 385  
 386              case 'topengines':
 387                  $AdminUI->disp_view( 'sessions/views/_stats_search_engines.view.php' );
 388                  break;
 389                  
 390              case 'intsearches':
 391                  $AdminUI->disp_view( 'sessions/views/_stats_internal_searches.view.php' );
 392                  break;
 393          }
 394          break;
 395  
 396      case 'domains':
 397          // Display VIEW:
 398          $AdminUI->disp_view( 'sessions/views/_stats_refdomains.view.php' );
 399          break;
 400  
 401      case 'goals':
 402          // Display VIEW for Goal HITS:
 403          switch( $tab3 )
 404          {
 405              case 'hits':
 406                  $AdminUI->disp_view( 'sessions/views/_stats_goalhits.view.php' );
 407                  break;
 408          }
 409          break;
 410  
 411  }
 412  }
 413  
 414  // End payload block:
 415  $AdminUI->disp_payload_end();
 416  
 417  // Display body bottom, debug info and close </html>:
 418  $AdminUI->disp_global_footer();
 419  
 420  ?>

title

Description

title

Description

title

Description

title

title

Body