• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Commit MetaInfo

Revision277b97abb67699d5cace12f8666c5a3ea283e80d (tree)
Time2014-11-26 01:32:43
Authorhenoheno <henoheno>
Commiterumorigu

Log Message

BugTrack/191: counter plugin still reset the count to zero (Notified by someone)

Change Summary

Incremental Difference

--- a/plugin/counter.inc.php
+++ b/plugin/counter.inc.php
@@ -1,12 +1,12 @@
11 <?php
22 // 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 $
44 // Copyright (C)
5-// 2002-2005 PukiWiki Developers Team
5+// 2002-2005, 2007 PukiWiki Developers Team
66 // 2002 Y.MASUI GPL2 http://masui.net/pukiwiki/ masui@masui.net
77 // License: GPL2
88 //
9-// Counter plugin
9+// Counter plugin (per page)
1010
1111 // Counter file's suffix
1212 define('PLUGIN_COUNTER_SUFFIX', '.count');
@@ -69,19 +69,24 @@ function plugin_counter_get_count($page)
6969 $counters[$page] = $default;
7070 $modify = FALSE;
7171
72+ // Open
7273 $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+')
7476 or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file));
7577 set_file_buffer($fp, 0);
7678 flock($fp, LOCK_EX);
7779 rewind($fp);
78- foreach ($default as $key=>$val) {
80+
81+ // Read
82+ foreach (array_keys($default) as $key) {
7983 // Update
8084 $counters[$page][$key] = rtrim(fgets($fp, 256));
8185 if (feof($fp)) break;
8286 }
87+
88+ // Anothoer day?
8389 if ($counters[$page]['date'] != $default['date']) {
84- // New day
8590 $modify = TRUE;
8691 $is_yesterday = ($counters[$page]['date'] == get_date('Y/m/d', strtotime('yesterday', UTIME)));
8792 $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR'];
@@ -89,7 +94,6 @@ function plugin_counter_get_count($page)
8994 $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0;
9095 $counters[$page]['today'] = 1;
9196 $counters[$page]['total']++;
92-
9397 } else if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR']) {
9498 // Not the same host
9599 $modify = TRUE;
@@ -97,6 +101,7 @@ function plugin_counter_get_count($page)
97101 $counters[$page]['today']++;
98102 $counters[$page]['total']++;
99103 }
104+
100105 // Modify
101106 if ($modify && $vars['cmd'] == 'read') {
102107 rewind($fp);
@@ -104,6 +109,8 @@ function plugin_counter_get_count($page)
104109 foreach (array_keys($default) as $key)
105110 fputs($fp, $counters[$page][$key] . "\n");
106111 }
112+
113+ // Close
107114 flock($fp, LOCK_UN);
108115 fclose($fp);
109116