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