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