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