TYPO3 API  SVNRelease
BackendConfigurationManager.php
Go to the documentation of this file.
00001 <?php
00002 /***************************************************************
00003 *  Copyright notice
00004 *
00005 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
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 *
00017 *  This script is distributed in the hope that it will be useful,
00018 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 *  GNU General Public License for more details.
00021 *
00022 *  This copyright notice MUST APPEAR in all copies of the script!
00023 ***************************************************************/
00024 
00025 /**
00026  * A general purpose configuration manager used in backend mode.
00027  *
00028  * @package Extbase
00029  * @subpackage Configuration
00030  * @version $ID:$
00031  */
00032 class Tx_Extbase_Configuration_BackendConfigurationManager extends Tx_Extbase_Configuration_AbstractConfigurationManager {
00033 
00034     /**
00035      * @var array
00036      */
00037     protected $typoScriptSetupCache = NULL;
00038 
00039     /**
00040      * Returns TypoScript Setup array from current Environment.
00041      *
00042      * @return array the raw TypoScript setup
00043      */
00044     public function getTypoScriptSetup() {
00045         if ($this->typoScriptSetupCache === NULL) {
00046             $template = t3lib_div::makeInstance('t3lib_TStemplate');
00047                 // do not log time-performance information
00048             $template->tt_track = 0;
00049             $template->init();
00050                 // Get the root line
00051             $sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
00052                 // get the rootline for the current page
00053             $rootline = $sysPage->getRootLine($this->getCurrentPageId());
00054                 // This generates the constants/config + hierarchy info for the template.
00055             $template->runThroughTemplates($rootline, 0);
00056             $template->generateConfig();
00057             $this->typoScriptSetupCache = $template->setup;
00058         }
00059         return $this->typoScriptSetupCache;
00060     }
00061 
00062     /**
00063      * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
00064      * merged with the global configuration of your extension from module.tx_yourextension
00065      *
00066      * @param string $extensionName
00067      * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
00068      * @return array
00069      */
00070     protected function getPluginConfiguration($extensionName, $pluginName) {
00071         $setup = $this->getTypoScriptSetup();
00072         $pluginConfiguration = array();
00073         if (is_array($setup['module.']['tx_' . strtolower($extensionName) . '.'])) {
00074             $pluginConfiguration = Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . strtolower($extensionName) . '.']);
00075         }
00076         $pluginSignature = strtolower($extensionName . '_' . $pluginName);
00077         if (is_array($setup['module.']['tx_' . $pluginSignature . '.'])) {
00078             $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, Tx_Extbase_Utility_TypoScript::convertTypoScriptArrayToPlainArray($setup['module.']['tx_' . $pluginSignature . '.']));
00079         }
00080         return $pluginConfiguration;
00081     }
00082 
00083     /**
00084      * Returns the configured controller/action pairs of the specified module in the format
00085      * array(
00086      *  'Controller1' => array('action1', 'action2'),
00087      *  'Controller2' => array('action3', 'action4')
00088      * )
00089      *
00090      * @param string $extensionName
00091      * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
00092      * @return array
00093      */
00094     protected function getSwitchableControllerActions($extensionName, $pluginName) {
00095         $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
00096         if (!is_array($switchableControllerActions)) {
00097             $switchableControllerActions = array();
00098         }
00099         return $switchableControllerActions;
00100     }
00101 
00102     /**
00103      * Returns the page uid of the current page.
00104      * If no page is selected, we'll return the uid of the first root page.
00105      *
00106      * @return integer current page id. If no page is selected current root page id is returned
00107      */
00108     protected function getCurrentPageId() {
00109         $pageId = (integer)t3lib_div::_GP('id');
00110         if ($pageId > 0) {
00111             return $pageId;
00112         }
00113 
00114             // get current site root
00115         $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
00116         if (count($rootPages) > 0) {
00117             return $rootPages[0]['uid'];
00118         }
00119 
00120             // get root template
00121         $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
00122         if (count($rootTemplates) > 0) {
00123             return $rootTemplates[0]['pid'];
00124         }
00125 
00126             // fallback
00127         return self::DEFAULT_BACKEND_STORAGE_PID;
00128     }
00129 
00130     /**
00131      * We need to set some default request handler if the framework configuration
00132      * could not be loaded; to make sure Extbase also works in Backend modules
00133      * in all contexts.
00134      *
00135      * @return array
00136      */
00137     protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration) {
00138         if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
00139             $frameworkConfiguration['mvc']['requestHandlers'] = array(
00140                 'Tx_Extbase_MVC_Web_FrontendRequestHandler' => 'Tx_Extbase_MVC_Web_FrontendRequestHandler',
00141                 'Tx_Extbase_MVC_Web_BackendRequestHandler' => 'Tx_Extbase_MVC_Web_BackendRequestHandler'
00142             );
00143         }
00144         return $frameworkConfiguration;
00145     }
00146 }
00147 ?>