BackendConfigurationManager.php 5.82 KB
Newer Older
1
2
<?php
/***************************************************************
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
 *  Copyright notice
 *
 *  (c) 2009 Jochen Rau <jochen.rau@typoplanet.de>
 *  All rights reserved
 *
 *  This script is part of the TYPO3 project. The TYPO3 project is
 *  free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  The GNU General Public License can be found at
 *  http://www.gnu.org/copyleft/gpl.html.
 *
 *  This script is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  This copyright notice MUST APPEAR in all copies of the script!
 ***************************************************************/
24
25
26
27
28
29
30
/**
 * A general purpose configuration manager used in backend mode.
 *
 * @package Extbase
 * @subpackage Configuration
 * @version $ID:$
 */
31
class Tx_Extbase_Configuration_BackendConfigurationManager extends Tx_Extbase_Configuration_AbstractConfigurationManager {
32
33
34
35
36
37
38
39
40

	/**
	 * @var array
	 */
	protected $typoScriptSetupCache = NULL;

	/**
	 * Returns TypoScript Setup array from current Environment.
	 *
41
	 * @return array the raw TypoScript setup
42
	 */
43
	public function getTypoScriptSetup() {
44
45
		if ($this->typoScriptSetupCache === NULL) {
			$template = t3lib_div::makeInstance('t3lib_TStemplate');
46
			// do not log time-performance information
47
48
			$template->tt_track = 0;
			$template->init();
49
			// Get the root line
50
51
52
53
54
			$rootline = array();
			$pageId = $this->getCurrentPageId();
			if ($pageId > 0) {
				/** @var $sysPage t3lib_pageSelect */
				$sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
55
				// Get the rootline for the current page
56
57
				$rootline = $sysPage->getRootLine($this->getCurrentPageId(), '', TRUE);
			}
58
			// This generates the constants/config + hierarchy info for the template.
59
60
61
62
63
64
65
			$template->runThroughTemplates($rootline, 0);
			$template->generateConfig();
			$this->typoScriptSetupCache = $template->setup;
		}
		return $this->typoScriptSetupCache;
	}

66
67
68
69
70
71
72
73
	/**
	 * Returns the TypoScript configuration found in module.tx_yourextension_yourmodule
	 * merged with the global configuration of your extension from module.tx_yourextension
	 *
	 * @param string $extensionName
	 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
	 * @return array
	 */
74
	protected function getPluginConfiguration($extensionName, $pluginName = NULL) {
75
76
		$setup = $this->getTypoScriptSetup();
		$pluginConfiguration = array();
77
78
		if (is_array($setup['module.'][('tx_' . strtolower($extensionName)) . '.'])) {
			$pluginConfiguration = $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.'][('tx_' . strtolower($extensionName)) . '.']);
79
		}
80
		if ($pluginName !== NULL) {
81
82
83
			$pluginSignature = strtolower(($extensionName . '_') . $pluginName);
			if (is_array($setup['module.'][('tx_' . $pluginSignature) . '.'])) {
				$pluginConfiguration = t3lib_div::array_merge_recursive_overrule($pluginConfiguration, $this->typoScriptService->convertTypoScriptArrayToPlainArray($setup['module.'][('tx_' . $pluginSignature) . '.']));
84
			}
85
86
87
88
89
90
91
		}
		return $pluginConfiguration;
	}

	/**
	 * Returns the configured controller/action pairs of the specified module in the format
	 * array(
92
93
	 * 'Controller1' => array('action1', 'action2'),
	 * 'Controller2' => array('action3', 'action4')
94
95
96
97
98
99
100
101
102
103
104
105
106
107
	 * )
	 *
	 * @param string $extensionName
	 * @param string $pluginName in BE mode this is actually the module signature. But we're using it just like the plugin name in FE
	 * @return array
	 */
	protected function getSwitchableControllerActions($extensionName, $pluginName) {
		$switchableControllerActions = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['extbase']['extensions'][$extensionName]['modules'][$pluginName]['controllers'];
		if (!is_array($switchableControllerActions)) {
			$switchableControllerActions = array();
		}
		return $switchableControllerActions;
	}

108
109
110
111
112
113
114
	/**
	 * Returns the page uid of the current page.
	 * If no page is selected, we'll return the uid of the first root page.
	 *
	 * @return integer current page id. If no page is selected current root page id is returned
	 */
	protected function getCurrentPageId() {
115
		$pageId = (int) t3lib_div::_GP('id');
116
117
118
		if ($pageId > 0) {
			return $pageId;
		}
119
		// get current site root
120
121
122
123
		$rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
		if (count($rootPages) > 0) {
			return $rootPages[0]['uid'];
		}
124
		// get root template
125
126
127
128
		$rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
		if (count($rootTemplates) > 0) {
			return $rootTemplates[0]['pid'];
		}
129
		// fallback
130
131
		return self::DEFAULT_BACKEND_STORAGE_PID;
	}
132

133
134
135
136
137
138
139
140
141
	/**
	 * Returns the default backend storage pid
	 *
	 * @return string
	 */
	public function getDefaultBackendStoragePid() {
		return $this->getCurrentPageId();
	}

142
	/**
143
144
145
146
	 * We need to set some default request handler if the framework configuration
	 * could not be loaded; to make sure Extbase also works in Backend modules
	 * in all contexts.
	 *
147
	 * @param array $frameworkConfiguration
148
149
150
	 * @return array
	 */
	protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration) {
151
152
153
154
155
156
		if (!isset($frameworkConfiguration['mvc']['requestHandlers'])) {
			$frameworkConfiguration['mvc']['requestHandlers'] = array(
				'Tx_Extbase_MVC_Web_FrontendRequestHandler' => 'Tx_Extbase_MVC_Web_FrontendRequestHandler',
				'Tx_Extbase_MVC_Web_BackendRequestHandler' => 'Tx_Extbase_MVC_Web_BackendRequestHandler'
			);
		}
157
158
		return $frameworkConfiguration;
	}
159

160
}
161

162
?>