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