File: index.php

package info (click to toggle)
dotclear 2.6.4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 8,420 kB
  • sloc: php: 54,270; sql: 1,290; sh: 213; xml: 173; makefile: 158
file content (263 lines) | stat: -rw-r--r-- 7,156 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of Antispam, a plugin for Dotclear 2.
#
# Copyright (c) 2003-2013 Olivier Meunier & Association Dotclear
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK -----------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
dcPage::check('admin');

dcAntispam::initFilters();
$filters = dcAntispam::$filters->getFilters();

$page_name = __('Antispam');
$filter_gui = false;
$default_tab = null;

try
{
	# Show filter configuration GUI
	if (!empty($_GET['f']))
	{
		if (!isset($filters[$_GET['f']])) {
			throw new Exception(__('Filter does not exist.'));
		}

		if (!$filters[$_GET['f']]->hasGUI()) {
			throw new Exception(__('Filter has no user interface.'));
		}

		$filter = $filters[$_GET['f']];
		$filter_gui = $filter->gui($filter->guiURL());
	}

	# Remove all spam
	if (!empty($_POST['delete_all']))
	{
		$ts = dt::str('%Y-%m-%d %H:%M:%S',$_POST['ts'],$core->blog->settings->system->blog_timezone);

		dcAntispam::delAllSpam($core,$ts);

		dcPage::addSuccessNotice(__('Spam comments have been successfully deleted.'));
		http::redirect($p_url);
	}

	# Update filters
	if (isset($_POST['filters_upd']))
	{
		$filters_opt = array();
		$i = 0;
		foreach ($filters as $fid => $f) {
			$filters_opt[$fid] = array(false,$i);
			$i++;
		}

		# Enable active filters
		if (isset($_POST['filters_active']) && is_array($_POST['filters_active'])) {
			foreach ($_POST['filters_active'] as $v) {
				$filters_opt[$v][0] = true;
			}
		}

		# Order filters
		if (!empty($_POST['f_order']) && empty($_POST['filters_order']))
		{
			$order = $_POST['f_order'];
			asort($order);
			$order = array_keys($order);
		}
		elseif (!empty($_POST['filters_order']))
		{
			$order = explode(',',trim($_POST['filters_order'],','));
		}

		if (isset($order)) {
			foreach ($order as $i => $f) {
				$filters_opt[$f][1] = $i;
			}
		}

		# Set auto delete flag
		if (isset($_POST['filters_auto_del']) && is_array($_POST['filters_auto_del'])) {
			foreach ($_POST['filters_auto_del'] as $v) {
				$filters_opt[$v][2] = true;
			}
		}

		dcAntispam::$filters->saveFilterOpts($filters_opt);

		dcPage::addSuccessNotice(__('Filters configuration has been successfully saved.'));
		http::redirect($p_url);
	}
}
catch (Exception $e)
{
	$core->error->add($e->getMessage());
}
?>
<html>
<head>
  <title><?php echo ($filter_gui !== false ? sprintf(__('%s configuration'),$filter->name).' - ' : '').$page_name; ?></title>
  <script type="text/javascript">
  //<![CDATA[
  <?php
  echo dcPage::jsVar('dotclear.msg.confirm_spam_delete',__('Are you sure you want to delete all spams?'));
  ?>
  //]]>
  </script>
  <?php
  echo dcPage::jsPageTabs($default_tab);
  $core->auth->user_prefs->addWorkspace('accessibility');
  if (!$core->auth->user_prefs->accessibility->nodragdrop) {
	echo
		dcPage::jsLoad('js/jquery/jquery-ui.custom.js').
		dcPage::jsLoad('index.php?pf=antispam/antispam.js');
  }
  ?>
  <link rel="stylesheet" type="text/css" href="index.php?pf=antispam/style.css" />
</head>
<body>
<?php

if ($filter_gui !== false)
{
	echo dcPage::breadcrumb(
		array(
			__('Plugins') => '',
			$page_name => $p_url,
			sprintf(__('%s filter configuration'),$filter->name) => ''
		)).
		dcPage::notices();

	echo '<p><a href="plugin.php?p=antispam" class="back">'.__('Back to filters list').'</a></p>';

	echo $filter_gui;

	if ($filter->help) {
		dcPage::helpBlock($filter->help);
	}
}
else
{
	echo dcPage::breadcrumb(
		array(
			__('Plugins') => '',
			$page_name => ''
		)).
		dcPage::notices();

	# Information
	$spam_count = dcAntispam::countSpam($core);
	$published_count = dcAntispam::countPublishedComments($core);
	$moderationTTL = $core->blog->settings->antispam->antispam_moderation_ttl;

	echo
	'<form action="'.$p_url.'" method="post" class="fieldset">'.
	'<h3>'.__('Information').'</h3>';

	echo
	'<ul class="spaminfo">'.
	'<li class="spamcount"><a href="comments.php?status=-2">'.__('Junk comments:').'</a> '.
	'<strong>'.$spam_count.'</strong></li>'.
	'<li class="hamcount"><a href="comments.php?status=1">'.__('Published comments:').'</a> '.
	$published_count.'</li>'.
	'</ul>';

	if ($spam_count > 0)
	{
		echo
		'<p>'.$core->formNonce().
		form::hidden('ts',time()).
		'<input name="delete_all" class="delete" type="submit" value="'.__('Delete all spams').'" /></p>';
	}
	if ($moderationTTL != null && $moderationTTL >=0) {
		echo '<p>'.sprintf(__('All spam comments older than %s day(s) will be automatically deleted.'), $moderationTTL).' '.
		sprintf(__('You can modify this duration in the %s'),'<a href="blog_pref.php#antispam_moderation_ttl"> '.__('Blog settings').'</a>').
			'.</p>';
	}
	echo '</form>';


	# Filters
	echo
	'<form action="'.$p_url.'" method="post" id="filters-list-form">';

	if (!empty($_GET['upd'])) {
		dcPage::success(__('Filters configuration has been successfully saved.'));
	}

	echo
	'<div class="table-outer">'.
	'<table class="dragable">'.
	'<caption class="as_h3">'.__('Available spam filters').'</caption>'.
	'<thead><tr>'.
	'<th>'.__('Order').'</th>'.
	'<th>'.__('Active').'</th>'.
	'<th>'.__('Auto Del.').'</th>'.
	'<th class="nowrap">'.__('Filter name').'</th>'.
	'<th colspan="2">'.__('Description').'</th>'.
	'</tr></thead>'.
	'<tbody id="filters-list" >';

	$i = 0;
	foreach ($filters as $fid => $f)
	{
		$gui_link = '&nbsp;';
		if ($f->hasGUI()) {
			$gui_link =
			'<a href="'.html::escapeHTML($f->guiURL()).'">'.
			'<img src="images/edit-mini.png" alt="'.__('Filter configuration').'" '.
			'title="'.__('Filter configuration').'" /></a>';
		}

		echo
		'<tr class="line'.($f->active ? '' : ' offline').'" id="f_'.$fid.'">'.
		'<td class="handle">'.form::field(array('f_order['.$fid.']'),2,5,(string) $i, 'position', '', false, 'title="'.__('position').'"').'</td>'.
		'<td class="nowrap">'.form::checkbox(array('filters_active[]'),$fid,$f->active, '', '', false, 'title="'.__('Active').'"').'</td>'.
		'<td class="nowrap">'.form::checkbox(array('filters_auto_del[]'),$fid,$f->auto_delete, '', '', false, 'title="'.__('Auto Del.').'"').'</td>'.
		'<td class="nowrap" scope="row">'.$f->name.'</td>'.
		'<td class="maximal">'.$f->description.'</td>'.
		'<td class="status">'.$gui_link.'</td>'.
		'</tr>';
		$i++;
	}
	echo
	'</tbody></table></div>'.
	'<p>'.form::hidden('filters_order','').
	$core->formNonce().
	'<input type="submit" name="filters_upd" value="'.__('Save').'" /></p>'.
	'</form>';


	# Syndication
	if (DC_ADMIN_URL)
	{
		$ham_feed = $core->blog->url.$core->url->getURLFor(
			'hamfeed',
			$code = dcAntispam::getUserCode($core)
		);
		$spam_feed = $core->blog->url.$core->url->getURLFor(
			'spamfeed',
			$code = dcAntispam::getUserCode($core)
		);

		echo
		'<h3>'.__('Syndication').'</h3>'.
		'<ul class="spaminfo">'.
		'<li class="feed"><a href="'.$spam_feed.'">'.__('Junk comments RSS feed').'</a></li>'.
		'<li class="feed"><a href="'.$ham_feed.'">'.__('Published comments RSS feed').'</a></li>'.
		'</ul>';
	}

	dcPage::helpBlock('antispam','antispam-filters');
}

?>

</body>
</html>