d17b855ad7f0d4396a59eb4ec6075dee74e5cc12
[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 /**
26 * A general purpose configuration manager used in backend mode.
27 *
28 * @package Extbase
29 * @subpackage Configuration
30 * @version $ID:$
31 */
32 class Tx_Extbase_Configuration_BackendConfigurationManager extends Tx_Extbase_Configuration_AbstractConfigurationManager {
33
34 /**
35 * @var array
36 */
37 protected $typoScriptSetupCache = NULL;
38
39 /**
40 * Returns TypoScript Setup array from current Environment.
41 *
42 * @return array the raw TypoScript setup
43 */
44 public function getTypoScriptSetup() {
45 if ($this->typoScriptSetupCache === NULL) {
46 $template = t3lib_div::makeInstance('t3lib_TStemplate');
47 // do not log time-performance information
48 $template->tt_track = 0;
49 $template->init();
50 // Get the root line
51 $sysPage = t3lib_div::makeInstance('t3lib_pageSelect');
52 // get the rootline for the current page
53 $rootline = $sysPage->getRootLine($this->getCurrentPageId());
54 // This generates the constants/config + hierarchy info for the template.
55 $template->runThroughTemplates($rootline, 0);
56 $template->generateConfig();
57 $this->typoScriptSetupCache = $template->setup;
58 }
59 return $this->typoScriptSetupCache;
60 }
61
62 /**
63 * Returns the page uid of the current page.
64 * If no page is selected, we'll return the uid of the first root page.
65 *
66 * @return integer current page id. If no page is selected current root page id is returned
67 */
68 protected function getCurrentPageId() {
69 $pageId = (integer)t3lib_div::_GP('id');
70 if ($pageId > 0) {
71 return $pageId;
72 }
73
74 // get root template
75 $rootTemplates = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'deleted=0 AND hidden=0 AND root=1', '', '', '1');
76 if (count($rootTemplates) > 0) {
77 return $rootTemplates[0]['pid'];
78 }
79
80 // get current site root
81 $rootPages = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
82 if (count($rootPages) > 0) {
83 return $rootPages[0]['uid'];
84 }
85
86 // fallback
87 return self::DEFAULT_BACKEND_STORAGE_PID;
88 }
89
90 /**
91 * We do not want to override anything in the backend.
92 * @return array
93 */
94 protected function getContextSpecificFrameworkConfiguration(array $frameworkConfiguration) {
95 return $frameworkConfiguration;
96 }
97 }
98 ?>