HTML_Template_Flexy
[ class tree: HTML_Template_Flexy ] [ index: HTML_Template_Flexy ] [ all elements ]

Source for file Tag.php

Documentation is available at Tag.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4: */
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2002 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors:  Alan Knowles <alan@akbkhome>                               |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Tag.php 334846 2014-09-12 04:50:56Z alan_k $
  20. /* FC/BC compatibility with php5 */
  21. if ( (substr(phpversion(),0,1< 5&& !function_exists('clone')) {
  22.     eval('function clone($t) { return $t; }');
  23. }
  24.  
  25. /**
  26. * Compiler That deals with standard HTML Tag output.
  27. * Since it's pretty complex it has it's own class.
  28. * I guess this class should deal with the main namespace
  29. * and the parent (standard compiler can redirect other namespaces to other classes.
  30. *
  31. * one instance of these exists for each namespace.
  32. *
  33. *
  34. @version    $Id: Tag.php 334846 2014-09-12 04:50:56Z alan_k $
  35. */
  36.  
  37. class HTML_Template_Flexy_Compiler_Standard_Tag {
  38.  
  39.         
  40.     /**
  41.     * Parent Compiler for
  42.     *
  43.     * @var  object  HTML_Template_Flexy_Compiler 
  44.     * 
  45.     * @access public
  46.     */
  47.     var $compiler;
  48.  
  49.     /**
  50.     *   
  51.     * Factory method to create Tag Handlers
  52.     *
  53.     * $type = namespace eg. <flexy:toJavascript loads Flexy.php
  54.     * the default is this... (eg. Tag)
  55.     * 
  56.     * 
  57.     * @param   string    Namespace handler for element.
  58.     * @param   object   HTML_Template_Flexy_Compiler 
  59.     * 
  60.     *
  61.     * @return    object    tag compiler
  62.     * @access   public
  63.     */
  64.     
  65.     function &factory($type,&$compiler{
  66.         if (!$type{
  67.             $type 'Tag';
  68.         }
  69.         // if we dont have a handler - just use the basic handler.
  70.         if (!file_exists(dirname(__FILE__'/'ucfirst(strtolower($type)) '.php')) {
  71.             $type 'Tag';
  72.         }
  73.             
  74.         include_once 'HTML/Template/Flexy/Compiler/Standard/' ucfirst(strtolower($type)) '.php';
  75.         
  76.         $class 'HTML_Template_Flexy_Compiler_Standard_' $type;
  77.         if (!class_exists($class)) {
  78.             return false;
  79.         }
  80.         $ret = new $class;
  81.         $ret->compiler = &$compiler;
  82.         return $ret;
  83.     }
  84.         
  85.         
  86.     /**
  87.     * The current element to parse..
  88.     *
  89.     * @var object 
  90.     * @access public
  91.     */    
  92.     var $element;
  93.     
  94.     /**
  95.     * Flag to indicate has attribute flexy:foreach (so you cant mix it with flexy:if!)
  96.     *
  97.     * @var boolean 
  98.     * @access public
  99.     */    
  100.     var $hasForeach = false;
  101.     
  102.     
  103.     
  104.     
  105.     /**
  106.     * toString - display tag, attributes, postfix and any code in attributes.
  107.     * Note first thing it does is call any parseTag Method that exists..
  108.     *
  109.     * 
  110.     * @see parent::toString()
  111.     */
  112.     function toString($element
  113.     {
  114.         
  115.         global $_HTML_TEMPLATE_FLEXY_TOKEN;
  116.         global $_HTML_TEMPLATE_FLEXY;
  117.          
  118.         // store the element in a variable
  119.         $this->element $element;
  120.        // echo "toString: Line {$this->element->line} &lt;{$this->element->tag}&gt;\n"; 
  121.         
  122.         // if the FLEXYSTARTCHILDREN flag was set, only do children
  123.         // normally set in BODY tag.
  124.         // this will probably be superseeded by the Class compiler.
  125.          
  126.         if (isset($element->ucAttributes['FLEXY:STARTCHILDREN'])) {
  127.             
  128.             return $element->compileChildren($this->compiler);
  129.         }
  130.         
  131.         $flexyignore $this->parseAttributeIgnore();
  132.         
  133.         // rewriting should be done with a tag.../flag.
  134.         
  135.         $this->reWriteURL("HREF");
  136.         $this->reWriteURL("SRC");
  137.         
  138.         // handle elements
  139.         if (($ret =$this->_parseTags()) !== false{
  140.             return $ret;
  141.         }
  142.         // these add to the close tag..
  143.         
  144.         $ret  $this->parseAttributeForeach();
  145.         $ret .= $this->parseAttributeIf();
  146.         
  147.         // spit ou the tag and attributes.
  148.         
  149.         if ($element->oTag{0== '?'{
  150.             $ret .= '<?php echo "<"; ?>';
  151.         else 
  152.             $ret .= "<";
  153.         }
  154.         $ret .= $element->oTag;
  155.       
  156.         foreach ($element->attributes as $k=>$v{
  157.             // if it's a flexy tag ignore it.
  158.             
  159.             
  160.             if (strtoupper($k== 'FLEXY:RAW'{
  161.                 if (!is_array($v|| !isset($v[1]|| !is_object($v[1])) {
  162.                     return HTML_Template_Flexy::staticRaiseError(
  163.                         'flexy:raw only accepts a variable or method call as an argument, eg.'.
  164.                         ' flexy:raw="{somevalue}" you provided something else.' .
  165.                         " Error on Line {$this->element->line} &lt;{$this->element->tag}&gt;",
  166.                          null,   HTML_TEMPLATE_FLEXY_ERROR_DIE);
  167.                 }
  168.                 $add $v[1]->compile($this->compiler);
  169.                 if (is_object($add&& is_a($add,'PEAR_Error')) {
  170.                     return $add;
  171.                 }
  172.                 $ret .= ' ' $add;
  173.                 continue;
  174.             
  175.             }
  176.             
  177.             if (strtoupper(substr($k,0,6)) == 'FLEXY:'{
  178.                 continue;
  179.             }
  180.             // true == an attribute without a ="xxx"
  181.             if ($v === true{
  182.                 $ret .= " $k";
  183.                 continue;
  184.             }
  185.             
  186.             // if it's a string just dump it.
  187.             if (is_string($v)) {
  188.                 $ret .=  " {$k}={$v}";
  189.                 continue;
  190.             }
  191.             
  192.             // normally the value is an array of string, however
  193.             // if it is an object - then it's a conditional key.
  194.             // eg.  if (something) echo ' SELECTED';
  195.             // the object is responsible for adding it's space..
  196.             
  197.             if (is_object($v)) {
  198.                 $add $v->compile($this->compiler);
  199.                 if (is_object($add&& is_a($add,'PEAR_Error')) {
  200.                     return $add;
  201.                 }
  202.             
  203.                 $ret .= $add;
  204.                 continue;
  205.             }
  206.             
  207.             // otherwise its a key="sometext{andsomevars}"
  208.             
  209.             $ret .=  " {$k}=";
  210.             
  211.             foreach($v as $item{
  212.                 if (is_string($item)) {
  213.                     $ret .= $item;
  214.                     continue;
  215.                 }
  216.                 $add $item->compile($this->compiler);
  217.                 if (is_object($add&& is_a($add,'PEAR_Error')) {
  218.                     return $add;
  219.                 }
  220.                 $ret .= $add;
  221.             }
  222.         }
  223.         $ret .= ">";
  224.         
  225.         // post stuff this is probably in the wrong place...
  226.         
  227.         if ($element->postfix{
  228.             foreach ($element->postfix as $e{
  229.                 $add $e->compile($this->compiler);
  230.                 if (is_object($add&& is_a($add,'PEAR_Error')) {
  231.                     return $add;
  232.                 }
  233.                 $ret .= $add;
  234.             }
  235.         else if ($this->element->postfix// if postfixed by self..
  236.             foreach ($this->element->postfix as $e{
  237.                 $add $e->compile($this->compiler);
  238.                 if (is_object($add&& is_a($add,'PEAR_Error')) {
  239.                     return $add;
  240.                 }
  241.             
  242.                 $ret .= $add;
  243.             }
  244.         }
  245.         // dump contents of script raw - to prevent gettext additions..
  246.         //  print_r($element);
  247.         if ($element->tag == 'SCRIPT'{
  248.             foreach($element->children as $c{
  249.                 //print_R($c);
  250.                 if (!$c{
  251.                     continue;
  252.                 }
  253.                 if ($c->token == 'Text'{
  254.                     $ret .= $c->value;
  255.                     continue;
  256.                 }
  257.                 // techically we shouldnt have anything else inside of script tags.
  258.                 // as the tokeinzer is supposted to ignore it..
  259.             }
  260.         else {
  261.             $add $element->compileChildren($this->compiler);
  262.             if (is_object($add&& is_a($add,'PEAR_Error')) {
  263.                 return $add;
  264.             }
  265.             $ret .= $add;
  266.         }
  267.         
  268.         
  269.         
  270.         // output the closing tag.
  271.         
  272.         if ($element->close{
  273.             $add $element->close->compile($this->compiler);
  274.             if (is_object($add&& is_a($add,'PEAR_Error')) {
  275.                 return $add;
  276.             }
  277.             $ret .= $add;
  278.         }
  279.         
  280.         // reset flexyignore
  281.         
  282.         $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'$flexyignore;
  283.         
  284.         if (isset($_HTML_TEMPLATE_FLEXY['currentOptions']['output.block']&& 
  285.             ($_HTML_TEMPLATE_FLEXY['currentOptions']['output.block'== $element->getAttribute('ID'))) {
  286.                 
  287.            // echo $_HTML_TEMPLATE_FLEXY['compiledTemplate'];
  288.             
  289.             $fh fopen($_HTML_TEMPLATE_FLEXY['compiledTemplate'],'w');
  290.             fwrite($fh,$ret);
  291.             fclose($fh);   
  292.            
  293.         }
  294.             
  295.         
  296.         
  297.         return $ret;
  298.     }
  299.     /**
  300.     * Reads an flexy:foreach attribute -
  301.     *
  302.     *
  303.     * @return   string to add to output.
  304.     * @access   public
  305.     */
  306.     
  307.     function parseAttributeIgnore(
  308.     {
  309.     
  310.         global $_HTML_TEMPLATE_FLEXY_TOKEN;
  311.         
  312.         $flexyignore $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'];
  313.         
  314.         if ($this->element->getAttribute('FLEXY:IGNORE'!== false{
  315.             $_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore'= true;
  316.             $this->element->clearAttribute('FLEXY:IGNORE');
  317.         }
  318.         return $flexyignore;
  319.  
  320.     }
  321.     
  322.     /**
  323.     * Reads an flexy:foreach attribute -
  324.     *
  325.     *
  326.     * @return   string to add to output.
  327.     * @access   public
  328.     */
  329.     
  330.     function parseAttributeForeach(
  331.     {
  332.         $foreach $this->element->getAttribute('FLEXY:FOREACH');
  333.         if ($foreach === false{
  334.             return '';
  335.         }
  336.         //var_dump($foreach);
  337.         
  338.         $this->element->hasForeach = true;
  339.         // create a foreach element to wrap this with.
  340.         
  341.         $foreachObj =  $this->element->factory('Foreach',
  342.                 explode(',',$foreach),
  343.                 $this->element->line);
  344.         // failed = probably not enough variables..    
  345.         
  346.         
  347.         if ($foreachObj === false{
  348.             return HTML_Template_Flexy::staticRaiseError(
  349.                 "Missing Arguments: An flexy:foreach attribute was foundon Line {$this->element->line} 
  350.                 in tag &lt;{$this->element->tag} flexy:foreach=&quot;$foreach&quot; .....&gt;<BR>
  351.                 the syntax is  &lt;sometag flexy:foreach=&quot;onarray,withvariable[,withanothervar] &gt;<BR>",
  352.                  null,  HTML_TEMPLATE_FLEXY_ERROR_DIE);
  353.         }
  354.         
  355.         
  356.         
  357.         // does it have a closetag?
  358.         if (!$this->element->close{
  359.         
  360.             if ($this->element->getAttribute('/'=== false{
  361.             
  362.             
  363.                 return HTML_Template_Flexy::staticRaiseError(
  364.                     "A flexy:foreach attribute was found in &lt;{$this->element->name} tag without a corresponding &lt;/{$this->element->tag}
  365.                         tag on Line {$this->element->line} &lt;{$this->element->tag}&gt;",
  366.                      nullHTML_TEMPLATE_FLEXY_ERROR_DIE);
  367.             }
  368.             // it's an xhtml tag!
  369.             $this->element->postfix = array($this->element->factory("End"''$this->element->line));
  370.         else {
  371.             $this->element->close->postfix = array($this->element->factory("End"''$this->element->line));
  372.         }
  373.  
  374.         $this->element->clearAttribute('FLEXY:FOREACH');
  375.         return $foreachObj->compile($this->compiler);
  376.     }
  377.     /**
  378.     * Reads an flexy:if attribute -
  379.     *
  380.     *
  381.     * @return   string to add to output.
  382.     * @access   public
  383.     */
  384.     
  385.     function parseAttributeIf(
  386.     {
  387.         // dont use the together, if is depreciated..
  388.         $if $this->element->getAttribute('FLEXY:IF');
  389.         
  390.         if ($if === false{
  391.             return '';
  392.         }
  393.         
  394.         if (isset($this->element->hasForeach)) {
  395.             return HTML_Template_Flexy::staticRaiseError(
  396.                 "You may not use FOREACH and IF tags in the same tag on Line {$this->element->line} &lt;{$this->element->tag}&gt;",
  397.                  nullHTML_TEMPLATE_FLEXY_ERROR_DIE);
  398.         }
  399.         
  400.         // allow if="!somevar"
  401.         $ifnegative '';
  402.         
  403.         if ($if{0== '!'{
  404.             $ifnegative '!';    
  405.             $if substr($if,1);
  406.         }
  407.         // if="xxxxx"
  408.         // if="xxxx.xxxx()" - should create a method prefixed with 'if:'
  409.         // these checks should really be in the if/method class..!!!
  410.         
  411.         
  412.         
  413.         if (!preg_match('/^[_A-Z][A-Z0-9_]*(\[[0-9]+\])?((\[|%5B)[A-Z0-9_]+(\]|%5D))*'.
  414.                 '(\.[_A-Z][A-Z0-9_]*((\[|%5B)[A-Z0-9_]+(\]|%5D))*)*(\\([^)]*\))?$/i',$if)) {
  415.             return HTML_Template_Flexy::staticRaiseError(
  416.                 "IF tags only accept simple object.variable or object.method() values on 
  417.                     Line {$this->element->line} &lt;{$this->element->tag}&gt;
  418.                     {$if}",
  419.                  nullHTML_TEMPLATE_FLEXY_ERROR_DIE);
  420.         }
  421.         
  422.         if (substr($if,-1== ')'{
  423.             // grab args..
  424.             $args substr($if,strpos($if,'(')+1,-1);
  425.             // simple explode ...
  426.             
  427.             $args strlen(trim($args)) explode(',',$args: array();
  428.             //print_R($args);
  429.             
  430.             // this is nasty... - we need to check for quotes = eg. # at beg. & end..
  431.             $args_clean = array();
  432.             for ($i=0; $i<count($args)$i++{
  433.                 if ($args[$i]{0!= '#'{
  434.                     $args_clean[$args[$i];
  435.                     continue;
  436.                 }
  437.                 // single # - so , must be inside..
  438.                 if ((strlen($args[$i]> 1&& ($args[$i]{strlen($args[$i])-1}=='#')) {
  439.                     $args_clean[$args[$i];
  440.                     continue;
  441.                 }
  442.                 
  443.                 $args[$i.=',' $args[$i+1];
  444.                 // remove args+1..
  445.                 array_splice($args,$i+1,1);
  446.                 $i--;
  447.                 // reparse..
  448.             }
  449.             
  450.             
  451.             
  452.             $ifObj =  $this->element->factory('Method',
  453.                     array('if:'.$ifnegative.substr($if,0,strpos($if,'('))$args_clean),
  454.                     $this->element->line);
  455.         else {
  456.             $ifObj =  $this->element->factory('If'$ifnegative.$if$this->element->line);
  457.         }
  458.         
  459.         // does it have a closetag? - you must have one - so you will have to hack in <span flexy:if=..><img></span> on tags
  460.         // that do not have close tags - it's done this way to try and avoid mistakes.
  461.         
  462.         
  463.         if (!$this->element->close{
  464.             //echo "<PRE>";print_R($this->element);
  465.             
  466.             if ($this->element->getAttribute('/'!== false{
  467.                 $this->element->postfix = array($this->element->factory("End",''$this->element->line));
  468.             else {
  469.             
  470.                 return HTML_Template_Flexy::staticRaiseError(
  471.                     "An flexy:if attribute was found in &lt;{$this->element->name} tag without a corresponding &lt;/{$this->element->name}
  472.                         tag on Line {$this->element->line} &lt;{$this->element->tag}&gt;",
  473.                      nullHTML_TEMPLATE_FLEXY_ERROR_DIE);
  474.                 }
  475.         else {
  476.         
  477.             $this->element->close->postfix = array($this->element->factory("End",''$this->element->line));
  478.         }
  479.         $this->element->clearAttribute('FLEXY:IF');
  480.         return $ifObj->compile($this->compiler);
  481.     }
  482.     
  483.      /**
  484.     * Reads Tags - and relays to parseTagXXXXXXX
  485.     *
  486.     *
  487.     * @return   string | false = html output or ignore (just output the tag)
  488.     * @access   private
  489.     */
  490.     
  491.     
  492.     function _parseTags(
  493.     {
  494.         global $_HTML_TEMPLATE_FLEXY_TOKEN;
  495.         // doesnt really need strtolower etc. as php functions are not case sensitive!
  496.         
  497.         if ($this->element->getAttribute('FLEXY:DYNAMIC')) {
  498.             return $this->compiler->appendPhp(
  499.                 $this->getElementPhp$this->element->getAttribute('ID') )
  500.             );
  501.             
  502.         }
  503.             
  504.         if ($this->element->getAttribute('FLEXY:IGNOREONLY'!== false{
  505.             return false;
  506.         }
  507.         if ($_HTML_TEMPLATE_FLEXY_TOKEN['flexyIgnore']{
  508.             return false;
  509.         }
  510.         $tag $this->element->tag;
  511.         if (strpos($tag,':'!== false{
  512.             $bits explode(':',$tag);
  513.             $tag $bits[1];
  514.         }
  515.         
  516.         $method 'parseTag'.$tag;
  517.         if (!method_exists($this,$method)) {
  518.             return false;
  519.         }
  520.         // do any of the attributes use flexy data...
  521.         foreach ($this->element->attributes as $k=>$v{
  522.             if (is_array($v)) {
  523.                 return false;
  524.             }
  525.         }
  526.         
  527.         //echo "call $method" . serialize($this->element->attributes). "\n";
  528.         
  529.         return $this->$method();
  530.             // allow the parse methods to return output.
  531.         
  532.     }
  533.     
  534.  
  535.     
  536.            
  537.     /**
  538.     * produces the code for dynamic elements
  539.     *
  540.     * @return   string | false = html output or ignore (just output the tag)
  541.     * @access   public
  542.     */
  543.         
  544.     function getElementPhp($id,$mergeWithName=false{
  545.         
  546.         global $_HTML_TEMPLATE_FLEXY;
  547.         static $tmpId=0;
  548.         if (!$id{
  549.             return HTML_Template_Flexy::staticRaiseError(
  550.                 "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} &lt;{$this->element->tag}&gt;: " .
  551.                 " Dynamic tags require an ID value",
  552.                 nullHTML_TEMPLATE_FLEXY_ERROR_DIE);
  553.         }
  554.         
  555.         // dont mix and match..
  556.         if (($this->element->getAttribute('FLEXY:IF'!== false|| 
  557.             ($this->element->getAttribute('FLEXY:FOREACH'!== false) )
  558.         {
  559.             return HTML_Template_Flexy::staticRaiseError(
  560.                 "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} &lt;{$this->element->tag}&gt;: " .
  561.                 " You can not mix flexy:if= or flexy:foreach= with dynamic form elements  " . 
  562.                 " (turn off tag to element code with flexyIgnore=0, use flexy:ignore=&quot;yes&quot; in the tag" .
  563.                 " or put the conditional outside in a span tag",
  564.                 null, <a href="../HTML_Template_Flexy/_HTML_Template_Flexy-1.3.13---HTML---Template---Flexy.php.html#defineHTML_TEMPLATE_FLEXY_ERROR_DIE">HTML_TEMPLATE_FLEXY_ERROR_DIE</a>);
  565.         }
  566.         
  567.         if ((strtolower($this->element->getAttribute('type')) == 'checkbox' ) && 
  568.                 (substr($this->element->getAttribute('name'),-2) == '[]')) {
  569.             if ($this->element->getAttribute('id') === false) {
  570.                 $id = 'tmpId'(++$tmpId);
  571.                 $this->element->attributes['id'] = $id;
  572.                 $this->element->ucAttributes['ID'] = $id;
  573.             } 
  574.             $mergeWithName =  true;
  575.         }
  576.         
  577.         
  578.         
  579.         
  580.         
  581.         if (isset($_HTML_TEMPLATE_FLEXY['elements'][$id])) {
  582.            // echo "<PRE>";print_r($this);print_r($_HTML_TEMPLATE_FLEXY['elements']);echo "</PRE>";
  583.             return HTML_Template_Flexy::staticRaiseError(
  584.                 "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} in Tag &lt;{$this->element->tag}&gt;:<BR> " 
  585.                  "The Dynamic tag Name '$id' has already been used previously by  tag &lt;{$_HTML_TEMPLATE_FLEXY['elements'][$id]->tag}&gt;",
  586.                  null,HTML_TEMPLATE_FLEXY_ERROR_DIE);
  587.         }
  588.         
  589.         // this is for a case where you can use a sprintf as the name, and overlay it with a variable element..
  590.         $_HTML_TEMPLATE_FLEXY['elements'][$id] = $this->toElement($this->element);
  591.         
  592.         if ($var = $this->element->getAttribute('FLEXY:NAMEUSES')) {
  593.             
  594.             $var = 'sprintf(\''.$id .'\','.$this->element->toVar($var) .')';
  595.             return  
  596.                 'if (!isset($this->elements['.$var.'])) $this->elements['.$var.']= $this->elements[\''.$id.'\'];
  597.                 $this->elements['.$var.'] = $this->mergeElement($this->elements[\''.$id.'\'],$this->elements['.$var.']);
  598.                 $this->elements['.$var.']->attributes[\'name\'] = '.$var';
  599.                 echo $this->elements['.$var.']->toHtml();'
  600.         } elseif ($mergeWithName) {
  601.             $name = $this->element->getAttribute('NAME');
  602.             return  
  603.                 '$element = $this->elements[\''.$id.'\'];
  604.                 $element = $this->mergeElement($element,$this->elements[\''.$name.'\']);
  605.                 echo  $element->toHtml();'
  606.         
  607.         
  608.         } else {
  609.            return 'echo $this->elements[\''.$id.'\']->toHtml();';
  610.         }
  611.     }
  612.     
  613. /**    
  614.     * Reads an Script tag - check if PHP is allowed.
  615.     *
  616.     * @return   false|PEAR_Error
  617.     * @access   public
  618.     */
  619.     function parseTagScript() {
  620.         
  621.         
  622.         $lang = $this->element->getAttribute('LANGUAGE');
  623.         if (!$lang) {
  624.             return false;
  625.         }
  626.         $lang = strtoupper($lang);
  627.         
  628.         if ($GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['allowPHP']) {
  629.             return false;
  630.         }
  631.         
  632.         if ($lang == "PHP") {
  633.             
  634.             return HTML_Template_Flexy::staticRaiseError('PHP code found in script',
  635.                 <a href="../HTML_Template_Flexy/_HTML_Template_Flexy-1.3.13---HTML---Template---Flexy.php.html#defineHTML_TEMPLATE_FLEXY_ERROR_SYNTAX">HTML_TEMPLATE_FLEXY_ERROR_SYNTAX</a>,<a href="../HTML_Template_Flexy/_HTML_Template_Flexy-1.3.13---HTML---Template---Flexy.php.html#defineHTML_TEMPLATE_FLEXY_ERROR_RETURN">HTML_TEMPLATE_FLEXY_ERROR_RETURN</a>
  636.             );
  637.         }
  638.         return false;
  639.     
  640.     }
  641. /**    
  642.     * Reads an Input tag - build a element object for it
  643.     *
  644.     *
  645.     * @return   string | false = html output or ignore (just output the tag)
  646.     * @access   public
  647.     */
  648.     
  649.   
  650.     function parseTagInput() 
  651.     {
  652.         global $_HTML_TEMPLATE_FLEXY;
  653.         
  654.         if (in_array(strtoupper($this->element->getAttribute('TYPE')), array('SUBMIT','BUTTON','INPUT','')))  {
  655.             $this->compiler->addStringToGettext($this->element->getAttribute('VALUE'));
  656.         }
  657.         // form elements : format:
  658.         //value - fill out as PHP CODE
  659.         
  660.         // as a general rule, this uses name, rather than ID except on 
  661.         // radio
  662.         $mergeWithName = false;
  663.         $id = $this->element->getAttribute('NAME');
  664.         // checkboxes need more work.. - at the momemnt assume one with the same value...
  665.         if (in_array(strtoupper($this->element->getAttribute('TYPE')), array('RADIO'))) {
  666.             
  667.             if (!isset($_HTML_TEMPLATE_FLEXY['elements'][$id])) {
  668.                 // register it..  - so we dont overwrite it...
  669.                 $_HTML_TEMPLATE_FLEXY['elements'][$id] = false;
  670.             } else if ($_HTML_TEMPLATE_FLEXY['elements'][$id] != false) {
  671.                 
  672.            
  673.                 return HTML_Template_Flexy::staticRaiseError(
  674.                     "Error:{$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line".
  675.                     "in Tag &lt;{$this->element->tag}&gt;:<BR>".
  676.                     "The Dynamic tag Name '$id' has already been used previously by ".
  677.                     "tag &lt;{$_HTML_TEMPLATE_FLEXY['elements'][$id]->tag}&gt;",
  678.                      null, HTML_TEMPLATE_FLEXY_ERROR_DIE
  679.                 );
  680.             }
  681.            
  682.             $id = $this->element->getAttribute('ID');
  683.             if (!$id) {
  684.                 return HTML_Template_Flexy::staticRaiseError("Error in {$_HTML_TEMPLATE_FLEXY['filename']} on Line {$this->element->line} &lt;{$this->element->tag}&gt: 
  685.                  Radio Input's require an ID tag..",
  686.                  null, HTML_TEMPLATE_FLEXY_ERROR_DIE);
  687.             }
  688.             $mergeWithName = true;
  689.             
  690.         }
  691.         if (!$id) {
  692.             return false;
  693.         }
  694.         return $this->compiler->appendPhp($this->getElementPhp( $id,$mergeWithName));
  695.  
  696.     }
  697.     
  698.     /**
  699.     * Deal with a TextArea tag - build a element object for it
  700.     *
  701.     * @return   string | false = html output or ignore (just output the tag)
  702.     * @access   public
  703.     */
  704.   
  705.     function parseTagTextArea() 
  706.     {
  707.          
  708.         return $this->compiler->appendPhp(
  709.             $this->getElementPhp( $this->element->getAttribute('NAME')));
  710.             
  711.         
  712.         
  713.     }
  714.     /**
  715.     * Deal with Selects - build a element object for it (unless flexyignore is set)
  716.     *
  717.     *
  718.     * @return   string | false = html output or ignore (just output the tag)
  719.     * @access   public
  720.     */
  721.   
  722.     function parseTagSelect() 
  723.     {
  724.         return $this->compiler->appendPhp(
  725.             $this->getElementPhp( $this->element->getAttribute('NAME')));
  726.     }
  727.       
  728.     
  729.     
  730.     
  731.      /**
  732.     * Reads an Form tag - and set up the element object header etc.
  733.     *    
  734.     * @return   string | false = html output or ignore (just output the tag)
  735.     * @access   public
  736.     */
  737.   
  738.     function parseTagForm() 
  739.     {
  740.         global $_HTML_TEMPLATE_FLEXY;
  741.         $copy = clone($this->element);
  742.         $copy->children = array();
  743.         $id = $this->element->getAttribute('NAME');
  744.         if (!$id) {
  745.             $id = 'form';
  746.         }
  747.         
  748.         // this adds the element to the elements array.
  749.         $old = clone($this->element);
  750.         $this->element = $copy;
  751.         $this->getElementPhp($id);
  752.         $this->element= $old;
  753.         
  754.         
  755.         return 
  756.             $this->compiler->appendPhp('echo $this->elements[\''.$id.'\']->toHtmlnoClose();') .
  757.             $this->element->compileChildren($this->compiler) .
  758.             $this->compiler->appendHtml( "</{$copy->oTag}>");
  759.     
  760.     }       
  761.        
  762.        
  763.         
  764.     
  765.     
  766.     /**
  767.     * reWriteURL - can using the config option 'url_rewrite'
  768.     *  format "from:to,from:to"
  769.     * only handle left rewrite. 
  770.     * so 
  771.     *  "/images:/myroot/images"
  772.     * would change
  773.     *   /images/xyz.gif to /myroot/images/xyz.gif
  774.     *   /images/stylesheet/imagestyles.css to  /myroot/images/stylesheet/imagestyles.css
  775.     *   note /imagestyles did not get altered.
  776.     * will only work on strings (forget about doing /images/{someimage}
  777.     *
  778.     *
  779.     * @param    string attribute to rewrite
  780.     * @return   none
  781.     * @access   public
  782.     */
  783.     function reWriteURL($which) 
  784.     {
  785.         global  $_HTML_TEMPLATE_FLEXY;
  786.         
  787.         
  788.         if (!is_string($original = $this->element->getAttribute($which))) {
  789.             return;
  790.         }
  791.         
  792.         if ($original == '') {
  793.             return;
  794.         }
  795.         
  796.         if (empty($_HTML_TEMPLATE_FLEXY['currentOptions']['url_rewrite'])) {
  797.             return;
  798.         }
  799.         
  800.         $bits = explode(",",$_HTML_TEMPLATE_FLEXY['currentOptions']['url_rewrite']);
  801.         $new = $original;
  802.         
  803.         foreach ($bits as $bit) {
  804.             if (!strlen(trim($bit))) {
  805.                 continue;
  806.             }
  807.             $parts = explode (':', $bit);
  808.             if (!isset($parts[1])) {
  809.                 return HTML_Template_Flexy::staticRaiseError('HTML_Template_Flexy: url_rewrite syntax incorrect'
  810.                     print_r(array($bits,$bits),true),null,<a href="../HTML_Template_Flexy/_HTML_Template_Flexy-1.3.13---HTML---Template---Flexy.php.html#defineHTML_TEMPLATE_FLEXY_ERROR_DIE">HTML_TEMPLATE_FLEXY_ERROR_DIE</a>);
  811.             }
  812.             $new = preg_replace('#^'.$parts[0].'#',$parts[1], $new);
  813.         }
  814.         
  815.         
  816.         if ($original == $new) {
  817.             return;
  818.         }
  819.         $this->element->ucAttributes[$which] = '"'$new . '"';
  820.     } 
  821.     
  822.     /**
  823.     * Convert flexy tokens to HTML_Template_Flexy_Elements.
  824.     *
  825.     * @param    object token to convert into a element.
  826.     * @return   object HTML_Template_Flexy_Element
  827.     * @access   public
  828.     */
  829.     function toElement($element) {
  830.         require_once 'HTML/Template/Flexy/Element.php';
  831.         $ret = new HTML_Template_Flexy_Element;
  832.         
  833.         if (strtolower(get_class($element)) != 'html_template_flexy_token_tag') {
  834.             $this->compiler->addStringToGettext($element->value);
  835.             return $element->value;
  836.         }
  837.         
  838.         
  839.         $ret->tag = strtolower($element->tag);
  840.         
  841.         $ats = $element->getAttributes();
  842.         
  843.         if (isset($element->attributes['flexy:xhtml'])) {
  844.             $ats['flexy:xhtml'] = true;
  845.         }
  846.         
  847.         foreach(array_keys($ats)  as $a) { 
  848.             $ret->attributes[$a] = $this->unHtmlEntities($ats[$a]);
  849.         }
  850.         //print_r($ats);
  851.         if (!$element->children) {
  852.             return $ret;
  853.         }
  854.         
  855.         // children - normally to deal with <element>
  856.         
  857.         //print_r($this->children);
  858.         foreach(array_keys($element->children) as $i) {
  859.             // not quite sure why this happens - but it does.
  860.             if (!is_object($element->children[$i])) {
  861.                 continue;
  862.             }
  863.             $ret->children[] = $this->toElement($element->children[$i]);
  864.         }
  865.         return $ret;
  866.     }
  867.         
  868.       /**
  869.     * do the reverse of htmlspecialchars on an attribute..
  870.     *
  871.     * copied from get-html-translation-table man page 
  872.     * 
  873.     * @param   mixed       from attribute values
  874.     *
  875.     * @return   string          return 
  876.     * @access   public
  877.     * @see      see also methods.....
  878.     */
  879.   
  880.     function unHtmlEntities ($in)  
  881.     {
  882.         if (!is_string($in)) {
  883.             return $in;
  884.         }
  885.         $trans_tbl = get_html_translation_table (HTML_ENTITIES);
  886.         $trans_tbl = array_flip ($trans_tbl);
  887.         $ret = strtr ($in, $trans_tbl);
  888.         return preg_replace('/&#(\d+);/me', "chr('\\1')",$ret);
  889.     }
  890.  

Documentation generated on Mon, 11 Mar 2019 15:59:59 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.