_globsource = $v; } function set_dest($v) { $this->_dest = $v; } function set_match($v) { $this->_match_source = $v; } //TODO: -It may miss some strings (smileys only lines, etc..) // -Classify lines (notices, /me, etc...) function parse_line($line,$counter) { $output=false; $type=''; $this->msg("parse_line: processing: " . $line); //Usual msg if (preg_match("/^([0-9]{2}:[0-9]{2})\s+<\s?([^\s]+)>\s+(.+)$/",$line, $array)) { $output='msg'; } //Emphatizes /me elseif (preg_match("/^([0-9]{2}:[0-9]{2})\s+\*\s+([^\s]+)\s(.+)$/",$line, $array)) { $output='me'; } //Joins, Quits, etc.. elseif (preg_match("/^([0-9]{2}:[0-9]{2})\s+-!-\s+([^\s]+)\s\[.+\]\s(.+)$/",$line, $array)) { if($this->_show_joins) $output='join'; } if ($output) { $ts = trim($array[1]); $nick = trim($array[2]); $msg = trim($array[3]); return $this->html_row($output,$counter,$ts,$nick,$msg); } } //TODO: -Beautify and colorize output // -CSS entities function html_row($type,$counter, $ts, $nick, $msg) { switch ($type) { case 'msg': $output .= "\t\t\t\t\n"; $output .= "\t\t\t\t\t[".htmlspecialchars($ts)."] \n"; $output .= "\t\t\t\t\t<".htmlspecialchars($nick)."> \n"; $output .= "\t\t\t\t\t".$this->hilite($msg)."\n"; $output .= "\t\t\t\t\n"; break; case 'me': $output .= "\t\t\t\t\n"; $output .= "\t\t\t\t\t[".htmlspecialchars($ts)."] \n"; $output .= "\t\t\t\t\t * ".htmlspecialchars($nick). "  " . $this->hilite($msg) . " \n"; $output .= "\t\t\t\t\n"; break; case 'join': $output .= "\t\t\t\t\n"; $output .= "\t\t\t\t\t[".htmlspecialchars($ts)."] \n"; $output .= "\t\t\t\t\t ".htmlspecialchars($nick)."  ". htmlspecialchars($msg) ." \n"; $output .= "\t\t\t\t\n"; break; } return $output; } function color_from_nick($nick) { $color = "#".substr(bin2hex(md5($nick)),-6,6); return $color; } function hilite($text) { $replace = '/((https?|ftp)+:(\/\/)|(www\.))((\w|\.|\-|_)+)(\/)?(\S+)?/i'; $with = "$4$5"; $output = preg_replace($replace,$with,htmlspecialchars($text)); return $output; } //TODO: -CSS Entities function html_table($content) { $output .= "\t\t\t\n"; $output .= $content; $output .= "\t\t\t
\n"; return $output; } function mk_dest_filename($orig) { $destname = '/dev/null'; $this->msg("mk_dest_filename: Processing: " . $orig); if (preg_match("/^.+\/([0-9]{4})\/.+\/#(.+)\.([0-9]{2}-[0-9]{2})\.log$/i",$orig, $array)) { $destname = $this->_dest . $array[2] .'-'. $array[1] . '-'. $array[3] . '.html'; } return $destname; } //TODO: -Proper loglevel support function msg($s, $level='WARN') { if ($level == $this->_loglevel) echo $s . "\n"; } //TODO: -Customizable fields function html_header() { $output .= "\n"; $output .= "\n"; $output .= "\tLog from #neuros IRC channel\n"; $output .= "\t\n"; $output .= "\t\n"; $output .= "\n"; $output .= "\n"; return $output; } //TODO: -Customizable fields function html_footer() { return "\t\n\n"; } //TODO: -Error handling function parse_file($log) { $fh = fopen($log,'r'); $counter = 1; while(!feof($fh)) { $line=fgets($fh); $output .= $this->parse_line($line,$counter); $counter++; } fclose($fh); return $output; } //TODO: -Error handling function export_html($htmlfile,$content) { $fh = fopen($htmlfile, 'w'); fputs($fh, $this->html_header()); fputs($fh, $this->html_table($content)); fputs($fh, $this->html_footer()); fclose($fh); } function import_from_glob() { $logs = glob($this->_globsource); foreach ($logs as $log) { $content = $this->parse_file($log); $this->export_html($this->mk_dest_filename($log),$content); } } //TODO: -Does not work accurately at the end of the day, // it may miss some strings during the latest period of cron // (That currently means up to a full hour!) // (FIXED) function update() { $date[0] = date('/Y/'); $date[1] = date('.m-d.'); $replace[0] = '/\/\*\//'; $replace[1] = '/\*\./'; $log = preg_replace($replace,$date,$this->_globsource); $content = $this->parse_file($log); $this->export_html($this->mk_dest_filename($log),$content); //Yesterday //Handle yesterday too $yesterday[0] = strftime("/%Y/",strtotime("-1 day")); $yesterday[1] = strftime(".%m-%d.",strtotime("-1 day")); $logy = preg_replace($replace,$yesterday,$this->_globsource); $contenty = $this->parse_file($logy); $this->export_html($this->mk_dest_filename($logy),$contenty); } } //EndOfClass irclogs // Main code $logs = new irclogs(); //$logs->import_from_glob(); $logs->update(); ?>