aliroRenderer.php

Go to the documentation of this file.
00001 <?php
00002 
00003 /* Aliro Renderer classes
00004 */
00005 
00006 class aliroRenderer {
00007     
00008     public static function getRenderer ($type='php') {
00009         if ('php' == $type) return new aliroPHPRenderer();
00010         else {
00011             $classname = $type.'Renderer';
00012             if (aliro::getInstance()->classExists($classname)) return new $classname();
00013         }
00014         trigger_error(T_('aliroRenderer called for invalid renderer type'), E_USER_ERROR);
00015     }
00016 }
00017 
00018 class aliroPHPRenderer extends basicAdminHTML implements ifTemplateRenderer  {
00019     private $dir;
00020     private $vars = array();
00021     protected $engine = 'php';
00022     private $template = '';
00023     private $debug = 0;
00024     protected $translations = array();
00025     public $act = '';
00026     public $pageNav = null;
00027 
00028     public function __construct () {
00029         $this->dir = criticalInfo::getInstance()->class_base.'/views/templates/';
00030     }
00031 
00032     public function display ($template='') {
00033         return $this->checkTemplate($template) ? $this->loadTemplate($this->template) : false;
00034     }
00035 
00036     public function fetch ($template='') {
00037         if ($this->checkTemplate($template)) {
00038             ob_start();
00039             $this->loadTemplate($this->template);
00040             $ret = ob_get_contents();
00041             ob_end_clean();
00042             return $ret;
00043         }
00044         return false;
00045     }
00046     
00047     private function loadTemplate ($template) {
00048         extract($this->vars);
00049         if (!empty($act)) $this->act = $act;
00050         include($this->template);
00051         return true;
00052     }
00053     
00054     private function checkTemplate ($template) {
00055         if (empty($template)) $template = $this->template;
00056         if ($this->debug) echo nl2br($this->template."\n");
00057         if (empty($template)) trigger_error(T_('A template has not been specified in a call to aliroRenderer'), E_USER_ERROR);
00058         elseif (!is_readable($this->dir.$template)) trigger_error(sprintf(T_('Specified template file %s is not readable in a call to aliroPHPRenderer'), $template), E_USER_ERROR);
00059         else {
00060             $this->template = $this->dir.$template;
00061             return true;
00062         }
00063         return false;
00064     }
00065 
00066     public function getengine(){
00067         return $this->engine;
00068     }
00069 
00070     public function addvar($key, $value){
00071         $this->vars[$key] = $value;
00072     }
00073 
00074     public function addbyref ($key, &$value) {
00075         $this->vars[$key] = $value;
00076     }
00077 
00078     public function getvars ($name) {
00079         return isset($this->vars[$name]) ? $this->vars[$name] : '';
00080     }
00081 
00082     public function setdir ($dir) {
00083         $this->dir = (substr($dir, -1) == '/') ? $dir : $dir.'/';
00084     }
00085 
00086     public function settemplate ($template){
00087         $this->template = $template;
00088     }
00089 
00090     // Provides for aliroHTML methods to be used within heredoc as $this->html('method', ...)
00091     protected function html () {
00092         $args = func_get_args();
00093         $method = array_shift($args);
00094         $html = call_user_func(array('aliroHTML', 'getInstance'));
00095         return call_user_func_array(array($html, $method), $args);
00096     }
00097    
00098     protected function T_ ($string) {
00099         return T_($string);
00100     }
00101 }

Generated on Wed May 14 13:01:56 2008 for ALIRO by  doxygen 1.5.5