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 (345 lines) | stat: -rw-r--r-- 8,826 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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
<?php
# -- BEGIN LICENSE BLOCK ---------------------------------------
#
# This file is part of 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; }

// Set env

$core->blog->settings->addNamespace('maintenance');

$maintenance = new dcMaintenance($core);
$tasks = $maintenance->getTasks();

$headers = '';
$p_url = 'plugin.php?p=maintenance';
$task = null;
$expired = array();

$code = empty($_POST['code']) ? null : (integer) $_POST['code'];
$tab = empty($_REQUEST['tab']) ? '' : $_REQUEST['tab'];

// Get task object

if (!empty($_REQUEST['task'])) {
	$task = $maintenance->getTask($_REQUEST['task']);

	if ($task === null) {
		$core->error->add('Unknow task ID');
	}

	$task->code($code);
}

// Execute task

if ($task && !empty($_POST['task']) && $task->id() == $_POST['task']) {
	try {
		$code = $task->execute();
		if (false === $code) {
			throw new Exception($task->error());
		}
		if (true === $code) {
			$maintenance->setLog($task->id());

			dcPage::addSuccessNotice($task->success());
			http::redirect($p_url.'&task='.$task->id().'&tab='.$tab.'#'.$tab);
		}
	}
	catch (Exception $e) {
		$core->error->add($e->getMessage());
	}
}

// Save settings

if (!empty($_POST['save_settings'])) {

	try {
		$core->blog->settings->maintenance->put(
			'plugin_message',
			!empty($_POST['settings_plugin_message']),
			'boolean',
			'Display alert message of late tasks on plugin page',
			true,
			true
		);

		foreach($tasks as $t) {
			if (!$t->id()) {
				continue;
			}

			if (!empty($_POST['settings_recall_type']) && $_POST['settings_recall_type'] == 'all') {
				$ts = $_POST['settings_recall_time'];
			}
			else {
				$ts = empty($_POST['settings_ts_'.$t->id()]) ? 0 : $_POST['settings_ts_'.$t->id()];
			}
			$core->blog->settings->maintenance->put(
				'ts_'.$t->id(),
				abs((integer) $ts),
				'integer',
				sprintf('Recall time for task %s', $t->id()),
				true,
				$t->blog()
			);
		}

		dcPage::addSuccessNotice(__('Maintenance plugin has been successfully configured.'));
		http::redirect($p_url.'&tab='.$tab.'#'.$tab);
	}
	catch(Exception $e) {
		$core->error->add($e->getMessage());
	}
}

// Combos

$combo_ts = array(
	__('Never') 			=> 0,
	__('Every week') 		=> 604800,
	__('Every two weeks') 	=> 1209600,
	__('Every month') 		=> 2592000,
	__('Every two months') 	=> 5184000
);

// Display page

echo '<html><head>
<title>'.__('Maintenance').'</title>'.
dcPage::jsPageTabs($tab).
dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');

if ($task && $task->ajax()) {
	echo
	'<script type="text/javascript">'."\n".
	"//<![CDATA[\n".
	dcPage::jsVar('dotclear.msg.wait', __('Please wait...')).
	"//]]>\n".
	'</script>'.
	dcPage::jsLoad('index.php?pf=maintenance/js/dc.maintenance.js');
}

echo
$maintenance->getHeaders().'
</head>
<body>';

// Check if there is somthing to display according to user permissions
if (empty($tasks)) {
	echo dcPage::breadcrumb(
		array(
			__('Plugins') => '',
			__('Maintenance') => ''
		)
	).
	'<p class="warn">'.__('You have not sufficient permissions to view this page.').'</p>'.
	'</body></html>';

	return null;
}

if ($task && ($res = $task->step()) !== null) {

	// Page title

	echo dcPage::breadcrumb(
		array(
			__('Plugins') => '',
			'<a href="'.$p_url.'">'.__('Maintenance').'</a>' => '',
			html::escapeHTML($task->name())=> ''
		)
	);

	// content
	if (substr($res, 0, 1) != '<') {
		$res = sprintf('<p class="step-msg">%s</p>', $res);
	}

	// Intermediate task (task required several steps)

	echo
	'<div class="step-box" id="'.$task->id().'">'.
	'<p class="step-back">'.
		'<a class="back" href="'.$p_url.'&amp;tab='.$task->tab().'#'.$task->tab().'">'.__('Back').'</a>'.
	'</p>'.
	'<h3>'.html::escapeHTML($task->name()).'</h3>'.
	'<form action="'.$p_url.'" method="post">'.
	$res.
	'<p class="step-submit">'.
		'<input type="submit" value="'.$task->task().'" /> '.
		form::hidden(array('task'), $task->id()).
		form::hidden(array('code'), (integer) $code).
		$core->formNonce().
	'</p>'.
	'</form>'.
	'</div>';
}
else {

	// Page title

	echo dcPage::breadcrumb(
		array(
			__('Plugins') => '',
			__('Maintenance') => ''
		)
	);

	// Simple task (with only a button to start it)

	foreach($maintenance->getTabs() as $tab_obj)
	{
		$res_group = '';
		foreach($maintenance->getGroups() as $group_obj)
		{
			$res_task = '';
			foreach($tasks as $t)
			{
				if (!$t->id()
				 || $t->group() != $group_obj->id()
				 || $t->tab() != $tab_obj->id()) {
					continue;
				}

				$res_task .=
				'<p>'.form::radio(array('task', $t->id()), $t->id()).' '.
				'<label class="classic" for="'.$t->id().'">'.
				html::escapeHTML($t->task()).'</label>';

				// Expired task alert message
				$ts = $t->expired();
				if ($core->blog->settings->maintenance->plugin_message && $ts !== false) {
					if ($ts === null) {
						$res_task .=
						'<br /> <span class="warn">'.
						__('This task has never been executed.').' '.
						__('You should execute it now.').'</span>';
					}
					else {
						$res_task .=
						'<br /> <span class="warn">'.sprintf(
							__('Last execution of this task was on %s.'),
							dt::str($core->blog->settings->system->date_format, $ts).' '.
							dt::str($core->blog->settings->system->time_format, $ts)
						).' '.
						__('You should execute it now.').'</span>';
					}
				}

				$res_task .= '</p>';
			}

			if (!empty($res_task)) {
				$res_group .=
				'<div class="fieldset">'.
				'<h4 id="'.$group_obj->id().'">'.$group_obj->name().'</h4>'.
				$res_task.
				'</div>';
			}
		}

		if (!empty($res_group)) {
			echo
			'<div id="'.$tab_obj->id().'" class="multi-part" title="'.$tab_obj->name().'">'.
			'<h3>'.$tab_obj->name().'</h3>'.
			// ($tab_obj->option('summary') ? '<p>'.$tab_obj->option('summary').'</p>' : '').
			'<form action="'.$p_url.'" method="post">'.
			$res_group.
			'<p><input type="submit" value="'.__('Execute task').'" /> '.
			form::hidden(array('tab'), $tab_obj->id()).
			$core->formNonce().'</p>'.
			'<p class="form-note info">'.__('This may take a very long time.').'</p>'.
			'</form>'.
			'</div>';
		}
	}

	// Advanced tasks (that required a tab)

	foreach($tasks as $t)
	{
		if (!$t->id() || $t->group() !== null) {
			continue;
		}

		echo
		'<div id="'.$t->id().'" class="multi-part" title="'.$t->name().'">'.
		'<h3>'.$t->name().'</h3>'.
		'<form action="'.$p_url.'" method="post">'.
		$t->content().
		'<p><input type="submit" value="'.__('Execute task').'" /> '.
		form::hidden(array('task'), $t->id()).
		form::hidden(array('tab'), $t->id()).
		$core->formNonce().'</p>'.
		'</form>'.
		'</div>';
	}

	// Settings

	echo
	'<div id="settings" class="multi-part" title="'.__('Alert settings').'">'.
	'<h3>'.__('Alert settings').'</h3>'.
	'<form action="'.$p_url.'" method="post">'.

	'<h4 class="pretty-title">'.__('Activation').'</h4>'.
	'<p><label for="settings_plugin_message" class="classic">'.
	form::checkbox('settings_plugin_message', 1, $core->blog->settings->maintenance->plugin_message).
	__('Display alert messages on late tasks').'</label></p>'.

	'<p class="info">'.sprintf(
		__('You can place list of late tasks on your %s.'),
		'<a href="preferences.php#user-favorites">'.__('Dashboard').'</a>'
	).'</p>'.

	'<h4 class="pretty-title vertical-separator">'.__('Frequency').'</h4>'.

	'<p class="vertical-separator">'.form::radio(array('settings_recall_type', 'settings_recall_all'), 'all').' '.
	'<label class="classic" for="settings_recall_all">'.
	'<strong>'.__('Use one recall time for all tasks').'</strong></label></p>'.

	'<p class="field wide vertical-separator"><label for="settings_recall_time">'.__('Recall time for all tasks:').'</label>'.
	form::combo('settings_recall_time', $combo_ts, 'seperate', 'recall-for-all').
	'</p>'.

	'<p class="vertical-separator">'.form::radio(array('settings_recall_type', 'settings_recall_separate'), 'separate', 1).' '.
	'<label class="classic" for="settings_recall_separate">'.
	'<strong>'.__('Use one recall time per task').'</strong></label></p>';

	foreach($tasks as $t)
	{
		if (!$t->id()) {
			continue;
		}
		echo
		'<div class="two-boxes">'.

		'<p class="field wide"><label for="settings_ts_'.$t->id().'">'.$t->task().'</label>'.
		form::combo('settings_ts_'.$t->id(), $combo_ts, $t->ts(), 'recall-per-task').
		'</p>'.

		'</div>';
	}

	echo
	'<p class="field wide"><input type="submit" value="'.__('Save').'" /> '.
	form::hidden(array('tab'), 'settings').
	form::hidden(array('save_settings'), 1).
	$core->formNonce().'</p>'.
	'</form>'.
	'</div>';
}

dcPage::helpBlock('maintenance', 'maintenancetasks');

echo
'</body></html>';