a023307865e4cbecdb6f152917ec9797e41dbdd3
[Packages/TYPO3.CMS.git] / typo3 / classes / class.shortcutmenu.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2007-2011 Ingo Renner <ingo@typo3.org>
6 * All rights reserved
7 *
8 * This script is part of the TYPO3 project. The TYPO3 project is
9 * free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * The GNU General Public License can be found at
15 * http://www.gnu.org/copyleft/gpl.html.
16 * A copy is found in the textfile GPL.txt and important notices to the license
17 * from the author is found in LICENSE.txt distributed with these scripts.
18 *
19 *
20 * This script is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * This copyright notice MUST APPEAR in all copies of the script!
26 ***************************************************************/
27
28 if(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
29 require_once(PATH_typo3 . 'interfaces/interface.backend_toolbaritem.php');
30 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
31
32 // needed to get the correct icons when reloading the menu after saving it
33 $loadModules = t3lib_div::makeInstance('t3lib_loadModules');
34 $loadModules->load($GLOBALS['TBE_MODULES']);
35 }
36
37
38 /**
39 * class to render the shortcut menu
40 *
41 * @author Ingo Renner <ingo@typo3.org>
42 * @package TYPO3
43 * @subpackage core
44 */
45 class ShortcutMenu implements backend_toolbarItem {
46
47 protected $shortcutGroups;
48
49 /**
50 * all available shortcuts
51 *
52 * @var array
53 */
54 protected $shortcuts;
55
56 /**
57 * labels of all groups.
58 * If value is 1, the system will try to find a label in the locallang array.
59 *
60 * @var array
61 */
62 protected $groupLabels;
63
64 /**
65 * reference back to the backend object
66 *
67 * @var TYPO3backend
68 */
69 protected $backendReference;
70
71 /**
72 * constructor
73 *
74 * @param TYPO3backend TYPO3 backend object reference
75 * @return void
76 */
77 public function __construct(TYPO3backend &$backendReference = NULL) {
78 $this->backendReference = $backendReference;
79 $this->shortcuts = array();
80
81 // by default, 5 groups are set
82 $this->shortcutGroups = array(
83 1 => '1',
84 2 => '1',
85 3 => '1',
86 4 => '1',
87 5 => '1',
88 );
89
90 $this->shortcutGroups = $this->initShortcutGroups();
91 $this->shortcuts = $this->initShortcuts();
92 }
93
94 /**
95 * checks whether the user has access to this toolbar item
96 *
97 * @return boolean TRUE if user has access, FALSE if not
98 */
99 public function checkAccess() {
100 return (bool) $GLOBALS['BE_USER']->getTSConfigVal('options.enableBookmarks');
101 }
102
103 /**
104 * Creates the shortcut menu (default renderer)
105 *
106 * @return string workspace selector as HTML select
107 */
108 public function render() {
109 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarks', TRUE);
110 $this->addJavascriptToBackend();
111
112 $shortcutMenu = array();
113
114 $shortcutMenu[] = '<a href="#" class="toolbar-item">' .
115 t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-shortcut', array('title' => $title)) .
116 '</a>';
117 $shortcutMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
118 $shortcutMenu[] = $this->renderMenu();
119 $shortcutMenu[] = '</div>';
120
121 return implode(LF, $shortcutMenu);
122 }
123
124 /**
125 * renders the pure contents of the menu
126 *
127 * @return string the menu's content
128 */
129 public function renderMenu() {
130
131 $shortcutGroup = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarksGroup', TRUE);
132 $shortcutEdit = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarksEdit', TRUE);
133 $shortcutDelete = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarksDelete', TRUE);
134
135 $groupIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/i/sysf.gif', 'width="18" height="16"').' title="'.$shortcutGroup.'" alt="'.$shortcutGroup.'" />';
136 $editIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/edit2.gif', 'width="11" height="12"').' title="'.$shortcutEdit.'" alt="'.$shortcutEdit.'"';
137 $deleteIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/garbage.gif', 'width="11" height="12"').' title="'.$shortcutDelete.'" alt="'.$shortcutDelete.'" />';
138
139 $shortcutMenu[] = '<table border="0" cellspacing="0" cellpadding="0" class="shortcut-list">';
140
141 // render shortcuts with no group (group id = 0) first
142 $noGroupShortcuts = $this->getShortcutsByGroup(0);
143 foreach($noGroupShortcuts as $shortcut) {
144 $shortcutMenu[] = '
145 <tr id="shortcut-'.$shortcut['raw']['uid'].'" class="shortcut">
146 <td class="shortcut-icon">'.$shortcut['icon'].'</td>
147 <td class="shortcut-label">
148 <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
149 </td>
150 <td class="shortcut-edit">'.$editIcon.' id="shortcut-edit-'.$shortcut['raw']['uid'].'" /></td>
151 <td class="shortcut-delete">'.$deleteIcon.'</td>
152 </tr>';
153 }
154
155 // now render groups and the contained shortcuts
156 $groups = $this->getGroupsFromShortcuts();
157 krsort($groups, SORT_NUMERIC);
158 foreach($groups as $groupId => $groupLabel) {
159 if($groupId != 0 ) {
160 $shortcutGroup = '
161 <tr class="shortcut-group" id="shortcut-group-'.$groupId.'">
162 <td class="shortcut-group-icon">'.$groupIcon.'</td>
163 <td class="shortcut-group-label">'.$groupLabel.'</td>
164 <td colspan="2">&nbsp;</td>
165 </tr>';
166
167 $shortcuts = $this->getShortcutsByGroup($groupId);
168 $i = 0;
169 foreach($shortcuts as $shortcut) {
170 $i++;
171
172 $firstRow = '';
173 if($i == 1) {
174 $firstRow = ' first-row';
175 }
176
177 $shortcutGroup .= '
178 <tr id="shortcut-'.$shortcut['raw']['uid'].'" class="shortcut'.$firstRow.'">
179 <td class="shortcut-icon">'.$shortcut['icon'].'</td>
180 <td class="shortcut-label">
181 <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
182 </td>
183 <td class="shortcut-edit">'.$editIcon.' id="shortcut-edit-'.$shortcut['raw']['uid'].'" /></td>
184 <td class="shortcut-delete">'.$deleteIcon.'</td>
185 </tr>';
186 }
187
188 $shortcutMenu[] = $shortcutGroup;
189 }
190 }
191
192 if(count($shortcutMenu) == 1) {
193 //no shortcuts added yet, show a small help message how to add shortcuts
194 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarks', TRUE);
195 $icon = t3lib_iconWorks::getSpriteIcon('actions-system-shortcut-new', array(
196 'title' => $title
197 ));
198 $label = str_replace('%icon%', $icon, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:bookmarkDescription'));
199
200 $shortcutMenu[] = '<tr><td style="padding:1px 2px; color: #838383;">'.$label.'</td></tr>';
201 }
202
203 $shortcutMenu[] = '</table>';
204
205 $compiledShortcutMenu = implode(LF, $shortcutMenu);
206
207 return $compiledShortcutMenu;
208 }
209
210 /**
211 * renders the menu so that it can be returned as response to an AJAX call
212 *
213 * @param array array of parameters from the AJAX interface, currently unused
214 * @param TYPO3AJAX object of type TYPO3AJAX
215 * @return void
216 */
217 public function renderAjax($params = array(), TYPO3AJAX &$ajaxObj = NULL) {
218 $menuContent = $this->renderMenu();
219
220 $ajaxObj->addContent('shortcutMenu', $menuContent);
221 }
222
223 /**
224 * adds the necessary JavaScript to the backend
225 *
226 * @return void
227 */
228 protected function addJavascriptToBackend() {
229 $this->backendReference->addJavascriptFile('js/shortcutmenu.js');
230 }
231
232 /**
233 * returns additional attributes for the list item in the toolbar
234 *
235 * @return string list item HTML attibutes
236 */
237 public function getAdditionalAttributes() {
238 return ' id="shortcut-menu"';
239 }
240
241 /**
242 * retrieves the shortcuts for the current user
243 *
244 * @return array array of shortcuts
245 */
246 protected function initShortcuts() {
247 $shortcuts = array();
248 $globalGroups = $this->getGlobalShortcutGroups();
249
250 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
251 '*',
252 'sys_be_shortcuts',
253 '((userid = '.$GLOBALS['BE_USER']->user['uid'].' AND sc_group>=0) OR sc_group IN ('.implode(',', array_keys($globalGroups)).'))',
254 '',
255 'sc_group,sorting'
256 );
257
258 // Traverse shortcuts
259 while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
260 $shortcut = array('raw' => $row);
261 $moduleParts = explode('|', $row['module_name']);
262 $row['module_name'] = $moduleParts[0];
263 $row['M_module_name'] = $moduleParts[1];
264 $moduleParts = explode('_', $row['M_module_name'] ?
265 $row['M_module_name'] :
266 $row['module_name']
267 );
268 $queryParts = parse_url($row['url']);
269 $queryParameters = t3lib_div::explodeUrl2Array($queryParts['query'], 1);
270
271 if($row['module_name'] == 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
272 $shortcut['table'] = key($queryParameters['edit']);
273 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
274
275 if($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
276 $shortcut['type'] = 'edit';
277 } elseif($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
278 $shortcut['type'] = 'new';
279 }
280
281 if(substr($shortcut['recordid'], -1) == ',') {
282 $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
283 }
284 } else {
285 $shortcut['type'] = 'other';
286 }
287
288 // check for module access
289 if(!$GLOBALS['BE_USER']->isAdmin()) {
290 if(!isset($GLOBALS['LANG']->moduleLabels['tabs_images'][implode('_', $moduleParts).'_tab'])) {
291 // nice hack to check if the user has access to this module
292 // - otherwise the translation label would not have been loaded :-)
293 continue;
294 }
295
296 $pageId = $this->getLinkedPageId($row['url']);
297 if(t3lib_utility_Math::canBeInterpretedAsInteger($pageId)) {
298 // check for webmount access
299 if(!$GLOBALS['BE_USER']->isInWebMount($pageId)) {
300 continue;
301 }
302
303 // check for record access
304 $pageRow = t3lib_BEfunc::getRecord('pages', $pageId);
305 if(!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow, $perms = 1)) {
306 continue;
307 }
308 }
309 }
310
311 $shortcutGroup = $row['sc_group'];
312 if($shortcutGroup && strcmp($lastGroup, $shortcutGroup) && ($shortcutGroup != -100)) {
313 $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
314 }
315
316 if($row['description']) {
317 $shortcut['label'] = $row['description'];
318 } else {
319 $shortcut['label'] = t3lib_div::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
320 }
321
322 $shortcut['group'] = $shortcutGroup;
323 $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
324 $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcutLabel, $row['module_name'], $row['M_module_name']);
325 $shortcut['action'] = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$moduleParts).'\',\''.$moduleParts[0].'\');';
326
327 $lastGroup = $row['sc_group'];
328 $shortcuts[] = $shortcut;
329 }
330
331 return $shortcuts;
332 }
333
334 /**
335 * gets shortcuts for a specific group
336 *
337 * @param integer group Id
338 * @return array array of shortcuts that matched the group
339 */
340 protected function getShortcutsByGroup($groupId) {
341 $shortcuts = array();
342
343 foreach($this->shortcuts as $shortcut) {
344 if($shortcut['group'] == $groupId) {
345 $shortcuts[] = $shortcut;
346 }
347 }
348
349 return $shortcuts;
350 }
351
352 /**
353 * gets a shortcut by its uid
354 *
355 * @param integer shortcut id to get the complete shortcut for
356 * @return mixed an array containing the shortcut's data on success or FALSE on failure
357 */
358 protected function getShortcutById($shortcutId) {
359 $returnShortcut = FALSE;
360
361 foreach($this->shortcuts as $shortcut) {
362 if($shortcut['raw']['uid'] == (int) $shortcutId) {
363 $returnShortcut = $shortcut;
364 continue;
365 }
366 }
367
368 return $returnShortcut;
369 }
370
371 /**
372 * gets the available shortcut groups from default gropups, user TSConfig,
373 * and global groups
374 *
375 * @param array array of parameters from the AJAX interface, currently unused
376 * @param TYPO3AJAX object of type TYPO3AJAX
377 * @return array
378 */
379 protected function initShortcutGroups($params = array(), TYPO3AJAX &$ajaxObj = NULL) {
380 // groups from TSConfig
381 $bookmarkGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.bookmarkGroups');
382
383 if(is_array($bookmarkGroups) && count($bookmarkGroups)) {
384 foreach($bookmarkGroups as $groupId => $label) {
385 if(strcmp('', $label) && strcmp('0', $label)) {
386 $this->shortcutGroups[$groupId] = (string) $label;
387 } elseif($GLOBALS['BE_USER']->isAdmin()) {
388 unset($this->shortcutGroups[$groupId]);
389 }
390 }
391 }
392
393 // generate global groups, all global groups have negative IDs.
394 if(count($this->shortcutGroups)) {
395 $groups = $this->shortcutGroups;
396 foreach($groups as $groupId => $groupLabel) {
397 $this->shortcutGroups[($groupId * -1)] = $groupLabel;
398 }
399 }
400
401 // group -100 is kind of superglobal and can't be changed.
402 $this->shortcutGroups[-100] = 1;
403
404 // add labels
405 foreach($this->shortcutGroups as $groupId => $groupLabel) {
406 $label = $groupLabel;
407
408 if($groupLabel == '1') {
409 $label = $GLOBALS['LANG']->getLL('bookmark_group_'.abs($groupId), 1);
410
411 if(empty($label)) {
412 // fallback label
413 $label = $GLOBALS['LANG']->getLL('bookmark_group', 1).' '.abs($groupId);
414 }
415 }
416
417 if($groupId < 0) {
418 // global group
419 $label = $GLOBALS['LANG']->getLL('bookmark_global', 1).': '.
420 (!empty($label) ?
421 $label :
422 abs($groupId)
423 );
424
425 if($groupId == -100) {
426 $label = $GLOBALS['LANG']->getLL('bookmark_global', 1).': '.$GLOBALS['LANG']->getLL('bookmark_all', 1);
427 }
428 }
429
430 $this->shortcutGroups[$groupId] = $label;
431 }
432
433 return $this->shortcutGroups;
434 }
435
436 /**
437 * gets the available shortcut groups
438 *
439 * @param array array of parameters from the AJAX interface, currently unused
440 * @param TYPO3AJAX object of type TYPO3AJAX
441 * @return void
442 */
443 public function getAjaxShortcutGroups($params = array(), TYPO3AJAX &$ajaxObj = NULL) {
444 $shortcutGroups = $this->shortcutGroups;
445
446 if(!$GLOBALS['BE_USER']->isAdmin()) {
447 foreach($shortcutGroups as $groupId => $groupName) {
448 if(intval($groupId) < 0) {
449 unset($shortcutGroups[$groupId]);
450 }
451 }
452 }
453
454 $ajaxObj->addContent('shortcutGroups', $shortcutGroups);
455 $ajaxObj->setContentFormat('json');
456 }
457
458 /**
459 * deletes a shortcut through an AJAX call
460 *
461 * @param array array of parameters from the AJAX interface, currently unused
462 * @param TYPO3AJAX object of type TYPO3AJAX
463 * @return void
464 */
465 public function deleteAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = NULL) {
466 $shortcutId = (int) t3lib_div::_POST('shortcutId');
467 $fullShortcut = $this->getShortcutById($shortcutId);
468 $ajaxReturn = 'failed';
469
470 if($fullShortcut['raw']['userid'] == $GLOBALS['BE_USER']->user['uid']) {
471 $GLOBALS['TYPO3_DB']->exec_DELETEquery(
472 'sys_be_shortcuts',
473 'uid = '.$shortcutId
474 );
475
476 if($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
477 $ajaxReturn = 'deleted';
478 }
479 }
480
481 $ajaxObj->addContent('delete', $ajaxReturn);
482 }
483
484 /**
485 * creates a shortcut through an AJAX call
486 *
487 * @param array array of parameters from the AJAX interface, currently unused
488 * @param TYPO3AJAX object of type TYPO3AJAX
489 * @return void
490 */
491 public function createAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = NULL) {
492 $shortcutCreated = 'failed';
493 $shortcutName = 'Shortcut'; // default name
494 $shortcutNamePrepend = '';
495
496 $url = t3lib_div::_POST('url');
497 $module = t3lib_div::_POST('module');
498 $motherModule = t3lib_div::_POST('motherModName');
499
500 // determine shortcut type
501 $queryParts = parse_url($url);
502 $queryParameters = t3lib_div::explodeUrl2Array($queryParts['query'], 1);
503
504 // Proceed only if no scheme is defined, as URL is expected to be relative
505 if (empty($queryParts['scheme'])) {
506 if (is_array($queryParameters['edit'])) {
507 $shortcut['table'] = key($queryParameters['edit']);
508 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
509
510 if($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
511 $shortcut['type'] = 'edit';
512 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_edit', 1);
513 } elseif($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
514 $shortcut['type'] = 'new';
515 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_create', 1);
516 }
517 } else {
518 $shortcut['type'] = 'other';
519 }
520
521 // Lookup the title of this page and use it as default description
522 $pageId = $shortcut['recordid'] ? $shortcut['recordid'] : $this->getLinkedPageId($url);
523
524 if(t3lib_utility_Math::canBeInterpretedAsInteger($pageId)) {
525 $page = t3lib_BEfunc::getRecord('pages', $pageId);
526 if(count($page)) {
527 // set the name to the title of the page
528 if($shortcut['type'] == 'other') {
529 $shortcutName = $page['title'];
530 } else {
531 $shortcutName = $shortcutNamePrepend.' '.$GLOBALS['LANG']->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']).' ('.$page['title'].')';
532 }
533 }
534 } else {
535 $dirName = urldecode($pageId);
536 if (preg_match('/\/$/', $dirName)) {
537 // if $pageId is a string and ends with a slash,
538 // assume it is a fileadmin reference and set
539 // the description to the basename of that path
540 $shortcutName .= ' ' . basename($dirName);
541 }
542 }
543
544 // adding the shortcut
545 if($module && $url) {
546 $fieldValues = array(
547 'userid' => $GLOBALS['BE_USER']->user['uid'],
548 'module_name' => $module.'|'.$motherModule,
549 'url' => $url,
550 'description' => $shortcutName,
551 'sorting' => $GLOBALS['EXEC_TIME'],
552 );
553 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fieldValues);
554
555 if($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
556 $shortcutCreated = 'success';
557 }
558 }
559
560 $ajaxObj->addContent('create', $shortcutCreated);
561 }
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 switch($row['module_name']) {
667 case 'xMOD_alt_doc.php':
668 $table = $shortcut['table'];
669 $recordid = $shortcut['recordid'];
670
671 if($shortcut['type'] == 'edit') {
672 // Creating the list of fields to include in the SQL query:
673 $selectFields = $this->fieldArray;
674 $selectFields[] = 'uid';
675 $selectFields[] = 'pid';
676
677 if($table=='pages') {
678 if(t3lib_extMgm::isLoaded('cms')) {
679 $selectFields[] = 'module';
680 $selectFields[] = 'extendToSubpages';
681 }
682 $selectFields[] = 'doktype';
683 }
684
685 if(is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
686 $selectFields = array_merge($selectFields,$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
687 }
688
689 if($GLOBALS['TCA'][$table]['ctrl']['type']) {
690 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
691 }
692
693 if($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
694 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
695 }
696
697 if($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
698 $selectFields[] = 't3ver_state';
699 }
700
701 $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') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.shortcutmenu.php'])) {
792 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.shortcutmenu.php']);
793 }
794
795 ?>