function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '')
{
    global $_G;
    static $_init_style = false;
    if ($_init_style === false) {
        C::app()->_init_style();
        $_init_style = true;
    }
    $oldfile = $file;
    if (strpos($file, ':') !== false) {
        $clonefile = '';
        list($templateid, $file, $clonefile) = explode(':', $file);
        $oldfile = $file;
        $file = empty($clonefile) ? $file : $file . '_' . $clonefile;
        if ($templateid == 'diy') {
            $indiy = false;
            $_G['style']['tpldirectory'] = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
            $_G['style']['prefile'] = '';
            $diypath = DISCUZ_ROOT . './data/diy/' . $_G['style']['tpldirectory'] . '/';
            //DIY模板文件目录
            $preend = '_diy_preview';
            $_GET['preview'] = !empty($_GET['preview']) ? $_GET['preview'] : '';
            $curtplname = $oldfile;
            $basescript = $_G['mod'] == 'viewthread' && !empty($_G['thread']) ? 'forum' : $_G['basescript'];
            if (isset($_G['cache']['diytemplatename' . $basescript])) {
                $diytemplatename =& $_G['cache']['diytemplatename' . $basescript];
            } else {
                if (!isset($_G['cache']['diytemplatename'])) {
                    loadcache('diytemplatename');
                }
                $diytemplatename =& $_G['cache']['diytemplatename'];
            }
            $tplsavemod = 0;
            if (isset($diytemplatename[$file]) && file_exists($diypath . $file . '.htm') && ($tplsavemod = 1) || empty($_G['forum']['styleid']) && ($file = $primaltpl ? $primaltpl : $oldfile) && isset($diytemplatename[$file]) && file_exists($diypath . $file . '.htm')) {
                $tpldir = 'data/diy/' . $_G['style']['tpldirectory'] . '/';
                !$gettplfile && ($_G['style']['tplsavemod'] = $tplsavemod);
                $curtplname = $file;
                if (isset($_GET['diy']) && $_GET['diy'] == 'yes' || isset($_GET['diy']) && $_GET['preview'] == 'yes') {
                    //DIY模式或预览模式下做以下判断
                    $flag = file_exists($diypath . $file . $preend . '.htm');
                    if ($_GET['preview'] == 'yes') {
                        $file .= $flag ? $preend : '';
                    } else {
                        $_G['style']['prefile'] = $flag ? 1 : '';
                    }
                }
                $indiy = true;
            } else {
                $file = $primaltpl ? $primaltpl : $oldfile;
            }
            $tplrefresh = $_G['config']['output']['tplrefresh'];
            if ($indiy && ($tplrefresh == 1 || $tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh)) && filemtime($diypath . $file . '.htm') < filemtime(DISCUZ_ROOT . $_G['style']['tpldirectory'] . '/' . ($primaltpl ? $primaltpl : $oldfile) . '.htm')) {
                if (!updatediytemplate($file, $_G['style']['tpldirectory'])) {
                    unlink($diypath . $file . '.htm');
                    $tpldir = '';
                }
            }
            if (!$gettplfile && empty($_G['style']['tplfile'])) {
                $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile . ':' . $clonefile;
            }
            $_G['style']['prefile'] = !empty($_GET['preview']) && $_GET['preview'] == 'yes' ? '' : $_G['style']['prefile'];
        } else {
            $tpldir = './source/plugin/' . $templateid . '/template';
        }
    }
    $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : '';
    $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
    $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : '');
    $filebak = $file;
    if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || isset($_G['forcemobilemessage']) && $_G['forcemobilemessage']) {
        $file = 'mobile/' . $oldfile;
    }
    if (!$tpldir) {
        $tpldir = './template/default';
    }
    $tplfile = $tpldir . '/' . $file . '.htm';
    $file == 'common/header' && defined('CURMODULE') && CURMODULE && ($file = 'common/header_' . $_G['basescript'] . '_' . CURMODULE);
    if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
        if (strpos($tpldir, 'plugin')) {
            if (!file_exists(DISCUZ_ROOT . $tpldir . '/' . $file . '.htm') && !file_exists(DISCUZ_ROOT . $tpldir . '/' . $file . '.php')) {
                discuz_error::template_error('template_notfound', $tpldir . '/' . $file . '.htm');
            } else {
                $mobiletplfile = $tpldir . '/' . $file . '.htm';
            }
        }
        !$mobiletplfile && ($mobiletplfile = $file . '.htm');
        if (strpos($tpldir, 'plugin') && (file_exists(DISCUZ_ROOT . $mobiletplfile) || file_exists(substr(DISCUZ_ROOT . $mobiletplfile, 0, -4) . '.php'))) {
            $tplfile = $mobiletplfile;
        } elseif (!file_exists(DISCUZ_ROOT . TPLDIR . '/' . $mobiletplfile) && !file_exists(substr(DISCUZ_ROOT . TPLDIR . '/' . $mobiletplfile, 0, -4) . '.php')) {
            $mobiletplfile = './template/default/' . $mobiletplfile;
            if (!file_exists(DISCUZ_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) {
                $tplfile = str_replace('mobile/', '', $tplfile);
                $file = str_replace('mobile/', '', $file);
                define('TPL_DEFAULT', true);
            } else {
                $tplfile = $mobiletplfile;
            }
        } else {
            $tplfile = TPLDIR . '/' . $mobiletplfile;
        }
    }
    $cachefile = './data/template/' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php';
    if ($templateid != 1 && !file_exists(DISCUZ_ROOT . $tplfile) && !file_exists(substr(DISCUZ_ROOT . $tplfile, 0, -4) . '.php') && !file_exists(DISCUZ_ROOT . ($tplfile = $tpldir . $filebak . '.htm'))) {
        $tplfile = './template/default/' . $filebak . '.htm';
    }
    if ($gettplfile) {
        return $tplfile;
    }
    checktplrefresh($tplfile, $tplfile, @filemtime(DISCUZ_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file);
    return DISCUZ_ROOT . $cachefile;
}
Beispiel #2
0
 function error($message, $tplname)
 {
     require_once libfile('class/error');
     discuz_error::template_error($message, $tplname);
 }
Beispiel #3
0
	function error($message, $tplname) {
		discuz_error::template_error($message, $tplname);
	}
Beispiel #4
0
function template($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '')
{
    global $_G;
    static $_init_style = false;
    if ($_init_style === false) {
        $discuz =& discuz_core::instance();
        $discuz->_init_style();
        $_init_style = true;
    }
    $oldfile = $file;
    if (strpos($file, ':') !== false) {
        $clonefile = '';
        list($templateid, $file, $clonefile) = explode(':', $file);
        $oldfile = $file;
        $file = empty($clonefile) || STYLEID != $_G['cache']['style_default']['styleid'] ? $file : $file . '_' . $clonefile;
        if ($templateid == 'diy' && STYLEID == $_G['cache']['style_default']['styleid']) {
            $_G['style']['prefile'] = '';
            /*vot*/
            $diypath = DISCUZ_ROOT . './data/diy/';
            //DIY template file directory
            $preend = '_diy_preview';
            $_G['gp_preview'] = !empty($_G['gp_preview']) ? $_G['gp_preview'] : '';
            $curtplname = $oldfile;
            if (isset($_G['cache']['diytemplatename' . $_G['basescript']])) {
                $diytemplatename =& $_G['cache']['diytemplatename' . $_G['basescript']];
            } else {
                $diytemplatename =& $_G['cache']['diytemplatename'];
            }
            $tplsavemod = 0;
            if (isset($diytemplatename[$file]) && file_exists($diypath . $file . '.htm') && ($tplsavemod = 1) || ($file = $primaltpl ? $primaltpl : $oldfile) && isset($diytemplatename[$file]) && file_exists($diypath . $file . '.htm')) {
                $tpldir = 'data/diy';
                !$gettplfile && ($_G['style']['tplsavemod'] = $tplsavemod);
                $curtplname = $file;
                /*vot*/
                if ($_G['gp_diy'] == 'yes' || $_G['gp_preview'] == 'yes') {
                    //DIY mode or preview mode, do the following judge
                    $flag = file_exists($diypath . $file . $preend . '.htm');
                    if ($_G['gp_preview'] == 'yes') {
                        $file .= $flag ? $preend : '';
                    } else {
                        $_G['style']['prefile'] = $flag ? 1 : '';
                    }
                }
            } else {
                $file = $primaltpl ? $primaltpl : $oldfile;
            }
            $tplrefresh = $_G['config']['output']['tplrefresh'];
            if ($tpldir == 'data/diy' && ($tplrefresh == 1 || $tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh)) && filemtime($diypath . $file . '.htm') < filemtime(DISCUZ_ROOT . TPLDIR . '/' . ($primaltpl ? $primaltpl : $oldfile) . '.htm')) {
                if (!updatediytemplate($file)) {
                    unlink($diypath . $file . '.htm');
                    $tpldir = '';
                }
            }
            if (!$gettplfile && empty($_G['style']['tplfile'])) {
                $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile . ':' . $clonefile;
            }
            $_G['style']['prefile'] = !empty($_G['gp_preview']) && $_G['gp_preview'] == 'yes' ? '' : $_G['style']['prefile'];
        } else {
            $tpldir = './source/plugin/' . $templateid . '/template';
        }
    }
    $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : '';
    $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
    $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : '');
    $filebak = $file;
    if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || $_G['forcemobilemessage']) {
        $file = 'mobile/' . $oldfile;
    }
    $tplfile = ($tpldir ? $tpldir . '/' : './template/') . $file . '.htm';
    $file == 'common/header' && defined('CURMODULE') && CURMODULE && ($file = 'common/header_' . $_G['basescript'] . '_' . CURMODULE);
    if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
        if (strpos($tpldir, 'plugin')) {
            if (!file_exists(DISCUZ_ROOT . $tpldir . '/' . $file . '.htm')) {
                require_once libfile('class/error');
                discuz_error::template_error('template_notfound', $tpldir . '/' . $file . '.htm');
            } else {
                $mobiletplfile = $tpldir . '/' . $file . '.htm';
            }
        }
        !$mobiletplfile && ($mobiletplfile = $file . '.htm');
        if (strpos($tpldir, 'plugin') && file_exists(DISCUZ_ROOT . $mobiletplfile)) {
            $tplfile = $mobiletplfile;
        } elseif (!file_exists(DISCUZ_ROOT . TPLDIR . '/' . $mobiletplfile)) {
            $mobiletplfile = './template/default/' . $mobiletplfile;
            if (!file_exists(DISCUZ_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) {
                $tplfile = str_replace('mobile/', '', $tplfile);
                $file = str_replace('mobile/', '', $file);
                define('TPL_DEFAULT', true);
            } else {
                $tplfile = $mobiletplfile;
            }
        } else {
            $tplfile = TPLDIR . '/' . $mobiletplfile;
        }
    }
    $cachefile = './data/template/' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php';
    if ($templateid != 1 && !file_exists(DISCUZ_ROOT . $tplfile)) {
        $tplfile = './template/default/' . $filebak . '.htm';
    }
    if ($gettplfile) {
        return $tplfile;
    }
    checktplrefresh($tplfile, $tplfile, @filemtime(DISCUZ_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file);
    return DISCUZ_ROOT . $cachefile;
}
Beispiel #5
0
function templateEx($file, $templateid = 0, $tpldir = '', $gettplfile = 0, $primaltpl = '')
{
    global $_G, $brandresult;
    $m = md5($file);
    if (empty($_G[$m])) {
        hookscript('sanreebrandtemplatefile', 'global', 'funcs', array('file' => &$file, 'templateid' => &$templateid, 'tpldir' => &$tpldir, 'gettplfile' => &$gettplfile, 'primaltpl' => &$primaltpl), 'sanreebrandtemplatefile');
        $_G[$m] = true;
    }
    $appVer = $_G['setting']['version'];
    $debartemplate = array('srhead', 'srfoot', 'header_one_' . $appVer);
    list($plugin, $temp) = explode(':', $file);
    list($template, $birdfile) = explode('/', $temp);
    if ($_G['cache']['plugin']['sanree_brand']['isbird'] && !in_array($birdfile, $debartemplate)) {
        $birdtemplate = array('index', 'hello', 'christmas', 'newyear', 'springfestival', 'item', 'detail', 'albumlist', 'albumshow');
        if ($_G['item_detail'] == 'detail') {
            $birdfile = $_G['item_detail'];
        }
        $fulltemplate = array('item', 'detail', 'albumlist', 'albumshow');
        $fullflag = array('item' => 'index', 'detail' => 'detail', 'albumlist' => 'myalbum', 'albumshow' => 'myalbum');
        if (in_array($birdfile, $fulltemplate)) {
            require_once libfile('class/' . $plugin . '_newmenu', 'plugin/' . $plugin);
            new sanree_brand_newmenu($fullflag[$birdfile], $brandresult, $birdfile);
        }
        if ($plugin == 'sanree_brand' && in_array($birdfile, $birdtemplate)) {
            $template = 'bird';
            define('BIRD_IMG', 'source/plugin/' . $plugin . '/tpl/' . $template . '/images/');
            define('BIRD_JS', 'source/plugin/' . $plugin . '/tpl/' . $template . '/js/');
            define('BIRD_CSS', 'source/plugin/' . $plugin . '/tpl/' . $template . '/');
            $birdindex = array('index', 'hello', 'christmas', 'newyear', 'springfestival');
            if (in_array($birdfile, $birdindex)) {
                $file = $plugin . ':' . $template . '/' . $birdtemplate[0];
            } elseif ($birdfile == $fulltemplate[0]) {
                $file = $plugin . ':' . $template . '/' . $birdfile . '_' . $fullflag[$birdfile];
            } elseif ($birdfile == $fulltemplate[1]) {
                $file = $plugin . ':' . $template . '/' . $fulltemplate[0] . '_' . $birdfile;
            } elseif ($birdfile == $fulltemplate[2]) {
                $file = $plugin . ':' . $template . '/' . $birdfile;
            } elseif ($birdfile == $fulltemplate[3]) {
                $file = $plugin . ':' . $template . '/' . $birdfile;
            }
        }
    }
    if ($_G['setting']['version'] == 'X2.5' || $_G['setting']['version'] == 'X3' || $_G['setting']['version'] == 'X3.1' || $_G['setting']['version'] == 'X3.2') {
        static $_init_style = false;
        if ($_init_style === false) {
            C::app()->_init_style();
            $_init_style = true;
        }
    } else {
        if (!defined('STYLEID')) {
            define('STYLEID', 1);
        }
    }
    $oldfile = $file;
    if (strpos($file, ':') !== false) {
        $clonefile = '';
        list($templateid, $file, $clonefile) = explode(':', $file);
        $oldfile = $file;
        $file = empty($clonefile) ? $file : $file . '_' . $clonefile;
        if ($templateid == 'diy') {
            $indiy = false;
            $_G['style']['tpldirectory'] = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
            $_G['style']['prefile'] = '';
            $diypath = DISCUZ_ROOT . './data/diy/' . $_G['style']['tpldirectory'] . '/';
            //DIY模板文件目录
            $preend = '_diy_preview';
            $_GET['preview'] = !empty($_GET['preview']) ? $_GET['preview'] : '';
            $curtplname = $oldfile;
            $basescript = $_G['mod'] == 'viewthread' && !empty($_G['thread']) ? 'forum' : $_G['basescript'];
            if (isset($_G['cache']['diytemplatename' . $basescript])) {
                $diytemplatename =& $_G['cache']['diytemplatename' . $basescript];
            } else {
                if (!isset($_G['cache']['diytemplatename'])) {
                    loadcache('diytemplatename');
                }
                $diytemplatename =& $_G['cache']['diytemplatename'];
            }
            $tplsavemod = 0;
            if (isset($diytemplatename[$file]) && file_exists($diypath . $file . '.php') && ($tplsavemod = 1) || empty($_G['forum']['styleid']) && ($file = $primaltpl ? $primaltpl : $oldfile) && isset($diytemplatename[$file]) && file_exists($diypath . $file . '.php')) {
                $tpldir = 'data/diy/' . $_G['style']['tpldirectory'] . '/';
                !$gettplfile && ($_G['style']['tplsavemod'] = $tplsavemod);
                $curtplname = $file;
                if (isset($_GET['diy']) && $_GET['diy'] == 'yes' || isset($_GET['diy']) && $_GET['preview'] == 'yes') {
                    //DIY模式或预览模式下做以下判断
                    $flag = file_exists($diypath . $file . $preend . '.php');
                    if ($_GET['preview'] == 'yes') {
                        $file .= $flag ? $preend : '';
                    } else {
                        $_G['style']['prefile'] = $flag ? 1 : '';
                    }
                }
                $indiy = true;
            } else {
                $file = $primaltpl ? $primaltpl : $oldfile;
            }
            $tplrefresh = $_G['config']['output']['tplrefresh'];
            if ($indiy && ($tplrefresh == 1 || $tplrefresh > 1 && !($_G['timestamp'] % $tplrefresh)) && filemtime($diypath . $file . '.php') < filemtime(DISCUZ_ROOT . $_G['style']['tpldirectory'] . '/' . ($primaltpl ? $primaltpl : $oldfile) . '.php')) {
                if (!updatediytemplate($file, $_G['style']['tpldirectory'])) {
                    unlink($diypath . $file . '.php');
                    $tpldir = '';
                }
            }
            if (!$gettplfile && empty($_G['style']['tplfile'])) {
                $_G['style']['tplfile'] = empty($clonefile) ? $curtplname : $oldfile . ':' . $clonefile;
            }
            $_G['style']['prefile'] = !empty($_GET['preview']) && $_GET['preview'] == 'yes' ? '' : $_G['style']['prefile'];
        } else {
            $tpldir = './source/plugin/' . $templateid . '/tpl';
        }
    }
    $file .= !empty($_G['inajax']) && ($file == 'common/header' || $file == 'common/footer') ? '_ajax' : '';
    $tpldir = $tpldir ? $tpldir : (defined('TPLDIR') ? TPLDIR : '');
    $templateid = $templateid ? $templateid : (defined('TEMPLATEID') ? TEMPLATEID : '');
    $filebak = $file;
    if (defined('IN_MOBILE') && !defined('TPL_DEFAULT') && strpos($file, 'mobile/') === false || isset($_G['forcemobilemessage']) && $_G['forcemobilemessage']) {
        $file = 'mobile/' . $oldfile;
        $tpldir = './source/plugin/' . $templateid . '_mobile/tpl';
    }
    if (!$tpldir) {
        $tpldir = './template/default';
    }
    $tplfile = $tpldir . '/' . $file . '.tpl.php';
    $file == 'common/header' && defined('CURMODULE') && CURMODULE && ($file = 'common/header_' . $_G['basescript'] . '_' . CURMODULE);
    if (defined('IN_MOBILE') && !defined('TPL_DEFAULT')) {
        if (strpos($tpldir, 'plugin')) {
            if (!file_exists(DISCUZ_ROOT . $tplfile) && !file_exists(DISCUZ_ROOT . $tpldir . '/' . $file . '.php')) {
                discuz_error::template_error('template_notfound', $tplfile);
            } else {
                $mobiletplfile = $tplfile;
            }
        }
        !$mobiletplfile && ($mobiletplfile = $file . '.php');
        if (strpos($tpldir, 'plugin') && (file_exists(DISCUZ_ROOT . $mobiletplfile) || file_exists(substr(DISCUZ_ROOT . $mobiletplfile, 0, -4) . '.php'))) {
            $tplfile = $mobiletplfile;
        } elseif (!file_exists(DISCUZ_ROOT . TPLDIR . '/' . $mobiletplfile) && !file_exists(substr(DISCUZ_ROOT . TPLDIR . '/' . $mobiletplfile, 0, -4) . '.php')) {
            $mobiletplfile = './template/default/' . $mobiletplfile;
            if (!file_exists(DISCUZ_ROOT . $mobiletplfile) && !$_G['forcemobilemessage']) {
                $tplfile = str_replace('mobile/', '', $tplfile);
                $file = str_replace('mobile/', '', $file);
                define('TPL_DEFAULT', true);
            } else {
                $tplfile = $mobiletplfile;
            }
        } else {
            $tplfile = TPLDIR . '/' . $mobiletplfile;
        }
    }
    $cachefile = './data/template/' . (defined('STYLEID') ? STYLEID . '_' : '_') . $templateid . '_' . str_replace('/', '_', $file) . '.tpl.php';
    if ($templateid != 1 && !file_exists(DISCUZ_ROOT . $tplfile) && !file_exists(substr(DISCUZ_ROOT . $tplfile, 0, -4) . '.php') && !file_exists(DISCUZ_ROOT . ($tplfile = $tpldir . $filebak . '.php'))) {
        $tplfile = './template/default/' . $filebak . '.php';
    }
    if ($gettplfile) {
        return $tplfile;
    }
    checktplrefreshEx($tplfile, $tplfile, @filemtime(DISCUZ_ROOT . $cachefile), $templateid, $cachefile, $tpldir, $file);
    srhookscriptoutput($tplfile);
    return DISCUZ_ROOT . $cachefile;
}