Passed
Push — master ( de73eb...4c6a80 )
by Timo
04:52
created

Util::legacySiteModeIsEnabled()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
ccs 0
cts 0
cp 0
rs 10
cc 2
nc 2
nop 0
crap 6
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 3 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\Site\SiteRepository;
28
use ApacheSolrForTypo3\Solr\System\Cache\TwoLevelCache;
29
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationManager;
30
use ApacheSolrForTypo3\Solr\System\Configuration\ConfigurationPageResolver;
31
use ApacheSolrForTypo3\Solr\System\Configuration\ExtensionConfiguration;
32
use ApacheSolrForTypo3\Solr\System\Configuration\TypoScriptConfiguration;
33
use Symfony\Component\EventDispatcher\GenericEvent;
34
use TYPO3\CMS\Core\Context\Context;
35
use TYPO3\CMS\Core\Context\LanguageAspect;
36
use TYPO3\CMS\Core\Utility\RootlineUtility;
37
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
38
use ApacheSolrForTypo3\Solr\System\Mvc\Frontend\Controller\OverriddenTypoScriptFrontendController;
39
use TYPO3\CMS\Backend\Utility\BackendUtility;
40
use TYPO3\CMS\Core\TimeTracker\TimeTracker;
41
use TYPO3\CMS\Core\TypoScript\ExtendedTemplateService;
42
use TYPO3\CMS\Core\Utility\GeneralUtility;
43
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
44
use TYPO3\CMS\Frontend\Page\PageRepository;
45
46
/**
47
 * Utility class for tx_solr
48
 *
49
 * @author Ingo Renner <[email protected]>
50
 */
51
class Util
52
{
53
54
    /**
55
     * Generates a document id for documents representing page records.
56
     *
57
     * @param int $uid The page's uid
58
     * @param int $typeNum The page's typeNum
59
     * @param int $language the language id, defaults to 0
60
     * @param string $accessGroups comma separated list of uids of groups that have access to that page
61 68
     * @param string $mountPointParameter The mount point parameter that is used to access the page.
62
     * @return string The document id for that page
63 68
     */
64
    public static function getPageDocumentId($uid, $typeNum = 0, $language = 0, $accessGroups = '0,-1', $mountPointParameter = '')
65 68
    {
66 2
        $additionalParameters = $typeNum . '/' . $language . '/' . $accessGroups;
67
68
        if ((string)$mountPointParameter !== '') {
69 68
            $additionalParameters = $mountPointParameter . '/' . $additionalParameters;
70
        }
71 68
72
        $documentId = self::getDocumentId('pages', $uid, $uid, $additionalParameters);
73
74
        return $documentId;
75
    }
76
77
    /**
78
     * Generates a document id in the form $siteHash/$type/$uid.
79
     *
80
     * @param string $table The records table name
81
     * @param int $rootPageId The record's site root id
82
     * @param int $uid The record's uid
83 89
     * @param string $additionalIdParameters Additional ID parameters
84
     * @return string A document id
85 89
     */
86 89
    public static function getDocumentId($table, $rootPageId, $uid, $additionalIdParameters = '')
87 89
    {
88
        $siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
89 89
        $site = $siteRepository->getSiteByPageId($rootPageId);
90 89
        $siteHash = $site->getSiteHash();
91 68
92
        $documentId = $siteHash . '/' . $table . '/' . $uid;
93
        if (!empty($additionalIdParameters)) {
94 89
            $documentId .= '/' . $additionalIdParameters;
95
        }
96
97
        return $documentId;
98
    }
99
100
    /**
101
     * Shortcut to retrieve the TypoScript configuration for EXT:solr
102
     * (plugin.tx_solr) from TSFE.
103 197
     *
104
     * @return TypoScriptConfiguration
105 197
     */
106 197
    public static function getSolrConfiguration()
107
    {
108
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
109
        return $configurationManager->getTypoScriptConfiguration();
110
    }
111
112
    /**
113
     * Gets the Solr configuration for a specific root page id.
114
     * To be used from the backend.
115
     *
116
     * @param int $pageId Id of the (root) page to get the Solr configuration from.
117
     * @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE
118 171
     * @param int $language System language uid, optional, defaults to 0
119
     * @return TypoScriptConfiguration The Solr configuration for the requested tree.
120 171
     */
121 171
    public static function getSolrConfigurationFromPageId($pageId, $initializeTsfe = false, $language = 0)
122
    {
123
        $rootPath = '';
124
        return self::getConfigurationFromPageId($pageId, $rootPath, $initializeTsfe, $language);
125
    }
126
127
    /**
128
     * Loads the TypoScript configuration for a given page id and language.
129
     * Language usage may be disabled to get the default TypoScript
130
     * configuration.
131
     *
132
     * @param int $pageId Id of the (root) page to get the Solr configuration from.
133
     * @param string $path The TypoScript configuration path to retrieve.
134
     * @param bool $initializeTsfe Optionally initializes a full TSFE to get the configuration, defaults to FALSE
135
     * @param int $language System language uid, optional, defaults to 0
136 175
     * @param bool $useTwoLevelCache Flag to enable the two level cache for the typoscript configuration array
137
     * @return TypoScriptConfiguration The Solr configuration for the requested tree.
138 175
     */
139
    public static function getConfigurationFromPageId($pageId, $path, $initializeTsfe = false, $language = 0, $useTwoLevelCache = true)
140 175
    {
141 175
        $pageId = self::getConfigurationPageIdToUse($pageId);
142 175
143 77
        static $configurationObjectCache = [];
144 5
        $cacheId = md5($pageId . '|' . $path . '|' . $language . '|' . ($initializeTsfe ? '1' : '0'));
145
        if (isset($configurationObjectCache[$cacheId])) {
146 77
            if ($initializeTsfe) {
147
                self::initializeTsfe($pageId, $language);
148
            }
149
            return $configurationObjectCache[$cacheId];
150
        }
151
152 175
        // If we're on UID 0, we cannot retrieve a configuration currently.
153 3
        // getRootline() below throws an exception (since #typo3-60 )
154
        // as UID 0 cannot have any parent rootline by design.
155
        if ($pageId == 0) {
156 173
            return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray([], $pageId, $language, $path);
157
        }
158 173
159 173
        if ($useTwoLevelCache) {
160
            /** @var $cache TwoLevelCache */
161
            $cache = GeneralUtility::makeInstance(TwoLevelCache::class, /** @scrutinizer ignore-type */ 'tx_solr_configuration');
162 173
            $configurationArray = $cache->get($cacheId);
163
        }
164
165
        if (!empty($configurationArray)) {
166
            // we have a cache hit and can return it.
167
            if ($initializeTsfe) {
168
                self::initializeTsfe($pageId, $language);
169
            }
170
            return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path);
171 173
        }
172
173 173
        // we have nothing in the cache. We need to build the configurationToUse
174 173
        $configurationArray = self::buildConfigurationArray($pageId, $path, $initializeTsfe, $language);
175
176
        if ($useTwoLevelCache && isset($cache)) {
177 173
            $cache->set($cacheId, $configurationArray);
178
        }
179
180
        return $configurationObjectCache[$cacheId] = self::buildTypoScriptConfigurationFromArray($configurationArray, $pageId, $language, $path);
181
    }
182
183
    /**
184
     * This method retrieves the closest pageId where a configuration is located, when this
185
     * feature is enabled.
186
     *
187 175
     * @param int $pageId
188
     * @return int
189 175
     */
190 175
    protected static function getConfigurationPageIdToUse($pageId)
191
    {
192
        $extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
193
        if ($extensionConfiguration->getIsUseConfigurationFromClosestTemplateEnabled()) {
194
            /** @var $configurationPageResolve ConfigurationPageResolver */
195
            $configurationPageResolver = GeneralUtility::makeInstance(ConfigurationPageResolver::class);
196 175
            $pageId = $configurationPageResolver->getClosestPageIdWithActiveTemplate($pageId);
197
            return $pageId;
198
        }
199
        return $pageId;
200
    }
201
202
    /**
203
     * Initializes a TSFE, if required and builds an configuration array, containing the solr configuration.
204
     *
205
     * @param integer $pageId
206
     * @param string $path
207
     * @param boolean $initializeTsfe
208 173
     * @param integer $language
209
     * @return array
210 173
     */
211 22
    protected static function buildConfigurationArray($pageId, $path, $initializeTsfe, $language)
212 22
    {
213
        if ($initializeTsfe) {
214 171
            self::initializeTsfe($pageId, $language);
215
            $configurationToUse = self::getConfigurationFromInitializedTSFE($path);
216
        } else {
217 173
            $configurationToUse = self::getConfigurationFromExistingTSFE($pageId, $path, $language);
218
        }
219
220
        return is_array($configurationToUse) ? $configurationToUse : [];
221
    }
222
223
    /**
224
     * Builds the configuration object from a config array and returns it.
225
     *
226
     * @param array $configurationToUse
227
     * @param int $pageId
228
     * @param int $languageId
229 175
     * @param string $typoScriptPath
230
     * @return TypoScriptConfiguration
231 175
     */
232 175
    protected static function buildTypoScriptConfigurationFromArray(array $configurationToUse, $pageId, $languageId, $typoScriptPath)
233
    {
234
        $configurationManager = GeneralUtility::makeInstance(ConfigurationManager::class);
235
        return $configurationManager->getTypoScriptConfiguration($configurationToUse, $pageId, $languageId, $typoScriptPath);
236
    }
237
238
    /**
239
     * This function is used to retrieve the configuration from a previous initialized TSFE
240
     * (see: getConfigurationFromPageId)
241
     *
242 22
     * @param string $path
243
     * @return mixed
244
     */
245 22
    private static function getConfigurationFromInitializedTSFE($path)
246 22
    {
247 22
        /** @var $tmpl ExtendedTemplateService */
248 22
        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
249
        $configuration = $tmpl->ext_getSetup($GLOBALS['TSFE']->tmpl->setup, $path);
250
        $configurationToUse = $configuration[0];
251
        return $configurationToUse;
252
    }
253
254
    /**
255
     * This function is used to retrieve the configuration from an existing TSFE instance
256
     *
257
     * @param $pageId
258
     * @param $path
259 171
     * @param $language
260
     * @return mixed
261 171
     */
262 171
    private static function getConfigurationFromExistingTSFE($pageId, $path, $language)
263
    {
264
        if (is_int($language)) {
265
            GeneralUtility::_GETset($language, 'L');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Core\Utility\GeneralUtility::_GETset() has been deprecated: since TYPO3 v9 LTS, will be removed in TYPO3 v10.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

265
            /** @scrutinizer ignore-deprecated */ GeneralUtility::_GETset($language, 'L');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
266 171
        }
267 171
268
            /** @var $pageSelect PageRepository */
269 171
        $pageSelect = GeneralUtility::makeInstance(PageRepository::class);
270 171
271 171
        $rootlineUtility = GeneralUtility::makeInstance(RootlineUtility::class, $pageId);
272 92
        try {
273 92
            $rootLine = $rootlineUtility->get();
274 92
        } catch (\RuntimeException $e) {
275 92
            $rootLine = [];
276 92
        }
277 92
278 92
        $initializedTsfe = false;
279 92
        $initializedPageSelect = false;
280
        if (empty($GLOBALS['TSFE']->sys_page)) {
281
            if (empty($GLOBALS['TSFE'])) {
282 92
                $GLOBALS['TSFE'] = new \stdClass();
283 92
                $GLOBALS['TSFE']->tmpl = new \stdClass();
284
                $GLOBALS['TSFE']->tmpl->rootLine = $rootLine;
285
                $GLOBALS['TSFE']->sys_page = $pageSelect;
286 171
                $GLOBALS['TSFE']->id = $pageId;
287 171
                $GLOBALS['TSFE']->tx_solr_initTsfe = 1;
288 171
                $initializedTsfe = true;
289 171
            }
290 171
291
            $GLOBALS['TSFE']->sys_page = $pageSelect;
292 171
            $initializedPageSelect = true;
293 171
        }
294
            /** @var $tmpl ExtendedTemplateService */
295 171
        $tmpl = GeneralUtility::makeInstance(ExtendedTemplateService::class);
296 92
        $tmpl->tt_track = false; // Do not log time-performance information
297
        $tmpl->init();
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Core\TypoScript\TemplateService::init() has been deprecated: since TYPO3 v9, will be removed in TYPO3 v10.0 ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

297
        /** @scrutinizer ignore-deprecated */ $tmpl->init();

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
298 171
        $tmpl->runThroughTemplates($rootLine); // This generates the constants/config + hierarchy info for the template.
299 92
        $tmpl->generateConfig();
300
301 171
        $getConfigurationFromInitializedTSFEAndWriteToCache = $tmpl->ext_getSetup($tmpl->setup, $path);
302
        $configurationToUse = $getConfigurationFromInitializedTSFEAndWriteToCache[0];
303
304
        if ($initializedPageSelect) {
305
            $GLOBALS['TSFE']->sys_page = null;
306
        }
307
        if ($initializedTsfe) {
308
            unset($GLOBALS['TSFE']);
309
        }
310
        return $configurationToUse;
311
    }
312
313 27
    /**
314
     * Initializes the TSFE for a given page ID and language.
315 27
     *
316
     * @param int $pageId The page id to initialize the TSFE for
317
     * @param int $language System language uid, optional, defaults to 0
318 27
     * @param bool $useCache Use cache to reuse TSFE
319
     * @todo When we drop TYPO3 8 support we should use a middleware stack to initialize a TSFE for our needs
320 27
     * @return void
321
     */
322 27
    public static function initializeTsfe($pageId, $language = 0, $useCache = true)
323 26
    {
324
        static $tsfeCache = [];
325
326 27
        // resetting, a TSFE instance with data from a different page Id could be set already
327 27
        unset($GLOBALS['TSFE']);
328
329
        $cacheId = $pageId . '|' . $language;
330 27
331
        if (!is_object($GLOBALS['TT'])) {
332
            $GLOBALS['TT'] = GeneralUtility::makeInstance(TimeTracker::class, false);
333
        }
334
335 27
336 27
        /** @var Context $context */
337 27
        $context = GeneralUtility::makeInstance(Context::class);
338
        $context->setAspect('language', GeneralUtility::makeInstance(LanguageAspect::class, $language));
339 27
340 27
        // needs to be set regardless if $GLOBALS['TSFE'] is loaded from cache
341
        // otherwise it is not guaranteed that the correct language id is used everywhere for this index cycle (e.g. Typo3QuerySettings)
342
        GeneralUtility::_GETset($language, 'L');
0 ignored issues
show
Deprecated Code introduced by
The function TYPO3\CMS\Core\Utility\GeneralUtility::_GETset() has been deprecated: since TYPO3 v9 LTS, will be removed in TYPO3 v10.0. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

342
        /** @scrutinizer ignore-deprecated */ GeneralUtility::_GETset($language, 'L');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
343 26
344
        if (!isset($tsfeCache[$cacheId]) || !$useCache) {
345 26
346 26
            $GLOBALS['TSFE'] = GeneralUtility::makeInstance(OverriddenTypoScriptFrontendController::class, $GLOBALS['TYPO3_CONF_VARS'], $pageId, 0);
347 26
348 26
            // for certain situations we need to trick TSFE into granting us
349
            // access to the page in any case to make getPageAndRootline() work
350
            // see http://forge.typo3.org/issues/42122
351 26
            $pageRecord = BackendUtility::getRecord('pages', $pageId, 'fe_group');
352 26
            $groupListBackup = $GLOBALS['TSFE']->gr_list;
353 26
            $GLOBALS['TSFE']->gr_list = $pageRecord['fe_group'];
354 26
355 26
            $GLOBALS['TSFE']->sys_page = GeneralUtility::makeInstance(PageRepository::class);
356 26
            self::getPageAndRootlineOfTSFE($pageId);
0 ignored issues
show
Deprecated Code introduced by
The function ApacheSolrForTypo3\Solr\...PageAndRootlineOfTSFE() has been deprecated: This is only implemented to provide compatibility for TYPO3 8 and 9 when we drop TYPO3 8 support this should changed to use a middleware stack ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

356
            /** @scrutinizer ignore-deprecated */ self::getPageAndRootlineOfTSFE($pageId);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
357
358
            // restore gr_list
359
            $GLOBALS['TSFE']->gr_list = $groupListBackup;
360 26
361 26
            $GLOBALS['TSFE']->initTemplate();
362 26
            $GLOBALS['TSFE']->forceTemplateParsing = true;
363
            $GLOBALS['TSFE']->initFEuser();
364 26
            $GLOBALS['TSFE']->initUserGroups();
365 26
            //  $GLOBALS['TSFE']->getCompressedTCarray(); // seems to cause conflicts sometimes
366
367
            $GLOBALS['TSFE']->no_cache = true;
368
            $GLOBALS['TSFE']->tmpl->start($GLOBALS['TSFE']->rootLine);
369 26
            $GLOBALS['TSFE']->no_cache = false;
370 26
            $GLOBALS['TSFE']->getConfigArray();
371 26
            $GLOBALS['TSFE']->settingLanguage();
372
            if (!$useCache) {
373 26
                $GLOBALS['TSFE']->settingLocale();
374
            }
375
376
            $GLOBALS['TSFE']->newCObj();
377
            $GLOBALS['TSFE']->absRefPrefix = self::getAbsRefPrefixFromTSFE($GLOBALS['TSFE']);
378
            $GLOBALS['TSFE']->calculateLinkVars();
379
380 27
            // fixes wrong language uid in global context when tsfe is taken from cache
381
            $GLOBALS['TSFE']->__set('sys_language_uid', $language);
382
383
384 27
            if ($useCache) {
385 27
                $tsfeCache[$cacheId] = $GLOBALS['TSFE'];
386 27
            }
387 26
        }
388
389
        if ($useCache) {
390
            $GLOBALS['TSFE'] = $tsfeCache[$cacheId];
391
            $GLOBALS['TSFE']->settingLocale();
392
        }
393
    }
394
395
    /**
396 42
     * @deprecated This is only implemented to provide compatibility for TYPO3 8 and 9 when we drop TYPO3 8 support this
397
     * should changed to use a middleware stack
398 42
     * @param integer $pageId
399
     */
400 42
    private static function getPageAndRootlineOfTSFE($pageId)
401
    {
402
        //@todo When we drop the support of TYPO3 8 we should use the frontend middleware stack instead of initializing this on our own
403
        /** @var $siteRepository SiteRepository */
404
        $siteRepository = GeneralUtility::makeInstance(SiteRepository::class);
405
        $site = $siteRepository->getSiteByPageId($pageId);
406
        $GLOBALS['TSFE']->getPageAndRootlineWithDomain($site->getRootPageId());
407
    }
408 42
409
    /**
410
     * Check if record ($table, $uid) is a workspace record
411
     *
412
     * @param string $table The table the record belongs to
413
     * @param int $uid The record's uid
414
     * @return bool TRUE if the record is in a draft workspace, FALSE if it's a LIVE record
415
     */
416
    public static function isDraftRecord($table, $uid)
417
    {
418
        $isWorkspaceRecord = false;
419 31
420
        if ((ExtensionManagementUtility::isLoaded('workspaces')) && (BackendUtility::isTableWorkspaceEnabled($table))) {
421 31
            $record = BackendUtility::getRecord($table, $uid, 'pid, t3ver_state');
422 31
423 31
            if ($record['pid'] == '-1' || $record['t3ver_state'] > 0) {
424
                $isWorkspaceRecord = true;
425 31
            }
426 30
        }
427
428
        return $isWorkspaceRecord;
429 31
    }
430
431
    /**
432
     * Check if the page type of a page record is allowed
433
     *
434
     * @param array $pageRecord The pages database row
435
     * @param string $configurationName The name of the configuration to use.
436
     *
437
     * @return bool TRUE if the page type is allowed, otherwise FALSE
438
     */
439
    public static function isAllowedPageType(array $pageRecord, $configurationName = 'pages')
440 31
    {
441
        $isAllowedPageType = false;
442 31
        $configurationName = $configurationName ?? 'pages';
443 31
        $allowedPageTypes = self::getAllowedPageTypes($pageRecord['uid'], $configurationName);
444 31
445
        if (in_array($pageRecord['doktype'], $allowedPageTypes)) {
446
            $isAllowedPageType = true;
447
        }
448
449
        return $isAllowedPageType;
450
    }
451
452
    /**
453
     * Get allowed page types
454 26
     *
455
     * @param int $pageId Page ID
456 26
     * @param string $configurationName The name of the configuration to use.
457 26
     *
458 23
     * @return array Allowed page types to compare to a doktype of a page record
459
     */
460
    public static function getAllowedPageTypes($pageId, $configurationName = 'pages')
461 3
    {
462 3
        $rootPath = '';
463 1
        $configuration = self::getConfigurationFromPageId($pageId, $rootPath);
464
        return $configuration->getIndexQueueAllowedPageTypesArrayByConfigurationName($configurationName);
465
    }
466 3
467
    /**
468
     * Resolves the configured absRefPrefix to a valid value and resolved if absRefPrefix
469
     * is set to "auto".
470
     *
471
     * @param TypoScriptFrontendController $TSFE
472
     * @return string
473
     */
474
    public static function getAbsRefPrefixFromTSFE(TypoScriptFrontendController $TSFE)
475
    {
476
        $absRefPrefix = '';
477
        if (empty($TSFE->config['config']['absRefPrefix'])) {
478
            return $absRefPrefix;
479
        }
480
481
        $absRefPrefix = trim($TSFE->config['config']['absRefPrefix']);
482
        if ($absRefPrefix === 'auto') {
483
            $absRefPrefix = GeneralUtility::getIndpEnv('TYPO3_SITE_PATH');
484
        }
485
486
        return $absRefPrefix;
487
    }
488
489 55
490
    /**
491 55
     * This function can be used to check if one of the strings in needles is
492 55
     * contained in the haystack.
493 55
     *
494 3
     *
495
     * Example:
496
     *
497
     * haystack: the brown fox
498 52
     * needles: ['hello', 'world']
499
     * result: false
500
     *
501
     * haystack: the brown fox
502
     * needles: ['is', 'fox']
503
     * result: true
504
     *
505
     * @param string $haystack
506
     * @param array $needles
507
     * @return bool
508
     */
509
    public static function containsOneOfTheStrings($haystack, array $needles)
510
    {
511
        foreach ($needles as $needle) {
512
            $position = strpos($haystack, $needle);
513
            if ($position !== false) {
514
                return true;
515
            }
516
        }
517
518
        return false;
519
    }
520
521
    /**
522
     * Returns the current language ID from the active context.
523
     * @return int
524
     */
525
    public static function getLanguageUid(): int
526
    {
527
        $context = GeneralUtility::makeInstance(Context::class);
528
        return (int)$context->getPropertyFromAspect('language', 'id');
529
    }
530
531
    /**
532
     * @return string
533
     */
534
    public static function getFrontendUserGroupsList(): string
535
    {
536
        return implode(',', self::getFrontendUserGroups());
537
    }
538
539
    /**
540
     * @return array
541
     * @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
542
     */
543
    public static function getFrontendUserGroups(): array
544
    {
545
        $context = GeneralUtility::makeInstance(Context::class);
546
        return $context->getPropertyFromAspect('frontend.user', 'groupIds');
547
    }
548
549
    /**
550
     * Checks whether legacy site mode is enabled.
551
     *
552
     * @return bool
553
     */
554
    public static function legacySiteModeIsEnabled(): bool
555
    {
556
        return isset($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['solr']['allowLegacySiteMode']) && (int)$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['solr']['allowLegacySiteMode'] === 1;
557
    }
558
559
}
560