3
* This file implements functions for logging of hits and extracting stats.
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.
7
* This file is part of Quam Plures - {@link http://quamplures.net/}
8
* See also {@link https://launchpad.net/quam-plures}.
10
* @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
11
* @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
12
* Parts of this file are copyright (c)2004-2006 by Daniel HAHLER - {@link http://thequod.de/contact}.
14
* {@internal License choice
15
* - If you have received this file as part of a package, please find the license.txt file in
16
* the same folder or the closest folder above for complete license terms.
17
* - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
18
* then you must choose one of the following licenses before using the file:
19
* - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
20
* - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
23
* {@internal Open Source relicensing agreement:
24
* Daniel HAHLER grants Francois PLANQUE the right to license
25
* Daniel HAHLER's contributions to this file and the b2evolution project
26
* under any OSI approved OSS license (http://www.opensource.org/licenses/).
3
* This file implements functions for logging of hits and extracting stats
5
* NOTE: the refererList() and stats_* functions are not fully functional ATM.
6
* I'll transform them into the Hitlog object during the next days. blueyed.
30
8
* This file was inspired by N C Young's Referer Script released in
31
9
* the public domain on 07/19/2002. {@link http://ncyoung.com/entry/57}.
32
10
* See also {@link http://ncyoung.com/demo/referer/}.
35
* {@internal Below is a list of authors who have contributed to design/coding of this file: }}
36
* @author N C Young (nathan@ncyoung.com).
37
* @author blueyed: Daniel HAHLER.
38
* @author fplanque: Francois PLANQUE.
39
* @author vegarg: Vegar BERG GULDAL.
12
* @todo (0000): Transform refererList() to make it a stub for {@link $Hitlist}
14
* @author {@link http://wonderwinds.com/ Ed Bennett}
15
* @author {@link http://daniel.hahler.de/ Daniel HAHLER}
16
* @author {@link http://funky-m.com/ Vegar BERG GULDAL}
17
* @author {@link http://fplanque.net/ Francois PLANQUE}
18
* @author N C Young (nathan@ncyoung.com)
19
* @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
20
* @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
41
21
* @package sessions
43
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
23
if(!defined('QP_MAIN_INIT')) die('fail');
48
* @todo Transform to make this a stub for {@link $Hitlist}
52
28
function refererList(
57
$type = "'referer'", // was: 'referer' normal refer, 'invalid', 'badchar', 'blacklist', 'rss', 'robot', 'search'
58
// new: 'search', 'blacklist', 'referer', 'direct', ('spam' but spam is not logged)
59
$groupby = '', // dom_name
33
$type = "'referer'", // 'search', 'blacklist', 'referer', 'direct', ('spam' but spam is not logged)
34
$groupby = '', // dom_name
61
36
$get_total_hits = false, // Get total number of hits (needed for percentages)
62
37
$get_user_agent = false ) // Get the user agent
64
39
global $DB, $res_stats, $stats_total_hits, $ReqURI;
66
41
if( strpos( $type, "'" ) !== 0 )
67
{ // no quote at position 0
43
// no quote at position 0
68
44
$type = "'".$type."'";
71
47
//if no visitURL, will show links to current page.
72
48
//if url given, will show links to that page.
73
49
//if url="global" will show links to all pages
76
52
$visitURL = $ReqURI;
79
55
if( $groupby == '' )
81
58
$sql = 'SELECT hit_ID, UNIX_TIMESTAMP(hit_datetime) AS hit_datetime, hit_referer, dom_name';
85
63
if( $groupby == 'baseDomain' )
86
{ // compatibility HACK!
65
// compatibility HACK!
87
66
$groupby = 'dom_name';
89
$sql = 'SELECT COUNT(*) AS totalHits, hit_referer, dom_name';
68
$sql = 'SELECT COUNT(*) AS totalHits, hit_referer, dom_name ';
101
80
$sql .= ', hit_agnt_signature';
106
LEFT JOIN T_basedomains ON dom_ID = hit_referer_dom_ID
107
WHERE hit_referer_type IN (".$type.")
108
AND hit_agnt_type = 'browser'";
109
if( !empty($blog_ID) )
83
$sql_from_where = "FROM T_hitlog LEFT JOIN T_basedomains ON dom_ID = hit_referer_dom_ID
84
WHERE hit_referer_type IN (".$type.") AND hit_agnt_type = 'browser'";
85
if( ! empty( $blog_ID ) )
111
87
$sql_from_where .= " AND hit_blog_ID = '".$blog_ID."'";
113
if ( $visitURL != 'global' )
89
if( $visitURL != 'global' )
115
$sql_from_where .= " AND hit_uri = '".$DB->escape($visitURL, 0, 250)."'";
91
$sql_from_where .= " AND hit_uri = '".$DB->escape( $visitURL, 0, 250 )."'";
118
94
$sql .= $sql_from_where;
120
96
if( $groupby == '' )
122
99
$sql .= ' ORDER BY hit_ID DESC';
126
104
$sql .= " GROUP BY ".$groupby." ORDER BY totalHits DESC";
128
106
$sql .= ' LIMIT '.$howMany;
130
108
$res_stats = $DB->get_results( $sql, ARRAY_A );
132
110
if( $get_total_hits )
133
{ // we need to get total hits
112
// we need to get total hits
134
113
$sql = 'SELECT COUNT(*) '.$sql_from_where;
135
114
$stats_total_hits = $DB->get_var( $sql );
138
{ // we're not getting total hits
139
$stats_total_hits = 1; // just in case some tries a percentage anyway (avoid div by 0)
118
// we're not getting total hits
119
$stats_total_hits = 1; // just in case some tries a percentage anyway (avoid div by 0)
276
256
// Save original string
277
257
$keyphrase_orig = $keyphrase;
279
if( evo_strlen( $keyphrase ) > $length )
259
if( app_strlen( $keyphrase ) > $length )
281
// TODO: dh> there are other places, where mb_substr should get used, when available!
282
// Either create a generic wrapper (evo_substr()), or just use
283
// mbstring_func_overlay=7 (php.ini). I'd say the latter is the way to go,
284
// but at least the first option ("evo_substr") should get used otherwise
285
// (which is kind of crappy though). Note: there are more internal PHP funcs
286
// that would need wrapping, so overloading appears to be the way to go.
287
// fp> we should just init somewhere that if( ! function_exists('mb_substr') ) function mbsubstr() { return substr() }
288
$keyphrase = evo_substr( $keyphrase, 0, $length ).'...'; // word too long, crop it
261
// @todo (0000): dh> there are other places, where mb_substr should get used, when available!
262
// Either create a generic wrapper (app_substr()), or just use mbstring_func_overlay=7
263
// (php.ini). I'd say the latter is the way to go, but at least the first option
264
// ("app_substr") should get used otherwise (which is kind of crappy though).
265
// Note: there are more internal PHP funcs that would need wrapping, so
266
// overloading appears to be the way to go.
267
// fp> we should just init somewhere that if( ! function_exists('mb_substr') )
268
// function mbsubstr() { return substr() }
269
$keyphrase = app_substr( $keyphrase, 0, $length ).'...'; // word too long, crop it
291
272
// Convert keyword encoding, some charsets are supported only in PHP 4.3.2 and later.
292
273
// This fixes encoding problem for Cyrillic keywords
293
274
// See http://forums.b2evolution.net/viewtopic.php?t=17431
294
$keyphrase = htmlentities( $keyphrase, ENT_COMPAT, $evo_charset );
275
$keyphrase = htmlentities( $keyphrase, ENT_COMPAT, $app_charset );
296
277
return '<span title="'.format_to_output( $keyphrase_orig, 'htmlattr' ).'">'.$keyphrase.'</span>';
315
296
function stats_user_agent( $translate = false )
317
298
global $row_stats, $user_agents;
318
$UserAgent = $row_stats[ 'hit_agnt_signature' ];
299
$UserAgent = $row_stats['hit_agnt_signature'];
321
foreach ($user_agents as $curr_user_agent)
302
foreach ( $user_agents as $curr_user_agent )
323
if (stristr($UserAgent, $curr_user_agent[1]))
304
if(stristr( $UserAgent, $curr_user_agent[1] ) )
325
306
$UserAgent = $curr_user_agent[2];