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