Added the ability to web users to change the theme

This commit is contained in:
Ribas160 2025-02-05 15:12:38 +02:00
parent 6ba9fe5a93
commit c7a4ced9e1
45 changed files with 367 additions and 43 deletions

View file

@ -179,7 +179,14 @@ class Controller
$this->_request = new Request;
$this->_urlBase = $this->_request->getRequestUri();
// set default language
$this->_setDefaultLanguage();
$this->_setDefaultTemplate();
}
private function _setDefaultLanguage()
{
$this->_conf = new Configuration;
$lang = $this->_conf->getKey('languagedefault');
I18n::setLanguageFallback($lang);
// force default language, if language selection is disabled and a default is set
@ -189,6 +196,20 @@ class Controller
}
}
private function _setDefaultTemplate()
{
$this->_conf = new Configuration;
$template = $this->_conf->getKey('templatedefault');
TemplateSwitcher::setTemplateFallback($template);
// force default template, if template selection is disabled and a default is set
if (!$this->_conf->getKey('languageselection') && strlen($template) == 2) {
$_COOKIE['template'] = $template;
setcookie('template', $template, array('SameSite' => 'Lax', 'Secure' => true));
}
}
/**
* Turn off browser caching
*
@ -400,6 +421,13 @@ class Controller
setcookie('lang', $languageselection, array('SameSite' => 'Lax', 'Secure' => true));
}
// set template cookie if that functionality was enabled
$templateselection = '';
if ($this->_conf->getKey('templateselection')) {
$templateselection = TemplateSwitcher::getTemplate();
setcookie('template', $templateselection, array('SameSite' => 'Lax', 'Secure' => true));
}
// strip policies that are unsupported in meta tag
$metacspheader = str_replace(
array(
@ -438,6 +466,8 @@ class Controller
$page->assign('ZEROBINCOMPATIBILITY', $this->_conf->getKey('zerobincompatibility'));
$page->assign('LANGUAGESELECTION', $languageselection);
$page->assign('LANGUAGES', I18n::getLanguageLabels(I18n::getAvailableLanguages()));
$page->assign('TEMPLATESELECTION', $templateselection);
$page->assign('TEMPLATES', TemplateSwitcher::getAvailableTemplates());
$page->assign('EXPIRE', $expire);
$page->assign('EXPIREDEFAULT', $this->_conf->getKey('default', 'expire'));
$page->assign('URLSHORTENER', $this->_conf->getKey('urlshortener'));
@ -447,7 +477,7 @@ class Controller
$page->assign('HTTPSLINK', 'https://' . $this->_request->getHost() . $this->_request->getRequestUri());
$page->assign('COMPRESSION', $this->_conf->getKey('compression'));
$page->assign('SRI', $this->_conf->getSection('sri'));
$page->draw($this->_conf->getKey('template'));
$page->draw(TemplateSwitcher::getTemplate());
}
/**