[CLEANUP] Use comments not PHPDoc style comments in copyright block
[Packages/TYPO3.CMS.git] / typo3 / sysext / linkvalidator / Classes / Report / LinkValidatorReport.php
1 <?php
2 namespace TYPO3\CMS\Linkvalidator\Report;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Backend\Utility\BackendUtility;
18 use TYPO3\CMS\Core\Messaging\FlashMessage;
19 use TYPO3\CMS\Core\Utility\GeneralUtility;
20
21 /**
22 * Module 'Linkvalidator' for the 'linkvalidator' extension
23 *
24 * @author Michael Miousse <michael.miousse@infoglobe.ca>
25 * @author Jochen Rieger <j.rieger@connecta.ag>
26 */
27 class LinkValidatorReport extends \TYPO3\CMS\Backend\Module\AbstractFunctionModule {
28
29 /**
30 * @var \TYPO3\CMS\Backend\Template\DocumentTemplate
31 */
32 public $doc;
33
34 /**
35 * @var string
36 */
37 protected $relativePath;
38
39 /**
40 * Information about the current page record
41 *
42 * @var array
43 */
44 protected $pageRecord = array();
45
46 /**
47 * Information, if the module is accessible for the current user or not
48 *
49 * @var bool
50 */
51 protected $isAccessibleForCurrentUser = FALSE;
52
53 /**
54 * Depth for the recursive traversal of pages for the link validation
55 *
56 * @var int
57 */
58 protected $searchLevel;
59
60 /**
61 * Link validation class
62 *
63 * @var \TYPO3\CMS\Linkvalidator\LinkAnalyzer
64 */
65 protected $processor;
66
67 /**
68 * TSconfig of the current module
69 *
70 * @var array
71 */
72 protected $modTS = array();
73
74 /**
75 * List of available link types to check defined in the TSconfig
76 *
77 * @var array
78 */
79 protected $availableOptions = array();
80
81 /**
82 * List of link types currently chosen in the statistics table
83 * Used to show broken links of these types only
84 *
85 * @var array
86 */
87 protected $checkOpt = array();
88
89 /**
90 * Html for the button "Check Links"
91 *
92 * @var string
93 */
94 protected $updateListHtml;
95
96 /**
97 * Html for the button "Refresh Display"
98 *
99 * @var string
100 */
101 protected $refreshListHtml;
102
103 /**
104 * Html for the statistics table with the checkboxes of the link types
105 * and the numbers of broken links for report tab
106 *
107 * @var string
108 */
109 protected $checkOptHtml;
110
111 /**
112 * Html for the statistics table with the checkboxes of the link types
113 * and the numbers of broken links for check links tab
114 *
115 * @var string
116 */
117 protected $checkOptHtmlCheck;
118
119 /**
120 * Complete content (html) to be displayed
121 *
122 * @var string
123 */
124 protected $content;
125
126 /**
127 * @var \TYPO3\CMS\Core\Page\PageRenderer
128 */
129 protected $pageRenderer;
130
131 /**
132 * @var \TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface[]
133 */
134 protected $hookObjectsArr = array();
135
136 /**
137 * @var string $checkAllHtml
138 */
139 protected $checkAllHtml = '';
140
141 /**
142 * Main method of modfuncreport
143 *
144 * @return string Module content
145 */
146 public function main() {
147 $GLOBALS['LANG']->includeLLFile('EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf');
148 $this->searchLevel = GeneralUtility::_GP('search_levels');
149 if (isset($this->pObj->id)) {
150 $this->modTS = BackendUtility::getModTSconfig($this->pObj->id, 'mod.linkvalidator');
151 $this->modTS = $this->modTS['properties'];
152 }
153 $update = GeneralUtility::_GP('updateLinkList');
154 $prefix = '';
155 if (!empty($update)) {
156 $prefix = 'check';
157 }
158 $set = GeneralUtility::_GP($prefix . 'SET');
159 $this->pObj->handleExternalFunctionValue();
160 if (isset($this->searchLevel)) {
161 $this->pObj->MOD_SETTINGS['searchlevel'] = $this->searchLevel;
162 } else {
163 $this->searchLevel = $this->pObj->MOD_SETTINGS['searchlevel'];
164 }
165 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
166 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $linkType => $value) {
167 // Compile list of all available types. Used for checking with button "Check Links".
168 if (strpos($this->modTS['linktypes'], $linkType) !== FALSE) {
169 $this->availableOptions[$linkType] = 1;
170 }
171 // Compile list of types currently selected by the checkboxes
172 if ($this->pObj->MOD_SETTINGS[$linkType] && empty($set) || $set[$linkType]) {
173 $this->checkOpt[$linkType] = 1;
174 $this->pObj->MOD_SETTINGS[$linkType] = 1;
175 } else {
176 $this->pObj->MOD_SETTINGS[$linkType] = 0;
177 unset($this->checkOpt[$linkType]);
178 }
179 }
180 }
181 $GLOBALS['BE_USER']->pushModuleData('web_info', $this->pObj->MOD_SETTINGS);
182 $this->initialize();
183
184 // Localization
185 $this->pageRenderer->addInlineLanguageLabelFile(
186 \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('linkvalidator', 'Resources/Private/Language/Module/locallang.xlf')
187 );
188 $this->pageRenderer->addJsInlineCode('linkvalidator', 'function toggleActionButton(prefix) {
189 var buttonDisable = true;
190 Ext.select(\'.\' + prefix ,false).each(function(checkBox,i){
191 checkDom = checkBox.dom;
192 if (checkDom.checked){
193 buttonDisable = false;
194 }
195
196 });
197 if (prefix == \'check\'){
198 checkSub = document.getElementById(\'updateLinkList\');
199 } else {
200 checkSub = document.getElementById(\'refreshLinkList\');
201 }
202 checkSub.disabled = buttonDisable;
203 }');
204 // Add JS
205 $this->pageRenderer->addJsFile($this->doc->backPath . 'js/extjs/ux/Ext.ux.FitToParent.js');
206 $this->pageRenderer->addJsFile($this->doc->backPath . 'sysext/backend/Resources/Public/JavaScript/iframepanel.js');
207 if ($this->modTS['showCheckLinkTab'] == 1) {
208 $this->updateListHtml = '<input type="submit" name="updateLinkList" id="updateLinkList" value="' . $GLOBALS['LANG']->getLL('label_update') . '"/>';
209 }
210 $this->refreshListHtml = '<input type="submit" name="refreshLinkList" id="refreshLinkList" value="' . $GLOBALS['LANG']->getLL('label_refresh') . '"/>';
211 $this->processor = GeneralUtility::makeInstance(\TYPO3\CMS\Linkvalidator\LinkAnalyzer::class);
212 $this->updateBrokenLinks();
213 $brokenLinkOverView = $this->processor->getLinkCounts($this->pObj->id);
214 $this->checkOptHtml = $this->getCheckOptions($brokenLinkOverView);
215 $this->checkOptHtmlCheck = $this->getCheckOptions($brokenLinkOverView, 'check');
216 $this->createTabs();
217
218 $content = '';
219 if ($this->pObj->id) {
220 $pageRecord = BackendUtility::getRecord('pages', $this->pObj->id);
221 $content = '<h1>' . htmlspecialchars(BackendUtility::getRecordTitle('pages', $pageRecord)) . '</h1>';
222 }
223
224 $content .= '<div id="linkvalidator-modfuncreport"></div>';
225 return $content;
226 }
227
228 /**
229 * Create TabPanel to split the report and the checkLink functions
230 *
231 * @return void
232 */
233 protected function createTabs() {
234 $panelCheck = '';
235 if ($this->modTS['showCheckLinkTab'] == 1) {
236 $panelCheck = ',
237 {
238 title: TYPO3.l10n.localize(\'CheckLink\'),
239 html: ' . json_encode($this->flush()) . ',
240 }';
241 }
242 $this->render();
243 $js = 'var panel = new Ext.TabPanel( {
244 renderTo: \'linkvalidator-modfuncreport\',
245 id: \'linkvalidator-main\',
246 plain: true,
247 activeTab: 0,
248 bodyStyle: \'padding:10px;\',
249 items : [
250 {
251 autoHeight: true,
252 title: TYPO3.l10n.localize(\'Report\'),
253 html: ' . json_encode($this->flush(TRUE)) . '
254 }' . $panelCheck . '
255 ]
256
257 });
258 ';
259 $this->pageRenderer->addExtOnReadyCode($js);
260 }
261
262 /**
263 * Initializes the menu array internally
264 *
265 * @return array Module menu
266 */
267 public function modMenu() {
268 $modMenu = array(
269 'checkAllLink' => 0
270 );
271 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
272 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $linkType => $value) {
273 $modMenu[$linkType] = 1;
274 }
275 }
276 return $modMenu;
277 }
278
279 /**
280 * Initializes the Module
281 *
282 * @return void
283 */
284 protected function initialize() {
285 if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
286 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $linkType => $classRef) {
287 $this->hookObjectsArr[$linkType] = GeneralUtility::getUserObj($classRef);
288 }
289 }
290 $this->doc = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Template\DocumentTemplate::class);
291 $this->doc->backPath = $GLOBALS['BACK_PATH'];
292 $this->doc->setModuleTemplate(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('linkvalidator') . 'Resources/Private/Templates/mod_template.html');
293 $this->relativePath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('linkvalidator');
294 $this->pageRecord = BackendUtility::readPageAccess($this->pObj->id, $GLOBALS['BE_USER']->getPagePermsClause(1));
295 $this->pageRenderer = $this->doc->getPageRenderer();
296 $this->isAccessibleForCurrentUser = FALSE;
297 if ($this->pObj->id && is_array($this->pageRecord) || !$this->pObj->id && $this->isCurrentUserAdmin()) {
298 $this->isAccessibleForCurrentUser = TRUE;
299 }
300 $this->loadHeaderData();
301 // Don't access in workspace
302 if ($GLOBALS['BE_USER']->workspace !== 0) {
303 $this->isAccessibleForCurrentUser = FALSE;
304 }
305 }
306
307 /**
308 * Updates the table of stored broken links
309 *
310 * @return void
311 */
312 protected function updateBrokenLinks() {
313 $searchFields = array();
314 // Get the searchFields from TypoScript
315 foreach ($this->modTS['searchFields.'] as $table => $fieldList) {
316 $fields = GeneralUtility::trimExplode(',', $fieldList);
317 foreach ($fields as $field) {
318 if (!$searchFields || !is_array($searchFields[$table]) || array_search($field, $searchFields[$table]) == FALSE) {
319 $searchFields[$table][] = $field;
320 }
321 }
322 }
323 $rootLineHidden = $this->processor->getRootLineIsHidden($this->pObj->pageinfo);
324 if (!$rootLineHidden || $this->modTS['checkhidden'] == 1) {
325 // Get children pages
326 $pageList = $this->processor->extGetTreeList($this->pObj->id, $this->searchLevel, 0, $GLOBALS['BE_USER']->getPagePermsClause(1), $this->modTS['checkhidden']);
327 if ($this->pObj->pageinfo['hidden'] == 0 || $this->modTS['checkhidden'] == 1) {
328 $pageList .= $this->pObj->id;
329 }
330 $this->processor->init($searchFields, $pageList, $this->modTS);
331 // Check if button press
332 $update = GeneralUtility::_GP('updateLinkList');
333 if (!empty($update)) {
334 $this->processor->getLinkStatistics($this->checkOpt, $this->modTS['checkhidden']);
335 }
336 }
337 }
338
339 /**
340 * Renders the content of the module
341 *
342 * @return void
343 */
344 protected function render() {
345 if ($this->isAccessibleForCurrentUser) {
346 $this->content = $this->renderBrokenLinksTable();
347 } else {
348 // If no access or if ID == zero
349 /** @var FlashMessage $message */
350 $message = GeneralUtility::makeInstance(
351 FlashMessage::class,
352 $GLOBALS['LANG']->getLL('no.access'),
353 $GLOBALS['LANG']->getLL('no.access.title'),
354 FlashMessage::ERROR
355 );
356 $this->content .= $message->render();
357 }
358 }
359
360 /**
361 * Flushes the rendered content to the browser
362 *
363 * @param bool $form
364 * @return string $content
365 */
366 protected function flush($form = FALSE) {
367 $content = $this->doc->moduleBody(
368 $this->pageRecord,
369 $this->getDocHeaderButtons(),
370 $form ? $this->getTemplateMarkers() : $this->getTemplateMarkersCheck()
371 );
372 return $content;
373 }
374
375 /**
376 * Builds the selector for the level of pages to search
377 *
378 * @return string Html code of that selector
379 */
380 protected function getLevelSelector() {
381 // Build level selector
382 $opt = array();
383 $parts = array(
384 0 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_0'),
385 1 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_1'),
386 2 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_2'),
387 3 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_3'),
388 999 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xlf:labels.depth_infi')
389 );
390 foreach ($parts as $kv => $label) {
391 $opt[] = '<option value="' . $kv . '"' . ($kv == (int)$this->searchLevel ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
392 }
393 $lMenu = '<select name="search_levels">' . implode('', $opt) . '</select>';
394 return $lMenu;
395 }
396
397 /**
398 * Displays the table of broken links or a note if there were no broken links
399 *
400 * @return string Content of the table or of the note
401 */
402 protected function renderBrokenLinksTable() {
403 $items = ($brokenLinksMarker = array());
404 $brokenLinkItems = '';
405 $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###NOBROKENLINKS_CONTENT###');
406 $keyOpt = array();
407 if (is_array($this->checkOpt)) {
408 $keyOpt = array_keys($this->checkOpt);
409 }
410 $rootLineHidden = $this->processor->getRootLineIsHidden($this->pObj->pageinfo);
411 if (!$rootLineHidden || $this->modTS['checkhidden'] == 1) {
412 $pageList = $this->processor->extGetTreeList(
413 $this->pObj->id,
414 $this->searchLevel,
415 0,
416 $GLOBALS['BE_USER']->getPagePermsClause(1),
417 $this->modTS['checkhidden']
418 );
419 // Always add the current page, because we are just displaying the results
420 $pageList .= $this->pObj->id;
421 if (($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
422 '*',
423 'tx_linkvalidator_link',
424 'record_pid in (' . $pageList . ') and link_type in (\'' . implode('\',\'', $keyOpt) . '\')',
425 '',
426 'record_uid ASC, uid ASC')
427 )) {
428 // Display table with broken links
429 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
430 $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_CONTENT###');
431 $brokenLinksItemTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_ITEM###');
432 // Table header
433 $brokenLinksMarker = $this->startTable();
434 // Table rows containing the broken links
435 while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
436 $items[] = $this->renderTableRow($row['table_name'], $row, $brokenLinksItemTemplate);
437 }
438 $brokenLinkItems = implode(LF, $items);
439 } else {
440 $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker);
441 }
442 $GLOBALS['TYPO3_DB']->sql_free_result($res);
443 }
444 } else {
445 $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker);
446 }
447 $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray(
448 $brokenLinksTemplate,
449 $brokenLinksMarker, '###|###',
450 TRUE
451 );
452 $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($brokenLinksTemplate, '###BROKENLINKS_ITEM', $brokenLinkItems);
453 return $content;
454 }
455
456 /**
457 * Replace $brokenLinksMarker['NO_BROKEN_LINKS] with localized flashmessage
458 *
459 * @param array $brokenLinksMarker
460 * @return array $brokenLinksMarker['NO_BROKEN_LINKS] replaced with flashmessage
461 */
462 protected function getNoBrokenLinkMessage(array $brokenLinksMarker) {
463 $brokenLinksMarker['LIST_HEADER'] = $this->doc->sectionHeader($GLOBALS['LANG']->getLL('list.header'));
464 /** @var $message FlashMessage */
465 $message = GeneralUtility::makeInstance(
466 FlashMessage::class,
467 $GLOBALS['LANG']->getLL('list.no.broken.links'),
468 $GLOBALS['LANG']->getLL('list.no.broken.links.title'),
469 FlashMessage::OK
470 );
471 $brokenLinksMarker['NO_BROKEN_LINKS'] = $message->render();
472 return $brokenLinksMarker;
473 }
474
475 /**
476 * Displays the table header of the table with the broken links
477 *
478 * @return string Code of content
479 */
480 protected function startTable() {
481 // Listing head
482 $makerTableHead = array();
483 $makerTableHead['tablehead_path'] = $GLOBALS['LANG']->getLL('list.tableHead.path');
484 $makerTableHead['tablehead_element'] = $GLOBALS['LANG']->getLL('list.tableHead.element');
485 $makerTableHead['tablehead_headlink'] = $GLOBALS['LANG']->getLL('list.tableHead.headlink');
486 $makerTableHead['tablehead_linktarget'] = $GLOBALS['LANG']->getLL('list.tableHead.linktarget');
487 $makerTableHead['tablehead_linkmessage'] = $GLOBALS['LANG']->getLL('list.tableHead.linkmessage');
488 $makerTableHead['tablehead_lastcheck'] = $GLOBALS['LANG']->getLL('list.tableHead.lastCheck');
489 // Add CSH to the header of each column
490 foreach ($makerTableHead as $column => $label) {
491 $label = BackendUtility::wrapInHelp('linkvalidator', $column, $label);
492 $makerTableHead[$column] = $label;
493 }
494 // Add section header
495 $makerTableHead['list_header'] = $this->doc->sectionHeader($GLOBALS['LANG']->getLL('list.header'));
496 return $makerTableHead;
497 }
498
499 /**
500 * Displays one line of the broken links table
501 *
502 * @param string $table Name of database table
503 * @param array $row Record row to be processed
504 * @param array $brokenLinksItemTemplate Markup of the template to be used
505 * @return string HTML of the rendered row
506 */
507 protected function renderTableRow($table, array $row, $brokenLinksItemTemplate) {
508 $markerArray = array();
509 $fieldName = '';
510 // Restore the linktype object
511 $hookObj = $this->hookObjectsArr[$row['link_type']];
512 $brokenUrl = $hookObj->getBrokenUrl($row);
513 // Construct link to edit the content element
514 $params = '&edit[' . $table . '][' . $row['record_uid'] . ']=edit';
515 $requestUri = GeneralUtility::getIndpEnv('REQUEST_URI') .
516 '?id=' . $this->pObj->id .
517 '&search_levels=' . $this->searchLevel;
518 $actionLink = '<a href="#" onclick="';
519 $actionLink .= BackendUtility::editOnClick(
520 $params,
521 $GLOBALS['BACK_PATH'],
522 $requestUri
523 );
524 $actionLink .= '" title="' . $GLOBALS['LANG']->getLL('list.edit') . '">';
525 $actionLink .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open');
526 $actionLink .= '</a>';
527 $elementHeadline = $row['headline'];
528 if (empty($elementHeadline)) {
529 $elementHeadline = '<i>' . $GLOBALS['LANG']->getLL('list.no.headline') . '</i>';
530 }
531 // Get the language label for the field from TCA
532 if ($GLOBALS['TCA'][$table]['columns'][$row['field']]['label']) {
533 $fieldName = $GLOBALS['TCA'][$table]['columns'][$row['field']]['label'];
534 $fieldName = $GLOBALS['LANG']->sL($fieldName);
535 // Crop colon from end if present
536 if (substr($fieldName, '-1', '1') === ':') {
537 $fieldName = substr($fieldName, '0', strlen($fieldName) - 1);
538 }
539 }
540 // Fallback, if there is no label
541 $fieldName = !empty($fieldName) ? $fieldName : $row['field'];
542 // column "Element"
543 $element = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord(
544 $table,
545 $row,
546 array('title' => $table . ':' . $row['record_uid'])
547 );
548 $element .= $elementHeadline;
549 $element .= ' ' . sprintf($GLOBALS['LANG']->getLL('list.field'), $fieldName);
550 $markerArray['actionlink'] = $actionLink;
551 $markerArray['path'] = BackendUtility::getRecordPath($row['record_pid'], '', 0, 0);
552 $markerArray['element'] = $element;
553 $markerArray['headlink'] = $row['link_title'];
554 $markerArray['linktarget'] = $brokenUrl;
555 $response = unserialize($row['url_response']);
556 if ($response['valid']) {
557 $linkMessage = '<span style="color: green;">' . $GLOBALS['LANG']->getLL('list.msg.ok') . '</span>';
558 } else {
559 $linkMessage = '<span style="color: red;">' . $hookObj->getErrorMessage($response['errorParams']) . '</span>';
560 }
561 $markerArray['linkmessage'] = $linkMessage;
562 $lastRunDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $row['last_check']);
563 $lastRunTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $row['last_check']);
564 $message = sprintf($GLOBALS['LANG']->getLL('list.msg.lastRun'), $lastRunDate, $lastRunTime);
565 $markerArray['lastcheck'] = $message;
566 // Return the table html code as string
567 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($brokenLinksItemTemplate, $markerArray, '###|###', TRUE, TRUE);
568 }
569
570 /**
571 * Builds the checkboxes out of the hooks array
572 *
573 * @param array $brokenLinkOverView Array of broken links information
574 * @param string $prefix
575 * @return string code content
576 */
577 protected function getCheckOptions(array $brokenLinkOverView, $prefix = '') {
578 $markerArray = array();
579 $additionalAttr = '';
580 if (!empty($prefix)) {
581 $additionalAttr = ' onclick="toggleActionButton(\'' . $prefix . '\');" class="' . $prefix . '" ';
582 } else {
583 $additionalAttr = ' onclick="toggleActionButton(\'refresh\');" class="refresh" ';
584 }
585 $checkOptionsTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###CHECKOPTIONS_SECTION###');
586 $hookSectionTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($checkOptionsTemplate, '###HOOK_SECTION###');
587 $markerArray['statistics_header'] = $this->doc->sectionHeader($GLOBALS['LANG']->getLL('report.statistics.header'));
588 $totalCountLabel = $GLOBALS['LANG']->getLL('overviews.nbtotal');
589 $totalCountLabel = BackendUtility::wrapInHelp('linkvalidator', 'checkboxes', $totalCountLabel);
590 $markerArray['total_count_label'] = $totalCountLabel;
591 if (empty($brokenLinkOverView['brokenlinkCount'])) {
592 $markerArray['total_count'] = '0';
593 } else {
594 $markerArray['total_count'] = $brokenLinkOverView['brokenlinkCount'];
595 }
596 $linktypes = GeneralUtility::trimExplode(',', $this->modTS['linktypes'], TRUE);
597 $hookSectionContent = '';
598 if (is_array($linktypes)) {
599 if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])
600 && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
601 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $type => $value) {
602 if (in_array($type, $linktypes)) {
603 $hookSectionMarker = array();
604 if (empty($brokenLinkOverView[$type])) {
605 $hookSectionMarker['count'] = '0';
606 } else {
607 $hookSectionMarker['count'] = $brokenLinkOverView[$type];
608 }
609 $translation = $GLOBALS['LANG']->getLL('hooks.' . $type);
610 $translation = $translation ? $translation : $type;
611 $option = '<input type="checkbox" ' . $additionalAttr . ' id="' . $prefix . 'SET_' . $type . '" name="' . $prefix . 'SET[' . $type . ']" value="1"' . ($this->pObj->MOD_SETTINGS[$type] ? ' checked="checked"' : '') . '/>' . '<label for="' . $prefix . 'SET[' . $type . ']">' . htmlspecialchars($translation) . '</label>';
612 $hookSectionMarker['option'] = $option;
613 $hookSectionContent .= \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray(
614 $hookSectionTemplate,
615 $hookSectionMarker, '###|###',
616 TRUE,
617 TRUE
618 );
619 }
620 }
621 }
622 }
623 $checkOptionsTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart(
624 $checkOptionsTemplate,
625 '###HOOK_SECTION###', $hookSectionContent
626 );
627 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($checkOptionsTemplate, $markerArray, '###|###', TRUE, TRUE);
628 }
629
630 /**
631 * Loads data in the HTML head section (e.g. JavaScript or stylesheet information)
632 *
633 * @return void
634 */
635 protected function loadHeaderData() {
636 $this->doc->addStyleSheet('linkvalidator', $this->relativePath . 'Resources/Public/Css/linkvalidator.css', 'linkvalidator');
637 $this->pageRenderer->addJsFile($this->doc->backPath . 'js/extjs/ux/Ext.ux.FitToParent.js');
638 }
639
640 /**
641 * Gets the buttons that shall be rendered in the docHeader
642 *
643 * @return array Available buttons for the docHeader
644 */
645 protected function getDocHeaderButtons() {
646 $buttons = array(
647 'csh' => BackendUtility::cshItem('_MOD_web_func', ''),
648 'shortcut' => $this->getShortcutButton(),
649 'save' => ''
650 );
651 return $buttons;
652 }
653
654 /**
655 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
656 *
657 * @return string HTML representation of the shortcut button
658 */
659 protected function getShortcutButton() {
660 $result = '';
661 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
662 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
663 }
664 return $result;
665 }
666
667 /**
668 * Gets the filled markers that are used in the HTML template
669 *
670 * @return array The filled marker array
671 */
672 protected function getTemplateMarkers() {
673 $markers = array(
674 'FUNC_TITLE' => $GLOBALS['LANG']->getLL('report.func.title'),
675 'CHECKOPTIONS_TITLE' => $GLOBALS['LANG']->getLL('report.statistics.header'),
676 'FUNC_MENU' => $this->getLevelSelector(),
677 'CONTENT' => $this->content,
678 'CHECKALLLINK' => $this->checkAllHtml,
679 'CHECKOPTIONS' => $this->checkOptHtml,
680 'ID' => '<input type="hidden" name="id" value="' . $this->pObj->id . '" />',
681 'REFRESH' => $this->refreshListHtml,
682 'UPDATE' => ''
683 );
684 return $markers;
685 }
686
687 /**
688 * Gets the filled markers that are used in the HTML template
689 *
690 * @return array The filled marker array
691 */
692 protected function getTemplateMarkersCheck() {
693 $markers = array(
694 'FUNC_TITLE' => $GLOBALS['LANG']->getLL('checklinks.func.title'),
695 'CHECKOPTIONS_TITLE' => $GLOBALS['LANG']->getLL('checklinks.statistics.header'),
696 'FUNC_MENU' => $this->getLevelSelector(),
697 'CONTENT' => '',
698 'CHECKALLLINK' => $this->checkAllHtml,
699 'CHECKOPTIONS' => $this->checkOptHtmlCheck,
700 'ID' => '<input type="hidden" name="id" value="' . $this->pObj->id . '" />',
701 'REFRESH' => '',
702 'UPDATE' => $this->updateListHtml
703 );
704 return $markers;
705 }
706
707 /**
708 * Determines whether the current user is an admin
709 *
710 * @return bool Whether the current user is admin
711 */
712 protected function isCurrentUserAdmin() {
713 return (bool)$GLOBALS['BE_USER']->user['admin'];
714 }
715
716 }