Revision | 277b97abb67699d5cace12f8666c5a3ea283e80d (tree) |
---|---|
Time | 2014-11-26 01:32:43 |
Author | henoheno <henoheno> |
Commiter | umorigu |
BugTrack/191: counter plugin still reset the count to zero (Notified by someone)
@@ -1,12 +1,12 @@ | ||
1 | 1 | <?php |
2 | 2 | // PukiWiki - Yet another WikiWikiWeb clone |
3 | -// $Id: counter.inc.php,v 1.18 2006/05/27 13:31:11 henoheno Exp $ | |
3 | +// $Id: counter.inc.php,v 1.19 2007/02/04 11:14:44 henoheno Exp $ | |
4 | 4 | // Copyright (C) |
5 | -// 2002-2005 PukiWiki Developers Team | |
5 | +// 2002-2005, 2007 PukiWiki Developers Team | |
6 | 6 | // 2002 Y.MASUI GPL2 http://masui.net/pukiwiki/ masui@masui.net |
7 | 7 | // License: GPL2 |
8 | 8 | // |
9 | -// Counter plugin | |
9 | +// Counter plugin (per page) | |
10 | 10 | |
11 | 11 | // Counter file's suffix |
12 | 12 | define('PLUGIN_COUNTER_SUFFIX', '.count'); |
@@ -69,19 +69,24 @@ function plugin_counter_get_count($page) | ||
69 | 69 | $counters[$page] = $default; |
70 | 70 | $modify = FALSE; |
71 | 71 | |
72 | + // Open | |
72 | 73 | $file = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX; |
73 | - $fp = fopen($file, file_exists($file) ? 'r+' : 'w+') | |
74 | + pkwk_touch_file($file); | |
75 | + $fp = fopen($file, 'r+') | |
74 | 76 | or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file)); |
75 | 77 | set_file_buffer($fp, 0); |
76 | 78 | flock($fp, LOCK_EX); |
77 | 79 | rewind($fp); |
78 | - foreach ($default as $key=>$val) { | |
80 | + | |
81 | + // Read | |
82 | + foreach (array_keys($default) as $key) { | |
79 | 83 | // Update |
80 | 84 | $counters[$page][$key] = rtrim(fgets($fp, 256)); |
81 | 85 | if (feof($fp)) break; |
82 | 86 | } |
87 | + | |
88 | + // Anothoer day? | |
83 | 89 | if ($counters[$page]['date'] != $default['date']) { |
84 | - // New day | |
85 | 90 | $modify = TRUE; |
86 | 91 | $is_yesterday = ($counters[$page]['date'] == get_date('Y/m/d', strtotime('yesterday', UTIME))); |
87 | 92 | $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR']; |
@@ -89,7 +94,6 @@ function plugin_counter_get_count($page) | ||
89 | 94 | $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0; |
90 | 95 | $counters[$page]['today'] = 1; |
91 | 96 | $counters[$page]['total']++; |
92 | - | |
93 | 97 | } else if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR']) { |
94 | 98 | // Not the same host |
95 | 99 | $modify = TRUE; |
@@ -97,6 +101,7 @@ function plugin_counter_get_count($page) | ||
97 | 101 | $counters[$page]['today']++; |
98 | 102 | $counters[$page]['total']++; |
99 | 103 | } |
104 | + | |
100 | 105 | // Modify |
101 | 106 | if ($modify && $vars['cmd'] == 'read') { |
102 | 107 | rewind($fp); |
@@ -104,6 +109,8 @@ function plugin_counter_get_count($page) | ||
104 | 109 | foreach (array_keys($default) as $key) |
105 | 110 | fputs($fp, $counters[$page][$key] . "\n"); |
106 | 111 | } |
112 | + | |
113 | + // Close | |
107 | 114 | flock($fp, LOCK_UN); |
108 | 115 | fclose($fp); |
109 | 116 |