[BUGFIX] Usage of undefined variables in ShortcutToolbarItem
[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($row['url']) . '\'),\'' . $moduleName . '\',\'' . $moduleParts[0] . '\', ' . (int)$pageId . ');';
317
318 $shortcuts[] = $shortcut;
319 }
320 return $shortcuts;
321 }
322
323 /**
324 * Gets shortcuts for a specific group
325 *
326 * @param integer $groupId Group Id
327 * @return array Array of shortcuts that matched the group
328 */
329 protected function getShortcutsByGroup($groupId) {
330 $shortcuts = array();
331 foreach ($this->shortcuts as $shortcut) {
332 if ($shortcut['group'] == $groupId) {
333 $shortcuts[] = $shortcut;
334 }
335 }
336 return $shortcuts;
337 }
338
339 /**
340 * Gets a shortcut by its uid
341 *
342 * @param integer $shortcutId Shortcut id to get the complete shortcut for
343 * @return mixed An array containing the shortcut's data on success or FALSE on failure
344 */
345 protected function getShortcutById($shortcutId) {
346 $returnShortcut = FALSE;
347 foreach ($this->shortcuts as $shortcut) {
348 if ($shortcut['raw']['uid'] == (int)$shortcutId) {
349 $returnShortcut = $shortcut;
350 continue;
351 }
352 }
353 return $returnShortcut;
354 }
355
356 /**
357 * Gets the available shortcut groups from default groups, user TSConfig, and global groups
358 *
359 * @return array
360 */
361 protected function initShortcutGroups() {
362 // Groups from TSConfig
363 $bookmarkGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.bookmarkGroups');
364 if (is_array($bookmarkGroups) && count($bookmarkGroups)) {
365 foreach ($bookmarkGroups as $groupId => $label) {
366 if (!empty($label)) {
367 $this->shortcutGroups[$groupId] = (string)$label;
368 } elseif ($GLOBALS['BE_USER']->isAdmin()) {
369 unset($this->shortcutGroups[$groupId]);
370 }
371 }
372 }
373 // Generate global groups, all global groups have negative IDs.
374 if (count($this->shortcutGroups)) {
375 $groups = $this->shortcutGroups;
376 foreach ($groups as $groupId => $groupLabel) {
377 $this->shortcutGroups[$groupId * -1] = $groupLabel;
378 }
379 }
380 // Group -100 is kind of superglobal and can't be changed.
381 $this->shortcutGroups[self::SUPERGLOBAL_GROUP] = 1;
382 // Add labels
383 foreach ($this->shortcutGroups as $groupId => $groupLabel) {
384 $groupId = (int)$groupId;
385 $label = $groupLabel;
386 if ($groupLabel == '1') {
387 $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_group_' . abs($groupId), TRUE);
388 if (empty($label)) {
389 // Fallback label
390 $label = $GLOBALS['LANG']->getLL('bookmark_group', 1) . ' ' . abs($groupId);
391 }
392 }
393 if ($groupId < 0) {
394 // Global group
395 $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_global', TRUE) . ': ' . (!empty($label) ? $label : abs($groupId));
396 if ($groupId === self::SUPERGLOBAL_GROUP) {
397 $label = $GLOBALS['LANG']->getLL('bookmark_global', 1) . ': ' . $GLOBALS['LANG']->getLL('bookmark_all', 1);
398 }
399 }
400 $this->shortcutGroups[$groupId] = $label;
401 }
402 return $this->shortcutGroups;
403 }
404
405 /**
406 * gets the available shortcut groups
407 *
408 * @param array $params Array of parameters from the AJAX interface, currently unused
409 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
410 * @return void
411 */
412 public function getAjaxShortcutGroups($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
413 $shortcutGroups = $this->shortcutGroups;
414 if (!$GLOBALS['BE_USER']->isAdmin()) {
415 foreach ($shortcutGroups as $groupId => $groupName) {
416 if ((int)$groupId < 0) {
417 unset($shortcutGroups[$groupId]);
418 }
419 }
420 }
421 $ajaxObj->addContent('shortcutGroups', $shortcutGroups);
422 $ajaxObj->setContentFormat('json');
423 }
424
425 /**
426 * Deletes a shortcut through an AJAX call
427 *
428 * @param array $params Array of parameters from the AJAX interface, currently unused
429 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
430 * @return void
431 */
432 public function deleteAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
433 $shortcutId = (int)GeneralUtility::_POST('shortcutId');
434 $fullShortcut = $this->getShortcutById($shortcutId);
435 $ajaxReturn = 'failed';
436 if ($fullShortcut['raw']['userid'] == $GLOBALS['BE_USER']->user['uid']) {
437 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid = ' . $shortcutId);
438 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
439 $ajaxReturn = 'deleted';
440 }
441 }
442 $ajaxObj->addContent('delete', $ajaxReturn);
443 }
444
445 /**
446 * Creates a shortcut through an AJAX call
447 *
448 * @param array $params Array of parameters from the AJAX interface, currently unused
449 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Oject of type AjaxRequestHandler
450 * @return void
451 */
452 public function createAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
453 $shortcutCreated = 'failed';
454 // Default name
455 $shortcutName = 'Shortcut';
456 $shortcutNamePrepend = '';
457 $url = GeneralUtility::_POST('url');
458 $module = GeneralUtility::_POST('module');
459 $motherModule = GeneralUtility::_POST('motherModName');
460 // Determine shortcut type
461 $queryParts = parse_url($url);
462 $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
463 // Proceed only if no scheme is defined, as URL is expected to be relative
464 if (empty($queryParts['scheme'])) {
465 if (is_array($queryParameters['edit'])) {
466 $shortcut['table'] = key($queryParameters['edit']);
467 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
468 if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
469 $shortcut['type'] = 'edit';
470 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_edit', 1);
471 } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
472 $shortcut['type'] = 'new';
473 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_create', 1);
474 }
475 } else {
476 $shortcut['type'] = 'other';
477 }
478 // Lookup the title of this page and use it as default description
479 $pageId = $shortcut['recordid'] ? $shortcut['recordid'] : $this->getLinkedPageId($url);
480 if (MathUtility::canBeInterpretedAsInteger($pageId)) {
481 $page = BackendUtility::getRecord('pages', $pageId);
482 if (count($page)) {
483 // Set the name to the title of the page
484 if ($shortcut['type'] == 'other') {
485 $shortcutName = $page['title'];
486 } else {
487 $shortcutName = $shortcutNamePrepend . ' ' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']) . ' (' . $page['title'] . ')';
488 }
489 }
490 } else {
491 $dirName = urldecode($pageId);
492 if (preg_match('/\\/$/', $dirName)) {
493 // If $pageId is a string and ends with a slash,
494 // assume it is a fileadmin reference and set
495 // the description to the basename of that path
496 $shortcutName .= ' ' . basename($dirName);
497 }
498 }
499 // adding the shortcut
500 if ($module && $url) {
501 $fieldValues = array(
502 'userid' => $GLOBALS['BE_USER']->user['uid'],
503 'module_name' => $module . '|' . $motherModule,
504 'url' => $url,
505 'description' => $shortcutName,
506 'sorting' => $GLOBALS['EXEC_TIME']
507 );
508 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fieldValues);
509 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
510 $shortcutCreated = 'success';
511 }
512 }
513 $ajaxObj->addContent('create', $shortcutCreated);
514 }
515 }
516
517 /**
518 * Gets called when a shortcut is changed, checks whether the user has
519 * permissions to do so and saves the changes if everything is ok
520 *
521 * @param array $params Array of parameters from the AJAX interface, currently unused
522 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
523 * @return void
524 */
525 public function setAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
526 $shortcutId = (int)GeneralUtility::_POST('shortcutId');
527 $shortcutName = strip_tags(GeneralUtility::_POST('value'));
528 $shortcutGroupId = (int)GeneralUtility::_POST('shortcut-group');
529 if ($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) {
530 // Users can delete only their own shortcuts (except admins)
531 $addUserWhere = !$GLOBALS['BE_USER']->isAdmin() ? ' AND userid=' . (int)$GLOBALS['BE_USER']->user['uid'] : '';
532 $fieldValues = array(
533 'description' => $shortcutName,
534 'sc_group' => $shortcutGroupId
535 );
536 if ($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) {
537 $fieldValues['sc_group'] = 0;
538 }
539 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid=' . $shortcutId . $addUserWhere, $fieldValues);
540 $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
541 if ($affectedRows == 1) {
542 $ajaxObj->addContent('shortcut', $shortcutName);
543 } else {
544 $ajaxObj->addContent('shortcut', 'failed');
545 }
546 }
547 $ajaxObj->setContentFormat('plain');
548 }
549
550 /**
551 * Gets the label for a shortcut group
552 *
553 * @param integer $groupId A shortcut group id
554 * @return string The shortcut group label, can be an empty string if no group was found for the id
555 */
556 protected function getShortcutGroupLabel($groupId) {
557 return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
558 }
559
560 /**
561 * Gets a list of global groups, shortcuts in these groups are available to all users
562 *
563 * @return array Array of global groups
564 */
565 protected function getGlobalShortcutGroups() {
566 $globalGroups = array();
567 foreach ($this->shortcutGroups as $groupId => $groupLabel) {
568 if ($groupId < 0) {
569 $globalGroups[$groupId] = $groupLabel;
570 }
571 }
572 return $globalGroups;
573 }
574
575 /**
576 * runs through the available shortcuts an collects their groups
577 *
578 * @return array Array of groups which have shortcuts
579 */
580 protected function getGroupsFromShortcuts() {
581 $groups = array();
582 foreach ($this->shortcuts as $shortcut) {
583 $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
584 }
585 return array_unique($groups);
586 }
587
588 /**
589 * Gets the icon for the shortcut
590 *
591 * @param array $row
592 * @param array $shortcut
593 * @return string Shortcut icon as img tag
594 */
595 protected function getShortcutIcon($row, $shortcut) {
596 switch ($row['module_name']) {
597 case 'xMOD_alt_doc.php':
598 $table = $shortcut['table'];
599 $recordid = $shortcut['recordid'];
600 $icon = '';
601 if ($shortcut['type'] == 'edit') {
602 // Creating the list of fields to include in the SQL query:
603 $selectFields = $this->fieldArray;
604 $selectFields[] = 'uid';
605 $selectFields[] = 'pid';
606 if ($table == 'pages') {
607 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
608 $selectFields[] = 'module';
609 $selectFields[] = 'extendToSubpages';
610 }
611 $selectFields[] = 'doktype';
612 }
613 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
614 $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
615 }
616 if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
617 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
618 }
619 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
620 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
621 }
622 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
623 $selectFields[] = 't3ver_state';
624 }
625 // Unique list!
626 $selectFields = array_unique($selectFields);
627 $permissionClause = $table === 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
628 $sqlQueryParts = array(
629 'SELECT' => implode(',', $selectFields),
630 'FROM' => $table,
631 'WHERE' => 'uid IN (' . $recordid . ') ' . $permissionClause . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table)
632 );
633 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($sqlQueryParts);
634 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
635 $icon = IconUtility::getIcon($table, $row, $this->backPath);
636 } elseif ($shortcut['type'] == 'new') {
637 $icon = IconUtility::getIcon($table, '', $this->backPath);
638 }
639 $icon = IconUtility::skinImg($this->backPath, $icon, '', 1);
640 break;
641 case 'xMOD_file_edit.php':
642 $icon = 'gfx/edit_file.gif';
643 break;
644 case 'xMOD_wizard_rte.php':
645 $icon = 'gfx/edit_rtewiz.gif';
646 break;
647 default:
648 if ($GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab']) {
649 $icon = $GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab'];
650 // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
651 $icon = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $icon);
652 if (GeneralUtility::isAbsPath($icon)) {
653 $icon = '../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($icon);
654 }
655 } else {
656 $icon = 'gfx/dummy_module.gif';
657 }
658 }
659 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) . '" />';
660 }
661
662 /**
663 * Returns title for the shortcut icon
664 *
665 * @param string $shortcutLabel Shortcut label
666 * @param string $moduleName Backend module name (key)
667 * @param string $parentModuleName Parent module label
668 * @return string Title for the shortcut icon
669 */
670 protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '') {
671 $title = '';
672 if (substr($moduleName, 0, 5) == 'xMOD_') {
673 $title = substr($moduleName, 5);
674 } else {
675 $splitModuleName = explode('_', $moduleName);
676 $title = $GLOBALS['LANG']->moduleLabels['tabs'][$splitModuleName[0] . '_tab'];
677 if (count($splitModuleName) > 1) {
678 $title .= '>' . $GLOBALS['LANG']->moduleLabels['tabs'][($moduleName . '_tab')];
679 }
680 }
681 if ($parentModuleName) {
682 $title .= ' (' . $parentModuleName . ')';
683 }
684 $title .= ': ' . $shortcutLabel;
685 return $title;
686 }
687
688 /**
689 * Return the ID of the page in the URL if found.
690 *
691 * @param string $url The URL of the current shortcut link
692 * @return string If a page ID was found, it is returned. Otherwise: 0
693 */
694 protected function getLinkedPageId($url) {
695 return preg_replace('/.*[\\?&]id=([^&]+).*/', '$1', $url);
696 }
697
698 }