TYPO3 API  SVNRelease
class.shortcutmenu.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2007-2011 Ingo Renner <ingo@typo3.org>
00006 *  All rights reserved
00007 *
00008 *  This script is part of the TYPO3 project. The TYPO3 project is
00009 *  free software; you can redistribute it and/or modify
00010 *  it under the terms of the GNU General Public License as published by
00011 *  the Free Software Foundation; either version 2 of the License, or
00012 *  (at your option) any later version.
00013 *
00014 *  The GNU General Public License can be found at
00015 *  http://www.gnu.org/copyleft/gpl.html.
00016 *  A copy is found in the textfile GPL.txt and important notices to the license
00017 *  from the author is found in LICENSE.txt distributed with these scripts.
00018 *
00019 *
00020 *  This script is distributed in the hope that it will be useful,
00021 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 *  GNU General Public License for more details.
00024 *
00025 *  This copyright notice MUST APPEAR in all copies of the script!
00026 ***************************************************************/
00027 
00028 if(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) {
00029     require_once(PATH_typo3 . 'interfaces/interface.backend_toolbaritem.php');
00030     $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml');
00031 
00032         // needed to get the correct icons when reloading the menu after saving it
00033     $loadModules = t3lib_div::makeInstance('t3lib_loadModules');
00034     $loadModules->load($GLOBALS['TBE_MODULES']);
00035 }
00036 
00037 
00038 /**
00039  * class to render the shortcut menu
00040  *
00041  * $Id: class.shortcutmenu.php 10121 2011-01-18 20:15:30Z ohader $
00042  *
00043  * @author  Ingo Renner <ingo@typo3.org>
00044  * @package TYPO3
00045  * @subpackage core
00046  */
00047 class ShortcutMenu implements backend_toolbarItem {
00048 
00049     protected $shortcutGroups;
00050 
00051     /**
00052      * all available shortcuts
00053      *
00054      * @var array
00055      */
00056     protected $shortcuts;
00057 
00058     /**
00059      * labels of all groups.
00060      * If value is 1, the system will try to find a label in the locallang array.
00061      *
00062      * @var array
00063      */
00064     protected $groupLabels;
00065 
00066     /**
00067      * reference back to the backend object
00068      *
00069      * @var TYPO3backend
00070      */
00071     protected $backendReference;
00072 
00073     /**
00074      * constructor
00075      *
00076      * @param   TYPO3backend    TYPO3 backend object reference
00077      * @return  void
00078      */
00079     public function __construct(TYPO3backend &$backendReference = null) {
00080         $this->backendReference = $backendReference;
00081         $this->shortcuts        = array();
00082 
00083             // by default, 5 groups are set
00084         $this->shortcutGroups = array(
00085             1 => '1',
00086             2 => '1',
00087             3 => '1',
00088             4 => '1',
00089             5 => '1',
00090         );
00091 
00092         $this->shortcutGroups  = $this->initShortcutGroups();
00093         $this->shortcuts       = $this->initShortcuts();
00094     }
00095 
00096     /**
00097      * checks whether the user has access to this toolbar item
00098      *
00099      * @return  boolean  true if user has access, false if not
00100      */
00101     public function checkAccess() {
00102             // "Shortcuts" have been renamed to "Bookmarks"
00103             // @deprecated remove shortcuts code in TYPO3 4.7
00104         $useShortcuts = $GLOBALS['BE_USER']->getTSConfigVal('options.enableShortcuts');
00105         if ($useShortcuts !== NULL) {
00106             t3lib_div::deprecationLog('options.enableShortcuts - since TYPO3 4.5, will be removed in TYPO3 4.7 - use options.enableBookmarks instead');
00107             return (bool) $useShortcuts;
00108         }
00109 
00110         return (bool) $GLOBALS['BE_USER']->getTSConfigVal('options.enableBookmarks');
00111     }
00112 
00113     /**
00114      * Creates the shortcut menu (default renderer)
00115      *
00116      * @return  string      workspace selector as HTML select
00117      */
00118     public function render() {
00119         $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarks', true);
00120         $this->addJavascriptToBackend();
00121 
00122         $shortcutMenu = array();
00123 
00124         $shortcutMenu[] = '<a href="#" class="toolbar-item">' .
00125             t3lib_iconWorks::getSpriteIcon('apps-toolbar-menu-shortcut', array('title' => $title)) .
00126             '</a>';
00127         $shortcutMenu[] = '<div class="toolbar-item-menu" style="display: none;">';
00128         $shortcutMenu[] = $this->renderMenu();
00129         $shortcutMenu[] = '</div>';
00130 
00131         return implode(LF, $shortcutMenu);
00132     }
00133 
00134     /**
00135      * renders the pure contents of the menu
00136      *
00137      * @return  string      the menu's content
00138      */
00139     public function renderMenu() {
00140 
00141         $shortcutGroup  = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarksGroup', true);
00142         $shortcutEdit   = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarksEdit', true);
00143         $shortcutDelete = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarksDelete', true);
00144 
00145         $groupIcon  = '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/i/sysf.gif', 'width="18" height="16"').' title="'.$shortcutGroup.'" alt="'.$shortcutGroup.'" />';
00146         $editIcon   = '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/edit2.gif', 'width="11" height="12"').' title="'.$shortcutEdit.'" alt="'.$shortcutEdit.'"';
00147         $deleteIcon = '<img'.t3lib_iconWorks::skinImg($this->backPath, 'gfx/garbage.gif', 'width="11" height="12"').' title="'.$shortcutDelete.'" alt="'.$shortcutDelete.'" />';
00148 
00149         $shortcutMenu[] = '<table border="0" cellspacing="0" cellpadding="0" class="shortcut-list">';
00150 
00151         // render shortcuts with no group (group id = 0) first
00152         $noGroupShortcuts = $this->getShortcutsByGroup(0);
00153         foreach($noGroupShortcuts as $shortcut) {
00154             $shortcutMenu[] = '
00155             <tr id="shortcut-'.$shortcut['raw']['uid'].'" class="shortcut">
00156                 <td class="shortcut-icon">'.$shortcut['icon'].'</td>
00157                 <td class="shortcut-label">
00158                     <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
00159                 </td>
00160                 <td class="shortcut-edit">'.$editIcon.' id="shortcut-edit-'.$shortcut['raw']['uid'].'" /></td>
00161                 <td class="shortcut-delete">'.$deleteIcon.'</td>
00162             </tr>';
00163         }
00164 
00165             // now render groups and the contained shortcuts
00166         $groups = $this->getGroupsFromShortcuts();
00167         krsort($groups, SORT_NUMERIC);
00168         foreach($groups as $groupId => $groupLabel) {
00169             if($groupId != 0 ) {
00170                 $shortcutGroup = '
00171                 <tr class="shortcut-group" id="shortcut-group-'.$groupId.'">
00172                     <td class="shortcut-group-icon">'.$groupIcon.'</td>
00173                     <td class="shortcut-group-label">'.$groupLabel.'</td>
00174                     <td colspan="2">&nbsp;</td>
00175                 </tr>';
00176 
00177                 $shortcuts = $this->getShortcutsByGroup($groupId);
00178                 $i = 0;
00179                 foreach($shortcuts as $shortcut) {
00180                     $i++;
00181 
00182                     $firstRow = '';
00183                     if($i == 1) {
00184                         $firstRow = ' first-row';
00185                     }
00186 
00187                     $shortcutGroup .= '
00188                     <tr id="shortcut-'.$shortcut['raw']['uid'].'" class="shortcut'.$firstRow.'">
00189                         <td class="shortcut-icon">'.$shortcut['icon'].'</td>
00190                         <td class="shortcut-label">
00191                             <a id="shortcut-label-' . $shortcut['raw']['uid'] . '" href="#" onclick="' . $shortcut['action'] . '; return false;">' . htmlspecialchars($shortcut['label']) . '</a>
00192                         </td>
00193                         <td class="shortcut-edit">'.$editIcon.' id="shortcut-edit-'.$shortcut['raw']['uid'].'" /></td>
00194                         <td class="shortcut-delete">'.$deleteIcon.'</td>
00195                     </tr>';
00196                 }
00197 
00198                 $shortcutMenu[] = $shortcutGroup;
00199             }
00200         }
00201 
00202         if(count($shortcutMenu) == 1) {
00203                 //no shortcuts added yet, show a small help message how to add shortcuts
00204             $title = $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:toolbarItems.bookmarks', true);
00205             $icon = t3lib_iconWorks::getSpriteIcon('actions-system-shortcut-new', array(
00206                 'title' => $title
00207             ));
00208             $label = str_replace('%icon%', $icon, $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_misc.php:bookmarkDescription'));
00209 
00210             $shortcutMenu[] = '<tr><td style="padding:1px 2px; color: #838383;">'.$label.'</td></tr>';
00211         }
00212 
00213         $shortcutMenu[] = '</table>';
00214 
00215         $compiledShortcutMenu = implode(LF, $shortcutMenu);
00216 
00217         return $compiledShortcutMenu;
00218     }
00219 
00220     /**
00221      * renders the menu so that it can be returned as response to an AJAX call
00222      *
00223      * @param   array       array of parameters from the AJAX interface, currently unused
00224      * @param   TYPO3AJAX   object of type TYPO3AJAX
00225      * @return  void
00226      */
00227     public function renderAjax($params = array(), TYPO3AJAX &$ajaxObj = null) {
00228         $menuContent = $this->renderMenu();
00229 
00230         $ajaxObj->addContent('shortcutMenu', $menuContent);
00231     }
00232 
00233     /**
00234      * adds the necessary JavaScript to the backend
00235      *
00236      * @return  void
00237      */
00238     protected function addJavascriptToBackend() {
00239         $this->backendReference->addJavascriptFile('js/shortcutmenu.js');
00240     }
00241 
00242     /**
00243      * returns additional attributes for the list item in the toolbar
00244      *
00245      * @return  string      list item HTML attibutes
00246      */
00247     public function getAdditionalAttributes() {
00248         return ' id="shortcut-menu"';
00249     }
00250 
00251     /**
00252      * retrieves the shortcuts for the current user
00253      *
00254      * @return  array       array of shortcuts
00255      */
00256     protected function initShortcuts() {
00257         $shortcuts    = array();
00258         $globalGroups = $this->getGlobalShortcutGroups();
00259 
00260         $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
00261             '*',
00262             'sys_be_shortcuts',
00263             '((userid = '.$GLOBALS['BE_USER']->user['uid'].' AND sc_group>=0) OR sc_group IN ('.implode(',', array_keys($globalGroups)).'))',
00264             '',
00265             'sc_group,sorting'
00266         );
00267 
00268             // Traverse shortcuts
00269         while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
00270             $shortcut             = array('raw' => $row);
00271             $moduleParts          = explode('|', $row['module_name']);
00272             $row['module_name']   = $moduleParts[0];
00273             $row['M_module_name'] = $moduleParts[1];
00274             $moduleParts          = explode('_', $row['M_module_name'] ?
00275                 $row['M_module_name'] :
00276                 $row['module_name']
00277             );
00278             $queryParts           = parse_url($row['url']);
00279             $queryParameters      = t3lib_div::explodeUrl2Array($queryParts['query'], 1);
00280 
00281             if($row['module_name'] == 'xMOD_alt_doc.php' && is_array($queryParameters['edit'])) {
00282                 $shortcut['table']    = key($queryParameters['edit']);
00283                 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
00284 
00285                 if($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
00286                     $shortcut['type'] = 'edit';
00287                 } elseif($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
00288                     $shortcut['type'] = 'new';
00289                 }
00290 
00291                 if(substr($shortcut['recordid'], -1) == ',') {
00292                     $shortcut['recordid'] = substr($shortcut['recordid'], 0, -1);
00293                 }
00294             } else {
00295                 $shortcut['type'] = 'other';
00296             }
00297 
00298                 // check for module access
00299             if(!$GLOBALS['BE_USER']->isAdmin()) {
00300                 if(!isset($GLOBALS['LANG']->moduleLabels['tabs_images'][implode('_', $moduleParts).'_tab'])) {
00301                         // nice hack to check if the user has access to this module
00302                         // - otherwise the translation label would not have been loaded :-)
00303                     continue;
00304                 }
00305 
00306                 $pageId = $this->getLinkedPageId($row['url']);
00307                 if(t3lib_div::testInt($pageId)) {
00308                         // check for webmount access
00309                     if(!$GLOBALS['BE_USER']->isInWebMount($pageId)) {
00310                         continue;
00311                     }
00312 
00313                         // check for record access
00314                     $pageRow = t3lib_BEfunc::getRecord('pages', $pageId);
00315                     if(!$GLOBALS['BE_USER']->doesUserHaveAccess($pageRow, $perms = 1)) {
00316                         continue;
00317                     }
00318                 }
00319             }
00320 
00321             $shortcutGroup = $row['sc_group'];
00322             if($shortcutGroup && strcmp($lastGroup, $shortcutGroup) && ($shortcutGroup != -100)) {
00323                 $shortcut['groupLabel'] = $this->getShortcutGroupLabel($shortcutGroup);
00324             }
00325 
00326             if($row['description']) {
00327                 $shortcut['label'] = $row['description'];
00328             } else {
00329                 $shortcut['label'] = t3lib_div::fixed_lgd_cs(rawurldecode($queryParts['query']), 150);
00330             }
00331 
00332             $shortcut['group']     = $shortcutGroup;
00333             $shortcut['icon']      = $this->getShortcutIcon($row, $shortcut);
00334             $shortcut['iconTitle'] = $this->getShortcutIconTitle($shortcutLabel, $row['module_name'], $row['M_module_name']);
00335             $shortcut['action']    = 'jump(unescape(\''.rawurlencode($row['url']).'\'),\''.implode('_',$moduleParts).'\',\''.$moduleParts[0].'\');';
00336 
00337             $lastGroup   = $row['sc_group'];
00338             $shortcuts[] = $shortcut;
00339         }
00340 
00341         return $shortcuts;
00342     }
00343 
00344     /**
00345      * gets shortcuts for a specific group
00346      *
00347      * @param   integer     group Id
00348      * @return  array       array of shortcuts that matched the group
00349      */
00350     protected function getShortcutsByGroup($groupId) {
00351         $shortcuts = array();
00352 
00353         foreach($this->shortcuts as $shortcut) {
00354             if($shortcut['group'] == $groupId) {
00355                 $shortcuts[] = $shortcut;
00356             }
00357         }
00358 
00359         return $shortcuts;
00360     }
00361 
00362     /**
00363      * gets a shortcut by its uid
00364      *
00365      * @param   integer     shortcut id to get the complete shortcut for
00366      * @return  mixed       an array containing the shortcut's data on success or false on failure
00367      */
00368     protected function getShortcutById($shortcutId) {
00369         $returnShortcut = false;
00370 
00371         foreach($this->shortcuts as $shortcut) {
00372             if($shortcut['raw']['uid'] == (int) $shortcutId) {
00373                 $returnShortcut = $shortcut;
00374                 continue;
00375             }
00376         }
00377 
00378         return $returnShortcut;
00379     }
00380 
00381     /**
00382      * gets the available shortcut groups from default gropups, user TSConfig,
00383      * and global groups
00384      *
00385      * @param   array       array of parameters from the AJAX interface, currently unused
00386      * @param   TYPO3AJAX   object of type TYPO3AJAX
00387      * @return  array
00388      */
00389     protected function initShortcutGroups($params = array(), TYPO3AJAX &$ajaxObj = null) {
00390             // groups from TSConfig
00391             // "Shortcuts" have been renamed to "Bookmarks"
00392             // @deprecated remove shortcuts code in TYPO3 4.7
00393         $userShortcutGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.shortcutGroups');
00394         if ($userShortcutGroups) {
00395             t3lib_div::deprecationLog('options.shortcutGroups - since TYPO3 4.5, will be removed in TYPO3 4.7 - use options.bookmarkGroups instead');
00396         }
00397         $bookmarkGroups = $GLOBALS['BE_USER']->getTSConfigProp('options.bookmarkGroups');
00398         if ($bookmarkGroups !== NULL) {
00399             $userShortcutGroups = $bookmarkGroups;
00400         }
00401 
00402         if(is_array($userShortcutGroups) && count($userShortcutGroups)) {
00403             foreach($userShortcutGroups as $groupId => $label) {
00404                 if(strcmp('', $label) && strcmp('0', $label)) {
00405                     $this->shortcutGroups[$groupId] = (string) $label;
00406                 } elseif($GLOBALS['BE_USER']->isAdmin()) {
00407                     unset($this->shortcutGroups[$groupId]);
00408                 }
00409             }
00410         }
00411 
00412             // generate global groups, all global groups have negative IDs.
00413         if(count($this->shortcutGroups)) {
00414             $groups = $this->shortcutGroups;
00415             foreach($groups as $groupId => $groupLabel) {
00416                 $this->shortcutGroups[($groupId * -1)] = $groupLabel;
00417             }
00418         }
00419 
00420             // group -100 is kind of superglobal and can't be changed.
00421         $this->shortcutGroups[-100] = 1;
00422 
00423             // add labels
00424         foreach($this->shortcutGroups as $groupId => $groupLabel) {
00425             $label = $groupLabel;
00426 
00427             if($groupLabel == '1') {
00428                 $label = $GLOBALS['LANG']->getLL('bookmark_group_'.abs($groupId), 1);
00429 
00430                 if(empty($label)) {
00431                         // fallback label
00432                     $label = $GLOBALS['LANG']->getLL('bookmark_group', 1).' '.abs($groupId);
00433                 }
00434             }
00435 
00436             if($groupId < 0) {
00437                     // global group
00438                 $label = $GLOBALS['LANG']->getLL('bookmark_global', 1).': '.
00439                     (!empty($label) ?
00440                         $label :
00441                         abs($groupId)
00442                     );
00443 
00444                 if($groupId == -100) {
00445                     $label = $GLOBALS['LANG']->getLL('bookmark_global', 1).': '.$GLOBALS['LANG']->getLL('bookmark_all', 1);
00446                 }
00447             }
00448 
00449             $this->shortcutGroups[$groupId] = $label;
00450         }
00451 
00452         return $this->shortcutGroups;
00453     }
00454 
00455     /**
00456      * gets the available shortcut groups
00457      *
00458      * @param   array       array of parameters from the AJAX interface, currently unused
00459      * @param   TYPO3AJAX   object of type TYPO3AJAX
00460      * @return  void
00461      */
00462     public function getAjaxShortcutGroups($params = array(), TYPO3AJAX &$ajaxObj = null) {
00463         $shortcutGroups = $this->shortcutGroups;
00464 
00465         if(!$GLOBALS['BE_USER']->isAdmin()) {
00466             foreach($shortcutGroups as $groupId => $groupName) {
00467                 if(intval($groupId) < 0) {
00468                     unset($shortcutGroups[$groupId]);
00469                 }
00470             }
00471         }
00472 
00473         $ajaxObj->addContent('shortcutGroups', $shortcutGroups);
00474         $ajaxObj->setContentFormat('json');
00475     }
00476 
00477     /**
00478      * deletes a shortcut through an AJAX call
00479      *
00480      * @param   array       array of parameters from the AJAX interface, currently unused
00481      * @param   TYPO3AJAX   object of type TYPO3AJAX
00482      * @return  void
00483      */
00484     public function deleteAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = null) {
00485         $shortcutId   = (int) t3lib_div::_POST('shortcutId');
00486         $fullShortcut = $this->getShortcutById($shortcutId);
00487         $ajaxReturn   = 'failed';
00488 
00489         if($fullShortcut['raw']['userid'] == $GLOBALS['BE_USER']->user['uid']) {
00490             $GLOBALS['TYPO3_DB']->exec_DELETEquery(
00491                 'sys_be_shortcuts',
00492                 'uid = '.$shortcutId
00493             );
00494 
00495             if($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
00496                 $ajaxReturn = 'deleted';
00497             }
00498         }
00499 
00500         $ajaxObj->addContent('delete', $ajaxReturn);
00501     }
00502 
00503     /**
00504      * creates a shortcut through an AJAX call
00505      *
00506      * @param   array       array of parameters from the AJAX interface, currently unused
00507      * @param   TYPO3AJAX   object of type TYPO3AJAX
00508      * @return  void
00509      */
00510     public function createAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = null) {
00511         global $TCA, $LANG;
00512 
00513         $shortcutCreated     = 'failed';
00514         $shortcutName        = 'Shortcut'; // default name
00515         $shortcutNamePrepend = '';
00516 
00517         $url             = t3lib_div::_POST('url');
00518         $module          = t3lib_div::_POST('module');
00519         $motherModule    = t3lib_div::_POST('motherModName');
00520 
00521             // determine shortcut type
00522         $queryParts      = parse_url($url);
00523         $queryParameters = t3lib_div::explodeUrl2Array($queryParts['query'], 1);
00524 
00525             // Proceed only if no scheme is defined, as URL is expected to be relative
00526         if (empty($queryParts['scheme'])) {
00527             if (is_array($queryParameters['edit'])) {
00528                 $shortcut['table']    = key($queryParameters['edit']);
00529                 $shortcut['recordid'] = key($queryParameters['edit'][$shortcut['table']]);
00530 
00531                 if($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'edit') {
00532                     $shortcut['type']    = 'edit';
00533                     $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_edit', 1);
00534                 } elseif($queryParameters['edit'][$shortcut['table']][$shortcut['recordid']] == 'new') {
00535                     $shortcut['type']    = 'new';
00536                     $shortcutNamePrepend = $GLOBALS['LANG']->getLL('shortcut_create', 1);
00537                 }
00538             } else {
00539                 $shortcut['type'] = 'other';
00540             }
00541 
00542                 // Lookup the title of this page and use it as default description
00543             $pageId = $shortcut['recordid'] ? $shortcut['recordid'] : $this->getLinkedPageId($url);
00544 
00545             if(t3lib_div::testInt($pageId)) {
00546                 $page = t3lib_BEfunc::getRecord('pages', $pageId);
00547                 if(count($page)) {
00548                         // set the name to the title of the page
00549                     if($shortcut['type'] == 'other') {
00550                         $shortcutName = $page['title'];
00551                     } else {
00552                         $shortcutName = $shortcutNamePrepend.' '.$LANG->sL($TCA[$shortcut['table']]['ctrl']['title']).' ('.$page['title'].')';
00553                     }
00554                 }
00555             } else {
00556                 $dirName = urldecode($pageId);
00557                 if (preg_match('/\/$/', $dirName))  {
00558                         // if $pageId is a string and ends with a slash,
00559                         // assume it is a fileadmin reference and set
00560                         // the description to the basename of that path
00561                     $shortcutName .= ' ' . basename($dirName);
00562                 }
00563             }
00564 
00565                 // adding the shortcut
00566             if($module && $url) {
00567                 $fieldValues = array(
00568                     'userid'      => $GLOBALS['BE_USER']->user['uid'],
00569                     'module_name' => $module.'|'.$motherModule,
00570                     'url'         => $url,
00571                     'description' => $shortcutName,
00572                     'sorting'     => $GLOBALS['EXEC_TIME'],
00573                 );
00574                 $GLOBALS['TYPO3_DB']->exec_INSERTquery('sys_be_shortcuts', $fieldValues);
00575 
00576                 if($GLOBALS['TYPO3_DB']->sql_affected_rows() == 1) {
00577                     $shortcutCreated = 'success';
00578                 }
00579             }
00580 
00581             $ajaxObj->addContent('create', $shortcutCreated);
00582         }
00583     }
00584 
00585     /**
00586      * gets called when a shortcut is changed, checks whether the user has
00587      * permissions to do so and saves the changes if everything is ok
00588      *
00589      * @param   array       array of parameters from the AJAX interface, currently unused
00590      * @param   TYPO3AJAX   object of type TYPO3AJAX
00591      * @return  void
00592      */
00593     public function setAjaxShortcut($params = array(), TYPO3AJAX &$ajaxObj = null) {
00594 
00595         $shortcutId      = (int) t3lib_div::_POST('shortcutId');
00596         $shortcutName    = strip_tags(t3lib_div::_POST('value'));
00597         $shortcutGroupId = (int) t3lib_div::_POST('shortcut-group');
00598 
00599         if($shortcutGroupId > 0 || $GLOBALS['BE_USER']->isAdmin()) {
00600                 // users can delete only their own shortcuts (except admins)
00601             $addUserWhere = (!$GLOBALS['BE_USER']->isAdmin() ?
00602                 ' AND userid='.intval($GLOBALS['BE_USER']->user['uid'])
00603                 : ''
00604             );
00605 
00606             $fieldValues = array(
00607                 'description' => $shortcutName,
00608                 'sc_group'    => $shortcutGroupId
00609             );
00610 
00611             if($fieldValues['sc_group'] < 0 && !$GLOBALS['BE_USER']->isAdmin()) {
00612                 $fieldValues['sc_group'] = 0;
00613             }
00614 
00615             $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
00616                 'sys_be_shortcuts',
00617                 'uid='.$shortcutId.$addUserWhere,
00618                 $fieldValues
00619             );
00620 
00621             $affectedRows = $GLOBALS['TYPO3_DB']->sql_affected_rows();
00622             if($affectedRows == 1) {
00623                 $ajaxObj->addContent('shortcut', $shortcutName);
00624             } else {
00625                 $ajaxObj->addContent('shortcut', 'failed');
00626             }
00627         }
00628 
00629         $ajaxObj->setContentFormat('plain');
00630     }
00631 
00632     /**
00633      * gets the label for a shortcut group
00634      *
00635      * @param   integer     a shortcut group id
00636      * @return  string      the shortcut group label, can be an empty string if no group was found for the id
00637      */
00638     protected function getShortcutGroupLabel($groupId) {
00639         $label = '';
00640 
00641         if($this->shortcutGroups[$groupId]) {
00642             $label = $this->shortcutGroups[$groupId];
00643         }
00644 
00645         return $label;
00646     }
00647 
00648     /**
00649      * gets a list of global groups, shortcuts in these groups are available to all users
00650      *
00651      * @return  array       array of global groups
00652      */
00653     protected function getGlobalShortcutGroups() {
00654         $globalGroups = array();
00655 
00656         foreach($this->shortcutGroups as $groupId => $groupLabel) {
00657             if($groupId < 0) {
00658                 $globalGroups[$groupId] = $groupLabel;
00659             }
00660         }
00661 
00662         return $globalGroups;
00663     }
00664 
00665     /**
00666      * runs through the available shortcuts an collects their groups
00667      *
00668      * @return  array   array of groups which have shortcuts
00669      */
00670     protected function getGroupsFromShortcuts() {
00671         $groups = array();
00672 
00673         foreach($this->shortcuts as $shortcut) {
00674             $groups[$shortcut['group']] = $this->shortcutGroups[$shortcut['group']];
00675         }
00676 
00677         return array_unique($groups);
00678     }
00679 
00680     /**
00681      * gets the icon for the shortcut
00682      *
00683      * @param   string      backend module name
00684      * @return  string      shortcut icon as img tag
00685      */
00686     protected function getShortcutIcon($row, $shortcut) {
00687         global $TCA;
00688 
00689         switch($row['module_name']) {
00690             case 'xMOD_alt_doc.php':
00691                 $table              = $shortcut['table'];
00692                 $recordid           = $shortcut['recordid'];
00693 
00694                 if($shortcut['type'] == 'edit') {
00695                         // Creating the list of fields to include in the SQL query:
00696                     $selectFields = $this->fieldArray;
00697                     $selectFields[] = 'uid';
00698                     $selectFields[] = 'pid';
00699 
00700                     if($table=='pages') {
00701                         if(t3lib_extMgm::isLoaded('cms')) {
00702                             $selectFields[] = 'module';
00703                             $selectFields[] = 'extendToSubpages';
00704                         }
00705                         $selectFields[] = 'doktype';
00706                     }
00707 
00708                     if(is_array($TCA[$table]['ctrl']['enablecolumns'])) {
00709                         $selectFields = array_merge($selectFields,$TCA[$table]['ctrl']['enablecolumns']);
00710                     }
00711 
00712                     if($TCA[$table]['ctrl']['type']) {
00713                         $selectFields[] = $TCA[$table]['ctrl']['type'];
00714                     }
00715 
00716                     if($TCA[$table]['ctrl']['typeicon_column']) {
00717                         $selectFields[] = $TCA[$table]['ctrl']['typeicon_column'];
00718                     }
00719 
00720                     if($TCA[$table]['ctrl']['versioningWS']) {
00721                         $selectFields[] = 't3ver_state';
00722                     }
00723 
00724                     $selectFields     = array_unique($selectFields); // Unique list!
00725                     $permissionClause = ($table=='pages' && $this->perms_clause) ?
00726                         ' AND '.$this->perms_clause :
00727                         '';
00728 
00729                     $sqlQueryParts = array(
00730                         'SELECT' => implode(',', $selectFields),
00731                         'FROM'   => $table,
00732                         'WHERE'  => 'uid IN ('.$recordid.') '.$permissionClause.
00733                         t3lib_BEfunc::deleteClause($table).
00734                         t3lib_BEfunc::versioningPlaceholderClause($table)
00735                     );
00736                     $result = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($sqlQueryParts);
00737                     $row    = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
00738 
00739                     $icon = t3lib_iconWorks::getIcon($table, $row, $this->backPath);
00740                 } elseif($shortcut['type'] == 'new') {
00741                     $icon = t3lib_iconWorks::getIcon($table, '', $this->backPath);
00742                 }
00743 
00744                 $icon = t3lib_iconWorks::skinImg($this->backPath, $icon, '', 1);
00745                 break;
00746             case 'xMOD_file_edit.php':
00747                 $icon = 'gfx/edit_file.gif';
00748                 break;
00749             case 'xMOD_wizard_rte.php':
00750                 $icon = 'gfx/edit_rtewiz.gif';
00751                 break;
00752             default:
00753                 if($GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'].'_tab']) {
00754                     $icon = $GLOBALS['LANG']->moduleLabels['tabs_images'][$row['module_name'].'_tab'];
00755 
00756                         // change icon of fileadmin references - otherwise it doesn't differ with Web->List
00757                     $icon = str_replace('mod/file/list/list.gif', 'mod/file/file.gif', $icon);
00758 
00759                     if(t3lib_div::isAbsPath($icon)) {
00760                         $icon = '../'.substr($icon, strlen(PATH_site));
00761                     }
00762                 } else {
00763                     $icon = 'gfx/dummy_module.gif';
00764                 }
00765         }
00766 
00767         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) . '" />';
00768     }
00769 
00770     /**
00771      * Returns title for the shortcut icon
00772      *
00773      * @param   string      shortcut label
00774      * @param   string      backend module name (key)
00775      * @param   string      parent module label
00776      * @return  string      title for the shortcut icon
00777      */
00778     protected function getShortcutIconTitle($shortcutLabel, $moduleName, $parentModuleName = '') {
00779         $title = '';
00780 
00781         if(substr($moduleName, 0, 5) == 'xMOD_') {
00782             $title = substr($moduleName, 5);
00783         } else {
00784             $splitModuleName = explode('_', $moduleName);
00785             $title = $GLOBALS['LANG']->moduleLabels['tabs'][$splitModuleName[0].'_tab'];
00786 
00787             if(count($splitModuleName) > 1) {
00788                 $title .= '>'.$GLOBALS['LANG']->moduleLabels['tabs'][$moduleName.'_tab'];
00789             }
00790         }
00791 
00792         if($parentModuleName) {
00793             $title .= ' ('.$parentModuleName.')';
00794         }
00795 
00796         $title .= ': '.$shortcutLabel;
00797 
00798         return $title;
00799     }
00800 
00801     /**
00802      * Return the ID of the page in the URL if found.
00803      *
00804      * @param   string      The URL of the current shortcut link
00805      * @return  string      If a page ID was found, it is returned. Otherwise: 0
00806      */
00807     protected function getLinkedPageId($url)    {
00808         return preg_replace('/.*[\?&]id=([^&]+).*/', '$1', $url);
00809     }
00810 
00811 }
00812 
00813 
00814 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.shortcutmenu.php'])) {
00815     include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.shortcutmenu.php']);
00816 }
00817 
00818 ?>