~quam-plures-core/quam-plures/file_manager_limits

« back to all changes in this revision

Viewing changes to qp_inc/sessions/model/_hitlog.funcs.php

  • Committer: EdB
  • Date: 2013-03-04 07:15:41 UTC
  • mfrom: (7655.1.3 qp5_antispam)
  • Revision ID: 1912webworks@gmail.com-20130304071541-x462crs4d531rh69
http://forums.quamplures.net/viewtopic.php?f=6&t=1887

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
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 Quam Plures - {@link http://quamplures.net/}
8
 
 * See also {@link https://launchpad.net/quam-plures}.
9
 
 *
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}.
13
 
 *
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
21
 
 * }}
22
 
 *
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/).
27
 
 * }}
28
 
 *
29
 
 * {@internal Origin:
 
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.
 
6
 * I'll transform them into the Hitlog object during the next days. blueyed.
 
7
 *
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/}.
33
 
 * }}
34
 
 *
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.
40
 
 *
 
11
 *
 
12
 * @todo (0000): Transform refererList() to make it a stub for {@link $Hitlist}
 
13
 *
 
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
42
22
 */
43
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
44
 
 
45
 
 
 
23
if(!defined('QP_MAIN_INIT')) die('fail');
46
24
 
47
25
/**
48
 
 * @todo Transform to make this a stub for {@link $Hitlist}
49
 
 *
50
26
 * Extract stats
51
27
 */
52
28
function refererList(
54
30
        $visitURL = '',
55
31
        $disp_blog = 0,
56
32
        $disp_uri = 0,
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
60
35
        $blog_ID = '',
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;
65
40
 
66
41
        if( strpos( $type, "'" ) !== 0 )
67
 
        { // no quote at position 0
 
42
        {
 
43
                // no quote at position 0
68
44
                $type = "'".$type."'";
69
45
        }
70
46
 
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
74
 
        if (!$visitURL)
 
50
        if( ! $visitURL )
75
51
        {
76
52
                $visitURL = $ReqURI;
77
53
        }
78
54
 
79
55
        if( $groupby == '' )
80
 
        { // No grouping:
 
56
        {
 
57
                // No grouping
81
58
                $sql = 'SELECT hit_ID, UNIX_TIMESTAMP(hit_datetime) AS hit_datetime, hit_referer, dom_name';
82
59
        }
83
60
        else
84
 
        { // group by
 
61
        {
 
62
                // group by
85
63
                if( $groupby == 'baseDomain' )
86
 
                { // compatibility HACK!
 
64
                {
 
65
                        // compatibility HACK!
87
66
                        $groupby = 'dom_name';
88
67
                }
89
 
                $sql = 'SELECT COUNT(*) AS totalHits, hit_referer, dom_name';
 
68
                $sql = 'SELECT COUNT(*) AS totalHits, hit_referer, dom_name ';
90
69
        }
91
70
        if( $disp_blog )
92
71
        {
101
80
                $sql .= ', hit_agnt_signature';
102
81
        }
103
82
 
104
 
        $sql_from_where = "
105
 
                          FROM T_hitlog
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 ) )
110
86
        {
111
87
                $sql_from_where .= " AND hit_blog_ID = '".$blog_ID."'";
112
88
        }
113
 
        if ( $visitURL != 'global' )
 
89
        if( $visitURL != 'global' )
114
90
        {
115
 
                $sql_from_where .= " AND hit_uri = '".$DB->escape($visitURL, 0, 250)."'";
 
91
                $sql_from_where .= " AND hit_uri = '".$DB->escape( $visitURL, 0, 250 )."'";
116
92
        }
117
93
 
118
94
        $sql .= $sql_from_where;
119
95
 
120
96
        if( $groupby == '' )
121
 
        { // No grouping:
 
97
        {
 
98
                // No grouping
122
99
                $sql .= ' ORDER BY hit_ID DESC';
123
100
        }
124
101
        else
125
 
        { // group by
 
102
        {
 
103
                // group by
126
104
                $sql .= " GROUP BY ".$groupby." ORDER BY totalHits DESC";
127
105
        }
128
106
        $sql .= ' LIMIT '.$howMany;
130
108
        $res_stats = $DB->get_results( $sql, ARRAY_A );
131
109
 
132
110
        if( $get_total_hits )
133
 
        { // we need to get total hits
 
111
        {
 
112
                // we need to get total hits
134
113
                $sql = 'SELECT COUNT(*) '.$sql_from_where;
135
114
                $stats_total_hits = $DB->get_var( $sql );
136
115
        }
137
116
        else
138
 
        { // we're not getting total hits
139
 
                $stats_total_hits = 1;          // just in case some tries a percentage anyway (avoid div by 0)
 
117
        {
 
118
                // we're not getting total hits
 
119
                $stats_total_hits = 1; // just in case some tries a percentage anyway (avoid div by 0)
140
120
        }
141
121
 
142
122
}
226
206
        global $row_stats;
227
207
 
228
208
        $BlogCache = & get_Cache('BlogCache');
229
 
        $Blog = & $BlogCache->get_by_ID($row_stats['hit_blog_ID']);
 
209
        $Blog = & $BlogCache->get_by_ID( $row_stats['hit_blog_ID'] );
230
210
 
231
211
        $Blog->disp('name');
232
212
}
238
218
function stats_referer( $before='', $after='', $disp_ref = true )
239
219
{
240
220
        global $row_stats;
241
 
        $ref = trim($row_stats['hit_referer']);
242
 
        if( strlen($ref) > 0 )
 
221
        $ref = trim( $row_stats['hit_referer'] );
 
222
        if( strlen( $ref ) > 0 )
243
223
        {
244
224
                echo $before;
245
225
                if( $disp_ref ) echo htmlentities( $ref );
266
246
 */
267
247
function stats_search_keywords( $keyphrase, $length = 45 )
268
248
{
269
 
        global $evo_charset;
 
249
        global $app_charset;
270
250
 
271
251
        if( empty( $keyphrase ) )
272
252
        {
276
256
        // Save original string
277
257
        $keyphrase_orig = $keyphrase;
278
258
 
279
 
        if( evo_strlen( $keyphrase ) > $length )
 
259
        if( app_strlen( $keyphrase ) > $length )
280
260
        {
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
289
270
        }
290
271
 
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 );
295
276
 
296
277
        return '<span title="'.format_to_output( $keyphrase_orig, 'htmlattr' ).'">'.$keyphrase.'</span>';
297
278
}
303
284
function stats_req_URI()
304
285
{
305
286
        global $row_stats;
306
 
        echo htmlentities($row_stats['hit_uri']);
 
287
        echo htmlentities( $row_stats['hit_uri'] );
307
288
}
308
289
 
309
290
 
315
296
function stats_user_agent( $translate = false )
316
297
{
317
298
        global $row_stats, $user_agents;
318
 
        $UserAgent = $row_stats[ 'hit_agnt_signature' ];
 
299
        $UserAgent = $row_stats['hit_agnt_signature'];
319
300
        if( $translate )
320
301
        {
321
 
                foreach ($user_agents as $curr_user_agent)
 
302
                foreach ( $user_agents as $curr_user_agent )
322
303
                {
323
 
                        if (stristr($UserAgent, $curr_user_agent[1]))
 
304
                        if(stristr( $UserAgent, $curr_user_agent[1] ) )
324
305
                        {
325
306
                                $UserAgent = $curr_user_agent[2];
326
307
                                break;