[0] | 1 | <?php |
---|
| 2 | # -- BEGIN LICENSE BLOCK --------------------------------------- |
---|
| 3 | # |
---|
| 4 | # This file is part of Antispam, a plugin for Dotclear 2. |
---|
| 5 | # |
---|
| 6 | # Copyright (c) 2003-2010 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 | http::redirect($p_url.'&del=1'); |
---|
| 46 | } |
---|
| 47 | |
---|
| 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 | } |
---|
| 57 | |
---|
| 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 | } |
---|
| 64 | |
---|
| 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 | } |
---|
| 76 | |
---|
| 77 | if (isset($order)) { |
---|
| 78 | foreach ($order as $i => $f) { |
---|
| 79 | $filters_opt[$f][1] = $i; |
---|
| 80 | } |
---|
| 81 | } |
---|
| 82 | |
---|
| 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 | } |
---|
| 89 | |
---|
| 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> |
---|
| 101 | <title><?php echo $page_name; ?></title> |
---|
| 102 | <?php |
---|
| 103 | echo |
---|
| 104 | dcPage::jsToolMan(). |
---|
| 105 | dcPage::jsPageTabs($default_tab). |
---|
| 106 | dcPage::jsLoad('index.php?pf=antispam/antispam.js'); |
---|
| 107 | ?> |
---|
| 108 | <link rel="stylesheet" type="text/css" href="index.php?pf=antispam/style.css" /> |
---|
| 109 | </head> |
---|
| 110 | <body> |
---|
| 111 | <?php |
---|
| 112 | echo '<h2>'.html::escapeHTML($core->blog->name).' › '.$page_name.'</h2>'; |
---|
| 113 | |
---|
| 114 | if ($filter_gui !== false) |
---|
| 115 | { |
---|
| 116 | echo '<p><a href="'.$p_url.'">'.__('Return to filters').'</a></p>'; |
---|
| 117 | printf('<h3>'.__('%s configuration').'</h3>',$filter->name); |
---|
| 118 | |
---|
| 119 | echo $filter_gui; |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | # Information |
---|
| 124 | $spam_count = dcAntispam::countSpam($core); |
---|
| 125 | $published_count = dcAntispam::countPublishedComments($core); |
---|
| 126 | $moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl; |
---|
| 127 | |
---|
| 128 | echo |
---|
| 129 | '<form action="'.$p_url.'" method="post">'. |
---|
| 130 | '<fieldset><legend>'.__('Information').'</legend>'; |
---|
| 131 | |
---|
| 132 | if (!empty($_GET['del'])) { |
---|
| 133 | echo '<p class="message">'.__('Spam comments have been successfully deleted.').'</p>'; |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | echo |
---|
| 137 | '<ul class="spaminfo">'. |
---|
| 138 | '<li class="spamcount"><a href="comments.php?status=-2">'.__('Junk comments:').'</a> '. |
---|
| 139 | '<strong>'.$spam_count.'</strong></li>'. |
---|
| 140 | '<li class="hamcount"><a href="comments.php?status=1">'.__('Published comments:').'</a> '. |
---|
| 141 | $published_count.'</li>'. |
---|
| 142 | '</ul>'; |
---|
| 143 | |
---|
| 144 | if ($spam_count > 0) |
---|
| 145 | { |
---|
| 146 | echo |
---|
| 147 | '<p>'.$core->formNonce(). |
---|
| 148 | form::hidden('ts',time()). |
---|
| 149 | '<input name="delete_all" type="submit" value="'.__('Delete all spams').'" /></p>'; |
---|
| 150 | } |
---|
| 151 | if ($moderationTTL != null && $moderationTTL >=0) { |
---|
| 152 | echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).'</p>'; |
---|
| 153 | } |
---|
| 154 | echo '</fieldset></form>'; |
---|
| 155 | |
---|
| 156 | |
---|
| 157 | # Filters |
---|
| 158 | echo |
---|
| 159 | '<form action="'.$p_url.'" method="post">'. |
---|
| 160 | '<fieldset><legend>'.__('Available spam filters').'</legend>'; |
---|
| 161 | |
---|
| 162 | if (!empty($_GET['upd'])) { |
---|
| 163 | echo '<p class="message">'.__('Filters configuration has been successfully saved.').'</p>'; |
---|
| 164 | } |
---|
| 165 | |
---|
| 166 | echo |
---|
| 167 | '<table class="dragable">'. |
---|
| 168 | '<thead><tr>'. |
---|
| 169 | '<th>'.__('Order').'</th>'. |
---|
| 170 | '<th>'.__('Active').'</th>'. |
---|
| 171 | '<th>'.__('Auto Del.').'</th>'. |
---|
| 172 | '<th class="nowrap">'.__('Filter name').'</th>'. |
---|
| 173 | '<th colspan="2">'.__('Description').'</th>'. |
---|
| 174 | '</tr></thead>'. |
---|
| 175 | '<tbody id="filters-list" >'; |
---|
| 176 | |
---|
| 177 | $i = 0; |
---|
| 178 | foreach ($filters as $fid => $f) |
---|
| 179 | { |
---|
| 180 | $gui_link = ' '; |
---|
| 181 | if ($f->hasGUI()) { |
---|
| 182 | $gui_link = |
---|
| 183 | '<a href="'.html::escapeHTML($f->guiURL()).'">'. |
---|
| 184 | '<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '. |
---|
| 185 | 'title="'.__('Filter configuration').'" /></a>'; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | echo |
---|
| 189 | '<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'. |
---|
| 190 | '<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i).'</td>'. |
---|
| 191 | '<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active).'</td>'. |
---|
| 192 | '<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete).'</td>'. |
---|
| 193 | '<td class="nowrap">'.$f->name.'</td>'. |
---|
| 194 | '<td class="maximal">'.$f->description.'</td>'. |
---|
| 195 | '<td class="status">'.$gui_link.'</td>'. |
---|
| 196 | '</tr>'; |
---|
| 197 | $i++; |
---|
| 198 | } |
---|
| 199 | echo |
---|
| 200 | '</tbody></table>'. |
---|
| 201 | '<p>'.form::hidden('filters_order',''). |
---|
| 202 | $core->formNonce(). |
---|
| 203 | '<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'. |
---|
| 204 | '</fieldset></form>'; |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | # Syndication |
---|
| 208 | if (DC_ADMIN_URL) |
---|
| 209 | { |
---|
| 210 | $ham_feed = $core->blog->url.$core->url->getBase('hamfeed').'/'.$code = dcAntispam::getUserCode($core); |
---|
| 211 | $spam_feed = $core->blog->url.$core->url->getBase('spamfeed').'/'.$code = dcAntispam::getUserCode($core); |
---|
| 212 | |
---|
| 213 | echo |
---|
| 214 | '<fieldset><legend>'.__('Syndication').'</legend>'. |
---|
| 215 | '<ul class="spaminfo">'. |
---|
| 216 | '<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'. |
---|
| 217 | '<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'. |
---|
| 218 | '</ul>'. |
---|
| 219 | '</fieldset>'; |
---|
| 220 | } |
---|
| 221 | } |
---|
| 222 | ?> |
---|
| 223 | |
---|
| 224 | </body> |
---|
| 225 | </html> |
---|