Index: bot_views/bot_views.info
===================================================================
RCS file: bot_views/bot_views.info
diff -N bot_views/bot_views.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_views/bot_views.info	19 Dec 2009 13:05:29 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Bot views
+package = Bot
+description = "Enables views integration for bot logs."
+dependencies[] = bot_log
+dependencies[] = views
+core = 6.x
Index: bot_views/bot_views.install
===================================================================
RCS file: bot_views/bot_views.install
diff -N bot_views/bot_views.install
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_views/bot_views.install	19 Dec 2009 13:05:29 -0000
@@ -0,0 +1,9 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_install().
+ */
+function bot_views_install() {
+  db_query("UPDATE {system} SET weight = 11 WHERE name = 'bot_views'");
+}
Index: bot_views/bot_views.module
===================================================================
RCS file: bot_views/bot_views.module
diff -N bot_views/bot_views.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_views/bot_views.module	19 Dec 2009 13:05:29 -0000
@@ -0,0 +1,84 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Enables views integration for bot logs.
+ */
+
+/**
+ * Implementation of hook_views_api.
+ * Notifies the Views module that we're compatible with a particular API revision.
+ */
+function bot_views_views_api() {
+  return array('api' => 2);
+}
+
+/**
+ * Implementation of hook_theme().
+ *
+ * Define theme functions for bot_views/bot_views.module.
+ */
+function bot_views_theme($existing, $type, $theme, $path) {
+  return array(
+    'views_view_table__bot_log' => array(
+      'arguments' => array(
+        'view' => NULL, 
+        'options' => NULL, 
+        'rows' => NULL, 
+        'title' => NULL,
+      ),
+      'template' => '/views-view-table--bot-log',
+      'path' => $path,
+      'original hook' => 'views_view_table',
+    ),
+  );
+}
+
+/**
+ * Override or insert variables used in views-view-table--bot-log.
+ */
+function bot_views_preprocess_views_view_table__bot_log(&$vars) {
+  // Load type constants.
+  include_once("Net/SmartIRC/defines.php");
+  // Load css for some styling.
+  drupal_add_css(drupal_get_path('module', 'bot_log') .'/bot_log.css');
+  foreach ($vars['rows'] as $index => $row) {
+    // Build class for each table row.
+    $last_nick = $last_nick ? $last_nick : $row['nick'];
+    $last_class = $last_class ? $last_class : 'bot-log-nick-odd';
+    $nick_class = ($last_nick == $row['nick']) ? $last_class : (($last_class == 'bot-log-nick-even') ? 'bot-log-nick-odd' : 'bot-log-nick-even');
+    $vars['row_classes'][$index][] = $nick_class;
+    // Handle message types.
+    $filter_message = TRUE;
+    switch ($row['type']) {
+      case SMARTIRC_TYPE_JOIN:
+        $message = t('* @nick has joined @channel', array('@nick' => $row['nick'], '@channel' => $row['channel']));
+        break;
+      case SMARTIRC_TYPE_PART:
+        $message = t('* @nick has left @channel (@reason)', array('@nick' => $row['nick'], '@channel' => $row['channel'], '@reason' => $row['message']));
+        break; 
+      case SMARTIRC_TYPE_QUIT:
+        $message = t('* @nick has quit (@reason)', array('@nick' => $row['nick'], '@reason' => $row['message']));
+        break;
+      case SMARTIRC_TYPE_ACTION:
+        $row['message'] = preg_replace('/^ACTION/', '', trim($row['message'], '')); // odd bits.
+        $message = t('* @nick @message', array('@nick' => $row['nick'], '@message' => $row['message']));
+        break;
+      case SMARTIRC_TYPE_NICKCHANGE:
+        $message = t('* @nick is now known as @new_nick', array('@nick' => $row['nick'], '@new_nick' => $row['message']));
+        break;
+      case SMARTIRC_TYPE_TOPICCHANGE:
+        $message = t('* @nick has changed the topic to @topic', array('@nick' => $row['nick'], '@topic' => $row['message']));
+        break;
+      default:
+        $message = $row['message'];
+        $filter_message = FALSE;
+        break;
+    }
+    // If there are URLs, make them links and shorten them if they're long.
+    if (!variable_get('bot_log_dont_change_the_content', FALSE) || !$filter_message) {
+      $vars['rows'][$index]['message'] = filter_filter('process', 2, 'bot_log', $message);
+    }
+  }
+}
Index: bot_views/bot_views.views.inc
===================================================================
RCS file: bot_views/bot_views.views.inc
diff -N bot_views/bot_views.views.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_views/bot_views.views.inc	19 Dec 2009 13:05:29 -0000
@@ -0,0 +1,108 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Provide views data and handlers for bot_views/bot_views.module
+ */
+
+/**
+ * @defgroup bot_views/bot_views.module handlers
+ *
+ * Includes the ability to create views of the bot_log table.
+ * @{
+ */
+
+/**
+ * Implementation of hook_views_data()
+ */
+function bot_views_views_data() {
+  // Basic table information.
+
+  $data['bot_log']['table']['group']  = t('Bot');
+
+  // Advertise this table as a possible base table.
+  $data['bot_log']['table']['base'] = array(
+    'field' => 'id',
+    'title' => t('Bot log'),
+    'help' => t('Message logged by bot.module in IRC channels.'),
+    'weight' => 10,
+  );
+
+  // Message id value provided by Net_SmartIRC.
+  $data['bot_log']['type'] = array(
+    'title' => t('Message type'),
+    'help' => t('The message id value provided by Net_SmartIRC.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => FALSE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  // Log message timestamp.
+  $data['bot_log']['timestamp'] = array(
+    'title' => t('Message timestamp'),
+    'help' => t('The Unix timestamp the log message occurred.'),
+    'field' => array(
+      'handler' => 'views_handler_field_date',
+      'click sortable' => TRUE,
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_date',
+    ),
+  );
+
+  // Log message channel.
+  $data['bot_log']['channel'] = array(
+    'title' => t('Channel'),
+    'help' => t('The IRC channel or channels where this log message occurred.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  // Log message nickname.
+  $data['bot_log']['nick'] = array(
+    'title' => t('Nickname'),
+    'help' => t('The IRC user that caused this log message to occur.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  // Log message.
+  $data['bot_log']['message'] = array(
+    'title' => t('Message'),
+    'help' => t('The log message itself.'),
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+    ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_string',
+    ),
+  );
+
+  return $data;
+}
+
+/**
+ * @}
+ */
Index: bot_views/bot_views.views_default.inc
===================================================================
RCS file: bot_views/bot_views.views_default.inc
diff -N bot_views/bot_views.views_default.inc
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_views/bot_views.views_default.inc	19 Dec 2009 13:05:30 -0000
@@ -0,0 +1,274 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * View for listing bot log messages.
+ */
+
+function bot_views_views_default_views() {
+  $view = new view;
+  $view->name = 'bot_log';
+  $view->description = '';
+  $view->tag = '';
+  $view->view_php = '';
+  $view->base_table = 'bot_log';
+  $view->is_cacheable = FALSE;
+  $view->api_version = 2;
+  $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
+  $handler = $view->new_display('default', 'Defaults', 'default');
+  $handler->override_option('fields', array(
+    'timestamp' => array(
+      'label' => 'Timestamp',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'date_format' => 'custom',
+      'custom_date_format' => 'Y-m-d H:i:s',
+      'exclude' => 0,
+      'id' => 'timestamp',
+      'table' => 'bot_log',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+      'override' => array(
+        'button' => 'Override',
+      ),
+    ),
+    'nick' => array(
+      'label' => 'Nickname',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'nick',
+      'table' => 'bot_log',
+      'field' => 'nick',
+      'relationship' => 'none',
+    ),
+    'message' => array(
+      'label' => 'Message',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'message',
+      'table' => 'bot_log',
+      'field' => 'message',
+      'relationship' => 'none',
+    ),
+    'type' => array(
+      'label' => 'Type',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'type',
+      'table' => 'bot_log',
+      'field' => 'type',
+      'relationship' => 'none',
+    ),
+    'channel' => array(
+      'label' => 'Channel',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'exclude' => 0,
+      'id' => 'channel',
+      'table' => 'bot_log',
+      'field' => 'channel',
+      'override' => array(
+        'button' => 'Override',
+      ),
+      'relationship' => 'none',
+    ),
+    'timestamp_1' => array(
+      'label' => '',
+      'alter' => array(
+        'alter_text' => 0,
+        'text' => '',
+        'make_link' => 0,
+        'path' => '',
+        'link_class' => '',
+        'alt' => '',
+        'prefix' => '',
+        'suffix' => '',
+        'target' => '',
+        'help' => '',
+        'trim' => 0,
+        'max_length' => '',
+        'word_boundary' => 1,
+        'ellipsis' => 1,
+        'strip_tags' => 0,
+        'html' => 0,
+      ),
+      'empty' => '',
+      'hide_empty' => 0,
+      'empty_zero' => 0,
+      'date_format' => 'custom',
+      'custom_date_format' => 'l, Y-m-d',
+      'exclude' => 0,
+      'id' => 'timestamp_1',
+      'table' => 'bot_log',
+      'field' => 'timestamp',
+      'relationship' => 'none',
+    ),
+  ));
+  $handler->override_option('access', array(
+    'type' => 'none',
+  ));
+  $handler->override_option('cache', array(
+    'type' => 'none',
+  ));
+  $handler->override_option('use_ajax', TRUE);
+  $handler->override_option('items_per_page', 50);
+  $handler->override_option('use_pager', '1');
+  $handler->override_option('style_plugin', 'table');
+  $handler->override_option('style_options', array(
+    'grouping' => 'timestamp_1',
+    'override' => 1,
+    'sticky' => 1,
+    'order' => 'asc',
+    'columns' => array(
+      'timestamp' => 'timestamp',
+      'nick' => 'nick',
+      'message' => 'message',
+      'type' => 'type',
+      'channel' => 'channel',
+      'timestamp_1' => 'timestamp_1',
+    ),
+    'info' => array(
+      'timestamp' => array(
+        'sortable' => 1,
+        'separator' => '',
+      ),
+      'nick' => array(
+        'sortable' => 0,
+        'separator' => '',
+      ),
+      'message' => array(
+        'sortable' => 0,
+        'separator' => '',
+      ),
+      'type' => array(
+        'separator' => '',
+      ),
+      'channel' => array(
+        'sortable' => 0,
+        'separator' => '',
+      ),
+      'timestamp_1' => array(
+        'sortable' => 0,
+        'separator' => '',
+      ),
+    ),
+    'default' => 'timestamp',
+  ));
+  $handler = $view->new_display('page', 'Page', 'page_1');
+  $handler->override_option('path', 'logs');
+  $handler->override_option('menu', array(
+    'type' => 'normal',
+    'title' => 'Logs',
+    'description' => '',
+    'weight' => '-10',
+    'name' => 'navigation',
+  ));
+  $handler->override_option('tab_options', array(
+    'type' => 'none',
+    'title' => '',
+    'description' => '',
+    'weight' => 0,
+  ));
+
+  $views[$view->name] = $view;
+  return $views;
+}
Index: bot_views/views-view-table--bot-log.tpl.php
===================================================================
RCS file: bot_views/views-view-table--bot-log.tpl.php
diff -N bot_views/views-view-table--bot-log.tpl.php
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ bot_views/views-view-table--bot-log.tpl.php	19 Dec 2009 13:05:30 -0000
@@ -0,0 +1,55 @@
+<?php
+// $Id$
+
+/**
+ * @file views-view-table--bot-log.tpl.php
+ * Template to display the bot log view as a table.
+ *
+ * - $title : The title of this group of rows.  May be empty.
+ * - $header: An array of header labels keyed by field id.
+ * - $fields: An array of CSS IDs to use for each field id.
+ * - $class: A class or classes to apply to the table, based on settings.
+ * - $row_classes: An array of classes to apply to each row, indexed by row
+ *   number. This matches the index in $rows.
+ * - $rows: An array of row items. Each row is an array of content.
+ *   $rows are keyed by row number, fields within rows are keyed by field ID.
+ * @ingroup views_templates
+ */
+?>
+<table class="<?php print $class; ?>" id="bot-log-day">
+  <?php if (!empty($title)) : ?>
+    <caption><?php print $title; ?></caption>
+  <?php endif; ?>
+  <thead>
+    <tr>
+      <th class="views-field views-field-<?php print $header['timestamp'][$field]; ?>"><?php print $header['timestamp']; ?></th>
+      <th class="views-field views-field-<?php print $header['nick'][$field]; ?>"><?php print $header['nick']; ?></th>
+      <th class="views-field views-field-<?php print $header['message'][$field]; ?>"><?php print $header['message']; ?></th>
+    </tr>
+  </thead>
+  <tbody>
+<?php 
+  foreach ($rows as $count => $row) { 
+?>
+    <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
+      <td class="bot-log-time"><?php print $row['timestamp']; ?></td>
+<?php
+    if ($row['type'] == SMARTIRC_TYPE_CHANNEL) {
+?>
+      <td class="bot-log-nick"><?php print $row['nick']; ?></td>
+      <td class="bot-log-message"><?php print $row['message']; ?></td>
+<?php
+    }
+    else {
+      $type = ($row['type'] == SMARTIRC_TYPE_ACTION) ? 'action' : 'status';
+?>
+      <td class="bot-log-<?php print $type; ?>" colspan="2"><?php print $row['message']; ?></td>
+<?php
+    }
+?>
+    </tr>
+<?php
+  }
+?>
+  </tbody>
+</table>
