Do not add a tag to the search if it's already being searched for

This commit is contained in:
Florian Eula 2014-11-20 20:04:24 +01:00
parent 9362352e12
commit 732e683bda

View file

@ -337,7 +337,7 @@ function isLoggedIn()
} }
// Force logout. // Force logout.
function logout() { if (isset($_SESSION)) { unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); } function logout() { if (isset($_SESSION)) { unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); }
setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH);
} }
@ -907,7 +907,7 @@ function showRSS()
else $linksToDisplay = $LINKSDB; else $linksToDisplay = $LINKSDB;
$nblinksToDisplay = 50; // Number of links to display. $nblinksToDisplay = 50; // Number of links to display.
if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.
{ {
$nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;
} }
@ -982,7 +982,7 @@ function showATOM()
else $linksToDisplay = $LINKSDB; else $linksToDisplay = $LINKSDB;
$nblinksToDisplay = 50; // Number of links to display. $nblinksToDisplay = 50; // Number of links to display.
if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links.
{ {
$nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ;
} }
@ -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;
@ -1558,7 +1576,7 @@ function renderPage()
$title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet).
$description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that]
$tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL
$private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL
if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url;
// If this is an HTTP link, we try go get the page to extract the title (otherwise we will to straight to the edit form.) // If this is an HTTP link, we try go get the page to extract the title (otherwise we will to straight to the edit form.)
if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http')
@ -1569,7 +1587,7 @@ function renderPage()
{ {
// Look for charset in html header. // Look for charset in html header.
preg_match('#<meta .*charset=.*>#Usi', $data, $meta); preg_match('#<meta .*charset=.*>#Usi', $data, $meta);
// If found, extract encoding. // If found, extract encoding.
if (!empty($meta[0])) if (!empty($meta[0]))
{ {
@ -1579,7 +1597,7 @@ function renderPage()
$html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8';
} }
else { $html_charset = 'utf-8'; } else { $html_charset = 'utf-8'; }
// Extract title // Extract title
$title = html_extract_title($data); $title = html_extract_title($data);
if (!empty($title)) if (!empty($title))