Добавление счетчика в DokuWiki

Источник: http://wiki.erazor-zone.de/doku.php?id=wiki:projects:php:dokuwiki:counter

Count unique views for today

I patched the previos script because on my wiki I need to count unique views for today.
(Also I delete the PHP4 writing file support)

Instructions:

chown -R www:www wiki_dir/data/pages/_views

(or change www:www on your server's uid and gid)

<?php
 
/* 
	http://tinymailto.com/oliver
 
	Patched by ASCHE. Count unique views for today.
	http://asche0.ath.cx
*/
 
###############################################
$today_str = "today"; // you can translate this =)
$views_str = "views";
###############################################

global $ID, $ACT;
 
$myip    = "<".$_SERVER["REMOTE_ADDR"].">";
$ips     = "";
$unique  = true;
$views   = 0;
$d       = date("Ymd");
 
$file = realpath($conf["datadir"])."/_views/".$ID;
 
if (file_exists($file)) {
    $content = file_get_contents($file);
	$pos = strpos($content, " ");
 
	if ($pos !== FALSE) {
		$views = substr($content, 0, $pos);
		$str   = substr($content, $pos + 1);
		$pos   = strpos($str, " ");
 
		if ($pos !== FALSE) {
			$old_d = substr($str, 0, $pos);
			$ips   = substr($str, $pos + 1);
 
			if ($old_d != $d) {
				$views = 0;
				$ips   = "";
			} else if (strpos($ips, $myip) !== FALSE) {
				$unique = false;
			}
		}
	}
}
 
if (($ACT == "show") && ($INFO["exists"]) && ($unique)) {
    $ips.="\n".$myip;
 
	$content = ++$views." ".$d." ".$ips;
	file_put_contents($file, $content);
}
 
$fn.=" ($today_str $views $views_str) ";
 
?>
  $fn = utf8_decodeFN($fn);
  $date = strftime($conf['dformat'],$INFO['lastmod']);
 
  // print it
  if($INFO['exists']){
    ###############################################
    include("counter.php");
    ###############################################
    print $fn;

–ASCHE