-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathConfigurationGenerator.php
More file actions
236 lines (217 loc) · 9.14 KB
/
Copy pathConfigurationGenerator.php
File metadata and controls
236 lines (217 loc) · 9.14 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
<?php
namespace Nimut\Hellurl\Configuration;
/***************************************************************
* Copyright notice
*
* (c) 2017 Nicole Cordes (typo3@cordes.co)
* (c) 2007-2010 Dmitry Dulepov (dmitry@typo3.org)
* 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!
***************************************************************/
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Class for generating of automatic HellUrl configuration
*/
class ConfigurationGenerator
{
const AUTOCONFIGURTION_FILE = 'typo3conf/hellurl_autoconf.php';
/**
* @var \TYPO3\CMS\Core\Database\DatabaseConnection
*/
protected $databaseConnection;
/**
* @var bool
*/
protected $hasStaticInfoTables;
/**
* Generates configuration. Locks configuration file for exclusive access to avoid collisions. Will not be stabe on Windows.
*
* @return void
*/
public function generateConfiguration()
{
$fileName = PATH_site . self::AUTOCONFIGURTION_FILE;
if (class_exists('TYPO3\\CMS\\Core\\Locking\\LockFactory')) {
$lockFactory = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Locking\\LockFactory');
$capabilities = constant('TYPO3\\CMS\\Core\\Locking\\LockingStrategyInterface::LOCK_CAPABILITY_EXCLUSIVE')
| constant('TYPO3\\CMS\\Core\\Locking\\LockingStrategyInterface::LOCK_CAPABILITY_NOBLOCK');
$lockObject = $lockFactory->createLocker(
$fileName,
$capabilities
);
$lockObject->acquire();
} else {
// @deprecated since 7.6, will be removed once 6.2 support is removed
$lockObject = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Locking\\Locker', $fileName, $GLOBALS['TYPO3_CONF_VARS']['SYS']['lockingMode']);
$lockObject->setEnableLogging(false);
$lockObject->acquireExclusiveLock();
}
$fd = @fopen($fileName, 'a+');
if ($fd) {
// Check size
fseek($fd, 0, SEEK_END);
if (ftell($fd) == 0) {
$this->doGenerateConfiguration($fd);
}
fclose($fd);
\TYPO3\CMS\Core\Utility\GeneralUtility::fixPermissions($fileName);
}
$lockObject->release();
}
/**
* Performs actual generation.
*
* @param resource $fd FIle descriptor to write to
*
* @return void
*/
protected function doGenerateConfiguration(&$fd)
{
$this->databaseConnection = $GLOBALS['TYPO3_DB'];
$this->hasStaticInfoTables = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('static_info_tables');
$conf = array();
$template = $this->getTemplate();
// Find all domains
$domains = $this->databaseConnection->exec_SELECTgetRows('pid,domainName,redirectTo', 'sys_domain', 'hidden=0',
'', '', '', 'domainName');
if (count($domains) == 0) {
$conf['_DEFAULT'] = $template;
$rows = $this->databaseConnection->exec_SELECTgetRows('uid', 'pages',
'deleted=0 AND hidden=0 AND is_siteroot=1', '', '', '1');
if (count($rows) > 0) {
$conf['_DEFAULT']['pagePath']['rootpage_id'] = $rows[0]['uid'];
}
} else {
foreach ($domains as $domain) {
if ($domain['redirectTo'] != '') {
// Redirects to another domain, see if we can make a shortcut
$parts = parse_url($domain['redirectTo']);
if (isset($domains[$parts['host']]) && ($domains['path'] == '/' || $domains['path'] == '')) {
// Make a shortcut
if ($conf[$parts['host']] != $domain['domainName']) {
// Here if there were no redirect from this domain to source domain
$conf[$domain['domainName']] = $parts['host'];
}
continue;
}
}
// Make entry
$conf[$domain['domainName']] = $template;
$conf[$domain['domainName']]['pagePath']['rootpage_id'] = $domain['pid'];
}
}
// Post process generated configuration
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/hellurl/class.tx_hellurl_autoconfgen.php']['postProcessConfiguration'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/hellurl/class.tx_hellurl_autoconfgen.php']['postProcessConfiguration'] as $userFunc) {
$parameters = array(
'config' => &$conf,
);
\TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($userFunc, $parameters, $this);
}
}
fwrite($fd, '<' . '?php' . LF . '$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'hellurl\']=' .
\TYPO3\CMS\Core\Utility\ArrayUtility::arrayExport($conf) . ';' . chr(10)
);
}
/**
* Creates common configuration template.
*
* @return array Template
*/
protected function getTemplate()
{
$confTemplate = array(
'init' => array(
'enableCHashCache' => true,
'appendMissingSlash' => 'ifNotFile,redirect',
'adminJumpToBackend' => true,
'enableUrlDecodeCache' => true,
'enableUrlEncodeCache' => true,
'emptyUrlReturnValue' => \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'),
),
'pagePath' => array(
'type' => 'user',
'userFunc' => 'Nimut\\Hellurl\\UriGeneratorAndResolver->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
),
'fileName' => array(
'defaultToHTMLsuffixOnPrev' => 0,
'acceptHTMLsuffix' => 1,
),
);
// Add print feature if TemplaVoila is not loaded
if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('templavoila')) {
$confTemplate['fileName']['index']['print'] = array(
'keyValues' => array(
'type' => 98,
),
);
}
// Add respectSimulateStaticURLs if SimulateStatic is loaded
if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('simulatestatic')) {
$confTemplate['init']['respectSimulateStaticURLs'] = true;
}
$this->addLanguages($confTemplate);
// Add from extensions
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/hellurl/class.tx_hellurl_autoconfgen.php']['extensionConfiguration'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/hellurl/class.tx_hellurl_autoconfgen.php']['extensionConfiguration'] as $extKey => $userFunc) {
$params = array(
'config' => $confTemplate,
'extKey' => $extKey,
);
$var = \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($userFunc, $params, $this);
if ($var) {
$confTemplate = $var;
}
}
}
return $confTemplate;
}
/**
* Adds languages to configuration
*
* @param array $conf Configuration (passed as reference)
*
* @return void
*/
protected function addLanguages(&$conf)
{
if ($this->hasStaticInfoTables) {
$languages = $this->databaseConnection->exec_SELECTgetRows('t1.uid AS uid,t2.lg_iso_2 AS lg_iso_2', 'sys_language t1, static_languages t2', 't2.uid=t1.static_lang_isocode AND t1.hidden=0');
} else {
$languages = $this->databaseConnection->exec_SELECTgetRows('t1.uid AS uid,t1.uid AS lg_iso_2', 'sys_language t1', 't1.hidden=0');
}
if (count($languages) > 0) {
$conf['preVars'] = array(
0 => array(
'GETvar' => 'L',
'valueMap' => array(
),
'noMatch' => 'bypass',
),
);
foreach ($languages as $lang) {
$conf['preVars'][0]['valueMap'][strtolower($lang['lg_iso_2'])] = $lang['uid'];
}
}
}
}