1 | <?php |
---|
2 | |
---|
3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
4 | global $conf; |
---|
5 | |
---|
6 | /* Secure Config */ |
---|
7 | |
---|
8 | $conf_whois = whois_online_conf(); |
---|
9 | |
---|
10 | function whois_online_conf() |
---|
11 | { |
---|
12 | global $conf; |
---|
13 | $conf_whois = unserialize($conf['Whois Online']); |
---|
14 | if (!isset($conf_whois['Active'])) $conf_whois['Active'] = true; |
---|
15 | if (!isset($conf_whois['Delete level'])) $conf_whois['Delete level'] = 20; |
---|
16 | if (!isset($conf_whois['Radar limit'])) $conf_whois['Radar limit'] = 25; |
---|
17 | if (!isset($conf_whois['Webmasters'])) $conf_whois['Webmasters'] = 2; |
---|
18 | if (!isset($conf_whois['Administrators'])) $conf_whois['Administrators'] = 2; |
---|
19 | if (!isset($conf_whois['Obsolete limit'])) $conf_whois['Obsolete limit'] = 20; |
---|
20 | if (!isset($conf_whois['Add to Plugins menu'])) $conf_whois['Add to Plugins menu'] = false; |
---|
21 | if (!isset($conf_whois['Add icon to History'])) $conf_whois['Add icon to History'] = true; |
---|
22 | if (!isset($conf_whois['Keep data'])) $conf_whois['Keep data'] = true; |
---|
23 | if (!isset($conf_whois['Default display'])) $conf_whois['Default display'] = true; |
---|
24 | if (!isset($conf_whois['Search id'])) $conf_whois['Search id'] = 0; |
---|
25 | if (!isset($conf_whois['Users'])) |
---|
26 | $conf_whois['Users'] = Array('max' => 0, 'When' => date('Y-m-d'), 'count' => 0); |
---|
27 | if ((!isset($conf_whois['Version'])) or $conf_whois['Version'] != WHOIS_ONLINE_VER |
---|
28 | or $conf['Whois Online'] != serialize($conf_whois)) { |
---|
29 | $conf_whois['Version'] = WHOIS_ONLINE_VER; |
---|
30 | $conf['Whois Online'] = serialize($conf_whois); |
---|
31 | pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) |
---|
32 | VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); |
---|
33 | } |
---|
34 | return $conf_whois; |
---|
35 | } |
---|
36 | |
---|
37 | define('ONLINE_LEVEL', (100+$conf_whois['Delete level'])/100); |
---|
38 | define('ONLINE_LIMIT', $conf_whois['Obsolete limit']); |
---|
39 | |
---|
40 | /* Admin menus are always available */ |
---|
41 | $conf['Add to Plugins menu'] = $conf_whois['Add to Plugins menu']; |
---|
42 | $conf['Add icon to History'] = $conf_whois['Add icon to History']; |
---|
43 | add_event_handler('get_admin_plugin_menu_links', 'whois_add_icon' ); |
---|
44 | /* On Active */ |
---|
45 | if ($conf_whois['Active']) { |
---|
46 | $conf['Whois Online Update'] = true; |
---|
47 | add_event_handler('loc_begin_picture', 'whois_online_management'); |
---|
48 | add_event_handler('loc_begin_index', 'whois_online_management'); |
---|
49 | add_event_handler('register_user', 'whois_online_register'); |
---|
50 | if ($conf_whois['Default display'] or (defined('IN_ADMIN') and IN_ADMIN)) add_event_handler('loc_begin_page_tail', 'whois_default_display' ); |
---|
51 | } |
---|
52 | |
---|
53 | /* --------------- Functions ----------------- */ |
---|
54 | |
---|
55 | // pparse whois_online/default.tpl |
---|
56 | function whois_default_display() { |
---|
57 | global $template; |
---|
58 | $template->set_filenames(array( 'Whois_display' => dirname(__FILE__).'/default.tpl')); |
---|
59 | $template->pparse('Whois_display'); |
---|
60 | // Based on get_enums(USER_INFOS_TABLE, 'status') ??? |
---|
61 | } |
---|
62 | |
---|
63 | // Add admin links |
---|
64 | function whois_add_icon($menu) { |
---|
65 | global $conf, $lang; |
---|
66 | if ($conf['Add icon to History']) |
---|
67 | $lang['History'] .= '</a> <a class="external" href="' . get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php') . '"> |
---|
68 | <img class="button" src="' . WHOIS_ONLINE_PATH . 'icons/Whois_tuner.gif" alt="Whois Online configuration" title="Whois Online configuration" /></a>'; |
---|
69 | if ($conf['Add to Plugins menu']) array_push($menu, array( |
---|
70 | 'NAME' => 'Whois Online', |
---|
71 | 'URL' => get_admin_plugin_menu_link(WHOIS_ONLINE_PATH.'config.php'), |
---|
72 | )); |
---|
73 | return $menu; |
---|
74 | } |
---|
75 | |
---|
76 | // Template function |
---|
77 | function Whois_most($text, $count, $when, $format) { |
---|
78 | return sprintf(l10n($text),$count,date(l10n($format),$when)); |
---|
79 | } |
---|
80 | |
---|
81 | // New member |
---|
82 | function whois_online_register($who) { |
---|
83 | global $conf, $conf_whois; |
---|
84 | $conf_whois['Users']['count'] = $who['id']; |
---|
85 | $conf['Whois Online'] = serialize($conf_whois); |
---|
86 | pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) |
---|
87 | VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); |
---|
88 | return; |
---|
89 | } |
---|
90 | |
---|
91 | function whois_country($trace, $bypass = false) { |
---|
92 | if (!isset($trace['country'])) { |
---|
93 | pwg_query('ALTER TABLE ' . WHOIS_ONLINE_TABLE . ' ADD `country` VARCHAR( 256 ) NOT NULL AFTER `lang` ;'); |
---|
94 | $trace['country']=''; |
---|
95 | } |
---|
96 | $c = array(); |
---|
97 | if ($trace['country']!='') $c = @unserialize(htmlspecialchars_decode($trace['country'])); |
---|
98 | if (isset($c['Code']) and $c['Code']!='' and $c['Code']!='__') return $c; |
---|
99 | if ($bypass and isset($c['Code']) and $c['Code']=='__') return $c; |
---|
100 | $f = @fopen ('http://api.hostip.info/get_html.php?ip=' . $trace['IP'], 'r'); |
---|
101 | if ($f === FALSE) return Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); |
---|
102 | $result=''; |
---|
103 | while ($l = fgets ($f, 1024)) $result .= $l; |
---|
104 | fclose ($f); |
---|
105 | $tokens = split ("[:\n]", $result); |
---|
106 | $c = array ('Name' => $tokens[1], 'City' => $tokens[3]); |
---|
107 | if (strpos ($c['Name'], '?') === FALSE) { |
---|
108 | $tokens = split ("[\(\)]", $c['Name']); |
---|
109 | $c['Code'] = isset($tokens[1]) ? $tokens[1]:'__'; |
---|
110 | $c['Name'] = ucwords ( strtolower( ereg_replace |
---|
111 | (' \([^\)]+)', '', $c['Name']))); |
---|
112 | } |
---|
113 | else $c = Array('Code' => '__', 'Name' => l10n('Unknown country'), 'City' => 'N/A',); |
---|
114 | if ($c['Code'] == 'Private Address') { |
---|
115 | $c['Name'] = l10n('Private Address'); |
---|
116 | $c['City'] = l10n('N/A'); |
---|
117 | $c['Code'] = '__'; |
---|
118 | } |
---|
119 | pwg_query('UPDATE ' . WHOIS_ONLINE_TABLE . ' |
---|
120 | SET `country` = \'' . htmlspecialchars(serialize($c),ENT_QUOTES,'UTF-8') . '\' |
---|
121 | WHERE `session_id` = \'' . $trace['session_id'] . '\';'); |
---|
122 | return $c; |
---|
123 | } |
---|
124 | |
---|
125 | function whois_flag($trace, &$step, $limit = 10) { |
---|
126 | $flag = WHOIS_ONLINE_PATH . 'flags/' . $trace['Country']['Code'] . '.jpg'; |
---|
127 | if (file_exists($flag)) return $flag; |
---|
128 | if ( $step > $limit ) return WHOIS_ONLINE_PATH . 'flags/__.jpg'; |
---|
129 | $f = fopen ('http://api.hostip.info/flag.php?ip=' . $trace['IP'], 'r'); |
---|
130 | $result=''; |
---|
131 | while ($l = fgets ($f, 1024)) $result .= $l; |
---|
132 | fclose ($f); |
---|
133 | $f = fopen($flag,"w+"); |
---|
134 | fputs($f,$result); |
---|
135 | fclose($f); |
---|
136 | return $flag; |
---|
137 | } |
---|
138 | |
---|
139 | // Read all data |
---|
140 | function whois_online_get_data($order='') { |
---|
141 | $remove = "''"; // Nothing to remove ( = an empty session_id) |
---|
142 | $ctr = 0; $Online[0] = ''; |
---|
143 | $result = pwg_query('SELECT * FROM ' . WHOIS_ONLINE_TABLE . $order . ';'); |
---|
144 | while($row=mysql_fetch_array($result)) { |
---|
145 | $row['delay'] = (int) time() - $row['last_access']; |
---|
146 | $row['elm_ids'] = explode(' ', $row['last_elm_ids']); |
---|
147 | $row['cat_ids'] = explode(' ', $row['last_cat_ids']); |
---|
148 | $row['tag_ids'] = explode(' ', $row['last_tag_ids']); |
---|
149 | $row['sch_ids'] = explode(' ', $row['last_sch_ids']); |
---|
150 | $row['dates'] = explode(' ', $row['last_dates']); |
---|
151 | $ctr++; |
---|
152 | if ( $row['IP'] != 'global' and $row['permanent'] == 'false' |
---|
153 | and $row['delay'] > (float)( 60 * 60 * 24 * 3 )) $remove .= ", '" . $row['session_id'] . "'"; |
---|
154 | elseif ($row['IP'] == 'global') $Online[0] = $row; |
---|
155 | else $Online[] = $row; |
---|
156 | } |
---|
157 | // Out of 7 visits: Reduce registered visits for 3 days without access |
---|
158 | if ($remove != "''" and $ctr > (count($Online) * ONLINE_LEVEL) |
---|
159 | and ($ctr-count($Online)) > ONLINE_LIMIT and ($Online[0]['pag_hits']%7)==0) { |
---|
160 | pwg_query('DELETE FROM ' . WHOIS_ONLINE_TABLE . ' WHERE `session_id` IN ('. $remove .') |
---|
161 | AND `permanent` = \'false\' AND `IP` <> \'global\';'); |
---|
162 | if (($Online[0]['pag_hits']%13)==0) @pwg_query('OPTIMIZE TABLE ' . WHOIS_ONLINE_TABLE . ';'); |
---|
163 | } |
---|
164 | return $Online; |
---|
165 | } |
---|
166 | |
---|
167 | // Update global and update/create current session_id |
---|
168 | function whois_online_update(&$global, &$dedicated, &$gtrace) |
---|
169 | { |
---|
170 | global $lang_info; |
---|
171 | // Rewrite the global record |
---|
172 | if ( $gtrace == 2 ) { |
---|
173 | $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, |
---|
174 | `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`, |
---|
175 | `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`) |
---|
176 | VALUES (\'global\', \'true\',\'global\', 0, \''. $global['username'] .'\', \'--\', \'true\', \'' |
---|
177 | . time() .'\', \'' |
---|
178 | . implode(' ',$global['elm_ids']) . '\', \'' |
---|
179 | . implode(' ',$global['cat_ids']) . '\', \'' |
---|
180 | . implode(' ',$global['tag_ids']) . '\', \'' |
---|
181 | . implode(' ',$global['sch_ids']) . '\', \'' |
---|
182 | . $global['first_access_date'] . '\', \'\', \'' |
---|
183 | . $global['elm_hits'] . '\', \'' . $global['pag_hits'] . '\');'; |
---|
184 | pwg_query($query); |
---|
185 | } |
---|
186 | // Write or Rewrite the dedicated record |
---|
187 | $query = 'REPLACE INTO ' . WHOIS_ONLINE_TABLE . ' (`IP`, `hidden_IP`, `session_id`,`user_id`,`username`,`lang`, |
---|
188 | `permanent`,`last_access`,`last_elm_ids`, `last_cat_ids`, `last_tag_ids`, `last_sch_ids`, |
---|
189 | `first_access_date`, `last_dates`, `elm_hits`, `pag_hits`) |
---|
190 | VALUES (\''. $dedicated['IP'] .'\', \'' |
---|
191 | . $dedicated['hidden_IP'] .'\', \''. $dedicated['session_id'] .'\', \'' |
---|
192 | . $dedicated['user_id'] .'\', \''. $dedicated['username'] .'\', \'' |
---|
193 | . substr($lang_info['code'],0,2) .'\', \'' |
---|
194 | . $dedicated['permanent'] . '\', \''. time() .'\', \'' |
---|
195 | . implode(' ',$dedicated['elm_ids']) . '\', \'' |
---|
196 | . implode(' ',$dedicated['cat_ids']) . '\', \'' |
---|
197 | . implode(' ',$dedicated['tag_ids']) . '\', \'' |
---|
198 | . implode(' ',$dedicated['sch_ids']) . '\', \'' |
---|
199 | . $dedicated['first_access_date'] . '\', \'' |
---|
200 | . implode(' ',$dedicated['dates']) . '\', \'' |
---|
201 | . $dedicated['elm_hits'] . '\', \'' |
---|
202 | . $dedicated['pag_hits'] . '\');'; |
---|
203 | pwg_query($query); |
---|
204 | } |
---|
205 | |
---|
206 | // Data tracking |
---|
207 | // Parameters: |
---|
208 | // - Array of Ids |
---|
209 | // - New ID |
---|
210 | // - Array of dates |
---|
211 | // => Add the ID if needed, Add Today if needed |
---|
212 | function whois_online_track(&$key, $id, &$date) { |
---|
213 | if ($id != '') array_unshift($key, $id); |
---|
214 | $key = array_unique($key); |
---|
215 | if (count($key)>10) array_pop($key); |
---|
216 | array_unshift($date, date('Y-m-d')); |
---|
217 | $date = array_unique($date); |
---|
218 | if (count($date)>5) array_pop($date); |
---|
219 | return; |
---|
220 | } |
---|
221 | |
---|
222 | /* |
---|
223 | Main process: Analyze, set new values and prepare displayed values. |
---|
224 | |
---|
225 | Update on parameter... |
---|
226 | */ |
---|
227 | function whois_online_management() |
---|
228 | { |
---|
229 | global $user, $conf, $conf_whois, $template, $page, $lang, $lang_info; |
---|
230 | load_language('plugin.lang', WHOIS_ONLINE_PATH); |
---|
231 | srand((float)time()); |
---|
232 | |
---|
233 | pwg_debug('*********** start Online_management ***********'); |
---|
234 | if (!isset($conf_whois['Active'])) $conf_whois = whois_online_conf(); |
---|
235 | |
---|
236 | $online = whois_online_get_data(); |
---|
237 | |
---|
238 | $global = $online[0]; |
---|
239 | unset($online[0]); |
---|
240 | $sid = session_id(); |
---|
241 | |
---|
242 | // Step 1 - Find the User and/or IP/session_id |
---|
243 | foreach ($online as $key => $record) { |
---|
244 | // 1st case: Same IP and same member (Proxy guests are viewed as one) |
---|
245 | if ($record['IP'] == $_SERVER['REMOTE_ADDR'] |
---|
246 | and $record['username'] == $user['username'] ) { |
---|
247 | $visit = $record; |
---|
248 | $v = $key; |
---|
249 | break; |
---|
250 | } |
---|
251 | // 2nd case: Same session and user (No doubt) |
---|
252 | if ($record['session_id'] == $sid |
---|
253 | and $record['username'] == $user['username'] ) { |
---|
254 | $visit = $record; // Maybe a guest |
---|
255 | if (!is_a_guest()) $visit['hidden_IP'] = 'true'; // Maybe Proxy or hidden IP |
---|
256 | //$visit['IP'] = $_SERVER['REMOTE_ADDR']; |
---|
257 | $v = $key; |
---|
258 | break; |
---|
259 | } |
---|
260 | // 3rd and last case: Same user_id |
---|
261 | if ($record['user_id'] == $user['id'] and !is_a_guest()) { // new IP and new session |
---|
262 | $visit = $record; |
---|
263 | $visit['hidden_IP'] = 'true'; /* Or Generic user or the user is using several connections */ |
---|
264 | //$visit['IP'] = $_SERVER['REMOTE_ADDR']; |
---|
265 | $v = $key; |
---|
266 | break; |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | // Step 2 - Assume a new comer |
---|
271 | if ( !isset($visit) ) { |
---|
272 | $visit = Array( |
---|
273 | 'IP' => $_SERVER['REMOTE_ADDR'], // First known IP (Is that one true?) |
---|
274 | 'hidden_IP' => 'false', // supposed a fixed IP |
---|
275 | 'session_id' => $sid, |
---|
276 | 'user_id' => $user['id'], |
---|
277 | 'username' => $user['username'], |
---|
278 | 'delay' => 0, |
---|
279 | 'lang' => substr($lang_info['code'],0,2), |
---|
280 | 'permanent' => 'false', // False: delete after 72 Hours / True: delete after 90 days |
---|
281 | 'last_access' => time(), // Last access by this user |
---|
282 | 'elm_ids' => array_fill(0, 10, 0), // 10 last minutes + Last reference minute |
---|
283 | 'cat_ids' => array_fill(0, 12, 0), // 12 ranges (of 5 minutes) + ref |
---|
284 | 'tag_ids' => array_fill(0, 24, 0), // 24 hours + ref |
---|
285 | 'sch_ids' => array_fill(0, 14, 0), // 14 days + ref |
---|
286 | 'date' => date('Y-m-d'), // Futur usage |
---|
287 | 'elm_hits' => 0, 'pag_hits' => 0, // elements hits and pages hits by this user |
---|
288 | 'first_access_date' => date('Y-m-d'), // First access by this user |
---|
289 | 'dates' => Array(), // 5 last access dates |
---|
290 | ); |
---|
291 | $online[] = $visit; |
---|
292 | $v = count($online); |
---|
293 | } |
---|
294 | |
---|
295 | // Step 3 - Monitor this access |
---|
296 | $base = script_basename(); |
---|
297 | // Picture page |
---|
298 | if (isset($page['image_id']) and $base == 'picture') { |
---|
299 | whois_online_track($visit['elm_ids'], $page['image_id'],$visit['dates']); |
---|
300 | if (isset($page['tags'])) |
---|
301 | whois_online_track($visit['tag_ids'], $page['image_id'],$visit['dates']); |
---|
302 | if (isset($page['search'])) |
---|
303 | whois_online_track($visit['sch_ids'], $page['image_id'],$visit['dates']); |
---|
304 | $visit['elm_hits']++; |
---|
305 | $global['elm_hits']++; |
---|
306 | } |
---|
307 | // Category page |
---|
308 | if (isset($page['category']['id']) and $base == 'index') |
---|
309 | whois_online_track($visit['cat_ids'], $page['category']['id'],$visit['dates']); |
---|
310 | // Page index |
---|
311 | if (!isset($page['category']['id']) and !isset($page['image_id'])) |
---|
312 | whois_online_track($visit['cat_ids'], '' ,$visit['dates']); |
---|
313 | $visit['pag_hits']++; |
---|
314 | $global['pag_hits']++; |
---|
315 | |
---|
316 | // Step 4 - Identify current range |
---|
317 | $current = floor(time() / 60); // minutes for Unix time origin |
---|
318 | $minute = $current % 10; // (0-9) current minute |
---|
319 | $five = floor($current / 5); // (0-11) last 5 minutes range |
---|
320 | $hour = floor($current / 60); // (0-11) last hours |
---|
321 | $day = floor($current / 1440); // (0-13) last days |
---|
322 | if (isset($global['elm_ids'][10])) $old = $global['elm_ids'][10]; // previous minute (last one, or maybe 60 minutes ago or more). |
---|
323 | else $old = $current; /* Only the first time or prevent wrong changes */ |
---|
324 | |
---|
325 | // Step 5 - Hits by range |
---|
326 | if ($current != $old) { |
---|
327 | $global['elm_ids'][11] = $global['elm_ids'][$minute]; |
---|
328 | $raz = min($current-$old, 10); |
---|
329 | // 5.1 - $global['elm_ids'] ( hits by minute range ) |
---|
330 | for ($i=0;$i<$raz;$i++) { |
---|
331 | $global['elm_ids'][($minute+10-$i)%10] = 0; |
---|
332 | } |
---|
333 | // 5.2 - $global['cat_ids'] ( hits by 5 minutes range ) |
---|
334 | if (isset($global['cat_ids'][12])) $oldfive = $global['cat_ids'][12]; |
---|
335 | else $oldfive = floor($old / 5); |
---|
336 | $raz = min($five - $oldfive, 12); |
---|
337 | for ($i=0;$i<$raz;$i++) { |
---|
338 | $global['cat_ids'][($five+12-$i)%12] = 0; // Reset in backside |
---|
339 | } |
---|
340 | // 5.3 - $global['tag_ids'] (hits by hours ) |
---|
341 | if (count($global['tag_ids'])<25) $global['tag_ids'] = array_fill(0, 24, 0); |
---|
342 | if (isset($global['tag_ids'][24])) $oldhour = $global['tag_ids'][24]; |
---|
343 | else $oldhour = floor($old / 60); |
---|
344 | $raz = min($hour - $oldhour, 24); |
---|
345 | for ($i=0;$i<$raz;$i++) { |
---|
346 | $global['tag_ids'][($hour+24-$i)%24] = 0; // Reset in backside |
---|
347 | } |
---|
348 | // 5.4 - $global['sch_ids'] ( hits by days ) |
---|
349 | if (isset($global['sch_ids'][14])) $oldday = $global['sch_ids'][14]; |
---|
350 | else $oldday = floor($old / 1440); |
---|
351 | $raz = min($day - $oldday, 14); |
---|
352 | for ($i=0;$i<$raz;$i++) { |
---|
353 | $global['sch_ids'][($day+14-$i)%14] = 0; // Reset in backside |
---|
354 | } |
---|
355 | } |
---|
356 | $global['elm_ids'][$minute]++; |
---|
357 | $global['cat_ids'][$five%12]++; |
---|
358 | $global['tag_ids'][$hour%12]++; |
---|
359 | $global['sch_ids'][$day%14]++; |
---|
360 | // !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! |
---|
361 | $global['elm_ids'][10] = $current; // reference minute has changed |
---|
362 | $global['cat_ids'][12] = $five; |
---|
363 | $global['tag_ids'][24] = $hour; |
---|
364 | $global['sch_ids'][14] = $day; |
---|
365 | // !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! |
---|
366 | |
---|
367 | // Step 6 - Update (on Conf_Update and trace) and send trace to determine global tracing or not |
---|
368 | $dtrace = 0; |
---|
369 | if ($user['status'] == 'admin') $dtrace += $conf_whois['Administrators']; |
---|
370 | elseif ($user['status'] == 'webmaster') $dtrace += $conf_whois['Webmasters']; |
---|
371 | else $dtrace = 2; |
---|
372 | if ($conf['Whois Online Update'] and $dtrace > 0) whois_online_update($global, $visit, $dtrace); |
---|
373 | |
---|
374 | // Step 7 - Find your recent visits (These image_ids are presumely authorized) |
---|
375 | $my_ids = $visit['elm_ids']; |
---|
376 | sort($my_ids); |
---|
377 | unset($my_ids[0]); |
---|
378 | $url_visited = (count($my_ids)>0) ? make_index_url(array('list' => $my_ids)).'&review':''; |
---|
379 | |
---|
380 | // Step 8 - Guest count and Member list |
---|
381 | $h24 = 0; $h1 = 0; $guest = 0; |
---|
382 | $list = array(); |
---|
383 | $elm = array(); $excl = array(); // Get images_ids from all and from the current visitor |
---|
384 | foreach ($online as $k => $monit) |
---|
385 | { |
---|
386 | if ($user['id']==$monit['user_id']) $excl = $monit['elm_ids']; |
---|
387 | else $elm = array_merge($elm, $monit['elm_ids']); |
---|
388 | if ($monit['delay'] <= (24*3600)) $h24++; |
---|
389 | if ($monit['delay'] <= 3600) $h1++; |
---|
390 | // Less than 5 minutes: users are considered as still online... |
---|
391 | if ($monit['delay'] <= 300) { |
---|
392 | if ($monit['user_id'] == $conf['guest_id']) $guest++; |
---|
393 | else $list[] = $monit['username']; |
---|
394 | } |
---|
395 | } |
---|
396 | // The first (and current) access are not recorded in $online |
---|
397 | // As visitor you are not expecting your access to be already counted: Ok that the case |
---|
398 | // but you are expecting to see you as a member in the member list if you are: and there it is |
---|
399 | if ($visit['user_id'] != $conf['guest_id'] ) $list[] = $visit['username']; |
---|
400 | $list = array_unique($list); |
---|
401 | |
---|
402 | if (count($list) > $conf_whois['Users']['max']) { |
---|
403 | $conf_whois['Users']['max'] = count($list); |
---|
404 | $conf_whois['Users']['When'] = time(); |
---|
405 | $conf['Whois Online'] = serialize($conf_whois); |
---|
406 | pwg_query('REPLACE INTO ' . CONFIG_TABLE . " (param,value,comment) |
---|
407 | VALUES ('Whois Online','". $conf['Whois Online'] ."','Whois Online configuration');"); |
---|
408 | } |
---|
409 | |
---|
410 | // Step 9 - Review pictures viewed by others (all images except yours) |
---|
411 | $elm = array_diff( array_unique($elm), $excl ); |
---|
412 | shuffle($elm); |
---|
413 | $elm = array_slice($elm,0,($conf['top_number']+50)); |
---|
414 | sort($elm); |
---|
415 | array_shift($elm); |
---|
416 | $elm[] = 0; // Check if authorized pictures |
---|
417 | $query = 'SELECT DISTINCT(image_id) |
---|
418 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
419 | INNER JOIN '.IMAGES_TABLE.' ON id = image_id |
---|
420 | WHERE image_id IN ('.implode(',', $elm ).') |
---|
421 | '.get_sql_condition_FandF( |
---|
422 | array( |
---|
423 | 'forbidden_categories' => 'category_id', |
---|
424 | 'visible_categories' => 'category_id', |
---|
425 | 'visible_images' => 'id' |
---|
426 | ), "\n AND") . ';'; |
---|
427 | $ids = array_from_query($query, 'image_id'); |
---|
428 | shuffle($ids); |
---|
429 | $ids = array_slice($ids, 0, $conf['top_number']); // Keep some |
---|
430 | $url_someothers = (isset($ids[0])) ? make_index_url(array('list' => $ids)).'&others':''; |
---|
431 | |
---|
432 | // Random page title change |
---|
433 | $url_type = pwg_get_session_var('whois_url_type', ''); /* previous review or others */ |
---|
434 | $list_ids = pwg_get_session_var('whois_list_ids', ''); /* previous list/xx,yy,zz, ... */ |
---|
435 | $list_section = (isset($page['section']) and $page['section'] == 'list') ? true:false; |
---|
436 | $same_ids = (isset($page['list']) and $page['list'] == $list_ids) ? true:false; |
---|
437 | if ($list_section and isset($_GET['review'])) { |
---|
438 | $url_type = 'Whois_review'; |
---|
439 | $same_ids = true; |
---|
440 | } |
---|
441 | if ($list_section and isset($_GET['others'])) { |
---|
442 | $url_type = 'Whois_others'; |
---|
443 | $same_ids = true; |
---|
444 | } |
---|
445 | if ($list_section and $same_ids and isset($page['list'])) $list_ids = $page['list']; |
---|
446 | else $url_type = ''; // Not the same list |
---|
447 | pwg_set_session_var('whois_list_ids', $list_ids); |
---|
448 | pwg_set_session_var('whois_url_type', $url_type); |
---|
449 | if ($url_type != '' and $list_section) |
---|
450 | $page['title'] = '<a href="'.duplicate_index_url(array('start'=>0)).'">' |
---|
451 | .l10n($url_type).'</a>'; |
---|
452 | |
---|
453 | |
---|
454 | // Step 10 - Prepare data to display |
---|
455 | $yesterday = ($day+13) % 14; |
---|
456 | $template->assign('Whois', array( |
---|
457 | 'Total' => $global['pag_hits'], |
---|
458 | 'Image' => $global['elm_hits'], |
---|
459 | 'Other' => ($global['pag_hits']-$global['elm_hits']), |
---|
460 | 'Current_minute' => $global['elm_ids'][$minute], |
---|
461 | 'Previous_minute' => $global['elm_ids'][($minute+9) % 10], |
---|
462 | 'Current_5mins' => $global['elm_ids'][$minute] |
---|
463 | + $global['elm_ids'][($minute+9) % 10] |
---|
464 | + $global['elm_ids'][($minute+8) % 10] |
---|
465 | + $global['elm_ids'][($minute+7) % 10] |
---|
466 | + $global['elm_ids'][($minute+6) % 10], |
---|
467 | 'Current_10mins' => array_sum(array_slice($global['elm_ids'],0,10)), |
---|
468 | 'Current_hour' => array_sum(array_slice($global['cat_ids'],0,12)), |
---|
469 | 'Current_24h' => array_sum(array_slice($global['tag_ids'],0,24)), |
---|
470 | 'Yesterday' => $global['sch_ids'][$yesterday], |
---|
471 | 'Users_Last_day' => $h24, |
---|
472 | 'Users_Last_hour' => $h1, |
---|
473 | 'Guests' => $guest, |
---|
474 | 'Online' => $list, |
---|
475 | 'Review_url' => $url_someothers, |
---|
476 | 'Their_ids' => $ids, |
---|
477 | 'Seen_url' => $url_visited, |
---|
478 | 'My_ids' => $my_ids, |
---|
479 | 'Slideshow' => isset($_GET['slideshow']) ? true:false, |
---|
480 | )); |
---|
481 | $template->assign('Online', $global ); |
---|
482 | |
---|
483 | pwg_debug('end Online_management'); |
---|
484 | } |
---|
485 | ?> |
---|