Skip to content

Commit

Permalink
[FEATURE] Add URL match selection
Browse files Browse the repository at this point in the history
It is now possible to select how to match the URL in a select box.

It is possible to select from the following:

- partial: This is a partial match of the URL (LIKE %url%)
- exact: The URL entered in the input field must match exactly
- no partial match: This is the opposite of partial match, all
  broken link records which do not match the URL via partial
  match are displayed
- no exact match: This is the opposite of the exact match, all
  broken link records which do not match the URL exactly are
  displayed.
  • Loading branch information
sypets committed Mar 13, 2022
1 parent 7f2141b commit 7540429
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 34 deletions.
48 changes: 32 additions & 16 deletions Classes/Controller/BrokenLinkListController.php
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,30 @@ protected function getSettingsFromQueryParameters(): void
$depth = GeneralUtility::_GP('depth');

// store filter parameters in the Filter Object
$this->filter = new BrokenLinkListFilter();
$this->filter->setUidFilter(GeneralUtility::_GP('uid_searchFilter') ?? '');
$this->filter->setUrlFilter(GeneralUtility::_GP('url_searchFilter') ?? '');
$this->filter->setLinktypeFilter(GeneralUtility::_GP('linktype_searchFilter') ?? 'all');
$this->filter->setViewMode(GeneralUtility::_GP('view_mode') ?? BrokenLinkListFilter::VIEW_MODE_MIN);
$this->filter = $this->backendSession->get('filterKey');
if (!$this->filter) {
$this->filter = new BrokenLinkListFilter();
}
$uid = GeneralUtility::_GP('uid_searchFilter');
if ($uid !== null) {
$this->filter->setUidFilter($uid);
}
$url = GeneralUtility::_GP('url_searchFilter');
if ($url !== null) {
$this->filter->setUrlFilter($url);
}
$urlMatch = GeneralUtility::_GP('url_match_searchFilter');
if ($urlMatch !== null) {
$this->filter->setUrlFilterMatch($urlMatch ?: 'partial');
}
$linkType = GeneralUtility::_GP('linktype_searchFilter');
if ($linkType !== null) {
$this->filter->setLinktypeFilter($linkType ?: 'all');
}
$viewMode = GeneralUtility::_GP('view_mode');
if ($viewMode !== null) {
$this->filter->setViewMode($viewMode ?: BrokenLinkListFilter::VIEW_MODE_MIN);
}

// to prevent deleting session, when user sort the records
if (!is_null(GeneralUtility::_GP('url_searchFilter')) || !is_null(GeneralUtility::_GP('title_searchFilter')) || !is_null(GeneralUtility::_GP('uid_searchFilter'))) {
Expand All @@ -297,7 +316,7 @@ protected function getSettingsFromQueryParameters(): void
// create session, if it the first time
if (is_null($this->backendSession->get('filterKey'))) {
$this->backendSession->setStorageKey('filterKey');
$this->backendSession->store('filterKey', new BrokenLinkListFilter());
$this->backendSession->store('filterKey', $this->filter);
}

/**
Expand Down Expand Up @@ -539,18 +558,11 @@ protected function initializeViewForBrokenLinks(): void
// @extensionScannerIgnoreLine problem with getRootLineIsHidden
$rootLineHidden = $this->pagesRepository->getRootLineIsHidden($this->pObj->pageinfo);
if ($this->id > 0 && (!$rootLineHidden || $this->configuration->isCheckHidden())) {
// build the search filter from the backendSession session
$searchFilter = new BrokenLinkListFilter();
$searchFilter->setUrlFilter($this->backendSession->get('filterKey')->getUrlFilter());
$searchFilter->setLinktypeFilter($this->backendSession->get('filterKey')->getLinktypeFilter());
$searchFilter->setUidFilter($this->backendSession->get('filterKey')->getUidFilter());
$searchFilter->setViewMode($this->backendSession->get('filterKey')->getViewMode());

$brokenLinks = $this->brokenLinkRepository->getBrokenLinks(
$this->pageList,
$this->linkTypes,
$this->configuration->getSearchFields(),
$searchFilter,
$this->filter,
self::ORDER_BY_VALUES[$this->orderBy] ?? []
);
if ($brokenLinks) {
Expand All @@ -573,6 +585,7 @@ protected function initializeViewForBrokenLinks(): void
$this->view->assign('uid_filter', $this->backendSession->get('filterKey')->getUidFilter());
$this->view->assign('linktype_filter', $this->backendSession->get('filterKey')->getLinktypeFilter());
$this->view->assign('url_filter', $this->backendSession->get('filterKey')->getUrlFilter());
$this->view->assign('url_match_searchFilter', $this->backendSession->get('filterKey')->getUrlFilterMatch());
$this->view->assign('view_mode', $this->backendSession->get('filterKey')->getViewMode() ?: BrokenLinkListFilter::VIEW_MODE_MIN);
if ($this->id === 0) {
$this->createFlashMessagesForRootPage();
Expand Down Expand Up @@ -876,10 +889,13 @@ protected function renderTableRow($table, array $row): array
// link / URL
$variables['linktarget'] = $hookObj->getBrokenUrl($row);
$variables['orig_linktarget'] = $row['url'];
if ($this->filter->getUrlFilter() == '=' . $variables['orig_linktarget']) {
if ($this->filter->getUrlFilter() == $variables['orig_linktarget']
&& $this->filter->getUrlFilterMatch() === 'exact'
) {
// filter already active for this URL, offer to deactivate filter
$variables['encoded_linktarget'] = '';
} else {
$variables['encoded_linktarget'] = urlencode('=' . $variables['orig_linktarget']);
$variables['encoded_linktarget'] = urlencode($variables['orig_linktarget']);
}
if (isset($row['link_title']) && $variables['linktarget'] !== $row['link_title']) {
$variables['link_title'] = htmlspecialchars($row['link_title']);
Expand Down
19 changes: 19 additions & 0 deletions Classes/Controller/Filter/BrokenLinkListFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class BrokenLinkListFilter
*/
protected $url_filtre = '';

/** @var string */
protected $urlFilterMatch = 'partial';

/**
* @var string
* @deprecated
Expand Down Expand Up @@ -61,6 +64,22 @@ public function setUrlFilter(string $url_filter): void
$this->url_filtre = trim($url_filter);
}

/**
* @return string
*/
public function getUrlFilterMatch(): string
{
return $this->urlFilterMatch;
}

/**
* @param string $urlFilterMatch
*/
public function setUrlFilterMatch(string $urlFilterMatch): void
{
$this->urlFilterMatch = $urlFilterMatch;
}

/**
* @return string
*/
Expand Down
50 changes: 34 additions & 16 deletions Classes/Repository/BrokenLinkRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,22 +111,40 @@ public function getBrokenLinks(array $pageList, array $linkTypes, array $searchF
);
}
$urlFilter = $filter->getUrlFilter();
if ($urlFilter != '' && $urlFilter != '=') {
if (strpos($urlFilter, '=') === 0) {
// exact match
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
self::TABLE . '.url',
$queryBuilder->createNamedParameter(mb_substr($urlFilter, 1))
)
);
} else {
$queryBuilder->andWhere(
$queryBuilder->expr()->like(
self::TABLE . '.url',
$queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($filter->getUrlFilter()) . '%')
)
);
if ($urlFilter != '') {
switch ($filter->getUrlFilterMatch()) {
case 'partial':
$queryBuilder->andWhere(
$queryBuilder->expr()->like(
self::TABLE . '.url',
$queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($filter->getUrlFilter()) . '%')
)
);
break;
case 'exact':
$queryBuilder->andWhere(
$queryBuilder->expr()->eq(
self::TABLE . '.url',
$queryBuilder->createNamedParameter($urlFilter)
)
);
break;
case 'partialnot':
$queryBuilder->andWhere(
$queryBuilder->expr()->notLike(
self::TABLE . '.url',
$queryBuilder->createNamedParameter('%' . $queryBuilder->escapeLikeWildcards($filter->getUrlFilter()) . '%')
)
);
break;
case 'exactnot':
$queryBuilder->andWhere(
$queryBuilder->expr()->neq(
self::TABLE . '.url',
$queryBuilder->createNamedParameter(mb_substr($urlFilter, 1))
)
);
break;
}
}
$linktypeFilter = $filter->getLinkTypeFilter() ?: 'all';
Expand Down
14 changes: 13 additions & 1 deletion Resources/Private/Language/Module/locallang.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,19 @@
<source>URL</source>
</trans-unit>
<trans-unit id="list.filter.url.placeholder" resname="list.filter.url.placeholder">
<source>=URL (exact), URL (partial)</source>
<source>URL</source>
</trans-unit>
<trans-unit id="list.filter.url.match.partial" resname="list.filter.url.match.partial">
<source>partial match</source>
</trans-unit>
<trans-unit id="list.filter.url.match.exact" resname="list.filter.url.match.exact">
<source>exact match</source>
</trans-unit>
<trans-unit id="list.filter.url.match.partialnot" resname="list.filter.url.match.partialnot">
<source>no partial match</source>
</trans-unit>
<trans-unit id="list.filter.url.match.exactnot" resname="list.filter.url.match.exactnot">
<source>no exact match</source>
</trans-unit>
<trans-unit id="list.filter.title" resname="list.filter.title">
<source>Title</source>
Expand Down
16 changes: 15 additions & 1 deletion Resources/Private/Templates/Backend/BrokenLinkList.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,20 @@
<core:icon identifier="actions-close" size="small" />
</button>
</div>
<select id="url_match_searchFilter" name="url_match_searchFilter" class="form-control tceforms-select">
<option value="partial" {f:if(condition:'{url_match_searchFilter} == partial', then: 'selected')}>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.url.match.partial">partial match</f:translate>
</option>
<option value="exact" {f:if(condition:'{url_match_searchFilter} == exact', then: 'selected')}>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.url.match.exact">exact match</f:translate>
</option>
<option value="partialnot" {f:if(condition:'{url_match_searchFilter} == partialnot', then: 'selected')}>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.url.match.partialnot">no partial match</f:translate>
</option>
<option value="exactnot" {f:if(condition:'{url_match_searchFilter} == exactnot', then: 'selected')}>
<f:translate key="LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.url.match.exactnot">no exact match</f:translate>
</option>
</select>
</div>
</row>
<br/>
Expand Down Expand Up @@ -199,7 +213,7 @@
<div class="inline-action">
<f:if condition="{item.encoded_linktarget}">
<f:then>
<a href="{listUri}&url_searchFilter={item.encoded_linktarget}" title="{f:translate(key: 'LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.linktarget.tooltip', extensionName: 'Brofix')}">
<a href="{listUri}&url_searchFilter={item.encoded_linktarget}&url_match_searchFilter=exact" title="{f:translate(key: 'LLL:EXT:brofix/Resources/Private/Language/Module/locallang.xlf:list.filter.linktarget.tooltip', extensionName: 'Brofix')}">
<f:translate key="filter" extensionName="Brofix">Filter</f:translate>
</a>
</f:then>
Expand Down
14 changes: 14 additions & 0 deletions Resources/Public/JavaScript/Brofix.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,24 @@ define(['jquery'], function($) {
'use strict';
$(document).ready(function () {

// reload list on changing these values
$('#linktype_searchFilter').on('change', function () {
$('#refreshLinkList').click();
})

$('#url_match_searchFilter').on('change', function () {
$('#refreshLinkList').click();
})

$('#view_table_complex').on('change', function () {
$('#refreshLinkList').click();
})

$('#view_table_min').on('change', function () {
$('#refreshLinkList').click();
})

// clear input text fields with X button
$('#uidButton').on('click', function () {
$('#uid_searchFilter').val('');
$('#refreshLinkList').click();
Expand Down

0 comments on commit 7540429

Please sign in to comment.