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