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