3 * PukiWiki ¥«¥¦¥ó¥¿¡¼¥×¥é¥°¥¤¥ó
5 * CopyRight 2002 Y.MASUI GPL2
6 * http://masui.net/pukiwiki/ masui@masui.net
8 * $Id: counter.inc.php,v 1.9 2003/04/13 05:36:04 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'),
83 if (array_key_exists($page,$counters))
85 return $counters[$page];
88 // ¥«¥¦¥ó¥¿¤Î¥Ç¥Õ¥©¥ë¥ÈÃͤò¥»¥Ã¥È
89 $counters[$page] = $default;
91 // ¥«¥¦¥ó¥¿¥Õ¥¡¥¤¥ë¤¬Â¸ºß¤¹¤ë¾ì¹ç¤ÏÆɤ߹þ¤à
93 $file = COUNTER_DIR.encode($page).COUNTER_EXT;
94 if (file_exists($file))
96 $fp = fopen($file, 'r+')
97 or die_message('counter.inc.php:cannot read '.$file);
99 foreach ($default as $key=>$val)
101 $counters[$page][$key] = rtrim(fgets($fp,256));
104 // ¥Õ¥¡¥¤¥ë¹¹¿·¤¬É¬Íפ«?
108 if ($counters[$page]['date'] != $default['date'])
111 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
112 $counters[$page]['date'] = $default['date'];
113 $counters[$page]['yesterday'] = $counters[$page]['today'];
114 $counters[$page]['today'] = 1;
115 $counters[$page]['total']++;
117 // IP¥¢¥É¥ì¥¹¤¬°Û¤Ê¤ë
118 else if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR'])
121 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
122 $counters[$page]['today']++;
123 $counters[$page]['total']++;
126 //¥Ú¡¼¥¸Æɤ߽Ф·»þ¤Î¤ß¥Õ¥¡¥¤¥ë¤ò¹¹¿·
127 if ($modify and $vars['cmd'] == 'read')
129 // ¥Õ¥¡¥¤¥ë¤¬³«¤¤¤Æ¤¤¤ë
139 $fp = fopen($file, 'w')
140 or die_message('counter.inc.php:cannot write '.$file);
144 foreach (array_keys($default) as $key)
146 fputs($fp,$counters[$page][$key]."\n");
149 // ¥Õ¥¡¥¤¥ë¤¬³«¤¤¤Æ¤¤¤ë
157 return $counters[$page];