]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - index.php
Process bookmark exports through Slim controllers
[github/shaarli/Shaarli.git] / index.php
index 93e5590bbaa9d284885a634ef9f9e900214c364a..030fdfa3132512694773831e5af19f1475c60683 100644 (file)
--- a/index.php
+++ b/index.php
@@ -567,68 +567,13 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
     }
 
     if ($targetPage == Router::$PAGE_PINLINK) {
-        if (! isset($_GET['id']) || !$bookmarkService->exists($_GET['id'])) {
-            // FIXME! Use a proper error system.
-            $msg = t('Invalid link ID provided');
-            echo '<script>alert("'. $msg .'");document.location=\''. index_url($_SERVER) .'\';</script>';
-            exit;
-        }
-        if (! $sessionManager->checkToken($_GET['token'])) {
-            die('Wrong token.');
-        }
-
-        $link = $bookmarkService->get($_GET['id']);
-        $link->setSticky(! $link->isSticky());
-        $bookmarkService->set($link);
-        header('Location: '.index_url($_SERVER));
+        // This route is no longer supported in legacy mode
+        header('Location: ./');
         exit;
     }
 
     if ($targetPage == Router::$PAGE_EXPORT) {
-        // Export bookmarks as a Netscape Bookmarks file
-
-        if (empty($_GET['selection'])) {
-            $PAGE->assign('pagetitle', t('Export') .' - '. $conf->get('general.title', 'Shaarli'));
-            $PAGE->renderPage('export');
-            exit;
-        }
-
-        // export as bookmarks_(all|private|public)_YYYYmmdd_HHMMSS.html
-        $selection = $_GET['selection'];
-        if (isset($_GET['prepend_note_url'])) {
-            $prependNoteUrl = $_GET['prepend_note_url'];
-        } else {
-            $prependNoteUrl = false;
-        }
-
-        try {
-            $factory = new FormatterFactory($conf, $loginManager->isLoggedIn());
-            $formatter = $factory->getFormatter('raw');
-            $PAGE->assign(
-                'links',
-                NetscapeBookmarkUtils::filterAndFormat(
-                    $bookmarkService,
-                    $formatter,
-                    $selection,
-                    $prependNoteUrl,
-                    index_url($_SERVER)
-                )
-            );
-        } catch (Exception $exc) {
-            header('Content-Type: text/plain; charset=utf-8');
-            echo $exc->getMessage();
-            exit;
-        }
-        $now = new DateTime();
-        header('Content-Type: text/html; charset=utf-8');
-        header(
-            'Content-disposition: attachment; filename=bookmarks_'
-            .$selection.'_'.$now->format(Bookmark::LINK_DATE_FORMAT).'.html'
-        );
-        $PAGE->assign('date', $now->format(DateTime::RFC822));
-        $PAGE->assign('eol', PHP_EOL);
-        $PAGE->assign('selection', $selection);
-        $PAGE->renderPage('export.bookmarks');
+        header('Location: ./admin/export');
         exit;
     }
 
@@ -674,13 +619,8 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
         if (! $sessionManager->checkToken($_POST['token'])) {
             die('Wrong token.');
         }
-        $status = NetscapeBookmarkUtils::import(
-            $_POST,
-            $_FILES,
-            $bookmarkService,
-            $conf,
-            $history
-        );
+        $netscapeBookmarkUtils = new NetscapeBookmarkUtils($bookmarkService, $conf, $history);
+        $status = $netscapeBookmarkUtils->import($_POST, $_FILES);
         echo '<script>alert("'.$status.'");document.location=\'./?do='
              .Router::$PAGE_IMPORT .'\';</script>';
         exit;
@@ -1121,6 +1061,9 @@ $app->group('', function () {
     $this->post('/admin/shaare', '\Shaarli\Front\Controller\Admin\ManageShaareController:save');
     $this->get('/admin/shaare/delete', '\Shaarli\Front\Controller\Admin\ManageShaareController:deleteBookmark');
     $this->get('/admin/shaare/visibility', '\Shaarli\Front\Controller\Admin\ManageShaareController:changeVisibility');
+    $this->get('/admin/shaare/{id:[0-9]+}/pin', '\Shaarli\Front\Controller\Admin\ManageShaareController:pinBookmark');
+    $this->get('/admin/export', '\Shaarli\Front\Controller\Admin\ExportController:index');
+    $this->post('/admin/export', '\Shaarli\Front\Controller\Admin\ExportController:export');
 
     $this->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage');
     $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility');