diff --git a/lib/SimpleSAML/XHTML/Template.php b/lib/SimpleSAML/XHTML/Template.php index 9178f251c62eab7661e3d9a2abc8661f4b17e024..13be9e395106f6eddb6d03eea3578fa38bb297cf 100644 --- a/lib/SimpleSAML/XHTML/Template.php +++ b/lib/SimpleSAML/XHTML/Template.php @@ -56,7 +56,7 @@ class Template extends Response * * @var false|Twig_Environment */ - private $twig; + private $twig = false; /** * The template name. @@ -130,15 +130,17 @@ class Template extends Response // check if we are supposed to use the new UI $this->useNewUI = $this->configuration->getBoolean('usenewui', false); - // check if we need to attach a theme controller - $controller = $this->configuration->getString('theme.controller', false); - if ($controller && class_exists($controller) && - in_array('\SimpleSAML\XHTML\TemplateControllerInterface', class_implements($controller)) - ) { - $this->controller = new $controller(); - } + if ($this->useNewUI) { + // check if we need to attach a theme controller + $controller = $this->configuration->getString('theme.controller', false); + if ($controller && class_exists($controller) && + in_array('\SimpleSAML\XHTML\TemplateControllerInterface', class_implements($controller)) + ) { + $this->controller = new $controller(); + } - $this->twig = $this->setupTwig(); + $this->twig = $this->setupTwig(); + } parent::__construct(); } @@ -268,29 +270,21 @@ class Template extends Response $this->localization->addModuleDomain($this->theme['module']); } + // set up translation $options = [ 'cache' => $cache, 'auto_reload' => $auto_reload, - 'translation_function' => ['\SimpleSAML\Locale\Translate', 'translateSingularNativeGettext'], - 'translation_function_plural' => ['\SimpleSAML\Locale\Translate', 'translatePluralNativeGettext'], + 'translation_function' => ['\SimpleSAML\Locale\Translate', 'translateSingularGettext'], + 'translation_function_plural' => ['\SimpleSAML\Locale\Translate', 'translatePluralGettext'], ]; - // set up translation - if ($this->localization->i18nBackend === \SimpleSAML\Locale\Localization::GETTEXT_I18N_BACKEND) { - $options['translation_function'] = ['\SimpleSAML\Locale\Translate', 'translateSingularGettext']; - $options['translation_function_plural'] = [ - '\SimpleSAML\Locale\Translate', - 'translatePluralGettext' - ]; - } // TODO: add a branch for the old SimpleSAMLphp backend - $twig = new Twig_Environment($loader, $options); $twig->addExtension(new Twig_Extensions_Extension_I18n()); // initialize some basic context $langParam = $this->configuration->getString('language.parameter.name', 'language'); $twig->addGlobal('languageParameterName', $langParam); - $twig->addGlobal('localeBackend', $this->useNewUI ? Localization::GETTEXT_I18N_BACKEND : Localization::SSP_I18N_BACKEND); + $twig->addGlobal('localeBackend', Localization::GETTEXT_I18N_BACKEND); $twig->addGlobal('currentLanguage', $this->translator->getLanguage()->getLanguage()); $twig->addGlobal('isRTL', false); // language RTL configuration if ($this->translator->getLanguage()->isLanguageRTL()) { diff --git a/www/admin/sandbox.php b/www/admin/sandbox.php index d7cf29365cc7c9bb41d1953ed99a0ef8908ff61d..e2318bd187fedad71499f2467b8fc042bfcb9060 100644 --- a/www/admin/sandbox.php +++ b/www/admin/sandbox.php @@ -3,17 +3,15 @@ require_once('../_include.php'); // Load SimpleSAMLphp configuration -$config = \SimpleSAML\Configuration::getInstance(); +$config = \SimpleSAML\Configuration::getInstance()->toArray(); +$config['usenewui'] = true; +$config = \SimpleSAML\Configuration::loadFromArray($config, '[ARRAY]', 'simplesaml'); $session = \SimpleSAML\Session::getSessionFromRequest(); -// Check if valid local session exists.. -//SimpleSAML\Utils\Auth::requireAdmin(); - $template = new \SimpleSAML\XHTML\Template($config, 'sandbox.php'); - $template->data['pagetitle'] = 'Sandbox'; $template->data['sometext'] = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur.'; $template->data['remaining'] = $session->getAuthData('admin', 'Expire') - time(); $template->data['logout'] = null; -$template->show(); +$template->send();