phpDocumentor ZNF
Presentation
[ class tree: ZNF ] [ index: ZNF ] [ all elements ]

Source for file Smarty.php

Documentation is available at Smarty.php

  1. <?php
  2. /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
  3. /**
  4.  * PHP version 5
  5.  *
  6.  * This source file is subject to version 2.1 of the GNU Lesser General Public
  7.  * License, that is bundled with this package in the file COPYING, available
  8.  * through the world wide web at the following URI:
  9.  * http://www.gnu.org/copyleft/lesser.html.
  10.  *
  11.  * @package    ZNF
  12.  * @subpackage Presentation
  13.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  14.  * @author     Graziano Liberati <http://www.liberati.org>
  15.  * @copyright  2004-2007 The ZNF Development Team
  16.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  17.  * @version    SVN $Id: Smarty.php 43 2007-06-26 23:36:35Z aronnax $
  18.  * @since      Release 0.5.0
  19.  * @link       http://www.zeronotice.org
  20.  */
  21.  
  22. require_once('Smarty/Smarty.class.php');
  23. require_once('ZNF/Presentation/Render.php');
  24.  
  25. /**
  26.  * <i>ZNF_Presentation_Smarty</i> class extends the <i>ZNF_Presentation_Render</i> class and use the <i>Smarty</i> class of the <i>Smarty</i> package for the renderization.
  27.  *
  28.  * Render data using package or theme templates.
  29.  *
  30.  * @access     public
  31.  * @package    ZNF
  32.  * @subpackage Presentation
  33.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  34.  * @author     Graziano Liberati <http://www.liberati.org>
  35.  * @copyright  2004-2007 The ZNF Development Team
  36.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  37.  * @version    SVN $Id: Smarty.php 43 2007-06-26 23:36:35Z aronnax $
  38.  * @since      Release 0.5.0
  39.  * @link       http://www.zeronotice.org
  40.  */
  41. {
  42.  
  43.     const SMARTY_CACHING = false;
  44.  
  45.     const SMARTY_COMPILE_CHECK = true;
  46.  
  47.     const SMARTY_DEBUGGING = ZNF::DEBUG;
  48.  
  49.     const SMARTY_FORCE_COMPILE = false;
  50.  
  51.     /**
  52.      * The <i>Smarty</i> object
  53.      *
  54.      * @access protected
  55.      * @var string $_smarty 
  56.      */
  57.     protected $_smarty = null;
  58.  
  59.     /**
  60.      * Constructs a new <i>ZNF_Presentation_Smarty</i> object and sets the internal properties with application settings.
  61.      *
  62.      * @access public
  63.      * @param string $package Name of the package to which the smarty template
  64.      *                         refers, leave null this parameter to refer to the
  65.      *                         theme smarty templates
  66.      * @param ZNF_Action_ActionMapping $mapping 
  67.      */
  68.     public function __construct($package null$mapping null)
  69.     {
  70.         parent::__construct($package$mapping);
  71.  
  72.         $this->_smarty = new Smarty();
  73.  
  74.         $this->_smarty->template_dir '.';
  75.         $this->_smarty->compile_dir ZNF::CACHE_DIR;
  76.         $this->_smarty->config_dir ZNF::CONFIG_DIR;
  77.         $this->_smarty->cache_dir ZNF::CACHE_DIR;
  78.         $this->_smarty->caching self::SMARTY_CACHING;
  79.         $this->_smarty->compile_check self::SMARTY_COMPILE_CHECK;
  80.         $this->_smarty->debugging self::SMARTY_DEBUGGING;
  81.         $this->_smarty->force_compile self::SMARTY_FORCE_COMPILE;
  82.     }
  83.  
  84.     /**
  85.      * Executes and returns the smarty template results.
  86.      *
  87.      * Gets the path of the smarty template, calls
  88.      * <i>ZNF_Presentation_Smarty->_assignConstants()</i> and calls the
  89.      * <i>fetch()</i> method of <i>Smarty</i>.
  90.      *
  91.      * @access public
  92.      * @param string $template File name of the smarty template
  93.      * @param mixed $data Additional data to process
  94.      * @return string 
  95.      */
  96.     public function fetch($template$data null)
  97.     {
  98.         $template $this->_getTemplatePath($template$data);
  99.  
  100.         $this->_assignConstants();
  101.  
  102.         return $this->_smarty->fetch($templatenullnullfalse);
  103.     }
  104.  
  105.     /**
  106.      * Executes and displays the smarty template results.
  107.      *
  108.      * Gets the path of the smarty template, calls
  109.      * <i>ZNF_Presentation_Smarty->_assignConstants()</i> and calls the
  110.      * <i>display()</i> method of <i>Smarty</i>.
  111.      *
  112.      * @access public
  113.      * @param string $template File name of the smarty template
  114.      * @param mixed $data Additional data to process
  115.      */
  116.     public function display($template$data null)
  117.     {
  118.         $template $this->_getTemplatePath($template$data);
  119.  
  120.         $this->_assignConstants();
  121.  
  122.         $this->_smarty->fetch($templatenullnulltrue);
  123.     }
  124.  
  125.     /**
  126.      * Assigns values to smarty template variables.
  127.      *
  128.      * @param string $param The smarty template parameter name
  129.      * @param mixed $value The value to assign
  130.      */
  131.     public function assign($param$value)
  132.     {
  133.         $this->_smarty->assign($param$value);
  134.     }
  135.  
  136.     /**
  137.      * Assign to a smarty template the ZNF constants.
  138.      *
  139.      * @access protected
  140.      */
  141.     protected function _assignConstants()
  142.     {
  143.         $constants $this->_getConstants();
  144.         $this->_smarty->assign('znf'$constants);
  145.     }
  146.  
  147.     /**
  148.      * Destroys the <i>ZNF_Presentation_Smarty</i> object.</>
  149.      *
  150.      * @access public
  151.      */
  152.     public function __destruct()
  153.     {
  154.     }
  155.  
  156. }
  157.  
  158. /**
  159.  * <i>ZNF_Presentation_SmartyException</i> is the exception type for the <i>ZNF_Presentation_Smarty</i> class.
  160.  *
  161.  * <i>ZNF_Presentation_SmartyException</i> extends the <i>Exception</i> class of PHP5.
  162.  *
  163.  * @access     public
  164.  * @package    ZNF
  165.  * @subpackage Presentation
  166.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  167.  * @author     Graziano Liberati <http://www.liberati.org>
  168.  * @copyright  2004-2007 The ZNF Development Team
  169.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  170.  * @version    SVN $Id: Smarty.php 43 2007-06-26 23:36:35Z aronnax $
  171.  * @since      Release 0.5.0
  172.  * @link       http://www.zeronotice.org
  173.  */
  174. class ZNF_Presentation_SmartyException extends Exception
  175. {
  176. }
  177.  
  178. ?>

Documentation generated on Wed, 14 Nov 2007 23:47:41 +0100 by phpDocumentor 1.4.0