X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=index.php;h=cc7f3ca3497feaf96288b61f718997eb0c3a09cf;hb=36eb71fb48aa3e752a1e32774b8eead18780bf29;hp=145ea3f63a51edfda5e082cc1793ef44e30ccb2e;hpb=d029cf67f85c5aac1dc96b35d5e8b5e85aa25cbd;p=github%2Fshaarli%2FShaarli.git
diff --git a/index.php b/index.php
index 145ea3f6..cc7f3ca3 100644
--- a/index.php
+++ b/index.php
@@ -1,6 +1,6 @@
save($conf->get('resource.page_cache'));
- echo '';
+ echo '';
exit;
}
@@ -1349,31 +1349,15 @@ function renderPage($conf, $pluginManager, $LINKSDB)
// If we are called from the bookmarklet, we must close the popup:
if (isset($_GET['source']) && ($_GET['source']=='bookmarklet' || $_GET['source']=='firefoxsocialapi')) { echo ''; exit; }
- // Pick where we're going to redirect
- // =============================================================
- // Basically, we can't redirect to where we were previously if it was a permalink
- // or an edit_link, because it would 404.
- // Cases:
- // - / : nothing in $_GET, redirect to self
- // - /?page : redirect to self
- // - /?searchterm : redirect to self (there might be other links)
- // - /?searchtags : redirect to self
- // - /permalink : redirect to / (the link does not exist anymore)
- // - /?edit_link : redirect to / (the link does not exist anymore)
- // PHP treats the permalink as a $_GET variable, so we need to check if every condition for self
- // redirect is not satisfied, and only then redirect to /
- $location = "?";
- // Self redirection
- if (count($_GET) == 0
- || isset($_GET['page'])
- || isset($_GET['searchterm'])
- || isset($_GET['searchtags'])
- ) {
- if (isset($_POST['returnurl'])) {
- $location = $_POST['returnurl']; // Handle redirects given by the form
- } else if (isset($_SERVER['HTTP_REFERER'])) {
- $location = generateLocation($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST'], array('delete_link'));
- }
+
+ $location = '?';
+ if (isset($_SERVER['HTTP_REFERER'])) {
+ // Don't redirect to where we were previously if it was a permalink or an edit_link, because it would 404.
+ $location = generateLocation(
+ $_SERVER['HTTP_REFERER'],
+ $_SERVER['HTTP_HOST'],
+ ['delete_link', 'edit_link', $link['shorturl']]
+ );
}
header('Location: ' . $location); // After deleting the link, redirect to appropriate location
@@ -1544,7 +1528,7 @@ function renderPage($conf, $pluginManager, $LINKSDB)
$_POST,
$_FILES,
$LINKSDB,
- $conf->get('resource.page_cache')
+ $conf
);
echo '';
@@ -1630,8 +1614,8 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
}
} else {
// Filter links according search parameters.
- $privateonly = !empty($_SESSION['privateonly']);
- $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $privateonly);
+ $visibility = ! empty($_SESSION['privateonly']) ? 'private' : 'all';
+ $linksToDisplay = $LINKSDB->filterSearch($_GET, false, $visibility);
}
// ---- Handle paging.
@@ -1698,6 +1682,7 @@ function buildLinkList($PAGE,$LINKSDB, $conf, $pluginManager)
'result_count' => count($linksToDisplay),
'search_term' => $searchterm,
'search_tags' => $searchtags,
+ 'visibility' => ! empty($_SESSION['privateonly']) ? 'private' : '',
'redirector' => $conf->get('redirector.url'), // Optional redirector URL.
'links' => $linkDisp,
'tags' => $LINKSDB->allTags(),
@@ -2248,12 +2233,13 @@ $app = new \Slim\App($container);
$app->group('/api/v1', function() {
$this->get('/info', '\Shaarli\Api\Controllers\Info:getInfo');
$this->get('/links', '\Shaarli\Api\Controllers\Links:getLinks');
+ $this->get('/links/{id:[\d]+}', '\Shaarli\Api\Controllers\Links:getLink');
})->add('\Shaarli\Api\ApiMiddleware');
$response = $app->run(true);
// Hack to make Slim and Shaarli router work together:
-// If a Slim route isn't found, we call renderPage().
-if ($response->getStatusCode() == 404) {
+// If a Slim route isn't found and NOT API call, we call renderPage().
+if ($response->getStatusCode() == 404 && strpos($_SERVER['REQUEST_URI'], '/api/v1') === false) {
// We use UTF-8 for proper international characters handling.
header('Content-Type: text/html; charset=utf-8');
renderPage($conf, $pluginManager, $linkDb);