[TASK] Cleanup new files
[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 - 2012 Jochen Rieger (j.rieger@connecta.ag)
8 * (c) 2010 - 2012 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 \TYPO3\CMS\Core\Page\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 \TYPO3\CMS\Linkvalidator\Linktype\LinktypeInterface[]
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(
356 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
357 $GLOBALS['LANG']->getLL('no.access'),
358 $GLOBALS['LANG']->getLL('no.access.title'),
359 \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR
360 );
361 $this->content .= $message->render();
362 }
363 }
364
365 /**
366 * Flushes the rendered content to the browser
367 *
368 * @param boolean $form
369 * @return string $content
370 */
371 protected function flush($form = FALSE) {
372 $content = $this->doc->moduleBody(
373 $this->pageRecord,
374 $this->getDocHeaderButtons(),
375 $form ? $this->getTemplateMarkers() : $this->getTemplateMarkersCheck()
376 );
377 return $content;
378 }
379
380 /**
381 * Builds the selector for the level of pages to search
382 *
383 * @return string Html code of that selector
384 */
385 protected function getLevelSelector() {
386 // Build level selector
387 $opt = array();
388 $parts = array(
389 0 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_0'),
390 1 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_1'),
391 2 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_2'),
392 3 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_3'),
393 999 => $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.xml:labels.depth_infi')
394 );
395 foreach ($parts as $kv => $label) {
396 $opt[] = '<option value="' . $kv . '"' . ($kv == intval($this->searchLevel) ? ' selected="selected"' : '') . '>' . htmlspecialchars($label) . '</option>';
397 }
398 $lMenu = '<select name="search_levels">' . implode('', $opt) . '</select>';
399 return $lMenu;
400 }
401
402 /**
403 * Displays the table of broken links or a note if there were no broken links
404 *
405 * @return string Content of the table or of the note
406 */
407 protected function renderBrokenLinksTable() {
408 $items = ($brokenLinksMarker = array());
409 $brokenLinkItems = '';
410 $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###NOBROKENLINKS_CONTENT###');
411 $keyOpt = array();
412 if (is_array($this->checkOpt)) {
413 $keyOpt = array_keys($this->checkOpt);
414 }
415 $rootLineHidden = $this->processor->getRootLineIsHidden($this->pObj->pageinfo);
416 if (!$rootLineHidden || $this->modTS['checkhidden'] == 1) {
417 $pageList = $this->processor->extGetTreeList(
418 $this->pObj->id,
419 $this->searchLevel,
420 0,
421 $GLOBALS['BE_USER']->getPagePermsClause(1),
422 $this->modTS['checkhidden']
423 );
424 // Always add the current page, because we are just displaying the results
425 $pageList .= $this->pObj->id;
426 if (($res = $GLOBALS['TYPO3_DB']->exec_SELECTquery(
427 '*',
428 'tx_linkvalidator_link',
429 'record_pid in (' . $pageList . ') and link_type in (\'' . implode('\',\'', $keyOpt) . '\')',
430 '',
431 'record_uid ASC, uid ASC')
432 )) {
433 // Display table with broken links
434 if ($GLOBALS['TYPO3_DB']->sql_num_rows($res) > 0) {
435 $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_CONTENT###');
436 $brokenLinksItemTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###BROKENLINKS_ITEM###');
437 // Table header
438 $brokenLinksMarker = $this->startTable();
439 // Table rows containing the broken links
440 while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) !== FALSE) {
441 $items[] = $this->renderTableRow($row['table_name'], $row, $brokenLinksItemTemplate);
442 }
443 $brokenLinkItems = implode(chr(10), $items);
444 } else {
445 $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker);
446 }
447 }
448 } else {
449 $brokenLinksMarker = $this->getNoBrokenLinkMessage($brokenLinksMarker);
450 }
451 $brokenLinksTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray(
452 $brokenLinksTemplate,
453 $brokenLinksMarker, '###|###',
454 TRUE
455 );
456 $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart($brokenLinksTemplate, '###BROKENLINKS_ITEM', $brokenLinkItems);
457 return $content;
458 }
459
460 /**
461 * Replace $brokenLinksMarker['NO_BROKEN_LINKS] with localized flashmessage
462 *
463 * @param array $brokenLinksMarker
464 * @return array $brokenLinksMarker['NO_BROKEN_LINKS] replaced with flashmessage
465 */
466 protected function getNoBrokenLinkMessage(array $brokenLinksMarker) {
467 $brokenLinksMarker['LIST_HEADER'] = $this->doc->sectionHeader($GLOBALS['LANG']->getLL('list.header'));
468 /** @var \TYPO3\CMS\Core\Messaging\FlashMessage $message */
469 $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(
470 'TYPO3\\CMS\\Core\\Messaging\\FlashMessage',
471 $GLOBALS['LANG']->getLL('list.no.broken.links'),
472 $GLOBALS['LANG']->getLL('list.no.broken.links.title'),
473 \TYPO3\CMS\Core\Messaging\FlashMessage::OK
474 );
475 $brokenLinksMarker['NO_BROKEN_LINKS'] = $message->render();
476 return $brokenLinksMarker;
477 }
478
479 /**
480 * Displays the table header of the table with the broken links
481 *
482 * @return string Code of content
483 */
484 protected function startTable() {
485 // Listing head
486 $makerTableHead = array();
487 $makerTableHead['tablehead_path'] = $GLOBALS['LANG']->getLL('list.tableHead.path');
488 $makerTableHead['tablehead_element'] = $GLOBALS['LANG']->getLL('list.tableHead.element');
489 $makerTableHead['tablehead_headlink'] = $GLOBALS['LANG']->getLL('list.tableHead.headlink');
490 $makerTableHead['tablehead_linktarget'] = $GLOBALS['LANG']->getLL('list.tableHead.linktarget');
491 $makerTableHead['tablehead_linkmessage'] = $GLOBALS['LANG']->getLL('list.tableHead.linkmessage');
492 $makerTableHead['tablehead_lastcheck'] = $GLOBALS['LANG']->getLL('list.tableHead.lastCheck');
493 // Add CSH to the header of each column
494 foreach ($makerTableHead as $column => $label) {
495 $label = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', $column, $label);
496 $makerTableHead[$column] = $label;
497 }
498 // Add section header
499 $makerTableHead['list_header'] = $this->doc->sectionHeader($GLOBALS['LANG']->getLL('list.header'));
500 return $makerTableHead;
501 }
502
503 /**
504 * Displays one line of the broken links table
505 *
506 * @param string $table Name of database table
507 * @param array $row Record row to be processed
508 * @param array $brokenLinksItemTemplate Markup of the template to be used
509 * @return string HTML of the rendered row
510 */
511 protected function renderTableRow($table, array $row, $brokenLinksItemTemplate) {
512 $markerArray = array();
513 $fieldName = '';
514 // Restore the linktype object
515 $hookObj = $this->hookObjectsArr[$row['link_type']];
516 $brokenUrl = $hookObj->getBrokenUrl($row);
517 // Construct link to edit the content element
518 $params = '&edit[' . $table . '][' . $row['record_uid'] . ']=edit';
519 $requestUri = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('REQUEST_URI') .
520 '?id=' . $this->pObj->id .
521 '&search_levels=' . $this->searchLevel;
522 $actionLink = '<a href="#" onclick="';
523 $actionLink .= \TYPO3\CMS\Backend\Utility\BackendUtility::editOnClick(
524 $params,
525 $GLOBALS['BACK_PATH'],
526 $requestUri
527 );
528 $actionLink .= '" title="' . $GLOBALS['LANG']->getLL('list.edit') . '">';
529 $actionLink .= \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open');
530 $actionLink .= '</a>';
531 $elementHeadline = $row['headline'];
532 if (empty($elementHeadline)) {
533 $elementHeadline = '<i>' . $GLOBALS['LANG']->getLL('list.no.headline') . '</i>';
534 }
535 // Get the language label for the field from TCA
536 if ($GLOBALS['TCA'][$table]['columns'][$row['field']]['label']) {
537 $fieldName = $GLOBALS['TCA'][$table]['columns'][$row['field']]['label'];
538 $fieldName = $GLOBALS['LANG']->sL($fieldName);
539 // Crop colon from end if present
540 if (substr($fieldName, '-1', '1') === ':') {
541 $fieldName = substr($fieldName, '0', strlen($fieldName) - 1);
542 }
543 }
544 // Fallback, if there is no label
545 $fieldName = !empty($fieldName) ? $fieldName : $row['field'];
546 // column "Element"
547 $element = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord(
548 $table,
549 $row,
550 array('title' => $table . ':' . $row['record_uid'])
551 );
552 $element .= $elementHeadline;
553 $element .= ' ' . sprintf($GLOBALS['LANG']->getLL('list.field'), $fieldName);
554 $markerArray['actionlink'] = $actionLink;
555 $markerArray['path'] = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecordPath($row['record_pid'], '', 0, 0);
556 $markerArray['element'] = $element;
557 $markerArray['headlink'] = $row['link_title'];
558 $markerArray['linktarget'] = $brokenUrl;
559 $response = unserialize($row['url_response']);
560 if ($response['valid']) {
561 $linkMessage = '<span style="color: green;">' . $GLOBALS['LANG']->getLL('list.msg.ok') . '</span>';
562 } else {
563 $linkMessage = '<span style="color: red;">' . $hookObj->getErrorMessage($response['errorParams']) . '</span>';
564 }
565 $markerArray['linkmessage'] = $linkMessage;
566 $lastRunDate = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $row['last_check']);
567 $lastRunTime = date($GLOBALS['TYPO3_CONF_VARS']['SYS']['hhmm'], $row['last_check']);
568 $message = sprintf($GLOBALS['LANG']->getLL('list.msg.lastRun'), $lastRunDate, $lastRunTime);
569 $markerArray['lastcheck'] = $message;
570 // Return the table html code as string
571 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($brokenLinksItemTemplate, $markerArray, '###|###', TRUE, TRUE);
572 }
573
574 /**
575 * Builds the checkboxes out of the hooks array
576 *
577 * @param array $brokenLinkOverView Array of broken links information
578 * @param string $prefix
579 * @return string code content
580 */
581 protected function getCheckOptions(array $brokenLinkOverView, $prefix = '') {
582 $markerArray = array();
583 $additionalAttr = '';
584 if (!empty($prefix)) {
585 $additionalAttr = ' onclick="toggleActionButton(\'' . $prefix . '\');" class="' . $prefix . '" ';
586 } else {
587 $additionalAttr = ' onclick="toggleActionButton(\'refresh\');" class="refresh" ';
588 }
589 $checkOptionsTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($this->doc->moduleTemplate, '###CHECKOPTIONS_SECTION###');
590 $hookSectionTemplate = \TYPO3\CMS\Core\Html\HtmlParser::getSubpart($checkOptionsTemplate, '###HOOK_SECTION###');
591 $markerArray['statistics_header'] = $this->doc->sectionHeader($GLOBALS['LANG']->getLL('report.statistics.header'));
592 $totalCountLabel = $GLOBALS['LANG']->getLL('overviews.nbtotal');
593 $totalCountLabel = \TYPO3\CMS\Backend\Utility\BackendUtility::wrapInHelp('linkvalidator', 'checkboxes', $totalCountLabel);
594 $markerArray['total_count_label'] = $totalCountLabel;
595 if (empty($brokenLinkOverView['brokenlinkCount'])) {
596 $markerArray['total_count'] = '0';
597 } else {
598 $markerArray['total_count'] = $brokenLinkOverView['brokenlinkCount'];
599 }
600 $linktypes = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $this->modTS['linktypes'], 1);
601 $hookSectionContent = '';
602 if (is_array($linktypes)) {
603 if (!empty($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])
604 && is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
605 foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $type => $value) {
606 if (in_array($type, $linktypes)) {
607 $hookSectionMarker = array();
608 if (empty($brokenLinkOverView[$type])) {
609 $hookSectionMarker['count'] = '0';
610 } else {
611 $hookSectionMarker['count'] = $brokenLinkOverView[$type];
612 }
613 $translation = $GLOBALS['LANG']->getLL('hooks.' . $type);
614 $translation = $translation ? $translation : $type;
615 $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>';
616 $hookSectionMarker['option'] = $option;
617 $hookSectionContent .= \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray(
618 $hookSectionTemplate,
619 $hookSectionMarker, '###|###',
620 TRUE,
621 TRUE
622 );
623 }
624 }
625 }
626 }
627 $checkOptionsTemplate = \TYPO3\CMS\Core\Html\HtmlParser::substituteSubpart(
628 $checkOptionsTemplate,
629 '###HOOK_SECTION###', $hookSectionContent
630 );
631 return \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($checkOptionsTemplate, $markerArray, '###|###', TRUE, TRUE);
632 }
633
634 /**
635 * Loads data in the HTML head section (e.g. JavaScript or stylesheet information)
636 *
637 * @return void
638 */
639 protected function loadHeaderData() {
640 $this->doc->addStyleSheet('linkvalidator', $this->relativePath . 'res/linkvalidator.css', 'linkvalidator');
641 $this->doc->getPageRenderer()->addJsFile($this->doc->backPath . '../t3lib/js/extjs/ux/Ext.ux.FitToParent.js');
642 }
643
644 /**
645 * Gets the buttons that shall be rendered in the docHeader
646 *
647 * @return array Available buttons for the docHeader
648 */
649 protected function getDocHeaderButtons() {
650 $buttons = array(
651 'csh' => \TYPO3\CMS\Backend\Utility\BackendUtility::cshItem('_MOD_web_func', '', $GLOBALS['BACK_PATH']),
652 'shortcut' => $this->getShortcutButton(),
653 'save' => ''
654 );
655 return $buttons;
656 }
657
658 /**
659 * Gets the button to set a new shortcut in the backend (if current user is allowed to).
660 *
661 * @return string HTML representation of the shortcut button
662 */
663 protected function getShortcutButton() {
664 $result = '';
665 if ($GLOBALS['BE_USER']->mayMakeShortcut()) {
666 $result = $this->doc->makeShortcutIcon('', 'function', $this->MCONF['name']);
667 }
668 return $result;
669 }
670
671 /**
672 * Gets the filled markers that are used in the HTML template
673 *
674 * @return array The filled marker array
675 */
676 protected function getTemplateMarkers() {
677 $markers = array(
678 'FUNC_TITLE' => $GLOBALS['LANG']->getLL('report.func.title'),
679 'CHECKOPTIONS_TITLE' => $GLOBALS['LANG']->getLL('report.statistics.header'),
680 'FUNC_MENU' => $this->getLevelSelector(),
681 'CONTENT' => $this->content,
682 'CHECKALLLINK' => $this->checkAllHtml,
683 'CHECKOPTIONS' => $this->checkOptHtml,
684 'ID' => '<input type="hidden" name="id" value="' . $this->pObj->id . '" />',
685 'REFRESH' => $this->refreshListHtml,
686 'UPDATE' => ''
687 );
688 return $markers;
689 }
690
691 /**
692 * Gets the filled markers that are used in the HTML template
693 *
694 * @return array The filled marker array
695 */
696 protected function getTemplateMarkersCheck() {
697 $markers = array(
698 'FUNC_TITLE' => $GLOBALS['LANG']->getLL('checklinks.func.title'),
699 'CHECKOPTIONS_TITLE' => $GLOBALS['LANG']->getLL('checklinks.statistics.header'),
700 'FUNC_MENU' => $this->getLevelSelector(),
701 'CONTENT' => '',
702 'CHECKALLLINK' => $this->checkAllHtml,
703 'CHECKOPTIONS' => $this->checkOptHtmlCheck,
704 'ID' => '<input type="hidden" name="id" value="' . $this->pObj->id . '" />',
705 'REFRESH' => '',
706 'UPDATE' => $this->updateListHtml
707 );
708 return $markers;
709 }
710
711 /**
712 * Determines whether the current user is an admin
713 *
714 * @return boolean Whether the current user is admin
715 */
716 protected function isCurrentUserAdmin() {
717 return (bool) $GLOBALS['BE_USER']->user['admin'];
718 }
719
720 }
721
722
723 ?>