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-2003 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@akkbhome.com>                           |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Flexy.php 334846 2014-09-12 04:50:56Z alan_k $
  20. //
  21. //  Handler code for the <flexy: namespace
  22. //
  23.  
  24. /**
  25. * the <flexy:XXXX namespace
  26. * at present it handles
  27. *       <flexy:toJavascript flexy:prefix="Javascript_prefix"  javscriptName="PHPvar" .....>
  28. *       <flexy:include src="xxx.htm">
  29. *
  30. *
  31. *
  32. @version    $Id: Flexy.php 334846 2014-09-12 04:50:56Z alan_k $
  33. */
  34.  
  35. class HTML_Template_Flexy_Compiler_Standard_Flexy  {
  36.  
  37.         
  38.     /**
  39.     * Parent Compiler for
  40.     *
  41.     * @var  object  HTML_Template_Flexy_Compiler 
  42.     * 
  43.     * @access public
  44.     */
  45.     var $compiler;
  46.  
  47.    
  48.     /**
  49.     * The current element to parse..
  50.     *
  51.     * @var object 
  52.     * @access public
  53.     */    
  54.     var $element;
  55.     
  56.     
  57.     
  58.     
  59.     
  60.     /**
  61.     * toString - display tag, attributes, postfix and any code in attributes.
  62.     * Relays into namspace::method to get results..
  63.     *
  64.     * 
  65.     * @see parent::toString()
  66.     */
  67.     function toString($element
  68.     {
  69.         
  70.         list($namespace,$methodexplode(':',$element->oTag);
  71.         if (!strlen($method)) {
  72.             return '';
  73.         }
  74.         // things we dont handle...
  75.         if (!method_exists($this,$method.'ToString')) {
  76.             return '';
  77.         }
  78.         return $this->{$method.'ToString'}($element);
  79.         
  80.     }
  81.    /**
  82.     * toJavascript handler
  83.     * <flexy:toJavascript flexy:prefix="some_prefix_"  javascriptval="php.val" ....>
  84.     * 
  85.     * @see parent::toString()
  86.     */
  87.     
  88.     function toJavascriptToString($element
  89.     {
  90.         $ret $this->compiler->appendPhp"require_once 'HTML/Javascript/Convert.php';");
  91.         $ret .= $this->compiler->appendHTML("\n<script type='text/javascript'>\n");
  92.         $prefix ''$element->getAttribute('FLEXY:PREFIX');
  93.         
  94.         
  95.         foreach ($element->attributes as $k=>$v{
  96.             // skip directives..
  97.             if (strpos($k,':')) {
  98.                 continue;
  99.             }
  100.             if ($k == '/'{
  101.                 continue;
  102.             }
  103.             $v substr($v,1,-1);
  104.             $ret .= $this->compiler->appendPhp(
  105.                 '$__tmp = HTML_Javascript_Convert::convertVar('.$element->toVar($v.',\''.$prefix $k.'\',true);'.
  106.                 'echo (is_object($__tmp) && is_a($__tmp,"PEAR_Error")) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;');
  107.             $ret .= $this->compiler->appendHTML("\n");
  108.         }
  109.         $ret .= $this->compiler->appendHTML("</script>");
  110.         return $ret;
  111.     }
  112.     /**
  113.     * include handler
  114.     * <flexy:include src="test.html">
  115.     * 
  116.     * @see parent::toString()
  117.     */
  118.     function includeToString($element
  119.     {
  120.         // this is disabled by default...
  121.         // we ignore modifier pre/suffix
  122.     
  123.     
  124.     
  125.        
  126.         $arg $element->getAttribute('SRC');
  127.         if (!$arg{
  128.             return $this->compiler->appendHTML("<B>Flexy:Include without a src=filename</B>");
  129.         }
  130.         // ideally it would be nice to embed the results of one template into another.
  131.         // however that would involve some complex test which would have to stat
  132.         // the child templates anyway..
  133.         // compile the child template....
  134.         // output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php'
  135.         return $this->compiler->appendPHP"\n".
  136.                 "\$x = new HTML_Template_Flexy(\$this->options);\n".
  137.                 "\$x->compile('{$arg}');\n".
  138.                 "\$x->outputObject(\$t);\n"
  139.             );
  140.     
  141.     }
  142.     
  143.     /**
  144.     * Convert flexy tokens to HTML_Template_Flexy_Elements.
  145.     *
  146.     * @param    object token to convert into a element.
  147.     * @return   object HTML_Template_Flexy_Element 
  148.     * @access   public
  149.     */
  150.     function toElement($element
  151.     {
  152.        return '';
  153.     }
  154.         
  155.     
  156.     /**
  157.     * Handler for User defined functions in templates..
  158.     * <flexy:function name="xxxxx">.... </flexy:block>  // equivilant to function xxxxx() {
  159.     * <flexy:function call="{xxxxx}">.... </flexy:block>  // equivilant to function {$xxxxx}() {
  160.     * <flexy:function call="xxxxx">.... </flexy:block>  // equivilant to function {$xxxxx}() {
  161.     * 
  162.     * This will not handle nested blocks initially!! (and may cause even more problems with
  163.     * if /foreach stuff..!!
  164.     *
  165.     * @param    object token to convert into a element.
  166.     * @access   public
  167.     */
  168.   
  169.     
  170.     function functionToString($element
  171.     {
  172.         
  173.         if ($arg $element->getAttribute('NAME')) {
  174.             // this is a really kludgy way of doing this!!!
  175.             // hopefully the new Template Package will have a sweeter method..
  176.             $GLOBALS['_HTML_TEMPLATE_FLEXY']['prefixOutput']  .= 
  177.                 $this->compiler->appendPHP
  178.                     "\nfunction _html_template_flexy_compiler_standard_flexy_{$arg}(\$t,\$this) {\n").
  179.                 $element->compileChildren($this->compiler.
  180.                 $this->compiler->appendPHP"\n}\n");
  181.                 
  182.                 return '';
  183.         }
  184.         if (!isset($element->ucAttributes['CALL'])) {
  185.             
  186.             return HTML_Template_Flexy::staticRaiseError(
  187.                 ' tag flexy:function needs an argument call or name'.
  188.                 " Error on Line {$element->line} &lt;{$element->tag}&gt;",
  189.                          null,   HTML_TEMPLATE_FLEXY_ERROR_DIE);
  190.         }
  191.         // call is a  stirng : nice and simple..
  192.         if (is_string($element->ucAttributes['CALL'])) {
  193.             $arg = $element->getAttribute('CALL');
  194.             return $this->compiler->appendPHP
  195.                     "if (function_exists('_html_template_flexy_compiler_standard_flexy_'.{$arg})) " .
  196.                     " _html_template_flexy_compiler_standard_flexy_{$arg}(\$t,\$this);");
  197.         }
  198.         
  199.         // we make a big assumption here.. - it should really be error checked..
  200.         // that the {xxx} element is item 1 in the list... 
  201.         $e=$element->ucAttributes['CALL'][1];
  202.         $add $e->toVar($e->value);
  203.         if (is_object($add&& is_a($add,'PEAR_Error')) {
  204.             return $add;
  205.         } 
  206.         return $this->compiler->appendPHP(
  207.             "if (function_exists('_html_template_flexy_compiler_standard_flexy_'.{$add})) ".
  208.             "call_user_func_array('_html_template_flexy_compiler_standard_flexy_'.{$add},array(\$t,\$this));");
  209.         
  210.         
  211.         
  212.     }
  213.  

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