<?php 
require_once("smarty/Smarty.class.php"); 
 
//for the real site you would define Smarty settings in the site configuration script 
$TEMPLATE_OPTIONS = array( 
    'TEMPLATE_DIR' => 'templates', 
    'MAIL_TEMPLATE_DIR' => 'templates', 
    'COMPILE_DIR' => 'smarty/template_c/', 
    'CACHE_DIR'=> 'smarty/cache/', 
    'CONFIG_DIR'=> './', 
    'CACHING'=> false, 
    'CACHE_LIFETIME'=> 0, 
    'COMPILE_CHECK'=> true, 
    ); 
 
/*********************************************************** 
    Define custom class that configures Smarty 
***********************************************************/ 
class MySmarty extends Smarty { 
 
var $page_title=''; 
var $error_codes; 
var $config; 
 
static private $instance; 
 
/** 
 * @return object MySmarty 
 * @ desc returns an instance of MySmarty class  
*/ 
static public function factory(){ 
    isset(self::$instance) || self::$instance=new MySmarty(); 
    return self::$instance; 
} 
 
function __construct(){ 
     
    $c = $this->config = $GLOBALS['TEMPLATE_OPTIONS']; 
 
    //directories 
    $this->template_dir = $c['TEMPLATE_DIR'].'/'; 
    $this->compile_dir =  $c['COMPILE_DIR']; 
    $this->compile_check = $c['COMPILE_CHECK']; 
    $this->config_dir = $c['CONFIG_DIR']; 
 
    //configure caching 
    $this->cache_dir = $c['CACHE_DIR']; 
    $this->caching = $c['CACHING']; 
    $this->cache_lifetime = $c['CACHE_LIFETIME']; 
    $this->cache_modified_check = true; 
 
    //call original Smarty constructor 
    Smarty::Smarty(); 
} 
 
/** 
 * Check if the template file exists 
 * 
 * @param string $template_name 
 * @return bool 
 */ 
function templateExists($template_name){ 
    //don't allow access to the upper directories 
    if (strrpos($template_name,'..')!==false){ 
        return false; 
    } 
    $file_name = $this->template_dir.'/'.$template_name; 
    if (is_file($file_name) && is_readable($file_name)){ 
        return true; 
    } 
    return false; 
} 
 
//end of the class 
}
 
 |