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