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

Source for file Render.php

Documentation is available at Render.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: Render.php 44 2007-07-22 23:55:30Z evolic $
  18.  * @since      Release 0.6.2
  19.  * @link       http://www.zeronotice.org
  20.  */
  21.  
  22. require_once('ZNF/Config/AppConfig.php');
  23.  
  24. /**
  25.  * <i>ZNF_Presentation_Render</i> specifies the abstract class that renderization classes should extends.
  26.  *
  27.  * @access     public
  28.  * @package    ZNF
  29.  * @subpackage Presentation
  30.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  31.  * @author     Graziano Liberati <http://www.liberati.org>
  32.  * @copyright  2004-2007 The ZNF Development Team
  33.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  34.  * @version    SVN $Id: Render.php 44 2007-07-22 23:55:30Z evolic $
  35.  * @since      Release 0.6.2
  36.  * @link       http://www.zeronotice.org
  37.  */
  38. abstract class ZNF_Presentation_Render
  39. {
  40.  
  41.     /**
  42.      * The <i>ZNF_Config_AppConfig</i> instance.
  43.      *
  44.      * @access protected
  45.      * @var ZNF_Config_AppConfig $_appConfig 
  46.      */
  47.     protected $_appConfig;
  48.  
  49.     /**
  50.      * The name of the package to which the template refers.
  51.      *
  52.      * @access protected
  53.      * @var string $_package 
  54.      */
  55.     protected $_package = null;
  56.  
  57.     /**
  58.      * The <i>path</i> property of the <i>ZNF_Action_ActionMapping</i>.
  59.      *
  60.      * @access protected
  61.      * @var string $_path 
  62.      */
  63.     protected $_path = null;
  64.  
  65.     /**
  66.      * The <i>nextPath</i> property of the <i>ZNF_Action_ActionMapping</i>.
  67.      *
  68.      * @access protected
  69.      * @var string $_nextPath 
  70.      */
  71.     protected $_nextPath = null;
  72.  
  73.     /**
  74.      * Constructs a new <i>ZNF_Presentation_Render</i> object and sets the internal properties with application settings.
  75.      *
  76.      * @access public
  77.      * @param string $package Name of the package to which the template refers,
  78.      *                         leave null this parameter to refer to the theme
  79.      *                         template
  80.      * @param ZNF_Action_ActionMapping $mapping 
  81.      */
  82.     public function __construct($package null$mapping null)
  83.     {
  84.         $this->_appConfig = ZNF_Config_AppConfig::getInstance();
  85.         $this->_package = $package;
  86.  
  87.         if ($mapping{
  88.             $this->_path = $mapping->getPath();
  89.             $this->_nextPath = $mapping->getNextPath();
  90.         }
  91.     }
  92.  
  93.     /**
  94.      * Get the ZNF constants to be assigned to the templates.
  95.      *
  96.      * <ul>
  97.      *   <li>znf.baseHref: concatenation of hostname and relative path of the
  98.      *   public script directory, used as prefix in hyperlinks in order to
  99.      *   refer to correct URIs.</li>
  100.      *   <li>znf.actionIndex: Name of the GET attribute used to select the
  101.      *   action to execute.</li>
  102.      *   <li>znf.moduleIndex: Name of the GET attribute used to select the
  103.      *   module configuration.</li>
  104.      *   <li>znf.changeModuleIndex: Name of the GET attribute used to select
  105.      *   persistently the module configuration.</li>
  106.      *   <li>znf.themePath: relative path of the current theme, used as prefix
  107.      *   in hyperlinks (css, javascripts, images...) in order to refer to
  108.      *   correct paths.</li>
  109.      *   <li>znf.packagePath: relative path of the package in use, used as
  110.      *   prefix in hyperlinks (css, javascripts, images...) in order to refer
  111.      *   to correct paths.</li>
  112.      *   <li>znf.path: current action path.</li>
  113.      *   <li>znf.nextPath: next action path to request.</li>
  114.      *   <li>znf.credits: ZNF credits.</li>
  115.      * </ul>
  116.      *
  117.      * @access protected
  118.      * @return array 
  119.      */
  120.     protected function _getConstants()
  121.     {
  122.         if (isset($_SERVER['HTTPS'])) {
  123.           $protocol 'https://';
  124.         else {
  125.           $protocol 'http://';
  126.         }
  127.  
  128.         $constants['baseHref'$protocol "{$_SERVER['SERVER_NAME']}";
  129.         if ($_SERVER['SERVER_PORT'!= '80' && $_SERVER['SERVER_PORT'!= '443'{
  130.             $constants['baseHref'.= ":{$_SERVER['SERVER_PORT']}";
  131.         }
  132.         if (dirname($_SERVER['SCRIPT_NAME']!= '/'{
  133.             $constants['baseHref'.=  dirname($_SERVER['SCRIPT_NAME']);
  134.         }
  135.         $constants['baseHref']          .= '/';
  136.         $constants['actionIndex']       ZNF::ACTION_INDEX;
  137.         $constants['moduleIndex']       ZNF::MODULE_INDEX;
  138.         $constants['changeModuleIndex'ZNF::CHANGE_MODULE_INDEX;
  139.         $constants['themePath']         $this->_getThemePath();
  140.         $constants['packagePath']       $this->_package;
  141.         $constants['path']              $this->_path;
  142.         $constants['nextPath']          $this->_nextPath;
  143.         $constants['credits']           ZNF::CREDITS;
  144.  
  145.         return $constants;
  146.     }
  147.  
  148.     /**
  149.      * Returns the path of a theme template, tries to load the template in a predefined order.
  150.      *
  151.      * <ul>
  152.      *   <li>current theme and current lang template</li>
  153.      *   <li>current theme and default lang template</li>
  154.      *   <li>default theme and default lang template</li>
  155.      * </ul>
  156.      *
  157.      * @access protected
  158.      * @param string $template File name of the template to get
  159.      * @return string 
  160.      */
  161.     protected function _getThemeTemplatePath($template)
  162.     {
  163.         // loading current theme and current lang template
  164.         $path ZNF::THEME_DIR "/{$_SESSION['znf']['theme']}/{$_SESSION['znf']['lang']}/{$template}";
  165.  
  166.         if (!is_file($path)) {
  167.             // loading current theme and default lang template
  168.             $path ZNF::THEME_DIR "/{$_SESSION['znf']['theme']}/{$this->_appConfig->getLang()}/{$template}";
  169.  
  170.             if (!is_file($path)) {
  171.                 // loading default theme and default lang template
  172.                 $path ZNF::THEME_DIR "/{$this->_appConfig->getTheme()}/{$this->_appConfig->getLang()}/{$template}";
  173.  
  174.                 if (!is_file($path)) {
  175.                     // default theme and default lang template not found
  176.                     $translation new ZNF_Presentation_Translation('ZNF'$_SESSION['znf']['lang']);
  177.                     throw new ZNF_Presentation_RenderException($translation->get('errorLoadThemeTemplate'));
  178.                 }
  179.  
  180.             }
  181.  
  182.         }
  183.  
  184.         return $path;
  185.     }
  186.  
  187.     /**
  188.      * Returns the path of a package template, tries to load the template in a predefined order.
  189.      *
  190.      * <ul>
  191.      *   <li>overloaded package template in the current theme and lang path</li>
  192.      *   <li>current package and current lang template</li>
  193.      *   <li>current package and default lang template</li>
  194.      * </ul>
  195.      *
  196.      * @access protected
  197.      * @param string $template File name of the template to get
  198.      * @return string 
  199.      */
  200.     protected function _getPackageTemplatePath($template)
  201.     {
  202.         // loading overloaded package template in the current theme and lang path
  203.         $path ZNF::THEME_DIR "/{$_SESSION['znf']['theme']}/ZNF::TEMPLATE_OVERLAY_DIR "/{$this->_package}/{$_SESSION['znf']['lang']}/{$template}";
  204.  
  205.         if (!is_file($path)) {
  206.             // loading current package and current lang template
  207.             $path = ZNF::MODULES_DIR . "/{$this->_package}/" . ZNF::TEMPLATE_DIR . "/{$_SESSION['znf']['lang']}/{$template}";
  208.  
  209.             if (!is_file($path)) {
  210.                 // loading current package and default lang template
  211.                 $path = ZNF::MODULES_DIR . "/{$this->_package}/" . ZNF::TEMPLATE_DIR . "/{$this->_appConfig->getLang()}/{$template}";
  212.  
  213.                 if (!is_file($path)) {
  214.                     // current package and default lang template not found
  215.                     $translation = new ZNF_Presentation_Translation('ZNF', $_SESSION['znf']['lang']);
  216.                     throw new ZNF_Presentation_RenderException($translation->get('errorLoadPackageTemplate'));
  217.                 }
  218.  
  219.             }
  220.  
  221.         }
  222.  
  223.         return $path;
  224.     }
  225.  
  226.     /**
  227.      * Returns the path to get the template requested.
  228.      *
  229.      * @access public
  230.      * @param string $template File name of the template
  231.      * @return string
  232.      */
  233.     protected function _getTemplatePath($template)
  234.     {
  235.         if ($this->_package{
  236.             return $this->_getPackageTemplatePath($template);
  237.         } else {
  238.             return $this->_getThemeTemplatePath($template);
  239.         }
  240.     }
  241.  
  242.     /**
  243.      * Returns the path of a theme, tries to find the theme base directory in a predefined order.
  244.      *
  245.      * <ul>
  246.      *   <li>current theme and current lang theme base directory</li>
  247.      *   <li>current theme and default lang theme base directory</li>
  248.      *   <li>default theme and default lang theme base directory</li>
  249.      * </ul>
  250.      *
  251.      * @access protected
  252.      * @return string
  253.      */
  254.     protected function _getThemePath()
  255.     {
  256.         // loading current theme and current lang theme base directory
  257.         $path = ZNF::THEME_DIR . "/{$_SESSION['znf']['theme']}/{$_SESSION['znf']['lang']}";
  258.  
  259.         if (!is_dir($path)) {
  260.             // loading current theme and default lang theme base directory
  261.             $path = ZNF::THEME_DIR . "/{$_SESSION['znf']['theme']}/{$this->_appConfig->getLang()}";
  262.  
  263.             if (!is_dir($path)) {
  264.                 // loading default theme and default lang theme base directory
  265.                 $path = ZNF::THEME_DIR . "/{$this->_appConfig->getTheme()}/{$this->_appConfig->getLang()}";
  266.  
  267.                 if (!is_dir($path)) {
  268.                     // default theme and default lang theme base dir not found
  269.                     $translation = new ZNF_Presentation_Translation('ZNF', $_SESSION['znf']['lang']);
  270.                     throw new ZNF_Presentation_RenderException($translation->get('errorLoadThemeBaseDir'));
  271.                 }
  272.  
  273.             }
  274.  
  275.         }
  276.  
  277.         return $path;
  278.     }
  279.  
  280.  
  281.     /**
  282.      * Assigns values to template parameters.
  283.      *
  284.      * @access public
  285.      * @param string $param The template parameter name
  286.      * @param mixed $value The value to assign
  287.      */
  288.     abstract public function assign($param, $value);
  289.  
  290.     /**
  291.      * Executes the renderization and displays the result.
  292.      *
  293.      * @access public
  294.      * @param string $template File name of the template
  295.      * @param mixed $data Additional data to process
  296.      */
  297.     abstract public function display($template, $data = null);
  298.  
  299.     /**
  300.      * Executes the renderization and returns the result.
  301.      *
  302.      * @access public
  303.      * @param string $template File name of the template
  304.      * @param mixed $data Additional data to process
  305.      * @return string
  306.      */
  307.     abstract public function fetch($template, $data = null);
  308.  
  309. }
  310.  
  311. /**
  312.  * <i>ZNF_Presentation_RenderException</i> is the exception type for the <i>ZNF_Presentation_Render</i> class.
  313.  *
  314.  * <i>ZNF_Presentation_RenderException</i> extends the <i>Exception</i> class of PHP5.
  315.  *
  316.  * @access     public
  317.  * @package    ZNF
  318.  * @subpackage Presentation
  319.  * @author     Alessandro Rossini <http://www.alessandrorossini.org>
  320.  * @author     Graziano Liberati <http://www.liberati.org>
  321.  * @copyright  2004-2007 The ZNF Development Team
  322.  * @license    LGPL License 2.1 <http://www.gnu.org/copyleft/lesser.html>
  323.  * @version    SVN $Id: Render.php 44 2007-07-22 23:55:30Z evolic $
  324.  * @since      Release 0.5.0
  325.  * @link       http://www.zeronotice.org
  326.  */
  327. class ZNF_Presentation_RenderException extends Exception
  328. {
  329. }
  330.  

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