cvs: pear /HTML_Template_Flexy Flexy.php package.xml /HTML_Template_Flexy/Flexy Test.php Token.php Tokenizer.lex Tokenizer.php
/HTML_Template_Flexy/Flexy/Token Else.php End.php EndTag.php Foreach.php If.php Include.php Method.php Tag.php Var.php
| From: | Alan Knowles | Date: | Fri, 31 Jan 2003 16:22:09 +0000 |
| Subject: | cvs: pear /HTML_Template_Flexy Flexy.php package.xml /HTML_Template_Flexy/Flexy Test.php Token.php Tokenizer.lex Tokenizer.php /HTML_Template_Flexy/Flexy/Token Else.php End.php EndTag.php Foreach.php If.php Include.php Method.php Tag.php Var.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-8611@lists.php.net to get a copy of this message | ||
alan_k Fri Jan 31 11:22:09 2003 EDT
Added files:
/pear/HTML_Template_Flexy/Flexy/Token Else.php End.php EndTag.php
Foreach.php If.php
Include.php Method.php
Tag.php Var.php
Modified files:
/pear/HTML_Template_Flexy Flexy.php package.xml
/pear/HTML_Template_Flexy/Flexy Test.php Token.php Tokenizer.lex
Tokenizer.php
Log:
Broken up Token, standardized method names - toString, factory etc. - broken up Tags into their
own methods. taken all token manipulation logic away from compile, cache management class
Index: pear/HTML_Template_Flexy/Flexy.php diff -u pear/HTML_Template_Flexy/Flexy.php:1.8 pear/HTML_Template_Flexy/Flexy.php:1.9 --- pear/HTML_Template_Flexy/Flexy.php:1.8 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy.php Fri Jan 31 11:22:06 2003 @@ -41,7 +41,7 @@ * - heavily focused on displaying objects as pages. * (so you can document your tags.) * -* @version $Id: Flexy.php,v 1.8 2003/01/30 16:58:19 alan_k Exp $ +* @version $Id: Flexy.php,v 1.9 2003/01/31 16:22:06 alan_k Exp $ */ class HTML_Template_Flexy { @@ -157,7 +157,7 @@ $_error_reporting = false; if (!$options['debug']) { - $_error_reporting = error_reporting(); + $_error_reporting = error_reporting(E_ALL ^ E_NOTICE); } include($this->compiledTemplate); if ($_error_reporting !== false) { @@ -255,76 +255,25 @@ { // read the entire file into one variable + // note this should be moved to new HTML_Template_Flexy_Token + // and that can then manage all the tokens in one place.. + require_once 'HTML/Template/Flexy/Tokenizer.php'; $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions'] = $this->options; + + + $data = file_get_contents($this->currentTemplate); //echo strlen($data); $tokenizer = new HTML_Template_Flexy_Tokenizer($data); //$tokenizer->debug=1; - $i=0; - $res = array(); - - while ($t = $tokenizer->yylex()) { - //if ($tokenizer->value === '') { - // continue; - // } + $res = HTML_Template_Flexy_Token::buildTokens($tokenizer); - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { - PEAR::raiseError('HTML_Template_Flexy::Syntax error in Template line:'. $t->line,null,PEAR_ERROR_DIE); - } - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { - continue; - } - $i++; - $res[$i] = $tokenizer->value; - $res[$i]->id = $i; - //print_r($res[$i]); - - $tokenizer->value = ''; - - } - // connect parent and child tags. - $stack = array(); - for($i=0;$i<count($res);$i++) { - if (!@$res[$i]->tag) { - continue; - } - if ($res[$i]->tag{0} == '/') { // it's a close tag.. - //echo "GOT END TAG: {$res[$i]->tag}\n"; - $tag = strtoupper(substr($res[$i]->tag,1)); - if (!isset($stack[$tag]['pos'])) { - continue; // unmatched - } - $npos = $stack[$tag]['pos']; - //echo "matching it to {$stack[$tag][$npos]}\n"; - $res[$stack[$tag][$npos]]->close = &$res[$i]; - $stack[$tag]['pos']--; - if ($stack[$tag]['pos'] < 0) { - // too many closes - just ignore it.. - $stack[$tag]['pos'] = 0; - } - continue; - } - // new entry on stack.. - $tag = strtoupper($res[$i]->tag); - - if (!isset($stack[$tag])) { - $npos = $stack[$tag]['pos'] = 0; - } else { - $npos = ++$stack[$tag]['pos']; - } - $stack[$tag][$npos] = $i; - } - - - //new Gtk_VarDump($res); - $data = ''; - foreach($res as $v) { - $data .= $v->toHTML(); - } + $data = $res->toString(); + // error checking? if( ($cfp = fopen( $this->compiledTemplate , 'w' )) ) { @@ -557,4 +506,4 @@ } -?> +?> \ No newline at end of file Index: pear/HTML_Template_Flexy/package.xml diff -u pear/HTML_Template_Flexy/package.xml:1.8 pear/HTML_Template_Flexy/package.xml:1.9 --- pear/HTML_Template_Flexy/package.xml:1.8 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/package.xml Fri Jan 31 11:22:06 2003 @@ -52,6 +52,17 @@ <file>example.ini</file> <file>Tokenizer.php</file> <file>Token.php</file> + <dir name="Token" role="php"> + <file>Tag.php</file> + <file>EndTag.php</file> + <file>If.php</file> + <file>Else.php</file> + <file>End.php</file> + <file>Foreach.php</file> + <file>Include.php</file> + <file>Var.php</file> + <file>Method.php</file> + </dir> <file>Test.php</file> <dir name="Filter" role="php"> <file>BodyOnly.php</file> Index: pear/HTML_Template_Flexy/Flexy/Test.php diff -u pear/HTML_Template_Flexy/Flexy/Test.php:1.2 pear/HTML_Template_Flexy/Flexy/Test.php:1.3 --- pear/HTML_Template_Flexy/Flexy/Test.php:1.2 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Test.php Fri Jan 31 11:22:06 2003 @@ -17,7 +17,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Test.php,v 1.2 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Test.php,v 1.3 2003/01/31 16:22:06 alan_k Exp $ // // This is a temporary file - it includes some of the // Code that will have to go in the Engine eventually.. @@ -82,67 +82,12 @@ //echo strlen($data); $tokenizer = new HTML_Template_Flexy_Tokenizer($data); $tokenizer->debug=1; - $i=0; - $l = -1; - $tokenizer->value = ''; - $res = array(); - while ($t = $tokenizer->yylex()) { - //if ($tokenizer->value === '') { - // continue; - // } - - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { - $this->error(0,'GOT ERROR'); - } - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { - continue; - } - - $i++; - $res[$i] = $tokenizer->value; - $res[$i]->id = $i; - //print_r($res[$i]); - - $tokenizer->value = ''; - - } - $stack = array(); - for($i=0;$i<count($res);$i++) { - if (!@$res[$i]->tag) { - continue; - } - if ($res[$i]->tag{0} == '/') { // it's a close tag.. - //echo "GOT END TAG: {$res[$i]->tag}\n"; - $tag = strtoupper(substr($res[$i]->tag,1)); - if (!isset($stack[$tag]['pos'])) { - continue; // unmatched - } - $npos = $stack[$tag]['pos']; - //echo "matching it to {$stack[$tag][$npos]}\n"; - $res[$stack[$tag][$npos]]->close = &$res[$i]; - $stack[$tag]['pos']--; - if ($stack[$tag]['pos'] < 0) { - // too many closes - just ignore it.. - $stack[$tag]['pos'] = 0; - } - continue; - } - // new entry on stack.. - $tag = strtoupper($res[$i]->tag); - - if (!isset($stack[$tag])) { - $npos = $stack[$tag]['pos'] = 0; - } else { - $npos = ++$stack[$tag]['pos']; - } - $stack[$tag][$npos] = $i; - } - + $res = HTML_Template_Flexy_Token::buildTokens($tokenizer); + new Gtk_VarDump($res); - foreach($res as $v) { - echo $v->toHTML(); - } + echo $res->toString(); + } Index: pear/HTML_Template_Flexy/Flexy/Token.php diff -u pear/HTML_Template_Flexy/Flexy/Token.php:1.3 pear/HTML_Template_Flexy/Flexy/Token.php:1.4 --- pear/HTML_Template_Flexy/Flexy/Token.php:1.3 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Token.php Fri Jan 31 11:22:06 2003 @@ -16,7 +16,7 @@ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // -// $Id: Token.php,v 1.3 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Token.php,v 1.4 2003/01/31 16:22:06 alan_k Exp $ // // This is the master Token file for The New Token driver Engine. // All the Token output, and building routines are in here. @@ -27,11 +27,12 @@ $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state'] = 0; $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'] = array(); - +$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['activeForm'] = ''; +$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['tokens'] = array(); /** * Base Class for all Tokens. * -* @abstract Provides the static Create Method, and default toHTML() methods +* @abstract Provides the static Create Method, and default toString() methods * */ @@ -51,10 +52,18 @@ * @access public */ var $value; + /** + * the line the token is from + * + * @var int + * @access public + */ + + var $line; /** - * Create a Token + * factory a Token * * Standard factory method.. - with object vars. * ?? rename me to factory? @@ -67,8 +76,17 @@ * @access public */ - function create($token,$value,$line) { + function factory($token,$value,$line) { + // try not to reload the same class to often + static $loaded = array(); + + if (!isset($loaded[$token])) { + @include 'HTML/Template/Flexy/Token/'.$token.'.php'; + $loaded[$token] = true; + } + $c = 'HTML_Template_Flexy_Token_'.$token; + $t = new HTML_Template_Flexy_Token; if (class_exists($c)) { $t = new $c; @@ -100,13 +118,211 @@ * @access public */ - function toHTML() { + function toString() { if (is_array($this->value)) { var_dump($this); exit; } - return $this->value; + $ret = $this->value; + $ret .= $this->childrentoString(); + if ($this->close) { + $ret .= $this->close->toString(); + } + + return $ret; + } + + /** + * generate HTML from children after doing flexy manipulations.. + * + * @return string HTML + * @access public + */ + function childrentoString() { + if (!$this->children) { + return ''; + } + if ($this->ignoreChildren) { + return; + } + $ret = ''; + //echo "output $this->id"; + //new Gtk_VarDump($this); + foreach ($this->children as $child) { + if (!$child) { + continue; + } + $ret .= $child->toString(); + } + return $ret; + } + + + + /* ======================================================= */ + /* Token Managmenet = parse and store all the tokens in + * an associative array and tree. + */ + + /** + * Run a Tokenizer and Store its results + * It should build a DOM Tree of the HTML + * + * @param object Tokenizer to run.. - Theoretically other Tokenizers could be done for email,rtf etc. + * + * @access public + * @return base token (really a dummy token, which contains the tree) + * @static + */ + + function buildTokens($tokenizer) + { + + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + // first record is a filler - to stick all the children on ! + // reset my globals.. + + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = array(new HTML_Template_Flexy_Token); + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->id =0; + $i=1; + + + // step one just tokenize it. + while ($t = $tokenizer->yylex()) { + + if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { + PEAR::raiseError('HTML_Template_Flexy::Syntax error in Template line:'. $t->line, + null,PEAR_ERROR_DIE); + } + if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { + continue; + } + + $i++; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = $tokenizer->value; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $i; + //print_r($res[$i]); + + } + $res = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens']; + // connect parent and child tags. + $stack = array(); + $total = $i +1; + for($i=1;$i<$total;$i++) { + //echo "Checking TAG $i\n"; + if (!@$res[$i]->tag) { + continue; + } + if ($res[$i]->tag{0} == '/') { // it's a close tag.. + //echo "GOT END TAG: {$res[$i]->tag}\n"; + $tag = strtoupper(substr($res[$i]->tag,1)); + if (!isset($stack[$tag]['pos'])) { + continue; // unmatched + } + $npos = $stack[$tag]['pos']; + //echo "matching it to {$stack[$tag][$npos]}\n"; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$stack[$tag][$npos]]->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]; + $stack[$tag]['pos']--; + if ($stack[$tag]['pos'] < 0) { + // too many closes - just ignore it.. + $stack[$tag]['pos'] = 0; + } + continue; + } + // new entry on stack.. + $tag = strtoupper($res[$i]->tag); + + if (!isset($stack[$tag])) { + $npos = $stack[$tag]['pos'] = 0; + } else { + $npos = ++$stack[$tag]['pos']; + } + $stack[$tag][$npos] = $i; + } + + // create a dummy close for the end + $i = $total; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = new HTML_Template_Flexy_Token; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $total; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$total]; + + // now is it possible to connect children... + // now we need to GLOBALIZE!! - + + + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = $res; + + HTML_Template_Flexy_Token::buildChildren(0); + //new Gtk_VarDump($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]); + + return $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]; + } + /** + * Matching closing tag for a Token + * + * @var object|none optional closing tag + * @access public + */ + + + var $close; + + /** + * array of children to each object. + * + * @var array + * @access public|private + */ + + + var $children = array(); + + /** + * Build the child array for each element. + * + * @param object Tokenizer to run.. - Theoretically other Tokenizers could be done for email,rtf etc. + * + * @access public + * @static + */ + function buildChildren($id) + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + $base = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$id]; + $base->children = array(); + $start = $base->id +1; + $end = $base->close->id; + for ($i=$start; $i<$end; $i++) { + $base->children[] = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]; + if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close)) { + + // if the close id is greater than my id - ignore it! - + if ($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close->id > $end) { + continue; + } + HTML_Template_Flexy_Token::buildChildren($i); + $i = $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close->id; + } + } } + + + + /** + * Flag to ignore children - Used to block output for select/text area etc. + * + * @var boolean ingore children + * @access public + */ + + + var $ignoreChildren = false; + + + + /* ======================================================== */ /* variable STATE management * @@ -120,7 +336,7 @@ * @access public */ function reset() { - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state'] = 0; + $_HTML_TEMPLATE_FLEXY_TOKEN['state'] = 0; } /** @@ -128,11 +344,14 @@ * * @access public */ - function pushState() { - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']++; - $s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; + function pushState() + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + $_HTML_TEMPLATE_FLEXY_TOKEN['state']++; + $s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s] = array(); // initialize statevars + $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s] = array(); // initialize statevars } /** * tell the generator you are entering a block @@ -140,10 +359,13 @@ * @return boolean parse error - out of bounds * @access public */ - function pullState() { - $s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s] = array(); // initialize statevars - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']--; + function pullState() + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + $s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; + $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s] = array(); // initialize statevars + $_HTML_TEMPLATE_FLEXY_TOKEN['state']--; if ($s<0) { return false; } @@ -177,12 +399,15 @@ * @access public */ - function findVar($string) { + function findVar($string) + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + if ($string == 't') { return '$t'; } - for ($s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; $s > 0; $s--) { - if (in_array($string, $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s])) { + for ($s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; $s > 0; $s--) { + if (in_array($string, $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s])) { return '$'.$string; } } @@ -195,573 +420,15 @@ * @access public */ - function pushVar($string) { - $s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s][] = $string; + function pushVar($string) + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + $s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; + $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s][] = $string; } } - -/** -* A standard HTML Tag = eg. Table/Body etc. -* -* @abstract -* This is the generic HTML tag -* a simple one will have some attributes and a name. -* -*/ -class HTML_Template_Flexy_Token_Tag extends HTML_Template_Flexy_Token { - - /** - * HTML Tag: eg. Body or /Body - * - * @var string - * @access public - */ - var $tag = ''; - /** - * Associative array of attributes. - * - * key is the left, value is the right.. - * note: - * values are raw (eg. include "") - * valuse can be - * text = standard - * array (a parsed value with flexy tags in) - * object (normally some PHP code that generates the key as well..) - * - * - * @var array - * @access public - */ - - var $attributes = array(); - /** - * postfix tokens - * used to add code to end of tags - * - * @var array - * @access public - */ - var $postfix = ''; - /** - * prefix tokens - * used to add code to beginning of tags TODO - * - * @var array - * @access public - */ - var $prefix = ''; - - - /** - * Alias to closing tag (built externally). - * used to add < ? } ? > code to dynamic tags. - * @var object alias - * @access public - */ - var $close; // alias to closing tag. - - - - /** - * Setvalue - gets name, attribute as an array - * @see parent::setValue() - */ - - function setValue($value) { - - $this->tag = $value[0]; - $this->UCtag = strtoupper($value[0]); - if (isset($value[1])) { - $this->attributes = $value[1]; - } - if (in_array($this->UCtag,array("INPUT","TEXTAREA"))) { - $this->toFormElement(); - } - } - /** - * toHTML - display tag, attributes, postfix and any code in attributes. - * @see parent::toHTML() - */ - function toHTML() { - $ret = ''; - if ($foreach = $this->getAttribute('foreach')) { - $foreachObj = $this->create('Foreach', - explode(',',$foreach), - $this->line); - $ret = $foreachObj->toHTML(); - // does it have a closetag? - - $this->close->postfix = array($this->create("End", - '', - $this->line)); - - } - - $ret .= "<". $this->tag; - foreach ($this->attributes as $k=>$v) { - if ($v === null) { - $ret .= " $k"; - continue; - } - if (is_string($v)) { - $ret .= " {$k}={$v}"; - continue; - } - if (is_object($v)) { - $ret .= " " .$v->toHTML(); - continue; - } - - - $ret .= " {$k}="; - foreach($v as $item) { - if (is_string($item)) { - $ret .= $item; - continue; - } - $ret .= $item->toHTML(); - } - } - $ret .= ">"; - if ($this->postfix) { - foreach ($this->postfix as $e) { - $ret .= $e->toHTML(); - } - } - return $ret; - } - - /** - * toFormElement = takes an input field and generates related PHP code. - * - * Eg. filling in the value with $this->{fieldname}, adding in - * echo $this->errors['fieldname'] at the end. - * TODO : formating using DIV tags, and support for 'required tag' - * - * @return none - * @access public - */ - - function toFormElement() { - // form elements : format: - //value - fill out as PHP CODE - $name = $this->getAttribute('name'); - $type = strtoupper($this->getAttribute('type')); - $thisvar = str_replace(']','',$name); - $thisvar = str_replace('[','.',$thisvar); - - switch ($type) { - case "CHECKBOX": - $this->attributes['checked'] = - $this->create("PHP", - "<?php if (". $this->toVar($thisvar).") { ?>CHECKED<?php } ?>", - $this->line); - break; - - case "SUBMIT": - return; - - default: - $this->attributes['value'] = array( - "\"", - $this->create("Var",$thisvar.":u",$this->line), - "\""); - break; - - } - if ($type == "HIDDEN") { - return; - } - - $this->postfix = array( - $this->create("PHP", "<?php if (isset(\$this->errors['".urlencode($thisvar)."'])) { ". - "echo htmlspecialchars(\$this->errors['".urlencode($thisvar). "']); } ?>",$this->line)); - // this should use <div name="form.error"> or something... - - - } - /** - * getAttribute = reads an attribute value and strips the quotes - * - * TODO : sort out case issues... - * does not handle valuse with flexytags in - * - * @return none - * @access string - */ - function getAttribute($key) { - // really need to do a foreach/ strtoupper - if (!isset($this->attributes[$key])) { - return ''; - } - $v = $this->attributes[$key]; - switch($v{0}) { - case "\"": - case "'": - return substr($v,1,-1); - default: - return $v; - } - } - - - -} - - -/** -* The closing HTML Tag = eg. /Table or /Body etc. -* -* @abstract -* This just extends the generic HTML tag -* -*/ - -class HTML_Template_Flexy_Token_EndTag extends HTML_Template_Flexy_Token_Tag { } - - -/** -* Class to handle If statements -* -* -*/ -class HTML_Template_Flexy_Token_If extends HTML_Template_Flexy_Token{ - /** - * Condition for the if statement. - * @var string // a variable - * @access public - */ - - var $condition; - /** - * Setvalue - a string - * @see parent::setValue() - */ - function setValue($value) { - //var_dump($value); - $this->condition=$value; - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->toVar() - */ - function toHTML() { - $ret = "<?php if(@".$this->toVar($this->condition) .") { ?>"; - $this->pushState(); - return $ret; - - } - -} - - -/** -* Class to handle Else -* -* -*/ -class HTML_Template_Flexy_Token_Else extends HTML_Template_Flexy_Token { - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - // pushpull states to make sure we are in an area.. - should really check to see - // if the state it is pulling is a if... - if ($this->pullState() === false) { - echo "Unmatched End on Line {$this->line}"; - return false; - } - $this->pushState(); - return "<?php } else {?>"; - } - - -} - - - -/** -* Class to handle End statements (eg. close brakets) -* -* -*/ -class HTML_Template_Flexy_Token_End extends HTML_Template_Flexy_Token { - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - // pushpull states to make sure we are in an area.. - should really check to see - // if the state it is pulling is a if... - if ($this->pullState() === false) { - echo "Unmatched End on Line {$this->line}"; - return false; - } - - return "<?php } ?>"; - } - -} - - - -/** -* Class to handle foreach statements -* -* -*/ -class HTML_Template_Flexy_Token_Foreach extends HTML_Template_Flexy_Token { - - /** - * variable to loop on. - * - * @var string - * @access public - */ - var $loopOn = ''; - /** - * key value - * - * @var string - * @access public - */ - var $key = ''; - /** - * optional value (in key=>value pair) - * - * @var string - * @access public - */ - var $value = ''; - - /** - * Setvalue - a array of all three (last one optional) - * @see parent::setValue() - */ - - function setValue($value) { - $this->loopOn=$value[0]; - $this->key=$value[1]; - $this->value=@$value[2]; - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - $ret = "<?php if (is_array(". - $this->toVar($this->loopOn) . ")) " . - "foreach(".$this->toVar($this->loopOn). " "; - $ret .= "as \${$this->key}"; - if ($this->value) { - $ret .= " => \${$this->value}"; - } - $ret .= ") { ?>"; - - $this->pushState(); - $this->pushVar($this->key); - $this->pushVar($this->value); - return $ret; - } - -} - -/** -* Class to handle include statements -* TODO!!! -* -* Include is an odd baby.. - since we are supposed to be dealing with compiled templates.. -* It is the responsibility of the appliacation to make sure it has compiled the -* included template. -* Various types of Includes should be supported -* include:someobject.someval -* - maps to if (isset(....) && file_exists(....)) include ( value . '.{lang}.html') -* -* include: somevar -* -* -* -*/ -class HTML_Template_Flexy_Token_Include extends HTML_Template_Flexy_Token{ - - - - function toHTML() { - $v = $this->toVar($this->value); - - $options = $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']; - - $ret = "<?php if (isset($v) && - file_exists(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\")) - include(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\"); ?>"; - - return $ret; - - } - - - - -} - -/** -* Class to handle variable output -* * -* -*/ - -class HTML_Template_Flexy_Token_Var extends HTML_Template_Flexy_Token { - - /** - * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) - * - * @var char - * @access public - */ - var $modifier; - /** - * Setvalue - at present raw text.. - needs sorting out.. - * @see parent::setValue() - */ - function setValue($value) { - // comes in as raw {xxxx}, {xxxx:h} or {xxx.yyyy:h} - - if (strpos($value,":")) { - list($value,$this->modifier) = explode(':',$value); - } - $this->value = $value; - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - // ignore modifier at present!! - return "<?php echo htmlspecialchars(" . $this->toVar($this->value) . "); ?>"; - } - -} -/** -* Class to handle method calls -* * -* -*/ - -class HTML_Template_Flexy_Token_Method extends HTML_Template_Flexy_Token { - /** - * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) - * TODO - * @var char - * @access public - */ - var $modifier; - /** - * Method name - * - * @var char - * @access public - */ - var $method; - /** - * is it in if statement with a method? - * - * @var boolean - * @access public - */ - var $isConditional; - /** - * arguments, either variables or literals eg. #xxxxx yyyy# - * - * @var array - * @access public - */ - var $args= array(); - /** - * setvalue - at present array method, args (need to add modifier) - * @see parent::setValue() - */ - - function setValue($value) { - //var_dump($value); - $method = $value[0]; - if (substr($value[0],0,3) == 'if:') { - $this->isConditional = true; - $method = substr($value[0],3); - } - - if (strpos($method,":")) { - list($method,$this->modifier) = explode(':',$method); - } - $this->method = $method; - - $this->args = $value[1]; - // modifier TODO! - - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - - function toHTML() { - // ignore modifier at present!! - $prefix = 'echo '; - $suffix = ''; - switch ($this->modifier) { - case 'h': - break; - case 'u': - $prefix = 'echo urlencode('; - $suffix = ')'; - default: - $prefix = 'echo htmlspecialchars('; - // add language ? - $suffix = ')'; - } - - - - if ($this->isConditional) { - $prefix = 'if ('; - $this->pushState(); - $suffix = ')'; - } - // should really check the variable part of method ... - - $ret = '<?php ' . $prefix; - $ret .= $this->toVar($this->method) . "("; - $s =0; - - foreach($this->args as $a) { - - if ($s) { - $ret .= ","; - } - $ret .= $this->toVar($a); - $s =1; - } - $ret .= ")" . $suffix; - - if ($this->isConditional) { - $ret .= ' { '; - } else { - $ret .= ";"; - } - $ret .= ' ?>'; - - return $ret; - - - - } - -} - - ?> Index: pear/HTML_Template_Flexy/Flexy/Tokenizer.lex diff -u pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.3 pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.4 --- pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.3 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Tokenizer.lex Fri Jan 31 11:22:06 2003 @@ -16,7 +16,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Tokenizer.lex,v 1.3 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Tokenizer.lex,v 1.4 2003/01/31 16:22:06 alan_k Exp $ // // The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php) // You should always work with the .lex file and generate by @@ -186,21 +186,21 @@ <YYINITIAL>{CRO}{NUMBER}{REFERENCE_END}? { // { - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>{CRO}{NAME}{REFERENCE_END}? { // &#abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>{ERO}{NAME}{REFERENCE_END}? { // &abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -231,7 +231,7 @@ <YYINITIAL>{MDO}{NAME}{WHITESPACE} { /* <!DOCTYPE -- markup declaration */ - $this->value = HTML_Template_Flexy_Token::create('Doctype',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Doctype',$this->yytext(),$this->yyline); $this->yybegin(IN_MD); return HTML_TEMPLATE_FLEXY_TOKEN_OK; @@ -249,7 +249,7 @@ <YYINITIAL>{MDO}{COM} { /* <!-- -- comment declaration */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -273,7 +273,7 @@ /* <? ...> -- processing instruction */ // this is a little odd cause technically we dont allow it!! // really we only want to handle < ? xml - $this->value = HTML_Template_Flexy_Token::create('PHP',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('PHP',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -301,7 +301,7 @@ <YYINITIAL>([^\<\&\{]|(<[^<&a-zA-Z!->?])|(&[^<&#a-zA-Z]))+|"{" { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -440,7 +440,7 @@ // <a name=foo ^>,</foo^> -- tag close */ <IN_ATTR,IN_TAG>{TAGC} { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); @@ -464,7 +464,7 @@ <IN_ATTR>{NET}{WHITESPACE}{TAGC} { $this->attributes["/"] = null; - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); @@ -506,7 +506,7 @@ // end tag -- non-permissive */ <IN_ENDTAG>{TAGC} { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName), $this->yyline); array($this->tagName); @@ -526,7 +526,7 @@ <IN_COM>([^-]|-[^-])*{WHITESPACE} { // <!^--...--> -- comment */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -534,48 +534,48 @@ <IN_MD>{PERO}{NAME}{REFERENCE_END}?{WHITESPACE} { // <!doctype ^%foo;> -- parameter entity reference */ - $this->value = HTML_Template_Flexy_Token::create('EntityRef',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityRef',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{PERO}{SPACES} { // <!entity ^% foo system "..." ...> -- parameter entity definition */ - $this->value = HTML_Template_Flexy_Token::create('EntityPar',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityPar',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NUMBER}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('Number',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Number',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NAME}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('Name',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Name',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NUMBER_TOKEN}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('NumberT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NumberT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NAME_TOKEN}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('NameT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NameT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{LITERAL}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('Literal',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Literal',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_COM>{COM}{TAGC} { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{TAGC} { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -585,7 +585,7 @@ <IN_MD>{DSO} { // <!doctype foo ^[ -- declaration subset */ - $this->value = HTML_Template_Flexy_Token::create('BeginDS',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('BeginDS',$this->yytext(),$this->yyline); $this->yybegin(IN_DS); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -600,20 +600,20 @@ <IN_DS>{MSC}{TAGC} { // ]]> -- marked section end */ - $this->value = HTML_Template_Flexy_Token::create('DSEnd',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEnd',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_DS>{DSC} { // ] -- declaration subset close */ - $this->value = HTML_Template_Flexy_Token::create('DSEndSubset',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEndSubset',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_DS>[^\]]+ { - $this->value = HTML_Template_Flexy_Token::create('Declaration',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Declaration',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -622,7 +622,7 @@ <YYINITIAL>"{if:"{FLEXY_VAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('If',substr($this->yytext(),4,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('If',substr($this->yytext(),4,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -641,36 +641,36 @@ <YYINITIAL>"{foreach:"{FLEXY_VAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{foreach:"{FLEXY_VAR}","{FLEXY_SIMPLEVAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{foreach:"{FLEXY_VAR}","{FLEXY_SIMPLEVAR}","{FLEXY_SIMPLEVAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{end:}" { - $this->value = HTML_Template_Flexy_Token::create('End', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('End', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{else:}" { - $this->value = HTML_Template_Flexy_Token::create('Else', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Else', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{include:"{FLEXY_VAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } // needs to deal with \# - excaped #'s <YYINITIAL>"{include:#"{FLEXY_LITERAL}"#}" { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -686,11 +686,15 @@ $n = $this->yytext(); if ($n{0} != '{') { $n = substr($n,3); + } else { + $n = substr($n,1); } if ($n{strlen($n)-1} != '}') { $n = substr($n,0,-3); + } else { + $n = substr($n,0,-1); } - $this->attrVal[] = HTML_Template_Flexy_Token::create('Var' , $n, $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Var' , $n, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -699,7 +703,7 @@ $t = $this->yytext(); $t = substr($t,1,-1); - $this->value = HTML_Template_Flexy_Token::create('Var' , $t, $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Var' , $t, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -726,7 +730,7 @@ $this->flexyMethod .= substr($t,1,-1); } - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -750,7 +754,7 @@ } $this->flexyArgs[] = $t; - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -763,7 +767,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -801,7 +805,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-2); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -814,7 +818,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } Index: pear/HTML_Template_Flexy/Flexy/Tokenizer.php diff -u pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.3 pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.4 --- pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.3 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Tokenizer.php Fri Jan 31 11:22:06 2003 @@ -16,7 +16,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Tokenizer.php,v 1.3 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Tokenizer.php,v 1.4 2003/01/31 16:22:06 alan_k Exp $ // // The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php) // You should always work with the .lex file and generate by @@ -1518,13 +1518,13 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 4: { // &abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 5: @@ -1546,13 +1546,13 @@ case 7: { // { - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 8: { // &#abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 9: @@ -1573,7 +1573,7 @@ case 11: { /* <!DOCTYPE -- markup declaration */ - $this->value = HTML_Template_Flexy_Token::create('Doctype',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Doctype',$this->yytext(),$this->yyline); $this->yybegin(IN_MD); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1594,7 +1594,7 @@ /* <? ...> -- processing instruction */ // this is a little odd cause technically we dont allow it!! // really we only want to handle < ? xml - $this->value = HTML_Template_Flexy_Token::create('PHP',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('PHP',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 15: @@ -1607,7 +1607,7 @@ { $t = $this->yytext(); $t = substr($t,1,-1); - $this->value = HTML_Template_Flexy_Token::create('Var' , $t, $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Var' , $t, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 17: @@ -1627,13 +1627,13 @@ case 19: { /* <!-- -- comment declaration */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 20: { - $this->value = HTML_Template_Flexy_Token::create('If',substr($this->yytext(),4,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('If',substr($this->yytext(),4,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 21: @@ -1646,37 +1646,37 @@ } case 22: { - $this->value = HTML_Template_Flexy_Token::create('End', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('End', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 23: { - $this->value = HTML_Template_Flexy_Token::create('Else', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Else', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 24: { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 25: { - $this->value = HTML_Template_Flexy_Token::create('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 26: { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 27: { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 28: { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 29: @@ -1719,7 +1719,7 @@ } case 34: { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); $this->yybegin(YYINITIAL); @@ -1750,7 +1750,7 @@ case 38: { $this->attributes["/"] = null; - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); $this->yybegin(YYINITIAL); @@ -1810,7 +1810,7 @@ } case 47: { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName), $this->yyline); array($this->tagName); @@ -1845,11 +1845,15 @@ $n = $this->yytext(); if ($n{0} != '{') { $n = substr($n,3); + } else { + $n = substr($n,1); } if ($n{strlen($n)-1} != '}') { $n = substr($n,0,-3); + } else { + $n = substr($n,0,-1); } - $this->attrVal[] = HTML_Template_Flexy_Token::create('Var' , $n, $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Var' , $n, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } case 51: @@ -1872,82 +1876,82 @@ } case 53: { - $this->value = HTML_Template_Flexy_Token::create('Number',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Number',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 54: { - $this->value = HTML_Template_Flexy_Token::create('Name',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Name',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 55: { - $this->value = HTML_Template_Flexy_Token::create('NameT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NameT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 56: { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 57: { // <!doctype foo ^[ -- declaration subset */ - $this->value = HTML_Template_Flexy_Token::create('BeginDS',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('BeginDS',$this->yytext(),$this->yyline); $this->yybegin(IN_DS); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 58: { - $this->value = HTML_Template_Flexy_Token::create('NumberT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NumberT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 59: { - $this->value = HTML_Template_Flexy_Token::create('Literal',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Literal',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 60: { // <!entity ^% foo system "..." ...> -- parameter entity definition */ - $this->value = HTML_Template_Flexy_Token::create('EntityPar',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityPar',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 61: { // <!doctype ^%foo;> -- parameter entity reference */ - $this->value = HTML_Template_Flexy_Token::create('EntityRef',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityRef',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 62: { // <!^--...--> -- comment */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 63: { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 64: { - $this->value = HTML_Template_Flexy_Token::create('Declaration',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Declaration',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 65: { // ] -- declaration subset close */ - $this->value = HTML_Template_Flexy_Token::create('DSEndSubset',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEndSubset',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 66: { // ]]> -- marked section end */ - $this->value = HTML_Template_Flexy_Token::create('DSEnd',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEnd',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1971,7 +1975,7 @@ $t = substr($t,0,-2); } $this->flexyArgs[] = $t; - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1981,7 +1985,7 @@ if ($t{1} == ':') { $this->flexyMethod .= substr($t,1,-1); } - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1994,7 +1998,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -2007,7 +2011,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-2); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -2020,7 +2024,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -2033,13 +2037,13 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 76: { // &abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 77: @@ -2055,13 +2059,13 @@ case 78: { // { - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 79: { // &#abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 80: @@ -2076,7 +2080,7 @@ case 81: { /* <!DOCTYPE -- markup declaration */ - $this->value = HTML_Template_Flexy_Token::create('Doctype',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Doctype',$this->yytext(),$this->yyline); $this->yybegin(IN_MD); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -2128,39 +2132,39 @@ } case 89: { - $this->value = HTML_Template_Flexy_Token::create('Number',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Number',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 90: { - $this->value = HTML_Template_Flexy_Token::create('Name',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Name',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 91: { - $this->value = HTML_Template_Flexy_Token::create('NameT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NameT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 92: { - $this->value = HTML_Template_Flexy_Token::create('NumberT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NumberT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 93: { - $this->value = HTML_Template_Flexy_Token::create('Literal',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Literal',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 94: { // <!doctype ^%foo;> -- parameter entity reference */ - $this->value = HTML_Template_Flexy_Token::create('EntityRef',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityRef',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 95: { // <!^--...--> -- comment */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 96: @@ -2172,7 +2176,7 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 99: @@ -2223,7 +2227,7 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 175: Index: pear/HTML_Template_Flexy/Flexy/Token/Else.php +++ pear/HTML_Template_Flexy/Flexy/Token/Else.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Else.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle Else * * */ class HTML_Template_Flexy_Token_Else extends HTML_Template_Flexy_Token { /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // pushpull states to make sure we are in an area.. - should really check to see // if the state it is pulling is a if... if ($this->pullState() === false) { echo "Unmatched End on Line {$this->line}"; return false; } $this->pushState(); return "<?php } else {?>"; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/End.php +++ pear/HTML_Template_Flexy/Flexy/Token/End.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: End.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle End statements (eg. close brakets) * * */ class HTML_Template_Flexy_Token_End extends HTML_Template_Flexy_Token { /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // pushpull states to make sure we are in an area.. - should really check to see // if the state it is pulling is a if... if ($this->pullState() === false) { echo "Unmatched End on Line {$this->line}"; return false; } return "<?php } ?>"; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/EndTag.php +++ pear/HTML_Template_Flexy/Flexy/Token/EndTag.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: EndTag.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * The closing HTML Tag = eg. /Table or /Body etc. * * @abstract * This just extends the generic HTML tag * */ class HTML_Template_Flexy_Token_EndTag extends HTML_Template_Flexy_Token_Tag { } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Foreach.php +++ pear/HTML_Template_Flexy/Flexy/Token/Foreach.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Foreach.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle foreach statements * * */ class HTML_Template_Flexy_Token_Foreach extends HTML_Template_Flexy_Token { /** * variable to loop on. * * @var string * @access public */ var $loopOn = ''; /** * key value * * @var string * @access public */ var $key = ''; /** * optional value (in key=>value pair) * * @var string * @access public */ var $value = ''; /** * Setvalue - a array of all three (last one optional) * @see parent::setValue() */ function setValue($value) { $this->loopOn=$value[0]; $this->key=$value[1]; $this->value=@$value[2]; } /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { $ret = "<?php if (is_array(". $this->toVar($this->loopOn) . ")) " . "foreach(".$this->toVar($this->loopOn). " "; $ret .= "as \${$this->key}"; if ($this->value) { $ret .= " => \${$this->value}"; } $ret .= ") { ?>"; $this->pushState(); $this->pushVar($this->key); $this->pushVar($this->value); return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/If.php +++ pear/HTML_Template_Flexy/Flexy/Token/If.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: If.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle If statements * * */ class HTML_Template_Flexy_Token_If extends HTML_Template_Flexy_Token{ /** * Condition for the if statement. * @var string // a variable * @access public */ var $condition; /** * Setvalue - a string * @see parent::setValue() */ function setValue($value) { //var_dump($value); $this->condition=$value; } /** * toString - generate PHP code * @see parent::toString(), $this->toVar() */ function toString() { $ret = "<?php if(@".$this->toVar($this->condition) .") { ?>"; $this->pushState(); return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Include.php +++ pear/HTML_Template_Flexy/Flexy/Token/Include.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Include.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle include statements * TODO!!! * * Include is an odd baby.. - since we are supposed to be dealing with compiled templates.. * It is the responsibility of the appliacation to make sure it has compiled the * included template. * Various types of Includes should be supported * include:someobject.someval * - maps to if (isset(....) && file_exists(....)) include ( value . '.{lang}.html') * * include: somevar * * * */ class HTML_Template_Flexy_Token_Include extends HTML_Template_Flexy_Token{ function toString() { $v = $this->toVar($this->value); $options = $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']; $ret = "<?php if (isset($v) && file_exists(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\")) include(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\"); ?>"; return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Method.php +++ pear/HTML_Template_Flexy/Flexy/Token/Method.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Method.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle method calls * * * */ class HTML_Template_Flexy_Token_Method extends HTML_Template_Flexy_Token { /** * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) * TODO * @var char * @access public */ var $modifier; /** * Method name * * @var char * @access public */ var $method; /** * is it in if statement with a method? * * @var boolean * @access public */ var $isConditional; /** * arguments, either variables or literals eg. #xxxxx yyyy# * * @var array * @access public */ var $args= array(); /** * setvalue - at present array method, args (need to add modifier) * @see parent::setValue() */ function setValue($value) { //var_dump($value); $method = $value[0]; if (substr($value[0],0,3) == 'if:') { $this->isConditional = true; $method = substr($value[0],3); } if (strpos($method,":")) { list($method,$this->modifier) = explode(':',$method); } $this->method = $method; $this->args = $value[1]; // modifier TODO! } /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // ignore modifier at present!! $prefix = 'echo '; $suffix = ''; switch ($this->modifier) { case 'h': break; case 'u': $prefix = 'echo urlencode('; $suffix = ')'; default: $prefix = 'echo htmlspecialchars('; // add language ? $suffix = ')'; } if ($this->isConditional) { $prefix = 'if ('; $this->pushState(); $suffix = ')'; } // should really check the variable part of method ... $ret = '<?php ' . $prefix; $ret .= $this->toVar($this->method) . "("; $s =0; foreach($this->args as $a) { if ($s) { $ret .= ","; } $ret .= $this->toVar($a); $s =1; } $ret .= ")" . $suffix; if ($this->isConditional) { $ret .= ' { '; } else { $ret .= ";"; } $ret .= ' ?>'; return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Tag.php +++ pear/HTML_Template_Flexy/Flexy/Token/Tag.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Tag.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ /** * A standard HTML Tag = eg. Table/Body etc. * * @abstract * This is the generic HTML tag * a simple one will have some attributes and a name. * */ class HTML_Template_Flexy_Token_Tag extends HTML_Template_Flexy_Token { /** * HTML Tag: eg. Body or /Body * * @var string * @access public */ var $tag = ''; /** * Associative array of attributes. * * key is the left, value is the right.. * note: * values are raw (eg. include "") * valuse can be * text = standard * array (a parsed value with flexy tags in) * object (normally some PHP code that generates the key as well..) * * * @var array * @access public */ var $attributes = array(); /** * postfix tokens * used to add code to end of tags * * @var array * @access public */ var $postfix = ''; /** * prefix tokens * used to add code to beginning of tags TODO * * @var array * @access public */ var $prefix = ''; /** * Alias to closing tag (built externally). * used to add < ? } ? > code to dynamic tags. * @var object alias * @access public */ var $close; // alias to closing tag. /** * Setvalue - gets name, attribute as an array * @see parent::setValue() */ function setValue($value) { global $_HTML_TEMPLATE_FLEXY_TOKEN; $this->tag = $value[0]; $this->UCtag = strtoupper($value[0]); if (isset($value[1])) { $this->attributes = $value[1]; } // hey one day PHP will be case sensitive :) } /** * toString - display tag, attributes, postfix and any code in attributes. * Note first thing it does is call any parseTag Method that exists.. * * * @see parent::toString() */ function toString() { $method = 'parseTag'.ucfirst(strtolower($this->tag)); if (method_exists($this,$method)) { $this->$method(); } $ret = ''; if ($foreach = $this->getAttribute('foreach')) { $foreachObj = $this->factory('Foreach', explode(',',$foreach), $this->line); $ret = $foreachObj->toString(); // does it have a closetag? $this->close->postfix = array($this->factory("End", '', $this->line)); } $ret .= "<". $this->tag; foreach ($this->attributes as $k=>$v) { if ($v === null) { $ret .= " $k"; continue; } if (is_string($v)) { $ret .= " {$k}={$v}"; continue; } if (is_object($v)) { $ret .= " " .$v->toString(); continue; } $ret .= " {$k}="; foreach($v as $item) { if (is_string($item)) { $ret .= $item; continue; } $ret .= $item->toString(); } } $ret .= ">"; if ($this->postfix) { foreach ($this->postfix as $e) { $ret .= $e->toString(); } } $ret .= $this->childrentoString(); if ($this->close) { $ret .= $this->close->toString(); } return $ret; } /** * Reads an Input tag and converts it to show variables based on the current form name * * Eg. filling in the value with $this->{fieldname}, adding in * echo $this->errors['fieldname'] at the end. * TODO : formating using DIV tags, and support for 'required tag' * * @return none * @access public */ function parseTagInput() { global $_HTML_TEMPLATE_FLEXY_TOKEN; // form elements : format: //value - fill out as PHP CODE $name = $this->getAttribute('name'); if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; } $type = strtoupper($this->getAttribute('type')); $thisvar = str_replace(']','',$name); $thisvar = str_replace('[','.',$thisvar); $posterror = array( $this->factory("PHP", "<?php if (isset(\$this->errors['".urlencode($thisvar)."'])) { ". "echo htmlspecialchars(\$this->errors['".urlencode($thisvar). "']); } ?>",$this->line)); switch ($type) { case "CHECKBOX": $this->attributes['checked'] = $this->factory("PHP", "<?php if (". $this->toVar($thisvar).") { ?>CHECKED<?php } ?>", $this->line); $this->postfix = $posterror; break; case "SUBMIT": return; case "HIDDEN": $this->attributes['value'] = array( "\"", $this->factory("Var",$thisvar.":u",$this->line), "\""); return; default: $this->attributes['value'] = array( "\"", $this->factory("Var",$thisvar.":u",$this->line), "\""); $this->postfix = $posterror; return; } $this->postfix = $posterror; // this should use <div name="form.error"> or something... } /** * Deal with a TextArea tag - empty the contents (eg. flag ignoreChildren), and add code.. * * Eg. filling in the value with $this->{fieldname}, adding in * echo $this->errors['fieldname'] at the end. * TODO : formating using DIV tags, and support for 'required tag' * * @return none * @access public */ function parseTagTextArea() { global $_HTML_TEMPLATE_FLEXY_TOKEN; // form elements : format: //value - fill out as PHP CODE $name = $this->getAttribute('name'); if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; } $thisvar = str_replace(']','',$name); $thisvar = str_replace('[','.',$thisvar); $posterror = array( $this->factory("PHP", "<?php if (isset(\$this->errors['".urlencode($thisvar)."'])) { ". "echo htmlspecialchars(\$this->errors['".urlencode($thisvar). "']); } ?>",$this->line)); $this->postfix = array( $this->factory("Var",$thisvar ,$this->line) ); $this->close->postfix = $posterror; $this->children = array(); return; } /** * Reads an Form tag and stores the current name (used as a prefix for input * in the form. * * Eg. * <form name="theform"><input name="an_input"> * gets converted to: * <form name="theform"><input name="an_input" value="<? echo htmlspecialchars($t->theform->an-input); ?>"> * * @return none * @access public */ function parseTagForm() { global $_HTML_TEMPLATE_FLEXY_TOKEN; if ($name = $this->getAttribute('name')) { $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] = $name; } } /** * getAttribute = reads an attribute value and strips the quotes * * TODO : sort out case issues... * does not handle valuse with flexytags in * * @return none * @access string */ function getAttribute($key) { // really need to do a foreach/ strtoupper if (!isset($this->attributes[$key])) { return ''; } $v = $this->attributes[$key]; switch($v{0}) { case "\"": case "'": return substr($v,1,-1); default: return $v; } } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Var.php +++ pear/HTML_Template_Flexy/Flexy/Token/Var.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Var.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle variable output * * * */ class HTML_Template_Flexy_Token_Var extends HTML_Template_Flexy_Token { /** * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) * * @var char * @access public */ var $modifier; /** * Setvalue - at present raw text.. - needs sorting out.. * @see parent::setValue() */ function setValue($value) { // comes in as raw {xxxx}, {xxxx:h} or {xxx.yyyy:h} if (strpos($value,":")) { list($value,$this->modifier) = explode(':',$value); } $this->value = $value; } /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // ignore modifier at present!! return "<?php echo htmlspecialchars(" . $this->toVar($this->value) . "); ?>"; } } ?>
Index: pear/HTML_Template_Flexy/Flexy.php diff -u pear/HTML_Template_Flexy/Flexy.php:1.8 pear/HTML_Template_Flexy/Flexy.php:1.9 --- pear/HTML_Template_Flexy/Flexy.php:1.8 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy.php Fri Jan 31 11:22:06 2003 @@ -41,7 +41,7 @@ * - heavily focused on displaying objects as pages. * (so you can document your tags.) * -* @version $Id: Flexy.php,v 1.8 2003/01/30 16:58:19 alan_k Exp $ +* @version $Id: Flexy.php,v 1.9 2003/01/31 16:22:06 alan_k Exp $ */ class HTML_Template_Flexy { @@ -157,7 +157,7 @@ $_error_reporting = false; if (!$options['debug']) { - $_error_reporting = error_reporting(); + $_error_reporting = error_reporting(E_ALL ^ E_NOTICE); } include($this->compiledTemplate); if ($_error_reporting !== false) { @@ -255,76 +255,25 @@ { // read the entire file into one variable + // note this should be moved to new HTML_Template_Flexy_Token + // and that can then manage all the tokens in one place.. + require_once 'HTML/Template/Flexy/Tokenizer.php'; $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions'] = $this->options; + + + $data = file_get_contents($this->currentTemplate); //echo strlen($data); $tokenizer = new HTML_Template_Flexy_Tokenizer($data); //$tokenizer->debug=1; - $i=0; - $res = array(); - - while ($t = $tokenizer->yylex()) { - //if ($tokenizer->value === '') { - // continue; - // } + $res = HTML_Template_Flexy_Token::buildTokens($tokenizer); - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { - PEAR::raiseError('HTML_Template_Flexy::Syntax error in Template line:'. $t->line,null,PEAR_ERROR_DIE); - } - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { - continue; - } - $i++; - $res[$i] = $tokenizer->value; - $res[$i]->id = $i; - //print_r($res[$i]); - - $tokenizer->value = ''; - - } - // connect parent and child tags. - $stack = array(); - for($i=0;$i<count($res);$i++) { - if (!@$res[$i]->tag) { - continue; - } - if ($res[$i]->tag{0} == '/') { // it's a close tag.. - //echo "GOT END TAG: {$res[$i]->tag}\n"; - $tag = strtoupper(substr($res[$i]->tag,1)); - if (!isset($stack[$tag]['pos'])) { - continue; // unmatched - } - $npos = $stack[$tag]['pos']; - //echo "matching it to {$stack[$tag][$npos]}\n"; - $res[$stack[$tag][$npos]]->close = &$res[$i]; - $stack[$tag]['pos']--; - if ($stack[$tag]['pos'] < 0) { - // too many closes - just ignore it.. - $stack[$tag]['pos'] = 0; - } - continue; - } - // new entry on stack.. - $tag = strtoupper($res[$i]->tag); - - if (!isset($stack[$tag])) { - $npos = $stack[$tag]['pos'] = 0; - } else { - $npos = ++$stack[$tag]['pos']; - } - $stack[$tag][$npos] = $i; - } - - - //new Gtk_VarDump($res); - $data = ''; - foreach($res as $v) { - $data .= $v->toHTML(); - } + $data = $res->toString(); + // error checking? if( ($cfp = fopen( $this->compiledTemplate , 'w' )) ) { @@ -557,4 +506,4 @@ } -?> +?> \ No newline at end of file Index: pear/HTML_Template_Flexy/package.xml diff -u pear/HTML_Template_Flexy/package.xml:1.8 pear/HTML_Template_Flexy/package.xml:1.9 --- pear/HTML_Template_Flexy/package.xml:1.8 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/package.xml Fri Jan 31 11:22:06 2003 @@ -52,6 +52,17 @@ <file>example.ini</file> <file>Tokenizer.php</file> <file>Token.php</file> + <dir name="Token" role="php"> + <file>Tag.php</file> + <file>EndTag.php</file> + <file>If.php</file> + <file>Else.php</file> + <file>End.php</file> + <file>Foreach.php</file> + <file>Include.php</file> + <file>Var.php</file> + <file>Method.php</file> + </dir> <file>Test.php</file> <dir name="Filter" role="php"> <file>BodyOnly.php</file> Index: pear/HTML_Template_Flexy/Flexy/Test.php diff -u pear/HTML_Template_Flexy/Flexy/Test.php:1.2 pear/HTML_Template_Flexy/Flexy/Test.php:1.3 --- pear/HTML_Template_Flexy/Flexy/Test.php:1.2 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Test.php Fri Jan 31 11:22:06 2003 @@ -17,7 +17,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Test.php,v 1.2 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Test.php,v 1.3 2003/01/31 16:22:06 alan_k Exp $ // // This is a temporary file - it includes some of the // Code that will have to go in the Engine eventually.. @@ -82,67 +82,12 @@ //echo strlen($data); $tokenizer = new HTML_Template_Flexy_Tokenizer($data); $tokenizer->debug=1; - $i=0; - $l = -1; - $tokenizer->value = ''; - $res = array(); - while ($t = $tokenizer->yylex()) { - //if ($tokenizer->value === '') { - // continue; - // } - - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { - $this->error(0,'GOT ERROR'); - } - if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { - continue; - } - - $i++; - $res[$i] = $tokenizer->value; - $res[$i]->id = $i; - //print_r($res[$i]); - - $tokenizer->value = ''; - - } - $stack = array(); - for($i=0;$i<count($res);$i++) { - if (!@$res[$i]->tag) { - continue; - } - if ($res[$i]->tag{0} == '/') { // it's a close tag.. - //echo "GOT END TAG: {$res[$i]->tag}\n"; - $tag = strtoupper(substr($res[$i]->tag,1)); - if (!isset($stack[$tag]['pos'])) { - continue; // unmatched - } - $npos = $stack[$tag]['pos']; - //echo "matching it to {$stack[$tag][$npos]}\n"; - $res[$stack[$tag][$npos]]->close = &$res[$i]; - $stack[$tag]['pos']--; - if ($stack[$tag]['pos'] < 0) { - // too many closes - just ignore it.. - $stack[$tag]['pos'] = 0; - } - continue; - } - // new entry on stack.. - $tag = strtoupper($res[$i]->tag); - - if (!isset($stack[$tag])) { - $npos = $stack[$tag]['pos'] = 0; - } else { - $npos = ++$stack[$tag]['pos']; - } - $stack[$tag][$npos] = $i; - } - + $res = HTML_Template_Flexy_Token::buildTokens($tokenizer); + new Gtk_VarDump($res); - foreach($res as $v) { - echo $v->toHTML(); - } + echo $res->toString(); + } Index: pear/HTML_Template_Flexy/Flexy/Token.php diff -u pear/HTML_Template_Flexy/Flexy/Token.php:1.3 pear/HTML_Template_Flexy/Flexy/Token.php:1.4 --- pear/HTML_Template_Flexy/Flexy/Token.php:1.3 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Token.php Fri Jan 31 11:22:06 2003 @@ -16,7 +16,7 @@ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // -// $Id: Token.php,v 1.3 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Token.php,v 1.4 2003/01/31 16:22:06 alan_k Exp $ // // This is the master Token file for The New Token driver Engine. // All the Token output, and building routines are in here. @@ -27,11 +27,12 @@ $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state'] = 0; $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'] = array(); - +$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['activeForm'] = ''; +$GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['tokens'] = array(); /** * Base Class for all Tokens. * -* @abstract Provides the static Create Method, and default toHTML() methods +* @abstract Provides the static Create Method, and default toString() methods * */ @@ -51,10 +52,18 @@ * @access public */ var $value; + /** + * the line the token is from + * + * @var int + * @access public + */ + + var $line; /** - * Create a Token + * factory a Token * * Standard factory method.. - with object vars. * ?? rename me to factory? @@ -67,8 +76,17 @@ * @access public */ - function create($token,$value,$line) { + function factory($token,$value,$line) { + // try not to reload the same class to often + static $loaded = array(); + + if (!isset($loaded[$token])) { + @include 'HTML/Template/Flexy/Token/'.$token.'.php'; + $loaded[$token] = true; + } + $c = 'HTML_Template_Flexy_Token_'.$token; + $t = new HTML_Template_Flexy_Token; if (class_exists($c)) { $t = new $c; @@ -100,13 +118,211 @@ * @access public */ - function toHTML() { + function toString() { if (is_array($this->value)) { var_dump($this); exit; } - return $this->value; + $ret = $this->value; + $ret .= $this->childrentoString(); + if ($this->close) { + $ret .= $this->close->toString(); + } + + return $ret; + } + + /** + * generate HTML from children after doing flexy manipulations.. + * + * @return string HTML + * @access public + */ + function childrentoString() { + if (!$this->children) { + return ''; + } + if ($this->ignoreChildren) { + return; + } + $ret = ''; + //echo "output $this->id"; + //new Gtk_VarDump($this); + foreach ($this->children as $child) { + if (!$child) { + continue; + } + $ret .= $child->toString(); + } + return $ret; + } + + + + /* ======================================================= */ + /* Token Managmenet = parse and store all the tokens in + * an associative array and tree. + */ + + /** + * Run a Tokenizer and Store its results + * It should build a DOM Tree of the HTML + * + * @param object Tokenizer to run.. - Theoretically other Tokenizers could be done for email,rtf etc. + * + * @access public + * @return base token (really a dummy token, which contains the tree) + * @static + */ + + function buildTokens($tokenizer) + { + + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + // first record is a filler - to stick all the children on ! + // reset my globals.. + + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = array(new HTML_Template_Flexy_Token); + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->id =0; + $i=1; + + + // step one just tokenize it. + while ($t = $tokenizer->yylex()) { + + if ($t == HTML_TEMPLATE_FLEXY_TOKEN_ERROR) { + PEAR::raiseError('HTML_Template_Flexy::Syntax error in Template line:'. $t->line, + null,PEAR_ERROR_DIE); + } + if ($t == HTML_TEMPLATE_FLEXY_TOKEN_NONE) { + continue; + } + + $i++; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = $tokenizer->value; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $i; + //print_r($res[$i]); + + } + $res = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens']; + // connect parent and child tags. + $stack = array(); + $total = $i +1; + for($i=1;$i<$total;$i++) { + //echo "Checking TAG $i\n"; + if (!@$res[$i]->tag) { + continue; + } + if ($res[$i]->tag{0} == '/') { // it's a close tag.. + //echo "GOT END TAG: {$res[$i]->tag}\n"; + $tag = strtoupper(substr($res[$i]->tag,1)); + if (!isset($stack[$tag]['pos'])) { + continue; // unmatched + } + $npos = $stack[$tag]['pos']; + //echo "matching it to {$stack[$tag][$npos]}\n"; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$stack[$tag][$npos]]->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]; + $stack[$tag]['pos']--; + if ($stack[$tag]['pos'] < 0) { + // too many closes - just ignore it.. + $stack[$tag]['pos'] = 0; + } + continue; + } + // new entry on stack.. + $tag = strtoupper($res[$i]->tag); + + if (!isset($stack[$tag])) { + $npos = $stack[$tag]['pos'] = 0; + } else { + $npos = ++$stack[$tag]['pos']; + } + $stack[$tag][$npos] = $i; + } + + // create a dummy close for the end + $i = $total; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i] = new HTML_Template_Flexy_Token; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->id = $total; + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]->close = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$total]; + + // now is it possible to connect children... + // now we need to GLOBALIZE!! - + + + $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'] = $res; + + HTML_Template_Flexy_Token::buildChildren(0); + //new Gtk_VarDump($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]); + + return $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][0]; + } + /** + * Matching closing tag for a Token + * + * @var object|none optional closing tag + * @access public + */ + + + var $close; + + /** + * array of children to each object. + * + * @var array + * @access public|private + */ + + + var $children = array(); + + /** + * Build the child array for each element. + * + * @param object Tokenizer to run.. - Theoretically other Tokenizers could be done for email,rtf etc. + * + * @access public + * @static + */ + function buildChildren($id) + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + $base = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$id]; + $base->children = array(); + $start = $base->id +1; + $end = $base->close->id; + for ($i=$start; $i<$end; $i++) { + $base->children[] = &$_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]; + if (isset($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close)) { + + // if the close id is greater than my id - ignore it! - + if ($_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close->id > $end) { + continue; + } + HTML_Template_Flexy_Token::buildChildren($i); + $i = $_HTML_TEMPLATE_FLEXY_TOKEN['tokens'][$i]->close->id; + } + } } + + + + /** + * Flag to ignore children - Used to block output for select/text area etc. + * + * @var boolean ingore children + * @access public + */ + + + var $ignoreChildren = false; + + + + /* ======================================================== */ /* variable STATE management * @@ -120,7 +336,7 @@ * @access public */ function reset() { - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state'] = 0; + $_HTML_TEMPLATE_FLEXY_TOKEN['state'] = 0; } /** @@ -128,11 +344,14 @@ * * @access public */ - function pushState() { - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']++; - $s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; + function pushState() + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + $_HTML_TEMPLATE_FLEXY_TOKEN['state']++; + $s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s] = array(); // initialize statevars + $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s] = array(); // initialize statevars } /** * tell the generator you are entering a block @@ -140,10 +359,13 @@ * @return boolean parse error - out of bounds * @access public */ - function pullState() { - $s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s] = array(); // initialize statevars - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']--; + function pullState() + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + + $s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; + $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s] = array(); // initialize statevars + $_HTML_TEMPLATE_FLEXY_TOKEN['state']--; if ($s<0) { return false; } @@ -177,12 +399,15 @@ * @access public */ - function findVar($string) { + function findVar($string) + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + if ($string == 't') { return '$t'; } - for ($s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; $s > 0; $s--) { - if (in_array($string, $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s])) { + for ($s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; $s > 0; $s--) { + if (in_array($string, $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s])) { return '$'.$string; } } @@ -195,573 +420,15 @@ * @access public */ - function pushVar($string) { - $s = $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['state']; - $GLOBALS['_HTML_TEMPLATE_FLEXY_TOKEN']['statevars'][$s][] = $string; + function pushVar($string) + { + global $_HTML_TEMPLATE_FLEXY_TOKEN; + $s = $_HTML_TEMPLATE_FLEXY_TOKEN['state']; + $_HTML_TEMPLATE_FLEXY_TOKEN['statevars'][$s][] = $string; } } - -/** -* A standard HTML Tag = eg. Table/Body etc. -* -* @abstract -* This is the generic HTML tag -* a simple one will have some attributes and a name. -* -*/ -class HTML_Template_Flexy_Token_Tag extends HTML_Template_Flexy_Token { - - /** - * HTML Tag: eg. Body or /Body - * - * @var string - * @access public - */ - var $tag = ''; - /** - * Associative array of attributes. - * - * key is the left, value is the right.. - * note: - * values are raw (eg. include "") - * valuse can be - * text = standard - * array (a parsed value with flexy tags in) - * object (normally some PHP code that generates the key as well..) - * - * - * @var array - * @access public - */ - - var $attributes = array(); - /** - * postfix tokens - * used to add code to end of tags - * - * @var array - * @access public - */ - var $postfix = ''; - /** - * prefix tokens - * used to add code to beginning of tags TODO - * - * @var array - * @access public - */ - var $prefix = ''; - - - /** - * Alias to closing tag (built externally). - * used to add < ? } ? > code to dynamic tags. - * @var object alias - * @access public - */ - var $close; // alias to closing tag. - - - - /** - * Setvalue - gets name, attribute as an array - * @see parent::setValue() - */ - - function setValue($value) { - - $this->tag = $value[0]; - $this->UCtag = strtoupper($value[0]); - if (isset($value[1])) { - $this->attributes = $value[1]; - } - if (in_array($this->UCtag,array("INPUT","TEXTAREA"))) { - $this->toFormElement(); - } - } - /** - * toHTML - display tag, attributes, postfix and any code in attributes. - * @see parent::toHTML() - */ - function toHTML() { - $ret = ''; - if ($foreach = $this->getAttribute('foreach')) { - $foreachObj = $this->create('Foreach', - explode(',',$foreach), - $this->line); - $ret = $foreachObj->toHTML(); - // does it have a closetag? - - $this->close->postfix = array($this->create("End", - '', - $this->line)); - - } - - $ret .= "<". $this->tag; - foreach ($this->attributes as $k=>$v) { - if ($v === null) { - $ret .= " $k"; - continue; - } - if (is_string($v)) { - $ret .= " {$k}={$v}"; - continue; - } - if (is_object($v)) { - $ret .= " " .$v->toHTML(); - continue; - } - - - $ret .= " {$k}="; - foreach($v as $item) { - if (is_string($item)) { - $ret .= $item; - continue; - } - $ret .= $item->toHTML(); - } - } - $ret .= ">"; - if ($this->postfix) { - foreach ($this->postfix as $e) { - $ret .= $e->toHTML(); - } - } - return $ret; - } - - /** - * toFormElement = takes an input field and generates related PHP code. - * - * Eg. filling in the value with $this->{fieldname}, adding in - * echo $this->errors['fieldname'] at the end. - * TODO : formating using DIV tags, and support for 'required tag' - * - * @return none - * @access public - */ - - function toFormElement() { - // form elements : format: - //value - fill out as PHP CODE - $name = $this->getAttribute('name'); - $type = strtoupper($this->getAttribute('type')); - $thisvar = str_replace(']','',$name); - $thisvar = str_replace('[','.',$thisvar); - - switch ($type) { - case "CHECKBOX": - $this->attributes['checked'] = - $this->create("PHP", - "<?php if (". $this->toVar($thisvar).") { ?>CHECKED<?php } ?>", - $this->line); - break; - - case "SUBMIT": - return; - - default: - $this->attributes['value'] = array( - "\"", - $this->create("Var",$thisvar.":u",$this->line), - "\""); - break; - - } - if ($type == "HIDDEN") { - return; - } - - $this->postfix = array( - $this->create("PHP", "<?php if (isset(\$this->errors['".urlencode($thisvar)."'])) { ". - "echo htmlspecialchars(\$this->errors['".urlencode($thisvar). "']); } ?>",$this->line)); - // this should use <div name="form.error"> or something... - - - } - /** - * getAttribute = reads an attribute value and strips the quotes - * - * TODO : sort out case issues... - * does not handle valuse with flexytags in - * - * @return none - * @access string - */ - function getAttribute($key) { - // really need to do a foreach/ strtoupper - if (!isset($this->attributes[$key])) { - return ''; - } - $v = $this->attributes[$key]; - switch($v{0}) { - case "\"": - case "'": - return substr($v,1,-1); - default: - return $v; - } - } - - - -} - - -/** -* The closing HTML Tag = eg. /Table or /Body etc. -* -* @abstract -* This just extends the generic HTML tag -* -*/ - -class HTML_Template_Flexy_Token_EndTag extends HTML_Template_Flexy_Token_Tag { } - - -/** -* Class to handle If statements -* -* -*/ -class HTML_Template_Flexy_Token_If extends HTML_Template_Flexy_Token{ - /** - * Condition for the if statement. - * @var string // a variable - * @access public - */ - - var $condition; - /** - * Setvalue - a string - * @see parent::setValue() - */ - function setValue($value) { - //var_dump($value); - $this->condition=$value; - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->toVar() - */ - function toHTML() { - $ret = "<?php if(@".$this->toVar($this->condition) .") { ?>"; - $this->pushState(); - return $ret; - - } - -} - - -/** -* Class to handle Else -* -* -*/ -class HTML_Template_Flexy_Token_Else extends HTML_Template_Flexy_Token { - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - // pushpull states to make sure we are in an area.. - should really check to see - // if the state it is pulling is a if... - if ($this->pullState() === false) { - echo "Unmatched End on Line {$this->line}"; - return false; - } - $this->pushState(); - return "<?php } else {?>"; - } - - -} - - - -/** -* Class to handle End statements (eg. close brakets) -* -* -*/ -class HTML_Template_Flexy_Token_End extends HTML_Template_Flexy_Token { - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - // pushpull states to make sure we are in an area.. - should really check to see - // if the state it is pulling is a if... - if ($this->pullState() === false) { - echo "Unmatched End on Line {$this->line}"; - return false; - } - - return "<?php } ?>"; - } - -} - - - -/** -* Class to handle foreach statements -* -* -*/ -class HTML_Template_Flexy_Token_Foreach extends HTML_Template_Flexy_Token { - - /** - * variable to loop on. - * - * @var string - * @access public - */ - var $loopOn = ''; - /** - * key value - * - * @var string - * @access public - */ - var $key = ''; - /** - * optional value (in key=>value pair) - * - * @var string - * @access public - */ - var $value = ''; - - /** - * Setvalue - a array of all three (last one optional) - * @see parent::setValue() - */ - - function setValue($value) { - $this->loopOn=$value[0]; - $this->key=$value[1]; - $this->value=@$value[2]; - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - $ret = "<?php if (is_array(". - $this->toVar($this->loopOn) . ")) " . - "foreach(".$this->toVar($this->loopOn). " "; - $ret .= "as \${$this->key}"; - if ($this->value) { - $ret .= " => \${$this->value}"; - } - $ret .= ") { ?>"; - - $this->pushState(); - $this->pushVar($this->key); - $this->pushVar($this->value); - return $ret; - } - -} - -/** -* Class to handle include statements -* TODO!!! -* -* Include is an odd baby.. - since we are supposed to be dealing with compiled templates.. -* It is the responsibility of the appliacation to make sure it has compiled the -* included template. -* Various types of Includes should be supported -* include:someobject.someval -* - maps to if (isset(....) && file_exists(....)) include ( value . '.{lang}.html') -* -* include: somevar -* -* -* -*/ -class HTML_Template_Flexy_Token_Include extends HTML_Template_Flexy_Token{ - - - - function toHTML() { - $v = $this->toVar($this->value); - - $options = $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']; - - $ret = "<?php if (isset($v) && - file_exists(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\")) - include(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\"); ?>"; - - return $ret; - - } - - - - -} - -/** -* Class to handle variable output -* * -* -*/ - -class HTML_Template_Flexy_Token_Var extends HTML_Template_Flexy_Token { - - /** - * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) - * - * @var char - * @access public - */ - var $modifier; - /** - * Setvalue - at present raw text.. - needs sorting out.. - * @see parent::setValue() - */ - function setValue($value) { - // comes in as raw {xxxx}, {xxxx:h} or {xxx.yyyy:h} - - if (strpos($value,":")) { - list($value,$this->modifier) = explode(':',$value); - } - $this->value = $value; - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - function toHTML() { - // ignore modifier at present!! - return "<?php echo htmlspecialchars(" . $this->toVar($this->value) . "); ?>"; - } - -} -/** -* Class to handle method calls -* * -* -*/ - -class HTML_Template_Flexy_Token_Method extends HTML_Template_Flexy_Token { - /** - * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) - * TODO - * @var char - * @access public - */ - var $modifier; - /** - * Method name - * - * @var char - * @access public - */ - var $method; - /** - * is it in if statement with a method? - * - * @var boolean - * @access public - */ - var $isConditional; - /** - * arguments, either variables or literals eg. #xxxxx yyyy# - * - * @var array - * @access public - */ - var $args= array(); - /** - * setvalue - at present array method, args (need to add modifier) - * @see parent::setValue() - */ - - function setValue($value) { - //var_dump($value); - $method = $value[0]; - if (substr($value[0],0,3) == 'if:') { - $this->isConditional = true; - $method = substr($value[0],3); - } - - if (strpos($method,":")) { - list($method,$this->modifier) = explode(':',$method); - } - $this->method = $method; - - $this->args = $value[1]; - // modifier TODO! - - } - /** - * toHTML - generate PHP code - * @see parent::toHTML(), $this->pullState() - */ - - function toHTML() { - // ignore modifier at present!! - $prefix = 'echo '; - $suffix = ''; - switch ($this->modifier) { - case 'h': - break; - case 'u': - $prefix = 'echo urlencode('; - $suffix = ')'; - default: - $prefix = 'echo htmlspecialchars('; - // add language ? - $suffix = ')'; - } - - - - if ($this->isConditional) { - $prefix = 'if ('; - $this->pushState(); - $suffix = ')'; - } - // should really check the variable part of method ... - - $ret = '<?php ' . $prefix; - $ret .= $this->toVar($this->method) . "("; - $s =0; - - foreach($this->args as $a) { - - if ($s) { - $ret .= ","; - } - $ret .= $this->toVar($a); - $s =1; - } - $ret .= ")" . $suffix; - - if ($this->isConditional) { - $ret .= ' { '; - } else { - $ret .= ";"; - } - $ret .= ' ?>'; - - return $ret; - - - - } - -} - - ?> Index: pear/HTML_Template_Flexy/Flexy/Tokenizer.lex diff -u pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.3 pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.4 --- pear/HTML_Template_Flexy/Flexy/Tokenizer.lex:1.3 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Tokenizer.lex Fri Jan 31 11:22:06 2003 @@ -16,7 +16,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Tokenizer.lex,v 1.3 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Tokenizer.lex,v 1.4 2003/01/31 16:22:06 alan_k Exp $ // // The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php) // You should always work with the .lex file and generate by @@ -186,21 +186,21 @@ <YYINITIAL>{CRO}{NUMBER}{REFERENCE_END}? { // { - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>{CRO}{NAME}{REFERENCE_END}? { // &#abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>{ERO}{NAME}{REFERENCE_END}? { // &abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -231,7 +231,7 @@ <YYINITIAL>{MDO}{NAME}{WHITESPACE} { /* <!DOCTYPE -- markup declaration */ - $this->value = HTML_Template_Flexy_Token::create('Doctype',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Doctype',$this->yytext(),$this->yyline); $this->yybegin(IN_MD); return HTML_TEMPLATE_FLEXY_TOKEN_OK; @@ -249,7 +249,7 @@ <YYINITIAL>{MDO}{COM} { /* <!-- -- comment declaration */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -273,7 +273,7 @@ /* <? ...> -- processing instruction */ // this is a little odd cause technically we dont allow it!! // really we only want to handle < ? xml - $this->value = HTML_Template_Flexy_Token::create('PHP',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('PHP',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -301,7 +301,7 @@ <YYINITIAL>([^\<\&\{]|(<[^<&a-zA-Z!->?])|(&[^<&#a-zA-Z]))+|"{" { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -440,7 +440,7 @@ // <a name=foo ^>,</foo^> -- tag close */ <IN_ATTR,IN_TAG>{TAGC} { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); @@ -464,7 +464,7 @@ <IN_ATTR>{NET}{WHITESPACE}{TAGC} { $this->attributes["/"] = null; - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); @@ -506,7 +506,7 @@ // end tag -- non-permissive */ <IN_ENDTAG>{TAGC} { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName), $this->yyline); array($this->tagName); @@ -526,7 +526,7 @@ <IN_COM>([^-]|-[^-])*{WHITESPACE} { // <!^--...--> -- comment */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -534,48 +534,48 @@ <IN_MD>{PERO}{NAME}{REFERENCE_END}?{WHITESPACE} { // <!doctype ^%foo;> -- parameter entity reference */ - $this->value = HTML_Template_Flexy_Token::create('EntityRef',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityRef',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{PERO}{SPACES} { // <!entity ^% foo system "..." ...> -- parameter entity definition */ - $this->value = HTML_Template_Flexy_Token::create('EntityPar',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityPar',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NUMBER}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('Number',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Number',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NAME}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('Name',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Name',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NUMBER_TOKEN}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('NumberT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NumberT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{NAME_TOKEN}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('NameT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NameT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{LITERAL}{WHITESPACE} { - $this->value = HTML_Template_Flexy_Token::create('Literal',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Literal',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_COM>{COM}{TAGC} { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_MD>{TAGC} { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -585,7 +585,7 @@ <IN_MD>{DSO} { // <!doctype foo ^[ -- declaration subset */ - $this->value = HTML_Template_Flexy_Token::create('BeginDS',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('BeginDS',$this->yytext(),$this->yyline); $this->yybegin(IN_DS); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -600,20 +600,20 @@ <IN_DS>{MSC}{TAGC} { // ]]> -- marked section end */ - $this->value = HTML_Template_Flexy_Token::create('DSEnd',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEnd',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_DS>{DSC} { // ] -- declaration subset close */ - $this->value = HTML_Template_Flexy_Token::create('DSEndSubset',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEndSubset',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <IN_DS>[^\]]+ { - $this->value = HTML_Template_Flexy_Token::create('Declaration',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Declaration',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -622,7 +622,7 @@ <YYINITIAL>"{if:"{FLEXY_VAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('If',substr($this->yytext(),4,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('If',substr($this->yytext(),4,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -641,36 +641,36 @@ <YYINITIAL>"{foreach:"{FLEXY_VAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{foreach:"{FLEXY_VAR}","{FLEXY_SIMPLEVAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{foreach:"{FLEXY_VAR}","{FLEXY_SIMPLEVAR}","{FLEXY_SIMPLEVAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{end:}" { - $this->value = HTML_Template_Flexy_Token::create('End', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('End', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{else:}" { - $this->value = HTML_Template_Flexy_Token::create('Else', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Else', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } <YYINITIAL>"{include:"{FLEXY_VAR}"}" { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } // needs to deal with \# - excaped #'s <YYINITIAL>"{include:#"{FLEXY_LITERAL}"#}" { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -686,11 +686,15 @@ $n = $this->yytext(); if ($n{0} != '{') { $n = substr($n,3); + } else { + $n = substr($n,1); } if ($n{strlen($n)-1} != '}') { $n = substr($n,0,-3); + } else { + $n = substr($n,0,-1); } - $this->attrVal[] = HTML_Template_Flexy_Token::create('Var' , $n, $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Var' , $n, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -699,7 +703,7 @@ $t = $this->yytext(); $t = substr($t,1,-1); - $this->value = HTML_Template_Flexy_Token::create('Var' , $t, $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Var' , $t, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -726,7 +730,7 @@ $this->flexyMethod .= substr($t,1,-1); } - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -750,7 +754,7 @@ } $this->flexyArgs[] = $t; - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -763,7 +767,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -801,7 +805,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-2); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -814,7 +818,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } Index: pear/HTML_Template_Flexy/Flexy/Tokenizer.php diff -u pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.3 pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.4 --- pear/HTML_Template_Flexy/Flexy/Tokenizer.php:1.3 Thu Jan 30 11:58:19 2003 +++ pear/HTML_Template_Flexy/Flexy/Tokenizer.php Fri Jan 31 11:22:06 2003 @@ -16,7 +16,7 @@ // | Authors: nobody <nobody@localhost> | // +----------------------------------------------------------------------+ // -// $Id: Tokenizer.php,v 1.3 2003/01/30 16:58:19 alan_k Exp $ +// $Id: Tokenizer.php,v 1.4 2003/01/31 16:22:06 alan_k Exp $ // // The Source Lex file. (Tokenizer.lex) and the Generated one (Tokenizer.php) // You should always work with the .lex file and generate by @@ -1518,13 +1518,13 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 4: { // &abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 5: @@ -1546,13 +1546,13 @@ case 7: { // { - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 8: { // &#abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 9: @@ -1573,7 +1573,7 @@ case 11: { /* <!DOCTYPE -- markup declaration */ - $this->value = HTML_Template_Flexy_Token::create('Doctype',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Doctype',$this->yytext(),$this->yyline); $this->yybegin(IN_MD); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1594,7 +1594,7 @@ /* <? ...> -- processing instruction */ // this is a little odd cause technically we dont allow it!! // really we only want to handle < ? xml - $this->value = HTML_Template_Flexy_Token::create('PHP',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('PHP',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 15: @@ -1607,7 +1607,7 @@ { $t = $this->yytext(); $t = substr($t,1,-1); - $this->value = HTML_Template_Flexy_Token::create('Var' , $t, $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Var' , $t, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 17: @@ -1627,13 +1627,13 @@ case 19: { /* <!-- -- comment declaration */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 20: { - $this->value = HTML_Template_Flexy_Token::create('If',substr($this->yytext(),4,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('If',substr($this->yytext(),4,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 21: @@ -1646,37 +1646,37 @@ } case 22: { - $this->value = HTML_Template_Flexy_Token::create('End', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('End', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 23: { - $this->value = HTML_Template_Flexy_Token::create('Else', '',$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Else', '',$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 24: { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 25: { - $this->value = HTML_Template_Flexy_Token::create('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach',array(substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 26: { - $this->value = HTML_Template_Flexy_Token::create('Include', substr($this->yytext(),9,-1),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Include', substr($this->yytext(),9,-1),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 27: { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 28: { - $this->value = HTML_Template_Flexy_Token::create('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Foreach', explode(',',substr($this->yytext(),9,-1)),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 29: @@ -1719,7 +1719,7 @@ } case 34: { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); $this->yybegin(YYINITIAL); @@ -1750,7 +1750,7 @@ case 38: { $this->attributes["/"] = null; - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName,$this->attributes), $this->yyline); $this->yybegin(YYINITIAL); @@ -1810,7 +1810,7 @@ } case 47: { - $this->value = HTML_Template_Flexy_Token::create($this->tokenName, + $this->value = HTML_Template_Flexy_Token::factory($this->tokenName, array($this->tagName), $this->yyline); array($this->tagName); @@ -1845,11 +1845,15 @@ $n = $this->yytext(); if ($n{0} != '{') { $n = substr($n,3); + } else { + $n = substr($n,1); } if ($n{strlen($n)-1} != '}') { $n = substr($n,0,-3); + } else { + $n = substr($n,0,-1); } - $this->attrVal[] = HTML_Template_Flexy_Token::create('Var' , $n, $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Var' , $n, $this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } case 51: @@ -1872,82 +1876,82 @@ } case 53: { - $this->value = HTML_Template_Flexy_Token::create('Number',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Number',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 54: { - $this->value = HTML_Template_Flexy_Token::create('Name',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Name',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 55: { - $this->value = HTML_Template_Flexy_Token::create('NameT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NameT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 56: { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 57: { // <!doctype foo ^[ -- declaration subset */ - $this->value = HTML_Template_Flexy_Token::create('BeginDS',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('BeginDS',$this->yytext(),$this->yyline); $this->yybegin(IN_DS); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 58: { - $this->value = HTML_Template_Flexy_Token::create('NumberT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NumberT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 59: { - $this->value = HTML_Template_Flexy_Token::create('Literal',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Literal',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 60: { // <!entity ^% foo system "..." ...> -- parameter entity definition */ - $this->value = HTML_Template_Flexy_Token::create('EntityPar',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityPar',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 61: { // <!doctype ^%foo;> -- parameter entity reference */ - $this->value = HTML_Template_Flexy_Token::create('EntityRef',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityRef',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 62: { // <!^--...--> -- comment */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 63: { - $this->value = HTML_Template_Flexy_Token::create('CloseTag',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('CloseTag',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 64: { - $this->value = HTML_Template_Flexy_Token::create('Declaration',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Declaration',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 65: { // ] -- declaration subset close */ - $this->value = HTML_Template_Flexy_Token::create('DSEndSubset',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEndSubset',$this->yytext(),$this->yyline); $this->yybegin(IN_COM); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 66: { // ]]> -- marked section end */ - $this->value = HTML_Template_Flexy_Token::create('DSEnd',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('DSEnd',$this->yytext(),$this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1971,7 +1975,7 @@ $t = substr($t,0,-2); } $this->flexyArgs[] = $t; - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1981,7 +1985,7 @@ if ($t{1} == ':') { $this->flexyMethod .= substr($t,1,-1); } - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -1994,7 +1998,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->value = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin(YYINITIAL); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -2007,7 +2011,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-2); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -2020,7 +2024,7 @@ return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } $this->flexyArgs[] = substr($t,0,-1); - $this->attrVal[] = HTML_Template_Flexy_Token::create('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); + $this->attrVal[] = HTML_Template_Flexy_Token::factory('Method' , array($this->flexyMethod,$this->flexyArgs), $this->yyline); $this->yybegin($this->flexyMethodState); return HTML_TEMPLATE_FLEXY_TOKEN_NONE; } @@ -2033,13 +2037,13 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 76: { // &abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 77: @@ -2055,13 +2059,13 @@ case 78: { // { - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 79: { // &#abc; - $this->value = HTML_Template_Flexy_Token::create('Ref',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Ref',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 80: @@ -2076,7 +2080,7 @@ case 81: { /* <!DOCTYPE -- markup declaration */ - $this->value = HTML_Template_Flexy_Token::create('Doctype',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Doctype',$this->yytext(),$this->yyline); $this->yybegin(IN_MD); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } @@ -2128,39 +2132,39 @@ } case 89: { - $this->value = HTML_Template_Flexy_Token::create('Number',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Number',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 90: { - $this->value = HTML_Template_Flexy_Token::create('Name',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Name',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 91: { - $this->value = HTML_Template_Flexy_Token::create('NameT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NameT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 92: { - $this->value = HTML_Template_Flexy_Token::create('NumberT',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('NumberT',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 93: { - $this->value = HTML_Template_Flexy_Token::create('Literal',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Literal',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 94: { // <!doctype ^%foo;> -- parameter entity reference */ - $this->value = HTML_Template_Flexy_Token::create('EntityRef',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('EntityRef',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 95: { // <!^--...--> -- comment */ - $this->value = HTML_Template_Flexy_Token::create('Comment',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Comment',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 96: @@ -2172,7 +2176,7 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 99: @@ -2223,7 +2227,7 @@ { //abcd -- data characters // { added for flexy - $this->value = HTML_Template_Flexy_Token::create('Text',$this->yytext(),$this->yyline); + $this->value = HTML_Template_Flexy_Token::factory('Text',$this->yytext(),$this->yyline); return HTML_TEMPLATE_FLEXY_TOKEN_OK; } case 175: Index: pear/HTML_Template_Flexy/Flexy/Token/Else.php +++ pear/HTML_Template_Flexy/Flexy/Token/Else.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Else.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle Else * * */ class HTML_Template_Flexy_Token_Else extends HTML_Template_Flexy_Token { /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // pushpull states to make sure we are in an area.. - should really check to see // if the state it is pulling is a if... if ($this->pullState() === false) { echo "Unmatched End on Line {$this->line}"; return false; } $this->pushState(); return "<?php } else {?>"; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/End.php +++ pear/HTML_Template_Flexy/Flexy/Token/End.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: End.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle End statements (eg. close brakets) * * */ class HTML_Template_Flexy_Token_End extends HTML_Template_Flexy_Token { /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // pushpull states to make sure we are in an area.. - should really check to see // if the state it is pulling is a if... if ($this->pullState() === false) { echo "Unmatched End on Line {$this->line}"; return false; } return "<?php } ?>"; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/EndTag.php +++ pear/HTML_Template_Flexy/Flexy/Token/EndTag.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: EndTag.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * The closing HTML Tag = eg. /Table or /Body etc. * * @abstract * This just extends the generic HTML tag * */ class HTML_Template_Flexy_Token_EndTag extends HTML_Template_Flexy_Token_Tag { } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Foreach.php +++ pear/HTML_Template_Flexy/Flexy/Token/Foreach.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Foreach.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle foreach statements * * */ class HTML_Template_Flexy_Token_Foreach extends HTML_Template_Flexy_Token { /** * variable to loop on. * * @var string * @access public */ var $loopOn = ''; /** * key value * * @var string * @access public */ var $key = ''; /** * optional value (in key=>value pair) * * @var string * @access public */ var $value = ''; /** * Setvalue - a array of all three (last one optional) * @see parent::setValue() */ function setValue($value) { $this->loopOn=$value[0]; $this->key=$value[1]; $this->value=@$value[2]; } /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { $ret = "<?php if (is_array(". $this->toVar($this->loopOn) . ")) " . "foreach(".$this->toVar($this->loopOn). " "; $ret .= "as \${$this->key}"; if ($this->value) { $ret .= " => \${$this->value}"; } $ret .= ") { ?>"; $this->pushState(); $this->pushVar($this->key); $this->pushVar($this->value); return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/If.php +++ pear/HTML_Template_Flexy/Flexy/Token/If.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: If.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle If statements * * */ class HTML_Template_Flexy_Token_If extends HTML_Template_Flexy_Token{ /** * Condition for the if statement. * @var string // a variable * @access public */ var $condition; /** * Setvalue - a string * @see parent::setValue() */ function setValue($value) { //var_dump($value); $this->condition=$value; } /** * toString - generate PHP code * @see parent::toString(), $this->toVar() */ function toString() { $ret = "<?php if(@".$this->toVar($this->condition) .") { ?>"; $this->pushState(); return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Include.php +++ pear/HTML_Template_Flexy/Flexy/Token/Include.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Include.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle include statements * TODO!!! * * Include is an odd baby.. - since we are supposed to be dealing with compiled templates.. * It is the responsibility of the appliacation to make sure it has compiled the * included template. * Various types of Includes should be supported * include:someobject.someval * - maps to if (isset(....) && file_exists(....)) include ( value . '.{lang}.html') * * include: somevar * * * */ class HTML_Template_Flexy_Token_Include extends HTML_Template_Flexy_Token{ function toString() { $v = $this->toVar($this->value); $options = $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']; $ret = "<?php if (isset($v) && file_exists(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\")) include(\"{$options['compileDir']}/\".{$v}.\".{$options['locale']}.php\"); ?>"; return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Method.php +++ pear/HTML_Template_Flexy/Flexy/Token/Method.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Method.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle method calls * * * */ class HTML_Template_Flexy_Token_Method extends HTML_Template_Flexy_Token { /** * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) * TODO * @var char * @access public */ var $modifier; /** * Method name * * @var char * @access public */ var $method; /** * is it in if statement with a method? * * @var boolean * @access public */ var $isConditional; /** * arguments, either variables or literals eg. #xxxxx yyyy# * * @var array * @access public */ var $args= array(); /** * setvalue - at present array method, args (need to add modifier) * @see parent::setValue() */ function setValue($value) { //var_dump($value); $method = $value[0]; if (substr($value[0],0,3) == 'if:') { $this->isConditional = true; $method = substr($value[0],3); } if (strpos($method,":")) { list($method,$this->modifier) = explode(':',$method); } $this->method = $method; $this->args = $value[1]; // modifier TODO! } /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // ignore modifier at present!! $prefix = 'echo '; $suffix = ''; switch ($this->modifier) { case 'h': break; case 'u': $prefix = 'echo urlencode('; $suffix = ')'; default: $prefix = 'echo htmlspecialchars('; // add language ? $suffix = ')'; } if ($this->isConditional) { $prefix = 'if ('; $this->pushState(); $suffix = ')'; } // should really check the variable part of method ... $ret = '<?php ' . $prefix; $ret .= $this->toVar($this->method) . "("; $s =0; foreach($this->args as $a) { if ($s) { $ret .= ","; } $ret .= $this->toVar($a); $s =1; } $ret .= ")" . $suffix; if ($this->isConditional) { $ret .= ' { '; } else { $ret .= ";"; } $ret .= ' ?>'; return $ret; } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Tag.php +++ pear/HTML_Template_Flexy/Flexy/Token/Tag.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Tag.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ /** * A standard HTML Tag = eg. Table/Body etc. * * @abstract * This is the generic HTML tag * a simple one will have some attributes and a name. * */ class HTML_Template_Flexy_Token_Tag extends HTML_Template_Flexy_Token { /** * HTML Tag: eg. Body or /Body * * @var string * @access public */ var $tag = ''; /** * Associative array of attributes. * * key is the left, value is the right.. * note: * values are raw (eg. include "") * valuse can be * text = standard * array (a parsed value with flexy tags in) * object (normally some PHP code that generates the key as well..) * * * @var array * @access public */ var $attributes = array(); /** * postfix tokens * used to add code to end of tags * * @var array * @access public */ var $postfix = ''; /** * prefix tokens * used to add code to beginning of tags TODO * * @var array * @access public */ var $prefix = ''; /** * Alias to closing tag (built externally). * used to add < ? } ? > code to dynamic tags. * @var object alias * @access public */ var $close; // alias to closing tag. /** * Setvalue - gets name, attribute as an array * @see parent::setValue() */ function setValue($value) { global $_HTML_TEMPLATE_FLEXY_TOKEN; $this->tag = $value[0]; $this->UCtag = strtoupper($value[0]); if (isset($value[1])) { $this->attributes = $value[1]; } // hey one day PHP will be case sensitive :) } /** * toString - display tag, attributes, postfix and any code in attributes. * Note first thing it does is call any parseTag Method that exists.. * * * @see parent::toString() */ function toString() { $method = 'parseTag'.ucfirst(strtolower($this->tag)); if (method_exists($this,$method)) { $this->$method(); } $ret = ''; if ($foreach = $this->getAttribute('foreach')) { $foreachObj = $this->factory('Foreach', explode(',',$foreach), $this->line); $ret = $foreachObj->toString(); // does it have a closetag? $this->close->postfix = array($this->factory("End", '', $this->line)); } $ret .= "<". $this->tag; foreach ($this->attributes as $k=>$v) { if ($v === null) { $ret .= " $k"; continue; } if (is_string($v)) { $ret .= " {$k}={$v}"; continue; } if (is_object($v)) { $ret .= " " .$v->toString(); continue; } $ret .= " {$k}="; foreach($v as $item) { if (is_string($item)) { $ret .= $item; continue; } $ret .= $item->toString(); } } $ret .= ">"; if ($this->postfix) { foreach ($this->postfix as $e) { $ret .= $e->toString(); } } $ret .= $this->childrentoString(); if ($this->close) { $ret .= $this->close->toString(); } return $ret; } /** * Reads an Input tag and converts it to show variables based on the current form name * * Eg. filling in the value with $this->{fieldname}, adding in * echo $this->errors['fieldname'] at the end. * TODO : formating using DIV tags, and support for 'required tag' * * @return none * @access public */ function parseTagInput() { global $_HTML_TEMPLATE_FLEXY_TOKEN; // form elements : format: //value - fill out as PHP CODE $name = $this->getAttribute('name'); if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; } $type = strtoupper($this->getAttribute('type')); $thisvar = str_replace(']','',$name); $thisvar = str_replace('[','.',$thisvar); $posterror = array( $this->factory("PHP", "<?php if (isset(\$this->errors['".urlencode($thisvar)."'])) { ". "echo htmlspecialchars(\$this->errors['".urlencode($thisvar). "']); } ?>",$this->line)); switch ($type) { case "CHECKBOX": $this->attributes['checked'] = $this->factory("PHP", "<?php if (". $this->toVar($thisvar).") { ?>CHECKED<?php } ?>", $this->line); $this->postfix = $posterror; break; case "SUBMIT": return; case "HIDDEN": $this->attributes['value'] = array( "\"", $this->factory("Var",$thisvar.":u",$this->line), "\""); return; default: $this->attributes['value'] = array( "\"", $this->factory("Var",$thisvar.":u",$this->line), "\""); $this->postfix = $posterror; return; } $this->postfix = $posterror; // this should use <div name="form.error"> or something... } /** * Deal with a TextArea tag - empty the contents (eg. flag ignoreChildren), and add code.. * * Eg. filling in the value with $this->{fieldname}, adding in * echo $this->errors['fieldname'] at the end. * TODO : formating using DIV tags, and support for 'required tag' * * @return none * @access public */ function parseTagTextArea() { global $_HTML_TEMPLATE_FLEXY_TOKEN; // form elements : format: //value - fill out as PHP CODE $name = $this->getAttribute('name'); if ($_HTML_TEMPLATE_FLEXY_TOKEN['activeForm']) { $name = $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] .'.'.$name; } $thisvar = str_replace(']','',$name); $thisvar = str_replace('[','.',$thisvar); $posterror = array( $this->factory("PHP", "<?php if (isset(\$this->errors['".urlencode($thisvar)."'])) { ". "echo htmlspecialchars(\$this->errors['".urlencode($thisvar). "']); } ?>",$this->line)); $this->postfix = array( $this->factory("Var",$thisvar ,$this->line) ); $this->close->postfix = $posterror; $this->children = array(); return; } /** * Reads an Form tag and stores the current name (used as a prefix for input * in the form. * * Eg. * <form name="theform"><input name="an_input"> * gets converted to: * <form name="theform"><input name="an_input" value="<? echo htmlspecialchars($t->theform->an-input); ?>"> * * @return none * @access public */ function parseTagForm() { global $_HTML_TEMPLATE_FLEXY_TOKEN; if ($name = $this->getAttribute('name')) { $_HTML_TEMPLATE_FLEXY_TOKEN['activeForm'] = $name; } } /** * getAttribute = reads an attribute value and strips the quotes * * TODO : sort out case issues... * does not handle valuse with flexytags in * * @return none * @access string */ function getAttribute($key) { // really need to do a foreach/ strtoupper if (!isset($this->attributes[$key])) { return ''; } $v = $this->attributes[$key]; switch($v{0}) { case "\"": case "'": return substr($v,1,-1); default: return $v; } } } ?> Index: pear/HTML_Template_Flexy/Flexy/Token/Var.php +++ pear/HTML_Template_Flexy/Flexy/Token/Var.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: Alan Knowles <alan@akbkhome> | // +----------------------------------------------------------------------+ // // $Id: Var.php,v 1.1 2003/01/31 16:22:08 alan_k Exp $ // /** * Class to handle variable output * * * */ class HTML_Template_Flexy_Token_Var extends HTML_Template_Flexy_Token { /** * variable modifier (h = raw, u = urlencode, none = htmlspecialchars) * * @var char * @access public */ var $modifier; /** * Setvalue - at present raw text.. - needs sorting out.. * @see parent::setValue() */ function setValue($value) { // comes in as raw {xxxx}, {xxxx:h} or {xxx.yyyy:h} if (strpos($value,":")) { list($value,$this->modifier) = explode(':',$value); } $this->value = $value; } /** * toString - generate PHP code * @see parent::toString(), $this->pullState() */ function toString() { // ignore modifier at present!! return "<?php echo htmlspecialchars(" . $this->toVar($this->value) . "); ?>"; } } ?>