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

Source for file SmartyAPI.php

Documentation is available at SmartyAPI.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: SmartyAPI.php 310198 2011-04-13 09:30:18Z alan_k $
  20. //
  21. //  Description this class emulates the Smarty API to attempt to enable 
  22. //  upgrading to flexy. (eg. for use with flexy templates (that have been
  23. //  converted using the SmartyConverter Compiler.
  24. //  
  25. //  I've no idea how complete this will end up being..
  26. //
  27. //  Technically Smarty is LGPL - so theortically no code in here should
  28. //  use the copy & paste the original smarty code....
  29. //
  30.  
  31. // to use as a full emulator : 
  32. // try 
  33. // class Smarty extends HTML_Template_Flexy_SmartyAPI {
  34. //   function Smarty() { parent::construct(); } 
  35. // }
  36.  
  37.  
  38. // not implemented: 
  39. /*
  40. append_by_ref
  41. append
  42. register_function / unregister_function
  43. register_object / register_object
  44. register_block / unregister_block
  45. register_compiler_function / unregister_compiler_function
  46. register_modifier / unregister_modifier
  47. register_resource / unregister_resource
  48. register_prefilter / unregister_prefilter
  49. register_postfilter / unregister_postfilter
  50. register_outputfilter / unregister_outputfilter
  51. load_filter 
  52. clear_cache
  53. clear_all_cache
  54. is_cached
  55. template_exists
  56. get_template_vars
  57. get_config_vars
  58. trigger_error
  59.  
  60. fetch
  61. get_registered_object
  62. config_load
  63. clear_config
  64. _* (all the privates)
  65. */
  66.  
  67. /**
  68. * Smarty API emulator for Flexy
  69. * - designed to make transitions simpler
  70. * - provides only basic support for variables
  71. * - uses flexy templates (that have been converted previosly with the converor)
  72. *  
  73. @version    $Id: SmartyAPI.php 310198 2011-04-13 09:30:18Z alan_k $
  74. */
  75.  
  76. class HTML_Template_Flexy_SmartyAPI {
  77.     
  78.     /**
  79.     * where the data for the template gets stored.
  80.     *
  81.     * @var array 
  82.     * @access public
  83.     */
  84.     var $vars = array();  
  85.  
  86.     /**
  87.     * Standard Variable assignment
  88.     *
  89.     * @param   string|array   element name to assign value or assoc. array
  90.     * @param   mixed           value of element.
  91.     * 
  92.     * @return   none 
  93.     * @access   public
  94.     */
  95.     function assign($k,$v
  96.     {
  97.         if (is_array($k)) {
  98.             $this->vars $k $this->vars;
  99.             return;
  100.         }
  101.         $this->vars[$k$v;
  102.     }
  103.     /**
  104.     * Standard Variable assignment (by reference)
  105.     *
  106.     * @param   string         element name to assign value
  107.     * @param   mixed           value of element.
  108.     * 
  109.     * @return   none 
  110.     * @access   public
  111.     */
  112.     function assign_by_ref($k&$v)
  113.     {
  114.         $this->vars[$k&$v;
  115.     }
  116.     /**
  117.     * Unset a variable assignment
  118.     *
  119.     * @param   string         element name to remove
  120.      * 
  121.     * @return   none 
  122.     * @access   public
  123.     */
  124.     function clear_assign($k
  125.     {
  126.         if (is_array($k)) {
  127.             foreach ($k as $kk{
  128.                 $this->clear_assign($kk);
  129.             }
  130.             return;
  131.         }
  132.     
  133.         if (isset($this->vars[$k])) {
  134.             unset($this->vars[$k]);
  135.         }
  136.     }
  137.     /**
  138.     * Unset all variables
  139.     *
  140.     * @return   none 
  141.     * @access   public
  142.     */
  143.     function clear_all_assign(
  144.     {
  145.        $this->vars = array()
  146.     
  147.     }
  148.     
  149.     /**
  150.     * output a template (optionally with flexy object & element.)
  151.     *
  152.     * @param   string         name of flexy template.
  153.     * @param   object         object as per HTML_Template_Flexy:outputObject
  154.     * @param   array          elements array as per HTML_Template_Flexy:outputObject
  155.     * 
  156.     * @return   none 
  157.     * @access   public
  158.     */
  159.     function display($templatename,$object=null,$elements=array()) 
  160.     {
  161.         // some standard stuff available to a smarty template..
  162.         $this->vars['SCRIPT_NAME'=  $_SERVER['SCRIPT_NAME'];
  163.         
  164.         if (class_exists('PEAR5',false)) {
  165.             $o = PEAR5::getStaticProperty('HTML_Template_Flexy','options');
  166.         }
  167.         if (empty($o)) {
  168.             $o = PEAR::getStaticProperty('HTML_Template_Flexy','options');
  169.         }
  170.          
  171.         require_once 'HTML/Template/Flexy.php';
  172.         $t = new HTML_Template_Flexy;
  173.         $t->compile($templatename);
  174.         $object ($object !== null$object : new StdClass;
  175.         
  176.         foreach($this->vars as $k=>$v{
  177.             $object->$k $v;
  178.         }
  179.         $t->outputObject($object,$elements);
  180.     }
  181.     
  182. }

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