도쿠위키 네임스페이스 카운터 달기

설정된 시간동안 네임스페이스 별로 클릭 수가 얼마나 있었는지를 세어 봅시다.

흐름은

# 일단 페이지가 갱신될 때마다 현재 시간과 보여지는 페이지의 네임스페이스를 파일에 저장합니다. # 설정된 시간 (예: 5분) 이 지난 내용은 버립니다. # 배열을 하나 잡고 네임스페이스 별로 카운트를 합니다. # 표로 출력!

PHP 코드

<strong>Recent requests</strong>
<?php
$count_my_page = ("hitcounter.txt");
$hits = file($count_my_page);
 
$towrite="";
$nsclickstatus="";
 
$t=time();  //현재시각
$nsns="root:".$INFO['namespace'];  // 네임스페이스 얻기
 
array_unshift($hits,$t.' '.$nsns.' '.$INFO['id']."\r\n");  //이번 클릭 추가
 
foreach ($hits as $temp)
{
 $xtime=strtok($temp,' ');
 $xns=strtok(' ');
 
 if ($t-$xtime<=60*5)  // 60*5 = 5분
  { 
   $towrite=$towrite.$temp;
   $nsclickstatus[$xns]++;  //배열에 카운트 
  }
}
 
$fp = fopen($count_my_page , "w"); //파일로 저장
fputs($fp , "$towrite");
fclose($fp);
 
global $oout;
 
function myfunction($value,$key)
{
global $oout;
$kkk=ucwords(substr($key,0,20));
$oout.="<tr><td>$kkk</td><td>$value</td></tr>";
}
 
if ($_SERVER['REMOTE_USER']!=null) //로그인한 사람만 볼 수 있게 합니다.
{
 $oout.='<table border="0" width="90%" style="font-size:10px;">';
 array_walk($nsclickstatus,"myfunction");
 $oout.='</table>';
 
 echo $oout;  // 테이블 출력
 
//$fp = fopen("status.html" , "w");   //혹시 파일로 저장하려면...
//fputs($fp , "$oout");
//fclose($fp);
}
?>

결과

Recent requests
Root:	8
Root:game:eve	3
Root:game	1
Root:med	2
Root:blog	1
Root:tech	1
Root:wiki	1 

저는 스킨의 sidebar.php에 넣었습니다. 로그인하면 왼쪽의 사이드바에 나타납니다.

출처: 도쿠위키 네임스페이스 카운터 달기

* 로긴 후 수정하실 수 있습니다. 관심있는 분들의 많은 참여 부탁드립니다. * 문법은 Formatting Syntax참조하세요.

역링크