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,v 1.12 2004/04/02 06:37:49 alan_k Exp $
  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,v 1.12 2004/04/02 06:37:49 alan_k Exp $
  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.         $ret $this->compiler->appendPhp"require_once 'HTML/Javascript/Convert.php';");
  90.         $ret .= $this->compiler->appendHTML("\n<script type='text/javascript'>\n");
  91.         $prefix ''$element->getAttribute('FLEXY:PREFIX');
  92.         
  93.         
  94.         foreach ($element->attributes as $k=>$v{
  95.             // skip directives..
  96.             if (strpos($k,':')) {
  97.                 continue;
  98.             }
  99.             if ($k == '/'{
  100.                 continue;
  101.             }
  102.             $v substr($v,1,-1);
  103.             $ret .= $this->compiler->appendPhp(
  104.                 '$__tmp = HTML_Javascript_Convert::convertVar('.$element->toVar($v.',\''.$prefix $k.'\',true);'.
  105.                 'echo (PEAR::isError($__tmp)) ? ("<pre>".print_r($__tmp,true)."</pre>") : $__tmp;');
  106.             $ret .= $this->compiler->appendHTML("\n");
  107.         }
  108.         $ret .= $this->compiler->appendHTML("</script>");
  109.         return $ret;
  110.     }
  111.     /**
  112.     * include handler
  113.     * <flexy:include src="test.html">
  114.     * 
  115.     * @see parent::toString()
  116.     */
  117.     function includeToString($element{
  118.         // this is disabled by default...
  119.         // we ignore modifier pre/suffix
  120.     
  121.     
  122.     
  123.        
  124.         $arg $element->getAttribute('SRC');
  125.         if (!$arg{
  126.             return $this->compiler->appendHTML("<B>Flexy:Include without a src=filename</B>");
  127.         }
  128.         // ideally it would be nice to embed the results of one template into another.
  129.         // however that would involve some complex test which would have to stat
  130.         // the child templates anyway..
  131.         // compile the child template....
  132.         // output... include $this->options['compiled_templates'] . $arg . $this->options['locale'] . '.php'
  133.         return $this->compiler->appendPHP"\n".
  134.                 "\$x = new HTML_Template_Flexy(\$this->options);\n".
  135.                 "\$x->compile('{$arg}');\n".
  136.                 "\$x->outputObject(\$t);\n"
  137.             );
  138.     
  139.     }
  140.     
  141.     /**
  142.     * Convert flexy tokens to HTML_Template_Flexy_Elements.
  143.     *
  144.     * @param    object token to convert into a element.
  145.     * @return   object HTML_Template_Flexy_Element 
  146.     * @access   public
  147.     */
  148.     function toElement($element{
  149.        return '';
  150.     }
  151.         
  152.     
  153.  
  154. }

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