Merge pull request #60 from pikzen/master
Do not add a tag to the search if it's already being searched for. * Fixes https://github.com/shaarli/Shaarli/issues/50 * Fixes https://github.com/sebsauvage/Shaarli/issues/140
This commit is contained in:
commit
4ad88dd190
1 changed files with 25 additions and 7 deletions
20
index.php
20
index.php
|
@ -1267,7 +1267,25 @@ function renderPage()
|
||||||
// Get previous URL (http_referer) and add the tag to the searchtags parameters in query.
|
// Get previous URL (http_referer) and add the tag to the searchtags parameters in query.
|
||||||
if (empty($_SERVER['HTTP_REFERER'])) { header('Location: ?searchtags='.urlencode($_GET['addtag'])); exit; } // In case browser does not send HTTP_REFERER
|
if (empty($_SERVER['HTTP_REFERER'])) { header('Location: ?searchtags='.urlencode($_GET['addtag'])); exit; } // In case browser does not send HTTP_REFERER
|
||||||
parse_str(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY), $params);
|
parse_str(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY), $params);
|
||||||
$params['searchtags'] = (empty($params['searchtags']) ? trim($_GET['addtag']) : trim($params['searchtags']).' '.trim($_GET['addtag']));
|
|
||||||
|
// Check if this tag is already in the search query and ignore it if it is.
|
||||||
|
// Each tag is always separated by a space
|
||||||
|
$current_tags = explode(' ', $params['searchtags']);
|
||||||
|
$addtag = true;
|
||||||
|
foreach ($current_tags as $value) {
|
||||||
|
if ($value === $_GET['addtag']) {
|
||||||
|
$addtag = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Append the tag if necessary
|
||||||
|
if (empty($params['searchtags'])) {
|
||||||
|
$params['searchtags'] = trim($_GET['addtag']);
|
||||||
|
}
|
||||||
|
else if ($addtag) {
|
||||||
|
$params['searchtags'] = trim($params['searchtags']).' '.trim($_GET['addtag']);
|
||||||
|
}
|
||||||
|
|
||||||
unset($params['page']); // We also remove page (keeping the same page has no sense, since the results are different)
|
unset($params['page']); // We also remove page (keeping the same page has no sense, since the results are different)
|
||||||
header('Location: ?'.http_build_query($params));
|
header('Location: ?'.http_build_query($params));
|
||||||
exit;
|
exit;
|
||||||
|
|
Loading…
Reference in a new issue