2017-12-31技术笔记

五指CMS模板加载函数

/**
 * 模板调用
 *
 * @param $m        模块名称
 * @param $template 模版名称
 * @param $style    模版风格
 * @return string
 */
function T($m = 'content', $template = 'index', $style = 'default'){
    $mb = false;
    if ($_POST['SUPPORT_MOBILE'] && is_mobile_request()) {
        $tmp = $template;
        $template = 'mobile/' . $template;
        $mb = true;
    }
    if($style=='default' && TPLID!='default') $style = TPLID;
    $cache_file = CACHE_ROOT . 'templates/' . $style . '/' . $m . '/' . $template . '.php';
    if (!file_exists($cache_file)) {
        $tpl_file = 'templates/' . $style . '/' . $m . '/' . $template . '.html';
        if (file_exists(COREFRAME_ROOT . $tpl_file)) {
            exit('Please update template cache!');
        } elseif(file_exists(CACHE_ROOT . 'templates/default/' . $m . '/' . $template . '.php')) {
            $cache_file = CACHE_ROOT . 'templates/default/' . $m . '/' . $template . '.php';
            if (AUTO_CACHE_TPL) {
                $c_template = load_class('template');
                $c_template->cache_template($m, $template, 'default');
            }
        } elseif ($mb) {
            $cache_file = CACHE_ROOT . 'templates/' . $style . '/' . $m . '/' . $tmp . '.php';
            if (!file_exists($cache_file)) {
                $tpl_file = 'templates/' . $style . '/' . $m . '/' . $tmp . '.html';
                if (file_exists(COREFRAME_ROOT . $tpl_file)) {
                    exit('Please update template cache!');
                } elseif(file_exists(CACHE_ROOT . 'templates/default/' . $m . '/' . $tmp . '.php')) {
                    $cache_file = CACHE_ROOT . 'templates/default/' . $m . '/' . $tmp . '.php';
                } else {
                    exit('Template does not exists:' . $tpl_file);
                }
            } elseif (AUTO_CACHE_TPL) {
                $c_template = load_class('template');
                $c_template->cache_template($m, $tmp, $style);
            }
        } else {
            exit('Template does not exists:' . $tpl_file);
        }
    } elseif (AUTO_CACHE_TPL) {
        $c_template = load_class('template');
        $c_template->cache_template($m, $template, $style);
    }

    return $cache_file;
}

你可能感兴趣的:(2017-12-31技术笔记)