|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AOE\Crawler\Service; |
|
6
|
|
|
|
|
7
|
|
|
/* |
|
8
|
|
|
* (c) 2021 AOE GmbH <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* This file is part of the TYPO3 Crawler Extension. |
|
11
|
|
|
* |
|
12
|
|
|
* It is free software; you can redistribute it and/or modify it under |
|
13
|
|
|
* the terms of the GNU General Public License, either version 2 |
|
14
|
|
|
* of the License, or any later version. |
|
15
|
|
|
* |
|
16
|
|
|
* For the full copyright and license information, please read the |
|
17
|
|
|
* LICENSE.txt file that was distributed with this source code. |
|
18
|
|
|
* |
|
19
|
|
|
* The TYPO3 project - inspiring people to share! |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
use AOE\Crawler\Configuration\ExtensionConfigurationProvider; |
|
23
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* @internal since v9.2.5 |
|
27
|
|
|
*/ |
|
28
|
|
|
class PageService |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Check if the given page should be crawled |
|
32
|
|
|
* |
|
33
|
|
|
* @return false|string false if the page should be crawled (not excluded), true / skipMessage if it should be skipped |
|
34
|
|
|
*/ |
|
35
|
|
|
public function checkIfPageShouldBeSkipped(array $pageRow) |
|
36
|
|
|
{ |
|
37
|
|
|
$extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration(); |
|
38
|
|
|
|
|
39
|
|
|
// if page is hidden |
|
40
|
|
|
if (! $extensionSettings['crawlHiddenPages'] && $pageRow['hidden']) { |
|
41
|
|
|
return 'Because page is hidden'; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
if (in_array($pageRow['doktype'], $this->getDisallowedDokTypes())) { |
|
45
|
|
|
return 'Because doktype is not allowed'; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['excludeDoktype'] ?? [] as $key => $doktypeList) { |
|
49
|
|
|
if (GeneralUtility::inList($doktypeList, $pageRow['doktype'])) { |
|
50
|
|
|
return 'Doktype was excluded by "' . $key . '"'; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
// veto hook |
|
55
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['pageVeto'] ?? [] as $key => $func) { |
|
56
|
|
|
$params = [ |
|
57
|
|
|
'pageRow' => $pageRow, |
|
58
|
|
|
]; |
|
59
|
|
|
// expects "false" if page is ok and "true" or a skipMessage if this page should _not_ be crawled |
|
60
|
|
|
$veto = GeneralUtility::callUserFunction($func, $params, $this); |
|
61
|
|
|
if ($veto !== false) { |
|
62
|
|
|
if (is_string($veto)) { |
|
63
|
|
|
return $veto; |
|
64
|
|
|
} |
|
65
|
|
|
return 'Veto from hook "' . htmlspecialchars($key) . '"'; |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return false; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
private function getDisallowedDokTypes(): array |
|
73
|
|
|
{ |
|
74
|
|
|
// Todo: Use PageRepository::DOKTYPE_ when dropping support for TYPO3 v9 |
|
75
|
|
|
return [3,4,199,254,255]; |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|