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