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

Source for file Flexy.php

Documentation is available at Flexy.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.com>                            |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Flexy.php 334846 2014-09-12 04:50:56Z alan_k $
  20. //
  21. //  Base Compiler Class
  22. //  Standard 'Original Flavour' Flexy compiler
  23.  
  24. // this does the main conversion, (eg. for {vars and methods}) 
  25. // it relays into Compiler/Tag & Compiler/Flexy for tags and namespace handling.
  26.  
  27.  
  28.  
  29.  
  30. require_once 'HTML/Template/Flexy/Tokenizer.php';
  31. require_once 'HTML/Template/Flexy/Token.php';
  32.  
  33. class HTML_Template_Flexy_Compiler_Flexy extends HTML_Template_Flexy_Compiler {
  34.     
  35.     /**
  36.      * reference to calling controller
  37.      *
  38.      * @var $flexy HTML_Template_Flexy
  39.      * @access public
  40.      */
  41.     var $flexy;
  42.     
  43.     
  44.         
  45.     /**
  46.     * The current template (Full path)
  47.     *
  48.     * @var string 
  49.     * @access public
  50.     */
  51.     var $currentTemplate;
  52.     
  53.     /**
  54.      * when using flexy::contents - this contains the map of
  55.      * <... flexy:conntents="KEY">.....VALUE ...<...>
  56.      * 
  57.      */
  58.     var $contentStrings = array();
  59.     
  60.     /**
  61.     * The compile method.
  62.     * 
  63.     * @params   object HTML_Template_Flexy
  64.     * @params   string|false string to compile of false to use a file.
  65.     * @return   string   filename of template
  66.     * @access   public
  67.     */
  68.     function compile($flexy$string=false
  69.     {
  70.         // read the entire file into one variable
  71.         
  72.         // note this should be moved to new HTML_Template_Flexy_Token
  73.         // and that can then manage all the tokens in one place..
  74.         global $_HTML_TEMPLATE_FLEXY_COMPILER;
  75.         
  76.         $this->flexy $flexy;
  77.         
  78.         $this->currentTemplate  $flexy->currentTemplate;
  79.         
  80.         $gettextStrings &$_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'];
  81.         $gettextStrings = array()// reset it.
  82.         
  83.         if (@$this->options['debug']{
  84.             echo "compiling template $flexy->currentTemplate<BR>";
  85.             
  86.         }
  87.          
  88.         // reset the elements.
  89.         $flexy->_elements = array();
  90.         
  91.         // replace this with a singleton??
  92.         
  93.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']  $this->options;
  94.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements']        = array();
  95.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename']        $flexy->currentTemplate;
  96.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput']    '';
  97.         $GLOBALS['_HTML_TEMPLATE_FLEXY']['compiledTemplate']$flexy->compiledTemplate;
  98.         
  99.         
  100.         // initialize Translation 2, and 
  101.         $this->flexy->initializeTranslator();
  102.         
  103.         
  104.         // load the template!
  105.         $data $string;
  106.         $res = false;
  107.         if ($string === false{
  108.             $data file_get_contents($flexy->currentTemplate);
  109.         }
  110.          
  111.         // PRE PROCESS {_(.....)} translation markers.
  112.         if (strpos($data'{_('!== false{
  113.             $data $this->preProcessTranslation($data);
  114.         }
  115.         
  116.         // Tree generation!!!
  117.         
  118.         
  119.         
  120.         if (!$this->options['forceCompile'&& isset($_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)])) {
  121.             $res $_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)];
  122.         else {
  123.         
  124.              
  125.             $tokenizer = new HTML_Template_Flexy_Tokenizer($data);
  126.             $tokenizer->fileName = $flexy->currentTemplate;
  127.             
  128.             
  129.               
  130.             //$tokenizer->debug=1;
  131.             $tokenizer->options['ignore_html'$this->options['nonHTML'];
  132.             
  133.           
  134.             require_once 'HTML/Template/Flexy/Token.php';
  135.             $res = HTML_Template_Flexy_Token::buildTokens($tokenizer);
  136.             if ($this->is_a($res'PEAR_Error')) {
  137.                 return $res;
  138.             }       
  139.             $_HTML_TEMPLATE_FLEXY_COMPILER['cache'][md5($data)$res;
  140.             
  141.         }
  142.         
  143.         
  144.         // technically we shouldnt get here as we dont cache errors..
  145.         if ($this->is_a($res'PEAR_Error')) {
  146.             return $res;
  147.         }
  148.         
  149.         // turn tokens into Template..
  150.         
  151.         $data $res->compile($this);
  152.         
  153.         if ($this->is_a($data'PEAR_Error')) {
  154.             return $data;
  155.         }
  156.         
  157.         $data $GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput'$data;
  158.         
  159.         if (   $flexy->options['debug'> 1{
  160.             echo "<B>Result: </B><PRE>".htmlspecialchars($data)."</PRE><BR>\n";
  161.         }
  162.  
  163.         if ($this->options['nonHTML']{
  164.            $data =  str_replace("?>\n""?>\n\n"$data);
  165.         }
  166.         
  167.          
  168.         
  169.         
  170.         // at this point we are into writing stuff...
  171.         if ($flexy->options['compileToString']{
  172.             if (   $flexy->options['debug']{
  173.                 echo "<B>Returning string:<BR>\n";
  174.             }
  175.  
  176.             $flexy->elements =  $GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'];
  177.             return $data;
  178.         }
  179.         
  180.         
  181.         
  182.         
  183.         // error checking?
  184.         $file  $flexy->compiledTemplate;
  185.         if (isset($flexy->options['output.block'])) {
  186.             list($file$partexplode('#'$file);
  187.         }
  188.         
  189.         if( ($cfp fopen($file'w')) ) {
  190.             if ($flexy->options['debug']{
  191.                 echo "<B>Writing: </B>$file<BR>\n";
  192.             }
  193.             fwrite($cfp$data);
  194.             fclose($cfp);
  195.             
  196.             chmod($file0775);
  197.             // make the timestamp of the two items match.
  198.             clearstatcache();
  199.             touch($filefilemtime($flexy->currentTemplate));
  200.             if ($file != $flexy->compiledTemplate{
  201.                 chmod($flexy->compiledTemplate0775);
  202.                 // make the timestamp of the two items match.
  203.                 clearstatcache();
  204.                 touch($flexy->compiledTemplatefilemtime($flexy->currentTemplate));
  205.             }
  206.              
  207.             
  208.         else {
  209.             return HTML_Template_Flexy::staticRaiseError('HTML_Template_Flexy::failed to write to '.$flexy->compiledTemplate,
  210.         }
  211.         // gettext strings
  212.          
  213.         if (file_exists($flexy->getTextStringsFile)) {
  214.             unlink($flexy->getTextStringsFile);
  215.         }
  216.  
  217.         if($gettextStrings && ($cfp fopen$flexy->getTextStringsFile'w') ) ) {
  218.             
  219.             fwrite($cfpserialize(array_unique($gettextStrings)));
  220.             fclose($cfp);
  221.             chmod($flexy->getTextStringsFile0664);
  222.         }
  223.         
  224.         // elements
  225.         if (file_exists($flexy->elementsFile)) {
  226.             unlink($flexy->elementsFile);
  227.         }
  228.         
  229.         if$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements'&&
  230.             ($cfp fopen$flexy->elementsFile'w') ) ) {
  231.             fwrite($cfpserialize$GLOBALS['_HTML_TEMPLATE_FLEXY']['elements']));
  232.             fclose($cfp);
  233.             chmod($flexy->elementsFile0664);
  234.             // now clear it.
  235.         
  236.         }
  237.         
  238.         return true;
  239.     }
  240.     
  241.     
  242.     
  243.     
  244.     
  245.     
  246.     /**
  247.     * do the early tranlsation of {_(......)_} text
  248.     *
  249.     * 
  250.     * @param    input string
  251.     * @return   output string
  252.     * @access   public
  253.     */
  254.     function preProcessTranslation($data{
  255.         global $_HTML_TEMPLATE_FLEXY_COMPILER;
  256.         $matches = array();
  257.         $lmatches explode ('{_('$data);
  258.         array_shift($lmatches);
  259.         // shift the first..
  260.         foreach ($lmatches as $k{
  261.             if (false === strpos($k')_}')) {
  262.                 continue;
  263.             }
  264.             $x explode(')_}'$k);
  265.             $matches[$x[0];
  266.         }
  267.     
  268.     
  269.        //echo '<PRE>';print_r($matches);
  270.         // we may need to do some house cleaning here...
  271.         $_HTML_TEMPLATE_FLEXY_COMPILER['gettextStrings'$matches;
  272.         
  273.         
  274.         // replace them now..  
  275.         // ** leaving in the tag (which should be ignored by the parser..
  276.         // we then get rid of the tags during the toString method in this class.
  277.         foreach($matches as $v{
  278.             $data str_replace('{_('.$v.')_}''{_('.$this->flexy->translateString($v).')_}'$data);
  279.         }
  280.         return $data;
  281.     }    
  282.  
  283.     
  284.     
  285.     
  286.     
  287.     /**
  288.     * Flag indicating compiler is inside {_( .... )_} block, and should not
  289.     * add to the gettextstrings array.
  290.     *
  291.     * @var boolean 
  292.     * @access public
  293.     */
  294.     var $inGetTextBlock = false;
  295.     
  296.     /**
  297.     * This is the base toString Method, it relays into toString{TokenName}
  298.     *
  299.     * @param    object    HTML_Template_Flexy_Token_* 
  300.     * 
  301.     * @return   string     string to build a template
  302.     * @access   public
  303.     * @see      toString*
  304.     */
  305.   
  306.  
  307.     function toString($element
  308.     {
  309.         static $len = 26; // strlen('HTML_Template_Flexy_Token_');
  310.         if ($this->options['debug'> 1{
  311.             $x $element;
  312.             unset($x->children);
  313.             //echo htmlspecialchars(print_r($x,true))."<BR>\n";
  314.         }
  315.         if ($element->token == 'GetTextStart'{
  316.             $this->inGetTextBlock = true;
  317.             return '';
  318.         }
  319.         if ($element->token == 'GetTextEnd'{
  320.             $this->inGetTextBlock = false;
  321.             return '';
  322.         }
  323.         
  324.             
  325.         $class get_class($element);
  326.         if (strlen($class>= $len{
  327.             $type substr($class$len);
  328.             return $this->{'toString'.$type}($element);
  329.         }
  330.         
  331.         $ret $element->value;
  332.         $add $element->compileChildren($this);
  333.         if ($this->is_a($add'PEAR_Error')) {
  334.             return $add;
  335.         }
  336.         $ret .= $add;
  337.         
  338.         if ($element->close{
  339.             $add $element->close->compile($this);
  340.             if ($this->is_a($add'PEAR_Error')) {
  341.                 return $add;
  342.             }
  343.             $ret .= $add;
  344.         }
  345.         
  346.         return $ret;
  347.     }
  348.  
  349.  
  350.     /**
  351.     *   HTML_Template_Flexy_Token_Else toString
  352.     *
  353.     * @param    object    HTML_Template_Flexy_Token_Else 
  354.     * 
  355.     * @return   string     string to build a template
  356.     * @access   public
  357.     * @see      toString*
  358.     */
  359.   
  360.  
  361.     function toStringElse($element
  362.      {
  363.         // pushpull states to make sure we are in an area.. - should really check to see 
  364.         // if the state it is pulling is a if...
  365.         if ($element->pullState(=== false{
  366.             return $this->appendHTML(
  367.                 "<font color=\"red\">Unmatched {else:} on line: {$element->line}</font>"
  368.                 );
  369.         }
  370.         $element->pushState();
  371.         return $this->appendPhp("} else {");
  372.     }
  373.     
  374.     /**
  375.     *   HTML_Template_Flexy_Token_End toString
  376.     *
  377.     * @param    object    HTML_Template_Flexy_Token_Else 
  378.     * 
  379.     * @return   string     string to build a template
  380.     * @access   public
  381.     * @see      toString*
  382.     */
  383.   
  384.     function toStringEnd($element
  385.     {
  386.         // pushpull states to make sure we are in an area.. - should really check to see 
  387.         // if the state it is pulling is a if...
  388.         if ($element->pullState(=== false{
  389.             return $this->appendHTML(
  390.                 "<font color=\"red\">Unmatched {end:} on line: {$element->line}</font>"
  391.                 );
  392.         }
  393.          
  394.         return $this->appendPhp("}");
  395.     }
  396.  
  397.     /**
  398.     *   HTML_Template_Flexy_Token_EndTag toString
  399.     *
  400.     * @param    object    HTML_Template_Flexy_Token_EndTag 
  401.     * 
  402.     * @return   string     string to build a template
  403.     * @access   public
  404.     * @see      toString*
  405.     */
  406.   
  407.  
  408.  
  409.     function toStringEndTag($element
  410.     {
  411.         return $this->toStringTag($element);
  412.     }
  413.         
  414.     
  415.     
  416.     /**
  417.     *   HTML_Template_Flexy_Token_Foreach toString
  418.     *
  419.     * @param    object    HTML_Template_Flexy_Token_Foreach 
  420.     * 
  421.     * @return   string     string to build a template
  422.     * @access   public
  423.     * @see      toString*
  424.     */
  425.   
  426.     
  427.     function toStringForeach($element
  428.     {
  429.     
  430.         $loopon $element->toVar($element->loopOn);
  431.         if ($this->is_a($loopon'PEAR_Error')) {
  432.             return $loopon;
  433.         }
  434.         
  435.         $ret 'if ($this->options[\'strict\'] || ('.
  436.             'is_array('$loopon')  || ' .
  437.             'is_object(' $loopon  '))) ' .
  438.             'foreach(' $loopon  " ";
  439.             
  440.         $ret .= "as \${$element->key}";
  441.         
  442.         if ($element->value{
  443.             $ret .=  " => \${$element->value}";
  444.         }
  445.         $ret .= ") {";
  446.         
  447.         $element->pushState();
  448.         $element->pushVar($element->key);
  449.         $element->pushVar($element->value);
  450.         return $this->appendPhp($ret);
  451.     }
  452.     /**
  453.     *   HTML_Template_Flexy_Token_If toString
  454.     *
  455.     * @param    object    HTML_Template_Flexy_Token_If 
  456.     * 
  457.     * @return   string     string to build a template
  458.     * @access   public
  459.     * @see      toString*
  460.     */
  461.   
  462.     function toStringIf($element
  463.     {
  464.         
  465.         $var $element->toVar($element->condition);
  466.         if ($this->is_a($var'PEAR_Error')) {
  467.             return $var;
  468.         }
  469.         
  470.         $ret "if (".$element->isNegative . $var .")  {";
  471.         $element->pushState();
  472.         return $this->appendPhp($ret);
  473.     }
  474.  
  475.    /**
  476.     *  get Modifier Wrapper
  477.     *
  478.     * converts :h, :u, :r , .....
  479.     * @param    object    HTML_Template_Flexy_Token_Method|Var
  480.     * 
  481.     * @return   array prefix,suffix
  482.     * @access   public
  483.     * @see      toString*
  484.     */
  485.  
  486.     function getModifierWrapper($element
  487.     {
  488.         $prefix 'echo ';
  489.         
  490.         $suffix '';
  491.         $modifier strlen(trim($element->modifier)) $element->modifier : ' ';
  492.         
  493.         switch ($modifier{
  494.             case 'h':
  495.                 break;
  496.             case 'u':
  497.                 $prefix 'echo urlencode(';
  498.                 $suffix ')';
  499.                 break;
  500.             case 'r':
  501.                 $prefix 'echo \'<pre>\'; echo htmlspecialchars(print_r(';
  502.                 $suffix ',true)); echo \'</pre>\';';
  503.                 break;                
  504.             case 'n'
  505.                 // blank or value..
  506.                 $numberformat @$GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'];
  507.                 $prefix 'echo number_format(';
  508.                 $suffix $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['numberFormat'')';
  509.                 break;
  510.             case 'b'// nl2br + htmlspecialchars
  511.                 $prefix 'echo nl2br(htmlspecialchars(';
  512.                 
  513.                 // add language ?
  514.                 $suffix '))';
  515.                 break;
  516.             case 'e':
  517.                 $prefix 'echo htmlentities(';
  518.                 // add language ?
  519.                 $suffix ')';
  520.                 break;
  521.              
  522.             case ' ':
  523.                 $prefix 'echo htmlspecialchars(';
  524.                 // add language ?
  525.                 $suffix ')';
  526.                 break;
  527.             default:
  528.                $prefix 'echo $this->plugin("'.trim($element->modifier.'",';
  529.                $suffix ')'
  530.             
  531.             
  532.         }
  533.         
  534.         return array($prefix$suffix);
  535.     }
  536.  
  537.  
  538.  
  539.   /**
  540.     *   HTML_Template_Flexy_Token_Var toString
  541.     *
  542.     * @param    object    HTML_Template_Flexy_Token_Method 
  543.     * 
  544.     * @return   string     string to build a template
  545.     * @access   public
  546.     * @see      toString*
  547.     */
  548.   
  549.     function toStringVar($element
  550.     {
  551.         // ignore modifier at present!!
  552.         
  553.         $var $element->toVar($element->value);
  554.         if ($this->is_a($var'PEAR_Error')) {
  555.             return $var;
  556.         }
  557.         list($prefix$suffix$this->getModifierWrapper($element);
  558.         return $this->appendPhp$prefix $var $suffix .';');
  559.     }
  560.    /**
  561.     *   HTML_Template_Flexy_Token_Method toString
  562.     *
  563.     * @param    object    HTML_Template_Flexy_Token_Method 
  564.     * 
  565.     * @return   string     string to build a template
  566.     * @access   public
  567.     * @see      toString*
  568.     */
  569.   
  570.     function toStringMethod($element
  571.     {
  572.  
  573.               
  574.         // set up the modifier at present!!
  575.          
  576.         list($prefix$suffix$this->getModifierWrapper($element);
  577.         
  578.         // add the '!' to if
  579.         
  580.         if ($element->isConditional{
  581.             $prefix 'if ('.$element->isNegative;
  582.             $element->pushState();
  583.             $suffix ')';
  584.         }  
  585.         
  586.         
  587.         // check that method exists..
  588.         // if (method_exists($object,'method');
  589.         $bits explode('.'$element->method);
  590.         $method array_pop($bits);
  591.         
  592.         $object implode('.'$bits);
  593.         
  594.         $var $element->toVar($object);
  595.         if ($this->is_a($var'PEAR_Error')) {
  596.             return $var;
  597.         }
  598.         
  599.         if (($object == 'GLOBALS'&& 
  600.             $GLOBALS['_HTML_TEMPLATE_FLEXY']['currentOptions']['globalfunctions']{
  601.             // we should check if they something weird like: GLOBALS.xxxx[sdf](....)
  602.             $var $method;
  603.         else {
  604.             $prefix 'if ($this->options[\'strict\'] || (isset('.$var.
  605.                 ') && method_exists('.$var .", '{$method}'))) " . $prefix;
  606.             $var $element->toVar($element->method);
  607.         }
  608.         
  609.  
  610.         if ($this->is_a($var'PEAR_Error')) {
  611.             return $var;
  612.         }
  613.         
  614.         $ret  =  $prefix;
  615.         $ret .=  $var "(";
  616.         $s =0;
  617.          
  618.        
  619.          
  620.         foreach($element->args as $a{
  621.              
  622.             if ($s{
  623.                 $ret .= ",";
  624.             }
  625.             $s =1;
  626.             if ($a{0== '#'{
  627.                 if (is_numeric(substr($a1-1))) {
  628.                     $ret .= substr($a1-1);
  629.                 else {
  630.                     $ret .= '"'addslashes(substr($a1-1)) '"';
  631.                 }
  632.                 continue;
  633.             }
  634.             
  635.             $var $element->toVar($a);
  636.             if ($this->is_a($var'PEAR_Error')) {
  637.                 return $var;
  638.             }
  639.             $ret .= $var;
  640.             
  641.         }
  642.         $ret .= ")" $suffix;
  643.         
  644.         if ($element->isConditional{
  645.             $ret .= ' { ';
  646.         else {
  647.             $ret .= ";";
  648.         }
  649.         
  650.         
  651.         
  652.         return $this->appendPhp($ret)
  653.         
  654.          
  655.  
  656.    }
  657.    /**
  658.     *   HTML_Template_Flexy_Token_Processing toString
  659.     *
  660.     * @param    object    HTML_Template_Flexy_Token_Processing 
  661.     * 
  662.     * @return   string     string to build a template
  663.     * @access   public
  664.     * @see      toString*
  665.     */
  666.  
  667.  
  668.     function toStringProcessing($element
  669.     {
  670.         // if it's XML then quote it..
  671.         if (strtoupper(substr($element->value23)) == 'XML'
  672.             return $this->appendPhp("echo '" str_replace("'""\\"."'"$element->value"';");
  673.         }
  674.         // otherwise it's PHP code - so echo it..
  675.         return $element->value;
  676.     }
  677.     
  678.     /**
  679.     *   HTML_Template_Flexy_Token_Text toString
  680.     *
  681.     * @param    object    HTML_Template_Flexy_Token_Text 
  682.     * 
  683.     * @return   string     string to build a template
  684.     * @access   public
  685.     * @see      toString*
  686.     */
  687.  
  688.  
  689.  
  690.     function toStringText($element
  691.     {
  692.         
  693.         // first get rid of stuff thats not translated etc.
  694.         // empty strings => output.
  695.         // comments -> just output
  696.         // our special tags -> output..
  697.         
  698.         if (!strlen(trim($element->value) )) {
  699.             return $this->appendHtml($element->value);
  700.         }
  701.         // dont add comments to translation lists.
  702.          
  703.         if (substr($element->value04== '<!--'{
  704.             return $this->appendHtml($element->value);
  705.         }
  706.         // ignore anything wrapped with {_( .... )_}
  707.         if ($this->inGetTextBlock{
  708.             return $this->appendHtml($element->value);
  709.         }
  710.         
  711.         
  712.         if (!$element->isWord()) {
  713.             return $this->appendHtml($element->value);
  714.         }
  715.         
  716.         // grab the white space at start and end (and keep it!
  717.         
  718.         $value ltrim($element->value);
  719.         $front substr($element->value0-strlen($value));
  720.         $value rtrim($element->value);
  721.         $rear  substr($element->valuestrlen($value));
  722.         $value trim($element->value);
  723.         
  724.         
  725.         // convert to escaped chars.. (limited..)
  726.         //$value = strtr($value,$cleanArray);
  727.         
  728.         // this only applies to html templates
  729.         if (empty($this->flexy->options['nonHTML'])) {
  730.             $this->addStringToGettext($value);
  731.             $value $this->flexy->translateString($value);
  732.         }
  733.         // its a simple word!
  734.         return $this->appendHtml($front $value $rear);
  735.         
  736.     }
  737.     
  738.     
  739.     
  740.       /**
  741.     *   HTML_Template_Flexy_Token_Cdata toString
  742.     *
  743.     * @param    object    HTML_Template_Flexy_Token_Cdata ?
  744.     * 
  745.     * @return   string     string to build a template
  746.     * @access   public
  747.     * @see      toString*
  748.     */
  749.  
  750.  
  751.  
  752.     function toStringCdata($element
  753.     {
  754.         return $this->appendHtml($element->value);
  755.     }
  756.     
  757.     
  758.     
  759.     
  760.     
  761.     
  762.     
  763.     
  764.     
  765.     
  766.     /**
  767.     * addStringToGettext
  768.     *
  769.     * Adds a string to the gettext array.
  770.     * 
  771.     * @param   mixed        preferably.. string to store
  772.     *
  773.     * @return   none 
  774.     * @access   public
  775.     */
  776.     
  777.     function addStringToGettext($string
  778.     {
  779.         if (!empty($this->options['disableTranslate'])) {
  780.             return;
  781.         }
  782.         if (!is_string($string)) {
  783.             return;
  784.         }
  785.         
  786.         if (!preg_match('/\w+/i'$string)) {
  787.             return;
  788.         }
  789.         $string trim($string);
  790.         
  791.         if (substr($string04== '<!--'{
  792.             return;
  793.         }
  794.         
  795.         $GLOBALS['_HTML_TEMPLATE_FLEXY_COMPILER']['gettextStrings'][$string;
  796.     }
  797.     
  798.     
  799.     
  800.      /**
  801.     *   HTML_Template_Flexy_Token_Tag toString
  802.     *
  803.     * @param    object    HTML_Template_Flexy_Token_Tag 
  804.     * 
  805.     * @return   string     string to build a template
  806.     * @access   public
  807.     * @see      toString*
  808.     */
  809.   
  810.     function toStringTag($element{
  811.         
  812.         $original $element->getAttribute('ALT');
  813.         // techncially only input type=(submit|button|input) alt=.. applies, but we may 
  814.         // as well translate any occurance...
  815.         if ( (($element->tag == 'IMG'|| ($element->tag == 'INPUT'))
  816.                 && is_string($original&& strlen($original)) {
  817.             $this->addStringToGettext($original);
  818.             $quote $element->ucAttributes['ALT']{0};
  819.             $element->ucAttributes['ALT'$quote  $this->flexy->translateString($original)$quote;
  820.         }
  821.         $original $element->getAttribute('TITLE');
  822.         if (is_string($original&& strlen($original)) {
  823.             $this->addStringToGettext($original);
  824.             $quote $element->ucAttributes['TITLE']{0};
  825.             $element->ucAttributes['TITLE'$quote  $this->flexy->translateString($original)$quote;
  826.         }
  827.         
  828.         
  829.         if (strpos($element->tag':'=== false{
  830.             $namespace 'Tag';
  831.         else {
  832.             $bits =  explode(':'$element->tag);
  833.             $namespace $bits[0];
  834.         }
  835.         if ($namespace{0== '/'{
  836.             $namespace substr($namespace1);
  837.         }
  838.         if (empty($this->tagHandlers[$namespace])) {
  839.             
  840.             require_once 'HTML/Template/Flexy/Compiler/Flexy/Tag.php';
  841.             $this->tagHandlers[$namespace&HTML_Template_Flexy_Compiler_Flexy_Tag::factory($namespace$this);
  842.             if (!$this->tagHandlers[$namespace{
  843.                 return HTML_Template_Flexy::staticRaiseError('HTML_Template_Flexy::failed to create Namespace Handler '.$namespace 
  844.                     ' in file ' $GLOBALS['_HTML_TEMPLATE_FLEXY']['filename'],
  845.                     HTML_TEMPLATE_FLEXY_ERROR_SYNTAXHTML_TEMPLATE_FLEXY_ERROR_RETURN);
  846.             }
  847.                 
  848.         }
  849.         return $this->tagHandlers[$namespace]->toString($element);
  850.         
  851.         
  852.     }
  853.      /**
  854.      * PHP5 compat - arg...
  855.      * - where else does this affect
  856.      */
  857.     function classExists($class)
  858.     {
  859.         return (substr(phpversion(),0,1< 5class_exists($class:  class_exists($class,false);
  860.     }
  861.  
  862.  
  863. }

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