Description//Perform substitution on the template. We don't really recurse//downward in the "sense" and "We do not do" subsitutions on inferior//templates. For each inferior template which are a part of this//template and we insert the current value of their results. Notes//Do I want to make this return a reference? function subst ($handle, $tag, $autoload = True) {$append = false; $debug = $this->debugall | | $this->debug[subst]; $this->last = $handle; if ($debug) $this->logwrite ("subst (handle= $handle, tag= $tag, autoload= $autoload)"); For compatibility with fasttemplate, the results need to overwrite//for an array. This really is useful in the case of//something like//$t->parse (Main, array (array, main)); Where The main template has a variable named main which'll be//set on the first pass (i.e., when parasing array) an D used on the//second pass (i.e., when parsing main). if (GetType ($tag) = = = Array) {foreach (array_valUEs ($tag) as $t) {if ($debug) $this->logwrite ("subst:calling subst ($handle, $t, $autoload)"), $this->subst ($handl E, $t, $autoload); } return $this->handle[$handle]; }//Period prefix means append result to pre-existing value. if (substr ($tag, 0, 1) = =.) {$append = true; $tag = substr ($tag, 1), if ($debug) $this->logwrite ("subst (handle= $handle, tag= $tag, autoload= $aut oload) in Append mode "); }//$this->template[$tag] would only be set if it is explicitly//declared via define (); i.e., inferior templates won't have a//entry. if (Isset ($this->template[$tag])) {if (!isset ($this->template[$tag][parsed]) | |! $this->template[$TAG] [ Parsed]) $this->parse_internal ($tag); } else {if (! $this->dynamic) {$this->error ("subst (handle= $handle, tag= $tag, autoload= $autoload):". No such tag and dynamic templates are turned off, true); if ($autoload) {if ($debug) $this->logwrite ("subst:template[tag= $tag] not found, trying autoload"); foreach (ARRay_keys ($this->template) as $t) {if ($debug) $this->logwrite ("Subst:calling parse_internal (tag= $t)"); if (!isse T ($this->template[$tag][parsed]) | | $this->template[$tag][parsed]) $this->parse_internal ($t); if ($debug) $this->logwrite (subst:retrying with autoload = false); $this->subst ($handle, $tag, false); if ($debug) $this->logwrite (subst:completed with autoload = false); Return } else {$this->error ("subst (handle= $handle, tag= $tag, autoload= $autoload): No such tag", True);}} if (! $append) {$this->template[$tag][result] =; if ($debug) $this->logwrite ("subst (handle= $handle, tag= $tag, AUT oload= $autoload) in overwrite mode "); if ($debug) $this->logwrite (Subst:type (this->template[$tag][part]) = GetType ($this->template[$tag] [ Part])); Hmmm, clear () called before subst () seems to result in this not//being defined which leaves me a bit confused .... $re Sult =; if (Isset ($this->template[$tag][part])) {Reset ($this->template[$tag][part]); foreach (Array_keys ($this->template[$tag][part]) as $p) {if ($debug) $this->logwrite ("Subst:looking at template[ $tag][part][$p] "); $tmp = $this->template[$tag][part][$p]; Dont Try if ($p = = parent) ... if (strcmp ($p, parent) = = 0) {if ($debug) $this->logwrite ("subst:skipping part $p "); $tmp =; } else if (GetType ($this->template[$tag][part][$p]) = = string) {if ($debug) $this->logwrite ("Subst:using part $p" ); Reset ($this->var); Because we treat VAR and HANDLE separately (unlike//class. FASTTEMPLATE.PHP3), we have to iterate over both or we//miss some substitutions and is not 100% compatible. while (list ($key, $val) = All ($this->var)) {if ($debug) $this->logwrite ("subst:substituting VAR $key = $val in $ Tag "); $key = {. $key.}; $tmp = Str_replace ($key, $val, $tmp); } reset ($this->handle); while (list ($key, $val) = each ($this->handle)) {if ($debug) $this->logwrite ("Subst:substituting HANDLE $key = $val in $tag "); $key = {. $key.}; $tmp = Str_replace ($key, $val, $tmp); } $result. = $tmp; } else {$xtag = $this->template[$tag][part][$p][tag]; if ($debug) {$this->logwrite ("subst:substituting other tag $xtag result in $tag "); }//The assignment is a no-op if the result isn't set, but when//E_all are in effect, a warning is generated without th E//Isset () test. if (Isset ($this->template[$xtag][result)) $result. = $this->template[$xtag][result]; }}} if ($this->strict) {//If Quiet-mode is turned on, skip the check since were no going//to do anything anyway. if (! $this->quiet) {if (Preg_match ($this->regex_var, $result)) {$this->error ("
unmatched tags still present in $tag
"); } } } else {$result = Preg_replace ($this->regex_var, $result),} if ($append) {if ($debug) {$this->logwrite ("subst: Appending template[$tag][result] = $result "); $this->logwrite ("Subst:old handle[$handle] = {$this->handle[$handle]}"); $this->logwrite ("Subst:old template[$tag][result] = {$this->template[$tag][result]}"); }//The Isset () tests was to suppresss warning when E_all was in effect//and the variables has not actually been set ye T (even though the//user specified Append-mode). if (Isset ($this->handle[$handle])) $this->handle[$handle]. = $result; else $this->handle[$handle] = $result; if (Isset ($this->template[$tag][result)) $this->template[$tag][result]. = $result; else $this->template[$tag][result] = $result; if ($debug) {$this->logwrite ("subst:new handle[$handle] = {$this->handle[$handle]}"); $this->logwrite (" Subst:new template[$tag][result] = {$this->template[$tag][result]} "); }} else {if ($debug)$this->logwrite ("subst:setting template[$tag][result] = $result"); $this->handle[$handle] = $result; $this->template[$tag][result] = $result; } return $this->handle[$handle]; }////Description//Clear a block from a template. The intent is to remove an inferior//template from a parent. This works even if the template have already//been parsed since we go straight to the specified template and clear/the Results element. If the given template has no yet been//loaded, the load is forced by calling Parse_internal (). function clear_dynamic ($tag = NULL) {$debug = $this->debugall | | $this->debug[clear_dynamic]; if (Is_null ($tag ) {//Clear all result elements. UHM, needs to be tested. if ($debug) $this->logwrite ("Clear_dynamic (NULL)"); foreach (Array_values ($this->template) as $t) {$this->clear_dynamic ($t);} return; } else if (GetType ($tag) = = array) {if ($debug) $this->logwrite ("Clear_dynamic ($tag)"); foreach (Array_values ($tag) As$t) {$this->clear_dynamic ($t);} return; } else if (!isset ($this->template[$tag])) {if ($debug) $this->logwrite ("Clear_dynamic ($tag)--$tag not set, Calling parse_internal "); $this->parse_internal ($tag); $this->template[$tag] = array (); } if ($debug) $this->logwrite ("Clear_dynamic ($tag)"); $this->template[$tag][loaded] = true; $this->template[$tag][string] =; $this->template[$tag][result] =; $this->template[$tag][clear] = true; }////Description//Clear The results of a handle set by Parse (). The input handle can/is a single value, an array, or the PHP constant NULL. For the//Last case, all handles cleared. function Clear ($handle = NULL) {$debug = $this->debugall | | $this->debug[clear]; if (Is_null ($handle)) {//Do NT bother unsetting them, just set the whole thing to a new,//empty array. if ($debug) $this->logwrite ("Clear (NULL)"); $this->handle = Array (); } else if (GetType ($handle) = = array) {iF ($debug) $this->logwrite ("Clear ($handle)"); foreach (Array_values ($handle) as $h) {$this->clear ($h);}} else if (isset ($this->handle[$h
http://www.bkjia.com/PHPjc/532114.html www.bkjia.com true http://www.bkjia.com/PHPjc/532114.html techarticle ///// Description///Perform substitution on the template. We don't really recurse//downward in the "sense" and "We do not do" subsitutions on inferior//templates. for each infer ...