This repository has been archived by the owner on May 7, 2022. It is now read-only.
forked from fbrnc/Realurl
-
Notifications
You must be signed in to change notification settings - Fork 3
/
class.tx_realurl_autoconfgen.php
255 lines (236 loc) · 7.88 KB
/
class.tx_realurl_autoconfgen.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
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<?php
/***************************************************************
* Copyright notice
*
* (c) 2007-2010 Dmitry Dulepov ([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!
***************************************************************/
/**
* Class for translating page ids to/from path strings (Speaking URLs)
*
* $Id: class.tx_realurl_advanced.php 5893 2007-07-09 13:41:07Z liels_bugs $
*
* @author Dmitry Dulepov <[email protected]>
*/
/**
* [CLASS/FUNCTION INDEX of SCRIPT]
*
*
*
* 57: class tx_realurl_autoconfgen
* 68: function generateConfiguration()
* 89: function doGenerateConfiguration(&$fd)
* 151: function getTemplate()
* 209: function addLanguages(&$conf)
*
* TOTAL FUNCTIONS: 4
* (This index is automatically created/updated by the extension "extdeveval")
*
*/
/**
* Class for generating of automatic RealURL configuration
*
* @author Dmitry Dulepov <[email protected]>
* @package realurl
* @subpackage tx_realurl
*/
class tx_realurl_autoconfgen {
/* @var $db t3lib_DB */
var $db;
/** @var bool */
var $hasStaticInfoTables;
/** @var tx_realurl_apiwrapper */
protected $apiWrapper;
/**
* Initializes the class.
*/
public function __construct() {
$this->apiWrapper = tx_realurl_apiwrapper::getInstance();
$this->db = $this->apiWrapper->getDatabaseConnection();
$this->hasStaticInfoTables = $this->apiWrapper->isExtLoaded('static_info_tables');
}
/**
* 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 . TX_REALURL_AUTOCONF_FILE;
$lockObject = $this->apiWrapper->getLockObject($fileName);
$fd = @fopen($fileName, 'a+');
if ($fd) {
// Check size
fseek($fd, 0, SEEK_END);
if (ftell($fd) == 0) {
$this->doGenerateConfiguration($fd);
}
fclose($fd);
$this->apiWrapper->fixPermissions($fileName);
}
$lockObject->release();
}
/**
* Performs actual generation.
*
* @param resource $fd FIle descriptor to write to
* @return void
*/
protected function doGenerateConfiguration(&$fd) {
$conf = array();
$template = $this->getTemplate();
// Find all domains
$domains = $this->db->exec_SELECTgetRows('pid,domainName,redirectTo', 'sys_domain', 'hidden=0',
'', '', '', 'domainName');
if (count($domains) == 0) {
$conf['_DEFAULT'] = $template;
$rows = $this->db->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/realurl/class.tx_realurl_autoconfgen.php']['postProcessConfiguration'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['postProcessConfiguration'] as $userFunc) {
$parameters = array(
'config' => &$conf,
);
$this->apiWrapper->callUserFunction($userFunc, $parameters, $this);
}
}
$realurlConf = @unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['realurl']);
if ($realurlConf['autoConfFormat'] == 0) {
fwrite($fd, '<' . '?php' . chr(10) . '$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'realurl\']=' .
'unserialize(\'' . str_replace('\'', '\\\'', serialize($conf)) . '\');' . chr(10)
);
}
else {
fwrite($fd, '<' . '?php' . chr(10) . '$GLOBALS[\'TYPO3_CONF_VARS\'][\'EXTCONF\'][\'realurl\']=' .
var_export($conf, true) . ';' . 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' => $this->apiWrapper->getIndpEnv('TYPO3_SITE_PATH')
),
'pagePath' => array(
'type' => 'user',
'userFunc' => 'EXT:realurl/class.tx_realurl_advanced.php:&tx_realurl_advanced->main',
'spaceCharacter' => '-',
'languageGetVar' => 'L',
),
'fileName' => array(
'defaultToHTMLsuffixOnPrev' => 0,
'acceptHTMLsuffix' => 1,
)
);
// Add print feature if TemplaVoila is not loaded
if (!$this->apiWrapper->isExtLoaded('templavoila')) {
$confTemplate['fileName']['index']['print'] = array(
'keyValues' => array(
'type' => 98,
)
);
}
// Add respectSimulateStaticURLs if SimulateStatic is loaded
if($this->apiWrapper->isExtLoaded('simulatestatic')) {
$confTemplate['init']['respectSimulateStaticURLs'] = true;
}
$this->addLanguages($confTemplate);
// Add from extensions
if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/realurl/class.tx_realurl_autoconfgen.php']['extensionConfiguration'] as $extKey => $userFunc) {
$params = array(
'config' => $confTemplate,
'extKey' => $extKey
);
$var = $this->apiWrapper->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->db->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->db->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'];
}
}
}
}
if (defined('TYPO3_MODE') && $GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/realurl/class.tx_realurl_autoconfgen.php']) {
/** @noinspection PhpIncludeInspection */
include_once($GLOBALS['TYPO3_CONF_VARS'][TYPO3_MODE]['XCLASS']['ext/realurl/class.tx_realurl_autoconfgen.php']);
}