<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied'); class mytpl extends Smarty { var $tpl_addr; function __construct(){ $this->template_dir = SMARTY_TPL; $this->compile_dir = SMARTY_TPL_C; $this->cache_dir = "../cache/"; $this->cache_lifetime = "60*60*24*2"; $this->left_delimiter = '<{'; $this->right_delimiter = '}>'; parent::__construct(); } function module($module_name){ static $mod_class = array(); if(isset($mod_class[$module_name])){ return $mod_class[$module_name]; }else{ $file_mod = UQCMS_PATH.'module/'.$module_name.".mod.php"; if(file_exists($file_mod)){ include_once $file_mod; $module_name = $module_name.'_mod'; $mod_class[$module_name] = new $module_name(); }else{ error_404('在模版中,读取的文件是不纯在的[mytpl.class.php]'); } } return $mod_class[$module_name]; } function print_current_dates($params){ pr($params); $url_m = $params['m']; $url_a = $params['a']; if(cfg('is_write') == '1' ){ } $url = cfg('site_path').$url_m."/".$url_a.".html"; return $url; } function load_module($params){ $arr=explode(':',$params['c']); $a = strpos($arr[1],'='); if($a == false){ $set_params = $this->check_GPRS($arr[1]); }else{ $p_data = explode('&',$arr[1]); for($i=0;$i<count($p_data);$i++){ $p_datas = explode('=',$p_data[$i]); $set_params[$p_datas[0]] = $this->check_GPRS($p_datas[1]); } } $action = $arr[0]; if($action){ $data = $this->module($params['m'])->$action($set_params); $this->assign($params['v'],$data); } } function load_ads($params){ $alias = $params['alias']; $data = $this->module('ad')->alias($alias); $this->assign($params['data'],$data); } function load_url($params){ $string = $params['path']; $arr = explode('?', $string); if($arr[0] == 'index.php'){ $name = ''; } if(!empty($arr[1])){ $arr2 = explode('&', $arr[1]); foreach($arr2 as $val){ list($val, $fun) = explode('=',$val); } } return $path; } function url($string){ $arr = explode('?', $string); if($arr[0] == 'index.php'){ $name = ''; } $a = parse_url($string); $aaa = parse_str($a['query']); pr($aaa); if(!empty($arr[1])){ $arr2 = explode('&', $string); foreach($arr2 as $v){ } } return $string; } function check_GPRS($params){ if(substr($params,0,6) == 'smarty'){ $paDot = explode('.',$params); if($paDot[1] == 'get'){ return $_GET[$paDot[2]]; }elseif($paDot[1] == 'session'){ return $_SESSION[$paDot[2]]; }elseif($paDot[1] == 'post'){ return $_POST[$paDot[2]]; }elseif($paDot[1] == 'cookie'){ return $_COOKIE[$paDot[2]]; } }else{ return $params; } } function img_size($string, $file_size = '150x150'){ return img_size($file_size, $string); } public function displays($tpl = NULL){ global $method,$action; $this->register_function('url', array($this, 'print_current_dates')); $this->register_function('uqcms', array($this, 'load_module')); $this->register_function('ads', array($this, 'load_ads')); $this->register_function('url', array($this, 'load_url')); $this->register_function('import', array($this, 'import')); $this->register_modifier('img_size', array($this, 'img_size')); $this->register_modifier('url', array($this, 'url')); $serverName = $_SERVER['PHP_SELF']?$_SERVER['PHP_SELF']:$_SERVER['SCRIPT_NAME']; $pc_tpl = substr($serverName, -9); $wap_tpl = substr($serverName, -7); if(($pc_tpl == 'index.php' ) || ($wap_tpl == 'wap.php')){ if($pc_tpl == 'index.php'){ $site_tpl = cfg('site_tpl_pc'); $this->tpl_addr = $site_tpl.'/'; }elseif($wap_tpl == 'wap.php'){ $site_tpl = cfg('site_tpl_wap'); $this->tpl_addr = $site_tpl.'/'; }else{ $this->tpl_addr = 'default/'; } }else{ $this->tpl_addr = ''; } if(!empty($tpl)){ $temp_url = UQCMS_APP_PATH.'templates/'.$this->tpl_addr.$tpl.".html"; }else{ $temp_url = UQCMS_APP_PATH.'templates/'.$this->tpl_addr.$method."/".$action.".html"; if(!file_exists($temp_url)){ error_404('没有找到对应的模板[mytpl.class.php]'); } } $this->assign('__HOST__', cfg('site_url')); $this->assign('__PUBLIC__', cfg('site_path').'public/'); $this->assign('__APP__', cfg('site_path').UQCMS_APP.'/templates/'.$this->tpl_addr); $this->assign('__URL__', cfg('site_path')); $this->assign('__IMG__', img_host()); $this->assign('js_version', time()); $this->assign('UQCMS', cfg()); parent::display($temp_url); } function import($arr){ if(count($arr) != '1'){ foreach($arr as $key=>$val){ if($key != 'file'){ $name = $arr[$key]; $this->assign($key, $val); } } } $file = $arr['file']?$arr['file']:''; $file = $this->tpl_addr.$file; $this->display($file); } } 