|
TYPO3 API
SVNRelease
|
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 00029 if(TYPO3_REQUESTTYPE & TYPO3_REQUESTTYPE_AJAX) { 00030 $GLOBALS['LANG']->includeLLFile('EXT:lang/locallang_misc.xml'); 00031 } 00032 00033 /** 00034 * class to render the TYPO3 backend menu for the modules 00035 * 00036 * @author Ingo Renner <ingo@typo3.org> 00037 * @package TYPO3 00038 * @subpackage core 00039 */ 00040 class ModuleMenu { 00041 00042 /** 00043 * module loading object 00044 * 00045 * @var t3lib_loadModules 00046 */ 00047 protected $moduleLoader; 00048 00049 protected $backPath; 00050 protected $linkModules; 00051 protected $loadedModules; 00052 00053 00054 /** 00055 * constructor, initializes several variables 00056 * 00057 * @return void 00058 */ 00059 public function __construct() { 00060 00061 $this->backPath = ''; 00062 $this->linkModules = true; 00063 00064 // Loads the backend modules available for the logged in user. 00065 $this->moduleLoader = t3lib_div::makeInstance('t3lib_loadModules'); 00066 $this->moduleLoader->observeWorkspaces = true; 00067 $this->moduleLoader->load($GLOBALS['TBE_MODULES']); 00068 $this->loadedModules = $this->moduleLoader->modules; 00069 00070 } 00071 00072 /** 00073 * sets the path back to /typo3/ 00074 * 00075 * @param string path back to /typo3/ 00076 * @return void 00077 */ 00078 public function setBackPath($backPath) { 00079 if(!is_string($backPath)) { 00080 throw new InvalidArgumentException('parameter $backPath must be of type string', 1193315266); 00081 } 00082 00083 $this->backPath = $backPath; 00084 } 00085 00086 /** 00087 * loads the collapse states for the main modules from user's configuration (uc) 00088 * 00089 * @return array collapse states 00090 */ 00091 protected function getCollapsedStates() { 00092 00093 $collapsedStates = array(); 00094 if($GLOBALS['BE_USER']->uc['moduleData']['moduleMenu']) { 00095 $collapsedStates = $GLOBALS['BE_USER']->uc['moduleData']['moduleMenu']; 00096 } 00097 00098 return $collapsedStates; 00099 } 00100 00101 /** 00102 * ModuleMenu Store loading data 00103 * 00104 * @param array_type $params 00105 * @param object $ajaxObj 00106 */ 00107 public function getModuleData($params, $ajaxObj) { 00108 $data = array('success' => TRUE, 'root' => array()); 00109 $rawModuleData = $this->getRawModuleData(); 00110 $index = 0; 00111 foreach($rawModuleData as $moduleKey => $moduleData) { 00112 $key = substr($moduleKey, 8); 00113 $num = count($data['root']); 00114 if($moduleData['link'] != 'dummy.php' || ($moduleData['link'] == 'dummy.php' && is_array($moduleData['subitems'])) ) { 00115 $data['root'][$num]['key'] = $key; 00116 $data['root'][$num]['menuState'] = $GLOBALS['BE_USER']->uc['moduleData']['menuState'][$moduleKey]; 00117 $data['root'][$num]['label'] = $moduleData['title']; 00118 $data['root'][$num]['subitems'] = is_array($moduleData['subitems']) ? count($moduleData['subitems']) : 0; 00119 00120 00121 if($moduleData['link'] && $this->linkModules) { 00122 $data['root'][$num]['link'] = 'top.goToModule(\'' . $moduleData['name'] . '\')'; 00123 } 00124 00125 // traverse submodules 00126 if (is_array($moduleData['subitems'])) { 00127 foreach($moduleData['subitems'] as $subKey => $subData) { 00128 $data['root'][$num]['sub'][] = array( 00129 'name' => $subData['name'], 00130 'description' => $subData['description'], 00131 'label' => $subData['title'], 00132 'icon' => $subData['icon']['filename'], 00133 'navframe' => $subData['parentNavigationFrameScript'], 00134 'link' => $subData['link'], 00135 'originalLink' => $subData['originalLink'], 00136 'index' => $index++, 00137 'navigationFrameScript' => $subData['navigationFrameScript'], 00138 'navigationFrameScriptParam' => $subData['navigationFrameScriptParam'], 00139 'navigationComponentId' => $subData['navigationComponentId'], 00140 ); 00141 } 00142 } 00143 } 00144 } 00145 if ($ajaxObj) { 00146 $ajaxObj->setContent($data); 00147 $ajaxObj->setContentFormat('jsonbody'); 00148 00149 } else { 00150 return $data; 00151 } 00152 } 00153 00154 /** 00155 * returns the loaded modules 00156 * 00157 * @return array array of loaded modules 00158 */ 00159 public function getLoadedModules() { 00160 return $this->loadedModules; 00161 } 00162 00163 /** 00164 * saves the menu's toggle state in the backend user's uc 00165 * 00166 * @param array array of parameters from the AJAX interface, currently unused 00167 * @param TYPO3AJAX object of type TYPO3AJAX 00168 * @return void 00169 */ 00170 public function saveMenuState($params, $ajaxObj) { 00171 $menuItem = t3lib_div::_POST('menuid'); 00172 $state = t3lib_div::_POST('state') === 'true' ? 1 : 0; 00173 00174 $GLOBALS['BE_USER']->uc['moduleData']['menuState'][$menuItem] = $state; 00175 $GLOBALS['BE_USER']->writeUC(); 00176 } 00177 00178 00179 /** 00180 * gets the raw module data 00181 * 00182 * @return array multi dimension array with module data 00183 */ 00184 public function getRawModuleData() { 00185 $modules = array(); 00186 00187 // Remove the 'doc' module? 00188 if($GLOBALS['BE_USER']->getTSConfigVal('options.disableDocModuleInAB')) { 00189 unset($this->loadedModules['doc']); 00190 } 00191 00192 foreach($this->loadedModules as $moduleName => $moduleData) { 00193 $moduleLink = ''; 00194 if(!is_array($moduleData['sub'])) { 00195 $moduleLink = $moduleData['script']; 00196 } 00197 $moduleLink = t3lib_div::resolveBackPath($moduleLink); 00198 00199 $moduleKey = 'modmenu_' . $moduleName; 00200 $moduleIcon = $this->getModuleIcon($moduleKey); 00201 00202 $modules[$moduleKey] = array( 00203 'name' => $moduleName, 00204 'title' => $GLOBALS['LANG']->moduleLabels['tabs'][$moduleName . '_tab'], 00205 'onclick' => 'top.goToModule(\''.$moduleName.'\');', 00206 'icon' => $moduleIcon, 00207 'link' => $moduleLink, 00208 'description' => $GLOBALS['LANG']->moduleLabels['labels'][$moduleKey.'label'] 00209 ); 00210 00211 if (!is_array($moduleData['sub']) && $moduleData['script'] != 'dummy.php') { 00212 // Work around for modules with own main entry, but being self the only submodule 00213 $modules[$moduleKey]['subitems'][$moduleKey] = array( 00214 'name' => $moduleName, 00215 'title' => $GLOBALS['LANG']->moduleLabels['tabs'][$moduleName . '_tab'], 00216 'onclick' => 'top.goToModule(\'' . $moduleName . '\');', 00217 'icon' => $this->getModuleIcon($moduleName . '_tab'), 00218 'link' => $moduleLink, 00219 'originalLink' => $moduleLink, 00220 'description' => $GLOBALS['LANG']->moduleLabels['labels'][$moduleKey . 'label'], 00221 'navigationFrameScript' => NULL, 00222 'navigationFrameScriptParam' => NULL, 00223 'navigationComponentId' => NULL, 00224 ); 00225 } else if (is_array($moduleData['sub'])) { 00226 foreach($moduleData['sub'] as $submoduleName => $submoduleData) { 00227 $submoduleLink = t3lib_div::resolveBackPath($submoduleData['script']); 00228 00229 $submoduleKey = $moduleName . '_' . $submoduleName . '_tab'; 00230 $submoduleIcon = $this->getModuleIcon($submoduleKey); 00231 $submoduleDescription = $GLOBALS['LANG']->moduleLabels['labels'][$submoduleKey . 'label']; 00232 00233 $originalLink = $submoduleLink; 00234 00235 $modules[$moduleKey]['subitems'][$submoduleKey] = array( 00236 'name' => $moduleName . '_' . $submoduleName, 00237 'title' => $GLOBALS['LANG']->moduleLabels['tabs'][$submoduleKey], 00238 'onclick' => 'top.goToModule(\'' . $moduleName . '_' . $submoduleName . '\');', 00239 'icon' => $submoduleIcon, 00240 'link' => $submoduleLink, 00241 'originalLink' => $originalLink, 00242 'description' => $submoduleDescription, 00243 'navigationFrameScript' => $submoduleData['navFrameScript'], 00244 'navigationFrameScriptParam' => $submoduleData['navFrameScriptParam'], 00245 'navigationComponentId' => $submoduleData['navigationComponentId'], 00246 ); 00247 00248 if($moduleData['navFrameScript']) { 00249 $modules[$moduleKey]['subitems'][$submoduleKey]['parentNavigationFrameScript'] = $moduleData['navFrameScript']; 00250 } 00251 } 00252 } 00253 } 00254 00255 return $modules; 00256 } 00257 00258 /** 00259 * gets the module icon and its size 00260 * 00261 * @param string module key 00262 * @return array icon data array with 'filename', 'size', and 'html' 00263 */ 00264 protected function getModuleIcon($moduleKey) { 00265 $icon = array( 00266 'filename' => '', 00267 'size' => '', 00268 'title' => '', 00269 'html' => '' 00270 ); 00271 00272 $iconFileRelative = $this->getModuleIconRelative($GLOBALS['LANG']->moduleLabels['tabs_images'][$moduleKey]); 00273 $iconFileAbsolute = $this->getModuleIconAbsolute($GLOBALS['LANG']->moduleLabels['tabs_images'][$moduleKey]); 00274 $iconSizes = @getimagesize($iconFileAbsolute); 00275 $iconTitle = $GLOBALS['LANG']->moduleLabels['tabs'][$moduleKey]; 00276 00277 if(!empty($iconFileRelative)) { 00278 $icon['filename'] = $iconFileRelative; 00279 $icon['size'] = $iconSizes[3]; 00280 $icon['title'] = htmlspecialchars($iconTitle); 00281 $icon['html'] = '<img src="' . $iconFileRelative . '" ' . $iconSizes[3] . 00282 ' title="' . htmlspecialchars($iconTitle) . '" alt="' . htmlspecialchars($iconTitle) . '" />'; 00283 } 00284 00285 return $icon; 00286 } 00287 00288 /** 00289 * Returns the filename readable for the script from PATH_typo3. 00290 * That means absolute names are just returned while relative names are 00291 * prepended with the path pointing back to typo3/ dir 00292 * 00293 * @param string icon filename 00294 * @return string icon filename with absolute path 00295 * @see getModuleIconRelative() 00296 */ 00297 protected function getModuleIconAbsolute($iconFilename) { 00298 00299 if(!t3lib_div::isAbsPath($iconFilename)) { 00300 $iconFilename = $this->backPath . $iconFilename; 00301 } 00302 00303 return $iconFilename; 00304 } 00305 00306 /** 00307 * Returns relative path to the icon filename for use in img-tags 00308 * 00309 * @param string icon filename 00310 * @return string icon filename with relative path 00311 * @see getModuleIconAbsolute() 00312 */ 00313 protected function getModuleIconRelative($iconFilename) { 00314 if (t3lib_div::isAbsPath($iconFilename)) { 00315 $iconFilename = '../' . substr($iconFilename, strlen(PATH_site)); 00316 } 00317 return $this->backPath.$iconFilename; 00318 } 00319 00320 00321 00322 /** 00323 * Appends a '?' if there is none in the string already 00324 * 00325 * @param string Link URL 00326 * @return string link URl appended with ? if there wasn't one 00327 */ 00328 protected function appendQuestionmarkToLink($link) { 00329 if(!strstr($link, '?')) { 00330 $link .= '?'; 00331 } 00332 00333 return $link; 00334 } 00335 00336 /** 00337 * renders the logout button form 00338 * 00339 * @return string html code snippet displaying the logout button 00340 */ 00341 public function renderLogoutButton() { 00342 $buttonLabel = $GLOBALS['BE_USER']->user['ses_backuserid'] ? 'LLL:EXT:lang/locallang_core.php:buttons.exit' : 'LLL:EXT:lang/locallang_core.php:buttons.logout'; 00343 00344 $buttonForm = ' 00345 <form action="logout.php" target="_top"> 00346 <input type="submit" value=" ' . $GLOBALS['LANG']->sL($buttonLabel, 1) . ' " /> 00347 </form>'; 00348 00349 return $buttonForm; 00350 } 00351 00352 /** 00353 * turns linking of modules on or off 00354 * 00355 * @param boolean status for linking modules with a-tags, set to false to turn lining off 00356 */ 00357 public function setLinkModules($linkModules) { 00358 if(!is_bool($linkModules)) { 00359 throw new InvalidArgumentException('parameter $linkModules must be of type bool', 1193326558); 00360 } 00361 00362 $this->linkModules = $linkModules; 00363 } 00364 00365 } 00366 00367 00368 if (defined('TYPO3_MODE') && isset($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.modulemenu.php'])) { 00369 include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['typo3/classes/class.modulemenu.php']); 00370 } 00371 00372 ?>
1.8.0