aboutsummaryrefslogtreecommitdiffhomepage
path: root/application
diff options
context:
space:
mode:
Diffstat (limited to 'application')
-rw-r--r--application/container/ContainerBuilder.php7
-rw-r--r--application/front/controller/admin/PluginsController.php98
-rw-r--r--application/plugin/PluginManager.php2
3 files changed, 105 insertions, 2 deletions
diff --git a/application/container/ContainerBuilder.php b/application/container/ContainerBuilder.php
index a4fd6a0c..ba91fe8b 100644
--- a/application/container/ContainerBuilder.php
+++ b/application/container/ContainerBuilder.php
@@ -88,7 +88,12 @@ class ContainerBuilder
88 }; 88 };
89 89
90 $container['pluginManager'] = function (ShaarliContainer $container): PluginManager { 90 $container['pluginManager'] = function (ShaarliContainer $container): PluginManager {
91 return new PluginManager($container->conf); 91 $pluginManager = new PluginManager($container->conf);
92
93 // FIXME! Configuration is already injected
94 $pluginManager->load($container->conf->get('general.enabled_plugins'));
95
96 return $pluginManager;
92 }; 97 };
93 98
94 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory { 99 $container['formatterFactory'] = function (ShaarliContainer $container): FormatterFactory {
diff --git a/application/front/controller/admin/PluginsController.php b/application/front/controller/admin/PluginsController.php
new file mode 100644
index 00000000..d5ec91f0
--- /dev/null
+++ b/application/front/controller/admin/PluginsController.php
@@ -0,0 +1,98 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Admin;
6
7use Exception;
8use Slim\Http\Request;
9use Slim\Http\Response;
10
11/**
12 * Class PluginsController
13 *
14 * Slim controller used to handle Shaarli plugins configuration page (display + save new config).
15 */
16class PluginsController extends ShaarliAdminController
17{
18 /**
19 * GET /admin/plugins - Displays the configuration page
20 */
21 public function index(Request $request, Response $response): Response
22 {
23 $pluginMeta = $this->container->pluginManager->getPluginsMeta();
24
25 // Split plugins into 2 arrays: ordered enabled plugins and disabled.
26 $enabledPlugins = array_filter($pluginMeta, function ($v) {
27 return ($v['order'] ?? false) !== false;
28 });
29 $enabledPlugins = load_plugin_parameter_values($enabledPlugins, $this->container->conf->get('plugins', []));
30 uasort(
31 $enabledPlugins,
32 function ($a, $b) {
33 return $a['order'] - $b['order'];
34 }
35 );
36 $disabledPlugins = array_filter($pluginMeta, function ($v) {
37 return ($v['order'] ?? false) === false;
38 });
39
40 $this->assignView('enabledPlugins', $enabledPlugins);
41 $this->assignView('disabledPlugins', $disabledPlugins);
42 $this->assignView(
43 'pagetitle',
44 t('Plugin Administration') .' - '. $this->container->conf->get('general.title', 'Shaarli')
45 );
46
47 return $response->write($this->render('pluginsadmin'));
48 }
49
50 /**
51 * POST /admin/plugins - Update Shaarli's configuration
52 */
53 public function save(Request $request, Response $response): Response
54 {
55 $this->checkToken($request);
56
57 try {
58 $parameters = $request->getParams() ?? [];
59
60 $this->executeHooks($parameters);
61
62 if (isset($parameters['parameters_form'])) {
63 unset($parameters['parameters_form']);
64 foreach ($parameters as $param => $value) {
65 $this->container->conf->set('plugins.'. $param, escape($value));
66 }
67 } else {
68 $this->container->conf->set('general.enabled_plugins', save_plugin_config($parameters));
69 }
70
71 $this->container->conf->write($this->container->loginManager->isLoggedIn());
72 $this->container->history->updateSettings();
73
74 $this->saveSuccessMessage(t('Setting successfully saved.'));
75 } catch (Exception $e) {
76 $this->saveErrorMessage(
77 t('ERROR while saving plugin configuration: ') . PHP_EOL . $e->getMessage()
78 );
79 }
80
81 return $this->redirect($response, '/admin/plugins');
82 }
83
84 /**
85 * @param mixed[] $data Variables passed to the template engine
86 *
87 * @return mixed[] Template data after active plugins render_picwall hook execution.
88 */
89 protected function executeHooks(array $data): array
90 {
91 $this->container->pluginManager->executeHooks(
92 'save_plugin_parameters',
93 $data
94 );
95
96 return $data;
97 }
98}
diff --git a/application/plugin/PluginManager.php b/application/plugin/PluginManager.php
index f7b24a8e..591a9180 100644
--- a/application/plugin/PluginManager.php
+++ b/application/plugin/PluginManager.php
@@ -16,7 +16,7 @@ class PluginManager
16 * 16 *
17 * @var array $authorizedPlugins 17 * @var array $authorizedPlugins
18 */ 18 */
19 private $authorizedPlugins; 19 private $authorizedPlugins = [];
20 20
21 /** 21 /**
22 * List of loaded plugins. 22 * List of loaded plugins.