3 * PukiWiki ¥«¥¦¥ó¥¿¡¼¥×¥é¥°¥¤¥ó
5 * CopyRight 2002 Y.MASUI GPL2
6 * http://masui.net/pukiwiki/ masui@masui.net
8 * $Id: counter.inc.php,v 1.10 2003/04/23 08:26:19 arino Exp $
12 if (!defined('COUNTER_DIR'))
14 define('COUNTER_DIR', './counter/');
17 if (!defined('COUNTER_EXT'))
19 define('COUNTER_EXT','.count');
22 function plugin_counter_inline()
27 if (func_num_args() > 0)
29 $args = func_get_args();
30 $arg = strtolower($args[0]);
33 $counter = plugin_counter_get_count($vars['page']);
39 $count = $counter[$arg];
42 $count = $counter['total'];
47 function plugin_counter_convert()
51 $counter = plugin_counter_get_count($vars['page']);
55 Counter: {$counter['total']},
56 today: {$counter['today']},
57 yesterday: {$counter['yesterday']}
62 function plugin_counter_get_count($page)
65 static $counters = array();
68 // ¥«¥¦¥ó¥¿¤Î¥Ç¥Õ¥©¥ë¥ÈÃÍ
73 'date' => get_date('Y/m/d'), // PukiWiki/1.4
74 // 'date' => date('Y/m/d'), // PukiWiki/1.3.x
84 if (array_key_exists($page,$counters))
86 return $counters[$page];
89 // ¥«¥¦¥ó¥¿¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤò¥»¥Ã¥È
90 $counters[$page] = $default;
92 // ¥«¥¦¥ó¥¿¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¾ì¹ç¤ÏÆɤ߹þ¤à
94 $file = COUNTER_DIR.encode($page).COUNTER_EXT;
95 if (file_exists($file))
97 $fp = fopen($file, 'r+')
98 or die_message('counter.inc.php:cannot read '.$file);
100 foreach ($default as $key=>$val)
102 $counters[$page][$key] = rtrim(fgets($fp,256));
105 // ¥Õ¥¡¥¤¥ë¹¹¿·¤¬É¬Íפ«?
109 if ($counters[$page]['date'] != $default['date'])
112 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
113 $counters[$page]['date'] = $default['date'];
114 $counters[$page]['yesterday'] = $counters[$page]['today'];
115 $counters[$page]['today'] = 1;
116 $counters[$page]['total']++;
118 // IP¥¢¥É¥ì¥¹¤¬°Û¤Ê¤ë
119 else if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR'])
122 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
123 $counters[$page]['today']++;
124 $counters[$page]['total']++;
127 //¥Ú¡¼¥¸Æɤ߽Ф·»þ¤Î¤ß¥Õ¥¡¥¤¥ë¤ò¹¹¿·
128 // for PukiWiki/1.3.x
129 // $is_read = !(arg_check('add') || arg_check('edit') || arg_check('preview') ||
130 // $vars['preview'] != '' || $vars['write'] != '');
132 $is_read = ($vars['cmd'] == 'read');
134 if ($modify and $is_read)
136 // ¥Õ¥¡¥¤¥ë¤¬³«¤¤¤Æ¤¤¤ë
146 $fp = fopen($file, 'w')
147 or die_message('counter.inc.php:cannot write '.$file);
151 foreach (array_keys($default) as $key)
153 fputs($fp,$counters[$page][$key]."\n");
156 // ¥Õ¥¡¥¤¥ë¤¬³«¤¤¤Æ¤¤¤ë
164 return $counters[$page];