Her er hele filen :D
<?
/*
Digital Diary Version 1.1
Copyright (C) 2002 Alex Moundalexis. All Rights Reserved.
http://gb.moundalexis.com/~alexm/dd.php*/
/*
Daily Counter 1.1 by Chi Kien Uong
http://www.proxy2.de Used and distributed with permission.
18 July 2002 Modifications:
Added globals to count queries.
Begin class...
*/
class dcounter_sql {
var $conn_id;
var $result;
var $record;
var $db = array();
function dcounter_sql() {
global $COUNT_DB;
$this->db = $COUNT_DB;
}
function connect() {
$this->conn_id = mysql_connect($this->db['host'],$this->db['user'],$this->db['pass']);
if ($this->conn_id == 0) {
return false;
}
if (!mysql_select_db($this->db['dbName'], $this->conn_id)) {
return false;
}
return $this->conn_id;
}
function query($query_string) {
global $tq;
$this->result = mysql_query($query_string,$this->conn_id);
$tq++;
if (!$this->result) {
return false;
}
return $this->result;
}
function fetch_array($query_id) {
$this->record = mysql_fetch_array($query_id,MYSQL_ASSOC);
return $this->record;
}
function num_rows($query_id) {
return ($query_id) ? mysql_num_rows($query_id) : 0;
}
function num_fields($query_id) {
return ($query_id) ? mysql_num_fields($query_id) : 0;
}
function insert_id() {
return mysql_insert_id($link_id);
}
function free_result($query_id) {
return mysql_free_result($query_id);
}
function affected_rows() {
return mysql_affected_rows($this->conn_id);
}
function close_db() {
if($this->conn_id) {
return mysql_close($this->conn_id);
} else {
return false;
}
}
}
/*
Daily Counter 1.1 by Chi Kien Uong
http://www.proxy2.de Used and distributed with permission.
18 July 2002 Modifications:
Added globals and fixed host
field to handle users instead.
Begin class...
*/
class dcounter {
var $config;
var $ip;
var $host;
var $table;
var $counter;
var $use_db;
var $visitor;
var $db;
function dcounter() {
global $COUNT_TBL,$COUNT_CFG,$aid;
if ($COUNT_CFG["use_db"]) {
$this->db = new dcounter_sql();
$this->db->connect();
$this->table = $COUNT_TBL;
}
$this->ip = getenv("REMOTE_ADDR");
$this->host = $aid;
$this->config = $COUNT_CFG;
$this->use_db = ($COUNT_CFG['use_db']) ? true : false;
if ($aid == "Anonymous") {
$aid = "Visitor";
}
}
function is_new_visitor() {
$now = $this->config['offset']*3600 + time() - $this->config['block_time'];
if ($this->use_db) {
$this->db->query("DELETE FROM ".$this->table['visitors']." WHERE $now > time");
$this->db->fetch_array($this->db->query("SELECT * FROM ".$this->table['visitors']." WHERE ip = '$this->ip' and host = '$this->host'"));
if ($this->db->record) {
$now = $this->config['offset']*3600 + time();
$this->db->query("UPDATE ".$this->table['visitors']." SET time='$now' host='$this->host' WHERE ip = '$this->ip'");
return false;
} else {
return true;
}
} else {
$found=0;
$rows = @file($this->config['logfile']);
$this_time = $this->config['offset']*3600 + time();
$reload_dat = fopen($this->config['logfile'],"wb");
flock($reload_dat, 2);
for ($i=0; $i<sizeof($rows); $i++) {
list($time_stamp,$ip_addr,$hostname) = split("\|",$rows[$i]);
if ($this_time < ($time_stamp+$this->config['block_time'])) {
if ($ip_addr == $this->ip) {
$found=1;
} else {
fwrite($reload_dat,"$time_stamp|$ip_addr|$hostname");
}
}
}
$new = "$this_time|".$this->ip."|".$this->host."\n";
fwrite($reload_dat,$new);
flock($reload_dat, 3);
fclose($reload_dat);
return ($found==1) ? false : true;
}
}
function update_counter() {
$now = time()+$this->config['offset']*3600;
if ($this->use_db) {
$this->db->query("INSERT INTO ".$this->table['visitors']." (time,ip,host) VALUES ('$now','$this->ip','$this->host')");
$this->db->query("UPDATE ".$this->table['total']." set total=total+1");
if ($this->db->affected_rows() == 0) {
$this->db->query("INSERT INTO ".$this->table['total']." SET total='1', installtime = UNIX_TIMESTAMP()");
}
$this->db->query("UPDATE ".$this->table['daily']." SET visitors=visitors+1 WHERE day = now()");
if ($this->db->affected_rows() == 0) {
$this->db->query("INSERT INTO ".$this->table['daily']." SET visitors='1', day = now()");
}
} else {
$today = date("Y-m-j",time()+$this->config['offset']*3600);
if (!file_exists($this->config['counter'])) {
$count_dat = fopen($this->config['counter'],"w+");
fwrite($count_dat,"1");
fclose($count_dat);
$this->counter = 1;
} else {
$fp = fopen($this->config['counter'], "r+");
flock($fp, 2);
$this->counter = fgets($fp, 4096);
$this->counter++;
rewind($fp);
fwrite($fp, $this->counter);
flock($fp, 3);
fclose($fp);
}
if (!file_exists($this->config['daylog'])) {
$count_dat = fopen($this->config['daylog'],"w+");
fwrite($count_dat,"$today\n1");
fclose($count_dat);
$this->visitor = 1;
} else {
$fp = fopen($this->config['daylog'], "r+");
flock($fp, 2);
$first_row = chop(fgets($fp, 4096));
$this->visitor = fgets($fp, 4096);
if ($today == $first_row) {
$this->visitor++;
} else {
$this->visitor = 1;
}
rewind($fp);
fwrite($fp,"$today\n");
fwrite($fp,$this->visitor);
flock($fp, 3);
fclose($fp);
}
}
}
function show_counter() {
if ($this->use_db) {
if ($this->is_new_visitor()) {
$this->update_counter();
}
$this->db->fetch_array($this->db->query("SELECT total FROM ".$this->table['total']));
$counter['total'] = $this->db->record['total'];
$this->db->fetch_array($this->db->query("SELECT visitors FROM ".$this->table['daily']." WHERE day = now()"));
$counter['visits_today'] = $this->db->record['visitors'];
$this->db->close_db();
} else {
if ($this->is_new_visitor()) {
$this->update_counter();
} else {
$fp = fopen($this->config['counter'], "r");
flock($fp, 2);
$this->counter = fgets($fp, 4096);
flock($fp, 3);
fclose($fp);
$fp = fopen($this->config['daylog'], "r");
flock($fp, 2);
$first_row = fgets($fp, 4096);
$this->visitor = chop(fgets($fp, 4096));
flock($fp, 3);
fclose($fp);
}
$counter['total'] = $this->counter;
$counter['visits_today'] = $this->visitor;
}
return $counter;
}
}
/*
Previous/Next Class v.01 by sephiroth
Alessandro Crugnola (alessandro at sephiroth.it)
Used and distributed with permission.
28 June 2002 Modifications:
Functions return values, instead of printing.
(better suited for templates)
Begin class...
*/
class PrevNext_class
{
var $dbconnection, $dbname, $limit, $execute, $query;
// database connection
function connection($dbhost,$dbuser,$dbpass)
{
@$this->conn = mysql_connect($dbhost,$dbuser,$dbpass) or die("Error connectiong to database $dbhost");
@mysql_select_db($this->dbname) or die ("Cannot connect to $this->dbname database");
!isset($GLOBALS[$this->offset]) ? $GLOBALS[$this->offset] = 0 : $GLOBALS[$this->offset] = $GLOBALS[$this->offset];
}
// mysql query execution
function execute($query)
{
@$this->sql_result = mysql_query($query,$this->conn) or die ("Error fetching information...");
$this->total_result = mysql_num_rows($this->sql_result);
if(isset($this->limit))
{
$query .= " LIMIT " . $GLOBALS[$this->offset] . ", $this->limit";
@$this->sql_result = mysql_query($query,$this->conn) or die ("Error fetching information...");
$this->num_pages = ceil($this->total_result/$this->limit);
}
}
######################
## PAGES NUMBERS ##
######################
##
## $class->show_num_pages('<< previuos','next >>','separator','class=\"myclass\"');
##
function show_num_pages($rew = '', $fwd = '', $separator = '|', $objClass = '')
{
if($this->num_pages > 1)
{
## searching for http_get_vars
foreach($GLOBALS[HTTP_GET_VARS] as $_get_name => $_get_value)
{
if($_get_name != $this->offset) $this->_get_vars .= "&$_get_name=$_get_value";
}
$this->successivo = $GLOBALS[$this->offset] + $this->limit;
$this->precedente = $GLOBALS[$this->offset] - $this->limit;
$this->theClass = $objClass;
if(!empty($rew))
{
$GLOBALS[$this->offset] > 0 ? $return .= "<a href='$GLOBALS[PHP_SELF]?$this->offset=$this->precedente$this->_get_vars' $this->theClass> $rew</a> $separator " : $return .= "$rew $separator ";
}
## showing pages
if($this->show_pages_number || !isset($this->show_pages_number))
{
for($this->a = 1; $this->a <= $this->num_pages; $this->a++)
{
$this->theNext = ($this->a-1)*$this->limit;
if($this->theNext != $GLOBALS[$this->offset])
{
$return .= "<a href='$GLOBALS[PHP_SELF]?$this->offset=$this->theNext$this->_get_vars' $this->theClass>";
if($this->number_type == 'alpha') $return .= chr(64 + ($this->a));
else $return .= $this->a;
$return .= "</a>";
} else {
if($this->number_type == 'alpha') $return .= chr(64 + ($this->a));
else $return .= $this->a;
}
$this->a < $this->num_pages ? $return .= " $separator " : $return .= " ";
}
}
$this->theNext = $GLOBALS[$this->offset] + $this->limit;
if(!empty($fwd))
{
$GLOBALS[$this->offset] + $this->limit < $this->total_result ? $return .= "$separator <a href='$GLOBALS[PHP_SELF]?$this->offset=$this->successivo$this->_get_vars' $this->theClass>$fwd</a>" : $return .= "$separator $fwd";
}
}
return $return;
}
##################################
## showing offest range results ##
##################################
##
## $class->show_offset_range('Previous','Next','-');
##
##
function show_offset_range($rew = '', $fwd = '', $separator = '|')
{
if($this->num_pages > 1)
{
foreach($GLOBALS[HTTP_GET_VARS] as $_get_name => $_get_value)
{
if($_get_name != $this->offset) $this->_get_vars .= "&$_get_name=$_get_value";
}
$this->successivo = $GLOBALS[$this->offset] + $this->limit;
$this->precedente = $GLOBALS[$this->offset] - $this->limit;
## previous num results...
if(!empty($rew))
{
$GLOBALS[$this->offset] > 0 ? $return .= "<a href='$GLOBALS[PHP_SELF]?$this->offset=$this->precedente$this->_get_vars' $this->theClass> $rew $this->limit</a> $separator " : $return .= "$rew $this->limit $separator ";
}
## showing numbers...
for($this->a = 1; $this->a <= $this->num_pages; $this->a++)
{
$this->theNext = ($this->a-1)*$this->limit;
$this->toShow = $this->limit*$this->a - $this->limit + 1 . " - " . $this->limit*$this->a;
if(($this->limit*$this->a - $this->limit + 1) == $this->total_result)
{
$this->theLast = $this->total_result;
} else {
$this->theLast = $this->limit*$this->a - $this->limit + 1 . " - " . $this->total_result;
}
if($this->theNext != $GLOBALS[$this->offset])
{
$return .= "<a href='$GLOBALS[PHP_SELF]?$this->offset=$this->theNext$this->_get_vars' $this->theClass>";
$this->a == $this->num_pages ? $return .= $this->theLast : $return .= $this->toShow;
$return .= "</a>";
} else {
$this->a == $this->num_pages ? $return .= $this->theLast : $return .= $this->toShow;
}
$this->a < $this->num_pages ? $return .= " $separator " : $return .= " ";
}
## showing next num results...
$this->theNext = $GLOBALS[$this->offset] + $this->limit;
if(!empty($fwd))
{
$GLOBALS[$this->offset] + $this->limit < $this->total_result ? $return .= "$separator <a href='$GLOBALS[PHP_SELF]?$this->offset=$this->successivo$this->_get_vars' $this->theClass>$fwd $this->limit</a>" : $return .= "$separator $fwd $this->limit";
}
}
return $return;
}
## show info for the offset
function show_info()
{
$return .= $this->total_result . " total entries. ";
$_from = $GLOBALS[$this->offset] + 1;
$GLOBALS[$this->offset] + $this->limit >= $this->total_result ? $_to = $this->total_result : $_to = $GLOBALS[$this->offset] + $this->limit;
$return .= "Showing entries " . $_from . " to " . $_to . ".";
return $return;
}
}
## END CLASS ##
?>