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