Skip to content

Commit

Permalink
[BUGFIX] Fix linktype selection in Linkvalidator report
Browse files Browse the repository at this point in the history
* handle uninitialized values
* do not show all results in report if no linktypes checked

Resolves: #84010
Releases: master, 8.7
Change-Id: Id04d2eed1b1390f2cbf67fd971d7cc4d61539f15
Reviewed-on: https://review.typo3.org/55966
Reviewed-by: Sybille Peters <sypets@gmx.de>
Tested-by: Sybille Peters <sypets@gmx.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
sypets authored and lolli42 committed Mar 1, 2018
1 parent ddee255 commit 8fa73fb
Showing 1 changed file with 56 additions and 25 deletions.
81 changes: 56 additions & 25 deletions typo3/sysext/linkvalidator/Classes/Report/LinkValidatorReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,6 @@ class LinkValidatorReport extends \TYPO3\CMS\Backend\Module\AbstractFunctionModu
*/
protected $isAccessibleForCurrentUser = false;

/**
* Depth for the recursive traversal of pages for the link validation
* For "Report" and "Check link" tab.
*
* @var array
*/
protected $searchLevel = ['report' => 0, 'check' => 0];

/**
* Link validation class
*
Expand All @@ -81,21 +73,31 @@ class LinkValidatorReport extends \TYPO3\CMS\Backend\Module\AbstractFunctionModu
*/
protected $availableOptions = [];

/**
* Depth for the recursive traversal of pages for the link validation
* For "Report" and "Check link" tab.
*
* @var array
*/
protected $searchLevel = ['report' => 0, 'check' => 0];

/**
* List of link types currently chosen in the statistics table
* Used to show broken links of these types only
* For "Report" and "Check link" tab
*
* @var array
*/
protected $checkOpt = [];
protected $checkOpt = ['report' => [], 'check' => []];

/**
* Html for the statistics table with the checkboxes of the link types
* and the numbers of broken links for report / check links tab
* and the numbers of broken links
* For "Report" and "Check link" tab
*
* @var array
*/
protected $checkOptionsHtml = [];
protected $checkOptionsHtml = ['report' => [], 'check' => []];

/**
* Complete content (html) to be displayed
Expand Down Expand Up @@ -147,13 +149,12 @@ public function main()
$other = 'check';
}

// get searchLevel (number of levels of pages to check / show results)
$this->searchLevel[$prefix] = GeneralUtility::_GP($prefix . '_search_levels');
if (isset($this->pObj->id)) {
$this->modTS = BackendUtility::getModTSconfig($this->pObj->id, 'mod.linkvalidator');
$this->modTS = $this->modTS['properties'];
}
$set = GeneralUtility::_GP($prefix . '_SET');
$this->pObj->handleExternalFunctionValue();
if (isset($this->searchLevel[$prefix])) {
$this->pObj->MOD_SETTINGS[$prefix . '_searchlevel'] = $this->searchLevel[$prefix];
} else {
Expand All @@ -162,22 +163,43 @@ public function main()
if (isset($this->pObj->MOD_SETTINGS[$other . '_searchlevel'])) {
$this->searchLevel[$other] = $this->pObj->MOD_SETTINGS[$other . '_searchlevel'];
}

// which linkTypes to check (internal, file, external, ...)
$set = GeneralUtility::_GP($prefix . '_SET');
$this->pObj->handleExternalFunctionValue();

if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'])) {
foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['linkvalidator']['checkLinks'] as $linkType => $value) {
// Compile list of all available types. Used for checking with button "Check Links".
if (strpos($this->modTS['linktypes'], $linkType) !== false) {
$this->availableOptions[$linkType] = 1;
}
// Compile list of types currently selected by the checkboxes
if ($this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] && empty($set) || $set[$linkType]) {
$this->checkOpt[$prefix][$linkType] = 1;
$this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = 1;

// 1) if "$prefix_values" = "1" : use POST variables
// 2) if not set, use stored configuration in $this->>pObj->MOD_SETTINGS
// 3) if not set, use default
unset($this->checkOpt[$prefix][$linkType]);
if (!empty(GeneralUtility::_GP($prefix . '_values'))) {
if (isset($set[$linkType])) {
$this->checkOpt[$prefix][$linkType] = $set[$linkType];
} else {
$this->checkOpt[$prefix][$linkType] = '0';
}
$this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = $this->checkOpt[$prefix][$linkType];
} elseif (isset($this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType])) {
$this->checkOpt[$prefix][$linkType] = $this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType];
} else {
$this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = 0;
unset($this->checkOpt[$prefix][$linkType]);
// use default
$this->checkOpt[$prefix][$linkType] = '0';
$this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = $this->checkOpt[$prefix][$linkType];
}
if (isset($this->pObj->MOD_SETTINGS[$other . '_' . $linkType])) {
$this->checkOpt[$other][$linkType] = $this->pObj->MOD_SETTINGS[$other . '_' . $linkType];
}
}
}

// save settings
$this->getBackendUser()->pushModuleData('web_info', $this->pObj->MOD_SETTINGS);
$this->initialize();

Expand Down Expand Up @@ -381,7 +403,7 @@ protected function renderBrokenLinksTable()

$linkTypes = [];
if (is_array($this->checkOpt['report'])) {
$linkTypes = array_keys($this->checkOpt['report']);
$linkTypes = array_keys($this->checkOpt['report'], '1');
}

// Table header
Expand All @@ -390,9 +412,12 @@ protected function renderBrokenLinksTable()
$rootLineHidden = $this->linkAnalyzer->getRootLineIsHidden($this->pObj->pageinfo);
if (!$rootLineHidden || (bool)$this->modTS['checkhidden']) {
$pageList = $this->getPageList($this->pObj->id);
$result = $this->getLinkValidatorBrokenLinks($pageList, $linkTypes);
$result = false;
if (!empty($linkTypes)) {
$result = $this->getLinkValidatorBrokenLinks($pageList, $linkTypes);
}

if ($result->rowCount()) {
if ($result && $result->rowCount()) {
// Display table with broken links
$brokenLinksTemplate = $this->templateService->getSubpart(
$this->doc->moduleTemplate,
Expand Down Expand Up @@ -622,10 +647,10 @@ protected function renderTableRow($table, array $row, $brokenLinksItemTemplate)
* Builds the checkboxes out of the hooks array
*
* @param array $brokenLinkOverView Array of broken links information
* @param string $prefix
* @param string $prefix "report" or "check" for "Report" and "Check links" tab
* @return string code content
*/
protected function getCheckOptions(array $brokenLinkOverView, $prefix = '')
protected function getCheckOptions(array $brokenLinkOverView, $prefix = 'report')
{
$markerArray = [];
if (!empty($prefix)) {
Expand Down Expand Up @@ -654,10 +679,12 @@ protected function getCheckOptions(array $brokenLinkOverView, $prefix = '')

$translation = $this->getLanguageService()->getLL('hooks.' . $type) ?: $type;

$checked = ($this->checkOpt[$prefix][$type]) ? 'checked="checked"' : '';

$hookSectionMarker['option'] = '<input type="checkbox"' . $additionalAttr
. ' id="' . $prefix . '_SET_' . $type
. '" name="' . $prefix . '_SET[' . $type . ']" value="1"'
. ($this->pObj->MOD_SETTINGS[$prefix . '_' . $type] ? ' checked="checked"' : '') . '/>' . '<label for="'
. ' ' . $checked . '/>' . '<label for="'
. $prefix . '_SET_' . $type . '">&nbsp;' . htmlspecialchars($translation) . '</label>';

$hookSectionContent .= $this->templateService->substituteMarkerArray(
Expand All @@ -676,6 +703,10 @@ protected function getCheckOptions(array $brokenLinkOverView, $prefix = '')
'###HOOK_SECTION###',
$hookSectionContent
);

// set this to signal that $prefix_SET variables should be used
$checkOptionsTemplate .= '<input type="hidden" name="' . $prefix . '_values" value="1">';

return $this->templateService->substituteMarkerArray($checkOptionsTemplate, $markerArray, '###|###', true, true);
}

Expand Down

0 comments on commit 8fa73fb

Please sign in to comment.