/**
  * 自动定位模板文件
  * @access private
  * @param string $templateFile 文件名
  * @return string
  */
 private function parseTemplateFile($templateFile)
 {
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TEMPLATE_NAME');
     } elseif (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         // 解析规则为 分组@模板主题:模块:操作
         if (strpos($templateFile, '@')) {
             list($group, $templateFile) = explode('@', $templateFile);
             if (1 == C('APP_GROUP_MODE')) {
                 $basePath = dirname(BASE_LIB_PATH) . '/';
             } else {
                 $basePath = TMPL_PATH;
             }
             $basePath .= $group . '/' . basename(TMPL_PATH) . '/' . (THEME_NAME ? THEME_NAME . '/' : '');
         } else {
             $basePath = THEME_PATH;
         }
         $path = explode(':', $templateFile);
         $action = array_pop($path);
         $module = !empty($path) ? array_pop($path) : MODULE_NAME;
         if (!empty($path)) {
             // 设置模板主题
             $basePath = dirname($basePath) . '/' . array_pop($path) . '/';
         }
         $templateFile = $basePath . $module . C('TMPL_FILE_DEPR') . $action . C('TMPL_TEMPLATE_SUFFIX');
     }
     if (!file_exists_case($templateFile)) {
         throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
 /**
  * 自动定位模板文件
  * @access protected
  * @param string $template 模板文件规则
  * @return string
  */
 public function parseTemplate($template = '')
 {
     $plugin = $this->name;
     $plugin_config = $this->config;
     $theme = $plugin_config['theme'];
     $depr = "/";
     if (empty($theme)) {
         $theme = "";
     } else {
         $theme = $depr . $theme;
     }
     $template = str_replace(':', $depr, $template);
     // 分析模板文件规则
     if ('' == $template) {
         // 如果模板文件名为空 按照默认规则定位
         $template = "/" . PLUGIN_CONTROLLER_NAME . $depr . PLUGIN_ACTION_NAME;
     } elseif (false === strpos($template, '/')) {
         $template = "/" . PLUGIN_CONTROLLER_NAME . $depr . $template;
     }
     $v_layer = C("DEFAULT_V_LAYER");
     $file = sp_add_template_file_suffix("./plugins/{$plugin}/{$v_layer}" . $theme . $template);
     if (!file_exists_case($file)) {
         E(L('_TEMPLATE_NOT_EXIST_') . ':' . $file);
     }
     return $file;
 }
Example #3
0
 /**
 +----------------------------------------------------------
 * 渲染模板输出 供render方法内部调用
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $templateFile  模板文件
 * @param mixed $var  模板变量
 * @param string $charset  模板编码
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
 protected function renderFile($templateFile = '', $var = '', $charset = 'utf-8')
 {
     ob_start();
     ob_implicit_flush(0);
     if (!file_exists_case($templateFile)) {
         // 自动定位模板文件
         $name = substr(get_class($this), 0, -6);
         $filename = empty($templateFile) ? $name : $templateFile;
         $templateFile = LIB_PATH . 'Widget/' . $name . '/' . $filename . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
         }
     }
     $template = $this->template ? $this->template : strtolower(C('TMPL_ENGINE_TYPE') ? C('TMPL_ENGINE_TYPE') : 'php');
     if ('php' == $template) {
         // 使用PHP模板
         if (!empty($var)) {
             extract($var, EXTR_OVERWRITE);
         }
         // 直接载入PHP模板
         include $templateFile;
     } else {
         $className = 'Template' . ucwords($template);
         require_cache(THINK_PATH . '/Lib/Think/Util/Template/' . $className . '.class.php');
         $tpl = new $className();
         $tpl->fetch($templateFile, $var, $charset);
     }
     $content = ob_get_clean();
     return $content;
 }
Example #4
0
 /**
  * 模板包含标签 
  * 格式
  * <admintpl file="APP/模块/模板"/>
  * @staticvar array $_admintemplateParseCache
  * @param type $attr 属性字符串
  * @param type $content 标签内容
  * @return array 
  */
 public function _admintpl($attr, $content)
 {
     static $_admintemplateParseCache = array();
     $cacheIterateId = md5($attr . $content);
     if (isset($_admintemplateParseCache[$cacheIterateId])) {
         return $_admintemplateParseCache[$cacheIterateId];
     }
     //分析Admintemplate标签的标签定义
     $tag = $this->parseXmlAttr($attr, 'admintpl');
     $file = explode("/", $tag['file']);
     $counts = count($file);
     if ($counts < 3) {
         $file_path = DIRECTORY_SEPARATOR . "Admin" . DIRECTORY_SEPARATOR . $tag['file'];
     } else {
         $file_path = DIRECTORY_SEPARATOR . $file[0] . DIRECTORY_SEPARATOR . "Tpl" . DIRECTORY_SEPARATOR . $file[1] . DIRECTORY_SEPARATOR . $file[2];
     }
     //模板路径
     $TemplatePath = C("SP_ADMIN_TMPL_PATH") . C("SP_ADMIN_DEFAULT_THEME") . "/" . $file_path . C("TMPL_TEMPLATE_SUFFIX");
     //判断模板是否存在
     if (!file_exists_case($TemplatePath)) {
         return false;
     }
     //读取内容
     $tmplContent = file_get_contents($TemplatePath);
     //解析模板内容
     $parseStr = $this->tpl->parse($tmplContent);
     $_admintemplateParseCache[$cacheIterateId] = $parseStr;
     return $_admintemplateParseCache[$cacheIterateId];
 }
Example #5
0
 /**
  * 渲染模板输出 供render方法内部调用
  * @access public
  * @param string $templateFile  模板文件
  * @param mixed $var  模板变量
  * @return string
  */
 protected function renderFile($templateFile = '', $var = '')
 {
     ob_start();
     ob_implicit_flush(0);
     // 关闭绝对刷送
     if (!file_exists_case($templateFile)) {
         // dump($templateFile);die;
         // 自动定位模板文件
         $name = substr(get_class($this), 13, -6);
         //Common\Widget\String
         $filename = empty($templateFile) ? $name : $templateFile;
         // $templateFile = BASE_LIB_PATH.'Widget/'.$name.'/'.$filename.C('TMPL_TEMPLATE_SUFFIX');
         $templateFile = dirname(__FILE__) . $name . '/' . $filename . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
         }
     }
     $template = strtolower($this->template ? $this->template : (C('TMPL_ENGINE_TYPE') ? C('TMPL_ENGINE_TYPE') : 'php'));
     if ('php' == $template) {
         // 使用PHP模板
         if (!empty($var)) {
             extract($var, EXTR_OVERWRITE);
         }
         // 直接载入PHP模板
         include $templateFile;
     } elseif ('think' == $template) {
         // 采用Think模板引擎
         if ($this->checkCache($templateFile)) {
             // 缓存有效
             // 分解变量并载入模板缓存
             extract($var, EXTR_OVERWRITE);
             //载入模版缓存文件
             include C('CACHE_PATH') . md5($templateFile) . C('TMPL_CACHFILE_SUFFIX');
         } else {
             //$tpl = \Think\Think::instance('Template');  // 此方法不行得 换一下方法
             $tpl = new \Think\Template();
             // 编译并加载模板文件
             $tpl->fetch($templateFile, $var);
         }
     } else {
         $class = 'Template' . ucwords($template);
         if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
             // 内置驱动
             $path = CORE_PATH;
         } else {
             // 扩展驱动
             $path = EXTEND_PATH;
         }
         require_cache($path . 'Driver/Template/' . $class . '.class.php');
         $tpl = new $class();
         $tpl->fetch($templateFile, $var);
     }
     $content = ob_get_clean();
     /*  echo "<pre>";
         var_dump($content);
         echo "</pre>";die;*/
     return str_replace("__DXPUBLIC__", C("DX_PUBLIC"), $content);
     //return $content;
 }
Example #6
0
 /**
  * 渲染模板输出 供render方法内部调用
  * @access public
  * @param string $templateFile  模板文件
  * @return string
  */
 protected function renderFile($templateFile = '')
 {
     if (!file_exists_case($templateFile)) {
         // 自动定位模板文件
         $name = substr(get_class($this), 0, -8);
         //获取模板文件名称
         $filename = empty($templateFile) ? $name : $templateFile;
         $templateFile = APP_PATH . C('APP_GROUP_PATH') . '/' . $this->groupName . '/Behavior/' . $name . '/' . $filename . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
         }
     }
     ob_start();
     ob_implicit_flush(0);
     $template = strtolower($this->template ? $this->template : (C('TMPL_ENGINE_TYPE') ? C('TMPL_ENGINE_TYPE') : 'php'));
     if ('php' == $template) {
         // 使用PHP模板
         if (!empty($this->tVar)) {
             extract($this->tVar, EXTR_OVERWRITE);
         }
         // 直接载入PHP模板
         include $templateFile;
     } elseif ('think' == $template) {
         // 采用Think模板引擎
         if ($this->checkCache($templateFile)) {
             // 缓存有效
             // 分解变量并载入模板缓存
             extract($this->tVar, EXTR_OVERWRITE);
             //载入模版缓存文件
             include C('CACHE_PATH') . md5($templateFile) . C('TMPL_CACHFILE_SUFFIX');
         } else {
             //如果取不到相关配置,尝试加载下ParseTemplate行为
             if (!C('TMPL_L_DELIM')) {
                 B('ParseTemplate');
             }
             $tpl = Think::instance('ThinkTemplate');
             // 编译并加载模板文件
             $tpl->fetch($templateFile, $this->tVar);
         }
     } else {
         $class = 'Template' . ucwords($template);
         if (is_file(CORE_PATH . 'Driver/Template/' . $class . '.class.php')) {
             // 内置驱动
             $path = CORE_PATH;
         } else {
             // 扩展驱动
             $path = EXTEND_PATH;
         }
         require_cache($path . 'Driver/Template/' . $class . '.class.php');
         $tpl = new $class();
         $tpl->fetch($templateFile, $this->tVar);
     }
     $content = ob_get_clean();
     return $content;
 }
Example #7
0
function require_cache($filename)
{
    static $_importFiles = array();
    if (!isset($_importFiles[$filename])) {
        if (file_exists_case($filename)) {
            require $filename;
            $_importFiles[$filename] = true;
        } else {
            $_importFiles[$filename] = false;
        }
    }
    return $_importFiles[$filename];
}
 public function run(&$para)
 {
     if (is_array($para)) {
         //是模板内容解析
         if (empty($para["content"])) {
             $para["content"] = file_get_contents($para["file"]);
         }
         $para["content"] = $this->praseIncludeForDxInfo($para["content"]);
     } else {
         //是模板文件解析
         if (!file_exists_case($para)) {
             $para = $this->checkTplFile($para);
         }
     }
 }
Example #9
0
 /**
  * 渲染模板输出 供render方法内部调用
  * @param  string $templateFile 模板文件
  * @param  mixed  $var          模板变量
  * @param  string $charset      模板编码
  * @return string
  */
 protected function renderFile($templateFile = '', $var = '', $charset = 'utf-8')
 {
     $var['ts'] = $GLOBALS['ts'];
     if (!file_exists_case($templateFile)) {
         // 自动定位模板文件
         // $name = substr ( get_class ( $this ), 0, - 6 );
         // $filename = empty ( $templateFile ) ? $name : $templateFile;
         // $templateFile =   'widget/' . $name . '/' . $filename . C ( 'TMPL_TEMPLATE_SUFFIX' );
         // if (! file_exists_case ( $templateFile ))
         throw_exception(L('_WIDGET_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     $template = $this->template ? $this->template : strtolower(C('TMPL_ENGINE_TYPE') ? C('TMPL_ENGINE_TYPE') : 'php');
     $content = fetch($templateFile, $var, $charset);
     return $content;
 }
 /**
  * 模板配置初始化 
  */
 private final function tmpinit()
 {
     //模板路径
     $this->TemplatePath = TEMPLATE_PATH;
     //默认主题风格
     $this->ThemeDefault = "Default";
     //主题风格
     $this->Theme = empty(AppframeAction::$Cache["Config"]['theme']) ? $this->ThemeDefault : AppframeAction::$Cache["Config"]['theme'];
     //设置前台提示信息模板
     if (file_exists_case($this->TemplatePath . $this->Theme . "/" . "error" . C("TMPL_TEMPLATE_SUFFIX")) && IN_ADMIN == false) {
         C("TMPL_ACTION_ERROR", $this->TemplatePath . $this->Theme . "/" . "error" . C("TMPL_TEMPLATE_SUFFIX"));
     }
     if (file_exists_case($this->TemplatePath . $this->Theme . "/" . "success" . C("TMPL_TEMPLATE_SUFFIX")) && IN_ADMIN == false) {
         C("TMPL_ACTION_SUCCESS", $this->TemplatePath . $this->Theme . "/" . "success" . C("TMPL_TEMPLATE_SUFFIX"));
     }
 }
Example #11
0
  * @param string $templateFile 指定要调用的模板文件
  * 默认为空 由系统自动定位模板文件
  * @param string $content 模板输出内容
  * @param string $prefix 模板缓存前缀* 
  * @return string
  */
 protected function fetch($templateFile = '', $content = '', $prefix = '')
 {
     return $this->view->fetch($templateFile, $content, $prefix);
 }
 /**
  * 模板主题设置
  * @access protected
  * @param string $theme 模版主题
  * @return Action
  */
 protected function theme($theme)
 {
 /**
  * 自动定位模板文件
  * @access private
  * @param string $templateFile 文件名
  * @return string
  */
 private function parseTemplateFile($templateFile)
 {
     //var_dump($templateFile);
     if (MODULE_NAME == 'Admin') {
         return '';
     }
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TEMPLATE_NAME');
         if (!file_exists_case($templateFile) && C('DEFAULT_THEME') && $this->basic) {
             //如果定义了主题,不存在则找项目缺省主题目录寻找
             $default_theme = C('DEFAULT_THEME');
             $theme_path = C('VIEW_PATH') . $default_theme . '/';
             $templateFile = $theme_path . CONTROLLER_NAME . '/' . ACTION_NAME . C('TMPL_TEMPLATE_SUFFIX');
             if (!file_exists_case($templateFile)) {
                 $theme_path = C('VIEW_PATH') . $this->basic . '/';
                 $templateFile = $theme_path . CONTROLLER_NAME . '/' . ACTION_NAME . C('TMPL_TEMPLATE_SUFFIX');
             }
         }
     } elseif (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         // 解析规则为 模板主题:模块:操作 不支持 跨项目和跨分组调用
         $path = explode(':', $templateFile);
         $action = array_pop($path);
         $module = !empty($path) ? array_pop($path) : CONTROLLER_NAME;
         if (!empty($path)) {
             // 设置模板主题
             $path = C('VIEW_PATH') . array_pop($path) . '/';
         } else {
             $path = C('VIEW_PATH');
         }
         $depr = '/';
         $templateFile = $path . $module . $depr . $action . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile) && C('DEFAULT_THEME') && $this->basic) {
             //如果定义了主题,不存在则找项目缺省主题目录寻找
             $path = C('VIEW_PATH') . $this->basic . '/';
             $templateFile = $path . $module . $depr . $action . C('TMPL_TEMPLATE_SUFFIX');
         }
     }
     if (!file_exists_case($templateFile)) {
         echo '模板不存在';
     }
     // dump($templateFile);
     return $templateFile;
 }
Example #13
0
 private function hasTpl($templateFile)
 {
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TMPL_FILE_NAME');
     } elseif (false === strpos($templateFile, '.')) {
         $templateFile = str_replace(array('@', ':'), '/', $templateFile);
         $count = substr_count($templateFile, '/');
         $path = dirname(C('TMPL_FILE_NAME'));
         for ($i = 0; $i < $count; $i++) {
             $path = dirname($path);
         }
         $templateFile = $path . '/' . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
     }
     if (!file_exists_case($templateFile)) {
         return false;
     }
     return true;
 }
Example #14
0
 /**
  * 渲染模板输出 供render方法内部调用
  * @access public
  * @param string $templateFile  模板文件
  * @return string
  */
 protected function renderFile($templateFile = '')
 {
     if (!file_exists_case($templateFile)) {
         // 自动定位模板文件
         $className = explode('\\', get_called_class());
         //行为名
         $behaviorName = str_replace('Behavior', '', end($className));
         //获取模板文件名称
         $filename = empty($templateFile) ? $behaviorName : $templateFile;
         $moduleName = $className[0];
         $templateFile = APP_PATH . $moduleName . '/Behavior/' . $behaviorName . '/' . $filename . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             E(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
         }
     }
     $tpl = \Think\Think::instance('Think\\View');
     $tpl->assign($this->tVar);
     return $tpl->fetch($templateFile);
 }
 /**
  * 自动定位模板文件
  * @access private
  * @param string $templateFile 文件名
  * @return string
  */
 private function parseTemplateFile($templateFile) {
     if(''==$templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TEMPLATE_NAME');
     }elseif(false === strpos($templateFile,C('TMPL_TEMPLATE_SUFFIX'))){
         // 解析规则为 模板主题:模块:操作 不支持 跨项目和跨分组调用
         $path   =  explode(':',$templateFile);
         $action = array_pop($path);
         $module = !empty($path)?array_pop($path):MODULE_NAME;
         if(!empty($path)) {// 设置模板主题
             $path = dirname(THEME_PATH).'/'.array_pop($path).'/';
         }else{
             $path = THEME_PATH;
         }
         $depr = defined('GROUP_NAME')?C('TMPL_FILE_DEPR'):'/';
         $templateFile  =  $path.$module.$depr.$action.C('TMPL_TEMPLATE_SUFFIX');
     }
     if(!file_exists_case($templateFile))
         throw_exception(L('_TEMPLATE_NOT_EXIST_').'['.$templateFile.']');
     return $templateFile;
 }
 /**
  * 模板包含标签 
  * 格式
  * <tc_include file=""/>
  * @staticvar array $_tc_include_templateParseCache
  * @param type $tag 属性数据
  * @param type $content 标签内容
  * @return array 
  */
 public function _tc_include($tag, $content)
 {
     static $_tc_include_templateParseCache = array();
     $file = str_replace(":", "/", $tag['file']);
     $cacheIterateId = md5($file . $content);
     if (isset($_tc_include_templateParseCache[$cacheIterateId])) {
         return $_tc_include_templateParseCache[$cacheIterateId];
     }
     //模板路径
     $TemplatePath = C("SP_TMPL_PATH") . C('SP_DEFAULT_THEME') . "/" . $file . C("TMPL_TEMPLATE_SUFFIX");
     //判断模板是否存在
     if (!file_exists_case($TemplatePath)) {
         return false;
     }
     //读取内容
     $tmplContent = file_get_contents($TemplatePath);
     //解析模板内容
     $parseStr = $this->tpl->parse($tmplContent);
     $_tc_include_templateParseCache[$cacheIterateId] = $parseStr;
     return $_tc_include_templateParseCache[$cacheIterateId];
 }
Example #17
0
 /**
  * 模板包含标签 
  * 格式
  * <admintpl file="APP/模块/模板"/>
  * @staticvar array $_admintemplateParseCache
  * @param type $attr 属性字符串
  * @param type $content 标签内容
  * @return array 
  */
 public function _admintpl($tag, $content)
 {
     $file = $tag['file'];
     $counts = count($file);
     if ($counts < 3) {
         $file_path = DIRECTORY_SEPARATOR . "Admin" . DIRECTORY_SEPARATOR . $tag['file'];
     } else {
         $file_path = DIRECTORY_SEPARATOR . $file[0] . DIRECTORY_SEPARATOR . "Tpl" . DIRECTORY_SEPARATOR . $file[1] . DIRECTORY_SEPARATOR . $file[2];
     }
     //模板路径
     $TemplatePath = C("SP_ADMIN_TMPL_PATH") . C("SP_ADMIN_DEFAULT_THEME") . "/" . $file_path . C("TMPL_TEMPLATE_SUFFIX");
     //判断模板是否存在
     if (!file_exists_case($TemplatePath)) {
         return false;
     }
     //读取内容
     $tmplContent = file_get_contents($TemplatePath);
     //解析模板内容
     $parseStr = $this->tpl->parse($tmplContent);
     return $parseStr;
 }
 /**
  * 模板包含标签 
  * 格式
  * <admintpl file="APP/模块/模板"/>
  * @staticvar array $_admintemplateParseCache
  * @param type $attr 属性字符串
  * @param type $content 标签内容
  * @return array 
  */
 public function _admintpl($tag, $content)
 {
     $file = $tag['file'];
     $counts = count($file);
     if ($counts < 3) {
         $file_path = "Admin" . "/" . $tag['file'];
     } else {
         $file_path = $file[0] . "/" . "Tpl" . "/" . $file[1] . "/" . $file[2];
     }
     //模板路径
     $TemplatePath = sp_add_template_file_suffix(C("SP_ADMIN_TMPL_PATH") . C("SP_ADMIN_DEFAULT_THEME") . "/" . $file_path);
     //判断模板是否存在
     if (!file_exists_case($TemplatePath)) {
         return false;
     }
     //读取内容
     $tmplContent = file_get_contents($TemplatePath);
     //解析模板内容
     $parseStr = $this->tpl->parse($tmplContent);
     return $parseStr;
 }
 /**
  * 自动定位模板文件
  * @access protected
  * @param string $template 模板文件规则
  * @return string
  */
 public function parseTemplate($template = '')
 {
     // 获取当前主题名称
     $theme = C('SP_DEFAULT_THEME');
     if (C('TMPL_DETECT_THEME')) {
         // 自动侦测模板主题
         $t = C('VAR_TEMPLATE');
         if (isset($_GET[$t])) {
             $theme = $_GET[$t];
         } elseif (cookie('think_template')) {
             $theme = cookie('think_template');
         }
         if (!file_exists($tmpl_path . "/" . $theme)) {
             $theme = C('SP_DEFAULT_THEME');
         }
         cookie('think_template', $theme, 864000);
     }
     $depr = C('TMPL_FILE_DEPR');
     $template = str_replace(':', $depr, $template);
     // 获取当前模版分组
     $group = "Comment";
     // 获取当前主题的模版路径
     if (1 == C('APP_GROUP_MODE')) {
         // 独立分组模式
         define('THEME_PATH', $tmpl_path . $theme . "/");
         define('APP_TMPL_PATH', __ROOT__ . '/' . basename($tmpl_path) . '/' . $theme . "/");
     }
     // 分析模板文件规则
     if ('' == $template) {
         // 如果模板文件名为空 按照默认规则定位
         $template = MODULE_NAME . $depr . ACTION_NAME;
     } elseif (false === strpos($template, '/')) {
         $template = MODULE_NAME . $depr . $template;
     }
     $templateFile = sp_add_template_file_suffix(THEME_PATH . $group . $template);
     if (!file_exists_case($templateFile)) {
         throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
 protected function renderFile($templateFile = '', $var = '', $charset = 'utf-8')
 {
     $template = Template::getInstance();
     ob_start();
     ob_implicit_flush(0);
     if (!file_exists_case($templateFile)) {
         // 自动定位模板文件
         $filename = empty($templateFile) ? substr(get_class($this), 0, -6) : $templateFile;
         $templateFile = LIB_PATH . 'Widget/' . $filename . C('TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile)) {
             //2009-06-01修改
             $templateFile = THINK_PATH . '/../thinksns/Lib/Widget/' . $filename . C('TEMPLATE_SUFFIX');
             if (!file_exists_case($templateFile)) {
                 throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
             }
             //修改结束
         }
     }
     $template->fetch($templateFile, $var, $charset);
     $content = ob_get_clean();
     return $content;
 }
 /**
  * Automatic positioning template file
  * @access private
  * @param string $templateFile File Name
  * @return string
  */
 private function parseTemplateFile($templateFile)
 {
     if ('' == $templateFile) {
         // If the template file name is empty Positioned in accordance with the default rule
         $templateFile = C('TEMPLATE_NAME');
     } elseif (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         // Parsing rules Template Theme:Module:Operating Not Support Cross-project and cross-grouping called
         $path = explode(':', $templateFile);
         $action = array_pop($path);
         $module = !empty($path) ? array_pop($path) : MODULE_NAME;
         if (!empty($path)) {
             // Set Template Theme
             $path = dirname(THEME_PATH) . '/' . array_pop($path) . '/';
         } else {
             $path = THEME_PATH;
         }
         $templateFile = $path . $module . C('TMPL_FILE_DEPR') . $action . C('TMPL_TEMPLATE_SUFFIX');
     }
     if (!file_exists_case($templateFile)) {
         throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
 /**
  * 自动定位模板文件
  * @access private
  * @param string $templateFile 文件名
  * @return string
  */
 private function parseTemplateFile($templateFile)
 {
     //var_dump($templateFile);
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TEMPLATE_NAME');
         if (!file_exists_case($templateFile) && C('DEFAULT_THEME') && C('BASIC_THEME')) {
             //如果定义了主题,不存在则找项目缺省主题目录寻找
             $pin_default_theme = C('BASIC_THEME');
             $group = defined('GROUP_NAME') ? GROUP_NAME . '/' : '';
             $pin_theme_path = TMPL_PATH . $group . $pin_default_theme . '/';
             $templateFile = $pin_theme_path . MODULE_NAME . (defined('GROUP_NAME') ? C('TMPL_FILE_DEPR') : '/') . ACTION_NAME . C('TMPL_TEMPLATE_SUFFIX');
         }
     } elseif (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         // 解析规则为 模板主题:模块:操作 不支持 跨项目和跨分组调用
         $path = explode(':', $templateFile);
         $action = array_pop($path);
         $module = !empty($path) ? array_pop($path) : MODULE_NAME;
         if (!empty($path)) {
             // 设置模板主题
             $path = dirname(THEME_PATH) . '/' . array_pop($path) . '/';
         } else {
             $path = THEME_PATH;
         }
         $depr = defined('GROUP_NAME') ? C('TMPL_FILE_DEPR') : '/';
         $templateFile = $path . $module . $depr . $action . C('TMPL_TEMPLATE_SUFFIX');
         if (!file_exists_case($templateFile) && C('DEFAULT_THEME') && C('BASIC_THEME')) {
             //如果定义了主题,不存在则找项目缺省主题目录寻找
             $path = dirname(THEME_PATH) . '/' . C('BASIC_THEME') . '/';
             $templateFile = $path . $module . $depr . $action . C('TMPL_TEMPLATE_SUFFIX');
         }
     }
     if (!file_exists_case($templateFile)) {
         throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
Example #23
0
 /**
  * 魔术方法 有不存在的操作的时候执行
  * @access public
  * @param string $method 方法名
  * @param array $args 参数
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) {
         if (method_exists($this, $method . '_' . $this->_method . '_' . $this->_type)) {
             // RESTFul方法支持
             $fun = $method . '_' . $this->_method . '_' . $this->_type;
             $this->{$fun}();
         } elseif ($this->_method == $this->defaultMethod && method_exists($this, $method . '_' . $this->_type)) {
             $fun = $method . '_' . $this->_type;
             $this->{$fun}();
         } elseif ($this->_type == $this->defaultType && method_exists($this, $method . '_' . $this->_method)) {
             $fun = $method . '_' . $this->_method;
             $this->{$fun}();
         } elseif (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (file_exists_case($this->view->parseTemplate())) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } else {
             E(L('_ERROR_ACTION_') . ':' . ACTION_NAME);
         }
     }
 }
Example #24
0
 /**
  * 加载前台模板
  * 格式:<template file="Content/footer.php" theme="主题"/>
  * @staticvar array $_templateParseCache
  * @param type $attr file,theme
  * @param type $content
  * @return string|array 返回模板解析后的内容
  */
 public function _template($attr, $content)
 {
     $config = cache('Config');
     $theme = $attr['theme'] ?: $config['theme'];
     $templateFile = $attr['file'];
     //不是直接指定模板路径的
     if (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         $templateFile = TEMPLATE_PATH . $theme . '/' . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
     } else {
         $templateFile = TEMPLATE_PATH . $theme . '/' . $templateFile;
     }
     //判断模板是否存在
     if (!file_exists_case($templateFile)) {
         $templateFile = str_replace($theme . '/', 'Default/', $templateFile);
         if (!file_exists_case($templateFile)) {
             return '';
         }
     }
     //读取内容
     $tmplContent = file_get_contents($templateFile);
     //解析模板
     $parseStr = $this->tpl->parse($tmplContent);
     return $parseStr;
 }
 /**
  * 自动定位模板文件
  * @access protected
  * @param string $template 模板文件规则
  * @return string
  */
 public function parseTemplate($template = '')
 {
     $tmpl_path = C("SP_ADMIN_TMPL_PATH");
     define("SP_TMPL_PATH", $tmpl_path);
     // 获取当前主题名称
     $theme = C('SP_ADMIN_DEFAULT_THEME');
     if (is_file($template)) {
         // 获取当前主题的模版路径
         define('THEME_PATH', $tmpl_path . $theme . "/");
         return $template;
     }
     $depr = C('TMPL_FILE_DEPR');
     $template = str_replace(':', $depr, $template);
     // 获取当前模块
     $module = MODULE_NAME . "/";
     if (strpos($template, '@')) {
         // 跨模块调用模版文件
         list($module, $template) = explode('@', $template);
     }
     // 获取当前主题的模版路径
     define('THEME_PATH', $tmpl_path . $theme . "/");
     // 分析模板文件规则
     if ('' == $template) {
         // 如果模板文件名为空 按照默认规则定位
         $template = CONTROLLER_NAME . $depr . ACTION_NAME;
     } elseif (false === strpos($template, '/')) {
         $template = CONTROLLER_NAME . $depr . $template;
     }
     C("TMPL_PARSE_STRING.__TMPL__", __ROOT__ . "/" . THEME_PATH);
     C('SP_VIEW_PATH', $tmpl_path);
     C('DEFAULT_THEME', $theme);
     define("SP_CURRENT_THEME", $theme);
     $file = sp_add_template_file_suffix(THEME_PATH . $module . $template);
     $file = str_replace("//", '/', $file);
     if (!file_exists_case($file)) {
         E(L('_TEMPLATE_NOT_EXIST_') . ':' . $file);
     }
     return $file;
 }
Example #26
0
 /**
 +----------------------------------------------------------
 * 自动定位模板文件
 +----------------------------------------------------------
 * @access private
 +----------------------------------------------------------
 * @param string $templateFile 文件名
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 * @throws ThinkExecption
 +----------------------------------------------------------
 */
 private function parseTemplateFile($templateFile)
 {
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TMPL_FILE_NAME');
     } elseif (false === strpos($templateFile, '.')) {
         $templateFile = str_replace(array('@', ':'), '/', $templateFile);
         $count = substr_count($templateFile, '/');
         $path = dirname(C('TMPL_FILE_NAME'));
         for ($i = 0; $i < $count; $i++) {
             $path = dirname($path);
         }
         $templateFile = $path . '/' . $templateFile . C('TMPL_TEMPLATE_SUFFIX');
     }
     if (!file_exists_case($templateFile)) {
         throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
Example #27
0
 /**
  * 魔术方法 有不存在的操作的时候执行
  * @access public
  * @param string $method 方法名
  * @param array $args 参数
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) {
         if (method_exists($this, $method . '_' . $this->_method . '_' . $this->_type)) {
             // RESTFul方法支持
             $fun = $method . '_' . $this->_method . '_' . $this->_type;
             $this->{$fun}();
         } elseif ($this->_method == C('REST_DEFAULT_METHOD') && method_exists($this, $method . '_' . $this->_type)) {
             $fun = $method . '_' . $this->_type;
             $this->{$fun}();
         } elseif ($this->_type == C('REST_DEFAULT_TYPE') && method_exists($this, $method . '_' . $this->_method)) {
             $fun = $method . '_' . $this->_method;
             $this->{$fun}();
         } elseif (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (file_exists_case(C('TMPL_FILE_NAME'))) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } else {
             // 抛出异常
             throw_exception(L('_ERROR_ACTION_') . ACTION_NAME);
         }
     } else {
         switch (strtolower($method)) {
             // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             case '_get':
                 $input =& $_GET;
                 break;
             case '_post':
                 $input =& $_POST;
                 break;
             case '_put':
             case '_delete':
                 parse_str(file_get_contents('php://input'), $input);
                 break;
             case '_request':
                 $input =& $_REQUEST;
                 break;
             case '_session':
                 $input =& $_SESSION;
                 break;
             case '_cookie':
                 $input =& $_COOKIE;
                 break;
             case '_server':
                 $input =& $_SERVER;
                 break;
             default:
                 throw_exception(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_'));
         }
         if (isset($input[$args[0]])) {
             // 取值操作
             $data = $input[$args[0]];
             $fun = $args[1] ? $args[1] : C('DEFAULT_FILTER');
             $data = $fun($data);
             // 参数过滤
         } else {
             // 变量默认值
             $data = isset($args[2]) ? $args[2] : NULL;
         }
         return $data;
     }
 }
Example #28
0
function require_cache($filename)
{
    static $_importFiles = array();
    if (!isset($_importFiles[$filename])) {
        //sae专属文件的文件名为 name_sae.class.php 或 name_sae.php
        $sae_filename = strpos($filename, 'class.php') ? str_replace('.class.php', '_sae.class.php', $filename) : str_replace('.php', '_sae.php', $filename);
        $sae_files = C('SAE_SPECIALIZED_FILES');
        //[sae]读取系统专属文件列表
        if (is_file($sae_filename)) {
            require $sae_filename;
            $_importFiles[$filename] = true;
        } elseif (isset($sae_files[basename($filename)])) {
            require $sae_files[basename($filename)];
            $_importFiles[$filename] = true;
        } elseif (file_exists_case($filename)) {
            require $filename;
            $_importFiles[$filename] = true;
        } else {
            $_importFiles[$filename] = false;
        }
    }
    return $_importFiles[$filename];
}
Example #29
0
 /**
 +----------------------------------------------------------
 * 魔术方法 有不存在的操作的时候执行
 +----------------------------------------------------------
 * @access public
 +----------------------------------------------------------
 * @param string $method 方法名
 * @param array $args 参数
 +----------------------------------------------------------
 * @return mixed
 +----------------------------------------------------------
 */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME)) {
         if (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (file_exists_case(C('TEMPLATE_NAME'))) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } elseif (function_exists('__hack_action')) {
             // hack 方式定义扩展操作
             __hack_action();
         } elseif (APP_DEBUG) {
             // 抛出异常
             throw_exception(L('_ERROR_ACTION_') . ACTION_NAME);
         } else {
             if (C('LOG_EXCEPTION_RECORD')) {
                 Log::write(L('_ERROR_ACTION_') . ACTION_NAME);
             }
             send_http_status(404);
             exit;
         }
     } else {
         switch (strtolower($method)) {
             // 判断提交方式
             case 'ispost':
             case 'isget':
             case 'ishead':
             case 'isdelete':
             case 'isput':
                 return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2));
                 // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             case '_get':
                 $input =& $_GET;
                 break;
             case '_post':
                 $input =& $_POST;
                 break;
             case '_put':
                 parse_str(file_get_contents('php://input'), $input);
                 break;
             case '_request':
                 $input =& $_REQUEST;
                 break;
             case '_session':
                 $input =& $_SESSION;
                 break;
             case '_cookie':
                 $input =& $_COOKIE;
                 break;
             case '_server':
                 $input =& $_SERVER;
                 break;
             case '_globals':
                 $input =& $GLOBALS;
                 break;
             default:
                 throw_exception(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_'));
         }
         if (isset($input[$args[0]])) {
             // 取值操作
             $data = $input[$args[0]];
             $fun = $args[1] ? $args[1] : C('DEFAULT_FILTER');
             $data = $fun($data);
             // 参数过滤
         } else {
             // 变量默认值
             $data = isset($args[2]) ? $args[2] : NULL;
         }
         return $data;
     }
 }
Example #30
0
 /**
  * 魔术方法 有不存在的操作的时候执行
  * @access public
  * @param string $method 方法名
  * @param array $args 参数
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) {
         if (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (file_exists_case(C('TEMPLATE_NAME'))) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } elseif (function_exists('__hack_action')) {
             // hack 方式定义扩展操作
             __hack_action();
         } else {
             _404(L('_ERROR_ACTION_') . ':' . ACTION_NAME);
         }
     } else {
         switch (strtolower($method)) {
             // 判断提交方式
             case 'ispost':
             case 'isget':
             case 'ishead':
             case 'isdelete':
             case 'isput':
                 return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2));
                 // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             case '_get':
                 $input =& $_GET;
                 break;
             case '_post':
                 $input =& $_POST;
                 break;
             case '_put':
                 parse_str(file_get_contents('php://input'), $input);
                 break;
             case '_param':
                 switch ($_SERVER['REQUEST_METHOD']) {
                     case 'POST':
                         $input = $_POST;
                         break;
                     case 'PUT':
                         parse_str(file_get_contents('php://input'), $input);
                         break;
                     default:
                         $input = $_GET;
                 }
                 if (C('VAR_URL_PARAMS')) {
                     $params = $_GET[C('VAR_URL_PARAMS')];
                     $input = array_merge($input, $params);
                 }
                 break;
             case '_request':
                 $input =& $_REQUEST;
                 break;
             case '_session':
                 $input =& $_SESSION;
                 break;
             case '_cookie':
                 $input =& $_COOKIE;
                 break;
             case '_server':
                 $input =& $_SERVER;
                 break;
             case '_globals':
                 $input =& $GLOBALS;
                 break;
             default:
                 throw_exception(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_'));
         }
         if (!isset($args[0])) {
             // 获取全局变量
             $data = $input;
             // 由VAR_FILTERS配置进行过滤
         } elseif (isset($input[$args[0]])) {
             // 取值操作
             $data = $input[$args[0]];
             $filters = isset($args[1]) ? $args[1] : C('DEFAULT_FILTER');
             if ($filters) {
                 // 2012/3/23 增加多方法过滤支持
                 $filters = explode(',', $filters);
                 foreach ($filters as $filter) {
                     if (function_exists($filter)) {
                         $data = is_array($data) ? array_map($filter, $data) : $filter($data);
                         // 参数过滤
                     }
                 }
             }
         } else {
             // 变量默认值
             $data = isset($args[2]) ? $args[2] : NULL;
         }
         return $data;
     }
 }