1
|
|
|
<?php |
2
|
|
|
namespace ApacheSolrForTypo3\Solr; |
3
|
|
|
|
4
|
|
|
/*************************************************************** |
5
|
|
|
* Copyright notice |
6
|
|
|
* |
7
|
|
|
* (c) 2009-2015 Ingo Renner <[email protected]> |
8
|
|
|
* All rights reserved |
9
|
|
|
* |
10
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
11
|
|
|
* free software; you can redistribute it and/or modify |
12
|
|
|
* it under the terms of the GNU General Public License as published by |
13
|
|
|
* the Free Software Foundation; either version 2 of the License, or |
14
|
|
|
* (at your option) any later version. |
15
|
|
|
* |
16
|
|
|
* The GNU General Public License can be found at |
17
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
18
|
|
|
* |
19
|
|
|
* This script is distributed in the hope that it will be useful, |
20
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
21
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22
|
|
|
* GNU General Public License for more details. |
23
|
|
|
* |
24
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
25
|
|
|
***************************************************************/ |
26
|
|
|
|
27
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Index\Queue\RecordMonitor\Helper\RootPageResolver; |
28
|
|
|
use ApacheSolrForTypo3\Solr\Domain\Site\SiteHashService; |
29
|
|
|
use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache; |
30
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager; |
31
|
|
|
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration; |
32
|
|
|
use ApacheSolrForTypo3\Solr\System\DateTime\FormatService; |
33
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
34
|
|
|
use TYPO3\CMS\Core\TimeTracker\NullTimeTracker; |
35
|
|
|
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService; |
36
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
37
|
|
|
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; |
38
|
|
|
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController; |
39
|
|
|
use TYPO3\CMS\Frontend\Page\PageRepository; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Utility class for tx_solr |
43
|
|
|
* |
44
|
|
|
* @author Ingo Renner <[email protected]> |
45
|
|
|
*/ |
46
|
|
|
class Util |
47
|
|
|
{ |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Generates a document id for documents representing page records. |
51
|
|
|
* |
52
|
|
|
* @param int $uid The page's uid |
53
|
|
|
* @param int $typeNum The page's typeNum |
54
|
|
|
* @param int $language the language id, defaults to 0 |
55
|
|
|
* @param string $accessGroups comma separated list of uids of groups that have access to that page |
56
|
|
|
* @param string $mountPointParameter The mount point parameter that is used to access the page. |
57
|
|
|
* @return string The document id for that page |
58
|
|
|
*/ |
59
|
42 |
|
public static function getPageDocumentId( |
60
|
|
|
$uid, |
61
|
|
|
$typeNum = 0, |
62
|
|
|
$language = 0, |
63
|
|
|
$accessGroups = '0,-1', |
64
|
|
|
$mountPointParameter = '' |
65
|
|
|
) { |
66
|
42 |
|
$additionalParameters = $typeNum . '/' . $language . '/' . $accessGroups; |
67
|
|
|
|
68
|
42 |
|
if ((string)$mountPointParameter !== '') { |
69
|
|
|
$additionalParameters = $mountPointParameter . '/' . $additionalParameters; |
70
|
|
|
} |
71
|
|
|
|
72
|
42 |
|
$documentId = self::getDocumentId( |
73
|
42 |
|
'pages', |
74
|
|
|
$uid, |
75
|
|
|
$uid, |
76
|
|
|
$additionalParameters |
77
|
|
|
); |
78
|
|
|
|
79
|
42 |
|
return $documentId; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* Generates a document id in the form $siteHash/$type/$uid. |
84
|
|
|
* |
85
|
|
|
* @param string $table The records table name |
86
|
|
|
* @param int $pid The record's pid |
87
|
|
|
* @param int $uid The record's uid |
88
|
|
|
* @param string $additionalIdParameters Additional ID parameters |
89
|
|
|
* @return string A document id |
90
|
|
|
*/ |
91
|
53 |
|
public static function getDocumentId( |
92
|
|
|
$table, |
93
|
|
|
$pid, |
94
|
|
|
$uid, |
95
|
|
|
$additionalIdParameters = '' |
96
|
|
|
) { |
97
|
53 |
|
$siteHash = Site::getSiteByPageId($pid)->getSiteHash(); |
98
|
|
|
|
99
|
53 |
|
$documentId = $siteHash . '/' . $table . '/' . $uid; |
100
|
53 |
|
if (!empty($additionalIdParameters)) { |
101
|
42 |
|
$documentId .= '/' . $additionalIdParameters; |
102
|
|
|
} |
103
|
|
|
|
104
|
53 |
|
return $documentId; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Converts a date from unix timestamp to ISO 8601 format. |
109
|
|
|
* |
110
|
|
|
* @param int $timestamp unix timestamp |
111
|
|
|
* @return string the date in ISO 8601 format |
112
|
|
|
* @deprecated since 6.1 will be removed in 7.0 |
113
|
|
|
*/ |
114
|
|
|
public static function timestampToIso($timestamp) |
115
|
|
|
{ |
116
|
|
|
GeneralUtility::logDeprecatedFunction(); |
117
|
|
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
118
|
|
|
|
119
|
|
|
return $formatService->timestampToIso($timestamp); |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Converts a date from ISO 8601 format to unix timestamp. |
124
|
|
|
* |
125
|
|
|
* @param string $isoTime date in ISO 8601 format |
126
|
|
|
* @return int unix timestamp |
127
|
|
|
* @deprecated since 6.1 will be removed in 7.0 |
128
|
|
|
*/ |
129
|
|
|
public static function isoToTimestamp($isoTime) |
130
|
|
|
{ |
131
|
|
|
GeneralUtility::logDeprecatedFunction(); |
132
|
|
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
133
|
|
|
|
134
|
|
|
return $formatService->isoToTimestamp($isoTime); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
/** |
138
|
|
|
* Converts a date from unix timestamp to ISO 8601 format in UTC timezone. |
139
|
|
|
* |
140
|
|
|
* @param int $timestamp unix timestamp |
141
|
|
|
* @return string the date in ISO 8601 format |
142
|
|
|
* @deprecated since 6.1 will be removed in 7.0 |
143
|
|
|
*/ |
144
|
|
|
public static function timestampToUtcIso($timestamp) |
145
|
|
|
{ |
146
|
|
|
GeneralUtility::logDeprecatedFunction(); |
147
|
|
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
148
|
|
|
|
149
|
|
|
return $formatService->timestampToUtcIso($timestamp); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* Converts a date from ISO 8601 format in UTC timezone to unix timestamp. |
154
|
|
|
* |
155
|
|
|
* @param string $isoTime date in ISO 8601 format |
156
|
|
|
* @return int unix timestamp |
157
|
|
|
* @deprecated since 6.1 will be removed in 7.0 |
158
|
|
|
*/ |
159
|
|
|
public static function utcIsoToTimestamp($isoTime) |
160
|
|
|
{ |
161
|
|
|
GeneralUtility::logDeprecatedFunction(); |
162
|
|
|
$formatService = GeneralUtility::makeInstance(FormatService::class); |
163
|
|
|
|
164
|
|
|
return $formatService->utcIsoToTimestamp($isoTime); |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Returns given word as CamelCased. |
169
|
|
|
* |
170
|
|
|
* Converts a word like "send_email" to "SendEmail". It |
171
|
|
|
* will remove non alphanumeric characters from the word, so |
172
|
|
|
* "who's online" will be converted to "WhoSOnline" |
173
|
|
|
* |
174
|
|
|
* @param string $word Word to convert to camel case |
175
|
|
|
* @return string UpperCamelCasedWord |
176
|
|
|
*/ |
177
|
|
|
public static function camelize($word) |
178
|
|
|
{ |
179
|
|
|
return str_replace(' ', '', |
180
|
|
|
ucwords(preg_replace('![^A-Z^a-z^0-9]+!', ' ', $word))); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* Returns a given CamelCasedString as an lowercase string with underscores. |
185
|
|
|
* Example: Converts BlogExample to blog_example, and minimalValue to minimal_value |
186
|
|
|
* |
187
|
|
|
* @param string $string String to be converted to lowercase underscore |
188
|
|
|
* @return string lowercase_and_underscored_string |
189
|
|
|
*/ |
190
|
|
|
public static function camelCaseToLowerCaseUnderscored($string) |
191
|
|
|
{ |
192
|
|
|
return strtolower(preg_replace('/(?<=\w)([A-Z])/', '_\\1', $string)); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Returns a given string with underscores as UpperCamelCase. |
197
|
|
|
* Example: Converts blog_example to BlogExample |
198
|
|
|
* |
199
|
|
|
* @param string $string String to be converted to camel case |
200
|
|
|
* @return string UpperCamelCasedWord |
201
|
|
|
*/ |
202
|
26 |
|
public static function underscoredToUpperCamelCase($string) |
203
|
|
|
{ |
204
|
26 |
|
return str_replace(' ', '', |
205
|
26 |
|
ucwords(str_replace('_', ' ', strtolower($string)))); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Shortcut to retrieve the TypoScript configuration for EXT:solr |
210
|
|
|
* (plugin.tx_solr) from TSFE. |
211
|
|
|
* |
212
|
|
|
* @return TypoScriptConfiguration |
213
|
|
|
*/ |
214
|
148 |
|
public static function getSolrConfiguration() |
215
|
|
|
{ |
216
|
148 |
|
$configurationManager = self::getConfigurationManager(); |
217
|
|
|
|
218
|
148 |
|
return $configurationManager->getTypoScriptConfiguration(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return ConfigurationManager |
223
|
|
|
*/ |
224
|
184 |
|
private static function getConfigurationManager() |
225
|
|
|
{ |
226
|
|
|
/** @var ConfigurationManager $configurationManager */ |
227
|
184 |
|
$configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class); |
228
|
184 |
|
return $configurationManager; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
/** |
232
|
|
|
* Gets the Solr configuration for a specific root page id. |
233
|
|
|
* To be used from the backend. |
234
|
|
|
* |
235
|
|
|
* @param int $pageId Id of the (root) page to get the Solr configuration from. |
236
|
|
|
* @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE |
237
|
|
|
* @param int $language System language uid, optional, defaults to 0 |
238
|
|
|
* @return TypoScriptConfiguration The Solr configuration for the requested tree. |
239
|
|
|
*/ |
240
|
59 |
|
public static function getSolrConfigurationFromPageId( |
241
|
|
|
$pageId, |
242
|
|
|
$initializeTsfe = false, |
243
|
|
|
$language = 0 |
244
|
|
|
) { |
245
|
59 |
|
$rootPath = ''; |
246
|
59 |
|
return self::getConfigurationFromPageId($pageId, $rootPath, $initializeTsfe, $language); |
247
|
|
|
} |
248
|
|
|
|
249
|
|
|
/** |
250
|
|
|
* Loads the TypoScript configuration for a given page id and language. |
251
|
|
|
* Language usage may be disabled to get the default TypoScript |
252
|
|
|
* configuration. |
253
|
|
|
* |
254
|
|
|
* @param int $pageId Id of the (root) page to get the Solr configuration from. |
255
|
|
|
* @param string $path The TypoScript configuration path to retrieve. |
256
|
|
|
* @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE |
257
|
|
|
* @param int $language System language uid, optional, defaults to 0 |
258
|
|
|
* @param bool $useTwoLevelCache Flag to enable the two level cache for the typoscript configuration array |
259
|
|
|
* @return TypoScriptConfiguration The Solr configuration for the requested tree. |
260
|
|
|
*/ |
261
|
61 |
|
public static function getConfigurationFromPageId( |
262
|
|
|
$pageId, |
263
|
|
|
$path, |
264
|
|
|
$initializeTsfe = false, |
265
|
|
|
$language = 0, |
266
|
|
|
$useTwoLevelCache = true |
267
|
|
|
) { |
268
|
61 |
|
static $configurationObjectCache = []; |
269
|
61 |
|
$cacheId = md5($pageId . '|' . $path . '|' . $language); |
270
|
61 |
|
if (isset($configurationObjectCache[$cacheId])) { |
271
|
53 |
|
return $configurationObjectCache[$cacheId]; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// If we're on UID 0, we cannot retrieve a configuration currently. |
275
|
|
|
// getRootline() below throws an exception (since #typo3-60 ) |
276
|
|
|
// as UID 0 cannot have any parent rootline by design. |
277
|
61 |
|
if ($pageId == 0) { |
278
|
2 |
|
return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray([], $pageId, $language, $path); |
279
|
|
|
} |
280
|
|
|
|
281
|
60 |
|
if ($useTwoLevelCache) { |
282
|
|
|
/** @var $cache TwoLevelCache */ |
283
|
60 |
|
$cache = GeneralUtility::makeInstance(TwoLevelCache::class, 'tx_solr_configuration'); |
284
|
60 |
|
$configurationArray = $cache->get($cacheId); |
285
|
|
|
} |
286
|
|
|
|
287
|
60 |
|
if (!empty($configurationArray)) { |
288
|
|
|
// we have a cache hit and can return it. |
289
|
|
|
return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
// we have nothing in the cache. We need to build the configurationToUse |
293
|
60 |
|
$configurationArray = self::buildConfigurationArray($pageId, $path, $initializeTsfe, $language); |
294
|
|
|
|
295
|
60 |
|
if ($useTwoLevelCache && isset($cache)) { |
296
|
60 |
|
$cache->set($cacheId, $configurationArray); |
297
|
|
|
} |
298
|
|
|
|
299
|
60 |
|
return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path); |
300
|
|
|
} |
301
|
|
|
|
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* Initializes a TSFE, if required and builds an configuration array, containing the solr configuration. |
305
|
|
|
* |
306
|
|
|
* @param integer $pageId |
307
|
|
|
* @param string $path |
308
|
|
|
* @param boolean $initializeTsfe |
309
|
|
|
* @param integer $language |
310
|
|
|
* @return array |
311
|
|
|
*/ |
312
|
60 |
|
protected static function buildConfigurationArray($pageId, $path, $initializeTsfe, $language) |
313
|
|
|
{ |
314
|
60 |
|
if ($initializeTsfe) { |
315
|
2 |
|
self::initializeTsfe($pageId, $language); |
316
|
2 |
|
$configurationToUse = self::getConfigurationFromInitializedTSFE($path); |
317
|
|
|
} else { |
318
|
60 |
|
$configurationToUse = self::getConfigurationFromExistingTSFE($pageId, $path, $language); |
319
|
|
|
} |
320
|
|
|
|
321
|
60 |
|
return is_array($configurationToUse) ? $configurationToUse : []; |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
/** |
325
|
|
|
* Builds the configuration object from a config array and returns it. |
326
|
|
|
* |
327
|
|
|
* @param array $configurationToUse |
328
|
|
|
* @param int $pageId |
329
|
|
|
* @param int $languageId |
330
|
|
|
* @param string $typoScriptPath |
331
|
|
|
* @return TypoScriptConfiguration |
332
|
|
|
*/ |
333
|
61 |
|
protected static function buildTypoScriptConfigurationFromArray(array $configurationToUse, $pageId, $languageId, $typoScriptPath) |
334
|
|
|
{ |
335
|
61 |
|
$configurationManager = self::getConfigurationManager(); |
336
|
61 |
|
return $configurationManager->getTypoScriptConfiguration($configurationToUse, $pageId, $languageId, $typoScriptPath); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* This function is used to retrieve the configuration from a previous initialized TSFE |
341
|
|
|
* (see: getConfigurationFromPageId) |
342
|
|
|
* |
343
|
|
|
* @param string $path |
344
|
|
|
* @return mixed |
345
|
|
|
*/ |
346
|
2 |
|
private static function getConfigurationFromInitializedTSFE($path) |
347
|
|
|
{ |
348
|
|
|
/** @var $tmpl ExtendedTemplateService */ |
349
|
2 |
|
$tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class); |
350
|
2 |
|
$configuration = $tmpl->ext_getSetup($GLOBALS['TSFE']->tmpl->setup, $path); |
351
|
2 |
|
$configurationToUse = $configuration[0]; |
352
|
2 |
|
return $configurationToUse; |
353
|
|
|
} |
354
|
|
|
|
355
|
|
|
/** |
356
|
|
|
* This function is used to retrieve the configuration from an existing TSFE instance |
357
|
|
|
* @param $pageId |
358
|
|
|
* @param $path |
359
|
|
|
* @param $language |
360
|
|
|
* @return mixed |
361
|
|
|
*/ |
362
|
60 |
|
private static function getConfigurationFromExistingTSFE($pageId, $path, $language) |
363
|
|
|
{ |
364
|
60 |
|
if (is_int($language)) { |
365
|
60 |
|
GeneralUtility::_GETset($language, 'L'); |
366
|
|
|
} |
367
|
|
|
|
368
|
|
|
/** @var $pageSelect PageRepository */ |
369
|
60 |
|
$pageSelect = GeneralUtility::makeInstance(PageRepository::class); |
370
|
60 |
|
$rootLine = $pageSelect->getRootLine($pageId); |
371
|
|
|
|
372
|
60 |
|
$initializedTsfe = false; |
373
|
60 |
|
$initializedPageSelect = false; |
374
|
60 |
|
if (empty($GLOBALS['TSFE']->sys_page)) { |
375
|
51 |
|
if (empty($GLOBALS['TSFE'])) { |
376
|
51 |
|
$GLOBALS['TSFE'] = new \stdClass(); |
377
|
51 |
|
$GLOBALS['TSFE']->tmpl = new \stdClass(); |
378
|
51 |
|
$GLOBALS['TSFE']->tmpl->rootLine = $rootLine; |
379
|
51 |
|
$GLOBALS['TSFE']->sys_page = $pageSelect; |
380
|
51 |
|
$GLOBALS['TSFE']->id = $pageId; |
381
|
51 |
|
$GLOBALS['TSFE']->tx_solr_initTsfe = 1; |
382
|
51 |
|
$initializedTsfe = true; |
383
|
|
|
} |
384
|
|
|
|
385
|
51 |
|
$GLOBALS['TSFE']->sys_page = $pageSelect; |
386
|
51 |
|
$initializedPageSelect = true; |
387
|
|
|
} |
388
|
|
|
/** @var $tmpl ExtendedTemplateService */ |
389
|
60 |
|
$tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class); |
390
|
60 |
|
$tmpl->tt_track = false; // Do not log time-performance information |
391
|
60 |
|
$tmpl->init(); |
392
|
60 |
|
$tmpl->runThroughTemplates($rootLine); // This generates the constants/config + hierarchy info for the template. |
393
|
60 |
|
$tmpl->generateConfig(); |
394
|
|
|
|
395
|
60 |
|
$getConfigurationFromInitializedTSFEAndWriteToCache = $tmpl->ext_getSetup($tmpl->setup, $path); |
396
|
60 |
|
$configurationToUse = $getConfigurationFromInitializedTSFEAndWriteToCache[0]; |
397
|
|
|
|
398
|
60 |
|
if ($initializedPageSelect) { |
399
|
51 |
|
$GLOBALS['TSFE']->sys_page = null; |
400
|
|
|
} |
401
|
60 |
|
if ($initializedTsfe) { |
402
|
51 |
|
unset($GLOBALS['TSFE']); |
403
|
|
|
} |
404
|
60 |
|
return $configurationToUse; |
405
|
|
|
} |
406
|
|
|
|
407
|
|
|
/** |
408
|
|
|
* Initializes the TSFE for a given page ID and language. |
409
|
|
|
* |
410
|
|
|
* @param int $pageId The page id to initialize the TSFE for |
411
|
|
|
* @param int $language System language uid, optional, defaults to 0 |
412
|
|
|
* @param bool $useCache Use cache to reuse TSFE |
413
|
|
|
* @return void |
414
|
|
|
*/ |
415
|
15 |
|
public static function initializeTsfe( |
416
|
|
|
$pageId, |
417
|
|
|
$language = 0, |
418
|
|
|
$useCache = true |
419
|
|
|
) { |
420
|
15 |
|
static $tsfeCache = []; |
421
|
|
|
|
422
|
|
|
// resetting, a TSFE instance with data from a different page Id could be set already |
423
|
15 |
|
unset($GLOBALS['TSFE']); |
424
|
|
|
|
425
|
15 |
|
$cacheId = $pageId . '|' . $language; |
426
|
|
|
|
427
|
15 |
|
if (!is_object($GLOBALS['TT'])) { |
428
|
15 |
|
$GLOBALS['TT'] = GeneralUtility::makeInstance(NullTimeTracker::class); |
429
|
|
|
} |
430
|
|
|
|
431
|
15 |
|
if (!isset($tsfeCache[$cacheId]) || !$useCache) { |
432
|
15 |
|
GeneralUtility::_GETset($language, 'L'); |
433
|
|
|
|
434
|
15 |
|
$GLOBALS['TSFE'] = GeneralUtility::makeInstance(TypoScriptFrontendController::class, |
435
|
15 |
|
$GLOBALS['TYPO3_CONF_VARS'], $pageId, 0); |
436
|
|
|
|
437
|
|
|
// for certain situations we need to trick TSFE into granting us |
438
|
|
|
// access to the page in any case to make getPageAndRootline() work |
439
|
|
|
// see http://forge.typo3.org/issues/42122 |
440
|
15 |
|
$pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group'); |
441
|
15 |
|
$groupListBackup = $GLOBALS['TSFE']->gr_list; |
442
|
15 |
|
$GLOBALS['TSFE']->gr_list = $pageRecord['fe_group']; |
443
|
|
|
|
444
|
15 |
|
$GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class); |
445
|
15 |
|
$GLOBALS['TSFE']->getPageAndRootline(); |
446
|
|
|
|
447
|
|
|
// restore gr_list |
448
|
15 |
|
$GLOBALS['TSFE']->gr_list = $groupListBackup; |
449
|
|
|
|
450
|
15 |
|
$GLOBALS['TSFE']->initTemplate(); |
451
|
15 |
|
$GLOBALS['TSFE']->forceTemplateParsing = true; |
452
|
15 |
|
$GLOBALS['TSFE']->initFEuser(); |
453
|
15 |
|
$GLOBALS['TSFE']->initUserGroups(); |
454
|
|
|
// $GLOBALS['TSFE']->getCompressedTCarray(); // seems to cause conflicts sometimes |
455
|
|
|
|
456
|
15 |
|
$GLOBALS['TSFE']->no_cache = true; |
457
|
15 |
|
$GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine); |
458
|
15 |
|
$GLOBALS['TSFE']->no_cache = false; |
459
|
15 |
|
$GLOBALS['TSFE']->getConfigArray(); |
460
|
|
|
|
461
|
15 |
|
$GLOBALS['TSFE']->settingLanguage(); |
462
|
15 |
|
if (!$useCache) { |
463
|
|
|
$GLOBALS['TSFE']->settingLocale(); |
464
|
|
|
} |
465
|
|
|
|
466
|
15 |
|
$GLOBALS['TSFE']->newCObj(); |
467
|
15 |
|
$GLOBALS['TSFE']->absRefPrefix = self::getAbsRefPrefixFromTSFE($GLOBALS['TSFE']); |
468
|
15 |
|
$GLOBALS['TSFE']->calculateLinkVars(); |
469
|
|
|
|
470
|
15 |
|
if ($useCache) { |
471
|
15 |
|
$tsfeCache[$cacheId] = $GLOBALS['TSFE']; |
472
|
|
|
} |
473
|
|
|
} |
474
|
|
|
|
475
|
15 |
|
if ($useCache) { |
476
|
15 |
|
$GLOBALS['TSFE'] = $tsfeCache[$cacheId]; |
477
|
15 |
|
$GLOBALS['TSFE']->settingLocale(); |
478
|
|
|
} |
479
|
15 |
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Determines the rootpage ID for a given page. |
483
|
|
|
* |
484
|
|
|
* @param int $pageId A page ID somewhere in a tree. |
485
|
|
|
* @param bool $forceFallback Force the explicit detection and do not use the current frontend root line |
486
|
|
|
* @return int The page's tree branch's root page ID |
487
|
|
|
* @deprecated since 6.1 will be removed in 7.0 |
488
|
|
|
*/ |
489
|
|
|
public static function getRootPageId($pageId = 0, $forceFallback = false) |
490
|
|
|
{ |
491
|
|
|
GeneralUtility::logDeprecatedFunction(); |
492
|
|
|
$rootPageResolver = GeneralUtility::makeInstance(RootPageResolver::class); |
493
|
|
|
|
494
|
|
|
return $rootPageResolver->getRootPageId($pageId, $forceFallback); |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* Takes a page Id and checks whether the page is marked as root page. |
499
|
|
|
* |
500
|
|
|
* @param int $pageId Page ID |
501
|
|
|
* @return bool TRUE if the page is marked as root page, FALSE otherwise |
502
|
|
|
* @deprecated since 6.1 will be removed in 7.0 |
503
|
|
|
*/ |
504
|
|
|
public static function isRootPage($pageId) |
505
|
|
|
{ |
506
|
|
|
GeneralUtility::logDeprecatedFunction(); |
507
|
|
|
$rootPageResolver = GeneralUtility::makeInstance(RootPageResolver::class); |
508
|
|
|
|
509
|
|
|
return $rootPageResolver->getIsRootPageId($pageId); |
510
|
|
|
} |
511
|
|
|
|
512
|
|
|
/** |
513
|
|
|
* Gets the site hash for a domain |
514
|
|
|
* |
515
|
|
|
* @deprecated since 6.1 will be removed in 7.0. use SiteHashService->getSiteHashForDomain now. |
516
|
|
|
* @param string $domain Domain to calculate the site hash for. |
517
|
|
|
* @return string site hash for $domain |
518
|
|
|
*/ |
519
|
|
|
public static function getSiteHashForDomain($domain) |
520
|
|
|
{ |
521
|
|
|
GeneralUtility::logDeprecatedFunction(); |
522
|
|
|
/** @var $siteHashService SiteHashService */ |
523
|
|
|
$siteHashService = GeneralUtility::makeInstance(SiteHashService::class); |
524
|
|
|
return $siteHashService->getSiteHashForDomain($domain); |
525
|
|
|
} |
526
|
|
|
|
527
|
|
|
/** |
528
|
|
|
* Resolves magic keywords in allowed sites configuration. |
529
|
|
|
* Supported keywords: |
530
|
|
|
* __solr_current_site - The domain of the site the query has been started from |
531
|
|
|
* __current_site - Same as __solr_current_site |
532
|
|
|
* __all - Adds all domains as allowed sites |
533
|
|
|
* * - Means all sites are allowed, same as no siteHash |
534
|
|
|
* |
535
|
|
|
* @deprecated since 6.1 will be removed in 7.0. use SiteHashService->getAllowedSitesForPageIdAndAllowedSitesConfiguration now. |
536
|
|
|
* @param int $pageId A page ID that is then resolved to the site it belongs to |
537
|
|
|
* @param string $allowedSitesConfiguration TypoScript setting for allowed sites |
538
|
|
|
* @return string List of allowed sites/domains, magic keywords resolved |
539
|
|
|
*/ |
540
|
|
|
public static function resolveSiteHashAllowedSites($pageId, $allowedSitesConfiguration) |
541
|
|
|
{ |
542
|
|
|
/** @var $siteHashService SiteHashService */ |
543
|
|
|
GeneralUtility::logDeprecatedFunction(); |
544
|
|
|
$siteHashService = GeneralUtility::makeInstance(SiteHashService::class); |
545
|
|
|
return $siteHashService->getAllowedSitesForPageIdAndAllowedSitesConfiguration($pageId, $allowedSitesConfiguration); |
546
|
|
|
} |
547
|
|
|
|
548
|
|
|
/** |
549
|
|
|
* Check if record ($table, $uid) is a workspace record |
550
|
|
|
* |
551
|
|
|
* @param string $table The table the record belongs to |
552
|
|
|
* @param int $uid The record's uid |
553
|
|
|
* @return bool TRUE if the record is in a draft workspace, FALSE if it's a LIVE record |
554
|
|
|
*/ |
555
|
35 |
|
public static function isDraftRecord($table, $uid) |
556
|
|
|
{ |
557
|
35 |
|
$isWorkspaceRecord = false; |
558
|
|
|
|
559
|
35 |
|
if ((ExtensionManagementUtility::isLoaded('workspaces')) && (BackendUtility::isTableWorkspaceEnabled($table))) { |
560
|
|
|
$record = BackendUtility::getRecord($table, $uid, 'pid, t3ver_state'); |
561
|
|
|
|
562
|
|
|
if ($record['pid'] == '-1' || $record['t3ver_state'] > 0) { |
563
|
|
|
$isWorkspaceRecord = true; |
564
|
|
|
} |
565
|
|
|
} |
566
|
|
|
|
567
|
35 |
|
return $isWorkspaceRecord; |
568
|
|
|
} |
569
|
|
|
|
570
|
|
|
/** |
571
|
|
|
* Checks whether a record is a localization overlay. |
572
|
|
|
* |
573
|
|
|
* @param string $tableName The record's table name |
574
|
|
|
* @param array $record The record to check |
575
|
|
|
* @return bool TRUE if the record is a language overlay, FALSE otherwise |
576
|
|
|
*/ |
577
|
28 |
|
public static function isLocalizedRecord($tableName, array $record) |
578
|
|
|
{ |
579
|
28 |
|
$isLocalizedRecord = false; |
580
|
|
|
|
581
|
28 |
|
if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])) { |
582
|
6 |
|
$translationOriginalPointerField = $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']; |
583
|
|
|
|
584
|
6 |
|
if ($record[$translationOriginalPointerField] > 0) { |
585
|
3 |
|
$isLocalizedRecord = true; |
586
|
|
|
} |
587
|
|
|
} |
588
|
|
|
|
589
|
28 |
|
return $isLocalizedRecord; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Check if the page type of a page record is allowed |
594
|
|
|
* |
595
|
|
|
* @param array $pageRecord The pages database row |
596
|
|
|
* @param string $configurationName The name of the configuration to use. |
597
|
|
|
* |
598
|
|
|
* @return bool TRUE if the page type is allowed, otherwise FALSE |
599
|
|
|
*/ |
600
|
27 |
|
public static function isAllowedPageType(array $pageRecord, $configurationName = 'pages') |
601
|
|
|
{ |
602
|
27 |
|
$isAllowedPageType = false; |
603
|
27 |
|
$configurationName = is_null($configurationName) ? 'pages' : $configurationName; |
604
|
27 |
|
$allowedPageTypes = self::getAllowedPageTypes($pageRecord['uid'], $configurationName); |
605
|
|
|
|
606
|
27 |
|
if (in_array($pageRecord['doktype'], $allowedPageTypes)) { |
607
|
26 |
|
$isAllowedPageType = true; |
608
|
|
|
} |
609
|
|
|
|
610
|
27 |
|
return $isAllowedPageType; |
611
|
|
|
} |
612
|
|
|
|
613
|
|
|
/** |
614
|
|
|
* Get allowed page types |
615
|
|
|
* |
616
|
|
|
* @param int $pageId Page ID |
617
|
|
|
* @param string $configurationName The name of the configuration to use. |
618
|
|
|
* |
619
|
|
|
* @return array Allowed page types to compare to a doktype of a page record |
620
|
|
|
*/ |
621
|
27 |
|
public static function getAllowedPageTypes($pageId, $configurationName = 'pages') |
622
|
|
|
{ |
623
|
27 |
|
$rootPath = ''; |
624
|
27 |
|
$configuration = self::getConfigurationFromPageId($pageId, $rootPath); |
625
|
27 |
|
return $configuration->getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
/** |
629
|
|
|
* Method to check if a page exists. |
630
|
|
|
* |
631
|
|
|
* @param int $pageId |
632
|
|
|
* @return bool |
633
|
|
|
*/ |
634
|
|
|
public static function pageExists($pageId) |
635
|
|
|
{ |
636
|
|
|
$page = BackendUtility::getRecord('pages', (int)$pageId, 'uid'); |
637
|
|
|
|
638
|
|
|
if (!is_array($page) || $page['uid'] != $pageId) { |
639
|
|
|
return false; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
return true; |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* Resolves the configured absRefPrefix to a valid value and resolved if absRefPrefix |
647
|
|
|
* is set to "auto". |
648
|
|
|
* |
649
|
|
|
* @param TypoScriptFrontendController $TSFE |
650
|
|
|
* @return string |
651
|
|
|
*/ |
652
|
15 |
|
public static function getAbsRefPrefixFromTSFE(TypoScriptFrontendController $TSFE) |
653
|
|
|
{ |
654
|
15 |
|
$absRefPrefix = ''; |
655
|
15 |
|
if (empty($TSFE->config['config']['absRefPrefix'])) { |
656
|
12 |
|
return $absRefPrefix; |
657
|
|
|
} |
658
|
|
|
|
659
|
3 |
|
$absRefPrefix = trim($TSFE->config['config']['absRefPrefix']); |
660
|
3 |
|
if ($absRefPrefix === 'auto') { |
661
|
1 |
|
$absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH'); |
662
|
|
|
} |
663
|
|
|
|
664
|
3 |
|
return $absRefPrefix; |
665
|
|
|
} |
666
|
|
|
|
667
|
|
|
/** |
668
|
|
|
* This function can be used to check if one of the strings in needles is |
669
|
|
|
* contained in the haystack. |
670
|
|
|
* |
671
|
|
|
* |
672
|
|
|
* Example: |
673
|
|
|
* |
674
|
|
|
* haystack: the brown fox |
675
|
|
|
* needles: ['hello', 'world'] |
676
|
|
|
* result: false |
677
|
|
|
* |
678
|
|
|
* haystack: the brown fox |
679
|
|
|
* needles: ['is', 'fox'] |
680
|
|
|
* result: true |
681
|
|
|
* |
682
|
|
|
* @param string $haystack |
683
|
|
|
* @param array $needles |
684
|
|
|
* @return bool |
685
|
|
|
*/ |
686
|
33 |
|
public static function containsOneOfTheStrings($haystack, array $needles) |
687
|
|
|
{ |
688
|
33 |
|
foreach ($needles as $needle) { |
689
|
33 |
|
$position = strpos($haystack, $needle); |
690
|
33 |
|
if ($position !== false) { |
691
|
33 |
|
return true; |
692
|
|
|
} |
693
|
|
|
} |
694
|
|
|
|
695
|
30 |
|
return false; |
696
|
|
|
} |
697
|
|
|
} |
698
|
|
|
|