Last active
September 4, 2015 18:14
-
-
Save Ttech/363083 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
GPL | |
2010 | |
[email protected] | |
*/ | |
include("colors.php"); | |
$excludes = array( | |
"alright sparky", | |
"spam" | |
); | |
$actual_lines = 1; | |
$line_change = array( | |
"sets", | |
"has", | |
"kicked" | |
); | |
$users = array(); | |
function is_even($number){ | |
return(!($number & 1)); | |
} | |
function make_users_list($users){ | |
foreach($users as $user => $color){ | |
echo "\t<span style=\"color: $color\">$user</span>\n"; | |
} | |
} | |
function process_line($line_num,$line,$null){ | |
global $excludes,$actual_lines,$colors_list,$users; | |
$date = ""; | |
if(is_even($line_num)){ | |
$line_type = "line_even"; | |
} else { | |
$line_type = "line_odd"; | |
} | |
// We need to create the line correctly, purge anything possibly not usefull to us. | |
// We need a better line thing here but I can't remember what I was saying. | |
$message_parts = explode(" ",$line); | |
if(preg_match("/(.*T.*) (\*\*\* (.*?) .*(has (joined|quit)|sets|was kicked) (.*))/",$line,$matches_result)){ | |
$date = $matches_result[1]; | |
$user = $matches_result[3]; | |
/*if(!$user == $message_parts[3]){ | |
$user = $message_parts[3]; | |
echo "True $user\n"; | |
}*/ | |
$user = str_replace(array("<",">"),"",$message_parts[3]); | |
if(in_array($user,$users)){ | |
$line = str_replace("*** $user","***<span class=\"$user\">$user</span>",$line); | |
} | |
$line = "<span class=\"action\">".$matches_result[2]."</span>\n"; | |
$actual_lines++; | |
} else { | |
foreach($excludes as $exclude){ | |
//if(!stristr($line,$exclude) OR !stristr($line,"***")){ | |
if(preg_match("/([0-9+\$\/_.-]*?T[0-9+\$\:\/_.-]*) .*(\<(.*?)\> .*)/",$line,$matches_result)){ | |
$date = $matches_result[1]; | |
$nick = $matches_result[3]; | |
$user = $matches_result[3]; | |
/*if($user != str_replace(array("<",">"),"",$message_parts[2])){ | |
$user = str_replace(array("<",">"),"",$message_parts[2]); | |
echo "True $user\n"; | |
}*/ | |
$user = str_replace(array("<",">"),"",$message_parts[2]); | |
//echo "A: ".$message_parts[2]."\tB: $user\n"; | |
if(!stristr($line,$exclude)){ | |
if(!fnmatch("*\*\*\* $nick <*!~*\@*> ", $line)){ | |
/*if(stristr($user,"!")){ | |
$user = explode("!",$user); | |
$user = $user[0]; | |
}*/ | |
if(array_key_exists($user,$users)){ | |
$line = str_replace("<$user>","<<span style=\"color: ".$users[$user]."\">$user</span>>",$line); | |
} else { | |
$users[$user] = get_random_color(); | |
} | |
} | |
$actual_lines++; // Increment all lines that are real... | |
} | |
} // end regex line match | |
} // End Foreach | |
} // End IF / Else | |
// Make a nice date format whoa hworth hw ot wrthp st | |
//var_dump($users); | |
$line = str_replace($date,"",$line); | |
$date = str_replace(array(" ","T"),array("","\t"),$date); | |
$proc_line = str_replace(array("\n","\t","\r"),"",$line); | |
echo "<div class=\"$line_type\"><span class=\"linenumbers\">$line_num</span><span class=\"date\">$date</span><span class=\"content\">$proc_line</span></div>\n"; | |
} | |
$filename = "/home/ttech/bot/bot/logs/ChannelLogger/freenode/##transcendence/April/##transcendence.log"; | |
include "header.php"; | |
echo "<div id=\"messages\">"; | |
$lines = file($filename, FILE_SKIP_EMPTY_LINES); | |
foreach ($lines as $line_num => $line) { | |
process_line($line_num,$line,$users); | |
} | |
echo "</div>\n<div id=\"userbar\">"; | |
make_users_list($users); | |
echo "</div>"; | |
include "footer.php"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment