Counter: {$counter['total']}, today: {$counter['today']}, yesterday: {$counter['yesterday']} EOD; } // Return a summary function plugin_counter_get_count($page) { global $vars; static $counters = array(); static $default; if (! isset($default)) $default = array( 'total' => 0, 'date' => get_date('Y/m/d'), 'today' => 0, 'yesterday' => 0, 'ip' => ''); if (! is_page($page)) return $default; if (isset($counters[$page])) return $counters[$page]; // Set default $counters[$page] = $default; $modify = FALSE; // Open $file = COUNTER_DIR . encode($page) . PLUGIN_COUNTER_SUFFIX; pkwk_touch_file($file); $fp = fopen($file, 'r+') or die('counter.inc.php: Cannot open COUTER_DIR/' . basename($file)); set_file_buffer($fp, 0); flock($fp, LOCK_EX); rewind($fp); // Read foreach (array_keys($default) as $key) { // Update $counters[$page][$key] = rtrim(fgets($fp, 256)); if (feof($fp)) break; } // Anothoer day? if ($counters[$page]['date'] != $default['date']) { $modify = TRUE; $is_yesterday = ($counters[$page]['date'] == get_date('Y/m/d', strtotime('yesterday', UTIME))); $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR']; $counters[$page]['date'] = $default['date']; $counters[$page]['yesterday'] = $is_yesterday ? $counters[$page]['today'] : 0; $counters[$page]['today'] = 1; $counters[$page]['total']++; } else if ($counters[$page]['ip'] != $_SERVER['REMOTE_ADDR']) { // Not the same host $modify = TRUE; $counters[$page]['ip'] = $_SERVER['REMOTE_ADDR']; $counters[$page]['today']++; $counters[$page]['total']++; } // Modify if ($modify && $vars['cmd'] == 'read') { rewind($fp); ftruncate($fp, 0); foreach (array_keys($default) as $key) fputs($fp, $counters[$page][$key] . "\n"); } // Close flock($fp, LOCK_UN); fclose($fp); return $counters[$page]; } ?>