Skip to content

Instantly share code, notes, and snippets.

@Ttech
Created June 21, 2010 23:02
Show Gist options
  • Save Ttech/447669 to your computer and use it in GitHub Desktop.
Save Ttech/447669 to your computer and use it in GitHub Desktop.
<?php
error_reporting(0);
include("colors.php");
$excludes = array(
"alright sparky",
"spam"
);
$actual_lines = 1;
$line_change = array(
"sets",
"has",
"kicked"
);
$dates = array(
"January" => 01,
"Febuary" => 02,
"March" => 03,
"April" => 05,
"May" => 05,
"June" => 06,
"July" => 07,
"August" => 08,
"September" => 09,
"October" => 10,
"November" => 11,
"December" => 12
);
$users = array();
$channel = "#transcendence";
$stats_totals = array(
"actions" => 1,
"messages" => 1
);
/* Found at http://kzar.co.uk/blog/view/strip-unicode-utf-php */
function strip_utf($string) {
for ($i = 0; $i < strlen ($string); $i++)
if (ord($string[$i]) > 127)
$string[$i] = " ";
return $string;
}
function generate_day($users,$filename){
global $dates,$month,$day;
}
function debug(){
global $channel,$network,$month,$day,$filename;
echo "<pre>";
echo "Information\r\nChannel: $channel\nNetwork = $network\nMonth = $month\nDay = $day\nFilename = $filename\n</div></div></body></html>";
echo "</pre>";
}
function get_channel_name(){
global $channel;
echo $channel;
}
function make_display_stats(){
global $stats_totals, $filename;
$message_total = $stats_totals['messages'];
$actions_total = $stats_totals['actions'];
if(file_exists($filename)){
print "Channel Stats: <i>Total Messages: ".$message_total.", Total Actions: ".$actions_total."</i>";
}
}
function make_date_list(){
global $dates;
if(isset($_GET['channel'])){
$channel = stripslashes(htmlentities($_GET['channel']));
}
//$line = "\t\t<div class=\"dates\"><p>";
$line = "";
foreach($dates as $date){
echo " / <a href=\"?month=$date\">$date</a> /";
}
//$line .= "</p></div>";
}
function get_last_updated($filename=__FILE__){
// Why the heck is filemtime not workign here?!
if(!file_exists($filename)){
$filename = __FILE__;
}
print date("F d H:i:s.",filemtime($filename));
}
function is_even($number){
return(!($number & 1));
}
function make_users_list($users){
echo "\t\t<ul>\n";
foreach($users as $user => $color){
if(!stristr($user,"*")){
echo "\t\t\t<li style=\"color: $color\">$user</li>\n";
}
}
echo "\t\t</ul>";
}
function process_line($line_num,$line,$null){
global $excludes,$actual_lines,$colors_list,$users,$stats_totals;
$date = "";
if(is_even($line_num)){
$line_type = "line_even";
} else {
$line_type = "line_odd";
}
$line = htmlentities($line);
// 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) (.*))/",htmlspecialchars_decode($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("<",">","&gt;","&lt;"),"",$message_parts[3]);
/*if(in_array($user,$users)){
$line = str_replace("*** $user","*** <span class=\"nick\">$user</span>",$line);
}*/
$line = "<span class=\"action\">".$matches_result[2]."</span>\n";
$actual_lines++;
$stats_totals['actions']++;
} elseif(stristr($line,"***") OR stristr($line,"* ")){
$date = $message_parts[0];
$user = $message_parts[3];
$user = str_replace(array("<",">","&gt;","&lt;"),"",$message_parts[3]);
$line = "<span class=\"action\">".$line."</span>\n";
$actual_lines++;
$stats_totals['actions']++;
} else {
foreach($excludes as $exclude){
//if(!stristr($line,$exclude) OR !stristr($line,"***")){
if(preg_match("/([0-9+\$\/_.-]*?T[0-9+\$\:\/_.-]*) .*(\<(.*?)\> .*)/",htmlspecialchars_decode($line),$matches_result)){
$date = $matches_result[1];
$nick = $matches_result[3];
$user = $matches_result[3];
$user = str_replace(array("<",">","&gt;","&lt;"),"",$message_parts[2]);
//echo "A: ".$message_parts[2]."\tB: $user\n";
if(!stristr($line,$exclude)){
if(!fnmatch("*\*\*\* $nick &lt;*!~*\@*\&gt; ", $line) OR !fnmatch("*\*\*\* $nick <*!~*\@*> ", $line)){
/*if(stristr($user,"!")){
$user = explode("!",$user);
$user = $user[0];
}*/
if(array_key_exists($user,$users)){
$line = str_replace(array("&lt;$user&gt;","<$user>"),"<span class=\"nick\"><span style=\"color: ".$users[$user]."\">$user</span></span>",$line);
} else {
$users[$user] = get_random_color();
}
}
$actual_lines++; // Increment all lines that are real...
$stats_totals['messages']++;
}
} // 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);
// Massive hack goes here... Fix later
//$date = str_replace(array(" ","T"),array("","\t"),$date);
$date_parts = explode("T", $date);
$date = "<span class=\"prefix\"><span class=\"date\">".$date_parts[0];
if(isset($date[1])){
@$date .= "<span class=\"time\">".str_replace(" ","",$date_parts[1])."</span>";
}
$date .= "</span></span>";
// End hack
$proc_line = str_replace(array("\n","\t","\r"," "," "),"",$line);
echo "\t\t\t<div class=\"$line_type\"><span class=\"linenumbers\">$line_num</span>$date<span class=\"content\">".strip_utf($proc_line)."</span></div>\n";
}
if(@isset($_GET['channel']) OR @stristr($_GET['channel'],"##")){
$channel = str_replace(array("#"),"",stripslashes(strval(urldecode($_GET['channel']))));
} elseif(isset($channel)){
$channel = str_replace(array("#"),"",stripslashes(strval(urldecode($channel))));
}
if(isset($_GET['month'])){
$month = stripslashes(strval(urldecode($_GET['month'])));
} else {
$month = date("F");
}
if(isset($_GET['year']) OR !isset($month)){
$year = stripslashes(intval(urldecode($_GET['year'])));
} else {
$year = date("Y");
}
if(isset($_GET['day'])){
$day = stripslashes(intval(urldecode($_GET['day'])));
} else {
$day = date("d");
}
if(isset($_GET['network'])){
$network = stripslashes(strval(urldecode($_GET['network'])));
} else {
$network = "freenode";
}
include "header.php";
$filename = /srv/bot/logs/ChannelLogger/$network/#$channel/$month/$channel.log";
if(file_exists($filename)){
echo "\t\t<div id=\"messages\">\n";
$lines = @file($filename, FILE_SKIP_EMPTY_LINES);
foreach ($lines as $line_num => $line) {
$date_string = date('Y')."-".sprintf("%02s",$dates[$month])."-".sprintf("%02s",$day);
if(stristr($line,$date_string) OR (@strval($_GET['display_all']) == '1')){
process_line($line_num,$line,$users);
} else {
//echo "<!-- No content for $date_string -->\n";
//echo "<hr>$date_string<br>$line";
}
}
echo "\t\t</div>\n\t </div>\n\t<div id=\"userbar\">\n";
make_users_list($users);
echo "\t</div>";
} else {
echo "\t\t<div id=\"messages\"><p>Sorry no channel exists by that name perhaps you should remove the forward # from the name and try again?</p></div>";
}
include "footer.php";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment