From 260361d9567f40db8d83f57d5a59f06996bf34c8 Mon Sep 17 00:00:00 2001 From: Thomas Berezansky Date: Mon, 26 Mar 2012 17:10:46 -0400 Subject: [PATCH] IRC Logs Viewer! To use, add the following to the apache configs: RewriteEngine On RewriteCond %{QUERY_STRING} !raw RewriteRule ^/?irc_logs/(.*) /irc_logs.php?check_path=$1 [T=php-script] Oh, and if we don't have it enabled, don't forget to enable mod_rewrite. Signed-off-by: Thomas Berezansky Signed-off-by: Ben Shum --- css/style.css | 14 +++++ irc_logs.php | 188 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100755 irc_logs.php diff --git a/css/style.css b/css/style.css index 4457b076f..53620568f 100644 --- a/css/style.css +++ b/css/style.css @@ -399,3 +399,17 @@ table.contenttable1 .tr-1 .td-s {background: #77AA77 !important;text-align:cente table.contenttable1 .tr-1 .td-u {background: #FBB19B !important;text-align:center; } /* unstable */ table.contenttable1 .tr-1 .td-p {background: #FBFFB3!important;text-align:center; } /* preview */ +.ircaction { font-weight: bold; } +.ircuser { font-weight: bold; } +table.month td, table.month th, table.irctable td, table.irctable th +{ +border: 1px solid green; +padding: 5px; +} +.hiddenchanactions .chanaction { +display: none; +} +.ircnav { +margin: auto; +text-align: center; +} diff --git a/irc_logs.php b/irc_logs.php new file mode 100755 index 000000000..4dbb4b8df --- /dev/null +++ b/irc_logs.php @@ -0,0 +1,188 @@ + + + + + Chat online: Evergreen open source library system + + + +
+ + + + + +
+

Evergreen on IRC

+ +

Channel

+

Please select a channel:

+ +Logs for #$channel"; + $months = array(); + $drawcalendars = true; + $drewprevheader = false; + if($month) { + $months[] = $month; + } else { + $files = scandir($check_path); + foreach($files as $file) { + if($file[0] == '.') continue; + $months[] = $file; + } + $months = array_reverse($months); + } + foreach($months as $month) { + list($year,$monthname,$monthnum,$monthstart,$monthlen) = explode(':', date_create($month . '-01')->format('Y:F:m:N:t')); + if($drawcalendars) { + $drawcalendars = false; + echo '
'; + echo '

', $year, ' ', $monthname, '

'; + echo ' +'; + $cur_dow = $monthstart % 7; + if($cur_dow != 0) + echo ''; + for($i = 1; $i <= $monthlen; $i++) { + if($cur_dow == 7) { + $cur_dow = 0; + echo ' +'; + } + $cur_dow++; + $base_filename = $channel . '.' . date_create($month . '-' . $i)->format('d-D-Y') . '.log'; + if(is_file('irc_logs/' . $channel . '/' . $month . '/#' . $base_filename)) { + $day = '' . $i . ''; + } else { + $day = $i; + } + echo ''; + } + if($cur_dow != 7) + echo ''; + echo '
SunMonTueWedThuFriSat
 
', $day, ' 
'; + echo '
'; + } else { + if(!$drewprevheader) { + $drewprevheader = true; + echo '

Previous Months

'; + } + echo '

', $year, ' ', $monthname, '

'; + } + } + } + } elseif (is_file($check_path)) { + // A log file! + $filename = $check_components[2]; + $file_contents = file($check_path); + $file_date = array(); + // #evergreen.17-Sat-2012.log + $nav_block = ''; + if(preg_match('/^#[^.]*\.(\d*)-/', $filename, $file_date)) { + $cur_date = $month . '-' . $file_date[1]; + $dateobj = date_create($cur_date); + echo '

#', $channel, ' Logs for ', $dateobj->format('l, F jS, Y') . '

'; + // Check for prev/next link possibilities? + $nav_block .= ''; + $base_filename = 'irc_logs/' . $channel . '/'; + $dateint = new DateInterval('P1D'); + $prevdateobj = clone $dateobj; + $prevdateobj->sub($dateint); + $prev_file = $base_filename . $prevdateobj->format('Y-m') . '/#' . $channel . '.' . $prevdateobj->format('d-D-Y') . '.log'; + if(is_file($prev_file)) + $nav_block .= ''; + $nav_block .= ''; + $nextdateobj = clone $dateobj; + $nextdateobj->add($dateint); + $next_file = $base_filename . $nextdateobj->format('Y-m') . '/#' . $channel . '.' . $nextdateobj->format('d-D-Y') . '.log'; + if(is_file($next_file)) + $nav_block .= ''; + $nav_block .= '
< ' . $prevdateobj->format('l, F jS, Y') . 'Raw Log File' . $nextdateobj->format('l, F jS, Y') . ' >
'; + echo $nav_block; + echo << +var chanactionsvisible = true; +function toggleChanActions() { + if(chanactionsvisible) { + alert + chanactionsvisible = false; + document.body.setAttribute('class','hiddenchanactions'); + } else { + chanactionsvisible = true; + document.body.removeAttribute('class'); + } +} +document.write('

Toggle Channel Actions

'); + +JAVASCRIPT; + } + $cur_line = 0; + echo ''; + foreach($file_contents as $raw_line) { + $cur_line++; + $line_parts = array(); + $extra_class = ''; + if(preg_match('/^.{10}T(\d{2}:\d{2}:\d{2}) (.*)$/', $raw_line, $line_parts)) { + $line_date = ''; + $raw_line = trim($line_parts[2]); + if($raw_line[0] == '*') { + // "Me" line or channel action? + if($raw_line[1] == '*') { + // Assume channel action. + $extra_class .= ' chanaction'; + $raw_line = substr($raw_line, 4); + } else { + // Me line + $extra_class .= ' me_line'; + $raw_line = substr($raw_line, 2); + } + $line_user = ''; + $line = ''; + } elseif(preg_match('/^<([^>]*)> (.*)$/', $raw_line, $line_parts)) { + $line_user = ''; + $line = ''; + } + } else { + $line_user = ''; + $line_date = ''; + $line = ''; + } + echo '', $line_date, $line_user, $line, ''; + } + echo '
#TimeNickMessage
' . $line_parts[1] . '' . htmlentities($raw_line) . '' . htmlentities($line_parts[1]) . '' . htmlentities($line_parts[2]) . '' . htmlentities($raw_line) . '
#
'; + echo $nav_block; + } else { + // JUNK! +?> +

Logs not found

+

We would show you a list of logs for browsing, or an actual log, but there isn't anything to show you at the URL you linked to. Sorry.

+ +
+ + +
+ + -- 2.11.0