1<?php 2 3/** 4 * Created by IntelliJ IDEA. 5 * User: clay 6 * Date: 8/23/15 7 * Time: 6:04 PM 8 */ 9class SpamLogger 10{ 11 public $logfile; 12 public $logdir; 13 14 public function __construct($logdir) 15 { 16 $this->logdir = $logdir; 17 $this->logfile = "StopForumSpam-" . date("Y-m") . ".csv"; 18 } 19 20 public function LogAttempt($username, $email, $ip, $trigger, $confidence, $accepted) 21 { 22 $fd = $this->OpenLogFile(); 23 $dt = new DateTime(); 24 25 fputcsv($fd, array( 26 $dt->format(DateTime::ISO8601), 27 $username, 28 $email, 29 $ip, 30 $trigger, 31 $confidence, 32 $accepted ? "accepted" : "rejected" 33 )); 34 35 } 36 37 private function OpenLogFile() 38 { 39 $filename = $this->logdir . "/" . $this->logfile; 40 if (file_exists($filename)) { 41 $fd = fopen($filename, "a"); 42 } else { 43 if (!file_exists($this->logdir)) { 44 mkdir($this->logdir, 0755, true); 45 } 46 $fd = fopen($filename, "w"); 47 fputcsv($fd, array( 48 "DATE", 49 "USERNAME", 50 "EMAIL", 51 "IP", 52 "TRIGGER", 53 "CONFIDENCE", 54 "ACCEPTED" 55 )); 56 } 57 return $fd; 58 } 59}