PageRenderTime 50ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/typo3/classes/class.shortcutmenu.php

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