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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
/**
 * This file implements the UI view for the robot stats.
 *
 * @uses PHP_SWF_Charts
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 * @author {@link http://fplanque.net/ Francois PLANQUE}
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
 * @package sessions
 */
if(!defined('QP_MAIN_INIT')) die('fail');

/**
 * View funcs
 */
require_once dirname(__FILE__).'/_stats_view.funcs.php';

global $admin_url;
global $AdminUI;
global $blog;
global $rsc_url;

echo '<h2>'.T_('Robot hits summary').'</h2>';
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>';
echo '<p class="notes">'.T_('In order to be detected, robots must be listed in /qp_config/_stats.php.').'</p>';

$sql = "SELECT COUNT(*) AS hits, EXTRACT(YEAR FROM hit_datetime) AS year,
	EXTRACT(MONTH FROM hit_datetime) AS month, EXTRACT(DAY FROM hit_datetime) AS day
	FROM T_hitlog WHERE hit_agnt_type = 'robot'";
if( $blog > 0 )
{
	$sql .= ' AND hit_blog_ID = '.$blog;
}
$sql .= ' GROUP BY year, month, day ORDER BY year DESC, month DESC, day DESC';

$res_hits = $DB->get_results( $sql, ARRAY_A, 'Get robot summary' );

// Chart
if( count( $res_hits ) )
{
	$last_date = 0;

	$chart['chart_data'][0] = array();
	$chart['chart_data'][1] = array();

	$count = 0;
	foreach( $res_hits as $row_stats )
	{
		$this_date = mktime( 0, 0, 0, $row_stats['month'], $row_stats['day'], $row_stats['year'] );
		if( $last_date != $this_date )
		{
			// We just hit a new day, let's display the previous one
			$last_date = $this_date; // that'll be the next one
			$count ++;
			array_unshift( $chart['chart_data'][0], date( locale_datefmt(), $last_date ) );
			array_unshift( $chart['chart_data'][1], 0 );
		}
		$chart ['chart_data'][1][0] = $row_stats['hits'];
	}

	array_unshift( $chart['chart_data'][0], '' );
	array_unshift( $chart['chart_data'][1], 'Robot hits' ); // Translations need to be UTF-8

	/**
	 * Include common chart properties
	 */
	require dirname(__FILE__).'/inc/_bar_chart.inc.php';

	$chart['series_color'] = array (
		'ff9900',
	);

	echo '<div class="center">';
	load_funcs( '_ext/_swfcharts.php' );
	DrawChart( $chart );
	echo '</div>';

}

// TOP INDEXING ROBOTS
// Create result set
$sql = "SELECT COUNT(*) AS hit_count, hit_agnt_signature FROM T_hitlog WHERE hit_agnt_type = 'robot' "
	.( empty( $blog ) ? '' : 'AND hit_blog_ID = '.$blog ).' GROUP BY hit_agnt_signature';

$count_sql = "SELECT COUNT( DISTINCT hit_agnt_signature )
	FROM T_hitlog
	WHERE hit_agnt_type = 'robot' "
	.( empty( $blog ) ? '' : 'AND hit_blog_ID = '.$blog );

$Results = new Results( $sql, 'topidx', '-D', 20, $count_sql );

$total_hit_count = $DB->get_var( "SELECT COUNT(*)
	FROM T_hitlog
	WHERE hit_agnt_type = 'robot' "
	.( empty( $blog ) ? '' : 'AND hit_blog_ID = '.$blog ) );

$Results->title = T_('Top Indexing Robots');

// User agent
$Results->cols[] = array(
	'th' => T_('Robot'),
	'order' => 'hit_agnt_signature',
	'td' => '%translate_user_agent(\'$hit_agnt_signature$\')%',
);

// Hit count
$Results->cols[] = array(
	'th' => T_('Hit count'),
	'order' => 'hit_count',
	'td_class' => 'right',
	'td' => '$hit_count$',
);

// Hit 
$Results->cols[] = array(
	'th' => T_('Hit %'),
	'order' => 'hit_count',
	'td_class' => 'right',
	'td' => '%percentage( #hit_count#, '.$total_hit_count.' )%',
);

// Display results
$Results->display();

/**
 * translate agnt_signature to a "human-friendly" version from {@link $user_agents}
 *
 * @return string
 */
function translate_user_agent( $agnt_signature )
{
	global $user_agents;

	foreach( $user_agents as $curr_user_agent )
	{
		if( stristr( $agnt_signature, $curr_user_agent[1] ) )
		{
			return '<span title="'.htmlspecialchars( $agnt_signature ).'">'.htmlspecialchars( $curr_user_agent[2] ).'</span>';
		}
	}

	return htmlspecialchars( $agnt_signature );
}

?>