IRC Logs Viewer! irc_logs
authorThomas Berezansky <tsbere@mvlc.org>
Mon, 26 Mar 2012 21:10:46 +0000 (17:10 -0400)
committerThomas Berezansky <tsbere@mvlc.org>
Mon, 26 Mar 2012 21:10:46 +0000 (17:10 -0400)
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 <tsbere@mvlc.org>
css/style.css
irc_logs.php [new file with mode: 0755]

index 4457b07..5362056 100644 (file)
@@ -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 (executable)
index 0000000..4dbb4b8
--- /dev/null
@@ -0,0 +1,188 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
+   <title>Chat online: Evergreen open source library system</title>
+   <link href="/css/style.css" rel="stylesheet" type="text/css" />
+</head>
+<body>
+<div id="wrap">
+<?php include "/var/www/open-ils.org/incl/header.php" ;?>
+<?php include "/var/www/open-ils.org/incl/news_box.php" ;?>
+<?php include "/var/www/open-ils.org/incl/sidebar.php" ;?>
+<?php /*include "/var/www/open-ils.org/incl/right_sidebar.php" ;*/?>
+<!--end side-->
+<div id="pagebody">
+<h1>Evergreen on IRC</h1>
+<?php 
+    // Ok, what are we being asked to look at, a file or a directory?
+    // First, what were we handed?
+    $check_path = $_GET['check_path'];
+    $check_components = explode('/', $check_path);
+    $channel = null;
+    $month = null;
+    if(!empty($check_components[0])) $channel = $check_components[0];
+    if(!empty($check_components[1])) $month = $check_components[1];
+    $check_path = 'irc_logs/' . $check_path;
+    if(is_dir($check_path)) {
+        // Directory!
+        if($check_path == 'irc_logs/') {
+            // Channel selection. Bah.
+            // Hard-coding the list to get descriptions in.
+?>
+<h3>Channel</h3>
+<p class="content">Please select a channel:</p>
+<ul class="bullet">
+<li class="content"><a href="/irc_logs/evergreen/">#Evergreen - The primary IRC channel where most discussion takes place.</a></li>
+<li class="content"><a href="/irc_logs/openils-evergreen/">#openils-evergreen - Secondary IRC channel, occasionally used as an overflow during meetings and such.</a></li>
+</ul>
+<?php   
+        } else {
+            // Date selection!
+            echo "<h2>Logs for #$channel</h2>";
+            $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 '<div class="irccalendar">';
+                    echo '<h4 class="monthname">', $year, ' ', $monthname, '</h4>';
+                    echo '<table class="month">
+<tr><th>Sun</th><th>Mon</th><th>Tue</th><th>Wed</th><th>Thu</th><th>Fri</th><th>Sat</th></tr>';
+                    $cur_dow = $monthstart % 7;
+                    if($cur_dow != 0)
+                        echo '<tr><td colspan="', $cur_dow, '">&nbsp;</td>';
+                    for($i = 1; $i <= $monthlen; $i++) {
+                        if($cur_dow == 7) {
+                            $cur_dow = 0;
+                            echo '</tr>
+<tr>';
+                        }
+                        $cur_dow++;
+                        $base_filename = $channel . '.' . date_create($month . '-' . $i)->format('d-D-Y') . '.log';
+                        if(is_file('irc_logs/' . $channel . '/' . $month . '/#' . $base_filename)) {
+                            $day = '<a href="/irc_logs/' . $channel . '/' . $month . '/%23' . $base_filename . '">' . $i . '</a>';
+                        } else {
+                            $day = $i;
+                        }
+                        echo '<td>', $day, '</td>';
+                    }
+                    if($cur_dow != 7)
+                        echo '<td colspan="', 7 - $cur_dow, '">&nbsp;</td>';
+                    echo '</tr></table>';
+                    echo '</div>';
+                } else {
+                    if(!$drewprevheader) {
+                        $drewprevheader = true;
+                        echo '<h3>Previous Months</h3>';
+                    }
+                    echo '<h4 class="monthname"><a href="/irc_logs/', $channel, '/', $month, '/">', $year, ' ', $monthname, '</a></h4>';
+                }
+            }
+        }
+    } 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 '<h3>#', $channel, ' Logs for ', $dateobj->format('l, F jS, Y') . '</h3>';
+            // Check for prev/next link possibilities?
+            $nav_block .= '<table class="ircnav"><tr>';
+            $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 .= '<td class="ircprev"><a href="/' . $base_filename . $prevdateobj->format('Y-m') . '/%23' . $channel . '.' . $prevdateobj->format('d-D-Y') . '.log">&lt; ' . $prevdateobj->format('l, F jS, Y') . '</a></td>';
+            $nav_block .= '<td><a href="?raw">Raw Log File</a></td>';
+            $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 .= '<td class="ircnext"><a href="/' . $base_filename . $nextdateobj->format('Y-m') . '/%23' . $channel . '.' . $nextdateobj->format('d-D-Y') . '.log">' . $nextdateobj->format('l, F jS, Y') . ' &gt;</a></td>';
+            $nav_block .= '</tr></table>';
+            echo $nav_block;
+            echo <<<JAVASCRIPT
+<script language="javascript">
+var chanactionsvisible = true;
+function toggleChanActions() {
+    if(chanactionsvisible) {
+        alert
+        chanactionsvisible = false;
+        document.body.setAttribute('class','hiddenchanactions');
+    } else {
+        chanactionsvisible = true;
+        document.body.removeAttribute('class');
+    }
+}
+document.write('<h4 class="actions"><a href="javascript:toggleChanActions()">Toggle Channel Actions</a></h4>');
+</script>
+JAVASCRIPT;
+        }
+        $cur_line = 0;
+        echo '<table class="irctable"><tr class="irchead"><th>#</th><th>Time</th><th>Nick</th><th>Message</th></tr>';
+        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 = '<td class="ircdate">' . $line_parts[1] . '</td>';
+                $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 = '<td class="ircaction" colspan="2">' . htmlentities($raw_line) . '</td>';
+                } elseif(preg_match('/^<([^>]*)> (.*)$/', $raw_line, $line_parts)) {
+                    $line_user = '<td class="ircuser">' . htmlentities($line_parts[1]) . '</td>';
+                    $line = '<td>' . htmlentities($line_parts[2]) . '</td>';
+                }
+            } else {
+                $line_user = '';
+                $line_date = '';
+                $line = '<td colspan="3">' . htmlentities($raw_line) . '</td>';
+            }
+            echo '<tr class="irclog', $extra_class, '"><td><a href="#line', $cur_line, '" name="line', $cur_line, '">#</a></td>', $line_date, $line_user, $line, '</tr>';
+        }
+        echo '</table>';
+        echo $nav_block;
+    } else {
+        // JUNK!
+?>
+<h3>Logs not found</h3>
+<p class="content">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.</p>
+<?php
+    }
+?>
+</div>
+<!--end pagebody-->
+<?php include "/var/www/open-ils.org/incl/footer.php"; ?>
+</div><!--end wrapper-->
+</body>
+</html>