phpDocumentor GloryLands
Interface
[ class tree: GloryLands ] [ index: GloryLands ] [ all elements ]

Source for file gltemplate.php

Documentation is available at gltemplate.php

  1. <?php
  2. /**
  3.   * GloryLands Inteface system
  4.   *
  5.   * <pre>
  6.   * GloryLands, a Web-Based, Massive Multiplayer Online RPG/Strategy Game
  7.   * Copyright (C) 2008-09  John Haralampidis <jïhnys2[at]gmail.cïm>
  8.   *
  9.   * This program is free software: you can redistribute it and/or modify
  10.   * it under the terms of the GNU General Public License as published by
  11.   * the Free Software Foundation, either version 3 of the License, or
  12.   * (at your option) any later version.
  13.   *
  14.   * This program is distributed in the hope that it will be useful,
  15.   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.   * GNU General Public License for more details.
  18.   *
  19.   * You should have received a copy of the GNU General Public License
  20.   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  21.   *
  22.   * For any help/suggestions or troubleshooting you can see the
  23.   * project community website at <http://www.glorylands.gr>
  24.   * </pre>
  25.   *
  26.   * @license GNU/GPLv3 GNU General Public License version 3
  27.   * @package GloryLands
  28.   * @subpackage Interface
  29.   * @author John Haralampidis <jïhnys2[at]gmail.cïm>
  30.   * @copyright Copyright (C) 2007-2009, John Haralampidis
  31.   * @version 1.0
  32.   */
  33.  
  34. /**
  35.   * GloryLands PHP Template Engine
  36.   *
  37.   * This template extends the Dataset structure in order to provide
  38.   * simple variable access, and uses template optimizer to convert
  39.   * short-hand PHP tags to fully compatible PHP code.
  40.   *
  41.   * @package GloryLands
  42.   * @subpackage Interface
  43.   */
  44. class GLTemplate extends GLDataset {
  45.     
  46.     static $extensions;
  47.     
  48.     /**
  49.       * Register a template extension
  50.       *
  51.       * @param    string    $category    Target category
  52.       * @param    object    $function    The function to call for this category
  53.       */
  54.     public static function register_extension($category$function{
  55.         if (!self::$extensionsself::$extensions array();
  56.         self::$extensions[array(
  57.             'category' => $category,
  58.             'call' => $function
  59.         );
  60.     }
  61.  
  62.     /**
  63.       * Call a template category
  64.       *
  65.       * @param    string    $category    Target category
  66.       */
  67.     public static function call_extension($category$a=false,$b=false,$c=false,$d=false,$e=false,$f=false,$g=false,$h=false{
  68.         // No chained events? 
  69.         // Allow execution
  70.         if (!isset(self::$extensions[$event])) {
  71.             return true;
  72.         }
  73.         
  74.         // Prepare parameters array
  75.         $parm array(&$a,&$b,&$c,&$d,&$e,&$f,&$g,&$h);
  76.         
  77.         // Start chaining
  78.         foreach (self::$extensions[$eventas $calee{
  79.             $ans true;
  80.             $ans call_user_func_array($calee$parm);
  81.             if ($ans === falsereturn false;
  82.         }
  83.         
  84.         // Everything is ok by default
  85.         return true;
  86.     }
  87.  
  88.     /**
  89.       * Template file
  90.       * @var string 
  91.       */    
  92.     protected $file;
  93.  
  94.     /**
  95.       * Evaluated flag
  96.       *
  97.       * When this flag is FALSE, the template must be re-evaluated.
  98.       *
  99.       * @var bool 
  100.       */    
  101.     protected $evaluated;
  102.  
  103.     /**
  104.       * Response buffer
  105.       *
  106.       * This variable contains the response buffer that is generated
  107.       * after the evaluation.
  108.       *
  109.       * @var buffer 
  110.       */    
  111.     protected $response;
  112.     
  113.     /**
  114.       * Construct the GL Template, using the file specified
  115.       */
  116.     public function __construct($file$id=NULL{
  117.         $this->file = GLOptimizer::optimize_file($file'template');
  118.         $this->vars = array();
  119.         $this->evaluated = false;
  120.     }
  121.  
  122.     /** 
  123.       * Convert this into a string
  124.       *
  125.       * Returns the 'text' variable, if exists.
  126.       */
  127.     public function __toString({
  128.         return $this->fetch();
  129.     }
  130.     
  131.     public function fetch({            
  132.     
  133.         // Pre-process template
  134.         self::call_extension('pre'$this->vars);
  135.     
  136.         // Extract the variables
  137.         extract($this->varsEXTR_OVERWRITE);
  138.         
  139.         // Start OB and render file
  140.         ob_start();
  141.         include $this->file;
  142.         
  143.         // Fetch buffer and quit
  144.         $buf ob_get_clean();
  145.         ob_end_clean();
  146.  
  147.         // Post-process buffer
  148.         self::call_extension('post'$buf);
  149.         
  150.         // Return buffer
  151.         return $buf;
  152.     }
  153.     
  154. }
  155.  
  156. ?>

Documentation generated on Tue, 13 Oct 2009 23:49:11 +0300 by phpDocumentor 1.4.1