[TASK] Remove global declarations inside methods
[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 $shortcutCreated = 'failed';
510 $shortcutName = 'Shortcut'; // default name
511 $shortcutNamePrepend = '';
512
513 $url = t3lib_div::_POST('url');
514 $module = t3lib_div::_POST('module');
515 $motherModule = t3lib_div::_POST('motherModName');
516
517 // determine shortcut type
518 $queryParts = parse_url($url);
519 $queryParameters = t3lib_div::explodeUrl2Array($queryParts['query'], 1);
520
521 // Proceed only if no scheme is defined, as URL is expected to be relative
522 if (empty($queryParts['scheme'])) {
523 if (is_array($queryParameters['edit'])) {
524 $shortcut['table'] = key($queryParameters['edit']);
525 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
526
527 if($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
528 $shortcut['type'] = 'edit';
529 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_edit', 1);
530 } elseif($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
531 $shortcut['type'] = 'new';
532 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_create', 1);
533 }
534 } else {
535 $shortcut['type'] = 'other';
536 }
537
538 // Lookup the title of this page and use it as default description
539 $pageId = $shortcut['recordid'] ? $shortcut['recordid'] : $this->getLinkedPageId($url);
540
541 if(t3lib_div::testInt($pageId)) {
542 $page = t3lib_BEfunc::getRecord('pages', $pageId);
543 if(count($page)) {
544 // set the name to the title of the page
545 if($shortcut['type'] == 'other') {
546 $shortcutName = $page['title'];
547 } else {
548 $shortcutName = $shortcutNamePrepend.' '.$GLOBALS['LANG']->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']).' ('.$page['title'].')';
549 }
550 }
551 } else {
552 $dirName = urldecode($pageId);
553 if (preg_match('/\/$/', $dirName)) {
554 // if $pageId is a string and ends with a slash,
555 // assume it is a fileadmin reference and set
556 // the description to the basename of that path
557 $shortcutName .= ' ' . basename($dirName);
558 }
559 }
560
561 // adding the shortcut
562 if($module && $url) {
563 $fieldValues = array(
564 'userid' => $GLOBALS['BE_USER']->user['uid'],
565 'module_name' => $module.'|'.$motherModule,
566 'url' => $url,
567 'description' => $shortcutName,
568 'sorting' => $GLOBALS['EXEC_TIME'],
569 );
570 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fieldValues);
571
572 if($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
573 $shortcutCreated = 'success';
574 }
575 }
576
577 $ajaxObj->addContent('create', $shortcutCreated);
578 }
579 }
580
581 /**
582 * gets called when a shortcut is changed, checks whether the user has
583 * permissions to do so and saves the changes if everything is ok
584 *
585 * @param array array of parameters from the AJAX interface, currently unused
586 * @param TYPO3AJAX object of type TYPO3AJAX
587 * @return void
588 */
589 public function setAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = NULL) {
590
591 $shortcutId = (int) t3lib_div::_POST('shortcutId');
592 $shortcutName = strip_tags(t3lib_div::_POST('value'));
593 $shortcutGroupId = (int) t3lib_div::_POST('shortcut-group');
594
595 if($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) {
596 // users can delete only their own shortcuts (except admins)
597 $addUserWhere = (!$GLOBALS['BE_USER']->isAdmin() ?
598 ' AND userid='.intval($GLOBALS['BE_USER']->user['uid'])
599 : ''
600 );
601
602 $fieldValues = array(
603 'description' => $shortcutName,
604 'sc_group' => $shortcutGroupId
605 );
606
607 if($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) {
608 $fieldValues['sc_group'] = 0;
609 }
610
611 $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
612 'sys_be_shortcuts',
613 'uid='.$shortcutId.$addUserWhere,
614 $fieldValues
615 );
616
617 $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
618 if($affectedRows == 1) {
619 $ajaxObj->addContent('shortcut', $shortcutName);
620 } else {
621 $ajaxObj->addContent('shortcut', 'failed');
622 }
623 }
624
625 $ajaxObj->setContentFormat('plain');
626 }
627
628 /**
629 * gets the label for a shortcut group
630 *
631 * @param integer a shortcut group id
632 * @return string the shortcut group label, can be an empty string if no group was found for the id
633 */
634 protected function getShortcutGroupLabel($groupId) {
635 $label = '';
636
637 if($this->shortcutGroups[$groupId]) {
638 $label = $this->shortcutGroups[$groupId];
639 }
640
641 return $label;
642 }
643
644 /**
645 * gets a list of global groups, shortcuts in these groups are available to all users
646 *
647 * @return array array of global groups
648 */
649 protected function getGlobalShortcutGroups() {
650 $globalGroups = array();
651
652 foreach($this->shortcutGroups as $groupId => $groupLabel) {
653 if($groupId < 0) {
654 $globalGroups[$groupId] = $groupLabel;
655 }
656 }
657
658 return $globalGroups;
659 }
660
661 /**
662 * runs through the available shortcuts an collects their groups
663 *
664 * @return array array of groups which have shortcuts
665 */
666 protected function getGroupsFromShortcuts() {
667 $groups = array();
668
669 foreach($this->shortcuts as $shortcut) {
670 $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
671 }
672
673 return array_unique($groups);
674 }
675
676 /**
677 * gets the icon for the shortcut
678 *
679 * @param string backend module name
680 * @return string shortcut icon as img tag
681 */
682 protected function getShortcutIcon($row, $shortcut) {
683 switch($row['module_name']) {
684 case 'xMOD_alt_doc.php':
685 $table = $shortcut['table'];
686 $recordid = $shortcut['recordid'];
687
688 if($shortcut['type'] == 'edit') {
689 // Creating the list of fields to include in the SQL query:
690 $selectFields = $this->fieldArray;
691 $selectFields[] = 'uid';
692 $selectFields[] = 'pid';
693
694 if($table=='pages') {
695 if(t3lib_extMgm::isLoaded('cms')) {
696 $selectFields[] = 'module';
697 $selectFields[] = 'extendToSubpages';
698 }
699 $selectFields[] = 'doktype';
700 }
701
702 if(is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
703 $selectFields = array_merge($selectFields,$GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
704 }
705
706 if($GLOBALS['TCA'][$table]['ctrl']['type']) {
707 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
708 }
709
710 if($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
711 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
712 }
713
714 if($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
715 $selectFields[] = 't3ver_state';
716 }
717
718 $selectFields = array_unique($selectFields); // Unique list!
719 $permissionClause = ($table=='pages' && $this->perms_clause) ?
720 ' AND '.$this->perms_clause :
721 '';
722
723 $sqlQueryParts = array(
724 'SELECT' => implode(',', $selectFields),
725 'FROM' => $table,
726 'WHERE' => 'uid IN ('.$recordid.') '.$permissionClause.
727 t3lib_BEfunc::deleteClause($table).
728 t3lib_BEfunc::versioningPlaceholderClause($table)
729 );
730 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($sqlQueryParts);
731 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
732
733 $icon = t3lib_iconWorks::getIcon($table, $row, $this->backPath);
734 } elseif($shortcut['type'] == 'new') {
735 $icon = t3lib_iconWorks::getIcon($table, '', $this->backPath);
736 }
737
738 $icon = t3lib_iconWorks::skinImg($this->backPath, $icon, '', 1);
739 break;
740 case 'xMOD_file_edit.php':
741 $icon = 'gfx/edit_file.gif';
742 break;
743 case 'xMOD_wizard_rte.php':
744 $icon = 'gfx/edit_rtewiz.gif';
745 break;
746 default:
747 if($GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'].'_tab']) {
748 $icon = $GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'].'_tab'];
749
750 // change icon of fileadmin references - otherwise it doesn't differ with Web->List
751 $icon = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $icon);
752
753 if(t3lib_div::isAbsPath($icon)) {
754 $icon = '../'.substr($icon, strlen(PATH_site));
755 }
756 } else {
757 $icon = 'gfx/dummy_module.gif';
758 }
759 }
760
761 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) . '" />';
762 }
763
764 /**
765 * Returns title for the shortcut icon
766 *
767 * @param string shortcut label
768 * @param string backend module name (key)
769 * @param string parent module label
770 * @return string title for the shortcut icon
771 */
772 protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '') {
773 $title = '';
774
775 if(substr($moduleName, 0, 5) == 'xMOD_') {
776 $title = substr($moduleName, 5);
777 } else {
778 $splitModuleName = explode('_', $moduleName);
779 $title = $GLOBALS['LANG']->moduleLabels['tabs'][$splitModuleName[0].'_tab'];
780
781 if(count($splitModuleName) > 1) {
782 $title .= '>'.$GLOBALS['LANG']->moduleLabels['tabs'][$moduleName.'_tab'];
783 }
784 }
785
786 if($parentModuleName) {
787 $title .= ' ('.$parentModuleName.')';
788 }
789
790 $title .= ': '.$shortcutLabel;
791
792 return $title;
793 }
794
795 /**
796 * Return the ID of the page in the URL if found.
797 *
798 * @param string The URL of the current shortcut link
799 * @return string If a page ID was found, it is returned. Otherwise: 0
800 */
801 protected function getLinkedPageId($url) {
802 return preg_replace('/.*[\?&]id=([^&]+).*/', '$1', $url);
803 }
804
805 }
806
807
808 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.shortcutmenu.php'])) {
809 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.shortcutmenu.php']);
810 }
811
812 ?>