statsincludes/stats_frontend.php
changeset 20 e2f6e3af9959
child 51 508400fc5282
equal deleted inserted replaced
19:eb92dc5d9fb4 20:e2f6e3af9959
       
     1 <?php
       
     2 
       
     3 ##
       
     4 ## Deletion requests
       
     5 ##
       
     6 
       
     7 eb_hook('snippet_dynamic', 'if ( $snippet === "deluser" ) return stats_handle_delete_request($chan, $message);');
       
     8 
       
     9 function stats_handle_delete_request($chan, $message)
       
    10 {
       
    11   global $privileged_list, $irc, $stats_data;
       
    12   
       
    13   // remove a user from the DB
       
    14   $targetuser = trim(substr(strstr($message['message'], '|'), 1));
       
    15   if ( empty($targetuser) )
       
    16     $targetuser = $message['nick'];
       
    17   
       
    18   if ( $targetuser != $message['nick'] && !in_array($message['nick'], $privileged_list) )
       
    19   {
       
    20     $irc->privmsg($message['nick'], "Sorry, you need to be a moderator to delete statistics for users other than yourself.");
       
    21     return true;
       
    22   }
       
    23   
       
    24   // we should be good - delete the user
       
    25   stats_del_user($chan->get_channel_name(), $targetuser);
       
    26   
       
    27   global $nick;
       
    28   $greeting = ( $targetuser == $message['nick'] ) ? "All of your statistics data" : "All of {$targetuser}'s statistic data";
       
    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.");
       
    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.");
       
    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.");
       
    32   
       
    33   return true;
       
    34 }
       
    35 
       
    36 ##
       
    37 ## Anonymization
       
    38 ##
       
    39 
       
    40 eb_hook('event_privmsg', 'stats_handle_privmsg($message);');
       
    41 
       
    42 function stats_handle_privmsg($message)
       
    43 {
       
    44   global $irc, $stats_data, $nick;
       
    45   static $poll_list = array();
       
    46   
       
    47   $message['message'] = strtolower($message['message']);
       
    48   
       
    49   if ( trim($message['message']) === 'anonymize' )
       
    50   {
       
    51     if ( stats_anonymize_user_now($message['nick']) )
       
    52     {
       
    53       $irc->privmsg($message['nick'], "Anonymization complete. Any further statistics recorded about you will be anonymous.");
       
    54       $irc->privmsg($message['nick'], "Do you want to also anonymize any past statistics about you? (type \"yes\" or \"no\")");
       
    55       $poll_list[$message['nick']] = true;
       
    56     }
       
    57     else
       
    58     {
       
    59       $irc->privmsg($message['nick'], "You're already marked as anonymous.");
       
    60     }
       
    61   }
       
    62   else if ( trim($message['message']) === 'denonymize' )
       
    63   {
       
    64     if ( stats_denonymize_user($message['nick']) )
       
    65     {
       
    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.");
       
    67     }
       
    68     else
       
    69     {
       
    70       $irc->privmsg($message['nick'], "You're not marked as anonymous.");
       
    71     }
       
    72   }
       
    73   else if ( trim($message['message']) === 'yes' && isset($poll_list[$message['nick']]) )
       
    74   {
       
    75     // anonymize logs for this user
       
    76     stats_anonymize_user_past($message['nick']);
       
    77     $irc->privmsg($message['nick'], "Anonymization complete. All past statistics on your nick are now anonymous.");
       
    78     
       
    79     unset($poll_list[$message['nick']]);
       
    80   }
       
    81   else if ( isset($poll_list[$message['nick']]) )
       
    82   {
       
    83     unset($poll_list[$message['nick']]);
       
    84   }
       
    85 }
       
    86