OSDN Git Service

MASUI'z Edition first beta release
[pukiwiki/pukiwiki.git] / plugin / counter.inc.php
1 <?
2 /*
3  * PukiWiki ¥«¥¦¥ó¥¿¡¼¥×¥é¥°¥¤¥ó
4  *
5  * CopyRight 2002 Y.MASUI GPL2
6  * http://masui.net/pukiwiki/ masui@masui.net
7  */
8
9 // counter file
10 define(COUNTER_DIR, "./counter/");
11
12 function plugin_counter_convert()
13 {
14         global $vars;
15         
16         $file = COUNTER_DIR.encode($vars["page"]).".count";
17         if(!file_exists($file))
18         {
19                 $nf = fopen($file, "w");
20                 fputs($nf,"0\n0\n0\n0\n\n");
21                 fclose($nf);
22         }
23         $array = file($file);
24         $count = rtrim($array[0]);
25         $today = rtrim($array[1]);
26         $today_count = rtrim($array[2]);
27         $yesterday_count = rtrim($array[3]);
28         $ip = rtrim($array[4]);
29         if($ip != $_SERVER["REMOTE_ADDR"] && !(arg_check("add") || arg_check("edit") || arg_check("preview") || $vars['preview'] != '' || $vars['write'] != '')) {
30                 $t = date("Y/m/d");
31                 if($t != $today) {
32                         $yesterday_count = $today_count;
33                         $today_count = 0;
34                         $today = $t;
35                 }
36                 ++$count;
37                 ++$today_count;
38         }
39         
40         $ip = $_SERVER["REMOTE_ADDR"];
41         $nf = fopen($file, "w");
42         fputs($nf,"$count\n");
43         fputs($nf,"$today\n");
44         fputs($nf,"$today_count\n");
45         fputs($nf,"$yesterday_count\n");
46         fputs($nf,"$ip\n");
47         fclose($nf);
48         
49         return "<font size='1'>Counter: $count, today: $today_count, yesterday: $yesterday_count</font>";
50
51 }
52 ?>