From f7addcc44d6fbf6dff84e48de6201384e2c1777c Mon Sep 17 00:00:00 2001 From: peter Date: Tue, 23 Oct 2007 09:59:59 +0000 Subject: [PATCH] - added new methods for time, date, price to language manager git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@64 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- www/inc/config_manager.php | 60 ++++++++++++++++++++++++++++++++++++++++++ www/inc/event.php | 19 ++----------- www/inc/language_manager.php | 19 ++++++++++--- www/inc/loader_nonadmin.php | 7 +++-- www/template/de/lang.conf | 10 +++++++ 5 files changed, 91 insertions(+), 24 deletions(-) create mode 100644 www/inc/config_manager.php create mode 100644 www/template/de/lang.conf diff --git a/www/inc/config_manager.php b/www/inc/config_manager.php new file mode 100644 index 0000000..0e21f38 --- /dev/null +++ b/www/inc/config_manager.php @@ -0,0 +1,60 @@ + +// +---------------------------------------------------------------------- +// | +// | Copyright: See COPYING file that comes with this distribution +// +---------------------------------------------------------------------- +// + +class ConfigManager +{ + private $configFile; + private $config; + + public function __construct($file = "lang.conf") + { + global $template; + + $this->configFile = $template.$file; + $this->readConfig(); + } + + /** reads the configuration values from the file */ + private function readConfig() + { + // check if file really exists + if (file_exists($this->configFile)) { + $lines = file($this->configFile); + $this->config = array(); + + foreach ($lines as $line_num => $line) { + # Comment? + if ( !preg_match("/^#.*/", $line) ) { + # Contains non-whitespace? + if ( preg_match("/\S/", $line) ) { + list( $key, $value ) = explode( "=", trim( $line ), 2); + $this->config[trim($key)] = trim($value); + } + } + } + } + } + + /** returns the value of the given configuration item */ + public function get($key) + { + return $this->config[$key]; + } + + /** can be used to set an alternate path to a config file */ + public function setConfigFile($file) + { + $this->configFile = $file; + $this->readConfig(); + } +} + +?> diff --git a/www/inc/event.php b/www/inc/event.php index 660ae61..14f9f2e 100644 --- a/www/inc/event.php +++ b/www/inc/event.php @@ -116,25 +116,12 @@ class Event public function getDescription(){return $this->description;} /**returns the reason why the event is cancelled if isCancelled() returns true*/ public function getCancelReason(){return $this->cancelreason;} - /**returns the date of the event*/ - public function getStDate() - { - return date("d.m.Y", $this->getStartTime()); - } - /**returns the time of the event*/ - public function getStTime() - { - return date("H:i", $this->getStartTime()); - } - /**returns the price in euro*/ - public function getPriceInEuro() - { - return number_format($this->getDefaultPrice()/100, 2, ",", "."); - } /**returns the data in an array*/ public function getParserData() { - return array("DATE"=>$this->getStDate(), "TIME"=>$this->getStTime(), "PLACE"=>$this->getRoomId(), "EVENTNAME"=>$this->getTitle(), "ARTIST"=>$this->getArtist(),"PRICE"=>$this->getPriceInEuro(), "ID"=>$this->getEventId(), "DESCRIPTION"=>$this->getDescription()); + global $lang; + + return array("DATE"=>$lang->getDate($this->getStartTime()), "TIME"=>$lang->getTime($this->getStartTime()), "PLACE"=>$this->getRoomId(), "EVENTNAME"=>$this->getTitle(), "ARTIST"=>$this->getArtist(),"PRICE"=>$lang->getPrice($this->getDefaultPrice()), "ID"=>$this->getEventId(), "DESCRIPTION"=>$this->getDescription()); } }; diff --git a/www/inc/language_manager.php b/www/inc/language_manager.php index 5956e03..6db60e8 100644 --- a/www/inc/language_manager.php +++ b/www/inc/language_manager.php @@ -13,6 +13,7 @@ class LanguageManager { private $COOKIE_NAME = "ms_lang"; private $lang; + private $config; /** constructor */ public function __construct() @@ -35,6 +36,8 @@ class LanguageManager // set default value $template .= "de/"; } + + $this->config = new ConfigManager("lang.conf"); } /** set language */ @@ -44,22 +47,28 @@ class LanguageManager setcookie($this->COOKIE_NAME, $language, 0); } - /** get date in current language */ + /** returns date in current language */ public function getDate($date) { - + return date($this->config->get("DateFormat"), $date); } - /** get time in current language */ + /** returns time in current language */ public function getTime($time) { - + return date($this->config->get("TimeFormat"), $time); } - /** get price in current language */ + /** returns price in current language */ public function getPrice($price) { + return number_format($price/100, 2, $this->config->get("DecimalPoint"), $this->config->get("ThousandSeparator")); + } + /** returns error message for specified number in current language */ + public function getErrMsg($num) + { + return $this->config->get("ERR".$num); } } diff --git a/www/inc/loader_nonadmin.php b/www/inc/loader_nonadmin.php index 7ae349c..13e48b1 100644 --- a/www/inc/loader_nonadmin.php +++ b/www/inc/loader_nonadmin.php @@ -8,8 +8,9 @@ include('./inc/room.php'); include("./inc/random.php"); include("./inc/order.php"); include("./inc/cart.php"); -include('inc/error.php'); -include('inc/language_manager.php'); -include('inc/parser.php'); +include('./inc/error.php'); +include('./inc/language_manager.php'); +include('./inc/parser.php'); +include('./inc/config_manager.php') ?> \ No newline at end of file diff --git a/www/template/de/lang.conf b/www/template/de/lang.conf new file mode 100644 index 0000000..f3b6c9a --- /dev/null +++ b/www/template/de/lang.conf @@ -0,0 +1,10 @@ +# Time +TimeFormat = H:i +DateFormat = d/m/Y + +# Currency +DecimalPoint = . +ThousandSeparator = , + +# Error messages +ERR001 = Test \ No newline at end of file -- 1.7.2.5