logfile = $_SERVER['DOCUMENT_ROOT'] . "blogspam.log"; } function add( $ipnum, $reason = '', $date = '' ) { if( empty( $date ) ) { $this->date = date( "Y-m-d" ); } else { $this->date = $date; } if( !empty( $reason ) ) { $this->reason = $reason; } if( empty( $this->map ) ) { $this->_fillmap(); } $this->map[$ipnum] = array( 'date' => $this->date, 'reason' => $this->reason); if(!($fh = fopen( $this->logfile,"w"))) return; fwrite( $fh, $this->tostring() ); fclose($fh); } function exists( $ipnum ) { $res = false; if( empty( $this->map ) ) { $this->_fillmap(); } if( isset($this->map[$ipnum]) ) { $res = true; } return $res; } function get( $ipnum ) { $res = array(); if( empty( $this->map ) ) { $this->_fillmap(); } if( isset($this->map[$ipnum]) ) { $a = $this->map[$ipnum]; $res = array( 'date' => $a['date'], 'reason' => $a['reason'] ); } return $res; } function getall() { if( empty( $this->map ) ) { $this->_fillmap(); } return $this->map; } function tostring() { if( empty( $this->map ) ) { $this->_fillmap(); } $str = ''; foreach( $this->map as $k => $v ) { $str .= $k . ' ' . $v['date']; if( !empty($v['reason']) ) { $str .= ' #' . $v['reason']; } $str .= "\n"; } return $str; } function _fillmap() { $this->map = array(); if( file_exists($this->logfile) ) { $arr = file( $this->logfile ); foreach( $arr as $line ) { $line = trim($line); if( empty($line) ) continue; $pos = strpos($line, '#'); $desc = ($pos?substr($line,$pos+1):''); list($fip, $fdate) = @split( ' ', $line ); $this->map[$fip] = array( 'date' => $fdate, 'reason' => $desc ); } } } } ?>