diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-01-17 09:53:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-17 09:53:55 +0100 |
commit | 078fcb56ad6bcec203ff91d956e03cf1605a93af (patch) | |
tree | 195cbf8a570faa7765a1f4f01f5f9dc3eff9b352 | |
parent | d029cf67f85c5aac1dc96b35d5e8b5e85aa25cbd (diff) | |
parent | 95e5add4be1fb98a1cae5d30f4fd6e0d2b0a56bc (diff) | |
download | Shaarli-078fcb56ad6bcec203ff91d956e03cf1605a93af.tar.gz Shaarli-078fcb56ad6bcec203ff91d956e03cf1605a93af.tar.zst Shaarli-078fcb56ad6bcec203ff91d956e03cf1605a93af.zip |
Merge pull request #766 from ArthurHoaro/hotfix/deletion-redirect
Fix redirection after link deletion
-rw-r--r-- | index.php | 34 |
1 files changed, 9 insertions, 25 deletions
@@ -1349,31 +1349,15 @@ function renderPage($conf, $pluginManager, $LINKSDB) | |||
1349 | 1349 | ||
1350 | // If we are called from the bookmarklet, we must close the popup: | 1350 | // If we are called from the bookmarklet, we must close the popup: |
1351 | if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } | 1351 | if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo '<script>self.close();</script>'; exit; } |
1352 | // Pick where we're going to redirect | 1352 | |
1353 | // ============================================================= | 1353 | $location = '?'; |
1354 | // Basically, we can't redirect to where we were previously if it was a permalink | 1354 | if (isset($_SERVER['HTTP_REFERER'])) { |
1355 | // or an edit_link, because it would 404. | 1355 | // Don't redirect to where we were previously if it was a permalink or an edit_link, because it would 404. |
1356 | // Cases: | 1356 | $location = generateLocation( |
1357 | // - / : nothing in $_GET, redirect to self | 1357 | $_SERVER['HTTP_REFERER'], |
1358 | // - /?page : redirect to self | 1358 | $_SERVER['HTTP_HOST'], |
1359 | // - /?searchterm : redirect to self (there might be other links) | 1359 | ['delete_link', 'edit_link', $link['shorturl']] |
1360 | // - /?searchtags : redirect to self | 1360 | ); |
1361 | // - /permalink : redirect to / (the link does not exist anymore) | ||
1362 | // - /?edit_link : redirect to / (the link does not exist anymore) | ||
1363 | // PHP treats the permalink as a $_GET variable, so we need to check if every condition for self | ||
1364 | // redirect is not satisfied, and only then redirect to / | ||
1365 | $location = "?"; | ||
1366 | // Self redirection | ||
1367 | if (count($_GET) == 0 | ||
1368 | || isset($_GET['page']) | ||
1369 | || isset($_GET['searchterm']) | ||
1370 | || isset($_GET['searchtags']) | ||
1371 | ) { | ||
1372 | if (isset($_POST['returnurl'])) { | ||
1373 | $location = $_POST['returnurl']; // Handle redirects given by the form | ||
1374 | } else if (isset($_SERVER['HTTP_REFERER'])) { | ||
1375 | $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('delete_link')); | ||
1376 | } | ||
1377 | } | 1361 | } |
1378 | 1362 | ||
1379 | header('Location: ' . $location); // After deleting the link, redirect to appropriate location | 1363 | header('Location: ' . $location); // After deleting the link, redirect to appropriate location |