Skip to content

Commit

Permalink
[BUGFIX] Handle settings for report / check in linkvalidator
Browse files Browse the repository at this point in the history
The level and link type checkmark options are now handled seperately
for the "Report" and "Check Links" tab. This way, the options can
be changed independantly on each tab.

Resolves: #81035
Releases: master, 8.7
Change-Id: I772f885940791a17269c413185d3bea46695ff19
Reviewed-on: https://review.typo3.org/52628
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Tested-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Sybille Peters <sypets@gmx.de>
Tested-by: Sybille Peters <sypets@gmx.de>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
  • Loading branch information
thommyhh authored and NeoBlack committed Feb 13, 2018
1 parent f7b516d commit aae9596
Showing 1 changed file with 58 additions and 46 deletions.
104 changes: 58 additions & 46 deletions typo3/sysext/linkvalidator/Classes/Report/LinkValidatorReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ class LinkValidatorReport extends \TYPO3\CMS\Backend\Module\AbstractFunctionModu

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

/**
* Link validation class
Expand Down Expand Up @@ -91,19 +92,11 @@ class LinkValidatorReport extends \TYPO3\CMS\Backend\Module\AbstractFunctionModu

/**
* Html for the statistics table with the checkboxes of the link types
* and the numbers of broken links for report tab
*
* @var string
*/
protected $checkOptionsHtml;

/**
* Html for the statistics table with the checkboxes of the link types
* and the numbers of broken links for check links tab
* and the numbers of broken links for report / check links tab
*
* @var string
* @var array
*/
protected $checkOptionsHtmlCheck;
protected $checkOptionsHtml = [];

/**
* Complete content (html) to be displayed
Expand Down Expand Up @@ -146,35 +139,47 @@ public function main()
{
$this->getLanguageService()->includeLLFile('EXT:linkvalidator/Resources/Private/Language/Module/locallang.xlf');
$this->iconFactory = GeneralUtility::makeInstance(IconFactory::class);
$this->searchLevel = GeneralUtility::_GP('search_levels');
$update = GeneralUtility::_GP('updateLinkList');
$prefix = 'check';
$other = 'report';

if (empty($update)) {
$prefix = 'report';
$other = 'check';
}

$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'];
}
$update = GeneralUtility::_GP('updateLinkList');
$prefix = '';
if (!empty($update)) {
$prefix = 'check';
}
$set = GeneralUtility::_GP($prefix . 'SET');
$set = GeneralUtility::_GP($prefix . '_SET');
$this->pObj->handleExternalFunctionValue();
if (isset($this->searchLevel)) {
$this->pObj->MOD_SETTINGS['searchlevel'] = $this->searchLevel;
if (isset($this->searchLevel[$prefix])) {
$this->pObj->MOD_SETTINGS[$prefix . '_searchlevel'] = $this->searchLevel[$prefix];
} else {
$this->searchLevel = $this->pObj->MOD_SETTINGS['searchlevel'];
$this->searchLevel[$prefix] = $this->pObj->MOD_SETTINGS[$prefix . '_searchlevel'];
}
if (isset($this->pObj->MOD_SETTINGS[$other . '_searchlevel'])) {
$this->searchLevel[$other] = $this->pObj->MOD_SETTINGS[$other . '_searchlevel'];
}
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[$linkType] && empty($set) || $set[$linkType]) {
$this->checkOpt[$linkType] = 1;
$this->pObj->MOD_SETTINGS[$linkType] = 1;
if ($this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] && empty($set) || $set[$linkType]) {
$this->checkOpt[$prefix][$linkType] = 1;
$this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = 1;
} else {
$this->pObj->MOD_SETTINGS[$prefix . '_' . $linkType] = 0;
unset($this->checkOpt[$prefix][$linkType]);
}
if (isset($this->pObj->MOD_SETTINGS[$other . '_' . $linkType])) {
$this->checkOpt[$other][$linkType] = $this->pObj->MOD_SETTINGS[$other . '_' . $linkType];
} else {
$this->pObj->MOD_SETTINGS[$linkType] = 0;
unset($this->checkOpt[$linkType]);
$this->checkOpt[$other][$linkType] = 0;
}
}
$this->getBackendUser()->pushModuleData('web_info', $this->pObj->MOD_SETTINGS);
Expand All @@ -191,8 +196,8 @@ public function main()
$this->updateBrokenLinks();

$brokenLinkOverView = $this->linkAnalyzer->getLinkCounts($this->pObj->id);
$this->checkOptionsHtml = $this->getCheckOptions($brokenLinkOverView);
$this->checkOptionsHtmlCheck = $this->getCheckOptions($brokenLinkOverView, 'check');
$this->checkOptionsHtml['report'] = $this->getCheckOptions($brokenLinkOverView, 'report');
$this->checkOptionsHtml['check'] = $this->getCheckOptions($brokenLinkOverView, 'check');
$this->render();

$pageTile = '';
Expand Down Expand Up @@ -278,7 +283,7 @@ protected function updateBrokenLinks()
// Get children pages
$pageList = $this->linkAnalyzer->extGetTreeList(
$this->pObj->id,
$this->searchLevel,
$this->searchLevel['check'],
0,
$this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW),
$this->modTS['checkhidden']
Expand All @@ -292,7 +297,7 @@ protected function updateBrokenLinks()
// Check if button press
$update = GeneralUtility::_GP('updateLinkList');
if (!empty($update)) {
$this->linkAnalyzer->getLinkStatistics($this->checkOpt, $this->modTS['checkhidden']);
$this->linkAnalyzer->getLinkStatistics($this->checkOpt['check'], $this->modTS['checkhidden']);
}
}
}
Expand Down Expand Up @@ -339,9 +344,11 @@ protected function flush($form = false)
/**
* Builds the selector for the level of pages to search
*
* @param string $prefix Indicating if the selector is build for the "report" or "check" tab
*
* @return string Html code of that selector
*/
protected function getLevelSelector()
protected function getLevelSelector($prefix = 'report')
{
// Build level selector
$options = [];
Expand All @@ -354,9 +361,9 @@ protected function getLevelSelector()
999 => $this->getLanguageService()->sL('LLL:EXT:lang/Resources/Private/Language/locallang_core.xlf:labels.depth_infi')
];
foreach ($availableOptions as $optionValue => $optionLabel) {
$options[] = '<option value="' . $optionValue . '"' . ($optionValue === (int)$this->searchLevel ? ' selected="selected"' : '') . '>' . htmlspecialchars($optionLabel) . '</option>';
$options[] = '<option value="' . $optionValue . '"' . ($optionValue === (int)$this->searchLevel[$prefix] ? ' selected="selected"' : '') . '>' . htmlspecialchars($optionLabel) . '</option>';
}
return '<select name="search_levels" class="form-control">' . implode('', $options) . '</select>';
return '<select name="' . $prefix . '_search_levels" class="form-control">' . implode('', $options) . '</select>';
}

/**
Expand All @@ -373,8 +380,8 @@ protected function renderBrokenLinksTable()
);

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

// Table header
Expand Down Expand Up @@ -430,7 +437,7 @@ protected function getPageList(int $currentPageUid): array
{
$pageList = $this->linkAnalyzer->extGetTreeList(
$currentPageUid,
$this->searchLevel,
$this->searchLevel['report'],
0,
$this->getBackendUser()->getPagePermsClause(Permission::PAGE_SHOW),
$this->modTS['checkhidden']
Expand Down Expand Up @@ -545,7 +552,7 @@ protected function renderTableRow($table, array $row, $brokenLinksItemTemplate)
// Construct link to edit the content element
$requestUri = GeneralUtility::getIndpEnv('REQUEST_URI') .
'&id=' . $this->pObj->id .
'&search_levels=' . $this->searchLevel;
'&search_levels=' . $this->searchLevel['report'];
/** @var \TYPO3\CMS\Backend\Routing\UriBuilder $uriBuilder */
$uriBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Backend\Routing\UriBuilder::class);
$url = (string)$uriBuilder->buildUriFromRoute('record_edit', [
Expand Down Expand Up @@ -646,9 +653,12 @@ protected function getCheckOptions(array $brokenLinkOverView, $prefix = '')
];

$translation = $this->getLanguageService()->getLL('hooks.' . $type) ?: $type;
$hookSectionMarker['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 . '">&nbsp;' . htmlspecialchars($translation) . '</label>';

$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="'
. $prefix . '_SET_' . $type . '">&nbsp;' . htmlspecialchars($translation) . '</label>';

$hookSectionContent .= $this->templateService->substituteMarkerArray(
$hookSectionTemplate,
Expand Down Expand Up @@ -699,6 +709,7 @@ protected function getShortcutButton()

/**
* Gets the filled markers that are used in the HTML template
* Reports tab
*
* @return array The filled marker array
*/
Expand All @@ -707,9 +718,9 @@ protected function getTemplateMarkers()
return [
'FUNC_TITLE' => $this->getLanguageService()->getLL('report.func.title'),
'CHECKOPTIONS_TITLE' => $this->getLanguageService()->getLL('report.statistics.header'),
'FUNC_MENU' => $this->getLevelSelector(),
'FUNC_MENU' => $this->getLevelSelector('report'),
'CONTENT' => $this->content,
'CHECKOPTIONS' => $this->checkOptionsHtml,
'CHECKOPTIONS' => $this->checkOptionsHtml['report'],
'ID' => '<input type="hidden" name="id" value="' . $this->pObj->id . '" />',
'REFRESH' => '<input type="submit" class="btn btn-default t3js-update-button" name="refreshLinkList" id="refreshLinkList" value="' . htmlspecialchars($this->getLanguageService()->getLL('label_refresh')) . '" data-notification-message="' . htmlspecialchars($this->getLanguageService()->getLL('label_refresh-link-list')) . '" />',
'UPDATE' => '',
Expand All @@ -718,6 +729,7 @@ protected function getTemplateMarkers()

/**
* Gets the filled markers that are used in the HTML template
* Check Links tab
*
* @return array The filled marker array
*/
Expand All @@ -726,9 +738,9 @@ protected function getTemplateMarkersCheck()
return [
'FUNC_TITLE' => $this->getLanguageService()->getLL('checklinks.func.title'),
'CHECKOPTIONS_TITLE' => $this->getLanguageService()->getLL('checklinks.statistics.header'),
'FUNC_MENU' => $this->getLevelSelector(),
'FUNC_MENU' => $this->getLevelSelector('check'),
'CONTENT' => '',
'CHECKOPTIONS' => $this->checkOptionsHtmlCheck,
'CHECKOPTIONS' => $this->checkOptionsHtml['check'],
'ID' => '<input type="hidden" name="id" value="' . $this->pObj->id . '" />',
'REFRESH' => '',
'UPDATE' => '<input type="submit" class="btn btn-default t3js-update-button" name="updateLinkList" id="updateLinkList" value="' . htmlspecialchars($this->getLanguageService()->getLL('label_update')) . '" data-notification-message="' . htmlspecialchars($this->getLanguageService()->getLL('label_update-link-list')) . '"/>',
Expand Down

0 comments on commit aae9596

Please sign in to comment.