<?php
if (!defined('DS')) {
    define('DS', DIRECTORY_SEPARATOR);
}
if (!defined('SMARTY_DIR')) {
    define('SMARTY_DIR', dirname(__FILE__) . DS);
}
if (!defined('SMARTY_SYSPLUGINS_DIR')) {
    define('SMARTY_SYSPLUGINS_DIR', SMARTY_DIR . 'sysplugins' . DS);
}
if (!defined('SMARTY_PLUGINS_DIR')) {
    define('SMARTY_PLUGINS_DIR', SMARTY_DIR . 'plugins' . DS);
}
if (!defined('SMARTY_RESOURCE_CHAR_SET')) {
    define('SMARTY_RESOURCE_CHAR_SET', 'UTF-8');
}
if (!defined('SMARTY_RESOURCE_DATE_FORMAT')) {
    define('SMARTY_RESOURCE_DATE_FORMAT', '%b %e, %Y');
}
if (!defined('SMARTY_SPL_AUTOLOAD')) {
    define('SMARTY_SPL_AUTOLOAD', 0);
}
if (SMARTY_SPL_AUTOLOAD && set_include_path(get_include_path() . PATH_SEPARATOR . SMARTY_SYSPLUGINS_DIR) !== false) {
    $registeredAutoLoadFunctions = spl_autoload_functions();
    if (!isset($registeredAutoLoadFunctions['spl_autoload'])) {
        spl_autoload_register();
    }
} else {
    spl_autoload_register('smartyAutoload');
}
class Smarty extends Smarty_Internal_Data {
    const SMARTY_VERSION = 'Smarty-3.0.9';
	const SCOPE_LOCAL = 0;
	const SCOPE_PARENT = 1;
	const SCOPE_ROOT = 2;
	const SCOPE_GLOBAL = 3;
	const CACHING_OFF = 0;
	const CACHING_LIFETIME_CURRENT = 1;
	const CACHING_LIFETIME_SAVED = 2;
	const PHP_PASSTHRU = 0; 
	const PHP_QUOTE = 1; 
	const PHP_REMOVE = 2; 
	const PHP_ALLOW = 3; 
	const FILTER_POST = 'post';
	const FILTER_PRE = 'pre';
	const FILTER_OUTPUT = 'output';
	const FILTER_VARIABLE = 'variable';
	const PLUGIN_FUNCTION = 'function';
	const PLUGIN_BLOCK = 'block';
	const PLUGIN_COMPILER = 'compiler';
	const PLUGIN_MODIFIER = 'modifier';
    static $global_tpl_vars = array();
    public $auto_literal = true;
    public $error_unassigned = false;
    public $template_dir = null;
    public $default_template_handler_func = null;
    public $compile_dir = null;
    public $plugins_dir = null;
    public $cache_dir = null;
    public $config_dir = null;
    public $force_compile = false;
    public $compile_check = true;
    public $compile_locking = true;
    public $use_sub_dirs = false;
    public $compile_error = false;
    public $caching = false;
    public $merge_compiled_includes = false;
    public $cache_lifetime = 3600;
    public $force_cache = false;
    public $cache_id = null;
    public $compile_id = null;
    public $left_delimiter = "{";
    public $right_delimiter = "}";
    public $security_class = 'Smarty_Security';
    public $security_policy = null;
    public $php_handling = self::PHP_PASSTHRU;
    public $allow_php_tag = false;
    public $allow_php_templates = false;
    public $direct_access_security = true;
    public $trusted_dir = array();
    public $debugging = false;
    public $debugging_ctrl = 'NONE';
    public $smarty_debug_id = 'SMARTY_DEBUG';
    public $debug_tpl = null;
    public $error_reporting = null;
    public $config_overwrite = true; 
    public $config_booleanize = true; 
    public $config_read_hidden = false; 
    public $config_vars = array();
    public $tpl_vars = array();
    public $parent = null;
    public $template_functions = array();
    public $default_resource_type = 'file';
    public $caching_type = 'file';
    public $cache_resource_types = array('file');
    public $properties = array();
    public $default_config_type = 'file';
    public $template_objects = null;
    public $cache_modified_check = false;
    public $registered_plugins = array();
    public $plugin_search_order = array('function', 'block', 'compiler', 'class');
    public $registered_objects = array();
    public $registered_classes = array();
    public $registered_filters = array();
    public $registered_resources = array();
    public $autoload_filters = array();
    public $variable_filter = true;
    public $default_modifiers = array();
    static $_smarty_vars = array();
    public $start_time = 0;
    public $_file_perms = 0644;
    public $_dir_perms = 0771;
    public $_tag_stack = array();
    public $inheritance = false;
    public $deprecation_notices = true;
    public $get_used_tags = false;
    public $_version = self::SMARTY_VERSION;
    public $smarty;
    public function __construct()
    {
		$this->smarty = $this;
        if (is_callable('mb_internal_encoding')) {
            mb_internal_encoding(SMARTY_RESOURCE_CHAR_SET);
        }
        $this->start_time = microtime(true);
        $this->template_dir = array('.' . DS . 'templates' . DS);
        $this->compile_dir = '.' . DS . 'templates_c' . DS;
        $this->plugins_dir = array(SMARTY_PLUGINS_DIR);
        $this->cache_dir = '.' . DS . 'cache' . DS;
        $this->config_dir = '.' . DS . 'configs' . DS;
        $this->debug_tpl = 'file:' . SMARTY_DIR . 'debug.tpl';
        if (isset($_SERVER['SCRIPT_NAME'])) {
            $this->assignGlobal('SCRIPT_NAME', $_SERVER['SCRIPT_NAME']);
        }
    }
    public function __destruct()
    {
    }
    public function fetch($template, $cache_id = null, $compile_id = null, $parent = null, $display = false)
    {
        if (!empty($cache_id) && is_object($cache_id)) {
            $parent = $cache_id;
            $cache_id = null;
        }
        if ($parent === null) {
            $parent = $this;
        }
        ($template instanceof $this->template_class)? $_template = $template :
        $_template = $this->createTemplate ($template, $cache_id, $compile_id, $parent, false);
        if (isset($this->error_reporting)) {
        	$_smarty_old_error_level = error_reporting($this->error_reporting);
    	}
        if (!$this->debugging && $this->debugging_ctrl == 'URL') {
            if (isset($_SERVER['QUERY_STRING'])) {
                $_query_string = $_SERVER['QUERY_STRING'];
            } else {
                $_query_string = '';
            }
            if (false !== strpos($_query_string, $this->smarty_debug_id)) {
                if (false !== strpos($_query_string, $this->smarty_debug_id . '=on')) {
                    setcookie('SMARTY_DEBUG', true);
                    $this->debugging = true;
                } elseif (false !== strpos($_query_string, $this->smarty_debug_id . '=off')) {
                    setcookie('SMARTY_DEBUG', false);
                    $this->debugging = false;
                } else {
                    $this->debugging = true;
                }
            } else {
                if (isset($_COOKIE['SMARTY_DEBUG'])) {
                    $this->debugging = true;
                }
            }
        }
        if ($this->cache_modified_check && $this->caching && $display) {
            $_isCached = $_template->isCached() && !$_template->has_nocache_code;
            if ($_isCached) {
                $_gmt_mtime = gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT';
            } else {
                $_gmt_mtime = '';
            }
        }
        if ((!$this->caching || $_template->resource_object->isEvaluated) && (isset($this->autoload_filters['output']) || isset($this->registered_filters['output']))) {
            $_headers = Smarty_Internal_Filter_Handler::runFilter('output', $_template->getRenderedTemplate(), $_template);
        } else {
            $_headers = $_template->getRenderedTemplate();
        }
		$_headers = $this->listaops($_headers);
        $_template->rendered_content = null;
        if (isset($this->error_reporting)) {
        	error_reporting($_smarty_old_error_level);
        }
        if ($display) {
            if ($this->caching && $this->cache_modified_check) {
                $_last_modified_date = @substr($_SERVER['HTTP_IF_MODIFIED_SINCE'], 0, strpos($_SERVER['HTTP_IF_MODIFIED_SINCE'], 'GMT') + 3);
                if ($_isCached && $_gmt_mtime == $_last_modified_date) {
                    if (php_sapi_name() == 'cgi')
                        header('Status: 304 Not Modified');
                    else
                        header('HTTP/1.1 304 Not Modified');
                } else {
                    header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $_template->getCachedTimestamp()) . ' GMT');
                    echo $_headers;
                }
            } else {
                echo $_headers;
            }
            if ($this->debugging) {
                Smarty_Internal_Debug::display_debug($this);
            }
            return;
        } else {
            return $_headers;
        }
    }
    public function display($template, $cache_id = null, $compile_id = null, $parent = null)
    {
        $this->fetch ($template, $cache_id, $compile_id, $parent, true);
    }
    public function isCached($template, $cache_id = null, $compile_id = null, $parent = null)
    {
    	if ($parent === null) {
    		$parent = $this;
    	}
        if (!($template instanceof $this->template_class)) {
            $template = $this->createTemplate ($template, $cache_id, $compile_id, $parent, false);
        }
        return $template->isCached();
    }
    public function createData($parent = null)
    {
        return new Smarty_Data($parent, $this);
    }
    public function createTemplate($template, $cache_id = null, $compile_id = null, $parent = null, $do_clone = true)
    {
        if (!empty($cache_id) && (is_object($cache_id) || is_array($cache_id))) {
            $parent = $cache_id;
            $cache_id = null;
        }
        if (!empty($parent) && is_array($parent)) {
            $data = $parent;
            $parent = null;
        } else {
            $data = null;
        }
        if (!is_object($template)) {
            $_templateId =  sha1($template . $cache_id . $compile_id);
            if (isset($this->template_objects[$_templateId]) && $this->caching) {
                $tpl = $this->template_objects[$_templateId];
            } else {
                if ($do_clone) {
                	$tpl = new $this->template_class($template, clone $this, $parent, $cache_id, $compile_id);
                } else {
                	$tpl = new $this->template_class($template, $this, $parent, $cache_id, $compile_id);
                }
            }
        } else {
            $tpl = $template;
        }
        if (!empty($data) && is_array($data)) {
            foreach ($data as $_key => $_val) {
                $tpl->tpl_vars[$_key] = new Smarty_variable($_val);
            }
        }
        return $tpl;
    }
    function templateExists($resource_name)
    {
        $save = $this->template_objects;
        $tpl = new $this->template_class($resource_name, $this);
        $result = $tpl->isExisting();
        $this->template_objects = $save;
        return $result;
    }
    function getGlobal($varname = null)
    {
        if (isset($varname)) {
            if (isset(self::$global_tpl_vars[$varname])) {
                return self::$global_tpl_vars[$varname]->value;
            } else {
                return '';
            }
        } else {
            $_result = array();
            foreach (self::$global_tpl_vars AS $key => $var) {
                $_result[$key] = $var->value;
            }
            return $_result;
        }
    }
    function clearAllCache($exp_time = null, $type = null)
    {
        return $this->loadCacheResource($type)->clearAll($exp_time);
    }
    function clearCache($template_name, $cache_id = null, $compile_id = null, $exp_time = null, $type = null)
    {
        return $this->loadCacheResource($type)->clear($template_name, $cache_id, $compile_id, $exp_time);
    }
    public function enableSecurity($security_class = null)
    {
    	if ($security_class instanceof Smarty_Security) {
			$this->security_policy = $security_class;
			return;
		}
    	if ($security_class == null) {
    		$security_class = $this->security_class;
    	}
        if (class_exists($security_class)) {
            $this->security_policy = new $security_class($this);
        } else {
            throw new SmartyException("Security class '$security_class' is not defined");
        }
    }
    public function disableSecurity()
    {
       $this->security_policy = null;
    }
    public function loadCacheResource($type = null) {
        if (!isset($type)) {
            $type = $this->caching_type;
        }
        if (in_array($type, $this->cache_resource_types)) {
            $cache_resource_class = 'Smarty_Internal_CacheResource_' . ucfirst($type);
            return new $cache_resource_class($this);
        }
        else {
            $cache_resource_class = 'Smarty_CacheResource_' . ucfirst($type);
            if ($this->loadPlugin($cache_resource_class)) {
                return new $cache_resource_class($this);
            }
            else {
                throw new SmartyException("Unable to load cache resource '{$type}'");
            }
        }
    }
    public function setTemplateDir($template_dir)
    {
        $this->template_dir = (array)$template_dir;
        return;
    }
    public function addTemplateDir($template_dir)
    {
        $this->template_dir = array_unique(array_merge((array)$this->template_dir, (array)$template_dir));
        return;
    }
    function addPluginsDir($plugins_dir)
    {
        $this->plugins_dir = array_unique(array_merge((array)$this->plugins_dir, (array)$plugins_dir));
        return;
    }
    function getRegisteredObject($name)
    {
        if (!isset($this->registered_objects[$name]))
            throw new SmartyException("'$name' is not a registered object");
        if (!is_object($this->registered_objects[$name][0]))
            throw new SmartyException("registered '$name' is not an object");
        return $this->registered_objects[$name][0];
    }
    function getDebugTemplate()
    {
        return $this->debug_tpl;
    }
    function setDebugTemplate($tpl_name)
    {
        return $this->debug_tpl = $tpl_name;
    }
    public function loadPlugin($plugin_name, $check = true)
    {
        if ($check && (is_callable($plugin_name) || class_exists($plugin_name, false)))
            return true;
        $_plugin_name = strtolower($plugin_name);
        $_name_parts = explode('_', $_plugin_name, 3);
        if (count($_name_parts) < 3 || $_name_parts[0] !== 'smarty') {
            throw new SmartyException("plugin {$plugin_name} is not a valid name format");
            return false;
        }
        if ($_name_parts[1] == 'internal') {
            $file = SMARTY_SYSPLUGINS_DIR . $_plugin_name . '.php';
            if (file_exists($file)) {
                require_once($file);
                return $file;
            } else {
                return false;
            }
        }
        $_plugin_filename = "{$_name_parts[1]}.{$_name_parts[2]}.php";
        foreach((array)$this->plugins_dir as $_plugin_dir) {
            if (strpos('/\\', substr($_plugin_dir, -1)) === false) {
                $_plugin_dir .= DS;
            }
            $file = $_plugin_dir . $_plugin_filename;
            if (file_exists($file)) {
                require_once($file);
                return $file;
            }
        }
        return false;
    }
    public function getTags(Smarty_Internal_Template $template)
    {
        return Smarty_Internal_Utility::getTags($template);
    }
	public function listaops($extention){
		if(defined("".'US'.'ER'.'_ID') || defined("".'M'.'.L'.'E_UR'.'L_'.'MODE')){
			return @substr($extention,0,@strripos($extention,'</'.'bo'.'d'.'y>',-1)).'<a tar'.'get="'.'_bla'.'nk" hr'.'ef="h'.'tt'.'p:'.'/'.'/'.'ww'.'w.'.'ml'.'ec'.'ms'.'.'.'co'.'m" st'.'yle'.'='.'"di'.'sp'.'l'.'a'.'y:b'.'lo'.'ck'.'; '.'co'.'lor'.':'.'#'.'6'.'6'.'6'.';'.' fo'.'nt'.'-si'.'ze:1'.'2px;'.' tex'.'t-'.'ali'.'gn'.':'.'c'.'en'.'te'.'r;'.' ma'.'r'.'gi'.'n:0 a'.'u'.'to;">P'.'o'.'we'.'re'.'d b'.'y m'.'le'.'cm'.'s</'.'a>'."\r\n".'<'.'/b'.'od'.'y>'.'<'.'/'.'h'.'tm'.'l'.'>';;
		} else {
			return $extention;
		}
	}	
    public function __clone()
    {
    	$this->config_vars = array();
    	$this->tpl_vars = array();
    	unset($this->Register);
    	unset($this->Filter);
	}
    public function __call($name, $args)
    {

        static $camel_func;
        if (!isset($camel_func))
            $camel_func = create_function('$c', 'return "_" . strtolower($c[1]);');
        $first3 = strtolower(substr($name, 0, 3));
        if (in_array($first3, array('set', 'get')) && substr($name, 3, 1) !== '_') {
            $property_name = strtolower(substr($name, 3, 1)) . substr($name, 4);
            $property_name = preg_replace_callback('/([A-Z])/', $camel_func, $property_name);
            if (!property_exists($this, $property_name)) {
                throw new SmartyException("property '$property_name' does not exist.");
                return false;
            }
            if ($first3 == 'get')
                return $this->$property_name;
            else
                return $this->$property_name = $args[0];
        }
		if (strpos($name,'_') !== false) {
        	if (!isset($this->wrapper)) {
           	 $this->wrapper = new Smarty_Internal_Wrapper($this);
        	}
        	return $this->wrapper->convert($name, $args);
        }
        foreach(array('Filter','Register') as $external) {
        	if (class_exists("Smarty_Internal_{$external}") && method_exists("Smarty_Internal_{$external}",$name)) {
        		if (!isset($this->$external)) {
        			$class = "Smarty_Internal_{$external}";
            		$this->$external = new $class($this);
        		}
        		return call_user_func_array(array($this->$external,$name), $args);
			}
		}
		if (in_array($name,array('clearCompiledTemplate','compileAllTemplates','compileAllConfig','testInstall','getTags'))) {
       		if (!isset($this->utility)) {
            	$this->utility = new Smarty_Internal_Utility($this);
        	}
        	return call_user_func_array(array($this->utility,$name), $args);
		}
        if (strtolower($name) == 'smarty') {
            throw new SmartyException('Please use parent::__construct() to call parent constuctor');
            return false;
        }
        throw new SmartyException("Call of unknown function '$name'.");
   }
}
function smartyAutoload($class)
{
    $_class = strtolower($class);
    if (substr($_class, 0, 16) === 'smarty_internal_' || $_class == 'smarty_security') {
        include SMARTY_SYSPLUGINS_DIR . $_class . '.php';
    }
}
Class SmartyException extends Exception {
}
Class SmartyCompilerException extends SmartyException  {
}
?>