aboutsummaryrefslogtreecommitdiff
path: root/services/templateservice.php
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2007-12-12 16:29:16 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2007-12-12 16:29:16 +0000
commitd582054c77b22daeb08d2bff17794b9a69a20dd4 (patch)
treed6e7cef8639da6f573cd0b21a5316abf5af24fac /services/templateservice.php
downloadsemanticscuttle-d582054c77b22daeb08d2bff17794b9a69a20dd4.tar.gz
semanticscuttle-d582054c77b22daeb08d2bff17794b9a69a20dd4.tar.bz2
import of scuttle 0.7.2
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@1 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'services/templateservice.php')
-rw-r--r--services/templateservice.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/services/templateservice.php b/services/templateservice.php
new file mode 100644
index 0000000..191ab8d
--- /dev/null
+++ b/services/templateservice.php
@@ -0,0 +1,46 @@
+<?php
+class TemplateService {
+ var $basedir;
+
+ function &getInstance() {
+ static $instance;
+ if (!isset($instance))
+ $instance =& new TemplateService();
+ return $instance;
+ }
+
+ function TemplateService() {
+ $this->basedir = $GLOBALS['TEMPLATES_DIR'];
+ }
+
+ function loadTemplate($template, $vars = NULL) {
+ if (substr($template, -4) != '.php')
+ $template .= '.php';
+ $tpl =& new Template($this->basedir .'/'. $template, $vars, $this);
+ $tpl->parse();
+ return $tpl;
+ }
+}
+
+class Template {
+ var $vars = array();
+ var $file = '';
+ var $templateservice;
+
+ function Template($file, $vars = NULL, &$templateservice) {
+ $this->vars = $vars;
+ $this->file = $file;
+ $this->templateservice = $templateservice;
+ }
+
+ function parse() {
+ if (isset($this->vars))
+ extract($this->vars);
+ include($this->file);
+ }
+
+ function includeTemplate($name) {
+ return $this->templateservice->loadTemplate($name, $this->vars);
+ }
+}
+?> \ No newline at end of file