-
Notifications
You must be signed in to change notification settings - Fork 19
/
stats.php
319 lines (286 loc) · 12.3 KB
/
stats.php
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<?php
/* Reminder: always indent with 4 spaces (no tabs). */
// +---------------------------------------------------------------------------+
// | Geeklog 2.1 |
// +---------------------------------------------------------------------------+
// | stats.php |
// | |
// | Geeklog system statistics page. |
// +---------------------------------------------------------------------------+
// | Copyright (C) 2000-2012 by the following authors: |
// | |
// | Authors: Tony Bibbs - tony AT tonybibbs DOT com |
// | Mark Limburg - mlimburg AT users DOT sourceforge DOT net |
// | Jason Whittenburg - jwhitten AT securitygeeks DOT com |
// | Dirk Haun - dirk AT haun-online DOT de |
// +---------------------------------------------------------------------------+
// | |
// | This program is free software; you can redistribute it and/or |
// | modify it under the terms of the GNU General Public License |
// | as published by the Free Software Foundation; either version 2 |
// | of the License, or (at your option) any later version. |
// | |
// | This program is distributed in the hope that it will be useful, |
// | but WITHOUT ANY WARRANTY; without even the implied warranty of |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
// | GNU General Public License for more details. |
// | |
// | You should have received a copy of the GNU General Public License |
// | along with this program; if not, write to the Free Software Foundation, |
// | Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
// | |
// +---------------------------------------------------------------------------+
require_once 'lib-common.php';
require_once $_CONF['path_system'] . 'lib-admin.php';
$display = '';
if (COM_isAnonUser() &&
(($_CONF['loginrequired'] == 1) || ($_CONF['statsloginrequired'] == 1))
) {
$display = COM_createHTMLDocument(SEC_loginRequiredForm(), array('pagetitle' => $LANG10[1]));
COM_output($display);
exit;
}
// MAIN
// Overall Site Statistics
$header_arr = array(
array(
'text' => $LANG10[1],
'field' => 'title',
'header_class' => 'stats-header-title',
),
array(
'text' => '',
'field' => 'stats',
'header_class' => 'stats-header-count',
'field_class' => 'stats-list-count',
),
);
$data_arr = array();
$text_arr = array(
'has_menu' => false,
'title' => $LANG10[1],
'form_url' => $_CONF['site_url'] . '/stats.php',
);
$totalhits = DB_getItem($_TABLES['vars'], 'value', "name = 'totalhits'");
$data_arr[] = array('title' => $LANG10[2], 'stats' => COM_NumberFormat($totalhits));
if ($_CONF['lastlogin']) {
// if we keep track of the last login date, count the number of users
// that have logged in during the last 4 weeks
$sql = array();
$sql['pgsql'] = "SELECT COUNT(*) AS count FROM {$_TABLES['users']} AS u,{$_TABLES['userinfo']} AS i WHERE (u.uid > 1) AND (u.uid = i.uid) AND (lastlogin <> '') AND (lastlogin::int4 >= date_part('epoch', INTERVAL '28 DAY'))";
$sql['mysql'] = "SELECT COUNT(*) AS count FROM {$_TABLES['users']} AS u,{$_TABLES['userinfo']} AS i WHERE (u.uid > 1) AND (u.uid = i.uid) AND (lastlogin <> '') AND (lastlogin >= UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 28 DAY)))";
$result = DB_query($sql);
list($active_users) = DB_fetchArray($result);
} else {
// otherwise, just count all users with status 'active'
// (i.e. those that logged in at least once and have not been banned since)
$active_users = DB_count($_TABLES['users'], 'status', 3);
$active_users--; // don't count the anonymous user account
}
$data_arr[] = array('title' => $LANG10[27], 'stats' => COM_NumberFormat($active_users));
$topicsql = COM_getTopicSql('AND', 0, 'ta');
$id = array('draft_flag', 'date');
$values = array('0', 'NOW()');
$sql = "SELECT COUNT(DISTINCT sid) AS count, SUM(comments) AS ccount
FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta
WHERE ta.type = 'article' AND ta.id = sid
AND (draft_flag = 0) AND (date <= NOW())" . COM_getPermSQL('AND') . $topicsql;
$result = DB_query($sql);
$A = DB_fetchArray($result);
if (empty ($A['ccount'])) {
$A['ccount'] = 0;
}
$data_arr[] = array(
'title' => $LANG10[3],
'stats' => COM_NumberFormat($A['count']) . " (" . COM_NumberFormat($A['ccount']) . ")",
);
// new stats plugin API call
$plg_stats = PLG_getPluginStats(3);
if (count($plg_stats) > 0) {
foreach ($plg_stats as $pstats) {
if (is_array($pstats[0])) {
foreach ($pstats as $pmstats) {
$data_arr[] = array('title' => $pmstats[0], 'stats' => $pmstats[1]);
}
} else {
$data_arr[] = array('title' => $pstats[0], 'stats' => $pstats[1]);
}
}
}
$display .= ADMIN_simpleList('', $header_arr, $text_arr, $data_arr);
// old stats plugin API call, for backward compatibilty
$display .= PLG_getPluginStats(1);
// Detailed story statistics
$sql = "SELECT sid,title,hits
FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta
WHERE ta.type = 'article' AND ta.id = sid
AND (draft_flag = 0) AND (date <= NOW()) AND (Hits > 0)" . COM_getPermSQL('AND') . $topicsql
. " GROUP BY sid, title, hits "
. " ORDER BY hits DESC LIMIT 10";
$result = DB_query($sql);
$nrows = DB_numRows($result);
if ($nrows > 0) {
$header_arr = array(
array(
'text' => $LANG10[8],
'field' => 'sid',
'header_class' => 'stats-header-title',
),
array(
'text' => $LANG10[9],
'field' => 'hits',
'header_class' => 'stats-header-count',
'field_class' => 'stats-list-count',
),
);
$data_arr = array();
$text_arr = array(
'has_menu' => false,
'title' => $LANG10[7],
'form_url' => $_CONF['site_url'] . '/stats.php',
);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$A['title'] = stripslashes(str_replace('$', '$', $A['title']));
$A['sid'] = COM_createLink($A['title'], COM_buildUrl($_CONF['site_url']
. "/article.php?story={$A['sid']}"));
$A['hits'] = COM_NumberFormat($A['hits']);
$data_arr[$i] = $A;
}
$display .= ADMIN_simpleList('', $header_arr, $text_arr, $data_arr);
} else {
$display .= COM_startBlock($LANG10[7]);
$display .= $LANG10[10];
$display .= COM_endBlock();
}
// Top Ten Commented Stories
$sql = "SELECT sid,title,comments
FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta
WHERE ta.type = 'article' AND ta.id = sid
AND (draft_flag = 0) AND (date <= NOW()) AND (comments > 0)" . COM_getPermSQL('AND') . $topicsql
. " GROUP BY sid, title, comments "
. " ORDER BY comments DESC LIMIT 10";
$result = DB_query($sql);
$nrows = DB_numRows($result);
if ($nrows > 0) {
$header_arr = array(
array(
'text' => $LANG10[8],
'field' => 'sid',
'header_class' => 'stats-header-title',
),
array(
'text' => $LANG10[12],
'field' => 'comments',
'header_class' => 'stats-header-count',
'field_class' => 'stats-list-count',
),
);
$data_arr = array();
$text_arr = array(
'has_menu' => false,
'title' => $LANG10[11],
'form_url' => $_CONF['site_url'] . '/stats.php',
);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$A['title'] = stripslashes(str_replace('$', '$', $A['title']));
$A['sid'] = COM_createLink($A['title'], COM_buildUrl($_CONF['site_url']
. "/article.php?story={$A['sid']}"));
$A['comments'] = COM_NumberFormat($A['comments']);
$data_arr[$i] = $A;
}
$display .= ADMIN_simpleList('', $header_arr, $text_arr, $data_arr);
} else {
$display .= COM_startBlock($LANG10[11]);
$display .= $LANG10[13];
$display .= COM_endBlock();
}
// Top Ten Trackback Comments
if ($_CONF['trackback_enabled'] || $_CONF['pingback_enabled']) {
$sql = "SELECT s.sid, s.title, COUNT(*) AS count
FROM {$_TABLES['stories']} s,{$_TABLES['trackback']} AS t, {$_TABLES['topic_assignments']} ta
WHERE ta.type = 'article' AND ta.id = s.sid
AND (s.draft_flag = 0) AND (s.date <= NOW()) AND (s.sid = t.sid) AND (t.type = 'article')" . COM_getPermSQL('AND') . $topicsql . " GROUP BY t.sid, s.sid, s.title ORDER BY count DESC LIMIT 10";
$result = DB_query($sql);
$nrows = DB_numRows($result);
if ($nrows > 0) {
$header_arr = array(
array(
'text' => $LANG10[8],
'field' => 'sid',
'header_class' => 'stats-header-title',
),
array(
'text' => $LANG10[12],
'field' => 'count',
'header_class' => 'stats-header-count',
'field_class' => 'stats-list-count',
),
);
$data_arr = array();
$text_arr = array(
'has_menu' => false,
'title' => $LANG10[25],
'form_url' => $_CONF['site_url'] . '/stats.php',
);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$A['title'] = stripslashes(str_replace('$', '$', $A['title']));
$A['sid'] = COM_createLink($A['title'], COM_buildUrl($_CONF['site_url']
. "/article.php?story={$A['sid']}"));
$A['count'] = COM_NumberFormat($A['count']);
$data_arr[$i] = $A;
}
$display .= ADMIN_simpleList('', $header_arr, $text_arr, $data_arr);
} else {
$display .= COM_startBlock($LANG10[25]);
$display .= $LANG10[26];
$display .= COM_endBlock();
}
}
// Top Ten Emailed Stories
$sql = "SELECT sid,title,numemails
FROM {$_TABLES['stories']}, {$_TABLES['topic_assignments']} ta
WHERE ta.type = 'article' AND ta.id = sid
AND (numemails > 0) AND (draft_flag = 0) AND (date <= NOW())" . COM_getPermSQL('AND') . $topicsql . " ORDER BY numemails DESC LIMIT 10";
$result = DB_query($sql);
$nrows = DB_numRows($result);
if ($nrows > 0) {
$header_arr = array(
array(
'text' => $LANG10[8],
'field' => 'sid',
'header_class' => 'stats-header-title',
),
array(
'text' => $LANG10[23],
'field' => 'numemails',
'header_class' => 'stats-header-count',
'field_class' => 'stats-list-count',
),
);
$data_arr = array();
$text_arr = array(
'has_menu' => false,
'title' => $LANG10[22],
'form_url' => $_CONF['site_url'] . '/stats.php',
);
for ($i = 0; $i < $nrows; $i++) {
$A = DB_fetchArray($result);
$A['title'] = stripslashes(str_replace('$', '$', $A['title']));
$A['sid'] = COM_createLink($A['title'], COM_buildUrl($_CONF['site_url']
. "/article.php?story={$A['sid']}"));
$A['numemails'] = COM_NumberFormat($A['numemails']);
$data_arr[$i] = $A;
}
$display .= ADMIN_simpleList('', $header_arr, $text_arr, $data_arr);
} else {
$display .= COM_startBlock($LANG10[22]);
$display .= $LANG10[24];
$display .= COM_endBlock();
}
// Now show stats for any plugins that want to be included
$display .= PLG_getPluginStats(2);
$display = COM_createHTMLDocument($display, array('pagetitle' => $LANG10[1]));
COM_output($display);