コード例 #1
0
ファイル: resource.db.php プロジェクト: nouphet/rata
function smarty_resource_db_tplinfo($tpl_name, $smarty)
{
    static $cache = array();
    global $xoopsConfig;
    // 1st, check the cache
    if (isset($cache[$tpl_name])) {
        return $cache[$tpl_name];
    }
    $tplset = isset($xoopsConfig['template_set']) ? $xoopsConfig['template_set'] : 'default';
    $theme = isset($xoopsConfig['theme_set']) ? $xoopsConfig['theme_set'] : 'default';
    // 2nd, check templates under themes/(theme)/templates/ (file template)
    $filepath = XOOPS_THEME_PATH . '/' . $theme . '/templates/' . $tpl_name;
    if (file_exists($filepath)) {
        return $cache[$tpl_name] = $filepath;
    }
    // 3rd, check templates under themes/(theme)/templates/(trust based template)
    @(list($dirname, $base_tpl_name) = explode('_', $tpl_name, 2));
    $mytrustdirname = Legacy_ResourcedbUtils::getTrustPath($dirname);
    if ($mytrustdirname && $base_tpl_name) {
        $filepath = XOOPS_THEME_PATH . '/' . $theme . '/templates/' . $mytrustdirname . '/' . $base_tpl_name;
        if (file_exists($filepath)) {
            return $cache[$tpl_name] = $filepath;
        }
    }
    // 4th, find a DB template of the selected tplset
    // check template update
    $tplfileHandler =& xoops_gethandler('tplfile');
    $tplObj = $tplfileHandler->find($tplset, null, null, null, $tpl_name, true);
    if (empty($tplObj)) {
        // 5th, find a DB template in default tplset
        $tplObj = $tplfileHandler->find('default', null, null, null, $tpl_name, true);
        if (empty($tplObj)) {
            return false;
        }
        //update template if admin user and new template file exists
        if (XCube_Root::getSingleton()->mContext->mUser->isInRole('Site.Administrator') && $smarty->xoops_canUpdateFromFile()) {
            Legacy_ResourcedbUtils::updateTemplate($tplObj[0]);
        }
    }
    return $cache[$tpl_name] = $tplObj[0];
}
コード例 #2
0
ファイル: resource.db.php プロジェクト: hiro1173/legacy
function smarty_resource_db_tplinfo($tpl_name, $smarty)
{
    static $cache = array();
    static $dir_cache = array();
    static $tplset = null;
    static $theme = null;
    static $theme_default = null;
    static $entries = null;
    global $xoopsConfig;
    // 1st, check the cache
    if (isset($cache[$tpl_name])) {
        return $cache[$tpl_name];
    }
    if (is_null($tplset)) {
        $tplset = isset($xoopsConfig['template_set']) ? $xoopsConfig['template_set'] : 'default';
        $theme = isset($xoopsConfig['theme_set']) ? $xoopsConfig['theme_set'] : 'default';
        if (($_pos = strpos($theme, '_')) && substr($theme, $_pos) !== '_default') {
            $theme_default = XOOPS_THEME_PATH . '/' . substr($theme, 0, $_pos) . '_default/templates/';
            is_dir($theme_default) || ($theme_default = '');
        } else {
            $theme_default = '';
        }
        $theme = XOOPS_THEME_PATH . '/' . $theme . '/templates/';
        $root = XCube_Root::getSingleton();
        if (!($resourceDiscoveryOrder = $root->getSiteConfig('Smarty', 'ResourceDiscoveryOrder'))) {
            $resourceDiscoveryOrder = 'Theme,ThemeD3,ThemeDefault,ThemeDefaultD3,DbTplSet';
        }
        $entries = array_map('strtoupper', array_map('trim', explode(',', $resourceDiscoveryOrder)));
        $dir_cache['d3'] = $dir_cache['def_d3'] = array();
    }
    @(list($dirname, $base_tpl_name) = explode('_', $tpl_name, 2));
    $mytrustdirname = Legacy_ResourcedbUtils::getTrustPath($dirname);
    // cache D3 dir exists
    if ($mytrustdirname && !isset($dir_cache['d3'][$mytrustdirname])) {
        $dir_cache['d3'][$mytrustdirname] = is_dir($theme . $mytrustdirname);
    }
    if ($theme_default && $mytrustdirname && !isset($dir_cache['def_d3'][$mytrustdirname])) {
        $dir_cache['def_d3'][$mytrustdirname] = is_dir($theme_default . $mytrustdirname);
    }
    foreach ($entries as $entry) {
        switch ($entry) {
            case 'THEME':
                // check templates under themes/(theme)/templates/ (file template)
                $filepath = $theme . $tpl_name;
                if (is_file($filepath)) {
                    return $cache[$tpl_name] = $filepath;
                }
                break;
            case 'THEMED3':
                // check templates under themes/(theme)/templates/(trust based template)
                if ($mytrustdirname && $dir_cache['d3'][$mytrustdirname] && $base_tpl_name) {
                    $filepath = $theme . $mytrustdirname . '/' . $base_tpl_name;
                    if (is_file($filepath)) {
                        return $cache[$tpl_name] = $filepath;
                    }
                }
                break;
            case 'THEMEDEFAULT':
                // check templates under themes/(theme prefix)_default/templates/ (file template)
                if ($theme_default) {
                    $filepath = $theme_default . $tpl_name;
                    if (is_file($filepath)) {
                        return $cache[$tpl_name] = $filepath;
                    }
                }
                break;
            case 'THEMEDEFAULTD3':
                // check templates under themes/(theme prefix)_default/templates/(trust based template)
                if ($theme_default && $mytrustdirname && $dir_cache['def_d3'][$mytrustdirname] && $base_tpl_name) {
                    $filepath = $theme_default . $mytrustdirname . '/' . $base_tpl_name;
                    if (is_file($filepath)) {
                        return $cache[$tpl_name] = $filepath;
                    }
                }
                break;
            case 'DBTPLSET':
                // find a DB template of the selected tplset
                // check template update
                $tplfileHandler =& xoops_gethandler('tplfile');
                $tplObj = $tplfileHandler->find($tplset, null, null, null, $tpl_name, true);
                if (!empty($tplObj)) {
                    return $cache[$tpl_name] = $tplObj[0];
                }
                break;
            default:
        }
    }
    // Finally, find a DB template in default tplset
    if (!isset($tplfileHandler)) {
        $tplfileHandler =& xoops_gethandler('tplfile');
    }
    $tplObj = $tplfileHandler->find('default', null, null, null, $tpl_name, true);
    if (empty($tplObj)) {
        return false;
    }
    //update template if admin user and new template file exists
    if (XCube_Root::getSingleton()->mContext->mUser->isInRole('Site.Administrator') && $smarty->xoops_canUpdateFromFile()) {
        Legacy_ResourcedbUtils::updateTemplate($tplObj[0]);
    }
    return $cache[$tpl_name] = $tplObj[0];
}