statsincludes/stats_frontend.php
author Dan
Wed, 31 Dec 2008 21:54:19 -0500
changeset 39 4027a5b47db5
parent 20 e2f6e3af9959
child 51 508400fc5282
permissions -rw-r--r--
echo: added ability to PM people with !pm [nick] [message]
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
##
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     4
## Deletion requests
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     5
##
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     6
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     7
eb_hook('snippet_dynamic', 'if ( $snippet === "deluser" ) return stats_handle_delete_request($chan, $message);');
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     8
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
     9
function stats_handle_delete_request($chan, $message)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    10
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    11
  global $privileged_list, $irc, $stats_data;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    12
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    13
  // remove a user from the DB
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    14
  $targetuser = trim(substr(strstr($message['message'], '|'), 1));
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    15
  if ( empty($targetuser) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    16
    $targetuser = $message['nick'];
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    17
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    18
  if ( $targetuser != $message['nick'] && !in_array($message['nick'], $privileged_list) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    19
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    20
    $irc->privmsg($message['nick'], "Sorry, you need to be a moderator to delete statistics for users other than yourself.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    21
    return true;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    22
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    23
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    24
  // we should be good - delete the user
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    25
  stats_del_user($chan->get_channel_name(), $targetuser);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    26
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    27
  global $nick;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    28
  $greeting = ( $targetuser == $message['nick'] ) ? "All of your statistics data" : "All of {$targetuser}'s statistic data";
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    29
  $irc->privmsg($message['nick'], "$greeting has been removed from the database for all channels. The changes will show up in the next commit to disk, which is usually no more than once every two minutes.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    30
  $irc->privmsg($message['nick'], "Want your stats to be anonymized in the future? Type /msg $nick anonymize to make me keep all your stats anonymous in the future. This only applies to your current nick though - for example if you change your nick to \"{$message['nick']}|sleep\" or similar your information will not be anonymous.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    31
  $irc->privmsg($message['nick'], "You can't clear your logs if you're anonymous. Type /msg $nick denonymize to remove yourself from the anonymization list. Anonymized logs can't be converted back to their original nicks.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    32
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    33
  return true;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    34
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    35
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    36
##
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    37
## Anonymization
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    38
##
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    39
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    40
eb_hook('event_privmsg', 'stats_handle_privmsg($message);');
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    41
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    42
function stats_handle_privmsg($message)
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    43
{
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    44
  global $irc, $stats_data, $nick;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    45
  static $poll_list = array();
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    46
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    47
  $message['message'] = strtolower($message['message']);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    48
  
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    49
  if ( trim($message['message']) === 'anonymize' )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    50
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    51
    if ( stats_anonymize_user_now($message['nick']) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    52
    {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    53
      $irc->privmsg($message['nick'], "Anonymization complete. Any further statistics recorded about you will be anonymous.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    54
      $irc->privmsg($message['nick'], "Do you want to also anonymize any past statistics about you? (type \"yes\" or \"no\")");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    55
      $poll_list[$message['nick']] = true;
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    56
    }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    57
    else
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    58
    {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    59
      $irc->privmsg($message['nick'], "You're already marked as anonymous.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    60
    }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    61
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    62
  else if ( trim($message['message']) === 'denonymize' )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    63
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    64
    if ( stats_denonymize_user($message['nick']) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    65
    {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    66
      $irc->privmsg($message['nick'], "Denonymization complete. Any further statistics recorded about you will bear your nick. Remember that you can always change this with /msg $nick anonymize.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    67
    }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    68
    else
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    69
    {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    70
      $irc->privmsg($message['nick'], "You're not marked as anonymous.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    71
    }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    72
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    73
  else if ( trim($message['message']) === 'yes' && isset($poll_list[$message['nick']]) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    74
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    75
    // anonymize logs for this user
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    76
    stats_anonymize_user_past($message['nick']);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    77
    $irc->privmsg($message['nick'], "Anonymization complete. All past statistics on your nick are now anonymous.");
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    78
    
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    79
    unset($poll_list[$message['nick']]);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    80
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    81
  else if ( isset($poll_list[$message['nick']]) )
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    82
  {
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    83
    unset($poll_list[$message['nick']]);
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    84
  }
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    85
}
e2f6e3af9959 Stats now uses MySQL backend
Dan
parents:
diff changeset
    86