Вход Регистрация
Файл: adultscript-2.0.3-pro/files/libraries/framework/template.php
Строк: 172
<?php
defined
('_VALID') or die('Restricted Access!');
class 
VTemplate
{
    public 
$cfg;
    
    private 
$templates    = array();

    public 
$errors        = array();
    public 
$messsages    = array();
    public 
$warnings    = array();
    
    public 
$meta_title;
    public 
$meta_desc;
    public 
$meta_keys;
    
    private 
$cache        false;
    
    private 
$_data        = array();
    
    public 
$css            NULL;
    public 
$js            NULL;
    
    public function 
__construct($options=array())
    {
        
$this->cfg VF::cfg('core.config');
        if (isset(
$options['template']) && isset($options['template_dir']) &&
            isset(
$options['template_url']) && isset($options['template_rel'])) {
            
$template        $options['template'];
            
$template_dir    $options['template_dir'];
            
$template_url    $options['template_url'];
            
$template_rel    $options['template_rel'];
        } else {
            
$template        $this->cfg['template'];
            
$template_dir    TEMPLATES_DIR.'/'.$template;
            
$template_url    BASE_URL.'/templates/'.$template;
            
$template_rel    RELATIVE_URL.'/templates/'.$template;
            if (
defined('CDN_URL')) {
                
$template_url    CDN_URL.'/templates/'.$template;
                
$template_rel    CDN_URL.'/templates/'.$template;
            }
        }
        
        
define('TPL',        $template);
          
define('TPL_DIR',    $template_dir);
          
define('TPL_URL',    $template_url);
          
define('TPL_REL',    $template_rel);
    }
    
    public function 
__set($key$value)
    {
        
$this->_data[$key] = $value;
    }
    
    public function 
__get($key)
    {
        if (isset(
$this->_data[$key])) {
            if (
is_array($this->_data[$key])) {
                return (array) 
$this->_data[$key];
            }
        
            return 
$this->_data[$key];
        }
    }
    
    public function 
__isset($key)
    {
        return isset(
$this->_data[$key]);
    }
    
    public function 
__unset($key)
    {
        unset(
$this->_data[$key]);
    }
        
    public function 
_($string)
    {
        return 
htmlspecialchars(htmlspecialchars_decode($string), ENT_QUOTES'UTF-8');
    }
    
    public function 
e($string)
    {
        echo 
htmlspecialchars(htmlspecialchars_decode($string), ENT_QUOTES'UTF-8');
    }
    
    public function 
load($tpl)
    {
        if (
is_array($tpl)) {
            foreach (
$tpl as $template) {
                
$this->templates[] = $template;
            }
        } else {
            
$this->templates[] = $tpl;
        }
    }

    public function 
fetch($tpl)
    {
        
$content    FALSE;
        
$tpl_path    = ($tpl['0'] == '/') ? $tpl TPL_DIR.'/'.$tpl.'.tpl.php';
        try {
            
ob_start();
            require 
$tpl_path;
            
$content ob_get_contents();
            
ob_end_clean();
        } catch (
Exception $e) {
            throw new 
VException($e);
        }
        
        return 
$content;
    }
    
    public function 
output()
    {
        if (isset(
$_SESSION['message'])) {
            
$this->messages array_merge((array) $_SESSION['message'], (array) $this->messages);
            unset(
$_SESSION['message']);
        }

        if (isset(
$_SESSION['error'])) {
            
$this->errors     array_merge((array) $_SESSION['error'], (array) $this->errors);
            unset(
$_SESSION['error']);
        }

        if (isset(
$_SESSION['warning'])) {
            
$this->warnings array_merge((array) $_SESSION['warning'], (array) $this->warnings);
            unset(
$_SESSION['warning']);
        }
    
        
$content NULL;
        foreach (
$this->templates as $tpl) {
            
$tpl_path    = ($tpl['0'] == '/') ? $tpl TPL_DIR.'/'.$tpl.'.tpl.php';
            require 
$tpl_path;
        }
        
        
$content ob_get_contents();
        
ob_end_clean();
        
        return 
$content;
    }
    
    public function 
display($cache=FALSE$seconds=60)
    {
        
$output $this->output();
        if (
$this->cache === true && $this->cfg['template_cache']) {
            
VTemplate_Cache::cache(CURRENT_URL$output);
        }
        
        echo 
VResponse::output($output$cache$seconds);
    }
    
    public function 
cache($enabled=false)
    {
        
$this->cache $enabled;
    }
}

function 
w($name$options=NULL)
{
    
$function_name 'template_widget_'.$name;
    if (!
function_exists($function_name)) {
        require 
TPL_DIR.'/extend/widgets/'.$name.'.widget.php';
    }
    
    return 
$function_name($options);
}
    
function 
p()
{
    
$args func_get_args();
    if (!isset(
$args['0'])) {
          die(
'Failed to initialize template plugin!');
    }

    
$plugin_name    $args['0'];
    
$plugin_args    array_slice($args1);
    
$plugin_func    'template_plugin_'.$plugin_name;
    if (!
function_exists($plugin_func)) {
          try {
              require 
TPL_DIR.'/extend/plugins/'.$plugin_name.'.plugin.php';
          } catch (
Exception $e) {
              throw new 
VException($e);
          }
    }

    
$count count($plugin_args);
    if (
$count === 0) {
          return 
$plugin_func();
    } elseif (
$count === 1) {
        return 
$plugin_func($plugin_args['0']);
    } elseif (
$count === 2) {
          return 
$plugin_func($plugin_args['0'], $plugin_args['1']);
    } elseif (
$count === 3) {
        return 
$plugin_func($plugin_args['0'], $plugin_args['1'], $plugin_args['2']);
    }

    return 
call_user_func_array($plugin_func$plugin_args);
}
?>
Онлайн: 0
Реклама