3 * PukiWiki ¥«¥¦¥ó¥¿¡¼¥×¥é¥°¥¤¥ó
5 * CopyRight 2002 Y.MASUI GPL2
6 * http://masui.net/pukiwiki/ masui@masui.net
8 * $Id: counter.inc.php,v 1.13 2004/03/18 10:02:13 arino Exp $
12 if (!defined('COUNTER_EXT'))
14 define('COUNTER_EXT','.count');
17 function plugin_counter_inline()
22 if (func_num_args() > 0)
24 $args = func_get_args();
25 $arg = strtolower($args[0]);
28 $counter = plugin_counter_get_count($vars['page']);
34 $count = $counter[$arg];
37 $count = $counter['total'];
42 function plugin_counter_convert()
46 $counter = plugin_counter_get_count($vars['page']);
50 Counter: {$counter['total']},
51 today: {$counter['today']},
52 yesterday: {$counter['yesterday']}
57 function plugin_counter_get_count($page)
60 static $counters = array();
63 // ¥«¥¦¥ó¥¿¤Î¥Ç¥Õ¥©¥ë¥ÈÃÍ
68 'date' => get_date('Y/m/d'),
78 if (array_key_exists($page,$counters))
80 return $counters[$page];
83 // ¥«¥¦¥ó¥¿¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤò¥»¥Ã¥È
84 $counters[$page] = $default;
86 // ¥«¥¦¥ó¥¿¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¾ì¹ç¤ÏÆɤ߹þ¤à
87 $file = COUNTER_DIR.encode($page).COUNTER_EXT;
88 $fp = fopen($file, file_exists($file) ? 'r+' : 'w+')
89 or die_message('counter.inc.php:cannot open '.$file);
90 set_file_buffer($fp, 0);
94 foreach ($default as $key=>$val)
96 $counters[$page][$key] = rtrim(fgets($fp,256));
97 if (feof($fp)) { break; }
99 // ¥Õ¥¡¥¤¥ë¹¹¿·¤¬É¬Íפ«?
103 if ($counters[$page]['date'] != $default['date'])
106 $is_yesterday = ($counters[$page]['date'] == get_date('Y/m/d',strtotime('yesterday',UTIME)));
107 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
108 $counters[$page]['date'] = $default['date'];
109 $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0;
110 $counters[$page]['today'] = 1;
111 $counters[$page]['total']++;
113 // IP¥¢¥É¥ì¥¹¤¬°Û¤Ê¤ë
114 else if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR'])
117 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
118 $counters[$page]['today']++;
119 $counters[$page]['total']++;
122 //¥Ú¡¼¥¸Æɤ߽Ф·»þ¤Î¤ß¥Õ¥¡¥¤¥ë¤ò¹¹¿·
123 if ($modify and $vars['cmd'] == 'read')
129 foreach (array_keys($default) as $key)
131 fputs($fp,$counters[$page][$key]."\n");
138 return $counters[$page];