diff options
author | nodiscc <nodiscc@gmail.com> | 2014-11-21 18:27:04 +0100 |
---|---|---|
committer | nodiscc <nodiscc@gmail.com> | 2014-11-21 18:27:04 +0100 |
commit | 4ad88dd190049c27305de6aa7faa1f74e6d5b791 (patch) | |
tree | 3fe48b6f3ca5ccf55353ae348a0b8a8f27f17d08 /index.php | |
parent | 9362352e124151a0fa8a145fe1dba4e6256b35c7 (diff) | |
parent | 732e683bdacc2033b03820c8e80f7d31c54b94ef (diff) | |
download | Shaarli-4ad88dd190049c27305de6aa7faa1f74e6d5b791.tar.gz Shaarli-4ad88dd190049c27305de6aa7faa1f74e6d5b791.tar.zst Shaarli-4ad88dd190049c27305de6aa7faa1f74e6d5b791.zip |
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
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -337,7 +337,7 @@ function isLoggedIn() | |||
337 | } | 337 | } |
338 | 338 | ||
339 | // Force logout. | 339 | // Force logout. |
340 | function logout() { if (isset($_SESSION)) { unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); } | 340 | function logout() { if (isset($_SESSION)) { unset($_SESSION['uid']); unset($_SESSION['ip']); unset($_SESSION['username']); unset($_SESSION['privateonly']); } |
341 | setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); | 341 | setcookie('shaarli_staySignedIn', FALSE, 0, WEB_PATH); |
342 | } | 342 | } |
343 | 343 | ||
@@ -907,7 +907,7 @@ function showRSS() | |||
907 | else $linksToDisplay = $LINKSDB; | 907 | else $linksToDisplay = $LINKSDB; |
908 | $nblinksToDisplay = 50; // Number of links to display. | 908 | $nblinksToDisplay = 50; // Number of links to display. |
909 | if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. | 909 | if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. |
910 | { | 910 | { |
911 | $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; | 911 | $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; |
912 | } | 912 | } |
913 | 913 | ||
@@ -982,7 +982,7 @@ function showATOM() | |||
982 | else $linksToDisplay = $LINKSDB; | 982 | else $linksToDisplay = $LINKSDB; |
983 | $nblinksToDisplay = 50; // Number of links to display. | 983 | $nblinksToDisplay = 50; // Number of links to display. |
984 | if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. | 984 | if (!empty($_GET['nb'])) // In URL, you can specificy the number of links. Example: nb=200 or nb=all for all links. |
985 | { | 985 | { |
986 | $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; | 986 | $nblinksToDisplay = $_GET['nb']=='all' ? count($linksToDisplay) : max($_GET['nb']+0,1) ; |
987 | } | 987 | } |
988 | 988 | ||
@@ -1267,7 +1267,25 @@ function renderPage() | |||
1267 | // Get previous URL (http_referer) and add the tag to the searchtags parameters in query. | 1267 | // Get previous URL (http_referer) and add the tag to the searchtags parameters in query. |
1268 | if (empty($_SERVER['HTTP_REFERER'])) { header('Location: ?searchtags='.urlencode($_GET['addtag'])); exit; } // In case browser does not send HTTP_REFERER | 1268 | if (empty($_SERVER['HTTP_REFERER'])) { header('Location: ?searchtags='.urlencode($_GET['addtag'])); exit; } // In case browser does not send HTTP_REFERER |
1269 | parse_str(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY), $params); | 1269 | parse_str(parse_url($_SERVER['HTTP_REFERER'],PHP_URL_QUERY), $params); |
1270 | $params['searchtags'] = (empty($params['searchtags']) ? trim($_GET['addtag']) : trim($params['searchtags']).' '.trim($_GET['addtag'])); | 1270 | |
1271 | // Check if this tag is already in the search query and ignore it if it is. | ||
1272 | // Each tag is always separated by a space | ||
1273 | $current_tags = explode(' ', $params['searchtags']); | ||
1274 | $addtag = true; | ||
1275 | foreach ($current_tags as $value) { | ||
1276 | if ($value === $_GET['addtag']) { | ||
1277 | $addtag = false; | ||
1278 | break; | ||
1279 | } | ||
1280 | } | ||
1281 | // Append the tag if necessary | ||
1282 | if (empty($params['searchtags'])) { | ||
1283 | $params['searchtags'] = trim($_GET['addtag']); | ||
1284 | } | ||
1285 | else if ($addtag) { | ||
1286 | $params['searchtags'] = trim($params['searchtags']).' '.trim($_GET['addtag']); | ||
1287 | } | ||
1288 | |||
1271 | unset($params['page']); // We also remove page (keeping the same page has no sense, since the results are different) | 1289 | unset($params['page']); // We also remove page (keeping the same page has no sense, since the results are different) |
1272 | header('Location: ?'.http_build_query($params)); | 1290 | header('Location: ?'.http_build_query($params)); |
1273 | exit; | 1291 | exit; |
@@ -1558,7 +1576,7 @@ function renderPage() | |||
1558 | $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). | 1576 | $title = (empty($_GET['title']) ? '' : $_GET['title'] ); // Get title if it was provided in URL (by the bookmarklet). |
1559 | $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] | 1577 | $description = (empty($_GET['description']) ? '' : $_GET['description']); // Get description if it was provided in URL (by the bookmarklet). [Bronco added that] |
1560 | $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL | 1578 | $tags = (empty($_GET['tags']) ? '' : $_GET['tags'] ); // Get tags if it was provided in URL |
1561 | $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL | 1579 | $private = (!empty($_GET['private']) && $_GET['private'] === "1" ? 1 : 0); // Get private if it was provided in URL |
1562 | if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; | 1580 | if (($url!='') && parse_url($url,PHP_URL_SCHEME)=='') $url = 'http://'.$url; |
1563 | // 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.) | 1581 | // 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.) |
1564 | if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') | 1582 | if (empty($title) && parse_url($url,PHP_URL_SCHEME)=='http') |
@@ -1569,7 +1587,7 @@ function renderPage() | |||
1569 | { | 1587 | { |
1570 | // Look for charset in html header. | 1588 | // Look for charset in html header. |
1571 | preg_match('#<meta .*charset=.*>#Usi', $data, $meta); | 1589 | preg_match('#<meta .*charset=.*>#Usi', $data, $meta); |
1572 | 1590 | ||
1573 | // If found, extract encoding. | 1591 | // If found, extract encoding. |
1574 | if (!empty($meta[0])) | 1592 | if (!empty($meta[0])) |
1575 | { | 1593 | { |
@@ -1579,7 +1597,7 @@ function renderPage() | |||
1579 | $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; | 1597 | $html_charset = (!empty($enc[1])) ? strtolower($enc[1]) : 'utf-8'; |
1580 | } | 1598 | } |
1581 | else { $html_charset = 'utf-8'; } | 1599 | else { $html_charset = 'utf-8'; } |
1582 | 1600 | ||
1583 | // Extract title | 1601 | // Extract title |
1584 | $title = html_extract_title($data); | 1602 | $title = html_extract_title($data); |
1585 | if (!empty($title)) | 1603 | if (!empty($title)) |