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