From b7f83ef31fdd7f4194bd611aff8af31df37c9690 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Tue, 18 Jun 2013 16:38:27 +0000 Subject: [PATCH] Use a static variable to handle expansion when initializing with content set (validation) --- etemplate/inc/class.etemplate_widget.inc.php | 25 +++++++++++++++++++ .../class.etemplate_widget_template.inc.php | 6 +++++ 2 files changed, 31 insertions(+) diff --git a/etemplate/inc/class.etemplate_widget.inc.php b/etemplate/inc/class.etemplate_widget.inc.php index 8a19bb100a..e34fc8bafc 100644 --- a/etemplate/inc/class.etemplate_widget.inc.php +++ b/etemplate/inc/class.etemplate_widget.inc.php @@ -75,6 +75,17 @@ class etemplate_widget */ static protected $response; + /** + * Namespaced content array, used when trying to initialize + * + * This is pretty much a global static variable, used when reading + * a template with the content set. This allows variable expansion + * in the constructor. + * + * @protected $cont + */ + static protected $cont = null; + /** * Constructor * @@ -89,6 +100,15 @@ class etemplate_widget $this->id = $reader->getAttribute('id'); + // Update content? + if(self::$cont == null) + self::$cont = is_array(self::$request->content) ? self::$request->content : array(); + if($this->id && is_array(self::$cont[$this->id])) + { + $old_cont = self::$cont; + self::$cont = self::$cont[$this->id]; + } + // read all attributes $this->set_attrs($reader); @@ -99,6 +119,11 @@ class etemplate_widget $this->children[] = self::factory($reader->name, $reader, $reader->getAttribute('id')); } } + + // Reset content as we leave + if($old_cont) { + self::$cont = $old_cont; + } } /** diff --git a/etemplate/inc/class.etemplate_widget_template.inc.php b/etemplate/inc/class.etemplate_widget_template.inc.php index 53daeea37c..5fe3ea7133 100644 --- a/etemplate/inc/class.etemplate_widget_template.inc.php +++ b/etemplate/inc/class.etemplate_widget_template.inc.php @@ -64,6 +64,12 @@ class etemplate_widget_template extends etemplate_widget if($name == $c_sub) return $c_template; } } + // Template not found, try again with content expansion + if (is_array(self::$request->content)) + { + $expand_name = self::expand_name($name, '','','','',self::$cont); + if($expand_name && $expand_name != $name) return self::instance($expand_name, $template_set, $version, $load_via); + } error_log(__METHOD__."('$name', '$template_set', '$version', '$load_via') template NOT found!"); return false;