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