]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - index.php
Add history entries for API endpoint
[github/shaarli/Shaarli.git] / index.php
index cddc9eeb34270961b0e6afd421fb1bed68776143..fb7318d918fc567726ab77e58aede00a6574cf1c 100644 (file)
--- a/index.php
+++ b/index.php
@@ -707,7 +707,7 @@ function showLinkList($PAGE, $LINKSDB, $conf, $pluginManager) {
  * @param PluginManager $pluginManager Plugin Manager instance,
  * @param LinkDB        $LINKSDB
  */
-function renderPage($conf, $pluginManager, $LINKSDB)
+function renderPage($conf, $pluginManager, $LINKSDB, $history)
 {
     $updater = new Updater(
         read_updates_file($conf->get('resource.updates')),
@@ -728,12 +728,6 @@ function renderPage($conf, $pluginManager, $LINKSDB)
         die($e->getMessage());
     }
 
-    try {
-        $history = new History($conf->get('resource.history'));
-    } catch(Exception $e) {
-        die($e->getMessage());
-    }
-
     $PAGE = new PageBuilder($conf);
     $PAGE->assign('linkcount', count($LINKSDB));
     $PAGE->assign('privateLinkcount', count_private($LINKSDB));
@@ -2240,9 +2234,16 @@ $linkDb = new LinkDB(
     $conf->get('redirector.encode_url')
 );
 
+try {
+    $history = new History($conf->get('resource.history'));
+} catch(Exception $e) {
+    die($e->getMessage());
+}
+
 $container = new \Slim\Container();
 $container['conf'] = $conf;
 $container['plugins'] = $pluginManager;
+$container['history'] = $history;
 $app = new \Slim\App($container);
 
 // REST API routes
@@ -2262,7 +2263,7 @@ $response = $app->run(true);
 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);
+    renderPage($conf, $pluginManager, $linkDb, $history);
 } else {
     $app->respond($response);
 }