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