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