-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.tx_realurl_configurationService.php
155 lines (136 loc) · 5.83 KB
/
class.tx_realurl_configurationService.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
<?php
/***************************************************************
* Copyright notice
*
* (c) 2009 ([email protected])
* 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.
* A copy is found in the textfile GPL.txt and important notices to the license
* from the author is found in LICENSE.txt distributed with these scripts.
*
*
* 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!
***************************************************************/
require_once(t3lib_extMgm::extPath('realurl') . 'class.tx_realurl_configurationService_exception.php');
class tx_realurl_configurationService {
private $confArray = array();
private $useAutoAdjustRootPid = FALSE;
public function __construct() {
$this->loadRealUrlConfiguration();
}
public function loadRealUrlConfiguration() {
$_realurl_conf = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['realurl']);
// Autoconfiguration
if ($_realurl_conf['enableAutoConf'] && !isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl']) && !@include_once (PATH_site . TX_REALURL_AUTOCONF_FILE) && !isset($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'])) {
require_once (t3lib_extMgm::extPath('realurl', 'class.tx_realurl_autoconfgen.php'));
$_realurl_gen = t3lib_div::makeInstance('tx_realurl_autoconfgen');
$_realurl_gen->generateConfiguration();
unset($_realurl_gen);
@include_once (PATH_site . TX_REALURL_AUTOCONF_FILE);
}
$this->confArray = &$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['realurl'];
}
public function setRealUrlConfiguration(array $conf) {
$this->confArray = $conf;
}
public function getConfigurationForDomain($host = '') {
if ($host == '') {
$host = t3lib_div::getIndpEnv('TYPO3_HOST_ONLY');
}
// First pass, finding configuration OR pointer string:
if (isset($this->confArray[$host])) {
$extConf = $this->confArray[$host];
// If it turned out to be a string pointer, then look up the real config:
while (!is_null($extConf) && is_string($extConf)) {
$extConf = $this->confArray[$this->extConf];
}
if (!is_array($extConf)) {
$extConf = $this->confArray['_DEFAULT'];
if ($this->multidomain && isset($extConf['pagePath']['rootpage_id'])) {
// This can't be right!
unset($extConf['pagePath']['rootpage_id']);
}
}
} else {
if ($this->enableStrictMode && $this->multidomain) {
throw new tx_realurl_configurationService_exception('RealURL strict mode error: ' . 'multidomain configuration detected and domain \'' . $this->host . '\' is not configured for RealURL. Please, fix your RealURL configuration!');
}
$extConf = (array)$this->confArray['_DEFAULT'];
if ($this->multidomain && isset($extConf['pagePath']['rootpage_id']) && $this->enableStrictMode) {
throw new tx_realurl_configurationService_exception('Rootpid configured for _DEFAULT namespace, tis can cause wron cache entries and should be avoided');
}
}
if ($this->useAutoAdjustRootPid) {
unset($extConf['pagePath']['rootpage_id']);
$extConf['pagePath']['rootpage_id'] = $this->findRootPageId($host);
}
/*
* @todo
*
* - do some struct mode checks:
* if (!$this->extConf['pagePath']['rootpage_id']) {
if ($this->enableStrictMode) {
$this->pObj->pageNotFoundAndExit('RealURL strict mode error: ' .
'multidomain configuration without rootpage_id. ' .
'Please, fix your RealURL configuration!');
}
*/
// $GLOBALS['TT']->setTSlogMessage('RealURL warning: rootpage_id was not configured!');
return $extConf;
}
/**
* Attempts to find root page ID for the current host. Processes redirectes as well.
*
* @return int Found root page false if not found
*/
private function findRootPageId($domain = '') {
$rootpage_id = false;
// Search by host
do {
$domain = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid,redirectTo,domainName', 'sys_domain', 'domainName=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($host, 'sys_domain') . ' AND hidden=0');
if (count($domain) > 0) {
if (!$domain[0]['redirectTo']) {
$rootpage_id = intval($domain[0]['pid']);
if ($this->enableDevLog) {
t3lib_div::devLog('Found rootpage_id by domain lookup', 'realurl', 0, array('domain' => $domain[0]['domainName'], 'rootpage_id' => $rootpage_id));
}
break;
} else {
$parts = @parse_url($domain[0]['redirectTo']);
$host = $parts['host'];
}
}
} while (count($domain) > 0);
// If root page id is not found, try other ways. We can do it only
// and only if there are no multiple domains. Otherwise we would
// get a lot of wrong page ids from old root pages, etc.
if (!$rootpage_id && !$this->multidomain) {
// Try by TS template
$rows = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('pid', 'sys_template', 'root=1 AND hidden=0');
if (count($rows) == 1) {
$rootpage_id = $rows[0]['pid'];
if ($this->enableDevLog) {
t3lib_div::devLog('Found rootpage_id by searching sys_template', 'realurl', 0, array('rootpage_id' => $rootpage_id));
}
}
}
return $rootpage_id;
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/realurl/class.tx_realurl_configurationService.php']) {
include_once ($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/realurl/class.tx_realurl_configurationService.php']);
}
?>