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