[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Antispam, a plugin for Dotclear 2. |
---|
| 5 | # |
---|
[1179] | 6 | # Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear |
---|
[0] | 7 | # Licensed under the GPL version 2.0 license. |
---|
| 8 | # See LICENSE file or |
---|
| 9 | # http://www.gnu.org/licenses/old-licenses/gpl-2.0.html |
---|
| 10 | # |
---|
| 11 | # -- END LICENSE BLOCK ----------------------------------------- |
---|
| 12 | if (!defined('DC_CONTEXT_ADMIN')) { return; } |
---|
| 13 | dcPage::check('admin'); |
---|
| 14 | |
---|
| 15 | dcAntispam::initFilters(); |
---|
| 16 | $filters = dcAntispam::$filters->getFilters(); |
---|
| 17 | |
---|
| 18 | $page_name = __('Antispam'); |
---|
| 19 | $filter_gui = false; |
---|
| 20 | $default_tab = null; |
---|
| 21 | |
---|
| 22 | try |
---|
| 23 | { |
---|
| 24 | # Show filter configuration GUI |
---|
| 25 | if (!empty($_GET['f'])) |
---|
| 26 | { |
---|
| 27 | if (!isset($filters[$_GET['f']])) { |
---|
| 28 | throw new Exception(__('Filter does not exist.')); |
---|
| 29 | } |
---|
[223] | 30 | |
---|
[0] | 31 | if (!$filters[$_GET['f']]->hasGUI()) { |
---|
| 32 | throw new Exception(__('Filter has no user interface.')); |
---|
| 33 | } |
---|
[223] | 34 | |
---|
[0] | 35 | $filter = $filters[$_GET['f']]; |
---|
| 36 | $filter_gui = $filter->gui($filter->guiURL()); |
---|
| 37 | } |
---|
[223] | 38 | |
---|
[0] | 39 | # Remove all spam |
---|
[1052] | 40 | if (!empty($_POST['delete_all'])) |
---|
[0] | 41 | { |
---|
| 42 | $ts = dt::str('%Y-%m-%d %H:%M:%S',$_POST['ts'],$core->blog->settings->system->blog_timezone); |
---|
[223] | 43 | |
---|
[0] | 44 | dcAntispam::delAllSpam($core,$ts); |
---|
[1052] | 45 | http::redirect($p_url.'&del=1'); |
---|
[0] | 46 | } |
---|
[223] | 47 | |
---|
[0] | 48 | # Update filters |
---|
| 49 | if (isset($_POST['filters_upd'])) |
---|
| 50 | { |
---|
| 51 | $filters_opt = array(); |
---|
| 52 | $i = 0; |
---|
| 53 | foreach ($filters as $fid => $f) { |
---|
| 54 | $filters_opt[$fid] = array(false,$i); |
---|
| 55 | $i++; |
---|
| 56 | } |
---|
[223] | 57 | |
---|
[0] | 58 | # Enable active filters |
---|
| 59 | if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) { |
---|
| 60 | foreach ($_POST['filters_active'] as $v) { |
---|
| 61 | $filters_opt[$v][0] = true; |
---|
| 62 | } |
---|
| 63 | } |
---|
[223] | 64 | |
---|
[0] | 65 | # Order filters |
---|
| 66 | if (!empty($_POST['f_order']) && empty($_POST['filters_order'])) |
---|
| 67 | { |
---|
| 68 | $order = $_POST['f_order']; |
---|
| 69 | asort($order); |
---|
| 70 | $order = array_keys($order); |
---|
| 71 | } |
---|
| 72 | elseif (!empty($_POST['filters_order'])) |
---|
| 73 | { |
---|
| 74 | $order = explode(',',trim($_POST['filters_order'],',')); |
---|
| 75 | } |
---|
[223] | 76 | |
---|
[0] | 77 | if (isset($order)) { |
---|
| 78 | foreach ($order as $i => $f) { |
---|
| 79 | $filters_opt[$f][1] = $i; |
---|
| 80 | } |
---|
| 81 | } |
---|
[223] | 82 | |
---|
[0] | 83 | # Set auto delete flag |
---|
| 84 | if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) { |
---|
| 85 | foreach ($_POST['filters_auto_del'] as $v) { |
---|
| 86 | $filters_opt[$v][2] = true; |
---|
| 87 | } |
---|
| 88 | } |
---|
[223] | 89 | |
---|
[0] | 90 | dcAntispam::$filters->saveFilterOpts($filters_opt); |
---|
| 91 | http::redirect($p_url.'&upd=1'); |
---|
| 92 | } |
---|
| 93 | } |
---|
| 94 | catch (Exception $e) |
---|
| 95 | { |
---|
| 96 | $core->error->add($e->getMessage()); |
---|
| 97 | } |
---|
| 98 | ?> |
---|
| 99 | <html> |
---|
| 100 | <head> |
---|
[892] | 101 | <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'),$filter->name).' - ' : '').$page_name; ?></title> |
---|
[1040] | 102 | <script type="text/javascript"> |
---|
| 103 | //<![CDATA[ |
---|
| 104 | <?php |
---|
| 105 | echo dcPage::jsVar('dotclear.msg.confirm_spam_delete',__('Are you sure you want to delete all spams?')); |
---|
| 106 | ?> |
---|
| 107 | //]]> |
---|
| 108 | </script> |
---|
[0] | 109 | <?php |
---|
[1130] | 110 | echo dcPage::jsPageTabs($default_tab); |
---|
| 111 | $core->auth->user_prefs->addWorkspace('accessibility'); |
---|
| 112 | if (!$core->auth->user_prefs->accessibility->nodragdrop) { |
---|
| 113 | echo |
---|
| 114 | dcPage::jsLoad('js/jquery/jquery-ui.custom.js'). |
---|
| 115 | dcPage::jsLoad('index.php?pf=antispam/antispam.js'); |
---|
[1127] | 116 | } |
---|
[0] | 117 | ?> |
---|
| 118 | <link rel="stylesheet" type="text/css" href="index.php?pf=antispam/style.css" /> |
---|
| 119 | </head> |
---|
| 120 | <body> |
---|
| 121 | <?php |
---|
| 122 | |
---|
| 123 | if ($filter_gui !== false) |
---|
| 124 | { |
---|
[1339] | 125 | dcPage::breadcrumb( |
---|
| 126 | array( |
---|
| 127 | __('Plugins') => '', |
---|
| 128 | $page_name => $p_url, |
---|
| 129 | '<span class="page-title">'.sprintf(__('%s configuration'),$filter->name).'</span>' => '' |
---|
| 130 | )); |
---|
[223] | 131 | |
---|
[0] | 132 | echo $filter_gui; |
---|
| 133 | } |
---|
| 134 | else |
---|
| 135 | { |
---|
[1339] | 136 | dcPage::breadcrumb( |
---|
| 137 | array( |
---|
| 138 | __('Plugins') => '', |
---|
| 139 | '<span class="page-title">'.$page_name.'</span>' => '' |
---|
| 140 | )); |
---|
[505] | 141 | |
---|
[0] | 142 | # Information |
---|
| 143 | $spam_count = dcAntispam::countSpam($core); |
---|
| 144 | $published_count = dcAntispam::countPublishedComments($core); |
---|
| 145 | $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl; |
---|
[223] | 146 | |
---|
[0] | 147 | echo |
---|
[536] | 148 | '<form action="'.$p_url.'" method="post" class="fieldset">'. |
---|
| 149 | '<h3>'.__('Information').'</h3>'; |
---|
[223] | 150 | |
---|
[1052] | 151 | if (!empty($_GET['del'])) { |
---|
[907] | 152 | dcPage::message(__('Spam comments have been successfully deleted.')); |
---|
[0] | 153 | } |
---|
[223] | 154 | |
---|
[0] | 155 | echo |
---|
| 156 | '<ul class="spaminfo">'. |
---|
| 157 | '<li class="spamcount"><a href="comments.php?status=-2">'.__('Junk comments:').'</a> '. |
---|
| 158 | '<strong>'.$spam_count.'</strong></li>'. |
---|
| 159 | '<li class="hamcount"><a href="comments.php?status=1">'.__('Published comments:').'</a> '. |
---|
| 160 | $published_count.'</li>'. |
---|
| 161 | '</ul>'; |
---|
[223] | 162 | |
---|
[0] | 163 | if ($spam_count > 0) |
---|
| 164 | { |
---|
| 165 | echo |
---|
| 166 | '<p>'.$core->formNonce(). |
---|
| 167 | form::hidden('ts',time()). |
---|
[1052] | 168 | '<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>'; |
---|
[0] | 169 | } |
---|
| 170 | if ($moderationTTL != null && $moderationTTL >=0) { |
---|
[565] | 171 | echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '. |
---|
[1207] | 172 | sprintf(__('You can modify this duration in the %s'),'<a href="blog_pref.php#antispam_moderation_ttl"> '.__('Blog preferences').'</a>'). |
---|
[1125] | 173 | '</p>'; |
---|
[0] | 174 | } |
---|
[536] | 175 | echo '</form>'; |
---|
[223] | 176 | |
---|
| 177 | |
---|
[0] | 178 | # Filters |
---|
| 179 | echo |
---|
[1130] | 180 | '<form action="'.$p_url.'" method="post" class="fieldset" id="filters-form">'; |
---|
[223] | 181 | |
---|
[0] | 182 | if (!empty($_GET['upd'])) { |
---|
[907] | 183 | dcPage::message(__('Filters configuration has been successfully saved.')); |
---|
[0] | 184 | } |
---|
[223] | 185 | |
---|
[0] | 186 | echo |
---|
| 187 | '<table class="dragable">'. |
---|
[536] | 188 | '<caption>'.__('Available spam filters').'</caption>'. |
---|
[0] | 189 | '<thead><tr>'. |
---|
| 190 | '<th>'.__('Order').'</th>'. |
---|
| 191 | '<th>'.__('Active').'</th>'. |
---|
[223] | 192 | '<th>'.__('Auto Del.').'</th>'. |
---|
[0] | 193 | '<th class="nowrap">'.__('Filter name').'</th>'. |
---|
| 194 | '<th colspan="2">'.__('Description').'</th>'. |
---|
| 195 | '</tr></thead>'. |
---|
| 196 | '<tbody id="filters-list" >'; |
---|
[223] | 197 | |
---|
[0] | 198 | $i = 0; |
---|
| 199 | foreach ($filters as $fid => $f) |
---|
| 200 | { |
---|
| 201 | $gui_link = ' '; |
---|
| 202 | if ($f->hasGUI()) { |
---|
| 203 | $gui_link = |
---|
| 204 | '<a href="'.html::escapeHTML($f->guiURL()).'">'. |
---|
| 205 | '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '. |
---|
| 206 | 'title="'.__('Filter configuration').'" /></a>'; |
---|
| 207 | } |
---|
[223] | 208 | |
---|
[0] | 209 | echo |
---|
| 210 | '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'. |
---|
[1130] | 211 | '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'. |
---|
[223] | 212 | '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'. |
---|
| 213 | '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'. |
---|
[1280] | 214 | '<td class="nowrap" scope="raw">'.$f->name.'</td>'. |
---|
[0] | 215 | '<td class="maximal">'.$f->description.'</td>'. |
---|
| 216 | '<td class="status">'.$gui_link.'</td>'. |
---|
| 217 | '</tr>'; |
---|
| 218 | $i++; |
---|
| 219 | } |
---|
| 220 | echo |
---|
| 221 | '</tbody></table>'. |
---|
| 222 | '<p>'.form::hidden('filters_order',''). |
---|
| 223 | $core->formNonce(). |
---|
| 224 | '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'. |
---|
[536] | 225 | '</form>'; |
---|
[223] | 226 | |
---|
| 227 | |
---|
[0] | 228 | # Syndication |
---|
| 229 | if (DC_ADMIN_URL) |
---|
| 230 | { |
---|
[776] | 231 | $ham_feed = $core->blog->url.$core->url->getURLFor( |
---|
| 232 | 'hamfeed', |
---|
| 233 | $code = dcAntispam::getUserCode($core) |
---|
| 234 | ); |
---|
| 235 | $spam_feed = $core->blog->url.$core->url->getURLFor( |
---|
| 236 | 'spamfeed', |
---|
| 237 | $code = dcAntispam::getUserCode($core) |
---|
| 238 | ); |
---|
[223] | 239 | |
---|
[0] | 240 | echo |
---|
[536] | 241 | '<h3>'.__('Syndication').'</h3>'. |
---|
[0] | 242 | '<ul class="spaminfo">'. |
---|
| 243 | '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'. |
---|
| 244 | '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'. |
---|
[536] | 245 | '</ul>'; |
---|
[0] | 246 | } |
---|
| 247 | } |
---|
| 248 | ?> |
---|
| 249 | |
---|
| 250 | </body> |
---|
[536] | 251 | </html> |
---|