-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.php
225 lines (190 loc) · 6.63 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
<?php
/**
* MyBB 1.8
* Copyright 2014 MyBB Group, All Rights Reserved
*
* Website: http://www.mybb.com
* License: http://www.mybb.com/about/license
*
*/
define("IN_MYBB", 1);
define('THIS_SCRIPT', 'stats.php');
$templatelist = "stats,stats_thread,stats_topforum";
require_once "./global.php";
require_once MYBB_ROOT."inc/functions_post.php";
require_once MYBB_ROOT."inc/class_parser.php";
$parser = new postParser;
// Load global language phrases
$lang->load("stats");
add_breadcrumb($lang->nav_stats);
$stats = $cache->read("stats");
if($stats['numthreads'] < 1 || $stats['numusers'] < 1)
{
error($lang->not_enough_info_stats);
}
if($mybb->settings['statsenabled'] != 1)
{
error($lang->stats_disabled);
}
$plugins->run_hooks("stats_start");
$repliesperthread = my_number_format(round((($stats['numposts'] - $stats['numthreads']) / $stats['numthreads']), 2));
$postspermember = my_number_format(round(($stats['numposts'] / $stats['numusers']), 2));
$threadspermember = my_number_format(round(($stats['numthreads'] / $stats['numusers']), 2));
// Get number of days since board start (might need improvement)
$query = $db->simple_select("users", "regdate", "", array('order_by' => 'regdate', 'limit' => 1));
$result = $db->fetch_array($query);
$days = (TIME_NOW - $result['regdate']) / 86400;
if($days < 1)
{
$days = 1;
}
// Get "per day" things
$postsperday = my_number_format(round(($stats['numposts'] / $days), 2));
$threadsperday = my_number_format(round(($stats['numthreads'] / $days), 2));
$membersperday = my_number_format(round(($stats['numusers'] / $days), 2));
// Get forum permissions
$unviewableforums = get_unviewable_forums(true);
$inactiveforums = get_inactive_forums();
$unviewablefids = $inactivefids = array();
$fidnot = '';
if($unviewableforums)
{
$fidnot .= "AND fid NOT IN ($unviewableforums)";
$unviewablefids = explode(',', $unviewableforums);
}
if($inactiveforums)
{
$fidnot .= "AND fid NOT IN ($inactiveforums)";
$inactivefids = explode(',', $inactiveforums);
}
$unviewableforumsarray = array_merge($unviewablefids, $inactivefids);
// Check group permissions if we can't view threads not started by us
$group_permissions = forum_permissions();
$onlyusfids = array();
foreach($group_permissions as $gpfid => $forum_permissions)
{
if(isset($forum_permissions['canonlyviewownthreads']) && $forum_permissions['canonlyviewownthreads'] == 1)
{
$onlyusfids[] = $gpfid;
}
}
// Most replied-to threads
$most_replied = $cache->read("most_replied_threads");
if(!$most_replied)
{
$cache->update_most_replied_threads();
$most_replied = $cache->read("most_replied_threads", true);
}
$mostreplies = '';
if(!empty($most_replied))
{
foreach($most_replied as $key => $thread)
{
if(
!in_array($thread['fid'], $unviewableforumsarray) &&
(!in_array($thread['fid'], $onlyusfids) || ($mybb->user['uid'] && $thread['uid'] == $mybb->user['uid']))
)
{
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
$numberbit = my_number_format($thread['replies']);
$numbertype = $lang->replies;
$thread['threadlink'] = get_thread_link($thread['tid']);
eval("\$mostreplies .= \"".$templates->get("stats_thread")."\";");
}
}
}
// Most viewed threads
$most_viewed = $cache->read("most_viewed_threads");
if(!$most_viewed)
{
$cache->update_most_viewed_threads();
$most_viewed = $cache->read("most_viewed_threads", true);
}
$mostviews = '';
if(!empty($most_viewed))
{
foreach($most_viewed as $key => $thread)
{
if(
!in_array($thread['fid'], $unviewableforumsarray) &&
(!in_array($thread['fid'], $onlyusfids) || ($mybb->user['uid'] && $thread['uid'] == $mybb->user['uid']))
)
{
$thread['subject'] = htmlspecialchars_uni($parser->parse_badwords($thread['subject']));
$numberbit = my_number_format($thread['views']);
$numbertype = $lang->views;
$thread['threadlink'] = get_thread_link($thread['tid']);
eval("\$mostviews .= \"".$templates->get("stats_thread")."\";");
}
}
}
$statistics = $cache->read('statistics');
$mybb->settings['statscachetime'] = (int)$mybb->settings['statscachetime'];
if($mybb->settings['statscachetime'] < 1)
{
$mybb->settings['statscachetime'] = 0;
}
$interval = $mybb->settings['statscachetime']*3600;
if(!$statistics || $interval == 0 || TIME_NOW - $interval > $statistics['time'])
{
$cache->update_statistics();
$statistics = $cache->read('statistics');
}
// Top forum
$query = $db->simple_select('forums', 'fid, name, threads, posts', "type='f'$fidnot", array('order_by' => 'posts', 'order_dir' => 'DESC', 'limit' => 1));
$forum = $db->fetch_array($query);
if(empty($forum['fid']))
{
$topforum = $lang->none;
$topforumposts = $lang->no;
$topforumthreads = $lang->no;
}
else
{
$forum['name'] = htmlspecialchars_uni(strip_tags($forum['name']));
$forum['link'] = get_forum_link($forum['fid']);
eval("\$topforum = \"".$templates->get("stats_topforum")."\";");
$topforumposts = $forum['posts'];
$topforumthreads = $forum['threads'];
}
// Top referrer defined for the templates even if we don't use it
$top_referrer = '';
if($mybb->settings['statstopreferrer'] == 1 && isset($statistics['top_referrer']['uid']))
{
// Only show this if we have anything more the 0 referrals
if($statistics['top_referrer']['referrals'] > 0)
{
$toprefuser = build_profile_link(htmlspecialchars_uni($statistics['top_referrer']['username']), $statistics['top_referrer']['uid']);
$top_referrer = $lang->sprintf($lang->top_referrer, $toprefuser, my_number_format($statistics['top_referrer']['referrals']));
}
}
// Today's top poster
if(!isset($statistics['top_poster']['uid']))
{
$topposter = $lang->nobody;
$topposterposts = $lang->no_posts;
}
else
{
if(!$statistics['top_poster']['uid'])
{
$topposter = $lang->guest;
}
else
{
$topposter = build_profile_link(htmlspecialchars_uni($statistics['top_poster']['username']), $statistics['top_poster']['uid']);
}
$topposterposts = $statistics['top_poster']['poststoday'];
}
// What percent of members have posted?
$posters = $statistics['posters'];
$havepostedpercent = my_number_format(round((($posters / $stats['numusers']) * 100), 2)) . "%";
$lang->todays_top_poster = $lang->sprintf($lang->todays_top_poster, $topposter, my_number_format($topposterposts));
$lang->popular_forum = $lang->sprintf($lang->popular_forum, $topforum, my_number_format($topforumposts), my_number_format($topforumthreads));
$stats['numposts'] = my_number_format($stats['numposts']);
$stats['numthreads'] = my_number_format($stats['numthreads']);
$stats['numusers'] = my_number_format($stats['numusers']);
$stats['newest_user'] = build_profile_link($stats['lastusername'], $stats['lastuid']);
$plugins->run_hooks("stats_end");
eval("\$stats = \"".$templates->get("stats")."\";");
output_page($stats);