]> git.immae.eu Git - github/shaarli/Shaarli.git/blobdiff - index.php
Process plugins administration page through Slim controllers
[github/shaarli/Shaarli.git] / index.php
index 7c49bc8dfafca3a186ca5f41e8e6dab2fb631b74..1571df60c9fa6f6085e1e21021712f2c0d2d0fdb 100644 (file)
--- a/index.php
+++ b/index.php
@@ -573,158 +573,25 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
     }
 
     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;
     }
 
     if ($targetPage == Router::$PAGE_IMPORT) {
-        // Upload a Netscape bookmark dump to import its contents
-
-        if (! isset($_POST['token']) || ! isset($_FILES['filetoupload'])) {
-            // Show import dialog
-            $PAGE->assign(
-                'maxfilesize',
-                get_max_upload_size(
-                    ini_get('post_max_size'),
-                    ini_get('upload_max_filesize'),
-                    false
-                )
-            );
-            $PAGE->assign(
-                'maxfilesizeHuman',
-                get_max_upload_size(
-                    ini_get('post_max_size'),
-                    ini_get('upload_max_filesize'),
-                    true
-                )
-            );
-            $PAGE->assign('pagetitle', t('Import') .' - '. $conf->get('general.title', 'Shaarli'));
-            $PAGE->renderPage('import');
-            exit;
-        }
-
-        // Import bookmarks from an uploaded file
-        if (isset($_FILES['filetoupload']['size']) && $_FILES['filetoupload']['size'] == 0) {
-            // The file is too big or some form field may be missing.
-            $msg = sprintf(
-                t(
-                    'The file you are trying to upload is probably bigger than what this webserver can accept'
-                    .' (%s). Please upload in smaller chunks.'
-                ),
-                get_max_upload_size(ini_get('post_max_size'), ini_get('upload_max_filesize'))
-            );
-            echo '<script>alert("'. $msg .'");document.location=\'./?do='.Router::$PAGE_IMPORT .'\';</script>';
-            exit;
-        }
-        if (! $sessionManager->checkToken($_POST['token'])) {
-            die('Wrong token.');
-        }
-        $netscapeBookmarkUtils = new NetscapeBookmarkUtils($bookmarkService, $conf, $history);
-        $status = $netscapeBookmarkUtils->import($_POST, $_FILES);
-        echo '<script>alert("'.$status.'");document.location=\'./?do='
-             .Router::$PAGE_IMPORT .'\';</script>';
+        header('Location: ./admin/import');
         exit;
     }
 
     // Plugin administration page
     if ($targetPage == Router::$PAGE_PLUGINSADMIN) {
-        $pluginMeta = $pluginManager->getPluginsMeta();
-
-        // Split plugins into 2 arrays: ordered enabled plugins and disabled.
-        $enabledPlugins = array_filter($pluginMeta, function ($v) {
-            return $v['order'] !== false;
-        });
-        // Load parameters.
-        $enabledPlugins = load_plugin_parameter_values($enabledPlugins, $conf->get('plugins', array()));
-        uasort(
-            $enabledPlugins,
-            function ($a, $b) {
-                return $a['order'] - $b['order'];
-            }
-        );
-        $disabledPlugins = array_filter($pluginMeta, function ($v) {
-            return $v['order'] === false;
-        });
-
-        $PAGE->assign('enabledPlugins', $enabledPlugins);
-        $PAGE->assign('disabledPlugins', $disabledPlugins);
-        $PAGE->assign('pagetitle', t('Plugin administration') .' - '. $conf->get('general.title', 'Shaarli'));
-        $PAGE->renderPage('pluginsadmin');
+        header('Location: ./admin/plugins');
         exit;
     }
 
     // Plugin administration form action
     if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) {
-        try {
-            if (isset($_POST['parameters_form'])) {
-                $pluginManager->executeHooks('save_plugin_parameters', $_POST);
-                unset($_POST['parameters_form']);
-                foreach ($_POST as $param => $value) {
-                    $conf->set('plugins.'. $param, escape($value));
-                }
-            } else {
-                $conf->set('general.enabled_plugins', save_plugin_config($_POST));
-            }
-            $conf->write($loginManager->isLoggedIn());
-            $history->updateSettings();
-        } catch (Exception $e) {
-            error_log(
-                'ERROR while saving plugin configuration:.' . PHP_EOL .
-                $e->getMessage()
-            );
-
-            // TODO: do not handle exceptions/errors in JS.
-            echo '<script>alert("'
-                . $e->getMessage()
-                .'");document.location=\'./?do='
-                . Router::$PAGE_PLUGINSADMIN
-                .'\';</script>';
-            exit;
-        }
-        header('Location: ./?do='. Router::$PAGE_PLUGINSADMIN);
+        // This route is no longer supported in legacy mode
+        header('Location: ./admin/plugins');
         exit;
     }
 
@@ -1105,6 +972,12 @@ $app->group('', function () {
     $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('/admin/import', '\Shaarli\Front\Controller\Admin\ImportController:index');
+    $this->post('/admin/import', '\Shaarli\Front\Controller\Admin\ImportController:import');
+    $this->get('/admin/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:index');
+    $this->post('/admin/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:save');
 
     $this->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage');
     $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility');