plugins/spamx/MassDelete.Admin.class.php
author Dirk Haun <dirk@haun-online.de>
Thu, 29 Oct 2009 13:00:11 +0100
branchHEAD
changeset 7397 c27e9026f22a
parent 6838 cb1ba8d99085
child 8352 fc233fa7fa1d
permissions -rw-r--r--
Fixed inclusion protection
     1 <?php
     2 
     3 /**
     4 * File:  MassDelete.Admin.class.php
     5 * Mass delete comment spam
     6 *
     7 * Copyright (C) 2004-2008 by the following authors:
     8 *
     9 * Author        Tom Willett        tomw AT pigstye DOT net
    10 *
    11 * Licensed under GNU General Public License
    12 *
    13 * @package Spam-X
    14 * @subpackage Modules
    15 */
    16 
    17 if (strpos(strtolower($_SERVER['PHP_SELF']), 'massdelete.admin.class.php') !== false) {
    18     die('This file can not be used on its own!');
    19 }
    20 
    21 /**
    22 * Include Abstract Base Class and comment library
    23 */
    24 require_once $_CONF['path'] . 'plugins/spamx/BaseAdmin.class.php';
    25 require_once $_CONF['path_system'] . 'lib-comment.php';
    26 
    27 /**
    28 * MassDelete class: Mass-delete comments
    29 *
    30 * @package Spam-X
    31 *
    32 */
    33 class MassDelete extends BaseAdmin {
    34     /**
    35     * Constructor
    36     *
    37     */
    38     function display()
    39     {
    40         global $_CONF, $_TABLES, $LANG_SX00;
    41 
    42         $display = $LANG_SX00['masshead'];
    43 
    44         $act = '';
    45         if (isset($_POST['action'])) {
    46             $act = COM_applyFilter($_POST['action']);
    47         }
    48         $lmt = 0;
    49         if (isset($_POST['limit'])) {
    50             $lmt = COM_applyFilter($_POST['limit'], true);
    51         }
    52 
    53         if (($act == $LANG_SX00['deletespam']) && ($lmt > 0) &&
    54                 SEC_checkToken()) {
    55             $numc = 0;
    56             $spamx_path = $_CONF['path'] . 'plugins/spamx/';
    57 
    58             if ($dir = @opendir($spamx_path)) {
    59                 while (($file = readdir($dir)) !== false) {
    60                     if (is_file($spamx_path . $file)) {
    61                         if (substr($file, -18) == '.Examine.class.php') {
    62                             $tmp = str_replace('.Examine.class.php', '', $file);
    63                             $Spamx_Examine[] = $tmp;
    64 
    65                             require_once $spamx_path . $file;
    66                         }
    67                     }
    68                 }
    69                 closedir($dir);
    70             }
    71 
    72             $result = DB_query("SELECT comment,cid,sid,type,UNIX_TIMESTAMP(date) as date,ipaddress FROM {$_TABLES['comments']} ORDER BY date DESC LIMIT $lmt");
    73             $nrows = DB_numRows($result);
    74             for ($i = 0; $i < $nrows; $i++) {
    75                 $A = DB_fetchArray($result);
    76                 foreach ($Spamx_Examine as $Examine) {
    77                     $EX = new $Examine;
    78                     if(method_exists($EX, 'reexecute'))
    79                     {
    80                     	$res = $EX->reexecute($A['comment'], $A['date'], $A['ipaddress'], $A['type']);
    81                     } else {
    82                     	$res = $EX->execute($A['comment']);
    83                     }
    84                     if ($res == 1) {
    85                         break;
    86                     }
    87                 }
    88                 if ($res == 1) {
    89                     $this->delcomment($A['cid'], $A['sid'], $A['type']);
    90                     $numc = $numc + 1;
    91                 }
    92             }
    93             $display .= '<p>' . $numc . $LANG_SX00['comdel'] . '</p>' . LB;
    94         } else {
    95             $token = SEC_createToken();
    96             $display .= '<form method="post" action="'
    97                      .  $_CONF['site_admin_url']
    98                      .  '/plugins/spamx/index.php?command=MassDelete"><div>';
    99             $display .= $LANG_SX00['numtocheck'] . '&nbsp;&nbsp;&nbsp;'
   100                      .  ' <select name="limit">' . LB;
   101             $display .= '<option value="10">10</option>' . LB
   102                      .  '<option value="50">50</option>' . LB
   103                      .  '<option value="100" selected="selected">100</option>'
   104                      .  LB
   105                      .  '<option value="200">200</option>' . LB
   106                      .  '<option value="300">300</option>' . LB
   107                      .  '<option value="400">400</option>' . LB;
   108             $display .= '</select>' . LB;
   109             $display .= $LANG_SX00['note1'];
   110             $display .= $LANG_SX00['note2'];
   111             $display .= $LANG_SX00['note3'];
   112             $display .= $LANG_SX00['note4'];
   113             $display .= $LANG_SX00['note5'];
   114             $display .= $LANG_SX00['note6'] . LB;
   115             $display .= '<input type="submit" name="action" value="'
   116                      . $LANG_SX00['deletespam'] . '"' . XHTML . '>' . LB;
   117             $display .= '<input type="hidden" name="' . CSRF_TOKEN
   118                  . "\" value=\"{$token}\"" . XHTML . '>' . LB;
   119             $display .= '</div></form>' . LB;
   120         }
   121 
   122         return $display;
   123     }
   124 
   125     function link()
   126     {
   127         return 'Mass Delete Spam Comments';
   128     }
   129 
   130     /**
   131     * Deletes a given comment
   132     * (lifted from comment.php)
   133     * @param    int         $cid    Comment ID
   134     * @param    string      $sid    ID of object comment belongs to
   135     * @param    string      $type   Comment type (e.g. article, poll, etc)
   136     * @return   string      Returns string needed to redirect page to right place
   137     *
   138     */
   139     function delcomment($cid, $sid, $type)
   140     {
   141         global $_CONF, $_TABLES, $LANG_SX00;
   142 
   143         $type = COM_applyFilter($type);
   144         $sid = COM_applyFilter($sid);
   145 
   146         switch ($type) {
   147         case 'article':
   148             $has_editPermissions = SEC_hasRights('story.edit');
   149             $result = DB_query("SELECT owner_id,group_id,perm_owner,perm_group,perm_members,perm_anon FROM {$_TABLES['stories']} WHERE sid = '$sid'");
   150             $A = DB_fetchArray($result);
   151 
   152             if ($has_editPermissions && SEC_hasAccess($A['owner_id'],
   153                     $A['group_id'], $A['perm_owner'], $A['perm_group'],
   154                     $A['perm_members'], $A['perm_anon']) == 3) {
   155                 CMT_deleteComment(COM_applyFilter($cid, true), $sid, 'article');
   156                 $comments = DB_count($_TABLES['comments'],
   157                         array('sid', 'type'), array($sid, 'article'));
   158                 DB_change($_TABLES['stories'], 'comments', $comments,
   159                           'sid', $sid);
   160             } else {
   161                 COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) tried to illegally delete comment $cid from $type $sid");
   162             }
   163             break;
   164 
   165         default: // assume plugin
   166             PLG_commentDelete($type, COM_applyFilter($cid, true), $sid);
   167             break;
   168         }
   169         SPAMX_log($LANG_SX00['spamdeleted']);
   170     }
   171 }
   172 
   173 ?>