irclogs.php
author Dan
Fri, 09 May 2008 22:19:32 -0400
changeset 6 a802bb5b3e08
parent 5 fcc1eac04772
permissions -rw-r--r--
Made the channel list completely dynamic now
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     1
<?php
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     2
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     3
/**
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     4
 * EnanoBot - copyright (C) 2008 Dan Fuhry
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     5
 * All rights reserved.
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     6
 */
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     7
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     8
/*****************************************************************
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
     9
 * YOU NEED TO SET THE PATH TO THE REST OF THE EnanoBot FILES HERE.
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    10
 * Include a trailing slash.
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    11
 * This script MUST be placed in an Enano installation directory.
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    12
 *****************************************************************/
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    13
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    14
define('ENANOBOT_ROOT', './');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    15
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    16
// We're authed.
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    17
// Load config
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    18
require(ENANOBOT_ROOT . 'config.php');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    19
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    20
// check config
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    21
if ( empty($mysql_host) || empty($mysql_user) || empty($mysql_dbname) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    22
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    23
  die("Bad config file - have a look at config-sample.php.\n");
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    24
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    25
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    26
$title_append = '';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    27
if ( isset($_GET['channel']) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    28
  $title_append .= ' - #' . $_GET['channel'];
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    29
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    30
$title = "Enano IRC logs$title_append";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    31
require('includes/common.php');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    32
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    33
// unset($template);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    34
// $template = new template();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    35
// $template->load_theme('oxygen', 'bleu');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    36
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    37
$template->header();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    38
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    39
$q = $db->sql_query('USE `' . $mysql_dbname . '`;');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    40
if ( !$q )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    41
  $db->_die();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    42
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    43
$days_in_month = array(
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    44
    1 => 31,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    45
    2 => ( intval(date('Y')) % 4 == 0 ? 29 : 28 ),
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    46
    3 => 31,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    47
    4 => 30,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    48
    5 => 31,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    49
    6 => 30,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    50
    7 => 31,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    51
    8 => 31,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    52
    9 => 30,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    53
    10 => 31,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    54
    11 => 30,
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    55
    12 => 31
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    56
  );
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    57
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    58
function irc_make_calendar($year = 0, $month = 0, $days_to_link = array())
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    59
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    60
  global $session;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    61
  global $days_in_month, $channel;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    62
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    63
  if ( $year < 1970 || $month < 1 || $month > 12 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    64
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    65
    $year = intval(date('Y'));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    66
    $month = intval(date('n'));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    67
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    68
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    69
  $month = intval($month);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    70
  $year = intval($year);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    71
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    72
  $this_month = mktime(0, 0, 1, $month, 1, $year);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    73
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    74
  $next_month = mktime(0, 0, 1, ( $month + 1 ), 1, $year);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    75
  $next_year = mktime(0, 0, 1, $month, 1, ( $year + 1 ) );
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    76
  $prev_month = mktime(0, 0, 1, ( $month - 1 ), 1, $year);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    77
  $prev_year = mktime(0, 0, 1, $month, 1, ( $year - 1 ) );
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    78
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    79
  $a_next_month = '<a href="' . htmlspecialchars($session->append_sid(scriptPath . '/irclogs.php?year=' . date('Y', $next_month) . '&month=' . date('n', $next_month) . '&channel=' . $channel)) . '">&gt;</a>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    80
  $a_next_year = '<a href="' . htmlspecialchars($session->append_sid(scriptPath . '/irclogs.php?year=' . date('Y', $next_year) . '&month=' . $month . '&channel=' . $channel)) . '">&gt;&gt;</a>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    81
  $a_prev_month = ( $year == 1970 && $month == 1 ) ? '&lt;' : '<a href="' . htmlspecialchars($session->append_sid(scriptPath . '/irclogs.php?year=' . date('Y', $prev_month) . '&month=' . date('n', $prev_month) . '&channel=' . $channel)) . '">&lt;</a>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    82
  $a_prev_year  = ( $year == 1970 ) ? '&lt;&lt;' : '<a href="' . htmlspecialchars($session->append_sid(scriptPath . '/irclogs.php?year=' . date('Y', $prev_year) . '&month=' . $month . '&channel=' . $channel)) . '">&lt;&lt;</a>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    83
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    84
  $dow = intval(date('w', $this_month));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    85
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    86
  $return = '';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    87
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    88
  $return .= '<div class="tblholder" style="display: table; text-align: center;">
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    89
          <table border="0" cellspacing="1" cellpadding="6">
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    90
            <tr>
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    91
              <th colspan="7">' . "$a_prev_year $a_prev_month " . date('F', $this_month) . ' ' . $year . " $a_next_month $a_next_year" . '</th>
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    92
            </tr>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    93
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    94
  $return .= '<tr>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    95
  $class = 'row1';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    96
  for ( $i = 0; $i < $dow; $i++ )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    97
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    98
    $class = ( $class == 'row1' ) ? 'row3' : 'row1';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
    99
    $return .= '<td class="' . $class . '"></td>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   100
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   101
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   102
  if ( $month == 2 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   103
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   104
    $days_in_this_month = ( $year % 4 == 0 ) ? 29 : 28;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   105
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   106
  else
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   107
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   108
    $days_in_this_month = $days_in_month[$month];
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   109
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   110
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   111
  for ( $i = 1; $i <= $days_in_this_month; $i++ )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   112
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   113
    if ( $dow == 7 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   114
    {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   115
      $return .= '</tr>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   116
      if ( $i < $days_in_this_month )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   117
        $return .= '<tr>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   118
      $dow = 0;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   119
    }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   120
    $dow++;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   121
    $class = ( $class == 'row1' ) ? 'row3' : 'row1';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   122
    $a = "<span style=\"color: #808080;\">$i</span>";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   123
    if ( in_array($i, $days_to_link) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   124
    {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   125
      $a = '<a class="wikilink-nonexistent" href="' . htmlspecialchars($session->append_sid(scriptPath . '/irclogs.php?year=' . $year . '&month=' . $month . '&day=' . $i . '&channel=' . $channel)) . '"><b>' . $i . '</b></a>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   126
    }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   127
    $return .= "<td class=\"$class\">$a</td>";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   128
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   129
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   130
  while ( $dow < 7 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   131
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   132
    $class = ( $class == 'row1' ) ? 'row3' : 'row1';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   133
    $return .= "<td class=\"$class\"></td>";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   134
    $dow++;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   135
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   136
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   137
  $return .= '</table></div>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   138
  return $return;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   139
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   140
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   141
$get_valid_year = isset($_GET['year']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   142
$get_valid_month = ( isset($_GET['month']) && intval($_GET['month']) > 0 && intval($_GET['month']) < 13 );
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   143
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   144
$year = ( $get_valid_year ) ? intval($_GET['year']) : intval(date('Y'));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   145
$month = ( $get_valid_month ) ? intval($_GET['month']) : intval(date('n'));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   146
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   147
function make_nick_color($username)
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   148
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   149
  if ( $username == '' )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   150
    return '';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   151
  $hash = substr(sha1($username), 0, 6);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   152
  $hash = enano_str_split($hash);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   153
  for ( $i = 0; $i < count($hash); $i++ )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   154
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   155
    if ( $i % 2 == 1 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   156
      continue;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   157
    
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   158
    // call this a cheap hack or whatever, but intval() doesn't accept 0x????
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   159
    $digit = eval("return 0x{$hash[$i]};");
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   160
    if ( $digit > 0x9 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   161
      $digit = "9";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   162
    else
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   163
      $digit = strval($digit);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   164
    $hash[$i] = $digit;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   165
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   166
  $color = implode('', $hash);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   167
  $span = "<span style=\"color: #$color;\">" . htmlspecialchars($username) . "</span>";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   168
  return $span;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   169
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   170
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   171
function irclog_autoparse_links($text)
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   172
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   173
  $sid = md5(microtime());
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   174
  preg_match_all('/((https?|ftp|irc):\/\/([^@\s\]"\':]+)?((([a-z0-9-]+\.)*)[a-z0-9-]+)(\/[A-z0-9_%\|~`!\!@#\$\^&\*\(\):;\.,\/-]*(\?(([a-' 
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   175
               . 'z0-9_-]+)(=[A-z0-9_%\|~`\!@#\$\^&\*\(\):;\.,\/-\[\]]*)?((&([a-z0-9_-]+)(=[A-z0-9_%\|~`!\!@#\$\^&\*\(\):;\.,\/-]*)?)*))'
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   176
               . '?)?)?)/', $text, $matches);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   177
  foreach ( $matches[0] as $i => $match )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   178
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   179
    $text = str_replace_once($match, "{AUTOLINK:$sid:$i}", $text);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   180
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   181
  $text = htmlspecialchars($text);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   182
  foreach ( $matches[0] as $i => $match )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   183
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   184
    $match_short = $match;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   185
    if ( strlen($match) > 75 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   186
    {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   187
      $match_short = htmlspecialchars(substr($match, 0, 25)) . '...' . htmlspecialchars(substr($match, -25));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   188
    }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   189
    $match = htmlspecialchars($match);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   190
    $text = str_replace_once("{AUTOLINK:$sid:$i}", "<a href=\"$match\">$match_short</a>", $text);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   191
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   192
  return $text;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   193
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   194
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   195
function irclog_protect_emails($text)
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   196
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   197
  global $email;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   198
  preg_match_all('/([a-z0-9_-]+@(([a-z0-9-]+\.)*)[a-z0-9-]+)/', $text, $matches);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   199
  foreach ( $matches[0] as $match )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   200
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   201
    $text = str_replace_once($match, $email->encryptEmail($match), $text);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   202
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   203
  return $text;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   204
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   205
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   206
function irclog_format_row($_, $row)
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   207
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   208
  static $class = 'row1';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   209
  $class = ( $class == 'row1' ) ? 'row3' : 'row1';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   210
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   211
  $time = date('H:i', $row['timestamp']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   212
  $nick = make_nick_color($row['nick']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   213
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   214
  $message = irclog_autoparse_links($row['line']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   215
  $message = irclog_protect_emails($message);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   216
  $message = RenderMan::smilieyize($message);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   217
  if ( $row['nick'] == '' )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   218
    $message = "<span style=\"color: #808080;\">" . $message . "</span>";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   219
  return "              <tr>
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   220
            <td class=\"$class\">$time</td>
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   221
            <td class=\"$class\">$nick</td>
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   222
            <td class=\"$class\">$message</td>
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   223
          </tr>\n";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   224
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   225
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   226
if ( $get_valid_year && $get_valid_month && isset($_GET['day']) && isset($_GET['channel']) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   227
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   228
  $days_in_this_month = $days_in_month[$month];
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   229
  if ( $month == 2 && $year !== intval(date('n')) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   230
    $days_in_this_month = ( $year % 4 == 0 ) ? 29 : 28;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   231
  $day = intval($_GET['day']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   232
  if ( $day < 1 || $day > $days_in_this_month )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   233
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   234
    $day = intval(date('j'));
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   235
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   236
  // mode is view logs, and we have the date on which to display them
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   237
  $channel = $db->escape($_GET['channel']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   238
  if ( !preg_match('/^[a-z0-9_-]+$/i', $channel) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   239
    die('Channel contains XSS attempt');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   240
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   241
  $datekey = $year . '-' . 
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   242
      ( $month < 10 ? "0$month" : $month ) . '-' . 
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   243
      ( $day < 10 ? "0$day" : $day );
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   244
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   245
  $q = $db->sql_query("SELECT * FROM irclog WHERE day='$datekey' AND channel = '#$channel' ORDER BY timestamp ASC;");
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   246
  if ( !$q )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   247
    $db->_die();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   248
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   249
  echo '<p><a href="' . htmlspecialchars($session->append_sid(scriptPath . "/irclogs.php?year=$year&month=$month&channel=$channel")) . '">&lt; Back to date listings</a></p>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   250
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   251
  if ( $db->numrows() < 1 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   252
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   253
    echo '<p>No chat logs for today.</p>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   254
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   255
  else
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   256
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   257
    $count = $db->numrows();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   258
    
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   259
    $start = ( isset($_GET['start']) ) ? intval($_GET['start']) : 0;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   260
    
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   261
    // ($q, $tpl_text, $num_results, $result_url, $start = 0, $perpage = 10, $callers = Array(), $header = '', $footer = '')
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   262
    $html = paginate($q, '{id}', $count, $session->append_sid(scriptPath . "/irclogs.php?year=$year&month=$month&day=$day&channel=$channel&start=%s"), $start, 100, array('id' => 'irclog_format_row'), '<p>All times are UTC.</p><div class="tblholder"><table border="0" cellspacing="1" cellpadding="4">', '</table></div>');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   263
    
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   264
    echo $html;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   265
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   266
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   267
else if ( isset($_GET['channel']) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   268
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   269
  // show log calendar
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   270
  $channel = $db->escape($_GET['channel']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   271
  if ( !preg_match('/^[a-z0-9_-]+$/i', $channel) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   272
    die('Channel contains XSS attempt');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   273
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   274
  echo "<h3>Chat logs for #$channel</h3>";
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   275
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   276
  echo '<p><a href="' . htmlspecialchars($session->append_sid(scriptPath . "/irclogs.php")) . '">&lt; Back to channel list</a></p>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   277
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   278
  $year = strval($year);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   279
  $month = strval($month);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   280
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   281
  if ( $month < 10 )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   282
    $month = "0" . $month;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   283
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   284
  $q = $db->sql_query("SELECT day FROM irclog WHERE day LIKE '$year-$month-__' AND channel = '#$channel' GROUP BY day ORDER BY timestamp ASC;");
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   285
  if ( !$q )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   286
    $db->_die();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   287
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   288
  $days = array();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   289
  while ( $row = $db->fetchrow() )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   290
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   291
    if ( !preg_match('/^[0-9]+-[0-9]+-([0-9]+)$/', $row['day'], $match) )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   292
    {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   293
      continue;
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   294
    }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   295
    $days[] = intval($match[1]);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   296
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   297
  
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   298
  echo irc_make_calendar($year, $month, $days);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   299
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   300
else
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   301
{
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   302
  // list channels
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   303
  $q = $db->sql_query("SELECT channel FROM irclog GROUP BY channel;");
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   304
  if ( !$q )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   305
    $db->_die();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   306
  echo '<h3>List of available channels</h3>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   307
  if ( $row = $db->fetchrow() )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   308
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   309
    echo '<p>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   310
    do
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   311
    {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   312
      $channel = preg_replace('/^#/', '', $row['channel']);
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   313
      echo '<a href="' . htmlspecialchars($session->append_sid(scriptPath . "/irclogs.php?channel={$channel}")) . '">' . $row['channel'] . '</a><br />';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   314
    }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   315
    while ( $row = $db->fetchrow() );
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   316
    echo '</p>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   317
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   318
  else
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   319
  {
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   320
    echo '<p>No channels logged.</p>';
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   321
  }
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   322
}
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   323
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   324
$q = $db->sql_query('USE enano_www;');
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   325
if ( !$q )
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   326
  $db->_die();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   327
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   328
$template->footer();
fcc1eac04772 Prepped for public distribution.
Dan
parents:
diff changeset
   329