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