68946383113c93a80330ba9a9db48624eb32f55c
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Configuration / BackendConfigurationManager.php
1 <?php
2 /***************************************************************
3 * Copyright notice
4 *
5 * (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
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 *
17 * This script is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * This copyright notice MUST APPEAR in all copies of the script!
23 ***************************************************************/
24 /**
25 * A general purpose configuration manager used in backend mode.
26 *
27 * @package Extbase
28 * @subpackage Configuration
29 * @version $ID:$
30 */
31 class Tx_Extbase_Configuration_BackendConfigurationManager extends Tx_Extbase_Configuration_AbstractConfigurationManager {
32
33 /**
34 * @var array
35 */
36 protected $typoScriptSetupCache = NULL;
37
38 /**
39 * Returns TypoScript Setup array from current Environment.
40 *
41 * @return array the raw TypoScript setup
42 */
43 public function getTypoScriptSetup() {
44 if ($this->typoScriptSetupCache === NULL) {
45 $template = t3lib_div::makeInstance('t3lib_TStemplate');
46 // do not log time-performance information
47 $template->tt_track = 0;
48 $template->init();
49 // Get the root line
50 $rootline = array();
51 $pageId = $this->getCurrentPageId();
52 if ($pageId > 0) {
53 /** @var $sysPage t3lib_pageSelect */
54 $sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
55 // Get the rootline for the current page
56 $rootline = $sysPage->getRootLine($this->getCurrentPageId(), '', TRUE);
57 }
58 // This generates the constants/config + hierarchy info for the template.
59 $template->runThroughTemplates($rootline, 0);
60 $template->generateConfig();
61 $this->typoScriptSetupCache = $template->setup;
62 }
63 return $this->typoScriptSetupCache;
64 }
65
66 /**
67 * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
68 * merged with the global configuration of your extension from module.tx_yourextension
69 *
70 * @param string $extensionName
71 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
72 * @return array
73 */
74 protected function getPluginConfiguration($extensionName, $pluginName = NULL) {
75 $setup = $this->getTypoScriptSetup();
76 $pluginConfiguration = array();
77 if (is_array($setup['module.'][('tx_' . strtolower($extensionName)) . '.'])) {
78 $pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.'][('tx_' . strtolower($extensionName)) . '.']);
79 }
80 if ($pluginName !== NULL) {
81 $pluginSignature = strtolower(($extensionName . '_') . $pluginName);
82 if (is_array($setup['module.'][('tx_' . $pluginSignature) . '.'])) {
83 $pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.'][('tx_' . $pluginSignature) . '.']));
84 }
85 }
86 return $pluginConfiguration;
87 }
88
89 /**
90 * Returns the configured controller/action pairs of the specified module in the format
91 * array(
92 * 'Controller1' => array('action1', 'action2'),
93 * 'Controller2' => array('action3', 'action4')
94 * )
95 *
96 * @param string $extensionName
97 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
98 * @return array
99 */
100 protected function getSwitchableControllerActions($extensionName, $pluginName) {
101 $switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
102 if (!is_array($switchableControllerActions)) {
103 $switchableControllerActions = array();
104 }
105 return $switchableControllerActions;
106 }
107
108 /**
109 * Returns the page uid of the current page.
110 * If no page is selected, we'll return the uid of the first root page.
111 *
112 * @return integer current page id. If no page is selected current root page id is returned
113 */
114 protected function getCurrentPageId() {
115 $pageId = (int) t3lib_div::_GP('id');
116 if ($pageId > 0) {
117 return $pageId;
118 }
119 // get current site root
120 $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
121 if (count($rootPages) > 0) {
122 return $rootPages[0]['uid'];
123 }
124 // get root template
125 $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
126 if (count($rootTemplates) > 0) {
127 return $rootTemplates[0]['pid'];
128 }
129 // fallback
130 return self::DEFAULT_BACKEND_STORAGE_PID;
131 }
132
133 /**
134 * Returns the default backend storage pid
135 *
136 * @return string
137 */
138 public function getDefaultBackendStoragePid() {
139 return $this->getCurrentPageId();
140 }
141
142 /**
143 * We need to set some default request handler if the framework configuration
144 * could not be loaded; to make sure Extbase also works in Backend modules
145 * in all contexts.
146 *
147 * @param array $frameworkConfiguration
148 * @return array
149 */
150 protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration) {
151 if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
152 $frameworkConfiguration['mvc']['requestHandlers'] = array(
153 'Tx_Extbase_MVC_Web_FrontendRequestHandler' => 'Tx_Extbase_MVC_Web_FrontendRequestHandler',
154 'Tx_Extbase_MVC_Web_BackendRequestHandler' => 'Tx_Extbase_MVC_Web_BackendRequestHandler'
155 );
156 }
157 return $frameworkConfiguration;
158 }
159
160 }
161
162 ?>