Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 601 lines (521 sloc) 22.347 kb
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
1 <?php
2
3 /**
a2897c56 »
2012-09-08 cleanup queries
4 * Copyright (c) 2007-2012, Jos de Ruijter <jos@dutnie.nl>
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
d790e8c7 »
2010-08-08 exit on error; fix typo
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
d790e8c7 »
2010-08-08 exit on error; fix typo
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
d790e8c7 »
2010-08-08 exit on error; fix typo
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 /**
6a3a8fb1 »
2010-05-02 optimize userstats
20 * Class for creating userstats.
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
21 */
0dee1251 »
2010-08-08 base for sss3
22 final class user
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
23 {
51c21ef1 »
2009-12-04 comments, fix a small bug where the last seen date for users with mul…
24 /**
354d99c7 »
2011-05-04 initial code for handling multiple channel configuration along with u…
25 * Default settings for this script, can be overridden in the vars.php file.
8a872b8a »
2010-10-17 make user editable settings more apparent in user.php and history.php
26 */
27 private $bar_afternoon = 'y.png';
28 private $bar_evening = 'r.png';
29 private $bar_morning = 'g.png';
30 private $bar_night = 'b.png';
354d99c7 »
2011-05-04 initial code for handling multiple channel configuration along with u…
31 private $channel = '';
32 private $db_host = '127.0.0.1';
33 private $db_pass = '';
34 private $db_port = 3306;
35 private $db_name = 'sss';
36 private $db_user = '';
37 private $debug = false;
964fc5cb »
2010-10-18 have user.php and history.php link back to the mainpage
38 private $mainpage = './';
8a872b8a »
2010-10-17 make user editable settings more apparent in user.php and history.php
39 private $stylesheet = 'sss.css';
354d99c7 »
2011-05-04 initial code for handling multiple channel configuration along with u…
40 private $timezone = 'UTC';
5497f095 »
2009-11-07 it's now possible to enable debug output so the database connection c…
41
42 /**
0dee1251 »
2010-08-08 base for sss3
43 * Variables that shouldn't be tampered with.
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
44 */
ec7df975 »
2011-05-05 exit if doesnt exist in vars.php
45 private $cid = '';
7a9fae41 »
2012-09-24 add year estimate to user stats
46 private $currentyear = 0;
fdd9a0b4 »
2010-08-12 spaces -> tabs
47 private $csnick = '';
48 private $date_lastlogparsed = '';
49 private $date_max = '';
62f5e2e7 »
2010-08-09 various small fixes and polishing
50 private $dayofmonth = 0;
7a9fae41 »
2012-09-24 add year estimate to user stats
51 private $daysleft = 0;
52 private $estimate = false;
fdd9a0b4 »
2010-08-12 spaces -> tabs
53 private $firstseen = '';
54 private $l_avg = 0;
55 private $l_max = 0;
56 private $l_total = 0;
57 private $lastseen = '';
58 private $month = 0;
3b56f7c7 »
2010-08-17 put users mood (most used smiley) on their userpage
59 private $mood = '';
fdd9a0b4 »
2010-08-12 spaces -> tabs
60 private $mysqli;
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
61 private $nick = '';
fdd9a0b4 »
2010-08-12 spaces -> tabs
62 private $ruid = 0;
63 private $year = 0;
64 private $years = 0;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
65
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
66 public function __construct($cid, $nick)
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
67 {
ec7df975 »
2011-05-05 exit if doesnt exist in vars.php
68 $this->cid = $cid;
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
69 $this->nick = $nick;
354d99c7 »
2011-05-04 initial code for handling multiple channel configuration along with u…
70
71 /**
72 * Open the vars.php file and load settings from it. First the global settings then the channel specific ones.
73 */
74 if ((@include 'vars.php') === false) {
75 exit('Missing configuration.');
76 }
77
453a6d92 »
2011-05-05 rename global to __global so to not conflict with possible cid and ex…
78 if (empty($settings['__global']) || empty($settings[$this->cid])) {
79 exit('Not configured.');
80 }
81
82 foreach ($settings['__global'] as $key => $value) {
354d99c7 »
2011-05-04 initial code for handling multiple channel configuration along with u…
83 $this->$key = $value;
84 }
85
86 /**
87 * $cid is the channel ID used in vars.php and is passed along in the URL so that channel specific settings can be identified and loaded.
88 */
ec7df975 »
2011-05-05 exit if doesnt exist in vars.php
89 foreach ($settings[$this->cid] as $key => $value) {
354d99c7 »
2011-05-04 initial code for handling multiple channel configuration along with u…
90 $this->$key = $value;
91 }
92
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
93 date_default_timezone_set($this->timezone);
94 }
95
0dee1251 »
2010-08-08 base for sss3
96 public function make_html()
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
97 {
647f0904 »
2010-08-12 add Historical stats: history.php
98 $this->mysqli = @mysqli_connect($this->db_host, $this->db_user, $this->db_pass, $this->db_name, $this->db_port) or $this->output('critical', 'mysqli: '.mysqli_connect_error());
c71d4639 »
2012-09-14 5.0
99 mysqli_set_charset($this->mysqli, 'utf8') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
100 $query = @mysqli_query($this->mysqli, 'select `ruid` from `user_status` join `user_details` on `user_status`.`uid` = `user_details`.`uid` where `csnick` = \''.mysqli_real_escape_string($this->mysqli, $this->nick).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
51c21ef1 »
2009-12-04 comments, fix a small bug where the last seen date for users with mul…
101 $rows = mysqli_num_rows($query);
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
102
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
103 /**
104 * The user does not exist in the database.
105 */
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
106 if (empty($rows)) {
107 exit('No data.');
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
108 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
109
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
110 $result = mysqli_fetch_object($query);
111 $this->ruid = (int) $result->ruid;
0df6e4cb »
2011-06-03 as per request; more userstats
112 $query = @mysqli_query($this->mysqli, 'select (select `csnick` from `user_details` where `uid` = '.$this->ruid.') as `csnick`, min(`firstseen`) as `firstseen`, max(`lastseen`) as `lastseen`, `l_total`, (`l_total` / `activedays`) as `l_avg` from `user_details` join `user_status` on `user_details`.`uid` = `user_status`.`uid` join `q_lines` on `user_status`.`ruid` = `q_lines`.`ruid` where `user_status`.`ruid` = '.$this->ruid.' and `firstseen` != \'0000-00-00 00:00:00\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
113 $result = mysqli_fetch_object($query);
114
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
115 /**
116 * Exit if the user has no logged activity. Most functions don't expect to be run on an empty database so keep this check in place.
117 */
77842101 »
2011-04-12 some cleaning up and various query checks backward compatible with my…
118 if (empty($result->l_total)) {
803eb115 »
2011-05-12 remove unnecessary formatting
119 exit('No data.');
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
120 }
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
121
77842101 »
2011-04-12 some cleaning up and various query checks backward compatible with my…
122 $this->csnick = $result->csnick;
0dee1251 »
2010-08-08 base for sss3
123 $this->firstseen = $result->firstseen;
124 $this->lastseen = $result->lastseen;
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
125 $this->l_total = (int) $result->l_total;
77842101 »
2011-04-12 some cleaning up and various query checks backward compatible with my…
126 $this->l_avg = (float) $result->l_avg;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
127
128 /**
3b56f7c7 »
2010-08-17 put users mood (most used smiley) on their userpage
129 * Fetch the users mood.
130 */
f3efaccb »
2011-06-03 check for all smileys and also htmlspecialchars them
131 $query = @mysqli_query($this->mysqli, 'select * from `q_smileys` where `ruid` = '.$this->ruid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
3b56f7c7 »
2010-08-17 put users mood (most used smiley) on their userpage
132 $rows = mysqli_num_rows($query);
133
134 if (!empty($rows)) {
135 $result = mysqli_fetch_object($query);
136
137 foreach ($result as $key => $value) {
f3efaccb »
2011-06-03 check for all smileys and also htmlspecialchars them
138 $smileys_totals[$key] = (int) $value;
3b56f7c7 »
2010-08-17 put users mood (most used smiley) on their userpage
139 }
140
f3efaccb »
2011-06-03 check for all smileys and also htmlspecialchars them
141 arsort($smileys_totals);
3b56f7c7 »
2010-08-17 put users mood (most used smiley) on their userpage
142 $smileys = array(
07514653 »
2011-05-17 update user.php to display the new smileys
143 's_01' => ':)',
144 's_02' => ';)',
145 's_03' => ':(',
146 's_04' => ':P',
147 's_05' => ':D',
148 's_06' => ';(',
149 's_07' => ':/',
150 's_08' => '\\o/',
151 's_09' => ':))',
152 's_10' => '<3',
153 's_11' => ':o',
154 's_12' => '=)',
155 's_13' => ':-)',
156 's_14' => ':x',
157 's_15' => ':\\',
158 's_16' => 'D:',
159 's_17' => ':|',
160 's_18' => ';-)',
161 's_19' => ';P',
162 's_20' => '=]',
163 's_21' => ':3',
164 's_22' => '8)',
165 's_23' => ':<',
166 's_24' => ':>',
167 's_25' => '=P',
168 's_26' => ';x',
169 's_27' => ':-D',
170 's_28' => ';))',
171 's_29' => ':]',
172 's_30' => ';D',
173 's_31' => '-_-',
174 's_32' => ':S',
175 's_33' => '=/',
176 's_34' => '=\\',
177 's_35' => ':((',
178 's_36' => '=D',
179 's_37' => ':-/',
180 's_38' => ':-P',
181 's_39' => ';_;',
182 's_40' => ';/',
183 's_41' => ';]',
184 's_42' => ':-(',
185 's_43' => ':\'(',
186 's_44' => '=(',
187 's_45' => '-.-',
188 's_46' => ';((',
189 's_47' => '=X',
190 's_48' => ':[',
191 's_49' => '>:(',
192 's_50' => ';o');
f3efaccb »
2011-06-03 check for all smileys and also htmlspecialchars them
193
194 foreach ($smileys_totals as $key => $value) {
195 if ($key != 'ruid') {
196 $this->mood = htmlspecialchars($smileys[$key]);
197 break;
198 }
199 }
3b56f7c7 »
2010-08-17 put users mood (most used smiley) on their userpage
200 }
201
202 /**
c71d4639 »
2012-09-14 5.0
203 * Date and time variables used throughout the script. These are based on the date of the last logfile parsed and used to define our scope.
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
204 */
a2897c56 »
2012-09-08 cleanup queries
205 $query = @mysqli_query($this->mysqli, 'select max(`date`) as `date` from `parse_history`') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
ebe141f1 »
2010-07-08 dirty hacks so it works and we can test
206 $result = mysqli_fetch_object($query);
a2897c56 »
2012-09-08 cleanup queries
207 $this->date_lastlogparsed = $result->date;
62f5e2e7 »
2010-08-09 various small fixes and polishing
208 $this->dayofmonth = (int) date('j', strtotime($this->date_lastlogparsed));
209 $this->month = (int) date('n', strtotime($this->date_lastlogparsed));
210 $this->year = (int) date('Y', strtotime($this->date_lastlogparsed));
211 $this->years = $this->year - (int) date('Y', strtotime($this->firstseen)) + 1;
7a9fae41 »
2012-09-24 add year estimate to user stats
212 $this->daysleft = (int) date('z', strtotime('last day of December '.$this->year)) - (int) date('z', strtotime($this->date_lastlogparsed));
213 $this->currentyear = (int) date('Y');
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
214
215 /**
b96cff62 »
2010-05-03 optimize userstats, dont return before mysqli_close
216 * If we have less than 3 years of data we set the amount of years to 3 so we have that many columns in our table. Looks better.
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
217 */
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
218 if ($this->years < 3) {
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
219 $this->years = 3;
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
220 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
221
b96cff62 »
2010-05-03 optimize userstats, dont return before mysqli_close
222 /**
7a9fae41 »
2012-09-24 add year estimate to user stats
223 * If there are still days ahead of us in the current year, we try to calculate an estimated line count and display it in an additional column.
224 * Don't forget to add another 34px to the table width, a bit further down in the html head.
225 */
226 if ($this->daysleft != 0 && $this->year == $this->currentyear) {
227 /**
228 * We base our calculations on the activity of the last 90 days logged. If there is none we won't display the extra column.
229 */
230 $query = @mysqli_query($this->mysqli, 'select count(*) as `activity` from `q_activity_by_day` where `ruid` = '.$this->ruid.' and `date` > \''.date('Y-m-d', mktime(0, 0, 0, $this->month, $this->dayofmonth - 90, $this->year)).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
231 $result = mysqli_fetch_object($query);
232
233 if (!empty($result->activity)) {
234 $this->estimate = true;
235 }
236 }
237
238 /**
c9f2b985 »
2011-04-09 sync url check in topics with that of the words check, increase allow…
239 * HTML Head.
b96cff62 »
2010-05-03 optimize userstats, dont return before mysqli_close
240 */
a2897c56 »
2012-09-08 cleanup queries
241 $query = @mysqli_query($this->mysqli, 'select `date`, `l_total` from `q_activity_by_day` where `ruid` = '.$this->ruid.' order by `l_total` desc, `date` asc limit 1') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
b96cff62 »
2010-05-03 optimize userstats, dont return before mysqli_close
242 $result = mysqli_fetch_object($query);
a2897c56 »
2012-09-08 cleanup queries
243 $this->date_max = $result->date;
244 $this->l_max = (int) $result->l_total;
62f5e2e7 »
2010-08-09 various small fixes and polishing
245 $output = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">'."\n\n"
246 . '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">'."\n\n"
247 . '<head>'."\n".'<title>'.htmlspecialchars($this->csnick).', seriously.</title>'."\n"
3af12e10 »
2011-02-03 charset=utf-8
248 . '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />'."\n"
62f5e2e7 »
2010-08-09 various small fixes and polishing
249 . '<meta http-equiv="Content-Style-Type" content="text/css" />'."\n"
250 . '<link rel="stylesheet" type="text/css" href="'.$this->stylesheet.'" />'."\n"
251 . '<style type="text/css">'."\n"
7a9fae41 »
2012-09-24 add year estimate to user stats
252 . ' .act-year {width:'.(2 + (($this->years + ($this->estimate ? 1 : 0)) * 34)).'px}'."\n"
62f5e2e7 »
2010-08-09 various small fixes and polishing
253 . '</style>'."\n"
254 . '</head>'."\n\n".'<body>'."\n"
4696ad4b »
2011-04-05 syncing with latest boring commit
255 . '<div class="box">'."\n"
a34a753b »
2011-05-07 have user.php accept n=nick instead of uid=123
256 . "\n".'<div class="info">'.htmlspecialchars($this->csnick).', seriously'.($this->mood != '' ? ' '.$this->mood : '.').'<br /><br />First seen on '.date('M j, Y', strtotime($this->firstseen)).' and last seen on '.date('M j, Y', strtotime($this->lastseen)).'.<br />'
0df6e4cb »
2011-06-03 as per request; more userstats
257 . '<br />'.htmlspecialchars($this->csnick).' typed '.number_format($this->l_total).' line'.($this->l_total > 1 ? 's' : '').' on <a href="'.$this->mainpage.'">'.htmlspecialchars($this->channel).'</a> &ndash; an average of '.number_format($this->l_avg).' line'.($this->l_avg > 1 ? 's' : '').' per day.<br />Most active day was '.date('M j, Y', strtotime($this->date_max)).' with a total of '.number_format($this->l_max).' line'.($this->l_max > 1 ? 's' : '').' typed.</div>'."\n";
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
258
259 /**
c9f2b985 »
2011-04-09 sync url check in topics with that of the words check, increase allow…
260 * Activity section.
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
261 */
4696ad4b »
2011-04-05 syncing with latest boring commit
262 $output .= "\n".'<div class="head">Activity</div>'."\n";
ad076fdc »
2011-05-13 rename to match other classes
263 $output .= $this->make_table_activity_distribution_hour();
401a4730 »
2011-05-13 sync make_table_activity
264 $output .= $this->make_table_activity('day');
265 $output .= $this->make_table_activity('month');
ad076fdc »
2011-05-13 rename to match other classes
266 $output .= $this->make_table_activity_distribution_day();
401a4730 »
2011-05-13 sync make_table_activity
267 $output .= $this->make_table_activity('year');
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
268
269 /**
c9f2b985 »
2011-04-09 sync url check in topics with that of the words check, increase allow…
270 * HTML Foot.
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
271 */
96cc7050 »
2011-05-09 make GitHub the new home for the project
272 $output .= "\n".'<div class="info">Statistics created with <a href="https://github.com/tommyrot/superseriousstats">superseriousstats</a> on '.date('r').'.</div>'."\n";
4696ad4b »
2011-04-05 syncing with latest boring commit
273 $output .= "\n".'</div>'."\n".'</body>'."\n\n".'</html>'."\n";
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
274 @mysqli_close($this->mysqli);
62f5e2e7 »
2010-08-09 various small fixes and polishing
275 return $output;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
276 }
277
0dee1251 »
2010-08-08 base for sss3
278 private function make_table_activity($type)
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
279 {
401a4730 »
2011-05-13 sync make_table_activity
280 if ($type == 'day') {
3d8cdb67 »
2011-05-17 sync css naming with new table names
281 $class = 'act';
c71d4639 »
2012-09-14 5.0
282 $columns = 24;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
283
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
284 for ($i = 23; $i >= 0; $i--) {
0dee1251 »
2010-08-08 base for sss3
285 $dates[] = date('Y-m-d', mktime(0, 0, 0, $this->month, $this->dayofmonth - $i, $this->year));
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
286 }
287
401a4730 »
2011-05-13 sync make_table_activity
288 $head = 'Activity by Day';
289 $query = @mysqli_query($this->mysqli, 'select `date`, `l_total`, `l_night`, `l_morning`, `l_afternoon`, `l_evening` from `q_activity_by_day` where `ruid` = '.$this->ruid.' and `date` > \''.date('Y-m-d', mktime(0, 0, 0, $this->month, $this->dayofmonth - 24, $this->year)).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
290 } elseif ($type == 'month') {
3d8cdb67 »
2011-05-17 sync css naming with new table names
291 $class = 'act';
c71d4639 »
2012-09-14 5.0
292 $columns = 24;
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
293
294 for ($i = 23; $i >= 0; $i--) {
295 $dates[] = date('Y-m', mktime(0, 0, 0, $this->month - $i, 1, $this->year));
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
296 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
297
401a4730 »
2011-05-13 sync make_table_activity
298 $head = 'Activity by Month';
299 $query = @mysqli_query($this->mysqli, 'select `date`, `l_total`, `l_night`, `l_morning`, `l_afternoon`, `l_evening` from `q_activity_by_month` where `ruid` = '.$this->ruid.' and `date` > \''.date('Y-m', mktime(0, 0, 0, $this->month - 24, 1, $this->year)).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
300 } elseif ($type == 'year') {
3d8cdb67 »
2011-05-17 sync css naming with new table names
301 $class = 'act-year';
c71d4639 »
2012-09-14 5.0
302 $columns = $this->years;
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
303
304 for ($i = $this->years - 1; $i >= 0; $i--) {
305 $dates[] = $this->year - $i;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
306 }
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
307
7a9fae41 »
2012-09-24 add year estimate to user stats
308 if ($this->estimate) {
309 $columns++;
310 $dates[] = 'estimate';
311 }
312
401a4730 »
2011-05-13 sync make_table_activity
313 $head = 'Activity by Year';
0dee1251 »
2010-08-08 base for sss3
314 $query = @mysqli_query($this->mysqli, 'select `date`, `l_total`, `l_night`, `l_morning`, `l_afternoon`, `l_evening` from `q_activity_by_year` where `ruid` = '.$this->ruid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
315 }
316
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
317 $rows = mysqli_num_rows($query);
318
401a4730 »
2011-05-13 sync make_table_activity
319 /**
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
320 * The queries above will either return one or more rows with activity, or no rows at all.
401a4730 »
2011-05-13 sync make_table_activity
321 */
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
322 if (empty($rows)) {
c71d4639 »
2012-09-14 5.0
323 return null;
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
324 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
325
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
326 $high_date = '';
327 $high_value = 0;
328
329 while ($result = mysqli_fetch_object($query)) {
330 $l_night[$result->date] = (int) $result->l_night;
331 $l_morning[$result->date] = (int) $result->l_morning;
332 $l_afternoon[$result->date] = (int) $result->l_afternoon;
333 $l_evening[$result->date] = (int) $result->l_evening;
62f5e2e7 »
2010-08-09 various small fixes and polishing
334 $l_total[$result->date] = (int) $result->l_total;
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
335
62f5e2e7 »
2010-08-09 various small fixes and polishing
336 if ($l_total[$result->date] > $high_value) {
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
337 $high_date = $result->date;
62f5e2e7 »
2010-08-09 various small fixes and polishing
338 $high_value = $l_total[$result->date];
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
339 }
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
340 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
341
7a9fae41 »
2012-09-24 add year estimate to user stats
342 if ($this->estimate && $type == 'year') {
343 $query = @mysqli_query($this->mysqli, 'select (sum(`l_night`) / 90) as `l_night_avg`, (sum(`l_morning`) / 90) as `l_morning_avg`, (sum(`l_afternoon`) / 90) as `l_afternoon_avg`, (sum(`l_evening`) / 90) as `l_evening_avg`, (sum(`l_total`) / 90) as `l_total_avg` from `q_activity_by_day` where `ruid` = '.$this->ruid.' and `date` > \''.date('Y-m-d', mktime(0, 0, 0, $this->month, $this->dayofmonth - 90, $this->year)).'\'') or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
344 $result = mysqli_fetch_object($query);
345 $l_night['estimate'] = $l_night[$this->currentyear] + round((float) $result->l_night_avg * $this->daysleft);
346 $l_morning['estimate'] = $l_morning[$this->currentyear] + round((float) $result->l_morning_avg * $this->daysleft);
347 $l_afternoon['estimate'] = $l_afternoon[$this->currentyear] + round((float) $result->l_afternoon_avg * $this->daysleft);
348 $l_evening['estimate'] = $l_evening[$this->currentyear] + round((float) $result->l_evening_avg * $this->daysleft);
349 $l_total['estimate'] = $l_total[$this->currentyear] + round((float) $result->l_total_avg * $this->daysleft);
350
351 if ($l_total['estimate'] > $high_value) {
352 $high_date = 'estimate';
353 $high_value = $l_total['estimate'];
354 }
355 }
356
c71d4639 »
2012-09-14 5.0
357 $tr1 = '<tr><th colspan="'.$columns.'">'.$head.'</th></tr>';
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
358 $tr2 = '<tr class="bars">';
359 $tr3 = '<tr class="sub">';
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
360
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
361 foreach ($dates as $date) {
aaf38ec5 »
2010-08-03 solve some php warnings concerning undefined indexes
362 if (!array_key_exists($date, $l_total) || $l_total[$date] == 0) {
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
363 $tr2 .= '<td><span class="grey">n/a</span></td>';
364 } else {
365 if ($l_total[$date] >= 999500) {
7a9fae41 »
2012-09-24 add year estimate to user stats
366 if ($date == 'estimate') {
30efef0b »
2012-09-24 use css opacity instead of dirty hacks
367 $tr2 .= '<td class="est"><span class="grey">'.number_format($l_total[$date] / 1000000, 1).'M</span>';
7a9fae41 »
2012-09-24 add year estimate to user stats
368 } else {
369 $tr2 .= '<td>'.number_format($l_total[$date] / 1000000, 1).'M';
370 }
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
371 } elseif ($l_total[$date] >= 10000) {
7a9fae41 »
2012-09-24 add year estimate to user stats
372 if ($date == 'estimate') {
30efef0b »
2012-09-24 use css opacity instead of dirty hacks
373 $tr2 .= '<td class="est"><span class="grey">'.round($l_total[$date] / 1000).'K</span>';
7a9fae41 »
2012-09-24 add year estimate to user stats
374 } else {
375 $tr2 .= '<td>'.round($l_total[$date] / 1000).'K';
376 }
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
377 } else {
7a9fae41 »
2012-09-24 add year estimate to user stats
378 if ($date == 'estimate') {
30efef0b »
2012-09-24 use css opacity instead of dirty hacks
379 $tr2 .= '<td class="est"><span class="grey">'.$l_total[$date].'</span>';
7a9fae41 »
2012-09-24 add year estimate to user stats
380 } else {
381 $tr2 .= '<td>'.$l_total[$date];
382 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
383 }
384
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
385 $times = array('evening', 'afternoon', 'morning', 'night');
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
386
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
387 foreach ($times as $time) {
388 if (${'l_'.$time}[$date] != 0) {
389 $height = round((${'l_'.$time}[$date] / $high_value) * 100);
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
390
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
391 if ($height != 0) {
30efef0b »
2012-09-24 use css opacity instead of dirty hacks
392 $tr2 .= '<img src="'.$this->{'bar_'.$time}.'" height="'.$height.'" alt="" title="" />';
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
393 }
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
394 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
395 }
396
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
397 $tr2 .= '</td>';
c6334349 »
2010-07-21 sync fixes to user.php
398 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
399
401a4730 »
2011-05-13 sync make_table_activity
400 if ($type == 'day') {
c6334349 »
2010-07-21 sync fixes to user.php
401 if ($high_date == $date) {
402 $tr3 .= '<td class="bold">'.date('D', strtotime($date)).'<br />'.date('j', strtotime($date)).'</td>';
403 } else {
404 $tr3 .= '<td>'.date('D', strtotime($date)).'<br />'.date('j', strtotime($date)).'</td>';
405 }
401a4730 »
2011-05-13 sync make_table_activity
406 } elseif ($type == 'month') {
c6334349 »
2010-07-21 sync fixes to user.php
407 if ($high_date == $date) {
408 $tr3 .= '<td class="bold">'.date('M', strtotime($date.'-01')).'<br />'.date('\'y', strtotime($date.'-01')).'</td>';
409 } else {
410 $tr3 .= '<td>'.date('M', strtotime($date.'-01')).'<br />'.date('\'y', strtotime($date.'-01')).'</td>';
411 }
401a4730 »
2011-05-13 sync make_table_activity
412 } elseif ($type == 'year') {
c6334349 »
2010-07-21 sync fixes to user.php
413 if ($high_date == $date) {
7a9fae41 »
2012-09-24 add year estimate to user stats
414 if ($date == 'estimate') {
415 $tr3 .= '<td class="bold">Est.</td>';
416 } else {
417 $tr3 .= '<td class="bold">'.date('\'y', strtotime($date.'-01-01')).'</td>';
418 }
c6334349 »
2010-07-21 sync fixes to user.php
419 } else {
7a9fae41 »
2012-09-24 add year estimate to user stats
420 if ($date == 'estimate') {
421 $tr3 .= '<td>Est.</td>';
422 } else {
423 $tr3 .= '<td>'.date('\'y', strtotime($date.'-01-01')).'</td>';
424 }
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
425 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
426 }
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
427 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
428
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
429 $tr2 .= '</tr>';
430 $tr3 .= '</tr>';
431 return '<table class="'.$class.'">'.$tr1.$tr2.$tr3.'</table>'."\n";
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
432 }
433
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
434 private function make_table_activity_distribution_day()
401a4730 »
2011-05-13 sync make_table_activity
435 {
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
436 $query = @mysqli_query($this->mysqli, 'select `l_mon_night`, `l_mon_morning`, `l_mon_afternoon`, `l_mon_evening`, `l_tue_night`, `l_tue_morning`, `l_tue_afternoon`, `l_tue_evening`, `l_wed_night`, `l_wed_morning`, `l_wed_afternoon`, `l_wed_evening`, `l_thu_night`, `l_thu_morning`, `l_thu_afternoon`, `l_thu_evening`, `l_fri_night`, `l_fri_morning`, `l_fri_afternoon`, `l_fri_evening`, `l_sat_night`, `l_sat_morning`, `l_sat_afternoon`, `l_sat_evening`, `l_sun_night`, `l_sun_morning`, `l_sun_afternoon`, `l_sun_evening` from `q_lines` where `ruid` = '.$this->ruid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
401a4730 »
2011-05-13 sync make_table_activity
437 $result = mysqli_fetch_object($query);
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
438 $high_day = '';
401a4730 »
2011-05-13 sync make_table_activity
439 $high_value = 0;
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
440 $days = array('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun');
401a4730 »
2011-05-13 sync make_table_activity
441
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
442 foreach ($days as $day) {
443 $l_night[$day] = (int) $result->{'l_'.$day.'_night'};
444 $l_morning[$day] = (int) $result->{'l_'.$day.'_morning'};
445 $l_afternoon[$day] = (int) $result->{'l_'.$day.'_afternoon'};
446 $l_evening[$day] = (int) $result->{'l_'.$day.'_evening'};
447 $l_total[$day] = $l_night[$day] + $l_morning[$day] + $l_afternoon[$day] + $l_evening[$day];
448
449 if ($l_total[$day] > $high_value) {
450 $high_day = $day;
451 $high_value = $l_total[$day];
401a4730 »
2011-05-13 sync make_table_activity
452 }
453 }
454
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
455 $tr1 = '<tr><th colspan="7">Activity Distribution by Day</th></tr>';
401a4730 »
2011-05-13 sync make_table_activity
456 $tr2 = '<tr class="bars">';
457 $tr3 = '<tr class="sub">';
458
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
459 foreach ($days as $day) {
460 if ($l_total[$day] == 0) {
401a4730 »
2011-05-13 sync make_table_activity
461 $tr2 .= '<td><span class="grey">n/a</span></td>';
462 } else {
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
463 $perc = ($l_total[$day] / $this->l_total) * 100;
401a4730 »
2011-05-13 sync make_table_activity
464
465 if ($perc >= 9.95) {
466 $tr2 .= '<td>'.round($perc).'%';
467 } else {
468 $tr2 .= '<td>'.number_format($perc, 1).'%';
469 }
470
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
471 $times = array('evening', 'afternoon', 'morning', 'night');
401a4730 »
2011-05-13 sync make_table_activity
472
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
473 foreach ($times as $time) {
474 if (${'l_'.$time}[$day] != 0) {
475 $height = round((${'l_'.$time}[$day] / $high_value) * 100);
476
477 if ($height != 0) {
478 $tr2 .= '<img src="'.$this->{'bar_'.$time}.'" height="'.$height.'" alt="" title="'.number_format($l_total[$day]).'" />';
479 }
401a4730 »
2011-05-13 sync make_table_activity
480 }
481 }
482
483 $tr2 .= '</td>';
484 }
485
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
486 if ($high_day == $day) {
487 $tr3 .= '<td class="bold">'.ucfirst($day).'</td>';
401a4730 »
2011-05-13 sync make_table_activity
488 } else {
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
489 $tr3 .= '<td>'.ucfirst($day).'</td>';
401a4730 »
2011-05-13 sync make_table_activity
490 }
491 }
492
493 $tr2 .= '</tr>';
494 $tr3 .= '</tr>';
3d8cdb67 »
2011-05-17 sync css naming with new table names
495 return '<table class="act-day">'.$tr1.$tr2.$tr3.'</table>'."\n";
401a4730 »
2011-05-13 sync make_table_activity
496 }
497
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
498 private function make_table_activity_distribution_hour()
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
499 {
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
500 $query = @mysqli_query($this->mysqli, 'select `l_00`, `l_01`, `l_02`, `l_03`, `l_04`, `l_05`, `l_06`, `l_07`, `l_08`, `l_09`, `l_10`, `l_11`, `l_12`, `l_13`, `l_14`, `l_15`, `l_16`, `l_17`, `l_18`, `l_19`, `l_20`, `l_21`, `l_22`, `l_23` from `q_lines` where `ruid` = '.$this->ruid) or $this->output('critical', 'mysqli: '.mysqli_error($this->mysqli));
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
501 $result = mysqli_fetch_object($query);
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
502 $high_key = '';
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
503 $high_value = 0;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
504
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
505 foreach ($result as $key => $value) {
506 if ((int) $value > $high_value) {
507 $high_key = $key;
508 $high_value = (int) $value;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
509 }
510 }
511
759c3383 »
2011-05-14 sync make_table_activity_distribution_hour
512 $tr1 = '<tr><th colspan="24">Activity Distribution by Hour</th></tr>';
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
513 $tr2 = '<tr class="bars">';
514 $tr3 = '<tr class="sub">';
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
515
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
516 foreach ($result as $key => $value) {
759c3383 »
2011-05-14 sync make_table_activity_distribution_hour
517 $hour = (int) preg_replace('/^l_0?/', '', $key);
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
518
519 if ((int) $value == 0) {
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
520 $tr2 .= '<td><span class="grey">n/a</span></td>';
521 } else {
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
522 $perc = ((int) $value / $this->l_total) * 100;
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
523
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
524 if ($perc >= 9.95) {
525 $tr2 .= '<td>'.round($perc).'%';
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
526 } else {
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
527 $tr2 .= '<td>'.number_format($perc, 1).'%';
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
528 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
529
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
530 $height = round(((int) $value / $high_value) * 100);
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
531
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
532 if ($height != 0) {
533 if ($hour >= 0 && $hour <= 5) {
534 $tr2 .= '<img src="'.$this->bar_night.'" height="'.$height.'" alt="" title="'.number_format((int) $value).'" />';
535 } elseif ($hour >= 6 && $hour <= 11) {
536 $tr2 .= '<img src="'.$this->bar_morning.'" height="'.$height.'" alt="" title="'.number_format((int) $value).'" />';
537 } elseif ($hour >= 12 && $hour <= 17) {
538 $tr2 .= '<img src="'.$this->bar_afternoon.'" height="'.$height.'" alt="" title="'.number_format((int) $value).'" />';
539 } elseif ($hour >= 18 && $hour <= 23) {
540 $tr2 .= '<img src="'.$this->bar_evening.'" height="'.$height.'" alt="" title="'.number_format((int) $value).'" />';
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
541 }
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
542 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
543
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
544 $tr2 .= '</td>';
c6334349 »
2010-07-21 sync fixes to user.php
545 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
546
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
547 if ($high_key == $key) {
548 $tr3 .= '<td class="bold">'.$hour.'h</td>';
c6334349 »
2010-07-21 sync fixes to user.php
549 } else {
5533f128 »
2011-05-14 sync make_table_activity_distribution_day
550 $tr3 .= '<td>'.$hour.'h</td>';
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
551 }
552 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
553
1962c28b »
2010-07-21 sync user.php with optimized HTML output code; update queries
554 $tr2 .= '</tr>';
555 $tr3 .= '</tr>';
3d8cdb67 »
2011-05-17 sync css naming with new table names
556 return '<table class="act">'.$tr1.$tr2.$tr3.'</table>'."\n";
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
557 }
3e0598ac »
2011-05-14 trivial structure changes
558
559 /**
c71d4639 »
2012-09-14 5.0
560 * For compatibility reasons this function has the same name as the original version in the base class and accepts the same arguments. Its functionality
561 * is slightly different in that it exits on any type of message passed to it.
3e0598ac »
2011-05-14 trivial structure changes
562 */
563 private function output($type, $msg)
564 {
565 /**
566 * If $debug is set to true we exit with the given message, otherwise exit silently.
567 */
568 if ($this->debug) {
569 exit($msg);
570 } else {
571 exit;
572 }
573 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
574 }
575
70b3da7d »
2011-05-09 do some stricter input variable checks and format the code in a way t…
576 /**
577 * If the channel ID is not set, empty, or has the value "__global" we exit.
578 */
579 if (!isset($_GET['cid']) || !preg_match('/^\S+$/', $_GET['cid']) || preg_match('/^__global$/', $_GET['cid'])) {
580 exit;
a34c6b94 »
2009-12-09 added curly brackets in all places to increase readability
581 }
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
582
70b3da7d »
2011-05-09 do some stricter input variable checks and format the code in a way t…
583 $cid = $_GET['cid'];
584
585 /**
586 * If nick is not set, empty, or has an erroneous value we also exit.
587 */
588 if (!isset($_GET['nick']) || !preg_match('/^[][^{}|\\\`_0-9a-z-]{1,255}$/i', $_GET['nick'])) {
589 exit;
590 }
591
592 $nick = $_GET['nick'];
593
594 /**
595 * Create the statspage!
596 */
597 $user = new user($cid, $nick);
598 echo $user->make_html();
599
cb5c74dd »
2009-10-30 userstats: shows activity graphs for a given user
600 ?>
Something went wrong with that request. Please try again.