File: _admin.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 (315 lines) | stat: -rw-r--r-- 9,414 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
<?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; }

// Sidebar menu
$_menu['Plugins']->addItem(
	__('Maintenance'),
	'plugin.php?p=maintenance',
	'index.php?pf=maintenance/icon.png',
	preg_match('/plugin.php\?p=maintenance(&.*)?$/', $_SERVER['REQUEST_URI']),
	$core->auth->check('admin', $core->blog->id)
);

// Admin behaviors
$core->addBehavior('dcMaintenanceInit', array('dcMaintenanceAdmin', 'dcMaintenanceInit'));
$core->addBehavior('adminDashboardFavorites', array('dcMaintenanceAdmin', 'adminDashboardFavorites'));
$core->addBehavior('adminDashboardContents', array('dcMaintenanceAdmin', 'adminDashboardItems'));
$core->addBehavior('adminDashboardOptionsForm',	array('dcMaintenanceAdmin',	'adminDashboardOptionsForm'));
$core->addBehavior('adminAfterDashboardOptionsUpdate',	array('dcMaintenanceAdmin',	'adminAfterDashboardOptionsUpdate'));
$core->addBehavior('adminPageHelpBlock',	array('dcMaintenanceAdmin',	'adminPageHelpBlock'));
$core->addBehavior('pluginsToolsHeaders',	array('dcMaintenanceAdmin',	'pluginsToolsHeaders'));

/**
@ingroup PLUGIN_MAINTENANCE
@nosubgrouping
@brief Maintenance plugin admin class.

Group of methods used on behaviors.
*/
class dcMaintenanceAdmin
{
	/**
	 * Register default tasks.
	 *
	 * @param	$maintenance	<b>dcMaintenance</b>	dcMaintenance instance
	 */
	 public static function dcMaintenanceInit($maintenance)
	{
		$maintenance
		->addTab('maintenance', __('Servicing'), array('summary' => __('Tools to maintain the performance of your blogs.')))
		->addTab('backup', __('Backup'), array('summary' => __('Tools to back up your content.')))
		->addTab('dev', __('Development'), array('summary' => __('Tools to assist in development of plugins, themes and core.')))

		->addGroup('optimize', __('Optimize'))
		->addGroup('index', __('Count and index'))
		->addGroup('purge', __('Purge'))
		->addGroup('other', __('Other'))
		->addGroup('zipblog', __('Current blog'))
		->addGroup('zipfull', __('All blogs'))

		->addGroup('l10n', __('Translations'), array('summary' => __('Maintain translations')))

		->addTask('dcMaintenanceCache')
		->addTask('dcMaintenanceIndexposts')
		->addTask('dcMaintenanceIndexcomments')
		->addTask('dcMaintenanceCountcomments')
		->addTask('dcMaintenanceSynchpostsmeta')
		->addTask('dcMaintenanceLogs')
		->addTask('dcMaintenanceVacuum')
		->addTask('dcMaintenanceZipmedia')
		->addTask('dcMaintenanceZiptheme')
		;
	}

	/**
	 * Favorites.
	 *
	 * @param	$core	<b>dcCore</b>	dcCore instance
	 * @param	$favs	<b>arrayObject</b>	Array of favs
	 */
	public static function adminDashboardFavorites($core, $favs)
	{
		$favs->register('maintenance', array(
			'title' => __('Maintenance'),
			'url' => 'plugin.php?p=maintenance',
			'small-icon' => 'index.php?pf=maintenance/icon.png',
			'large-icon' => 'index.php?pf=maintenance/icon-big.png',
			'permissions' => 'admin',
			'active_cb' => array('dcMaintenanceAdmin', 'adminDashboardFavoritesActive'),
			'dashboard_cb' => array('dcMaintenanceAdmin', 'adminDashboardFavoritesCallback')
		));
	}

	/**
	 * Favorites selection.
	 *
	 * @param	$request	<b>string</b>	Requested page
	 * @param	$params		<b>array</b>	Requested parameters
	 */
	public static function adminDashboardFavoritesActive($request, $params)
	{
		return $request == 'plugin.php' && isset($params['p']) && $params['p'] == 'maintenance';
	}

	/**
	 * Favorites hack.
	 *
	 * This updates maintenance fav icon text
	 * if there are tasks required maintenance.
	 *
	 * @param	$core	<b>dcCore</b>	dcCore instance
	 * @param	$fav	<b>arrayObject</b>	fav attributes
	 */
	public static function adminDashboardFavoritesCallback($core, $fav)
	{
		// Check user option
		$core->auth->user_prefs->addWorkspace('maintenance');
		if (!$core->auth->user_prefs->maintenance->dashboard_icon) {
			return null;
		}

		// Check expired tasks
		$maintenance = new dcMaintenance($core);
		$count = 0;
		foreach($maintenance->getTasks() as $t)
		{
			if ($t->expired() !== false){
				$count++;
			}
		}

		if (!$count) {
			return null;
		}

		$fav['title'] .= '<br />'.sprintf(__('One task to execute', '%s tasks to execute', $count), $count);
		$fav['large-icon'] = 'index.php?pf=maintenance/icon-big-update.png';
	}

	/**
	 * Dashboard items stack.
	 *
	 * @param	$core	<b>dcCore</b>	dcCore instance
	 * @param	$items	<b>arrayObject</b>	Dashboard items
	 */
	public static function adminDashboardItems($core, $items)
	{
		$core->auth->user_prefs->addWorkspace('maintenance');
		if (!$core->auth->user_prefs->maintenance->dashboard_item) {
			return null;
		}

		$maintenance = new dcMaintenance($core);

		$lines = array();
		foreach($maintenance->getTasks() as $t)
		{
			$ts = $t->expired();
			if ($ts === false){
				continue;
			}

			$lines[] =
			'<li title="'.($ts === null ?
				__('This task has never been executed.')
				:
				sprintf(__('Last execution of this task was on %s.'),
					dt::dt2str($core->blog->settings->system->date_format, $ts).' '.
					dt::dt2str($core->blog->settings->system->time_format, $ts)
				)
			).'">'.$t->task().'</li>';
		}

		if (empty($lines)) {
			return null;
		}

		$items[] = new ArrayObject(array(
			'<div id="maintenance-expired" class="box small">'.
			'<h3><img src="index.php?pf=maintenance/icon-small.png" alt="" /> '.__('Maintenance').'</h3>'.
			'<p class="warning no-margin">'.sprintf(__('There is a task to execute.', 'There are %s tasks to execute.', count($lines)), count($lines)).'</p>'.
			'<ul>'.implode('',$lines).'</ul>'.
			'<p><a href="plugin.php?p=maintenance">'.__('Manage tasks').'</a></p>'.
			'</div>'
			));
	}

	/**
	 * User preferences form.
	 *
	 * This add options for superadmin user
	 * to show or not expired taks.
	 *
	 * @param	$args	<b>object</b>	dcCore instance or record
	 */
	public static function adminDashboardOptionsForm($core)
	{
		$core->auth->user_prefs->addWorkspace('maintenance');

		echo
		'<div class="fieldset">'.
		'<h4>'.__('Maintenance').'</h4>'.

		'<p><label for="maintenance_dashboard_icon" class="classic">'.
		form::checkbox('maintenance_dashboard_icon', 1, $core->auth->user_prefs->maintenance->dashboard_icon).
		__('Display overdue tasks counter on maintenance dashboard icon').'</label></p>'.

		'<p><label for="maintenance_dashboard_item" class="classic">'.
		form::checkbox('maintenance_dashboard_item', 1, $core->auth->user_prefs->maintenance->dashboard_item).
		__('Display overdue tasks list on dashboard items').'</label></p>'.

		'</div>';
	}

	/**
	 * User preferences update.
	 *
	 * @param	$user_id	<b>string</b>	User ID
	 */
	public static function adminAfterDashboardOptionsUpdate($user_id=null)
	{
		global $core;

		if (is_null($user_id)) {
			return null;
		}

		$core->auth->user_prefs->addWorkspace('maintenance');
		$core->auth->user_prefs->maintenance->put('dashboard_icon', !empty($_POST['maintenance_dashboard_icon']), 'boolean');
		$core->auth->user_prefs->maintenance->put('dashboard_item', !empty($_POST['maintenance_dashboard_item']), 'boolean');
	}

	/**
	 * Build a well sorted help for tasks.
	 *
	 * This method is not so good if used with lot of tranlsations
	 * as it grows memory usage and translations files size,
	 * it is better to use help ressource files
	 * but keep it for exemple of how to use behavior adminPageHelpBlock.
	 * Cheers, JC
	 *
	 * @param	$block	<b>arrayObject</b>	Called helpblocks
	 */
	public static function adminPageHelpBlock($blocks)
	{
		$found = false;
		foreach($blocks as $block) {
			if ($block == 'maintenancetasks') {
				$found = true;
				break;
			}
		}
		if (!$found) {
			return null;
		}

		$maintenance = new dcMaintenance($GLOBALS['core']);

		$res_tab = '';
		foreach($maintenance->getTabs() as $tab_obj)
		{
			$res_group = '';
			foreach($maintenance->getGroups() as $group_obj)
			{
				$res_task = '';
				foreach($maintenance->getTasks() as $t)
				{
					if ($t->group() != $group_obj->id()
					 || $t->tab() != $tab_obj->id()) {
						continue;
					}
					if (($desc = $t->description()) != '') {
						$res_task .=
						'<dt>'.$t->task().'</dt>'.
						'<dd>'.$desc.'</dd>';
					}
				}
				if (!empty($res_task)) {
					$desc = $group_obj->description ? $group_obj->description : $group_obj->summary;

					$res_group .=
					'<h5>'.$group_obj->name().'</h5>'.
					($desc ? '<p>'.$desc.'</p>' : '').
					'<dl>'.$res_task.'</dl>';
				}
			}
			if (!empty($res_group)) {
				$desc = $tab_obj->description ? $tab_obj->description : $tab_obj->summary;

				$res_tab .=
				'<h4>'.$tab_obj->name().'</h4>'.
				($desc ? '<p>'.$desc.'</p>' : '').
				$res_group;
			}
		}
		if (!empty($res_tab)) {
			$res = new ArrayObject();
			$res->content = $res_tab;
			$blocks[] = $res;
		}
	}

	/**
	 * Add javascript for plugin configuration.
	 *
	 * @param	$core	<b>dcCore</b>	dcCore instance
	 * @param	$module	<b>mixed</b>	Module ID or false if none
	 * @return	<b>string</b>	Header code for js inclusion
	 */
	public static function pluginsToolsHeaders($core, $module)
	{
		if ($module == 'maintenance') {
			return dcPage::jsLoad('index.php?pf=maintenance/js/settings.js');
		}
	}
}