diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-06-20 15:14:24 +0200 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2020-07-23 21:19:21 +0200 |
commit | 1b8620b1ad4e2c647ff2d032c8e7c6687b6647a1 (patch) | |
tree | 98a76bf93f9ed84680daa06050680a7c0425e535 /index.php | |
parent | 78657347c5b463d7c22bfc8c87b7db39fe058833 (diff) | |
download | Shaarli-1b8620b1ad4e2c647ff2d032c8e7c6687b6647a1.tar.gz Shaarli-1b8620b1ad4e2c647ff2d032c8e7c6687b6647a1.tar.zst Shaarli-1b8620b1ad4e2c647ff2d032c8e7c6687b6647a1.zip |
Process plugins administration page through Slim controllers
Diffstat (limited to 'index.php')
-rw-r--r-- | index.php | 54 |
1 files changed, 5 insertions, 49 deletions
@@ -584,60 +584,14 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM | |||
584 | 584 | ||
585 | // Plugin administration page | 585 | // Plugin administration page |
586 | if ($targetPage == Router::$PAGE_PLUGINSADMIN) { | 586 | if ($targetPage == Router::$PAGE_PLUGINSADMIN) { |
587 | $pluginMeta = $pluginManager->getPluginsMeta(); | 587 | header('Location: ./admin/plugins'); |
588 | |||
589 | // Split plugins into 2 arrays: ordered enabled plugins and disabled. | ||
590 | $enabledPlugins = array_filter($pluginMeta, function ($v) { | ||
591 | return $v['order'] !== false; | ||
592 | }); | ||
593 | // Load parameters. | ||
594 | $enabledPlugins = load_plugin_parameter_values($enabledPlugins, $conf->get('plugins', array())); | ||
595 | uasort( | ||
596 | $enabledPlugins, | ||
597 | function ($a, $b) { | ||
598 | return $a['order'] - $b['order']; | ||
599 | } | ||
600 | ); | ||
601 | $disabledPlugins = array_filter($pluginMeta, function ($v) { | ||
602 | return $v['order'] === false; | ||
603 | }); | ||
604 | |||
605 | $PAGE->assign('enabledPlugins', $enabledPlugins); | ||
606 | $PAGE->assign('disabledPlugins', $disabledPlugins); | ||
607 | $PAGE->assign('pagetitle', t('Plugin administration') .' - '. $conf->get('general.title', 'Shaarli')); | ||
608 | $PAGE->renderPage('pluginsadmin'); | ||
609 | exit; | 588 | exit; |
610 | } | 589 | } |
611 | 590 | ||
612 | // Plugin administration form action | 591 | // Plugin administration form action |
613 | if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) { | 592 | if ($targetPage == Router::$PAGE_SAVE_PLUGINSADMIN) { |
614 | try { | 593 | // This route is no longer supported in legacy mode |
615 | if (isset($_POST['parameters_form'])) { | 594 | header('Location: ./admin/plugins'); |
616 | $pluginManager->executeHooks('save_plugin_parameters', $_POST); | ||
617 | unset($_POST['parameters_form']); | ||
618 | foreach ($_POST as $param => $value) { | ||
619 | $conf->set('plugins.'. $param, escape($value)); | ||
620 | } | ||
621 | } else { | ||
622 | $conf->set('general.enabled_plugins', save_plugin_config($_POST)); | ||
623 | } | ||
624 | $conf->write($loginManager->isLoggedIn()); | ||
625 | $history->updateSettings(); | ||
626 | } catch (Exception $e) { | ||
627 | error_log( | ||
628 | 'ERROR while saving plugin configuration:.' . PHP_EOL . | ||
629 | $e->getMessage() | ||
630 | ); | ||
631 | |||
632 | // TODO: do not handle exceptions/errors in JS. | ||
633 | echo '<script>alert("' | ||
634 | . $e->getMessage() | ||
635 | .'");document.location=\'./?do=' | ||
636 | . Router::$PAGE_PLUGINSADMIN | ||
637 | .'\';</script>'; | ||
638 | exit; | ||
639 | } | ||
640 | header('Location: ./?do='. Router::$PAGE_PLUGINSADMIN); | ||
641 | exit; | 595 | exit; |
642 | } | 596 | } |
643 | 597 | ||
@@ -1022,6 +976,8 @@ $app->group('', function () { | |||
1022 | $this->post('/admin/export', '\Shaarli\Front\Controller\Admin\ExportController:export'); | 976 | $this->post('/admin/export', '\Shaarli\Front\Controller\Admin\ExportController:export'); |
1023 | $this->get('/admin/import', '\Shaarli\Front\Controller\Admin\ImportController:index'); | 977 | $this->get('/admin/import', '\Shaarli\Front\Controller\Admin\ImportController:index'); |
1024 | $this->post('/admin/import', '\Shaarli\Front\Controller\Admin\ImportController:import'); | 978 | $this->post('/admin/import', '\Shaarli\Front\Controller\Admin\ImportController:import'); |
979 | $this->get('/admin/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:index'); | ||
980 | $this->post('/admin/plugins', '\Shaarli\Front\Controller\Admin\PluginsController:save'); | ||
1025 | 981 | ||
1026 | $this->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage'); | 982 | $this->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage'); |
1027 | $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility'); | 983 | $this->get('/visibility/{visibility}', '\Shaarli\Front\Controller\Admin\SessionFilterController:visibility'); |