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