tiki-admin_toolbars.php 9.19 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2015 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8 9
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$
10

11 12 13 14 15 16 17 18
$inputConfiguration = array(
				array(
					'staticKeyFilters' => array(
							'save' => 'alpha',
							'load' => 'alpha',
							'pref' => 'striptags',
							'section' => 'striptags',
					),
19
				)
20
);
21

22
$auto_query_args = array('section', 'comments', 'autoreload', 'view_mode');
23 24

require_once 'tiki-setup.php';
25
require_once 'lib/toolbars/toolbarslib.php';
26 27

$access->check_permission('tiki_p_admin');
28
$access->check_feature(array('javascript_enabled', 'feature_jquery_ui'));
29

30 31
$sections = array( 'global' => tra('Global'), 'admin' => tra('Admin'));
$sections2 = array();
32

33
if ($prefs['feature_wiki'] == 'y')			$sections2['wiki page'] = tra('Wiki Pages');
34
if ($prefs['feature_trackers'] == 'y')		$sections2['trackers'] = tra('Trackers');
35
if ($prefs['feature_blogs'] == 'y')			$sections2['blogs'] = tra('Blogs');
36 37
if ($prefs['feature_calendar'] == 'y')		$sections2['calendar'] = tra('Calendars');
if ($prefs['feature_articles'] == 'y')		$sections2['cms'] = tra('Articles');
38 39 40 41 42 43
if ($prefs['feature_faqs'] == 'y')			$sections2['faqs'] = tra('FAQs');
if ($prefs['feature_newsletters'] == 'y') 	$sections2['newsletters'] = tra('Newsletters');
if ($prefs['feature_forums'] == 'y')		$sections2['forums'] = tra('Forums');
if ($prefs['feature_maps'] == 'y')			$sections2['maps'] = tra('Maps');
if ($prefs['feature_sheet'] == 'y')			$sections2['sheet'] = tra('Spreadsheets');
if ($prefs['wikiplugin_wysiwyg'] == 'y')	$sections2['wysiwyg_plugin'] = tra('WYSIWYG Plugin');
44 45 46 47 48

asort($sections2);
$sections = array_merge($sections, $sections2);


49
if ( isset($_REQUEST['section']) && in_array($_REQUEST['section'], array_keys($sections)) ) {
50
	$section = $_REQUEST['section'];
51
} else {
52 53
	$keys = array_keys($sections);
	$section = reset($keys);
54
}
55
if ( isset($_REQUEST['comments']) && $_REQUEST['comments'] == 'on') {
56 57 58
	$comments = true;
} else {
	$comments = false;
59
}
60

61
foreach ($sections as $skey => $sval) {
62 63
	if (isset($prefs['toolbar_' . $skey . ($comments ? '_comments' : '') . 'modified'])
		&& $prefs['toolbar_' . $skey . ($comments ? '_comments' : '') . 'modified'] == 'y') {
64 65 66 67
		$sections[$skey] = $sval . ' *';
	}
}

68 69 70 71 72 73
$view_mode = isset($_REQUEST['view_mode']) ? $_REQUEST['view_mode'] : '';
if ($view_mode === 'sheet' && $section !== 'sheet') {
	$view_mode = '';
	$_REQUEST['view_mode'] = '';
}
$smarty->assign('view_mode', $view_mode);
74

75 76 77 78 79 80
if (!empty($_REQUEST['reset_all_custom_tools'])) {
	$access->check_authenticity(tra('Are you sure you want to delete all your custom tools?'));
	Toolbar::deleteAllCustomTools();
	$access->redirect('tiki-admin_toolbars.php');
}

81
if ( isset($_REQUEST['save'], $_REQUEST['pref']) ) {
82
	$prefName = 'toolbar_' . $section . ($comments ? '_comments' : '');
83
	$tikilib->set_preference($prefName, $_REQUEST['pref']);
84
	$tikilib->set_preference($prefName . 'modified', 'y');
85
}
86

87
if ( (isset($_REQUEST['reset']) && $section != 'global') || (isset($_REQUEST['reset_global']) && $section == 'global') ) {
88
	$prefName = 'toolbar_' . $section . ($comments ? '_comments' : '');
89
	$tikilib->delete_preference($prefName);
90
	$tikilib->set_preference($prefName . 'modified', 'n');
91
	$smarty->loadPlugin('smarty_function_query');
92
	header('location: ?'. smarty_function_query(array('_urlencode'=>'n'), $smarty));
93 94
}

95
if ( !empty($_REQUEST['save_tool']) && !empty($_REQUEST['tool_name'])) {	// input from the tool edit form
96
	Toolbar::saveTool(
97 98 99 100 101 102 103
		$_REQUEST['tool_name'],
		$_REQUEST['tool_label'],
		$_REQUEST['tool_icon'],
		$_REQUEST['tool_token'],
		$_REQUEST['tool_syntax'],
		$_REQUEST['tool_type'],
		$_REQUEST['tool_plugin']
104 105
	);

106
	$smarty->loadPlugin('smarty_function_query');
107
	header('location: ?'. smarty_function_query(array('_urlencode'=>'n'), $smarty));
108 109
}

110
$current = $tikilib->get_preference('toolbar_' . $section . ($comments ? '_comments' : ''));
111
if (empty($current)) {
112
	$current = $tikilib->get_preference('toolbar_global' . ($comments ? '_comments' : ''));
113 114 115 116 117 118
	$smarty->assign('not_global', false);
} else {
	$smarty->assign('not_global', true);
}
$smarty->assign('not_default', false);
if ($section == 'global') {
lphuberdeau's avatar
lphuberdeau committed
119
	$cachelib = TikiLib::lib('cache');
120
	if ( $defprefs = $cachelib->getSerialized("tiki_default_preferences_cache") ) {
121 122
		if ($defprefs['toolbar_global' . ($comments ? '_comments' : '')] != $current) {
			$smarty->assign('not_default', true);
123 124
		}
	}
125
}
126 127 128 129 130 131 132

if ( !empty($_REQUEST['delete_tool']) && !empty($_REQUEST['tool_name'])) {	// input from the tool edit form
	Toolbar::deleteTool($_REQUEST['tool_name']);
	if (strpos($_REQUEST['tool_name'], $current) !== false) {
		$current = str_replace($_REQUEST['tool_name'], '', $current);
		$current = str_replace(',,', ',', $current);
		$prefName = 'toolbar_' . $section . ($comments ? '_comments' : '');
133
		$tikilib->set_preference($prefName, $current);
134 135 136
	}
}

137
if (!empty($current)) {
138 139 140
	$current = preg_replace('/\s+/', '', $current);
	$current = trim($current, '/');
	$current = explode('/', $current);
141
	$loadedRows = count($current);
142
	foreach ( $current as &$line ) {
143
		$bits = explode('|', $line);
144
		$line = array();
145
		foreach ($bits as $bit) {
146
			$line[] = explode(',', $bit);
147
		}
148 149
	}
	$rowCount = max($loadedRows, 1) + 1;
150
} else {
151
	$rowCount = 1;
152
}
153

154 155 156
$init = '';
$setup = '';
$map = array();
157

158
$qtlist = Toolbar::getList();
159
$usedqt = array();
160 161
$qt_p_list = array();
$qt_w_list = array();
162

163 164
foreach ( $current as &$line ) {
	foreach ($line as $bit) {
165
		$usedqt = array_merge($usedqt, $bit);
166
	}
167 168
}

169 170
$customqt = Toolbar::getCustomList();

171 172
$view_mode = !empty($_REQUEST['view_mode']) ? $_REQUEST['view_mode'] : '';

173
foreach ( $qtlist as $name ) {
174

175
	$tag = Toolbar::getTag($name);
176
	if ( ! $tag ) {
177 178 179 180 181
		$tag = Toolbar::getTag($name, true);
		if ( ! $tag ) {
			$tag = Toolbar::getTag($name, true, true);
			continue;
		}
182
	}
183

184 185
	$wys = strlen($tag->getWysiwygToken('dummy', false)) ? 'qt-wys' : '';
	$wyswik = strlen($tag->getWysiwygWikiToken('dummy', false)) ? 'qt-wyswik' : '';
186 187 188
	$test_html = $tag->getWikiHtml('');
	$wiki = strlen($test_html) > 0 ? 'qt-wiki' : '';
	$wiki = strpos($test_html, 'qt-sheet') !== false ? 'qt-sheet' : $wiki;
189
	$cust = Toolbar::isCustomTool($name) ? 'qt-custom' : '';
190
	$avail = $tag->isAccessible() ? '' : 'qt-noaccess';
191
	$icon = $tag->getIconHtml();
192

193 194 195
	if (strpos($name, 'wikiplugin_') !== false) {
		$plug =  'qt-plugin';
		$label = substr($name, 11);
196
		$qt_p_list[] = $name;
197 198 199
	} else {
		$plug =  '';
		$label = $name;
200 201 202
		if (empty($cust)) {
			$qt_w_list[] = $name;
		}
203
	}
204

205
	$label = htmlspecialchars($label);
206
	$label .= '<input type="hidden" name="token" value="' . $tag->getWysiwygToken('dummy', false) . '" />';
207
	$label .= '<input type="hidden" name="syntax" value="' . htmlspecialchars($tag->getSyntax('dummy')) . '" />';
208 209
	$label .= '<input type="hidden" name="type" value="' . $tag->getType() . '" />';

210
	if ($tag->getType() == 'Wikiplugin') {
211
		$label .= '<input type="hidden" name="plugin" value="' . $tag->getPluginName() . '" />';
212
	}
213

214 215 216 217 218 219 220 221 222 223 224 225 226
	$visible = 	true;
	if ($view_mode === 'both') {
		$visible = (!empty($wys) || !empty($wiki));
	} else if ($view_mode === 'wiki') {
		$visible = !empty($wiki);
	} else if ($view_mode === 'wysiwyg') {
		$visible = !empty($wys);
	} else if ($view_mode === 'wysiwyg_wiki') {
		$visible = !empty($wyswik);
	} else if ($view_mode === 'sheet') {
		$visible = (strpos($wiki, 'qt-sheet') !== false);
	}

227
	$qtelement[$name] = array(
228
					'name' => $name,
229
					'class' => "toolbar qt-$name $wys $wiki $wyswik $plug $cust $avail",
230 231
					'html' => "$icon<span>$label</span>",
					'visible' => $visible,
232
	);
233
}
234

235
$headerlib->add_js(
236 237 238
	"var toolbarsadmin_rowStr = '" . substr(implode(",#row-", range(0, $rowCount)), 2) . "';" .
	"var toolbarsadmin_fullStr = '#full-list-w,#full-list-p,#full-list-c';" .
	"var toolbarsadmin_delete_text = '" . tra('Are you sure you want to delete this custom tool?') . "'\n"
239
);
240

241
$headerlib->add_jsfile('lib/toolbars/tiki-admin_toolbars.js');
242

243 244
$display_w = array_diff($qt_w_list, $usedqt);

245 246 247
if (!in_array('-', $display_w)) {
	array_unshift($display_w, '-');
}
248 249 250

$display_p = array_diff($qt_p_list, $usedqt);
$display_c = array_diff($customqt, $usedqt);
251

252 253 254 255
sort($display_c);
sort($display_p);
sort($display_w);

256
$headerlib->add_cssfile('themes/base_files/feature_css/admin.css');
257

258 259 260 261 262
if (count($_REQUEST) == 0) {
	$smarty->assign('autoreload', 'on');
} else {
	$smarty->assign('autoreload', isset($_REQUEST['autoreload']) ? $_REQUEST['autoreload'] : '');
}
263 264

$plugins = array();
265 266

$parserlib = TikiLib::lib('parser');
267

268
foreach ($parserlib->plugin_get_list() as $name) {
269
	$info = $parserlib->plugin_info($name);
270 271
	if (isset($info['prefs']) && is_array($info['prefs']) && count($info['prefs']) > 0) $plugins[$name] = $info;
}
272

273 274
$smarty->assign('plugins', $plugins);

275
$smarty->assign('comments', $comments);
276
$smarty->assign('loaded', $section);
277
$smarty->assign('rows', range(0, $rowCount - 1));
278 279
$smarty->assign('rowCount', $rowCount);
$smarty->assign('sections', $sections);
280 281 282 283 284 285
$smarty->assign_by_ref('qtelement', $qtelement);
$smarty->assign_by_ref('display_w', $display_w);
$smarty->assign_by_ref('display_p', $display_p);
$smarty->assign_by_ref('display_c', $display_c);

$smarty->assign_by_ref('current', $current);
286
$smarty->assign('mid', 'tiki-admin_toolbars.tpl');
287
$smarty->display('tiki.tpl');