/**
  * 自动定位模板文件
  * @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;
 }
 /**
  * 模板包含标签 
  * 格式
  * <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;
 }
 /**
  * 模板包含标签 
  * 格式
  * <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 = sp_add_template_file_suffix(C("SP_TMPL_PATH") . C('SP_DEFAULT_THEME') . "/" . $file);
     //判断模板是否存在
     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];
 }
 /**
  * 自动定位模板文件
  * @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;
 }
 /**
  * 自动定位模板文件
  * @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;
 }
 /**
  * CMF 分析加载的模板文件并读取内容 支持多个模板文件读取
  * @access private
  * @param string $tmplPublicName  模板文件名
  * @return string
  */
 private function parseTcTemplateName($templateName)
 {
     if (substr($templateName, 0, 1) == '$') {
         //支持加载变量文件名
         $templateName = $this->get(substr($templateName, 1));
     }
     $array = explode(',', $templateName);
     $parseStr = '';
     foreach ($array as $templateName) {
         if (empty($templateName)) {
             continue;
         }
         if (false === file_exists_case($templateName)) {
             $templateName = str_replace(':', "/", $templateName);
             defined("SP_TMPL_PATH") ? SP_TMPL_PATH : define("SP_TMPL_PATH", "tpl/");
             $templateName = sp_add_template_file_suffix(SP_TMPL_PATH . SP_CURRENT_THEME . "/" . $templateName);
             $templateName = str_replace("//", "/", $templateName);
         }
         // 获取模板文件内容
         $parseStr .= file_get_contents($templateName);
     }
     return $parseStr;
 }
Beispiel #7
0
/**
 * 判断模板文件是否存在,区分大小写
 * @param string $file 模板文件路径,相对于当前模板根目录,不带模板后缀名
 */
function sp_template_file_exists($file)
{
    $theme = sp_get_current_theme();
    $filepath = C("SP_TMPL_PATH") . $theme . "/" . $file;
    $tplpath = sp_add_template_file_suffix($filepath);
    if (file_exists_case($tplpath)) {
        return true;
    } else {
        return false;
    }
}
 /**
  * 设置错误,成功跳转界面
  */
 private function set_action_success_error_tpl()
 {
     $theme = C('SP_DEFAULT_THEME');
     if (C('TMPL_DETECT_THEME')) {
         // 自动侦测模板主题
         if (cookie('think_template')) {
             $theme = cookie('think_template');
         }
     }
     //by ayumi手机提示模板
     $tpl_path = '';
     if (C('MOBILE_TPL_ENABLED')) {
         //开启手机模板支持
         if (sp_is_mobile()) {
             if (file_exists(C("SP_TMPL_PATH") . "/" . $theme . "_mobile")) {
                 $theme = $theme . "_mobile";
                 $tpl_path = C("SP_TMPL_PATH") . $theme . "/";
             }
         }
     } else {
         $tpl_path = C("SP_TMPL_PATH") . $theme . "/";
     }
     //by ayumi手机提示模板
     $defaultjump = THINK_PATH . 'Tpl/dispatch_jump.tpl';
     $action_success = sp_add_template_file_suffix($tpl_path . C("SP_TMPL_ACTION_SUCCESS"));
     $action_error = sp_add_template_file_suffix($tpl_path . C("SP_TMPL_ACTION_ERROR"));
     if (file_exists_case($action_success)) {
         C("TMPL_ACTION_SUCCESS", $action_success);
     } else {
         C("TMPL_ACTION_SUCCESS", $defaultjump);
     }
     if (file_exists_case($action_error)) {
         C("TMPL_ACTION_ERROR", $action_error);
     } else {
         C("TMPL_ACTION_ERROR", $defaultjump);
     }
 }
Beispiel #9
0
 protected final function fetch($templateFile = 'widget')
 {
     if (!is_file($templateFile)) {
         $config = $this->getConfig();
         $theme = $config['theme'];
         $depr = "/";
         $theme = empty($theme) ? "" : $theme . $depr;
         $templateFile = sp_add_template_file_suffix("./" . $this->tmpl_root . $templateFile);
         if (!file_exists_case($templateFile)) {
             throw new \Exception("模板不存在:{$templateFile}");
         }
     }
     return $this->view->fetch($templateFile);
 }
 private function set_action_success_error_tpl()
 {
     $theme = C('SP_DEFAULT_THEME');
     if (C('TMPL_DETECT_THEME')) {
         // 自动侦测模板主题
         if (cookie('think_template')) {
             $theme = cookie('think_template');
         }
     }
     $tpl_path = C("SP_TMPL_PATH") . $theme . "/";
     $defaultjump = THINK_PATH . 'Tpl/dispatch_jump.tpl';
     $action_success = sp_add_template_file_suffix($tpl_path . C("SP_TMPL_ACTION_SUCCESS"));
     $action_error = sp_add_template_file_suffix($tpl_path . C("SP_TMPL_ACTION_ERROR"));
     if (file_exists_case($action_success)) {
         C("TMPL_ACTION_SUCCESS", $action_success);
     } else {
         C("TMPL_ACTION_SUCCESS", $defaultjump);
     }
     if (file_exists_case($action_error)) {
         C("TMPL_ACTION_ERROR", $action_error);
     } else {
         C("TMPL_ACTION_ERROR", $defaultjump);
     }
 }