plugins/spamx/MassDelTrackback.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:  MassDelTrackback.Admin.class.php
     5 *
     6 * Mass delete trackback spam
     7 *
     8 * Copyright (C) 2004-2008 by the following authors:
     9 *
    10 * @author   Tom Willett     tomw AT pigstye DOT net
    11 * @author   Dirk Haun       dirk AT haun-online DOT de
    12 *
    13 * Licensed under GNU General Public License
    14 *
    15 * @package Spam-X
    16 * @subpackage Modules
    17 */
    18 
    19 if (strpos(strtolower($_SERVER['PHP_SELF']), 'massdeltrackback.admin.class.php') !== false) {
    20     die('This file can not be used on its own!');
    21 }
    22 
    23 /**
    24 * Include Abstract Base Class
    25 */
    26 require_once $_CONF['path'] . 'plugins/spamx/BaseAdmin.class.php';
    27 
    28 /**
    29 * MassDelTrackback class: Mass-delete trackbacks
    30 *
    31 * @package Spam-X
    32 *
    33 */
    34 class MassDelTrackback extends BaseAdmin {
    35 
    36     function display()
    37     {
    38         global $_CONF, $_TABLES, $LANG_SX00;
    39 
    40         $display = $LANG_SX00['masstb'];
    41 
    42         $act = '';
    43         if (isset($_POST['action'])) {
    44             $act = COM_applyFilter($_POST['action']);
    45         }
    46         $lmt = 0;
    47         if (isset($_POST['limit'])) {
    48             $lmt = COM_applyFilter($_POST['limit'], true);
    49         }
    50 
    51         if (($act == $LANG_SX00['deletespam']) && ($lmt > 0) &&
    52                 SEC_checkToken()) {
    53             $numc = 0;
    54             $spamx_path = $_CONF['path'] . 'plugins/spamx/';
    55 
    56             if ($dir = @opendir($spamx_path)) {
    57                 while (($file = readdir($dir)) !== false) {
    58                     if (is_file($spamx_path . $file)) {
    59                         if (substr($file, -18) == '.Examine.class.php') {
    60                             $tmp = str_replace('.Examine.class.php', '', $file);
    61                             $Spamx_Examine[] = $tmp;
    62 
    63                             require_once $spamx_path . $file;
    64                         }
    65                     }
    66                 }
    67                 closedir($dir);
    68             }
    69 
    70             require_once $_CONF['path_system'] . 'lib-trackback.php';
    71 
    72             $result = DB_query("SELECT cid,sid,type,url,title,blog,excerpt,ipaddress,UNIX_TIMESTAMP(date) AS date FROM {$_TABLES['trackback']} ORDER BY date DESC LIMIT $lmt");
    73             $nrows = DB_numRows($result);
    74             for ($i = 0; $i < $nrows; $i++) {
    75                 $A = DB_fetchArray($result);
    76                 $comment = TRB_formatComment($A['url'], $A['title'],
    77                                              $A['blog'], $A['excerpt']);
    78 
    79                 foreach ($Spamx_Examine as $Examine) {
    80                     $EX = new $Examine;
    81                     if(method_exists($EX, 'reexecute'))
    82                     {
    83                     	$res = $EX->reexecute($comment, $A['date'], $A['ipaddress'], $A['type']);
    84                     } else {
    85                     	$res = $EX->execute($comment);
    86                     }
    87                     if ($res == 1) {
    88                         break;
    89                     }
    90                 }
    91                 if ($res == 1) {
    92                     $this->deltrackback($A['cid'], $A['sid'], $A['type']);
    93                     $numc = $numc + 1;
    94                 }
    95             }
    96             $display .= '<p>' . $numc . $LANG_SX00['comdel'] . '</p>' . LB;
    97         } else {
    98             $token = SEC_createToken();
    99             $display .= '<form method="post" action="'
   100                      . $_CONF['site_admin_url']
   101                      . '/plugins/spamx/index.php?command=MassDelTrackback"><div>';
   102             $display .= $LANG_SX00['numtocheck'] . '&nbsp;&nbsp;&nbsp;'
   103                      . ' <select name="limit">' . LB;
   104             $display .= '<option value="10">10</option>'
   105                      .  '<option value="50">50</option>'
   106                      .  '<option value="100" selected="selected">100</option>'
   107                      .  '<option value="200">200</option>'
   108                      .  '<option value="300">300</option>'
   109                      .  '<option value="400">400</option>';
   110             $display .= '</select>' . LB;
   111             $display .= $LANG_SX00['note1'];
   112             $display .= $LANG_SX00['note2'];
   113             $display .= $LANG_SX00['note3'];
   114             $display .= $LANG_SX00['note4'];
   115             $display .= $LANG_SX00['note5'];
   116             $display .= $LANG_SX00['note6'] . LB;
   117             $display .= '<input type="submit" name="action" value="'
   118                      . $LANG_SX00['deletespam'] . '"' . XHTML . '>' . LB;
   119             $display .= '<input type="hidden" name="' . CSRF_TOKEN
   120                      . "\" value=\"{$token}\"" . XHTML . '>' . LB;
   121             $display .= '</div></form>' . LB;
   122         }
   123 
   124         return $display;
   125     }
   126 
   127     function link()
   128     {
   129         global $LANG_SX00;
   130 
   131         return 'Mass Delete Trackback Spam';
   132     }
   133 
   134     /**
   135     * Deletes a given trackback comment
   136     *
   137     * @param    int         $cid    Comment ID
   138     * @param    string      $sid    ID of object comment belongs to
   139     * @param    string      $type   Comment type (e.g. article, poll, etc)
   140     * @return   void
   141     *
   142     */
   143     function deltrackback($cid, $sid, $type)
   144     {
   145         global $_TABLES, $LANG_SX00;
   146 
   147         if (TRB_allowDelete($sid, $type)) {
   148             TRB_deleteTrackbackComment($cid);
   149 
   150             if ($type == 'article') {
   151                 $tbcount = DB_count($_TABLES['trackback'],
   152                                     array('type', 'sid'),
   153                                     array('article', $sid));
   154                 DB_query("UPDATE {$_TABLES['stories']} SET trackbacks = $tbcount WHERE sid = '$sid'");
   155             }
   156 
   157             SPAMX_log($LANG_SX00['spamdeleted']);
   158         }
   159     }
   160 }
   161 
   162 ?>