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