1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AOE\Crawler\Backend; |
6
|
|
|
|
7
|
|
|
/*************************************************************** |
8
|
|
|
* Copyright notice |
9
|
|
|
* |
10
|
|
|
* (c) 2020 AOE GmbH <[email protected]> |
11
|
|
|
* |
12
|
|
|
* All rights reserved |
13
|
|
|
* |
14
|
|
|
* This script is part of the TYPO3 project. The TYPO3 project is |
15
|
|
|
* free software; you can redistribute it and/or modify |
16
|
|
|
* it under the terms of the GNU General Public License as published by |
17
|
|
|
* the Free Software Foundation; either version 3 of the License, or |
18
|
|
|
* (at your option) any later version. |
19
|
|
|
* |
20
|
|
|
* The GNU General Public License can be found at |
21
|
|
|
* http://www.gnu.org/copyleft/gpl.html. |
22
|
|
|
* |
23
|
|
|
* This script is distributed in the hope that it will be useful, |
24
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
25
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
26
|
|
|
* GNU General Public License for more details. |
27
|
|
|
* |
28
|
|
|
* This copyright notice MUST APPEAR in all copies of the script! |
29
|
|
|
***************************************************************/ |
30
|
|
|
|
31
|
|
|
use AOE\Crawler\Backend\RequestForm\RequestFormFactory; |
32
|
|
|
use AOE\Crawler\Configuration\ExtensionConfigurationProvider; |
33
|
|
|
use AOE\Crawler\Controller\CrawlerController; |
34
|
|
|
use AOE\Crawler\Converter\JsonCompatibilityConverter; |
35
|
|
|
use AOE\Crawler\Domain\Repository\QueueRepository; |
36
|
|
|
use AOE\Crawler\Hooks\CrawlerHookInterface; |
37
|
|
|
use AOE\Crawler\Service\ProcessService; |
38
|
|
|
use AOE\Crawler\Value\CrawlAction; |
39
|
|
|
use AOE\Crawler\Value\ModuleSettings; |
40
|
|
|
use Psr\Http\Message\UriInterface; |
41
|
|
|
use TYPO3\CMS\Backend\Routing\UriBuilder; |
42
|
|
|
use TYPO3\CMS\Backend\Template\ModuleTemplate; |
43
|
|
|
use TYPO3\CMS\Backend\Utility\BackendUtility; |
44
|
|
|
use TYPO3\CMS\Core\Database\ConnectionPool; |
45
|
|
|
use TYPO3\CMS\Core\Database\Query\QueryBuilder; |
46
|
|
|
use TYPO3\CMS\Core\Http\Uri; |
47
|
|
|
use TYPO3\CMS\Core\Imaging\Icon; |
48
|
|
|
use TYPO3\CMS\Core\Imaging\IconFactory; |
49
|
|
|
use TYPO3\CMS\Core\Localization\LanguageService; |
50
|
|
|
use TYPO3\CMS\Core\Utility\GeneralUtility; |
51
|
|
|
use TYPO3\CMS\Extbase\Object\ObjectManager; |
52
|
|
|
use TYPO3\CMS\Fluid\View\StandaloneView; |
53
|
|
|
use TYPO3\CMS\Info\Controller\InfoModuleController; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Function for Info module, containing three main actions: |
57
|
|
|
* - List of all queued items |
58
|
|
|
* - Log functionality |
59
|
|
|
* - Process overview |
60
|
|
|
*/ |
61
|
|
|
class BackendModule |
62
|
|
|
{ |
63
|
|
|
/** |
64
|
|
|
* @var InfoModuleController Contains a reference to the parent calling object |
65
|
|
|
*/ |
66
|
|
|
protected $pObj; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* The current page ID |
70
|
|
|
* @var int |
71
|
|
|
*/ |
72
|
|
|
protected $id; |
73
|
|
|
|
74
|
|
|
// Internal, dynamic: |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @var array |
78
|
|
|
*/ |
79
|
|
|
protected $duplicateTrack = []; |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @var bool |
83
|
|
|
*/ |
84
|
|
|
protected $submitCrawlUrls = false; |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @var bool |
88
|
|
|
*/ |
89
|
|
|
protected $downloadCrawlUrls = false; |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @var int |
93
|
|
|
*/ |
94
|
|
|
protected $scheduledTime = 0; |
95
|
|
|
|
96
|
|
|
/** |
97
|
|
|
* @var int |
98
|
|
|
*/ |
99
|
|
|
protected $reqMinute = 1000; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var array holds the selection of configuration from the configuration selector box |
103
|
|
|
*/ |
104
|
|
|
protected $incomingConfigurationSelection = []; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* @var CrawlerController |
108
|
|
|
*/ |
109
|
|
|
protected $crawlerController; |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @var array |
113
|
|
|
*/ |
114
|
|
|
protected $CSVaccu = []; |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* If true the user requested a CSV export of the queue |
118
|
|
|
* |
119
|
|
|
* @var boolean |
120
|
|
|
*/ |
121
|
|
|
protected $CSVExport = false; |
122
|
|
|
|
123
|
|
|
/** |
124
|
|
|
* @var array |
125
|
|
|
*/ |
126
|
|
|
protected $downloadUrls = []; |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Holds the configuration from ext_conf_template loaded by getExtensionConfiguration() |
130
|
|
|
* |
131
|
|
|
* @var array |
132
|
|
|
*/ |
133
|
|
|
protected $extensionSettings = []; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Indicate that an flash message with an error is present. |
137
|
|
|
* |
138
|
|
|
* @var boolean |
139
|
|
|
*/ |
140
|
|
|
protected $isErrorDetected = false; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* @var ProcessService |
144
|
|
|
*/ |
145
|
|
|
protected $processManager; |
146
|
|
|
|
147
|
|
|
/** |
148
|
|
|
* @var QueryBuilder |
149
|
|
|
*/ |
150
|
|
|
protected $queryBuilder; |
151
|
|
|
|
152
|
|
|
/** |
153
|
|
|
* @var QueueRepository |
154
|
|
|
*/ |
155
|
|
|
protected $queueRepository; |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* @var StandaloneView |
159
|
|
|
*/ |
160
|
|
|
protected $view; |
161
|
|
|
|
162
|
|
|
/** |
163
|
|
|
* @var IconFactory |
164
|
|
|
*/ |
165
|
|
|
protected $iconFactory; |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* @var JsonCompatibilityConverter |
169
|
|
|
*/ |
170
|
|
|
protected $jsonCompatibilityConverter; |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* @var LanguageService |
174
|
|
|
*/ |
175
|
|
|
private $languageService; |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @var ModuleSettings |
179
|
|
|
*/ |
180
|
|
|
private $moduleSettings; |
|
|
|
|
181
|
|
|
|
182
|
|
|
public function __construct() |
183
|
|
|
{ |
184
|
|
|
$this->languageService = $GLOBALS['LANG']; |
185
|
|
|
$objectManger = GeneralUtility::makeInstance(ObjectManager::class); |
186
|
|
|
$this->processManager = $objectManger->get(ProcessService::class); |
187
|
|
|
$this->queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_crawler_queue'); |
188
|
|
|
$this->queueRepository = $objectManger->get(QueueRepository::class); |
189
|
|
|
$this->initializeView(); |
190
|
|
|
$this->extensionSettings = GeneralUtility::makeInstance(ExtensionConfigurationProvider::class)->getExtensionConfiguration(); |
191
|
|
|
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class); |
192
|
|
|
$this->jsonCompatibilityConverter = GeneralUtility::makeInstance(JsonCompatibilityConverter::class); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Called by the InfoModuleController |
197
|
|
|
*/ |
198
|
|
|
public function init(InfoModuleController $pObj): void |
199
|
|
|
{ |
200
|
|
|
|
201
|
|
|
$this->pObj = $pObj; |
202
|
|
|
$this->id = (int) GeneralUtility::_GP('id'); |
203
|
|
|
// Setting MOD_MENU items as we need them for logging: |
204
|
|
|
$this->pObj->MOD_MENU = array_merge($this->pObj->MOD_MENU, $this->getModuleMenu()); |
205
|
|
|
} |
206
|
|
|
|
207
|
1 |
|
private function getModuleMenu(): array |
208
|
|
|
{ |
209
|
|
|
return [ |
210
|
|
|
'depth' => [ |
211
|
1 |
|
0 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
212
|
1 |
|
1 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
213
|
1 |
|
2 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
214
|
1 |
|
3 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
215
|
1 |
|
4 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
216
|
1 |
|
99 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'), |
217
|
|
|
], |
218
|
|
|
'crawlaction' => [ |
219
|
1 |
|
'start' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.start'), |
220
|
1 |
|
'log' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.log'), |
221
|
1 |
|
'multiprocess' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.multiprocess'), |
222
|
|
|
], |
223
|
1 |
|
'log_resultLog' => '', |
224
|
1 |
|
'log_feVars' => '', |
225
|
1 |
|
'processListMode' => '', |
226
|
|
|
'log_display' => [ |
227
|
1 |
|
'all' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.all'), |
228
|
1 |
|
'pending' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.pending'), |
229
|
1 |
|
'finished' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.finished'), |
230
|
|
|
], |
231
|
|
|
'itemsPerPage' => [ |
232
|
1 |
|
'5' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.5'), |
233
|
1 |
|
'10' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.10'), |
234
|
1 |
|
'50' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.50'), |
235
|
1 |
|
'0' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.itemsPerPage.0'), |
236
|
|
|
], |
237
|
|
|
]; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Additions to the function menu array |
242
|
|
|
* |
243
|
|
|
* @return array Menu array |
244
|
|
|
* @deprecated Using BackendModule->modMenu() is deprecated since 9.1.1 and will be removed in v11.x |
245
|
|
|
*/ |
246
|
1 |
|
public function modMenu(): array |
247
|
|
|
{ |
248
|
1 |
|
return $this->getModuleMenu(); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public function main(): string |
252
|
|
|
{ |
253
|
|
|
if (empty($this->pObj->MOD_SETTINGS['processListMode'])) { |
254
|
|
|
$this->pObj->MOD_SETTINGS['processListMode'] = 'simple'; |
255
|
|
|
} |
256
|
|
|
$this->view->assign('currentPageId', $this->id); |
257
|
|
|
|
258
|
|
|
$selectedAction = new CrawlAction($this->pObj->MOD_SETTINGS['crawlaction'] ?? 'start'); |
259
|
|
|
|
260
|
|
|
// Type function menu: |
261
|
|
|
$actionDropdown = BackendUtility::getFuncMenu( |
262
|
|
|
$this->id, |
263
|
|
|
'SET[crawlaction]', |
264
|
|
|
$selectedAction, |
265
|
|
|
$this->pObj->MOD_MENU['crawlaction'] |
266
|
|
|
); |
267
|
|
|
|
268
|
|
|
$theOutput = '<h2>' . htmlspecialchars($this->getLanguageService()->getLL('title')) . '</h2>' . $actionDropdown; |
269
|
|
|
$theOutput .= $this->renderForm($selectedAction); |
270
|
|
|
|
271
|
|
|
return $theOutput; |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
|
275
|
|
|
|
276
|
|
|
/** |
277
|
|
|
* Generates the configuration selectors for compiling URLs: |
278
|
|
|
*/ |
279
|
|
|
protected function generateConfigurationSelectors(): array |
280
|
|
|
{ |
281
|
|
|
$selectors = []; |
282
|
|
|
$selectors['depth'] = $this->selectorBox( |
283
|
|
|
[ |
284
|
|
|
0 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_0'), |
285
|
|
|
1 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_1'), |
286
|
|
|
2 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_2'), |
287
|
|
|
3 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_3'), |
288
|
|
|
4 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_4'), |
289
|
|
|
99 => $this->getLanguageService()->sL('LLL:EXT:core/Resources/Private/Language/locallang_core.xlf:labels.depth_infi'), |
290
|
|
|
], |
291
|
|
|
'SET[depth]', |
292
|
|
|
$this->pObj->MOD_SETTINGS['depth'], |
293
|
|
|
false |
294
|
|
|
); |
295
|
|
|
|
296
|
|
|
// Configurations |
297
|
|
|
$availableConfigurations = $this->crawlerController->getConfigurationsForBranch((int) $this->id, (int) $this->pObj->MOD_SETTINGS['depth'] ?: 0); |
298
|
|
|
$selectors['configurations'] = $this->selectorBox( |
299
|
|
|
empty($availableConfigurations) ? [] : array_combine($availableConfigurations, $availableConfigurations), |
|
|
|
|
300
|
|
|
'configurationSelection', |
301
|
|
|
$this->incomingConfigurationSelection, |
302
|
|
|
true |
303
|
|
|
); |
304
|
|
|
|
305
|
|
|
// Scheduled time: |
306
|
|
|
$selectors['scheduled'] = $this->selectorBox( |
307
|
|
|
[ |
308
|
|
|
'now' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.time.now'), |
309
|
|
|
'midnight' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.time.midnight'), |
310
|
|
|
'04:00' => $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.time.4am'), |
311
|
|
|
], |
312
|
|
|
'tstamp', |
313
|
|
|
GeneralUtility::_POST('tstamp'), |
314
|
|
|
false |
315
|
|
|
); |
316
|
|
|
|
317
|
|
|
return $selectors; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Create the rows for display of the page tree |
322
|
|
|
* For each page a number of rows are shown displaying GET variable configuration |
323
|
|
|
* |
324
|
|
|
* @param array $logEntriesOfPage Log items of one page |
325
|
|
|
* @param string $titleString Title string |
326
|
|
|
* @return string HTML <tr> content (one or more) |
327
|
|
|
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException |
328
|
|
|
*/ |
329
|
|
|
protected function drawLog_addRows(array $logEntriesOfPage, string $titleString): string |
330
|
|
|
{ |
331
|
|
|
$colSpan = 9 |
332
|
|
|
+ ($this->pObj->MOD_SETTINGS['log_resultLog'] ? -1 : 0) |
333
|
|
|
+ ($this->pObj->MOD_SETTINGS['log_feVars'] ? 3 : 0); |
334
|
|
|
|
335
|
|
|
if (! empty($logEntriesOfPage)) { |
336
|
|
|
$setId = (int) GeneralUtility::_GP('setID'); |
337
|
|
|
$refreshIcon = $this->iconFactory->getIcon('actions-system-refresh', Icon::SIZE_SMALL); |
338
|
|
|
// Traverse parameter combinations: |
339
|
|
|
$c = 0; |
340
|
|
|
$content = ''; |
341
|
|
|
foreach ($logEntriesOfPage as $vv) { |
342
|
|
|
// Title column: |
343
|
|
|
if (! $c) { |
344
|
|
|
$titleClm = '<td rowspan="' . count($logEntriesOfPage) . '">' . $titleString . '</td>'; |
345
|
|
|
} else { |
346
|
|
|
$titleClm = ''; |
347
|
|
|
} |
348
|
|
|
|
349
|
|
|
// Result: |
350
|
|
|
$resLog = $this->getResultLog($vv); |
351
|
|
|
|
352
|
|
|
$resultData = $vv['result_data'] ? $this->jsonCompatibilityConverter->convert($vv['result_data']) : []; |
353
|
|
|
$resStatus = $this->getResStatus($resultData); |
354
|
|
|
|
355
|
|
|
// Compile row: |
356
|
|
|
$parameters = $this->jsonCompatibilityConverter->convert($vv['parameters']); |
357
|
|
|
|
358
|
|
|
// Put data into array: |
359
|
|
|
$rowData = []; |
360
|
|
|
if ($this->pObj->MOD_SETTINGS['log_resultLog']) { |
361
|
|
|
$rowData['result_log'] = $resLog; |
362
|
|
|
} else { |
363
|
|
|
$rowData['scheduled'] = ($vv['scheduled'] > 0) ? BackendUtility::datetime($vv['scheduled']) : ' ' . $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.immediate'); |
364
|
|
|
$rowData['exec_time'] = $vv['exec_time'] ? BackendUtility::datetime($vv['exec_time']) : '-'; |
365
|
|
|
} |
366
|
|
|
$rowData['result_status'] = GeneralUtility::fixed_lgd_cs($resStatus, 50); |
367
|
|
|
$url = htmlspecialchars($parameters['url'] ?? $parameters['alturl']); |
368
|
|
|
$rowData['url'] = '<a href="' . $url . '" target="_newWIndow">' . $url . '</a>'; |
369
|
|
|
$rowData['feUserGroupList'] = $parameters['feUserGroupList'] ?: ''; |
370
|
|
|
$rowData['procInstructions'] = is_array($parameters['procInstructions']) ? implode('; ', $parameters['procInstructions']) : ''; |
371
|
|
|
$rowData['set_id'] = (string) $vv['set_id']; |
372
|
|
|
|
373
|
|
|
if ($this->pObj->MOD_SETTINGS['log_feVars']) { |
374
|
|
|
$resFeVars = $this->getResFeVars($resultData ?: []); |
|
|
|
|
375
|
|
|
$rowData['tsfe_id'] = $resFeVars['id'] ?: ''; |
376
|
|
|
$rowData['tsfe_gr_list'] = $resFeVars['gr_list'] ?: ''; |
377
|
|
|
$rowData['tsfe_no_cache'] = $resFeVars['no_cache'] ?: ''; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
$trClass = ''; |
381
|
|
|
$warningIcon = ''; |
382
|
|
|
if ($rowData['exec_time'] !== 0 && $resultData === false) { |
383
|
|
|
$trClass = 'class="bg-danger"'; |
384
|
|
|
$warningIcon = $this->iconFactory->getIcon('actions-ban', Icon::SIZE_SMALL); |
385
|
|
|
} |
386
|
|
|
|
387
|
|
|
// Put rows together: |
388
|
|
|
$content .= ' |
389
|
|
|
<tr ' . $trClass . ' > |
390
|
|
|
' . $titleClm . ' |
391
|
|
|
<td><a href="' . $this->getInfoModuleUrl(['qid_details' => $vv['qid'], 'setID' => $setId]) . '">' . htmlspecialchars((string) $vv['qid']) . '</a></td> |
392
|
|
|
<td><a href="' . $this->getInfoModuleUrl(['qid_read' => $vv['qid'], 'setID' => $setId]) . '">' . $refreshIcon . '</a> ' . $warningIcon . '</td>'; |
393
|
|
|
foreach ($rowData as $fKey => $value) { |
394
|
|
|
if ($fKey === 'url') { |
395
|
|
|
$content .= '<td>' . $value . '</td>'; |
396
|
|
|
} else { |
397
|
|
|
$content .= '<td>' . nl2br(htmlspecialchars(strval($value))) . '</td>'; |
398
|
|
|
} |
399
|
|
|
} |
400
|
|
|
$content .= '</tr>'; |
401
|
|
|
$c++; |
402
|
|
|
|
403
|
|
|
if ($this->CSVExport) { |
404
|
|
|
// Only for CSV (adding qid and scheduled/exec_time if needed): |
405
|
|
|
$rowData['result_log'] = implode('// ', explode(chr(10), $resLog)); |
406
|
|
|
$rowData['qid'] = $vv['qid']; |
407
|
|
|
$rowData['scheduled'] = BackendUtility::datetime($vv['scheduled']); |
408
|
|
|
$rowData['exec_time'] = $vv['exec_time'] ? BackendUtility::datetime($vv['exec_time']) : '-'; |
409
|
|
|
$this->CSVaccu[] = $rowData; |
410
|
|
|
} |
411
|
|
|
} |
412
|
|
|
} else { |
413
|
|
|
// Compile row: |
414
|
|
|
$content = ' |
415
|
|
|
<tr> |
416
|
|
|
<td>' . $titleString . '</td> |
417
|
|
|
<td colspan="' . $colSpan . '"><em>' . $this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.noentries') . '</em></td> |
418
|
|
|
</tr>'; |
419
|
|
|
} |
420
|
|
|
|
421
|
|
|
return $content; |
422
|
|
|
} |
423
|
|
|
|
424
|
|
|
/** |
425
|
|
|
* Find Fe vars |
426
|
|
|
*/ |
427
|
4 |
|
protected function getResFeVars(array $resultData): array |
428
|
|
|
{ |
429
|
4 |
|
if (empty($resultData)) { |
430
|
1 |
|
return []; |
431
|
|
|
} |
432
|
3 |
|
$requestResult = $this->jsonCompatibilityConverter->convert($resultData['content']); |
433
|
3 |
|
return $requestResult['vars'] ?? []; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
/** |
437
|
|
|
* Extract the log information from the current row and retrieve it as formatted string. |
438
|
|
|
* |
439
|
|
|
* @param array $resultRow |
440
|
|
|
* @return string |
441
|
|
|
*/ |
442
|
6 |
|
protected function getResultLog($resultRow) |
443
|
|
|
{ |
444
|
6 |
|
$content = ''; |
445
|
6 |
|
if (is_array($resultRow) && array_key_exists('result_data', $resultRow)) { |
446
|
5 |
|
$requestContent = $this->jsonCompatibilityConverter->convert($resultRow['result_data']) ?: ['content' => '']; |
447
|
5 |
|
if (! array_key_exists('content', $requestContent)) { |
|
|
|
|
448
|
1 |
|
return $content; |
449
|
|
|
} |
450
|
4 |
|
$requestResult = $this->jsonCompatibilityConverter->convert($requestContent['content']); |
451
|
|
|
|
452
|
4 |
|
if (is_array($requestResult) && array_key_exists('log', $requestResult)) { |
453
|
2 |
|
$content = implode(chr(10), $requestResult['log']); |
454
|
|
|
} |
455
|
|
|
} |
456
|
5 |
|
return $content; |
457
|
|
|
} |
458
|
|
|
|
459
|
7 |
|
protected function getResStatus($requestContent): string |
460
|
|
|
{ |
461
|
7 |
|
if (empty($requestContent)) { |
462
|
2 |
|
return '-'; |
463
|
|
|
} |
464
|
5 |
|
if (! array_key_exists('content', $requestContent)) { |
465
|
1 |
|
return 'Content index does not exists in requestContent array'; |
466
|
|
|
} |
467
|
|
|
|
468
|
4 |
|
$requestResult = $this->jsonCompatibilityConverter->convert($requestContent['content']); |
469
|
4 |
|
if (is_array($requestResult)) { |
470
|
3 |
|
if (empty($requestResult['errorlog'])) { |
471
|
1 |
|
return 'OK'; |
472
|
|
|
} |
473
|
2 |
|
return implode("\n", $requestResult['errorlog']); |
474
|
|
|
} |
475
|
|
|
|
476
|
1 |
|
if (is_bool($requestResult)) { |
|
|
|
|
477
|
1 |
|
return 'Error - no info, sorry!'; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
return 'Error: ' . substr(preg_replace('/\s+/', ' ', strip_tags($requestResult)), 0, 10000) . '...'; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
/** |
484
|
|
|
* Returns a link for the panel to enable or disable the crawler |
485
|
|
|
* |
486
|
|
|
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException |
487
|
|
|
*/ |
488
|
|
|
protected function getEnableDisableLink(bool $isCrawlerEnabled): string |
489
|
|
|
{ |
490
|
|
|
if ($isCrawlerEnabled) { |
491
|
|
|
return $this->getLinkButton( |
492
|
|
|
'tx-crawler-stop', |
493
|
|
|
$this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.disablecrawling'), |
494
|
|
|
$this->getInfoModuleUrl(['action' => 'stopCrawling']) |
495
|
|
|
); |
496
|
|
|
} |
497
|
|
|
return $this->getLinkButton( |
498
|
|
|
'tx-crawler-start', |
499
|
|
|
$this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.enablecrawling'), |
500
|
|
|
$this->getInfoModuleUrl(['action' => 'resumeCrawling']) |
501
|
|
|
); |
502
|
|
|
} |
503
|
|
|
|
504
|
|
|
/** |
505
|
|
|
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException |
506
|
|
|
*/ |
507
|
|
|
protected function getModeLink(string $mode): string |
508
|
|
|
{ |
509
|
|
|
if ($mode === 'detail') { |
510
|
|
|
return $this->getLinkButton( |
511
|
|
|
'actions-document-view', |
512
|
|
|
$this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.show.running'), |
513
|
|
|
$this->getInfoModuleUrl(['SET[\'processListMode\']' => 'simple']) |
514
|
|
|
); |
515
|
|
|
} elseif ($mode === 'simple') { |
516
|
|
|
return $this->getLinkButton( |
517
|
|
|
'actions-document-view', |
518
|
|
|
$this->getLanguageService()->sL('LLL:EXT:crawler/Resources/Private/Language/locallang.xlf:labels.show.all'), |
519
|
|
|
$this->getInfoModuleUrl(['SET[\'processListMode\']' => 'detail']) |
520
|
|
|
); |
521
|
|
|
} |
522
|
|
|
return ''; |
523
|
|
|
} |
524
|
|
|
|
525
|
|
|
/** |
526
|
|
|
* Returns the singleton instance of the crawler. |
527
|
|
|
*/ |
528
|
|
|
protected function findCrawler(): CrawlerController |
529
|
|
|
{ |
530
|
|
|
if (! $this->crawlerController instanceof CrawlerController) { |
|
|
|
|
531
|
|
|
$this->crawlerController = GeneralUtility::makeInstance(CrawlerController::class); |
532
|
|
|
} |
533
|
|
|
return $this->crawlerController; |
534
|
|
|
} |
535
|
|
|
|
536
|
|
|
/***************************** |
537
|
|
|
* |
538
|
|
|
* General Helper Functions |
539
|
|
|
* |
540
|
|
|
*****************************/ |
541
|
|
|
|
542
|
|
|
/** |
543
|
|
|
* Create selector box |
544
|
|
|
* |
545
|
|
|
* @param array $optArray Options key(value) => label pairs |
546
|
|
|
* @param string $name Selector box name |
547
|
|
|
* @param string|array $value Selector box value (array for multiple...) |
548
|
|
|
* @param boolean $multiple If set, will draw multiple box. |
549
|
|
|
* |
550
|
|
|
* @return string HTML select element |
551
|
|
|
*/ |
552
|
|
|
protected function selectorBox($optArray, $name, $value, bool $multiple): string |
553
|
|
|
{ |
554
|
|
|
if (! is_string($value) || ! is_array($value)) { |
|
|
|
|
555
|
|
|
$value = ''; |
556
|
|
|
} |
557
|
|
|
|
558
|
|
|
$options = []; |
559
|
|
|
foreach ($optArray as $key => $val) { |
560
|
|
|
$selected = (! $multiple && ! strcmp($value, (string) $key)) || ($multiple && in_array($key, (array) $value, true)); |
|
|
|
|
561
|
|
|
$options[] = ' |
562
|
|
|
<option value="' . $key . '" ' . ($selected ? ' selected="selected"' : '') . '>' . htmlspecialchars($val) . '</option>'; |
563
|
|
|
} |
564
|
|
|
|
565
|
|
|
return '<select class="form-control" name="' . htmlspecialchars($name . ($multiple ? '[]' : '')) . '"' . ($multiple ? ' multiple' : '') . '>' . implode('', $options) . '</select>'; |
566
|
|
|
} |
567
|
|
|
|
568
|
|
|
/** |
569
|
|
|
* Activate hooks |
570
|
|
|
*/ |
571
|
|
|
protected function runRefreshHooks(): void |
572
|
|
|
{ |
573
|
|
|
$crawlerLib = GeneralUtility::makeInstance(CrawlerController::class); |
574
|
|
|
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['crawler']['refresh_hooks'] ?? [] as $objRef) { |
575
|
|
|
/** @var CrawlerHookInterface $hookObj */ |
576
|
|
|
$hookObj = GeneralUtility::makeInstance($objRef); |
577
|
|
|
if (is_object($hookObj)) { |
578
|
|
|
$hookObj->crawler_init($crawlerLib); |
579
|
|
|
} |
580
|
|
|
} |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
protected function initializeView(): void |
584
|
|
|
{ |
585
|
|
|
$view = GeneralUtility::makeInstance(StandaloneView::class); |
586
|
|
|
$view->setLayoutRootPaths(['EXT:crawler/Resources/Private/Layouts']); |
587
|
|
|
$view->setPartialRootPaths(['EXT:crawler/Resources/Private/Partials']); |
588
|
|
|
$view->setTemplateRootPaths(['EXT:crawler/Resources/Private/Templates/Backend']); |
589
|
|
|
$view->getRequest()->setControllerExtensionName('Crawler'); |
590
|
|
|
$this->view = $view; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
protected function getLanguageService(): LanguageService |
594
|
|
|
{ |
595
|
|
|
return $GLOBALS['LANG']; |
596
|
|
|
} |
597
|
|
|
|
598
|
|
|
protected function getLinkButton(string $iconIdentifier, string $title, UriInterface $href): string |
599
|
|
|
{ |
600
|
|
|
$moduleTemplate = GeneralUtility::makeInstance(ModuleTemplate::class); |
601
|
|
|
$buttonBar = $moduleTemplate->getDocHeaderComponent()->getButtonBar(); |
602
|
|
|
return (string) $buttonBar->makeLinkButton() |
603
|
|
|
->setHref((string) $href) |
604
|
|
|
->setIcon($this->iconFactory->getIcon($iconIdentifier, Icon::SIZE_SMALL)) |
605
|
|
|
->setTitle($title) |
606
|
|
|
->setShowLabelText(true); |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* Returns the URL to the current module, including $_GET['id']. |
611
|
|
|
* |
612
|
|
|
* @param array $uriParameters optional parameters to add to the URL |
613
|
|
|
* |
614
|
|
|
* @throws \TYPO3\CMS\Backend\Routing\Exception\RouteNotFoundException |
615
|
|
|
*/ |
616
|
|
|
protected function getInfoModuleUrl(array $uriParameters = []): Uri |
617
|
|
|
{ |
618
|
|
|
if (GeneralUtility::_GP('id')) { |
619
|
|
|
$uriParameters = array_merge($uriParameters, [ |
620
|
|
|
'id' => GeneralUtility::_GP('id'), |
621
|
|
|
]); |
622
|
|
|
} |
623
|
|
|
/** @var UriBuilder $uriBuilder */ |
624
|
|
|
$uriBuilder = GeneralUtility::makeInstance(UriBuilder::class); |
625
|
|
|
return $uriBuilder->buildUriFromRoute('web_info', $uriParameters); |
626
|
|
|
} |
627
|
|
|
|
628
|
|
|
private function renderForm(CrawlAction $selectedAction): string |
629
|
|
|
{ |
630
|
|
|
$requestForm = RequestFormFactory::create($selectedAction, $this->view); |
631
|
|
|
return $requestForm->render( |
632
|
|
|
$this->id, |
633
|
|
|
$this->pObj->MOD_SETTINGS['depth'], |
634
|
|
|
$this->pObj->MOD_MENU['depth'] |
635
|
|
|
); |
636
|
|
|
} |
637
|
|
|
} |
638
|
|
|
|