Dotclear

source: plugins/antispam/index.php @ 3707:3a350757c847

Revision 3707:3a350757c847, 8.5 KB checked in by franck <carnet.franck.paul@…>, 7 years ago (diff)

Use array form of optionnal parameters for form::checkbox() where is relevant, code formatting (PSR-2)

Line 
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 -----------------------------------------
12if (!defined('DC_CONTEXT_ADMIN')) {return;}
13dcPage::check('admin');
14
15dcAntispam::initFilters();
16$filters = dcAntispam::$filters->getFilters();
17
18$page_name   = __('Antispam');
19$filter_gui  = false;
20$default_tab = null;
21
22try
23{
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        }
29
30        if (!$filters[$_GET['f']]->hasGUI()) {
31            throw new Exception(__('Filter has no user interface.'));
32        }
33
34        $filter     = $filters[$_GET['f']];
35        $filter_gui = $filter->gui($filter->guiURL());
36    }
37
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);
41
42        dcAntispam::delAllSpam($core, $ts);
43
44        dcPage::addSuccessNotice(__('Spam comments have been successfully deleted.'));
45        http::redirect($p_url);
46    }
47
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        }
56
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        }
63
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        }
72
73        if (isset($order)) {
74            foreach ($order as $i => $f) {
75                $filters_opt[$f][1] = $i;
76            }
77        }
78
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        }
85
86        dcAntispam::$filters->saveFilterOpts($filters_opt);
87
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());
93}
94?>
95<html>
96<head>
97  <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'), $filter->name) . ' - ' : '') . $page_name; ?></title>
98  <script type="text/javascript">
99  <?php
100echo dcPage::jsVar('dotclear.msg.confirm_spam_delete', __('Are you sure you want to delete all spams?'));
101?>
102  </script>
103  <?php
104echo dcPage::jsPageTabs($default_tab);
105$core->auth->user_prefs->addWorkspace('accessibility');
106if (!$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') .
110    dcPage::jsLoad(dcPage::getPF('antispam/antispam.js'));
111}
112echo dcPage::cssLoad(dcPage::getPF('antispam/style.css'));
113?>
114</head>
115<body>
116<?php
117
118if ($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();
126
127    echo '<p><a href="' . $p_url . '" class="back">' . __('Back to filters list') . '</a></p>';
128
129    echo $filter_gui;
130
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();
141
142    # Information
143    $spam_count      = dcAntispam::countSpam($core);
144    $published_count = dcAntispam::countPublishedComments($core);
145    $moderationTTL   = $core->blog->settings->antispam->antispam_moderation_ttl;
146
147    echo
148    '<form action="' . $p_url . '" method="post" class="fieldset">' .
149    '<h3>' . __('Information') . '</h3>';
150
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>';
158
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>';
172
173    # Filters
174    echo
175        '<form action="' . $p_url . '" method="post" id="filters-list-form">';
176
177    if (!empty($_GET['upd'])) {
178        dcPage::success(__('Filters configuration has been successfully saved.'));
179    }
180
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" >';
193
194    $i = 0;
195    foreach ($filters as $fid => $f) {
196        $gui_link = '&nbsp;';
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        }
203
204        echo
205        '<tr class="line' . ($f->active ? '' : ' offline') . '" id="f_' . $fid . '">' .
206        '<td class="handle">' . form::field(array('f_order[' . $fid . ']'), 2, 5, (string) $i, 'position', '', false, 'title="' . __('position') . '"') . '</td>' .
207        '<td class="nowrap">' . form::checkbox(array('filters_active[]'), $fid,
208            array(
209                'checked'    => $f->active,
210                'extra_html' => 'title="' . __('Active') . '"'
211            )
212        ) . '</td>' .
213        '<td class="nowrap">' . form::checkbox(array('filters_auto_del[]'), $fid,
214            array(
215                'checked'    => $f->auto_delete,
216                'extra_html' => 'title="' . __('Auto Del.') . '"'
217            )
218        ) . '</td>' .
219        '<td class="nowrap" scope="row">' . $f->name . '</td>' .
220        '<td class="maximal">' . $f->description . '</td>' .
221            '<td class="status">' . $gui_link . '</td>' .
222            '</tr>';
223        $i++;
224    }
225    echo
226    '</tbody></table></div>' .
227    '<p>' . form::hidden('filters_order', '') .
228    $core->formNonce() .
229    '<input type="submit" name="filters_upd" value="' . __('Save') . '" /></p>' .
230        '</form>';
231
232    # Syndication
233    if (DC_ADMIN_URL) {
234        $ham_feed = $core->blog->url . $core->url->getURLFor(
235            'hamfeed',
236            $code = dcAntispam::getUserCode($core)
237        );
238        $spam_feed = $core->blog->url . $core->url->getURLFor(
239            'spamfeed',
240            $code = dcAntispam::getUserCode($core)
241        );
242
243        echo
244        '<h3>' . __('Syndication') . '</h3>' .
245        '<ul class="spaminfo">' .
246        '<li class="feed"><a href="' . $spam_feed . '">' . __('Junk comments RSS feed') . '</a></li>' .
247        '<li class="feed"><a href="' . $ham_feed . '">' . __('Published comments RSS feed') . '</a></li>' .
248            '</ul>';
249    }
250
251    dcPage::helpBlock('antispam', 'antispam-filters');
252}
253
254?>
255
256</body>
257</html>
Note: See TracBrowser for help on using the repository browser.

Sites map