~quam-plures-core/quam-plures/xml-comment-feeds-fix

« back to all changes in this revision

Viewing changes to qp_inc/sessions/views/_stats_robots.view.php

  • Committer: EdB
  • Date: 2013-05-18 17:02:22 UTC
  • mfrom: (7556.2.107 quam-plures)
  • Revision ID: 1912webworks@gmail.com-20130518170222-ccp8ok2njoasujlb
updating to current core

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
/**
3
3
 * This file implements the UI view for the robot stats.
4
4
 *
5
 
 * This file is part of Quam Plures - {@link http://quamplures.net/}
6
 
 * See also {@link https://launchpad.net/quam-plures}.
7
 
 *
8
 
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
9
 
 * @copyright (c)2003-2009 by Francois PLANQUE - {@link http://fplanque.net/}
10
 
 *
11
 
 * {@internal License choice
12
 
 * - If you have received this file as part of a package, please find the license.txt file in
13
 
 *   the same folder or the closest folder above for complete license terms.
14
 
 * - If you have received this file individually (e-g: from http://evocms.cvs.sourceforge.net/)
15
 
 *   then you must choose one of the following licenses before using the file:
16
 
 *   - GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
17
 
 *   - Mozilla Public License 1.1 (MPL) - http://www.opensource.org/licenses/mozilla1.1.php
18
 
 * }}
19
 
 *
20
 
 * {@internal Open Source relicensing agreement:
21
 
 * }}
22
 
 *
 
5
 * @uses PHP_SWF_Charts
 
6
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
7
 * @author {@link http://fplanque.net/ Francois PLANQUE}
 
8
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
9
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
23
10
 * @package sessions
24
11
 */
25
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
12
if(!defined('QP_MAIN_INIT')) die('fail');
26
13
 
27
14
/**
28
15
 * View funcs
29
16
 */
30
17
require_once dirname(__FILE__).'/_stats_view.funcs.php';
31
18
 
32
 
 
33
 
global $blog, $admin_url, $rsc_url, $AdminUI;
34
 
 
35
 
echo '<h2>'.get_manual_link( 'robot-hits-summary' ).T_('Robot hits summary').'</h2>';
 
19
global $admin_url;
 
20
global $AdminUI;
 
21
global $blog;
 
22
global $rsc_url;
 
23
 
 
24
echo '<h2>'.T_('Robot hits summary').'</h2>';
36
25
echo '<p class="notes">'.sprintf( T_('This page only includes hits identified as made by <a %s>indexing robots</a> a.k.a. web crawlers.'), ' href="?ctrl=stats&amp;tab=useragents&amp;agnt_robot=1&amp;blog='.$blog.'"' ).'</p>';
37
26
echo '<p class="notes">'.T_('In order to be detected, robots must be listed in /qp_config/_stats.php.').'</p>';
38
27
 
39
 
$sql = "
40
 
        SELECT COUNT(*) AS hits, EXTRACT(YEAR FROM hit_datetime) AS year,
41
 
                           EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day
42
 
                FROM T_hitlog
43
 
         WHERE hit_agnt_type = 'robot'";
 
28
$sql = "SELECT COUNT(*) AS hits, EXTRACT(YEAR FROM hit_datetime) AS year,
 
29
        EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day
 
30
        FROM T_hitlog WHERE hit_agnt_type = 'robot'";
44
31
if( $blog > 0 )
45
32
{
46
33
        $sql .= ' AND hit_blog_ID = '.$blog;
47
34
}
48
 
$sql .= ' GROUP BY year, month, day
49
 
                                        ORDER BY year DESC, month DESC, day DESC';
 
35
$sql .= ' GROUP BY year, month, day ORDER BY year DESC, month DESC, day DESC';
 
36
 
50
37
$res_hits = $DB->get_results( $sql, ARRAY_A, 'Get robot summary' );
51
38
 
52
 
 
53
 
/*
54
 
 * Chart
55
 
 */
56
 
if( count($res_hits) )
 
39
// Chart
 
40
if( count( $res_hits ) )
57
41
{
58
42
        $last_date = 0;
59
43
 
60
 
        $chart[ 'chart_data' ][ 0 ] = array();
61
 
        $chart[ 'chart_data' ][ 1 ] = array();
 
44
        $chart['chart_data'][0] = array();
 
45
        $chart['chart_data'][1] = array();
62
46
 
63
47
        $count = 0;
64
48
        foreach( $res_hits as $row_stats )
65
49
        {
66
50
                $this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
67
51
                if( $last_date != $this_date )
68
 
                { // We just hit a new day, let's display the previous one:
69
 
                                $last_date = $this_date;        // that'll be the next one
70
 
                                $count ++;
71
 
                                array_unshift( $chart[ 'chart_data' ][ 0 ], date( locale_datefmt(), $last_date ) );
72
 
                                array_unshift( $chart[ 'chart_data' ][ 1 ], 0 );
 
52
                {
 
53
                        // We just hit a new day, let's display the previous one
 
54
                        $last_date = $this_date; // that'll be the next one
 
55
                        $count ++;
 
56
                        array_unshift( $chart['chart_data'][0], date( locale_datefmt(), $last_date ) );
 
57
                        array_unshift( $chart['chart_data'][1], 0 );
73
58
                }
74
 
                $chart [ 'chart_data' ][1][0] = $row_stats['hits'];
 
59
                $chart ['chart_data'][1][0] = $row_stats['hits'];
75
60
        }
76
61
 
77
 
        array_unshift( $chart[ 'chart_data' ][ 0 ], '' );
78
 
        array_unshift( $chart[ 'chart_data' ][ 1 ], 'Robot hits' );     // Translations need to be UTF-8
 
62
        array_unshift( $chart['chart_data'][0], '' );
 
63
        array_unshift( $chart['chart_data'][1], 'Robot hits' ); // Translations need to be UTF-8
79
64
 
80
 
        // Include common chart properties:
 
65
        /**
 
66
         * Include common chart properties
 
67
         */
81
68
        require dirname(__FILE__).'/inc/_bar_chart.inc.php';
82
69
 
83
 
        $chart[ 'series_color' ] = array (
84
 
                        'ff9900',
85
 
                );
86
 
 
 
70
        $chart['series_color'] = array (
 
71
                'ff9900',
 
72
        );
87
73
 
88
74
        echo '<div class="center">';
89
 
        load_funcs('_ext/_swfcharts.php');
 
75
        load_funcs( '_ext/_swfcharts.php' );
90
76
        DrawChart( $chart );
91
77
        echo '</div>';
92
78
 
93
79
}
94
80
 
95
 
 
96
 
 
97
81
// TOP INDEXING ROBOTS
98
 
 
99
 
// Create result set:
100
 
$sql = "SELECT COUNT(*) AS hit_count, hit_agnt_signature
101
 
                                        FROM T_hitlog
102
 
                                 WHERE hit_agnt_type = 'robot' "
103
 
                                                        .( empty($blog) ? '' : 'AND hit_blog_ID = '.$blog ).'
104
 
                                 GROUP BY hit_agnt_signature';
 
82
// Create result set
 
83
$sql = "SELECT COUNT(*) AS hit_count, hit_agnt_signature FROM T_hitlog WHERE hit_agnt_type = 'robot' "
 
84
        .( empty( $blog ) ? '' : 'AND hit_blog_ID = '.$blog ).' GROUP BY hit_agnt_signature';
105
85
 
106
86
$count_sql = "SELECT COUNT( DISTINCT hit_agnt_signature )
107
 
                                                                FROM T_hitlog
108
 
                                                         WHERE hit_agnt_type = 'robot' "
109
 
                                                         .( empty($blog) ? '' : 'AND hit_blog_ID = '.$blog );
 
87
        FROM T_hitlog
 
88
        WHERE hit_agnt_type = 'robot' "
 
89
        .( empty( $blog ) ? '' : 'AND hit_blog_ID = '.$blog );
110
90
 
111
91
$Results = new Results( $sql, 'topidx', '-D', 20, $count_sql );
112
92
 
113
 
$total_hit_count = $DB->get_var( "
114
 
                SELECT COUNT(*)
115
 
                        FROM T_hitlog
116
 
                 WHERE hit_agnt_type = 'robot' "
117
 
                .( empty($blog) ? '' : 'AND hit_blog_ID = '.$blog ) );
 
93
$total_hit_count = $DB->get_var( "SELECT COUNT(*)
 
94
        FROM T_hitlog
 
95
        WHERE hit_agnt_type = 'robot' "
 
96
        .( empty( $blog ) ? '' : 'AND hit_blog_ID = '.$blog ) );
118
97
 
119
98
$Results->title = T_('Top Indexing Robots');
120
99
 
 
100
// User agent
 
101
$Results->cols[] = array(
 
102
        'th' => T_('Robot'),
 
103
        'order' => 'hit_agnt_signature',
 
104
        'td' => '%translate_user_agent(\'$hit_agnt_signature$\')%',
 
105
);
 
106
 
 
107
// Hit count
 
108
$Results->cols[] = array(
 
109
        'th' => T_('Hit count'),
 
110
        'order' => 'hit_count',
 
111
        'td_class' => 'right',
 
112
        'td' => '$hit_count$',
 
113
);
 
114
 
 
115
// Hit 
 
116
$Results->cols[] = array(
 
117
        'th' => T_('Hit %'),
 
118
        'order' => 'hit_count',
 
119
        'td_class' => 'right',
 
120
        'td' => '%percentage( #hit_count#, '.$total_hit_count.' )%',
 
121
);
 
122
 
 
123
// Display results
 
124
$Results->display();
 
125
 
121
126
/**
122
 
 * Helper function to translate agnt_signature to a "human-friendly" version from {@link $user_agents}.
 
127
 * translate agnt_signature to a "human-friendly" version from {@link $user_agents}
 
128
 *
123
129
 * @return string
124
130
 */
125
131
function translate_user_agent( $agnt_signature )
126
132
{
127
133
        global $user_agents;
128
134
 
129
 
        foreach ($user_agents as $curr_user_agent)
 
135
        foreach( $user_agents as $curr_user_agent )
130
136
        {
131
 
                if (stristr($agnt_signature, $curr_user_agent[1]))
 
137
                if( stristr( $agnt_signature, $curr_user_agent[1] ) )
132
138
                {
133
 
                        return '<span title="'.htmlspecialchars($agnt_signature).'">'.htmlspecialchars($curr_user_agent[2]).'</span>';
 
139
                        return '<span title="'.htmlspecialchars( $agnt_signature ).'">'.htmlspecialchars( $curr_user_agent[2] ).'</span>';
134
140
                }
135
141
        }
136
142
 
137
 
        return htmlspecialchars($agnt_signature);
 
143
        return htmlspecialchars( $agnt_signature );
138
144
}
139
145
 
140
 
// User agent:
141
 
$Results->cols[] = array(
142
 
                'th' => T_('Robot'),
143
 
                'order' => 'hit_agnt_signature',
144
 
                'td' => '%translate_user_agent(\'$hit_agnt_signature$\')%',
145
 
        );
146
 
 
147
 
// Hit count:
148
 
$Results->cols[] = array(
149
 
                'th' => T_('Hit count'),
150
 
                'order' => 'hit_count',
151
 
                'td_class' => 'right',
152
 
                'td' => '$hit_count$',
153
 
        );
154
 
 
155
 
// Hit %
156
 
$Results->cols[] = array(
157
 
                'th' => T_('Hit %'),
158
 
                'order' => 'hit_count',
159
 
                'td_class' => 'right',
160
 
                'td' => '%percentage( #hit_count#, '.$total_hit_count.' )%',
161
 
        );
162
 
 
163
 
// Display results:
164
 
$Results->display();
165
 
 
166
 
 
167
 
?>
 
 
b'\\ No newline at end of file'
 
146
?>