class.shortcutmenu.php

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

Generated on Sat Jan 3 04:23:28 2009 for TYPO3 API by  doxygen 1.4.7