aboutsummaryrefslogtreecommitdiff
path: root/ratatoeskr/sys
diff options
context:
space:
mode:
Diffstat (limited to 'ratatoeskr/sys')
-rw-r--r--ratatoeskr/sys/init_ste.php46
-rw-r--r--ratatoeskr/sys/load_smarty.php30
-rw-r--r--ratatoeskr/sys/models.php4
-rw-r--r--ratatoeskr/sys/plugin_api.php12
-rw-r--r--ratatoeskr/sys/translation.php55
5 files changed, 110 insertions, 37 deletions
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 @@
+<?php
+
+/*
+ * File: ratatoeskr/sys/init_ste.php
+ *
+ * When included, the file will initialize the global STECore instance.
+ *
+ * License:
+ * This file is part of Ratatöskr.
+ * Ratatöskr is licensed unter the MIT / X11 License.
+ * See "ratatoeskr/licenses/ratatoeskr" for more information.
+ */
+
+require_once(dirname(__FILE__) . "/../libs/stupid_template_engine.php");
+
+$tpl_basedir = dirname(__FILE__) . "/../templates";
+
+if(!isset($ste))
+{
+ /*
+ * Variable: $ste
+ *
+ * The global STECore (Stupid Template Engine) instance.
+ */
+ $ste = new \ste\STECore(new \ste\FilesystemStorageAccess("$tpl_basedir/src", "$tpl_basedir/transc"));
+}
+
+$ste->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 @@
-<?php
-/*
- * File: ratatoeskr/sys/load_smarty.php
- *
- * Create the global Smarty instance.
- *
- * License:
- * This file is part of Ratatöskr.
- * Ratatöskr is licensed unter the MIT / X11 License.
- * See "ratatoeskr/licenses/ratatoeskr" for more information.
- */
-
-require_once(dirname(__FILE__) . "/../libs/smarty/Smarty.class.php");
-
-if(!isset($smarty))
-{
- /*
- * Variable: $smarty
- * Global smarty instance.
- */
- $smarty = new Smarty();
- $smarty->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 <Settings> 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 @@
+<?php
+/*
+ * File: ratatoeskr/backend/main.php
+ * Load translation.
+ *
+ * License:
+ * This file is part of Ratatöskr.
+ * Ratatöskr is licensed unter the MIT / X11 License.
+ * See "ratatoeskr/licenses/ratatoeskr" for more information.
+ */
+
+require_once(dirname(__FILE__) . "/models.php");
+require_once(dirname(__FILE__) . "/init_ste.php");
+
+if(!defined(TRANSLATION_PLUGIN_LOADED))
+{
+ $ste->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;
+}
+
+?>