OSDN Git Service

BugTrack2/62: Do remove the whole design, 'Showing TrackBack-ping list by html'.
[pukiwiki/pukiwiki.git] / plugin / online.inc.php
1 <?php
2 /////////////////////////////////////////////////
3 // PukiWiki - Yet another WikiWikiWeb clone.
4 //
5 // $Id: online.inc.php,v 1.8 2004/03/18 10:02:13 arino Exp $
6 //
7
8 // user list file
9 define('USR_LST', COUNTER_DIR.'user.dat');
10 // time out sec
11 define('TIMEOUT', 300);
12
13 function plugin_online_inline()
14 {
15         return plugin_online_convert();
16 }
17 function plugin_online_convert()
18 {
19         if (!file_exists(USR_LST))
20         {
21                 $nf = fopen(USR_LST, 'w');
22                 fclose($nf);
23         }
24         CheckUser($_SERVER['REMOTE_ADDR']);
25         return UserCount();
26 }
27
28 function CheckUser($addr)
29 {
30         $usr_arr = file(USR_LST);
31         $fp = fopen(USR_LST, 'w');
32         set_file_buffer($fp, 0);
33         flock($fp,LOCK_EX);
34         rewind($fp);
35         $now = UTIME;
36         for ($i = 0; $i < count($usr_arr); $i++)
37         {
38                 list($ip_addr,$tim_stmp) = explode('|', $usr_arr[$i]);
39                 if (($now - $tim_stmp) < TIMEOUT and $ip_addr != $addr)
40                 {
41                         fputs($fp, "$ip_addr|$tim_stmp");
42                 }
43         }
44         fputs($fp, "$addr|$now\n");
45         flock($fp,LOCK_UN);
46         fclose($fp);
47 }
48
49 function UserCount()
50 {
51         return count(file(USR_LST));
52 }
53 ?>