aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornodiscc <nodiscc@gmail.com>2015-02-17 21:13:35 +0100
committernodiscc <nodiscc@gmail.com>2015-02-17 21:13:35 +0100
commite49de55ab187e088ce5e355568b8b5d9ff9265e8 (patch)
treeedaa9ed001bca50564c08b64a4439796f1789dcd
parent225eff62a1f665ecdfdfc145bd81fc671d0961bb (diff)
parentd528433d73bd0ad3eb3d7a9c26a40d68aca84aeb (diff)
downloadShaarli-e49de55ab187e088ce5e355568b8b5d9ff9265e8.tar.gz
Shaarli-e49de55ab187e088ce5e355568b8b5d9ff9265e8.tar.zst
Shaarli-e49de55ab187e088ce5e355568b8b5d9ff9265e8.zip
Merge pull request #114 from nodiscc/redirect-previous-search
redirect to previous search (if any) when deleting a link
-rw-r--r--index.php32
1 files changed, 31 insertions, 1 deletions
diff --git a/index.php b/index.php
index 818fa680..3af38695 100644
--- a/index.php
+++ b/index.php
@@ -1550,7 +1550,37 @@ function renderPage()
1550 1550
1551 // If we are called from the bookmarklet, we must close the popup: 1551 // If we are called from the bookmarklet, we must close the popup:
1552 if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script>self.close();</script>'; exit; } 1552 if (isset($_GET['source']) && $_GET['source']=='bookmarklet') { echo '<script>self.close();</script>'; exit; }
1553 header('Location: ?'); // After deleting the link, redirect to the home page. 1553 // Pick where we're going to redirect
1554 // =============================================================
1555 // Basically, we can't redirect to where we were previously if it was a permalink
1556 // or an edit_link, because it would 404.
1557 // Cases:
1558 // - / : nothing in $_GET, redirect to self
1559 // - /?page : redirect to self
1560 // - /?searchterm : redirect to self (there might be other links)
1561 // - /?searchtags : redirect to self
1562 // - /permalink : redirect to / (the link does not exist anymore)
1563 // - /?edit_link : redirect to / (the link does not exist anymore)
1564 // PHP treats the permalink as a $_GET variable, so we need to check if every condition for self
1565 // redirect is not satisfied, and only then redirect to /
1566 $location = "?";
1567 // Self redirection
1568 if (count($_GET) == 0 ||
1569 isset($_GET['page']) ||
1570 isset($_GET['searchterm']) ||
1571 isset($_GET['searchtags'])) {
1572
1573 if (isset($_POST['returnurl'])) {
1574 $location = $_POST['returnurl']; // Handle redirects given by the form
1575 }
1576
1577 if ($location === "?" &&
1578 isset($_SERVER['HTTP_REFERER'])) { // Handle HTTP_REFERER in case we're not coming from the same place.
1579 $location = $_SERVER['HTTP_REFERER'];
1580 }
1581 }
1582
1583 header('Location: ' . $location); // After deleting the link, redirect to appropriate location
1554 exit; 1584 exit;
1555 } 1585 }
1556 1586