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