[TASK] Use new way to register rte wizard
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Toolbar / ShortcutToolbarItem.php
1 <?php
2 namespace TYPO3\CMS\Backend\Toolbar;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2007-2013 Ingo Renner <ingo@typo3.org>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 * A copy is found in the text file GPL.txt and important notices to the license
19 * from the author is found in LICENSE.txt distributed with these scripts.
20 *
21 *
22 * This script is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * This copyright notice MUST APPEAR in all copies of the script!
28 ***************************************************************/
29
30 use TYPO3\CMS\Backend\Utility\BackendUtility;
31 use TYPO3\CMS\Backend\Utility\IconUtility;
32 use TYPO3\CMS\Core\Utility\GeneralUtility;
33 use TYPO3\CMS\Core\Utility\MathUtility;
34
35 /**
36 * Class to render the shortcut menu
37 *
38 * @author Ingo Renner <ingo@typo3.org>
39 */
40 class ShortcutToolbarItem implements \TYPO3\CMS\Backend\Toolbar\ToolbarItemHookInterface {
41
42 const SUPERGLOBAL_GROUP = -100;
43
44 /**
45 * @var string
46 * @todo define visibility
47 */
48 public $perms_clause;
49
50 /**
51 * @var string
52 * @todo define visibility
53 */
54 public $backPath;
55
56 /**
57 * @var array
58 * @todo define visibility
59 */
60 public $fieldArray;
61
62 /**
63 * All available shortcuts
64 *
65 * @var array
66 */
67 protected $shortcuts;
68
69 /**
70 * @var array
71 */
72 protected $shortcutGroups;
73
74 /**
75 * Labels of all groups.
76 * If value is 1, the system will try to find a label in the locallang array.
77 *
78 * @var array
79 */
80 protected $groupLabels;
81
82 /**
83 * Reference back to the backend object
84 *
85 * @var \TYPO3\CMS\Backend\Controller\BackendController
86 */
87 protected $backendReference;
88
89 /**
90 * Constructor
91 *
92 * @param \TYPO3\CMS\Backend\Controller\BackendController $backendReference TYPO3 backend object reference
93 */
94 public function __construct(\TYPO3\CMS\Backend\Controller\BackendController &$backendReference = NULL) {
95 if (TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
96 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xlf');
97 // Needed to get the correct icons when reloading the menu after saving it
98 $loadModules = GeneralUtility::makeInstance('TYPO3\\CMS\\Backend\\Module\\ModuleLoader');
99 $loadModules->load($GLOBALS['TBE_MODULES']);
100 }
101 $this->backendReference = $backendReference;
102 $this->shortcuts = array();
103 // By default, 5 groups are set
104 $this->shortcutGroups = array(
105 1 => '1',
106 2 => '1',
107 3 => '1',
108 4 => '1',
109 5 => '1'
110 );
111 $this->shortcutGroups = $this->initShortcutGroups();
112 $this->shortcuts = $this->initShortcuts();
113 }
114
115 /**
116 * Checks whether the user has access to this toolbar item
117 *
118 * @return boolean TRUE if user has access, FALSE if not
119 */
120 public function checkAccess() {
121 return (bool) $GLOBALS['BE_USER']->getTSConfigVal('options.enableBookmarks');
122 }
123
124 /**
125 * Creates the shortcut menu (default renderer)
126 *
127 * @return string Workspace selector as HTML select
128 */
129 public function render() {
130 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarks', TRUE);
131 $this->addJavascriptToBackend();
132 $shortcutMenu = array();
133 $shortcutMenu[] = '<a href="#" class="toolbar-item">' . IconUtility::getSpriteIcon('apps-toolbar-menu-shortcut', array('title' => $title)) . '</a>';
134 $shortcutMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
135 $shortcutMenu[] = $this->renderMenu();
136 $shortcutMenu[] = '</div>';
137 return implode(LF, $shortcutMenu);
138 }
139
140 /**
141 * Renders the pure contents of the menu
142 *
143 * @return string The menu's content
144 */
145 public function renderMenu() {
146 $shortcutGroup = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarksGroup', TRUE);
147 $shortcutEdit = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarksEdit', TRUE);
148 $shortcutDelete = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarksDelete', TRUE);
149 $groupIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/i/sysf.gif', 'width="18" height="16"') . ' title="' . $shortcutGroup . '" alt="' . $shortcutGroup . '" />';
150 $editIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/edit2.gif', 'width="11" height="12"') . ' title="' . $shortcutEdit . '" alt="' . $shortcutEdit . '"';
151 $deleteIcon = '<img' . IconUtility::skinImg($this->backPath, 'gfx/garbage.gif', 'width="11" height="12"') . ' title="' . $shortcutDelete . '" alt="' . $shortcutDelete . '" />';
152 $shortcutMenu[] = '<table border="0" cellspacing="0" cellpadding="0" class="shortcut-list">';
153 // Render shortcuts with no group (group id = 0) first
154 $noGroupShortcuts = $this->getShortcutsByGroup(0);
155 foreach ($noGroupShortcuts as $shortcut) {
156 $shortcutMenu[] = '
157 <tr id="shortcut-' . $shortcut['raw']['uid'] . '" class="shortcut">
158 <td class="shortcut-icon">' . $shortcut['icon'] . '</td>
159 <td class="shortcut-label">
160 <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
161 </td>
162 <td class="shortcut-edit">' . $editIcon . ' id="shortcut-edit-' . $shortcut['raw']['uid'] . '" /></td>
163 <td class="shortcut-delete">' . $deleteIcon . '</td>
164 </tr>';
165 }
166 // Now render groups and the contained shortcuts
167 $groups = $this->getGroupsFromShortcuts();
168 krsort($groups, SORT_NUMERIC);
169 foreach ($groups as $groupId => $groupLabel) {
170 if ($groupId != 0) {
171 $shortcutGroup = '
172 <tr class="shortcut-group" id="shortcut-group-' . $groupId . '">
173 <td class="shortcut-group-icon">' . $groupIcon . '</td>
174 <td class="shortcut-group-label">' . $groupLabel . '</td>
175 <td colspan="2">&nbsp;</td>
176 </tr>';
177 $shortcuts = $this->getShortcutsByGroup($groupId);
178 $i = 0;
179 foreach ($shortcuts as $shortcut) {
180 $i++;
181 $firstRow = '';
182 if ($i == 1) {
183 $firstRow = ' first-row';
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 $shortcutMenu[] = $shortcutGroup;
196 }
197 }
198 if (count($shortcutMenu) == 1) {
199 // No shortcuts added yet, show a small help message how to add shortcuts
200 $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.bookmarks', TRUE);
201 $icon = IconUtility::getSpriteIcon('actions-system-shortcut-new', array(
202 'title' => $title
203 ));
204 $label = str_replace('%icon%', $icon, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmarkDescription'));
205 $shortcutMenu[] = '<tr><td style="padding:1px 2px; color: #838383;">' . $label . '</td></tr>';
206 }
207 $shortcutMenu[] = '</table>';
208 $compiledShortcutMenu = implode(LF, $shortcutMenu);
209 return $compiledShortcutMenu;
210 }
211
212 /**
213 * Renders the menu so that it can be returned as response to an AJAX call
214 *
215 * @param array $params Array of parameters from the AJAX interface, currently unused
216 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
217 * @return void
218 */
219 public function renderAjax($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
220 $menuContent = $this->renderMenu();
221 $ajaxObj->addContent('shortcutMenu', $menuContent);
222 }
223
224 /**
225 * Adds the necessary JavaScript to the backend
226 *
227 * @return void
228 */
229 protected function addJavascriptToBackend() {
230 $this->backendReference->addJavascriptFile('sysext/backend/Resources/Public/JavaScript/shortcutmenu.js');
231 $this->backendReference->getPageRenderer()->addInlineSetting('ShortcutMenu.saveShortcut', 'ajaxUrl', BackendUtility::getAjaxUrl('ShortcutMenu::saveShortcut'));
232 $this->backendReference->getPageRenderer()->addInlineSetting('ShortcutMenu.delete', 'ajaxUrl', BackendUtility::getAjaxUrl('ShortcutMenu::delete'));
233 $this->backendReference->getPageRenderer()->addInlineSetting('ShortcutMenu.getGroups', 'ajaxUrl', BackendUtility::getAjaxUrl('ShortcutMenu::getGroups'));
234 $this->backendReference->getPageRenderer()->addInlineSetting('ShortcutMenu.render', 'ajaxUrl', BackendUtility::getAjaxUrl('ShortcutMenu::render'));
235 $this->backendReference->getPageRenderer()->addInlineSetting('ShortcutMenu.create', 'ajaxUrl', BackendUtility::getAjaxUrl('ShortcutMenu::create'));
236 }
237
238 /**
239 * Returns additional attributes for the list item in the toolbar
240 *
241 * @return string List item HTML attibutes
242 */
243 public function getAdditionalAttributes() {
244 return ' id="shortcut-menu"';
245 }
246
247 /**
248 * Retrieves the shortcuts for the current user
249 *
250 * @return array Array of shortcuts
251 */
252 protected function initShortcuts() {
253 $globalGroupIdList = implode(',', array_keys($this->getGlobalShortcutGroups()));
254 $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
255 '*',
256 'sys_be_shortcuts',
257 '(userid = ' . (int)$GLOBALS['BE_USER']->user['uid'] . ' AND sc_group>=0) OR sc_group IN (' . $globalGroupIdList . ')',
258 '',
259 'sc_group,sorting'
260 );
261 // Traverse shortcuts
262 $lastGroup = 0;
263 $shortcuts = array();
264 while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
265 $shortcut = array('raw' => $row);
266
267 list($row['module_name'], $row['M_module_name']) = explode('|', $row['module_name']);
268
269 $queryParts = parse_url($row['url']);
270 $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
271 if ($row['module_name'] === 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
272 $shortcut['table'] = key($queryParameters['edit']);
273 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
274 if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'edit') {
275 $shortcut['type'] = 'edit';
276 } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] === 'new') {
277 $shortcut['type'] = 'new';
278 }
279 if (substr($shortcut['recordid'], -1) === ',') {
280 $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
281 }
282 } else {
283 $shortcut['type'] = 'other';
284 }
285 // Check for module access
286 $moduleName = $row['M_module_name'] ?: $row['module_name'];
287 $pageId = $this->getLinkedPageId($row['url']);
288 if (!$GLOBALS['BE_USER']->isAdmin()) {
289 if (!isset($GLOBALS['LANG']->moduleLabels['tabs_images'][$moduleName . '_tab'])) {
290 // Nice hack to check if the user has access to this module
291 // - otherwise the translation label would not have been loaded :-)
292 continue;
293 }
294 if (MathUtility::canBeInterpretedAsInteger($pageId)) {
295 // Check for webmount access
296 if (!$GLOBALS['BE_USER']->isInWebMount($pageId)) {
297 continue;
298 }
299 // Check for record access
300 $pageRow = BackendUtility::getRecord('pages', $pageId);
301 if (!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow, ($perms = 1))) {
302 continue;
303 }
304 }
305 }
306 $moduleParts = explode('_', $moduleName);
307 $shortcutGroup = (int)$row['sc_group'];
308 if ($shortcutGroup && $lastGroup !== $shortcutGroup && $shortcutGroup !== self::SUPERGLOBAL_GROUP) {
309 $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
310 }
311 $lastGroup = $shortcutGroup;
312
313 if ($row['description']) {
314 $shortcut['label'] = $row['description'];
315 } else {
316 $shortcut['label'] = GeneralUtility::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
317 }
318 $shortcut['group'] = $shortcutGroup;
319 $shortcut['icon'] = $this->getShortcutIcon($row, $shortcut);
320 $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcut['label'], $row['module_name'], $row['M_module_name']);
321 $shortcut['action'] = 'jump(unescape(\'' . rawurlencode($this->getTokenUrl($row['url'])) . '\'),\'' . $moduleName . '\',\'' . $moduleParts[0] . '\', ' . (int)$pageId . ');';
322
323 $shortcuts[] = $shortcut;
324 }
325 return $shortcuts;
326 }
327
328 /**
329 * Adds the correct token, if the url is a mod.php script
330 *
331 * @param string $url
332 * @return string
333 */
334 protected function getTokenUrl($url) {
335 $parsedUrl = parse_url($url);
336 parse_str($parsedUrl['query'], $parameters);
337 if (strpos($parsedUrl['path'], 'mod.php') !== FALSE && isset($parameters['M'])) {
338 $module = $parameters['M'];
339 unset($parameters['M']);
340 $url = str_replace('mod.php', '', $parsedUrl['path']) . BackendUtility::getModuleUrl($module, $parameters);
341 }
342 return $url;
343 }
344
345 /**
346 * Gets shortcuts for a specific group
347 *
348 * @param integer $groupId Group Id
349 * @return array Array of shortcuts that matched the group
350 */
351 protected function getShortcutsByGroup($groupId) {
352 $shortcuts = array();
353 foreach ($this->shortcuts as $shortcut) {
354 if ($shortcut['group'] == $groupId) {
355 $shortcuts[] = $shortcut;
356 }
357 }
358 return $shortcuts;
359 }
360
361 /**
362 * Gets a shortcut by its uid
363 *
364 * @param integer $shortcutId Shortcut id to get the complete shortcut for
365 * @return mixed An array containing the shortcut's data on success or FALSE on failure
366 */
367 protected function getShortcutById($shortcutId) {
368 $returnShortcut = FALSE;
369 foreach ($this->shortcuts as $shortcut) {
370 if ($shortcut['raw']['uid'] == (int)$shortcutId) {
371 $returnShortcut = $shortcut;
372 continue;
373 }
374 }
375 return $returnShortcut;
376 }
377
378 /**
379 * Gets the available shortcut groups from default groups, user TSConfig, and global groups
380 *
381 * @return array
382 */
383 protected function initShortcutGroups() {
384 // Groups from TSConfig
385 $bookmarkGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.bookmarkGroups');
386 if (is_array($bookmarkGroups) && count($bookmarkGroups)) {
387 foreach ($bookmarkGroups as $groupId => $label) {
388 if (!empty($label)) {
389 $this->shortcutGroups[$groupId] = (string)$label;
390 } elseif ($GLOBALS['BE_USER']->isAdmin()) {
391 unset($this->shortcutGroups[$groupId]);
392 }
393 }
394 }
395 // Generate global groups, all global groups have negative IDs.
396 if (count($this->shortcutGroups)) {
397 $groups = $this->shortcutGroups;
398 foreach ($groups as $groupId => $groupLabel) {
399 $this->shortcutGroups[$groupId * -1] = $groupLabel;
400 }
401 }
402 // Group -100 is kind of superglobal and can't be changed.
403 $this->shortcutGroups[self::SUPERGLOBAL_GROUP] = 1;
404 // Add labels
405 foreach ($this->shortcutGroups as $groupId => $groupLabel) {
406 $groupId = (int)$groupId;
407 $label = $groupLabel;
408 if ($groupLabel == '1') {
409 $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_group_' . abs($groupId), TRUE);
410 if (empty($label)) {
411 // Fallback label
412 $label = $GLOBALS['LANG']->getLL('bookmark_group', 1) . ' ' . abs($groupId);
413 }
414 }
415 if ($groupId < 0) {
416 // Global group
417 $label = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.xlf:bookmark_global', TRUE) . ': ' . (!empty($label) ? $label : abs($groupId));
418 if ($groupId === self::SUPERGLOBAL_GROUP) {
419 $label = $GLOBALS['LANG']->getLL('bookmark_global', 1) . ': ' . $GLOBALS['LANG']->getLL('bookmark_all', 1);
420 }
421 }
422 $this->shortcutGroups[$groupId] = $label;
423 }
424 return $this->shortcutGroups;
425 }
426
427 /**
428 * gets the available shortcut groups
429 *
430 * @param array $params Array of parameters from the AJAX interface, currently unused
431 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
432 * @return void
433 */
434 public function getAjaxShortcutGroups($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
435 $shortcutGroups = $this->shortcutGroups;
436 if (!$GLOBALS['BE_USER']->isAdmin()) {
437 foreach ($shortcutGroups as $groupId => $groupName) {
438 if ((int)$groupId < 0) {
439 unset($shortcutGroups[$groupId]);
440 }
441 }
442 }
443 $ajaxObj->addContent('shortcutGroups', $shortcutGroups);
444 $ajaxObj->setContentFormat('json');
445 }
446
447 /**
448 * Deletes a shortcut through an AJAX call
449 *
450 * @param array $params Array of parameters from the AJAX interface, currently unused
451 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
452 * @return void
453 */
454 public function deleteAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
455 $shortcutId = (int)GeneralUtility::_POST('shortcutId');
456 $fullShortcut = $this->getShortcutById($shortcutId);
457 $ajaxReturn = 'failed';
458 if ($fullShortcut['raw']['userid'] == $GLOBALS['BE_USER']->user['uid']) {
459 $GLOBALS['TYPO3_DB']->exec_DELETEquery('sys_be_shortcuts', 'uid = ' . $shortcutId);
460 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
461 $ajaxReturn = 'deleted';
462 }
463 }
464 $ajaxObj->addContent('delete', $ajaxReturn);
465 }
466
467 /**
468 * Creates a shortcut through an AJAX call
469 *
470 * @param array $params Array of parameters from the AJAX interface, currently unused
471 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Oject of type AjaxRequestHandler
472 * @return void
473 */
474 public function createAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
475 $shortcutCreated = 'failed';
476 // Default name
477 $shortcutName = 'Shortcut';
478 $shortcutNamePrepend = '';
479 $url = GeneralUtility::_POST('url');
480 $module = GeneralUtility::_POST('module');
481 $motherModule = GeneralUtility::_POST('motherModName');
482 // Determine shortcut type
483 $queryParts = parse_url($url);
484 $queryParameters = GeneralUtility::explodeUrl2Array($queryParts['query'], 1);
485 // Proceed only if no scheme is defined, as URL is expected to be relative
486 if (empty($queryParts['scheme'])) {
487 if (is_array($queryParameters['edit'])) {
488 $shortcut['table'] = key($queryParameters['edit']);
489 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
490 if ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
491 $shortcut['type'] = 'edit';
492 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_edit', 1);
493 } elseif ($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
494 $shortcut['type'] = 'new';
495 $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_create', 1);
496 }
497 } else {
498 $shortcut['type'] = 'other';
499 }
500 // Lookup the title of this page and use it as default description
501 $pageId = $shortcut['recordid'] ? $shortcut['recordid'] : $this->getLinkedPageId($url);
502 if (MathUtility::canBeInterpretedAsInteger($pageId)) {
503 $page = BackendUtility::getRecord('pages', $pageId);
504 if (count($page)) {
505 // Set the name to the title of the page
506 if ($shortcut['type'] == 'other') {
507 $shortcutName = $page['title'];
508 } else {
509 $shortcutName = $shortcutNamePrepend . ' ' . $GLOBALS['LANG']->sL($GLOBALS['TCA'][$shortcut['table']]['ctrl']['title']) . ' (' . $page['title'] . ')';
510 }
511 }
512 } else {
513 $dirName = urldecode($pageId);
514 if (preg_match('/\\/$/', $dirName)) {
515 // If $pageId is a string and ends with a slash,
516 // assume it is a fileadmin reference and set
517 // the description to the basename of that path
518 $shortcutName .= ' ' . basename($dirName);
519 }
520 }
521 // adding the shortcut
522 if ($module && $url) {
523 $fieldValues = array(
524 'userid' => $GLOBALS['BE_USER']->user['uid'],
525 'module_name' => $module . '|' . $motherModule,
526 'url' => $url,
527 'description' => $shortcutName,
528 'sorting' => $GLOBALS['EXEC_TIME']
529 );
530 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fieldValues);
531 if ($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
532 $shortcutCreated = 'success';
533 }
534 }
535 $ajaxObj->addContent('create', $shortcutCreated);
536 }
537 }
538
539 /**
540 * Gets called when a shortcut is changed, checks whether the user has
541 * permissions to do so and saves the changes if everything is ok
542 *
543 * @param array $params Array of parameters from the AJAX interface, currently unused
544 * @param \TYPO3\CMS\Core\Http\AjaxRequestHandler $ajaxObj Object of type AjaxRequestHandler
545 * @return void
546 */
547 public function setAjaxShortcut($params = array(), \TYPO3\CMS\Core\Http\AjaxRequestHandler &$ajaxObj = NULL) {
548 $shortcutId = (int)GeneralUtility::_POST('shortcutId');
549 $shortcutName = strip_tags(GeneralUtility::_POST('value'));
550 $shortcutGroupId = (int)GeneralUtility::_POST('shortcut-group');
551 if ($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) {
552 // Users can delete only their own shortcuts (except admins)
553 $addUserWhere = !$GLOBALS['BE_USER']->isAdmin() ? ' AND userid=' . (int)$GLOBALS['BE_USER']->user['uid'] : '';
554 $fieldValues = array(
555 'description' => $shortcutName,
556 'sc_group' => $shortcutGroupId
557 );
558 if ($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) {
559 $fieldValues['sc_group'] = 0;
560 }
561 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('sys_be_shortcuts', 'uid=' . $shortcutId . $addUserWhere, $fieldValues);
562 $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
563 if ($affectedRows == 1) {
564 $ajaxObj->addContent('shortcut', $shortcutName);
565 } else {
566 $ajaxObj->addContent('shortcut', 'failed');
567 }
568 }
569 $ajaxObj->setContentFormat('plain');
570 }
571
572 /**
573 * Gets the label for a shortcut group
574 *
575 * @param integer $groupId A shortcut group id
576 * @return string The shortcut group label, can be an empty string if no group was found for the id
577 */
578 protected function getShortcutGroupLabel($groupId) {
579 return isset($this->shortcutGroups[$groupId]) ? $this->shortcutGroups[$groupId] : '';
580 }
581
582 /**
583 * Gets a list of global groups, shortcuts in these groups are available to all users
584 *
585 * @return array Array of global groups
586 */
587 protected function getGlobalShortcutGroups() {
588 $globalGroups = array();
589 foreach ($this->shortcutGroups as $groupId => $groupLabel) {
590 if ($groupId < 0) {
591 $globalGroups[$groupId] = $groupLabel;
592 }
593 }
594 return $globalGroups;
595 }
596
597 /**
598 * runs through the available shortcuts an collects their groups
599 *
600 * @return array Array of groups which have shortcuts
601 */
602 protected function getGroupsFromShortcuts() {
603 $groups = array();
604 foreach ($this->shortcuts as $shortcut) {
605 $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
606 }
607 return array_unique($groups);
608 }
609
610 /**
611 * Gets the icon for the shortcut
612 *
613 * @param array $row
614 * @param array $shortcut
615 * @return string Shortcut icon as img tag
616 */
617 protected function getShortcutIcon($row, $shortcut) {
618 switch ($row['module_name']) {
619 case 'xMOD_alt_doc.php':
620 $table = $shortcut['table'];
621 $recordid = $shortcut['recordid'];
622 $icon = '';
623 if ($shortcut['type'] == 'edit') {
624 // Creating the list of fields to include in the SQL query:
625 $selectFields = $this->fieldArray;
626 $selectFields[] = 'uid';
627 $selectFields[] = 'pid';
628 if ($table == 'pages') {
629 if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('cms')) {
630 $selectFields[] = 'module';
631 $selectFields[] = 'extendToSubpages';
632 }
633 $selectFields[] = 'doktype';
634 }
635 if (is_array($GLOBALS['TCA'][$table]['ctrl']['enablecolumns'])) {
636 $selectFields = array_merge($selectFields, $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']);
637 }
638 if ($GLOBALS['TCA'][$table]['ctrl']['type']) {
639 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['type'];
640 }
641 if ($GLOBALS['TCA'][$table]['ctrl']['typeicon_column']) {
642 $selectFields[] = $GLOBALS['TCA'][$table]['ctrl']['typeicon_column'];
643 }
644 if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
645 $selectFields[] = 't3ver_state';
646 }
647 // Unique list!
648 $selectFields = array_unique($selectFields);
649 $permissionClause = $table === 'pages' && $this->perms_clause ? ' AND ' . $this->perms_clause : '';
650 $sqlQueryParts = array(
651 'SELECT' => implode(',', $selectFields),
652 'FROM' => $table,
653 'WHERE' => 'uid IN (' . $recordid . ') ' . $permissionClause . BackendUtility::deleteClause($table) . BackendUtility::versioningPlaceholderClause($table)
654 );
655 $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($sqlQueryParts);
656 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
657 $icon = IconUtility::getIcon($table, $row, $this->backPath);
658 } elseif ($shortcut['type'] == 'new') {
659 $icon = IconUtility::getIcon($table, '', $this->backPath);
660 }
661 $icon = IconUtility::skinImg($this->backPath, $icon, '', 1);
662 break;
663 case 'xMOD_file_edit.php':
664 $icon = 'gfx/edit_file.gif';
665 break;
666 case 'wizard_rte':
667 $icon = 'gfx/edit_rtewiz.gif';
668 break;
669 default:
670 if ($GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab']) {
671 $icon = $GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'] . '_tab'];
672 // Change icon of fileadmin references - otherwise it doesn't differ with Web->List
673 $icon = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $icon);
674 if (GeneralUtility::isAbsPath($icon)) {
675 $icon = '../' . \TYPO3\CMS\Core\Utility\PathUtility::stripPathSitePrefix($icon);
676 }
677 } else {
678 $icon = 'gfx/dummy_module.gif';
679 }
680 }
681 return '<img src="' . $icon . '" alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.shortcut', TRUE) . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:toolbarItems.shortcut', TRUE) . '" />';
682 }
683
684 /**
685 * Returns title for the shortcut icon
686 *
687 * @param string $shortcutLabel Shortcut label
688 * @param string $moduleName Backend module name (key)
689 * @param string $parentModuleName Parent module label
690 * @return string Title for the shortcut icon
691 */
692 protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '') {
693 $title = '';
694 if (substr($moduleName, 0, 5) == 'xMOD_') {
695 $title = substr($moduleName, 5);
696 } else {
697 $splitModuleName = explode('_', $moduleName);
698 $title = $GLOBALS['LANG']->moduleLabels['tabs'][$splitModuleName[0] . '_tab'];
699 if (count($splitModuleName) > 1) {
700 $title .= '>' . $GLOBALS['LANG']->moduleLabels['tabs'][($moduleName . '_tab')];
701 }
702 }
703 if ($parentModuleName) {
704 $title .= ' (' . $parentModuleName . ')';
705 }
706 $title .= ': ' . $shortcutLabel;
707 return $title;
708 }
709
710 /**
711 * Return the ID of the page in the URL if found.
712 *
713 * @param string $url The URL of the current shortcut link
714 * @return string If a page ID was found, it is returned. Otherwise: 0
715 */
716 protected function getLinkedPageId($url) {
717 return preg_replace('/.*[\\?&]id=([^&]+).*/', '$1', $url);
718 }
719
720 }