aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/front
diff options
context:
space:
mode:
Diffstat (limited to 'application/front')
-rw-r--r--application/front/controller/admin/ConfigureController.php120
1 files changed, 120 insertions, 0 deletions
diff --git a/application/front/controller/admin/ConfigureController.php b/application/front/controller/admin/ConfigureController.php
new file mode 100644
index 00000000..b1d32270
--- /dev/null
+++ b/application/front/controller/admin/ConfigureController.php
@@ -0,0 +1,120 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Shaarli\Front\Controller\Admin;
6
7use Shaarli\Languages;
8use Shaarli\Render\ThemeUtils;
9use Shaarli\Thumbnailer;
10use Slim\Http\Request;
11use Slim\Http\Response;
12use Throwable;
13
14/**
15 * Class PasswordController
16 *
17 * Slim controller used to handle Shaarli configuration page (display + save new config).
18 */
19class ConfigureController extends ShaarliAdminController
20{
21 /**
22 * GET /configure - Displays the configuration page
23 */
24 public function index(Request $request, Response $response): Response
25 {
26 $this->assignView('title', $this->container->conf->get('general.title', 'Shaarli'));
27 $this->assignView('theme', $this->container->conf->get('resource.theme'));
28 $this->assignView(
29 'theme_available',
30 ThemeUtils::getThemes($this->container->conf->get('resource.raintpl_tpl'))
31 );
32 $this->assignView('formatter_available', ['default', 'markdown']);
33 list($continents, $cities) = generateTimeZoneData(
34 timezone_identifiers_list(),
35 $this->container->conf->get('general.timezone')
36 );
37 $this->assignView('continents', $continents);
38 $this->assignView('cities', $cities);
39 $this->assignView('retrieve_description', $this->container->conf->get('general.retrieve_description', false));
40 $this->assignView('private_links_default', $this->container->conf->get('privacy.default_private_links', false));
41 $this->assignView(
42 'session_protection_disabled',
43 $this->container->conf->get('security.session_protection_disabled', false)
44 );
45 $this->assignView('enable_rss_permalinks', $this->container->conf->get('feed.rss_permalinks', false));
46 $this->assignView('enable_update_check', $this->container->conf->get('updates.check_updates', true));
47 $this->assignView('hide_public_links', $this->container->conf->get('privacy.hide_public_links', false));
48 $this->assignView('api_enabled', $this->container->conf->get('api.enabled', true));
49 $this->assignView('api_secret', $this->container->conf->get('api.secret'));
50 $this->assignView('languages', Languages::getAvailableLanguages());
51 $this->assignView('gd_enabled', extension_loaded('gd'));
52 $this->assignView('thumbnails_mode', $this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE));
53 $this->assignView('pagetitle', t('Configure') .' - '. $this->container->conf->get('general.title', 'Shaarli'));
54
55 return $response->write($this->render('configure'));
56 }
57
58 /**
59 * POST /configure - Update Shaarli's configuration
60 */
61 public function save(Request $request, Response $response): Response
62 {
63 $this->checkToken($request);
64
65 $continent = $request->getParam('continent');
66 $city = $request->getParam('city');
67 $tz = 'UTC';
68 if (null !== $continent && null !== $city && isTimeZoneValid($continent, $city)) {
69 $tz = $continent . '/' . $city;
70 }
71
72 $this->container->conf->set('general.timezone', $tz);
73 $this->container->conf->set('general.title', escape($request->getParam('title')));
74 $this->container->conf->set('general.header_link', escape($request->getParam('titleLink')));
75 $this->container->conf->set('general.retrieve_description', !empty($request->getParam('retrieveDescription')));
76 $this->container->conf->set('resource.theme', escape($request->getParam('theme')));
77 $this->container->conf->set(
78 'security.session_protection_disabled',
79 !empty($request->getParam('disablesessionprotection'))
80 );
81 $this->container->conf->set(
82 'privacy.default_private_links',
83 !empty($request->getParam('privateLinkByDefault'))
84 );
85 $this->container->conf->set('feed.rss_permalinks', !empty($request->getParam('enableRssPermalinks')));
86 $this->container->conf->set('updates.check_updates', !empty($request->getParam('updateCheck')));
87 $this->container->conf->set('privacy.hide_public_links', !empty($request->getParam('hidePublicLinks')));
88 $this->container->conf->set('api.enabled', !empty($request->getParam('enableApi')));
89 $this->container->conf->set('api.secret', escape($request->getParam('apiSecret')));
90 $this->container->conf->set('formatter', escape($request->getParam('formatter')));
91
92 if (!empty($request->getParam('language'))) {
93 $this->container->conf->set('translation.language', escape($request->getParam('language')));
94 }
95
96 $thumbnailsMode = extension_loaded('gd') ? $request->getParam('enableThumbnails') : Thumbnailer::MODE_NONE;
97 if ($thumbnailsMode !== Thumbnailer::MODE_NONE
98 && $thumbnailsMode !== $this->container->conf->get('thumbnails.mode', Thumbnailer::MODE_NONE)
99 ) {
100 $this->saveWarningMessage(t(
101 'You have enabled or changed thumbnails mode. '
102 .'<a href="./?do=thumbs_update">Please synchronize them</a>.'
103 ));
104 }
105 $this->container->conf->set('thumbnails.mode', $thumbnailsMode);
106
107 try {
108 $this->container->conf->write($this->container->loginManager->isLoggedIn());
109 $this->container->history->updateSettings();
110 $this->container->pageCacheManager->invalidateCaches();
111 } catch (Throwable $e) {
112 // TODO: translation + stacktrace
113 $this->saveErrorMessage('ERROR while writing config file after configuration update.');
114 }
115
116 $this->saveSuccessMessage(t('Configuration was saved.'));
117
118 return $response->withRedirect('./configure');
119 }
120}