statsincludes/stats_core.php
author Dan
Sat, 10 Jan 2009 14:08:11 -0500
changeset 49 4c4d69b2cd4d
parent 20 e2f6e3af9959
permissions -rw-r--r--
Rehash: added support for channel changing
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
20
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     1
<?php
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     2
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     3
$stats_anonymize_list = array();
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     4
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     5
eb_hook('startup_early', 'stats_core_cache_anons();');
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     6
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     7
function stats_core_cache_anons()
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     8
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     9
  global $stats_anonymize_list;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    10
  if ( $q = eb_mysql_query('SELECT nick FROM stats_anon;') )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    11
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    12
    while ( $row = mysql_fetch_assoc($q) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    13
    {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    14
      $stats_anonymize_list[] = $row['nick'];
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    15
    }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    16
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    17
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    18
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    19
function stats_log_message($channel, $nick, $timestamp)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    20
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    21
  // anonymize message?
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    22
  global $stats_anonymize_list;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    23
  if ( in_array($nick, $stats_anonymize_list) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    24
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    25
    $nick = 'Anonymous';
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    26
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    27
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    28
  $channel = db_escape($channel);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    29
  $nick = db_escape($nick);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    30
  $sql = 'INSERT INTO stats_messages(channel, nick, time) ' . "VALUES('$channel', '$nick', " . intval($timestamp) . ");";
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    31
  eb_mysql_query($sql);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    32
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    33
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    34
function stats_anonymize_user_now($nick)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    35
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    36
  global $stats_anonymize_list;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    37
  // anonymize list is cached in RAM
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    38
  if ( in_array($nick, $stats_anonymize_list) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    39
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    40
    return false;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    41
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    42
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    43
  $stats_anonymize_list[] = $nick;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    44
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    45
  $nick = db_escape($nick);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    46
  eb_mysql_query("INSERT INTO stats_anon(nick) VALUES('$nick');");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    47
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    48
  return true;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    49
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    50
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    51
function stats_anonymize_user_past($nick)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    52
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    53
  global $stats_anonymize_list;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    54
  if ( !in_array($nick, $stats_anonymize_list) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    55
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    56
    return false;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    57
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    58
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    59
  $nick = db_escape($nick);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    60
  eb_mysql_query("UPDATE stats_messages SET nick = 'Anonymous' WHERE nick = '$nick';");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    61
  return true;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    62
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    63
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    64
function stats_denonymize_user($nick)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    65
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    66
  global $stats_anonymize_list;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    67
  if ( !in_array($nick, $stats_anonymize_list) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    68
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    69
    return false;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    70
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    71
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    72
  $nick = db_escape($nick);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    73
  eb_mysql_query("DELETE FROM stats_anon WHERE nick = '$nick';");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    74
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    75
  unset($stats_anonymize_list[ array_search($nick, $stats_anonymize_list) ]);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    76
  return true;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    77
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    78
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    79
function stats_del_user($chan, $nick)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    80
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    81
  $chan = db_escape($chan);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    82
  $nick = db_escape($nick);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    83
  eb_mysql_query("DELETE FROM stats_messages WHERE channel = '$chan' AND nick = '$nick';");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    84
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    85