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