aboutsummaryrefslogtreecommitdiffhomepage
path: root/index.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-05-30 14:00:06 +0200
committerArthurHoaro <arthur@hoa.ro>2020-07-23 21:19:21 +0200
commit66063ed1a18d739b1a60bfb163d8656417a4c529 (patch)
tree5af628861a42af1a4bf84f6dcd18a24b80cc3a1c /index.php
parent465033230da0398426010aa7bd3694735b71c899 (diff)
downloadShaarli-66063ed1a18d739b1a60bfb163d8656417a4c529.tar.gz
Shaarli-66063ed1a18d739b1a60bfb163d8656417a4c529.tar.zst
Shaarli-66063ed1a18d739b1a60bfb163d8656417a4c529.zip
Process configure page through Slim controller
Diffstat (limited to 'index.php')
-rw-r--r--index.php86
1 files changed, 4 insertions, 82 deletions
diff --git a/index.php b/index.php
index ae56b800..50c0634a 100644
--- a/index.php
+++ b/index.php
@@ -513,88 +513,8 @@ function renderPage($conf, $pluginManager, $bookmarkService, $history, $sessionM
513 513
514 // -------- User wants to change configuration 514 // -------- User wants to change configuration
515 if ($targetPage == Router::$PAGE_CONFIGURE) { 515 if ($targetPage == Router::$PAGE_CONFIGURE) {
516 if (!empty($_POST['title'])) { 516 header('Location: ./configure');
517 if (!$sessionManager->checkToken($_POST['token'])) { 517 exit;
518 die(t('Wrong token.')); // Go away!
519 }
520 $tz = 'UTC';
521 if (!empty($_POST['continent']) && !empty($_POST['city'])
522 && isTimeZoneValid($_POST['continent'], $_POST['city'])
523 ) {
524 $tz = $_POST['continent'] . '/' . $_POST['city'];
525 }
526 $conf->set('general.timezone', $tz);
527 $conf->set('general.title', escape($_POST['title']));
528 $conf->set('general.header_link', escape($_POST['titleLink']));
529 $conf->set('general.retrieve_description', !empty($_POST['retrieveDescription']));
530 $conf->set('resource.theme', escape($_POST['theme']));
531 $conf->set('security.session_protection_disabled', !empty($_POST['disablesessionprotection']));
532 $conf->set('privacy.default_private_links', !empty($_POST['privateLinkByDefault']));
533 $conf->set('feed.rss_permalinks', !empty($_POST['enableRssPermalinks']));
534 $conf->set('updates.check_updates', !empty($_POST['updateCheck']));
535 $conf->set('privacy.hide_public_links', !empty($_POST['hidePublicLinks']));
536 $conf->set('api.enabled', !empty($_POST['enableApi']));
537 $conf->set('api.secret', escape($_POST['apiSecret']));
538 $conf->set('formatter', escape($_POST['formatter']));
539
540 if (! empty($_POST['language'])) {
541 $conf->set('translation.language', escape($_POST['language']));
542 }
543
544 $thumbnailsMode = extension_loaded('gd') ? $_POST['enableThumbnails'] : Thumbnailer::MODE_NONE;
545 if ($thumbnailsMode !== Thumbnailer::MODE_NONE
546 && $thumbnailsMode !== $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE)
547 ) {
548 $_SESSION['warnings'][] = t(
549 'You have enabled or changed thumbnails mode. '
550 .'<a href="./?do=thumbs_update">Please synchronize them</a>.'
551 );
552 }
553 $conf->set('thumbnails.mode', $thumbnailsMode);
554
555 try {
556 $conf->write($loginManager->isLoggedIn());
557 $history->updateSettings();
558 $pageCacheManager->invalidateCaches();
559 } catch (Exception $e) {
560 error_log(
561 'ERROR while writing config file after configuration update.' . PHP_EOL .
562 $e->getMessage()
563 );
564
565 // TODO: do not handle exceptions/errors in JS.
566 echo '<script>alert("'. $e->getMessage() .'");document.location=\'./?do=configure\';</script>';
567 exit;
568 }
569 echo '<script>alert("'. t('Configuration was saved.') .'");document.location=\'./?do=configure\';</script>';
570 exit;
571 } else {
572 // Show the configuration form.
573 $PAGE->assign('title', $conf->get('general.title'));
574 $PAGE->assign('theme', $conf->get('resource.theme'));
575 $PAGE->assign('theme_available', ThemeUtils::getThemes($conf->get('resource.raintpl_tpl')));
576 $PAGE->assign('formatter_available', ['default', 'markdown']);
577 list($continents, $cities) = generateTimeZoneData(
578 timezone_identifiers_list(),
579 $conf->get('general.timezone')
580 );
581 $PAGE->assign('continents', $continents);
582 $PAGE->assign('cities', $cities);
583 $PAGE->assign('retrieve_description', $conf->get('general.retrieve_description'));
584 $PAGE->assign('private_links_default', $conf->get('privacy.default_private_links', false));
585 $PAGE->assign('session_protection_disabled', $conf->get('security.session_protection_disabled', false));
586 $PAGE->assign('enable_rss_permalinks', $conf->get('feed.rss_permalinks', false));
587 $PAGE->assign('enable_update_check', $conf->get('updates.check_updates', true));
588 $PAGE->assign('hide_public_links', $conf->get('privacy.hide_public_links', false));
589 $PAGE->assign('api_enabled', $conf->get('api.enabled', true));
590 $PAGE->assign('api_secret', $conf->get('api.secret'));
591 $PAGE->assign('languages', Languages::getAvailableLanguages());
592 $PAGE->assign('gd_enabled', extension_loaded('gd'));
593 $PAGE->assign('thumbnails_mode', $conf->get('thumbnails.mode', Thumbnailer::MODE_NONE));
594 $PAGE->assign('pagetitle', t('Configure') .' - '. $conf->get('general.title', 'Shaarli'));
595 $PAGE->renderPage('configure');
596 exit;
597 }
598 } 518 }
599 519
600 // -------- User wants to rename a tag or delete it 520 // -------- User wants to rename a tag or delete it
@@ -1458,6 +1378,8 @@ $app->group('', function () {
1458 $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index')->setName('tools'); 1378 $this->get('/tools', '\Shaarli\Front\Controller\Admin\ToolsController:index')->setName('tools');
1459 $this->get('/password', '\Shaarli\Front\Controller\Admin\PasswordController:index')->setName('password'); 1379 $this->get('/password', '\Shaarli\Front\Controller\Admin\PasswordController:index')->setName('password');
1460 $this->post('/password', '\Shaarli\Front\Controller\Admin\PasswordController:change')->setName('changePassword'); 1380 $this->post('/password', '\Shaarli\Front\Controller\Admin\PasswordController:change')->setName('changePassword');
1381 $this->get('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:index')->setName('configure');
1382 $this->post('/configure', '\Shaarli\Front\Controller\Admin\ConfigureController:save')->setName('saveConfigure');
1461 1383
1462 $this 1384 $this
1463 ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage') 1385 ->get('/links-per-page', '\Shaarli\Front\Controller\Admin\SessionFilterController:linksPerPage')