4 * File: MassDelete.Admin.class.php
5 * Mass delete comment spam
7 * Copyright (C) 2004-2008 by the following authors:
9 * Author Tom Willett tomw AT pigstye DOT net
11 * Licensed under GNU General Public License
17 if (strpos(strtolower($_SERVER['PHP_SELF']), 'massdelete.admin.class.php') !== false) {
18 die('This file can not be used on its own!');
22 * Include Abstract Base Class and comment library
24 require_once $_CONF['path'] . 'plugins/spamx/BaseAdmin.class.php';
25 require_once $_CONF['path_system'] . 'lib-comment.php';
28 * MassDelete class: Mass-delete comments
33 class MassDelete extends BaseAdmin {
40 global $_CONF, $_TABLES, $LANG_SX00;
42 $display = $LANG_SX00['masshead'];
45 if (isset($_POST['action'])) {
46 $act = COM_applyFilter($_POST['action']);
49 if (isset($_POST['limit'])) {
50 $lmt = COM_applyFilter($_POST['limit'], true);
53 if (($act == $LANG_SX00['deletespam']) && ($lmt > 0) &&
56 $spamx_path = $_CONF['path'] . 'plugins/spamx/';
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;
65 require_once $spamx_path . $file;
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) {
78 if(method_exists($EX, 'reexecute'))
80 $res = $EX->reexecute($A['comment'], $A['date'], $A['ipaddress'], $A['type']);
82 $res = $EX->execute($A['comment']);
89 $this->delcomment($A['cid'], $A['sid'], $A['type']);
93 $display .= '<p>' . $numc . $LANG_SX00['comdel'] . '</p>' . LB;
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'] . ' '
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>'
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;
127 return 'Mass Delete Spam Comments';
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
139 function delcomment($cid, $sid, $type)
141 global $_CONF, $_TABLES, $LANG_SX00;
143 $type = COM_applyFilter($type);
144 $sid = COM_applyFilter($sid);
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);
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,
161 COM_errorLog("User {$_USER['username']} (IP: {$_SERVER['REMOTE_ADDR']}) tried to illegally delete comment $cid from $type $sid");
165 default: // assume plugin
166 PLG_commentDelete($type, COM_applyFilter($cid, true), $sid);
169 SPAMX_log($LANG_SX00['spamdeleted']);