From 8311cba002dfcaf1836530b978f944f7228ac004 Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 21 Sep 2011 17:00:50 +0200 Subject: Replaced Smarty with STE and started the backend. --- ratatoeskr/sys/init_ste.php | 46 +++++++++++++++++++++++++++++++++++ ratatoeskr/sys/load_smarty.php | 30 ----------------------- ratatoeskr/sys/models.php | 4 ++- ratatoeskr/sys/plugin_api.php | 12 ++++----- ratatoeskr/sys/translation.php | 55 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 110 insertions(+), 37 deletions(-) create mode 100644 ratatoeskr/sys/init_ste.php delete mode 100644 ratatoeskr/sys/load_smarty.php create mode 100644 ratatoeskr/sys/translation.php (limited to 'ratatoeskr/sys') diff --git a/ratatoeskr/sys/init_ste.php b/ratatoeskr/sys/init_ste.php new file mode 100644 index 0000000..567a32b --- /dev/null +++ b/ratatoeskr/sys/init_ste.php @@ -0,0 +1,46 @@ +register_tag( + "l10n_replace", + function($ste, $params, $sub) + { + $content = $sub($ste); + foreach($params as $name => $replace) + $content = str_replace("[[$name]]", $replace, $content); + return $content; + } +); +$ste->register_tag( + "capitalize", + function($ste, $params, $sub) + { + return ucwords($sub($ste)); + } +); + +?> diff --git a/ratatoeskr/sys/load_smarty.php b/ratatoeskr/sys/load_smarty.php deleted file mode 100644 index 43df957..0000000 --- a/ratatoeskr/sys/load_smarty.php +++ /dev/null @@ -1,30 +0,0 @@ -setTemplateDir(dirname(__FILE__) . "/../templates/"); - $smarty->setCompileDir(dirname(__FILE__) . "/../tmp/smartytemplates_c"); - $smarty->setCacheDir(dirname(__FILE__) . "/../tmp/smarty/cache"); - $smarty->setConfigDir(dirname(__FILE__) . "/../smarty_confdir"); - $smarty->left_delimiter = "{%"; - $smarty->right_delimiter = "%}"; -} - -?> diff --git a/ratatoeskr/sys/models.php b/ratatoeskr/sys/models.php index d8da3b0..21147fb 100644 --- a/ratatoeskr/sys/models.php +++ b/ratatoeskr/sys/models.php @@ -31,7 +31,7 @@ $imagetype_file_extensions = array( * Variable: $ratatoeskr_settings * The global object. For internal use. */ -$ratatoeskr_settings = new Settings("rw"); +$ratatoeskr_settings = NULL; /* * Class: DoesNotExistError @@ -911,6 +911,8 @@ class Settings implements Countable, ArrayAccess, IteratorAggregate public function getIterator() { return new SettingsIterator($this); } } +$ratatoeskr_settings = new Settings("rw"); + /* * Class: PluginKVStorage * A Key-Value-Storage for Plugins diff --git a/ratatoeskr/sys/plugin_api.php b/ratatoeskr/sys/plugin_api.php index 65e4c9c..6293c27 100644 --- a/ratatoeskr/sys/plugin_api.php +++ b/ratatoeskr/sys/plugin_api.php @@ -38,10 +38,10 @@ abstract class RatatoeskrPlugin * Variables: Protected variables * * $kvstorage - The Key-Value-Storage for the Plugin. - * $smarty - Access to the global smarty object. + * $ste - Access to the global STECore object. */ protected $kvstorage; - protected $smarty; + protected $ste; /* @@ -54,11 +54,11 @@ abstract class RatatoeskrPlugin */ public function __construct($id) { - global $smarty; + global $ste; $this->id = $id; $this->kvstorage = new PluginKVStorage($id); - $this->smarty = $smarty; + $this->ste = $ste; } /* @@ -70,7 +70,7 @@ abstract class RatatoeskrPlugin */ final public function get_id() { return $this->id; } final protected function get_additional_files_dir() { return dirname(dirname(__FILE__)) . "/plugin_extradata/" . $this->id; } - final protected function get_template_dir() { return dirname(dirname(__FILE__)) . "/templates/plugintemplates/" . $this->id; } + final protected function get_template_dir() { return dirname(dirname(__FILE__)) . "/templates/src/plugintemplates/" . $this->id; } /* * Function: register_url_handler @@ -85,7 +85,7 @@ abstract class RatatoeskrPlugin register_url_handler($name, array($this, $objfunction)); } - final protected function register_settings_page($get, $validate, $set, $structure) + /*final protected function register_settings_page($get, $validate, $set, $structure)*/ /* * Functions: Functions that are called at special events diff --git a/ratatoeskr/sys/translation.php b/ratatoeskr/sys/translation.php new file mode 100644 index 0000000..01f7c6d --- /dev/null +++ b/ratatoeskr/sys/translation.php @@ -0,0 +1,55 @@ +register_tag( + "get_translation", + function($ste, $params, $sub) + { + global $translation; + if((!isset($translation)) or empty($params["for"]) or (!isset($translation[$params["for"]]))) + return ""; + return $translation[$params["for"]]; + } + ); + define(TRANSLATION_PLUGIN_LOADED, True); +} + +/* + * Function: load_language + * Load a language (i.e. set the global $translation variable). + * + * Parameters: + * $lang - The language (2-Letter code, e.g. "en", "de", "it" ...) to load. NULL for default (from database). + */ +function load_language($lang=NULL) +{ + global $ratatoeskr_settings; + if($lang === NULL) + $lang = $ratatoeskr_settings["default_language"]; + + /* + * Because we will include an file defined by the $lang param, we will + * only allow alphabetic characters, so this function should not be + * vulnerable to LFI-Exploits... + */ + $lang = implode("", array_filter(str_split($lang, 1), "ctype_alpha")); + + require(dirname(__FILE__) . "/../translations/$lang.php"); + + $GLOBALS["translation"] = $translation; +} + +?> -- cgit v1.2.3-54-g00ecf