[TASK] Cleanup Ajax URL inline settings
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Toolbar / ShortcutToolbarItem.php
1 <?php
2 namespace TYPO3\CMS\Backend\Toolbar;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2007-2013 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33 use TYPO3\CMS\Core\Utility\MathUtility;
34
35 /**
36 * Class to render the shortcut menu
37 *
38 * @author Ingo Renner <ingo@typo3.org>
39 */
40 class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
41
42 const SUPERGLOBAL_GROUP = -100;
43
44 /**
45 * @var string
46 * @todo define visibility
47 */
48 public $perms_clause;
49
50 /**
51 * @var string
52 * @todo define visibility
53 */
54 public $backPath;
55
56 /**
57 * @var array
58 * @todo define visibility
59 */
60 public $fieldArray;
61
62 /**
63 * All available shortcuts
64 *
65 * @var array
66 */
67 protected $shortcuts;
68
69 /**
70 * @var array
71 */
72 protected $shortcutGroups;
73
74 /**
75 * Labels of all groups.
76 * If value is 1, the system will try to find a label in the locallang array.
77 *
78 * @var array
79 */
80 protected $groupLabels;
81
82 /**
83 * Reference back to the backend object
84 *
85 * @var \TYPO3\CMS\Backend\Controller\BackendController
86 */
87 protected $backendReference;
88
89 /**
90 * Constructor
91 *
92 * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference TYPO3 backend object reference
93 */
94 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
95 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
96 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
97 // Needed to get the correct icons when reloading the menu after saving it
98 $loadModules = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
99 $loadModules->load($GLOBALS['TBE_MODULES']);
100 }
101 $this->backendReference = $backendReference;
102 $this->shortcuts = array();
103 // By default, 5 groups are set
104 $this->shortcutGroups = array(
105 1 => '1',
106 2 => '1',
107 3 => '1',
108 4 => '1',
109 5 => '1'
110 );
111 $this->shortcutGroups = $this->initShortcutGroups();
112 $this->shortcuts = $this->initShortcuts();
113 }
114
115 /**
116 * Checks whether the user has access to this toolbar item
117 *
118 * @return boolean TRUE if user has access, FALSE if not
119 */
120 public function checkAccess() {
121 return (bool) $GLOBALS['BE_USER']->getTSConfigVal('options.enableBookmarks');
122 }
123
124 /**
125 * Creates the shortcut menu (default renderer)
126 *
127 * @return string Workspace selector as HTML select
128 */
129 public function render() {
130 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarks', TRUE);
131 $this->addJavascriptToBackend();
132 $shortcutMenu = array();
133 $shortcutMenu[] = '<a href="#" class="toolbar-item">' . IconUtility::getSpriteIcon('apps-toolbar-menu-shortcut', array('title' => $title)) . '</a>';
134 $shortcutMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
135 $shortcutMenu[] = $this->renderMenu();
136 $shortcutMenu[] = '</div>';
137 return implode(LF, $shortcutMenu);
138 }
139
140 /**
141 * Renders the pure contents of the menu
142 *
143 * @return string The menu's content
144 */
145 public function renderMenu() {
146 $shortcutGroup = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarksGroup', TRUE);
147 $shortcutEdit = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarksEdit', TRUE);
148 $shortcutDelete = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarksDelete', TRUE);
149 $groupIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/i/sysf.gif', 'width="18" height="16"') . ' title="' . $shortcutGroup . '" alt="' . $shortcutGroup . '" />';
150 $editIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="' . $shortcutEdit . '" alt="' . $shortcutEdit . '"';
151 $deleteIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="' . $shortcutDelete . '" alt="' . $shortcutDelete . '" />';
152 $shortcutMenu[] = '<table border="0" cellspacing="0" cellpadding="0" class="shortcut-list">';
153 // Render shortcuts with no group (group id = 0) first
154 $noGroupShortcuts = $this->getShortcutsByGroup(0);
155 foreach ($noGroupShortcuts as $shortcut) {
156 $shortcutMenu[] = '
157 <tr id="shortcut-' . $shortcut['raw']['uid'] . '" class="shortcut">
158 <td class="shortcut-icon">' . $shortcut['icon'] . '</td>
159 <td class="shortcut-label">
160 <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
161 </td>
162 <td class="shortcut-edit">' . $editIcon . ' id="shortcut-edit-' . $shortcut['raw']['uid'] . '" /></td>
163 <td class="shortcut-delete">' . $deleteIcon . '</td>
164 </tr>';
165 }
166 // Now render groups and the contained shortcuts
167 $groups = $this->getGroupsFromShortcuts();
168 krsort($groups, SORT_NUMERIC);
169 foreach ($groups as $groupId => $groupLabel) {
170 if ($groupId != 0) {
171 $shortcutGroup = '
172 <tr class="shortcut-group" id="shortcut-group-' . $groupId . '">
173 <td class="shortcut-group-icon">' . $groupIcon . '</td>
174 <td class="shortcut-group-label">' . $groupLabel . '</td>
175 <td colspan="2">&nbsp;</td>
176 </tr>';
177 $shortcuts = $this->getShortcutsByGroup($groupId);
178 $i = 0;
179 foreach ($shortcuts as $shortcut) {
180 $i++;
181 $firstRow = '';
182 if ($i == 1) {
183 $firstRow = ' first-row';
184 }
185 $shortcutGroup .= '
186 <tr id="shortcut-' . $shortcut['raw']['uid'] . '" class="shortcut' . $firstRow . '">
187 <td class="shortcut-icon">' . $shortcut['icon'] . '</td>
188 <td class="shortcut-label">
189 <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
190 </td>
191 <td class="shortcut-edit">' . $editIcon . ' id="shortcut-edit-' . $shortcut['raw']['uid'] . '" /></td>
192 <td class="shortcut-delete">' . $deleteIcon . '</td>
193 </tr>';
194 }
195 $shortcutMenu[] = $shortcutGroup;
196 }
197 }
198 if (count($shortcutMenu) == 1) {
199 // No shortcuts added yet, show a small help message how to add shortcuts
200 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarks', TRUE);
201 $icon = IconUtility::getSpriteIcon('actions-system-shortcut-new', array(
202 'title' => $title
203 ));
204 $label = str_replace('%icon%', $icon, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmarkDescription'));
205 $shortcutMenu[] = '<tr><td style="padding:1px 2px; color: #838383;">' . $label . '</td></tr>';
206 }
207 $shortcutMenu[] = '</table>';
208 $compiledShortcutMenu = implode(LF, $shortcutMenu);
209 return $compiledShortcutMenu;
210 }
211
212 /**
213 * Renders the menu so that it can be returned as response to an AJAX call
214 *
215 * @param array $params Array of parameters from the AJAX interface, currently unused
216 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
217 * @return void
218 */
219 public function renderAjax($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
220 $menuContent = $this->renderMenu();
221 $ajaxObj->addContent('shortcutMenu', $menuContent);
222 }
223
224 /**
225 * Adds the necessary JavaScript to the backend
226 *
227 * @return void
228 */
229 protected function addJavascriptToBackend() {
230 $this->backendReference->addJavascriptFile('sysext/backend/Resources/Public/JavaScript/shortcutmenu.js');
231 }
232
233 /**
234 * Returns additional attributes for the list item in the toolbar
235 *
236 * @return string List item HTML attibutes
237 */
238 public function getAdditionalAttributes() {
239 return 'id="shortcut-menu"';
240 }
241
242 /**
243 * Retrieves the shortcuts for the current user
244 *
245 * @return array Array of shortcuts
246 */
247 protected function initShortcuts() {
248 $globalGroupIdList = implode(',', array_keys($this->getGlobalShortcutGroups()));
249 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
250 '*',
251 'sys_be_shortcuts',
252 '(userid = ' . (int)$GLOBALS['BE_USER']->user['uid'] . ' AND sc_group>=0) OR sc_group IN (' . $globalGroupIdList . ')',
253 '',
254 'sc_group,sorting'
255 );
256 // Traverse shortcuts
257 $lastGroup = 0;
258 $shortcuts = array();
259 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
260 $shortcut = array('raw' => $row);
261
262 list($row['module_name'], $row['M_module_name']) = explode('|', $row['module_name']);
263
264 $queryParts = parse_url($row['url']);
265 $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
266 if ($row['module_name'] === 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
267 $shortcut['table'] = key($queryParameters['edit']);
268 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
269 if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
270 $shortcut['type'] = 'edit';
271 } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
272 $shortcut['type'] = 'new';
273 }
274 if (substr($shortcut['recordid'], -1) === ',') {
275 $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
276 }
277 } else {
278 $shortcut['type'] = 'other';
279 }
280 // Check for module access
281 $moduleName = $row['M_module_name'] ?: $row['module_name'];
282 $pageId = $this->getLinkedPageId($row['url']);
283 if (!$GLOBALS['BE_USER']->isAdmin()) {
284 if (!isset($GLOBALS['LANG']->moduleLabels['tabs_images'][$moduleName . '_tab'])) {
285 // Nice hack to check if the user has access to this module
286 // - otherwise the translation label would not have been loaded :-)
287 continue;
288 }
289 if (MathUtility::canBeInterpretedAsInteger($pageId)) {
290 // Check for webmount access
291 if (!$GLOBALS['BE_USER']->isInWebMount($pageId)) {
292 continue;
293 }
294 // Check for record access
295 $pageRow = BackendUtility::getRecord('pages', $pageId);
296 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow, ($perms = 1))) {
297 continue;
298 }
299 }
300 }
301 $moduleParts = explode('_', $moduleName);
302 $shortcutGroup = (int)$row['sc_group'];
303 if ($shortcutGroup && $lastGroup !== $shortcutGroup && $shortcutGroup !== self::SUPERGLOBAL_GROUP) {
304 $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
305 }
306 $lastGroup = $shortcutGroup;
307
308 if ($row['description']) {
309 $shortcut['label'] = $row['description'];
310 } else {
311 $shortcut['label'] = GeneralUtility::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
312 }
313 $shortcut['group'] = $shortcutGroup;
314 $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
315 $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcut['label'], $row['module_name'], $row['M_module_name']);
316 $shortcut['action'] = 'jump(unescape(\'' . rawurlencode($this->getTokenUrl($row['url'])) . '\'),\'' . $moduleName . '\',\'' . $moduleParts[0] . '\', ' . (int)$pageId . ');';
317
318 $shortcuts[] = $shortcut;
319 }
320 return $shortcuts;
321 }
322
323 /**
324 * Adds the correct token, if the url is a mod.php script
325 *
326 * @param string $url
327 * @return string
328 */
329 protected function getTokenUrl($url) {
330 $parsedUrl = parse_url($url);
331 parse_str($parsedUrl['query'], $parameters);
332 if (strpos($parsedUrl['path'], 'mod.php') !== FALSE && isset($parameters['M'])) {
333 $module = $parameters['M'];
334 unset($parameters['M']);
335 $url = str_replace('mod.php', '', $parsedUrl['path']) . BackendUtility::getModuleUrl($module, $parameters);
336 }
337 return $url;
338 }
339
340 /**
341 * Gets shortcuts for a specific group
342 *
343 * @param integer $groupId Group Id
344 * @return array Array of shortcuts that matched the group
345 */
346 protected function getShortcutsByGroup($groupId) {
347 $shortcuts = array();
348 foreach ($this->shortcuts as $shortcut) {
349 if ($shortcut['group'] == $groupId) {
350 $shortcuts[] = $shortcut;
351 }
352 }
353 return $shortcuts;
354 }
355
356 /**
357 * Gets a shortcut by its uid
358 *
359 * @param integer $shortcutId Shortcut id to get the complete shortcut for
360 * @return mixed An array containing the shortcut's data on success or FALSE on failure
361 */
362 protected function getShortcutById($shortcutId) {
363 $returnShortcut = FALSE;
364 foreach ($this->shortcuts as $shortcut) {
365 if ($shortcut['raw']['uid'] == (int)$shortcutId) {
366 $returnShortcut = $shortcut;
367 continue;
368 }
369 }
370 return $returnShortcut;
371 }
372
373 /**
374 * Gets the available shortcut groups from default groups, user TSConfig, and global groups
375 *
376 * @return array
377 */
378 protected function initShortcutGroups() {
379 // Groups from TSConfig
380 $bookmarkGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.bookmarkGroups');
381 if (is_array($bookmarkGroups) && count($bookmarkGroups)) {
382 foreach ($bookmarkGroups as $groupId => $label) {
383 if (!empty($label)) {
384 $this->shortcutGroups[$groupId] = (string)$label;
385 } elseif ($GLOBALS['BE_USER']->isAdmin()) {
386 unset($this->shortcutGroups[$groupId]);
387 }
388 }
389 }
390 // Generate global groups, all global groups have negative IDs.
391 if (count($this->shortcutGroups)) {
392 $groups = $this->shortcutGroups;
393 foreach ($groups as $groupId => $groupLabel) {
394 $this->shortcutGroups[$groupId * -1] = $groupLabel;
395 }
396 }
397 // Group -100 is kind of superglobal and can't be changed.
398 $this->shortcutGroups[self::SUPERGLOBAL_GROUP] = 1;
399 // Add labels
400 foreach ($this->shortcutGroups as $groupId => $groupLabel) {
401 $groupId = (int)$groupId;
402 $label = $groupLabel;
403 if ($groupLabel == '1') {
404 $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_group_' . abs($groupId), TRUE);
405 if (empty($label)) {
406 // Fallback label
407 $label = $GLOBALS['LANG']->getLL('bookmark_group', 1) . ' ' . abs($groupId);
408 }
409 }
410 if ($groupId < 0) {
411 // Global group
412 $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_global', TRUE) . ': ' . (!empty($label) ? $label : abs($groupId));
413 if ($groupId === self::SUPERGLOBAL_GROUP) {
414 $label = $GLOBALS['LANG']->getLL('bookmark_global', 1) . ': ' . $GLOBALS['LANG']->getLL('bookmark_all', 1);
415 }
416 }
417 $this->shortcutGroups[$groupId] = $label;
418 }
419 return $this->shortcutGroups;
420 }
421
422 /**
423 * gets the available shortcut groups
424 *
425 * @param array $params Array of parameters from the AJAX interface, currently unused
426 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
427 * @return void
428 */
429 public function getAjaxShortcutGroups($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
430 $shortcutGroups = $this->shortcutGroups;
431 if (!$GLOBALS['BE_USER']->isAdmin()) {
432 foreach ($shortcutGroups as $groupId => $groupName) {
433 if ((int)$groupId < 0) {
434 unset($shortcutGroups[$groupId]);
435 }
436 }
437 }
438 $ajaxObj->addContent('shortcutGroups', $shortcutGroups);
439 $ajaxObj->setContentFormat('json');
440 }
441
442 /**
443 * Deletes a shortcut through an AJAX call
444 *
445 * @param array $params Array of parameters from the AJAX interface, currently unused
446 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
447 * @return void
448 */
449 public function deleteAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
450 $shortcutId = (int)GeneralUtility::_POST('shortcutId');
451 $fullShortcut = $this->getShortcutById($shortcutId);
452 $ajaxReturn = 'failed';
453 if ($fullShortcut['raw']['userid'] == $GLOBALS['BE_USER']->user['uid']) {
454 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid = ' . $shortcutId);
455 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
456 $ajaxReturn = 'deleted';
457 }
458 }
459 $ajaxObj->addContent('delete', $ajaxReturn);
460 }
461
462 /**
463 * Creates a shortcut through an AJAX call
464 *
465 * @param array $params Array of parameters from the AJAX interface, currently unused
466 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Oject of type AjaxRequestHandler
467 * @return void
468 */
469 public function createAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
470 $shortcutCreated = 'failed';
471 // Default name
472 $shortcutName = 'Shortcut';
473 $shortcutNamePrepend = '';
474 $url = GeneralUtility::_POST('url');
475 $module = GeneralUtility::_POST('module');
476 $motherModule = GeneralUtility::_POST('motherModName');
477 // Determine shortcut type
478 $queryParts = parse_url($url);
479 $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
480 // Proceed only if no scheme is defined, as URL is expected to be relative
481 if (empty($queryParts['scheme'])) {
482 if (is_array($queryParameters['edit'])) {
483 $shortcut['table'] = key($queryParameters['edit']);
484 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
485 if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
486 $shortcut['type'] = 'edit';
487 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_edit', 1);
488 } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
489 $shortcut['type'] = 'new';
490 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_create', 1);
491 }
492 } else {
493 $shortcut['type'] = 'other';
494 }
495 // Lookup the title of this page and use it as default description
496 $pageId = $shortcut['recordid'] ? $shortcut['recordid'] : $this->getLinkedPageId($url);
497 if (MathUtility::canBeInterpretedAsInteger($pageId)) {
498 $page = BackendUtility::getRecord('pages', $pageId);
499 if (count($page)) {
500 // Set the name to the title of the page
501 if ($shortcut['type'] == 'other') {
502 $shortcutName = $page['title'];
503 } else {
504 $shortcutName = $shortcutNamePrepend . ' ' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']) . ' (' . $page['title'] . ')';
505 }
506 }
507 } else {
508 $dirName = urldecode($pageId);
509 if (preg_match('/\\/$/', $dirName)) {
510 // If $pageId is a string and ends with a slash,
511 // assume it is a fileadmin reference and set
512 // the description to the basename of that path
513 $shortcutName .= ' ' . basename($dirName);
514 }
515 }
516 // adding the shortcut
517 if ($module && $url) {
518 $fieldValues = array(
519 'userid' => $GLOBALS['BE_USER']->user['uid'],
520 'module_name' => $module . '|' . $motherModule,
521 'url' => $url,
522 'description' => $shortcutName,
523 'sorting' => $GLOBALS['EXEC_TIME']
524 );
525 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fieldValues);
526 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
527 $shortcutCreated = 'success';
528 }
529 }
530 $ajaxObj->addContent('create', $shortcutCreated);
531 }
532 }
533
534 /**
535 * Gets called when a shortcut is changed, checks whether the user has
536 * permissions to do so and saves the changes if everything is ok
537 *
538 * @param array $params Array of parameters from the AJAX interface, currently unused
539 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
540 * @return void
541 */
542 public function setAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
543 $shortcutId = (int)GeneralUtility::_POST('shortcutId');
544 $shortcutName = strip_tags(GeneralUtility::_POST('value'));
545 $shortcutGroupId = (int)GeneralUtility::_POST('shortcut-group');
546 if ($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) {
547 // Users can delete only their own shortcuts (except admins)
548 $addUserWhere = !$GLOBALS['BE_USER']->isAdmin() ? ' AND userid=' . (int)$GLOBALS['BE_USER']->user['uid'] : '';
549 $fieldValues = array(
550 'description' => $shortcutName,
551 'sc_group' => $shortcutGroupId
552 );
553 if ($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) {
554 $fieldValues['sc_group'] = 0;
555 }
556 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid=' . $shortcutId . $addUserWhere, $fieldValues);
557 $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
558 if ($affectedRows == 1) {
559 $ajaxObj->addContent('shortcut', $shortcutName);
560 } else {
561 $ajaxObj->addContent('shortcut', 'failed');
562 }
563 }
564 $ajaxObj->setContentFormat('plain');
565 }
566
567 /**
568 * Gets the label for a shortcut group
569 *
570 * @param integer $groupId A shortcut group id
571 * @return string The shortcut group label, can be an empty string if no group was found for the id
572 */
573 protected function getShortcutGroupLabel($groupId) {
574 return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
575 }
576
577 /**
578 * Gets a list of global groups, shortcuts in these groups are available to all users
579 *
580 * @return array Array of global groups
581 */
582 protected function getGlobalShortcutGroups() {
583 $globalGroups = array();
584 foreach ($this->shortcutGroups as $groupId => $groupLabel) {
585 if ($groupId < 0) {
586 $globalGroups[$groupId] = $groupLabel;
587 }
588 }
589 return $globalGroups;
590 }
591
592 /**
593 * runs through the available shortcuts an collects their groups
594 *
595 * @return array Array of groups which have shortcuts
596 */
597 protected function getGroupsFromShortcuts() {
598 $groups = array();
599 foreach ($this->shortcuts as $shortcut) {
600 $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
601 }
602 return array_unique($groups);
603 }
604
605 /**
606 * Gets the icon for the shortcut
607 *
608 * @param array $row
609 * @param array $shortcut
610 * @return string Shortcut icon as img tag
611 */
612 protected function getShortcutIcon($row, $shortcut) {
613 switch ($row['module_name']) {
614 case 'xMOD_alt_doc.php':
615 $table = $shortcut['table'];
616 $recordid = $shortcut['recordid'];
617 $icon = '';
618 if ($shortcut['type'] == 'edit') {
619 // Creating the list of fields to include in the SQL query:
620 $selectFields = $this->fieldArray;
621 $selectFields[] = 'uid';
622 $selectFields[] = 'pid';
623 if ($table == 'pages') {
624 $selectFields[] = 'module';
625 $selectFields[] = 'extendToSubpages';
626 $selectFields[] = 'doktype';
627 }
628 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
629 $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
630 }
631 if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
632 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
633 }
634 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
635 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
636 }
637 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
638 $selectFields[] = 't3ver_state';
639 }
640 // Unique list!
641 $selectFields = array_unique($selectFields);
642 $permissionClause = $table === 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
643 $sqlQueryParts = array(
644 'SELECT' => implode(',', $selectFields),
645 'FROM' => $table,
646 'WHERE' => 'uid IN (' . $recordid . ') ' . $permissionClause . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table)
647 );
648 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($sqlQueryParts);
649 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
650 $icon = IconUtility::getIcon($table, $row, $this->backPath);
651 } elseif ($shortcut['type'] == 'new') {
652 $icon = IconUtility::getIcon($table, '', $this->backPath);
653 }
654 $icon = IconUtility::skinImg($this->backPath, $icon, '', 1);
655 break;
656 case 'xMOD_file_edit.php':
657 $icon = 'gfx/edit_file.gif';
658 break;
659 case 'wizard_rte':
660 $icon = 'gfx/edit_rtewiz.gif';
661 break;
662 default:
663 if ($GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab']) {
664 $icon = $GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab'];
665 // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
666 $icon = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $icon);
667 if (GeneralUtility::isAbsPath($icon)) {
668 $icon = '../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($icon);
669 }
670 } else {
671 $icon = 'gfx/dummy_module.gif';
672 }
673 }
674 return '<img src="' . $icon . '" alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.shortcut', TRUE) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.shortcut', TRUE) . '" />';
675 }
676
677 /**
678 * Returns title for the shortcut icon
679 *
680 * @param string $shortcutLabel Shortcut label
681 * @param string $moduleName Backend module name (key)
682 * @param string $parentModuleName Parent module label
683 * @return string Title for the shortcut icon
684 */
685 protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '') {
686 $title = '';
687 if (substr($moduleName, 0, 5) == 'xMOD_') {
688 $title = substr($moduleName, 5);
689 } else {
690 $splitModuleName = explode('_', $moduleName);
691 $title = $GLOBALS['LANG']->moduleLabels['tabs'][$splitModuleName[0] . '_tab'];
692 if (count($splitModuleName) > 1) {
693 $title .= '>' . $GLOBALS['LANG']->moduleLabels['tabs'][($moduleName . '_tab')];
694 }
695 }
696 if ($parentModuleName) {
697 $title .= ' (' . $parentModuleName . ')';
698 }
699 $title .= ': ' . $shortcutLabel;
700 return $title;
701 }
702
703 /**
704 * Return the ID of the page in the URL if found.
705 *
706 * @param string $url The URL of the current shortcut link
707 * @return string If a page ID was found, it is returned. Otherwise: 0
708 */
709 protected function getLinkedPageId($url) {
710 return preg_replace('/.*[\\?&]id=([^&]+).*/', '$1', $url);
711 }
712
713 }