[ Index ]
 

Code source de b2evolution 2.1.0-beta

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/blogs/inc/sessions/model/ -> _hitlog.funcs.php (source)

   1  <?php
   2  /**

   3   * This file implements functions for logging of hits and extracting stats.

   4   *

   5   * NOTE: the refererList() and stats_* functions are not fully functional ATM. I'll transform them into the Hitlog object during the next days. blueyed.

   6   *

   7   * This file is part of the evoCore framework - {@link http://evocore.net/}

   8   * See also {@link http://sourceforge.net/projects/evocms/}.

   9   *

  10   * @copyright (c)2003-2007 by Francois PLANQUE - {@link http://fplanque.net/}

  11   * Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.

  12   *

  13   * {@internal License choice

  14   * - If you have received this file as part of a package, please find the license.txt file in

  15   *   the same folder or the closest folder above for complete license terms.

  16   * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)

  17   *   then you must choose one of the following licenses before using the file:

  18   *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php

  19   *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php

  20   * }}

  21   *

  22   * {@internal Open Source relicensing agreement:

  23   * Daniel HAHLER grants Francois PLANQUE the right to license

  24   * Daniel HAHLER's contributions to this file and the b2evolution project

  25   * under any OSI approved OSS license (http://www.opensource.org/licenses/).

  26   * }}

  27   *

  28   * {@internal Origin:

  29   * This file was inspired by N C Young's Referer Script released in

  30   * the public domain on 07/19/2002. {@link http://ncyoung.com/entry/57}.

  31   * See also {@link http://ncyoung.com/demo/referer/}.

  32   * }}

  33   *

  34   * @package evocore

  35   *

  36   * {@internal Below is a list of authors who have contributed to design/coding of this file: }}

  37   * @author N C Young (nathan@ncyoung.com).

  38   * @author blueyed: Daniel HAHLER.

  39   * @author fplanque: Francois PLANQUE.

  40   * @author vegarg: Vegar BERG GULDAL.

  41   *

  42   * @version $Id: _hitlog.funcs.php,v 1.1 2007/06/25 11:00:59 fplanque Exp $

  43   */
  44  if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
  45  
  46  //get most linked to pages on site

  47  //select count(hit_uri) as count, hit_uri from T_hitlog group by hit_uri order by count desc

  48  
  49  /*if ($refererList)

  50  {

  51      print "referers:<br />";

  52      $ar = refererList($refererList,"global");

  53      print join("<br />",$ar);

  54  }

  55  

  56  if ($topRefererList)

  57  {

  58      print join("<br />",topRefererList($topRefererList,"global"));

  59  }

  60  */
  61  
  62  
  63  /**

  64   * @todo Transform to make this a stub for {@link $Hitlist}

  65   *

  66   * Extract stats

  67   */
  68  function refererList(
  69      $howMany = 5,
  70      $visitURL = '',
  71      $disp_blog = 0,
  72      $disp_uri = 0,
  73      $type = "'referer'",        // was: 'referer' normal refer, 'invalid', 'badchar', 'blacklist', 'rss', 'robot', 'search'
  74                                                      // new: 'search', 'blacklist', 'referer', 'direct', ('spam' but spam is not logged)

  75      $groupby = '',     // dom_name
  76      $blog_ID = '',
  77      $get_total_hits = false, // Get total number of hits (needed for percentages)
  78      $get_user_agent = false ) // Get the user agent
  79  {
  80      global $DB, $res_stats, $stats_total_hits, $ReqURI;
  81  
  82      if( strpos( $type, "'" ) !== 0 )
  83      { // no quote at position 0
  84          $type = "'".$type."'";
  85      }
  86  
  87      //if no visitURL, will show links to current page.

  88      //if url given, will show links to that page.

  89      //if url="global" will show links to all pages

  90      if (!$visitURL)
  91      {
  92          $visitURL = $ReqURI;
  93      }
  94  
  95      if( $groupby == '' )
  96      { // No grouping:
  97          $sql = "SELECT hit_ID, UNIX_TIMESTAMP(hit_datetime) AS hit_datetime, hit_referer, dom_name";
  98      }
  99      else
 100      { // group by
 101          if( $groupby == 'baseDomain' )
 102          { // compatibility HACK!
 103              $groupby = 'dom_name';
 104          }
 105          $sql = "SELECT COUNT(*) AS totalHits, hit_referer, dom_name";
 106      }
 107      if( $disp_blog )
 108      {
 109          $sql .= ", hit_blog_ID";
 110      }
 111      if( $disp_uri )
 112      {
 113          $sql .= ", hit_uri";
 114      }
 115      if( $get_user_agent )
 116      {
 117          $sql .= ", agnt_signature";
 118      }
 119  
 120      $sql_from_where = "
 121                FROM T_hitlog
 122               INNER JOIN T_useragents ON hit_agnt_ID = agnt_ID
 123                LEFT JOIN T_basedomains ON dom_ID = hit_referer_dom_ID
 124               WHERE hit_referer_type IN (".$type.")
 125                 AND agnt_type = 'browser'";
 126      if( !empty($blog_ID) )
 127      {
 128          $sql_from_where .= " AND hit_blog_ID = '$blog_ID'";
 129      }
 130      if ($visitURL != "global")
 131      {
 132          $sql_from_where .= " AND hit_uri = '".$DB->escape($visitURL, 0, 250)."'";
 133      }
 134  
 135      $sql .= $sql_from_where;
 136  
 137      if( $groupby == '' )
 138      { // No grouping:
 139          $sql .= " ORDER BY hit_ID DESC";
 140      }
 141      else
 142      { // group by
 143          $sql .= " GROUP BY $groupby ORDER BY totalHits DESC";
 144      }
 145      $sql .= " LIMIT $howMany";
 146  
 147      $res_stats = $DB->get_results( $sql, ARRAY_A );
 148  
 149      if( $get_total_hits )
 150      { // we need to get total hits
 151          $sql = "SELECT COUNT(*) ".$sql_from_where;
 152          $stats_total_hits = $DB->get_var( $sql );
 153      }
 154      else
 155      { // we're not getting total hits
 156          $stats_total_hits = 1;        // just in case some tries a percentage anyway (avoid div by 0)

 157      }
 158  
 159  }
 160  
 161  
 162  /*

 163   * stats_hit_ID(-)

 164   */
 165  function stats_hit_ID()
 166  {
 167      global $row_stats;
 168      echo $row_stats['visitID'];
 169  }
 170  
 171  /*

 172   * stats_hit_remote_addr(-)

 173   */
 174  function stats_hit_remote_addr()
 175  {
 176      global $row_stats;
 177      echo $row_stats['hit_remote_addr'];
 178  }
 179  
 180  /*

 181   * stats_time(-)

 182   */
 183  function stats_time( $format = '' )
 184  {
 185      global $row_stats;
 186      if( $format == '' )
 187          $format = locale_datefmt().' '.locale_timefmt();
 188      echo date_i18n( $format, $row_stats['hit_datetime'] );
 189  }
 190  
 191  
 192  /*

 193   * stats_total_hit_count(-)

 194   */
 195  function stats_total_hit_count()
 196  {
 197      global $stats_total_hits;
 198      echo $stats_total_hits;
 199  }
 200  
 201  
 202  /*

 203   * stats_hit_count(-)

 204   */
 205  function stats_hit_count( $disp = true )
 206  {
 207      global $row_stats;
 208      if( $disp )
 209          echo $row_stats['totalHits'];
 210      else
 211          return $row_stats['totalHits'];
 212  }
 213  
 214  
 215  /*

 216   * stats_hit_percent(-)

 217   */
 218  function stats_hit_percent(
 219      $decimals = 1,
 220      $dec_point = '.' )
 221  {
 222      global $row_stats, $stats_total_hits;
 223      $percent = $row_stats['totalHits'] * 100 / $stats_total_hits;
 224      echo number_format( $percent, $decimals, $dec_point, '' ).'&nbsp;%';
 225  }
 226  
 227  
 228  /*

 229   * stats_blog_ID(-)

 230   */
 231  function stats_blog_ID()
 232  {
 233      global $row_stats;
 234      echo $row_stats['hit_blog_ID'];
 235  }
 236  
 237  
 238  /*

 239   * stats_blog_name(-)

 240   */
 241  function stats_blog_name()
 242  {
 243      global $row_stats;
 244  
 245      $BlogCache = & get_Cache('BlogCache');
 246      $Blog = & $BlogCache->get_by_ID($row_stats['hit_blog_ID']);
 247  
 248      $Blog->disp('name');
 249  }
 250  
 251  
 252  /*

 253   * stats_referer(-)

 254   */
 255  function stats_referer( $before='', $after='', $disp_ref = true )
 256  {
 257      global $row_stats;
 258      $ref = trim($row_stats['hit_referer']);
 259      if( strlen($ref) > 0 )
 260      {
 261          echo $before;
 262          if( $disp_ref ) echo htmlentities( $ref );
 263          echo $after;
 264      }
 265  }
 266  
 267  
 268  /*

 269   * stats_basedomain(-)

 270   */
 271  function stats_basedomain( $disp = true )
 272  {
 273      global $row_stats;
 274      if( $disp )
 275          echo htmlentities( $row_stats['dom_name'] );
 276      else
 277          return $row_stats['dom_name'];
 278  }
 279  
 280  
 281  /**

 282   * Displays keywords used for search leading to this page

 283   *

 284   * @todo link keyword param to search engine ()

 285   */
 286  function stats_search_keywords( $ref )
 287  {
 288      $kwout = '';
 289      if( ($pos_question = strpos( $ref, '?' )) == false )
 290      {
 291          return '['.T_('not a query - no params!').']';
 292      }
 293      $ref_params = explode( '&', substr( $ref, $pos_question+1 ) );
 294      foreach( $ref_params as $ref_param )
 295      {
 296          $param_parts = explode( '=', $ref_param );
 297          if( $param_parts[0] == 'q'
 298                  or $param_parts[0] == 'as_q'         // Google Advanced Search Query
 299                  or $param_parts[0] == 'query'
 300                  or $param_parts[0] == 'search'
 301                  or $param_parts[0] == 'p'
 302                  or $param_parts[0] == 'kw'
 303                  or $param_parts[0] == 'qs'
 304                  or $param_parts[0] == 'r'
 305                  or $param_parts[0] == 'rdata'                // search.ke.voila.fr
 306                  or $param_parts[0] == 'su'                // suche.web.de
 307              )
 308          { // found "q" query parameter
 309              $q = urldecode($param_parts[1]);
 310              if( strpos( $q, 'Ã' ) !== false )
 311              { // Probability that the string is UTF-8 encoded is very high, that'll do for now...
 312                  //echo "[UTF-8 decoding]";

 313                  $q = utf8_decode( $q );
 314              }
 315              $qwords = explode( ' ', $q );
 316              foreach( $qwords as $qw )
 317              {
 318                  if( strlen( $qw ) > 30 ) $qw = substr( $qw, 0, 30 )."...";    // word too long, crop it

 319                  $kwout .= $qw.' ';
 320              }
 321              return htmlentities($kwout);
 322          }
 323      }
 324      return '['.T_('no query string found').']';
 325  }
 326  
 327  
 328  /*

 329   * stats_req_URI(-)

 330   */
 331  function stats_req_URI()
 332  {
 333      global $row_stats;
 334      echo htmlentities($row_stats['hit_uri']);
 335  }
 336  
 337  
 338  /**

 339   * stats_user_agent(-)

 340   *

 341   * @param boolean

 342   */
 343  function stats_user_agent( $translate = false )
 344  {
 345      global $row_stats, $user_agents;
 346      $UserAgent = $row_stats[ 'agnt_signature' ];
 347      if( $translate )
 348      {
 349          foreach ($user_agents as $curr_user_agent)
 350          {
 351              if (stristr($UserAgent, $curr_user_agent[1]))
 352              {
 353                  $UserAgent = $curr_user_agent[2];
 354                  break;
 355              }
 356          }
 357      }
 358      echo htmlentities( $UserAgent );
 359  }
 360  
 361  
 362  /*

 363   * stats_title(-)

 364   *

 365   * @movedTo _obsolete092.php

 366   */
 367  
 368  
 369  /*

 370   * $Log: _hitlog.funcs.php,v $

 371   * Revision 1.1  2007/06/25 11:00:59  fplanque

 372   * MODULES (refactored MVC)

 373   *

 374   * Revision 1.12  2007/04/26 00:11:11  fplanque

 375   * (c) 2007

 376   *

 377   * Revision 1.11  2007/02/10 18:00:34  waltercruz

 378   * Changing double quotes to single quotes

 379   *

 380   * Revision 1.10  2006/11/24 18:27:24  blueyed

 381   * Fixed link to b2evo CVS browsing interface in file docblocks

 382   *

 383   * Revision 1.9  2006/10/10 19:26:24  blueyed

 384   * Use BlogCache instead "blogparams"

 385   *

 386   * Revision 1.8  2006/10/06 21:54:16  blueyed

 387   * Fixed hit_uri handling, especially in strict mode

 388   */
 389  ?>


Généré le : Thu Nov 29 23:58:50 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics