openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 1d2894cd663c380227070e618f1763b676922d93
parent f4f93f48036bf39596148cd0aec1cc4da083d054
Author: Jan Dankert <devnull@localhost>
Date:   Tue,  4 Sep 2018 22:54:39 +0200

Der Language-Loader ist jetzt nicht-statisch, damit die Initialisierung der Variablen im Konstruktur geschehen kann.

Diffstat:
modules/cms-core/Dispatcher.class.php | 3++-
modules/cms-core/action/LoginAction.class.php | 15++++++++++-----
modules/cms-core/action/ProfileAction.class.php | 3++-
modules/configuration/ConfigurationLoader.class.php | 6+++---
modules/language/Language.class.php | 35++++++++++++++++++++---------------
5 files changed, 37 insertions(+), 25 deletions(-)

diff --git a/modules/cms-core/Dispatcher.class.php b/modules/cms-core/Dispatcher.class.php @@ -239,7 +239,8 @@ class Dispatcher continue; // language is not configured as available. $isProduction = $conf['production']; - $lang = Language::getLanguage( $l,$isProduction); + $language = new \language\Language(); + $lang = $language->getLanguage( $l,$isProduction); $conf['language'] = $lang; $conf['language']['language_code'] = $l; break; diff --git a/modules/cms-core/action/LoginAction.class.php b/modules/cms-core/action/LoginAction.class.php @@ -353,10 +353,14 @@ class LoginAction extends Action foreach( $conf['database'] as $dbid => $dbconf ) { - if ( is_array($dbconf) && $dbconf['enabled'] ) - $dbids[$dbid] = array('key' => $dbid, - 'value' => empty($dbconf['name'])?$dbid:Text::maxLength($dbconf['name']), - 'title' => @$dbconf['description'] ); + $dbconf += $conf['database-default']['defaults']; // Add Default-Values + + if ( is_array($dbconf) && $dbconf['enabled'] ) // Database-Connection is enabled + $dbids[$dbid] = array( + 'key' => $dbid, + 'value' => empty($dbconf['name']) ? $dbid : Text::maxLength($dbconf['name']), + 'title' => $dbconf['description'] + ); } @@ -995,7 +999,8 @@ class LoginAction extends Action $this->setStyle( $user->style ); // Benutzer-Style setzen $config = Session::getConfig(); - $config['language'] = \language\Language::getLanguage($user->language); + $language = new \language\Language(); + $config['language'] = $language->getLanguage($user->language); $config['language']['language_code'] = $user->language; Session::setConfig( $config ); diff --git a/modules/cms-core/action/ProfileAction.class.php b/modules/cms-core/action/ProfileAction.class.php @@ -299,7 +299,8 @@ class ProfileAction extends Action public function setLanguage($l) { $conf = Session::getConfig(); - $conf['language'] = Language::getLanguage($l,PRODUCTION); + $language = new \language\Language(); + $conf['language'] = $language->getLanguage($l,PRODUCTION); $conf['language']['language_code'] = $l; Session::setConfig($conf); } diff --git a/modules/configuration/ConfigurationLoader.class.php b/modules/configuration/ConfigurationLoader.class.php @@ -69,9 +69,9 @@ class ConfigurationLoader // Den Dateinamen der Konfigurationsdatei in die Konfiguration schreiben. - $customConfig['config']['filename' ] = self::$configFile; - $customConfig['config']['last_modification_time'] = filemtime(self::$configFile); - $customConfig['config']['last_modification' ] = date('r', filemtime(self::$configFile)); + $customConfig['config']['filename' ] = $this->configFile; + $customConfig['config']['last_modification_time'] = filemtime($this->configFile); + $customConfig['config']['last_modification' ] = date('r', filemtime($this->configFile)); $customConfig['config']['read' ] = date('r'); return $customConfig; diff --git a/modules/language/Language.class.php b/modules/language/Language.class.php @@ -7,20 +7,25 @@ use Spyc; class Language { - private static $srcFile = __DIR__ . '/language.yml'; + private $srcFile; + + public function __construct() + { + $this->srcFile = __DIR__ . '/language.yml'; + } /** * @param $iso ISO-Code * @param bool $production Are we in a production environment? * @return array The language values */ - public static function getLanguage($iso, $production = true) + public function getLanguage($iso, $production = true) { if ( !$production) { - self::compileLanguage($iso); + $this->compileLanguage($iso); } - return self::getLanguageProduction($iso); + return $this->getLanguageProduction($iso); } /** @@ -28,12 +33,12 @@ class Language * Only, if the YAML source file has changed. * @param $iso ISO-code */ - private static function compileLanguage($iso) + private function compileLanguage($iso) { - if ( filemtime(self::$srcFile) > filemtime( self::getOutputLanguageFile('en')) ) + if ( filemtime($this->srcFile) > filemtime( $this->getOutputLanguageFile('en')) ) { // source file newer than production file => compile. - self::updateProduction(); + $this->updateProduction(); } } @@ -41,27 +46,27 @@ class Language * @param $iso ISO-language-code * @return array */ - private static function getLanguageProduction($iso) + private function getLanguageProduction($iso) { - $langFile = self::getOutputLanguageFile($iso,'en'); + $langFile = $this->getOutputLanguageFile($iso,'en'); require($langFile); // Contains the function 'language()' return language(); } - private static function getLanguageSource() + private function getLanguageSource() { - return Spyc::YAMLLoad( self::$srcFile); + return Spyc::YAMLLoad( $this->srcFile); } /** * Creates the production environment. */ - public static function updateProduction() + public function updateProduction() { - $lang = self::getLanguageSource(); + $lang = $this->getLanguageSource(); // creating a list of alle language iso codes. $isoList = array(); @@ -76,7 +81,7 @@ class Language } foreach ($isoList as $iso) { - $outputFilename = self::getOutputLanguageFile($iso); + $outputFilename = $this->getOutputLanguageFile($iso); $success = file_put_contents($outputFilename, "<?php /* DO NOT CHANGE THIS GENERATED FILE */\n"); @@ -108,7 +113,7 @@ class Language * @param null string $fallbackiso Fallback to this ISO-Code, if the file does not exist. * @return string filename */ - private static function getOutputLanguageFile($iso, $fallbackiso = null ) + private function getOutputLanguageFile($iso, $fallbackiso = null ) { $langFile = __DIR__ . '/lang-' . $iso . '.php';