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