|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace AOE\Crawler\Backend\RequestForm; |
|
6
|
|
|
|
|
7
|
|
|
/* |
|
8
|
|
|
* (c) 2020 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\Utility\MessageUtility; |
|
23
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
|
24
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
|
25
|
|
|
|
|
26
|
|
|
final class StartRequestForm implements RequestForm |
|
27
|
|
|
{ |
|
28
|
|
|
/** @var StandaloneView */ |
|
29
|
|
|
private $view; |
|
30
|
|
|
|
|
31
|
|
|
public function __construct(StandaloneView $view) |
|
32
|
|
|
{ |
|
33
|
|
|
$this->view = $view; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function render($id, string $elementName, array $menuItems): string |
|
37
|
|
|
{ |
|
38
|
|
|
return $this->showCrawlerInformationAction(); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/******************************* |
|
42
|
|
|
* |
|
43
|
|
|
* Generate URLs for crawling: |
|
44
|
|
|
* |
|
45
|
|
|
******************************/ |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Show a list of URLs to be crawled for each page |
|
49
|
|
|
*/ |
|
50
|
|
|
private function showCrawlerInformationAction(): string |
|
51
|
|
|
{ |
|
52
|
|
|
$this->view->setTemplate('ShowCrawlerInformation'); |
|
53
|
|
|
if (empty($this->id)) { |
|
54
|
|
|
$this->isErrorDetected = true; |
|
|
|
|
|
|
55
|
|
|
MessageUtility::addErrorMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.noPageSelected')); |
|
56
|
|
|
} else { |
|
57
|
|
|
$crawlerParameter = GeneralUtility::_GP('_crawl'); |
|
|
|
|
|
|
58
|
|
|
$downloadParameter = GeneralUtility::_GP('_download'); |
|
59
|
|
|
|
|
60
|
|
|
$this->duplicateTrack = []; |
|
|
|
|
|
|
61
|
|
|
$this->submitCrawlUrls = isset($crawlerParameter); |
|
|
|
|
|
|
62
|
|
|
$this->downloadCrawlUrls = isset($downloadParameter); |
|
|
|
|
|
|
63
|
|
|
$this->makeCrawlerProcessableChecks(); |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
switch ((string) GeneralUtility::_GP('tstamp')) { |
|
66
|
|
|
case 'midnight': |
|
67
|
|
|
$this->scheduledTime = mktime(0, 0, 0); |
|
|
|
|
|
|
68
|
|
|
break; |
|
69
|
|
|
case '04:00': |
|
70
|
|
|
$this->scheduledTime = mktime(0, 0, 0) + 4 * 3600; |
|
71
|
|
|
break; |
|
72
|
|
|
case 'now': |
|
73
|
|
|
default: |
|
74
|
|
|
$this->scheduledTime = time(); |
|
75
|
|
|
break; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
$this->incomingConfigurationSelection = GeneralUtility::_GP('configurationSelection'); |
|
|
|
|
|
|
79
|
|
|
$this->incomingConfigurationSelection = is_array($this->incomingConfigurationSelection) ? $this->incomingConfigurationSelection : []; |
|
80
|
|
|
|
|
81
|
|
|
$this->crawlerController = GeneralUtility::makeInstance(CrawlerController::class); |
|
|
|
|
|
|
82
|
|
|
$this->crawlerController->setAccessMode('gui'); |
|
83
|
|
|
$this->crawlerController->setID = GeneralUtility::md5int(microtime()); |
|
84
|
|
|
|
|
85
|
|
|
$code = ''; |
|
86
|
|
|
$noConfigurationSelected = empty($this->incomingConfigurationSelection) |
|
87
|
|
|
|| (count($this->incomingConfigurationSelection) === 1 && empty($this->incomingConfigurationSelection[0])); |
|
88
|
|
|
if ($noConfigurationSelected) { |
|
89
|
|
|
MessageUtility::addWarningMessage($this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.noConfigSelected')); |
|
90
|
|
|
} else { |
|
91
|
|
|
if ($this->submitCrawlUrls) { |
|
92
|
|
|
$reason = new Reason(); |
|
|
|
|
|
|
93
|
|
|
$reason->setReason(Reason::REASON_GUI_SUBMIT); |
|
94
|
|
|
$reason->setDetailText('The user ' . $GLOBALS['BE_USER']->user['username'] . ' added pages to the crawler queue manually'); |
|
95
|
|
|
|
|
96
|
|
|
$signalPayload = ['reason' => $reason]; |
|
97
|
|
|
SignalSlotUtility::emitSignal( |
|
|
|
|
|
|
98
|
|
|
self::class, |
|
99
|
|
|
SignalSlotUtility::SIGNAL_INVOKE_QUEUE_CHANGE, |
|
100
|
|
|
$signalPayload |
|
101
|
|
|
); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
$code = $this->crawlerController->getPageTreeAndUrls( |
|
105
|
|
|
$this->id, |
|
|
|
|
|
|
106
|
|
|
$this->pObj->MOD_SETTINGS['depth'], |
|
|
|
|
|
|
107
|
|
|
$this->scheduledTime, |
|
108
|
|
|
$this->reqMinute, |
|
|
|
|
|
|
109
|
|
|
$this->submitCrawlUrls, |
|
110
|
|
|
$this->downloadCrawlUrls, |
|
111
|
|
|
[], // Do not filter any processing instructions |
|
112
|
|
|
$this->incomingConfigurationSelection |
|
113
|
|
|
); |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
$this->downloadUrls = $this->crawlerController->downloadUrls; |
|
|
|
|
|
|
117
|
|
|
$this->duplicateTrack = $this->crawlerController->duplicateTrack; |
|
118
|
|
|
|
|
119
|
|
|
$this->view->assign('noConfigurationSelected', $noConfigurationSelected); |
|
120
|
|
|
$this->view->assign('submitCrawlUrls', $this->submitCrawlUrls); |
|
121
|
|
|
$this->view->assign('amountOfUrls', count(array_keys($this->duplicateTrack))); |
|
122
|
|
|
$this->view->assign('selectors', $this->generateConfigurationSelectors()); |
|
|
|
|
|
|
123
|
|
|
$this->view->assign('code', $code); |
|
124
|
|
|
$this->view->assign('displayActions', 0); |
|
125
|
|
|
|
|
126
|
|
|
// Download Urls to crawl: |
|
127
|
|
|
if ($this->downloadCrawlUrls) { |
|
128
|
|
|
// Creating output header: |
|
129
|
|
|
header('Content-Type: application/octet-stream'); |
|
130
|
|
|
header('Content-Disposition: attachment; filename=CrawlerUrls.txt'); |
|
131
|
|
|
|
|
132
|
|
|
// Printing the content of the CSV lines: |
|
133
|
|
|
echo implode(chr(13) . chr(10), $this->downloadUrls); |
|
134
|
|
|
exit; |
|
|
|
|
|
|
135
|
|
|
} |
|
136
|
|
|
} |
|
137
|
|
|
return $this->view->render(); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
private function getLanguageService(): LanguageService |
|
141
|
|
|
{ |
|
142
|
|
|
return $GLOBALS['LANG']; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
|