📄 theme.php
字号:
<?php
/**
* xos_opal_Theme component class file
*
* @copyright The Xoops project http://www.xoops.org/
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author Skalpa Keo <skalpa@xoops.org>
* @since 2.3.0
* @version $Id: theme.php 1100 2007-10-19 01:36:05Z dugris $
* @package xos_opal
* @subpackage xos_opal_Theme
*/
/**
* xos_opal_ThemeFactory
*
* @author Skalpa Keo
* @package xos_opal
* @subpackage xos_opal_Theme
* @since 2.3.0
*/
class xos_opal_ThemeFactory {
var $xoBundleIdentifier = 'xos_opal_ThemeFactory';
/**
* Currently enabled themes (if empty, all the themes in themes/ are allowed)
* @var array
*/
var $allowedThemes = array();
/**
* Default theme to instanciate if none specified
* @var string
*/
var $defaultTheme = 'default';
/**
* If users are allowed to choose a custom theme
* @var bool
*/
var $allowUserSelection = true;
/**
* Instanciate the specified theme
*/
function &createInstance( $options = array(), $initArgs = array() ) {
// Grab the theme folder from request vars if present
if ( @empty( $options['folderName'] ) ) {
if ( ( $req = @$_REQUEST['xoops_theme_select'] ) && $this->isThemeAllowed( $req ) ) {
$options['folderName'] = $req;
if ( isset( $_SESSION ) && $this->allowUserSelection ) {
$_SESSION[ $this->xoBundleIdentifier ]['defaultTheme'] = $req;
}
} elseif ( isset( $_SESSION[ $this->xoBundleIdentifier ]['defaultTheme'] ) ) {
$options['folderName'] = $_SESSION[ $this->xoBundleIdentifier ]['defaultTheme'];
} elseif ( @empty( $options['folderName'] ) || !$this->isThemeAllowed( $options['folderName'] ) ) {
$options['folderName'] = $this->defaultTheme;
}
$GLOBALS['xoopsConfig']['theme_set'] = $options['folderName'];
}
$options['path'] = XOOPS_THEME_PATH . '/' . $options['folderName'];
$inst =& new xos_opal_Theme();
foreach ( $options as $k => $v ) $inst->$k = $v;
$inst->xoInit();
return $inst;
}
/**
* Checks if the specified theme is enabled or not
* @param string $name
* @return bool
*/
function isThemeAllowed( $name ) {
return ( empty( $this->allowedThemes ) || in_array( $name, $this->allowedThemes ) );
}
}
class xos_opal_Theme {
/**
* The name of this theme
* @var string
*/
var $folderName = '';
/**
* Physical path of this theme folder
* @var string
*/
var $path = '';
var $url = '';
/**
* Whether or not the theme engine should include the output generated by php
* @var string
*/
var $bufferOutput = true;
/**
* Canvas-level template to use
* @var string
*/
var $canvasTemplate = 'theme.html';
/**
* Content-level template to use
* @var string
*/
var $contentTemplate = '';
var $contentCacheLifetime = 0;
var $contentCacheId = null;
/**
* Text content to display right after the contentTemplate output
* @var string
*/
var $content = '';
/**
* Page construction plug-ins to use
* @var array
* @access public
*/
var $plugins = array( 'xos_logos_PageBuilder' );
var $renderCount = 0;
/**
* Pointer to the theme template engine
* @var XoopsTpl
*/
var $template = false;
/**
* Array containing the document meta-information
* @var array
*/
var $metas = array(
'http' => array(
'Content-Script-Type' => 'text/javascript',
'Content-Style-Type' => 'text/css',
),
'meta' => array(),
'link' => array(),
'script' => array(),
);
/**
* Array of strings to be inserted in the head tag of HTML documents
* @var array
*/
var $htmlHeadStrings = array();
/**
* Custom variables that will always be assigned to the template
* @var array
*/
var $templateVars = array();
/**
* User extra information for cache id, like language, user groups
*
* @var boolean
*/
var $use_extra_cache_id = true;
/**#@-*/
/**#@+ @tasktype 10 Initialization*/
/**
* Initializes this theme
*
* Upon initialization, the theme creates its template engine and instanciates the
* plug-ins from the specified {@link $plugins} list. If the theme is a 2.0 theme, that does not
* display redirection messages, the HTTP redirections system is disabled to ensure users will
* see the redirection screen.
*
* @param array $options
* @return bool
*/
function xoInit( $options = array() ) {
global $xoops;
$this->path = XOOPS_THEME_PATH . '/' . $this->folderName;
$this->url = XOOPS_THEME_URL . '/' . $this->folderName;
$this->template =& new XoopsTpl();
$this->template->currentTheme =& $this;
$this->template->assign_by_ref( 'xoTheme', $this );
global $xoopsConfig, $xoopsModule, $xoopsUser;
$this->template->assign( array(
'xoops_theme' => $xoopsConfig['theme_set'],
'xoops_imageurl' => XOOPS_THEME_URL.'/'.$xoopsConfig['theme_set'].'/',
'xoops_themecss'=> xoops_getcss($xoopsConfig['theme_set']),
'xoops_requesturi' => htmlspecialchars( $_SERVER['REQUEST_URI'], ENT_QUOTES),
'xoops_sitename' => htmlspecialchars($xoopsConfig['sitename'], ENT_QUOTES),
'xoops_slogan' => htmlspecialchars($xoopsConfig['slogan'], ENT_QUOTES),
'xoops_dirname' => @$xoopsModule ? $xoopsModule->getVar( 'dirname' ) : 'system',
'xoops_banner' => $xoopsConfig['banners'] ? xoops_getbanner() : ' ',
'xoops_pagetitle' => isset($xoopsModule) && is_object($xoopsModule) ? $xoopsModule->getVar('name') : htmlspecialchars( $xoopsConfig['slogan'], ENT_QUOTES ),
) );
if ( isset($xoopsUser) && is_object($xoopsUser) ) {
$this->template->assign( array(
'xoops_isuser' => true,
'xoops_userid' => $xoopsUser->getVar('uid'),
'xoops_uname' => $xoopsUser->getVar('uname'),
'xoops_isadmin' => $GLOBALS['xoopsUserIsAdmin'],
) );
} else {
$this->template->assign( array( 'xoops_isuser' => false, 'xoops_isadmin' => false ) );
}
// Meta tags
$config_handler =& xoops_gethandler('config');
$criteria = new CriteriaCompo(new Criteria('conf_modid', 0));
$criteria->add(new Criteria('conf_catid', XOOPS_CONF_METAFOOTER));
$config = $config_handler->getConfigs($criteria, true);
foreach ( array_keys($config) as $i ) {
$name = $config[$i]->getVar( 'conf_name', 'n' );
$value = $config[$i]->getVar( 'conf_value', 'n' );
if ( substr( $name, 0, 5 ) == 'meta_' ) {
$this->addMeta( 'meta', substr( $name, 5 ), $value );
} else {
// prefix each tag with 'xoops_'
$this->template->assign( "xoops_$name", $value );
}
}
if ( $this->bufferOutput ) {
ob_start();
}
$GLOBALS['xoTheme'] =& $this;
$GLOBALS['xoopsTpl'] =& $this->template;
// Instanciate and initialize all the theme plugins
foreach ( $this->plugins as $k => $bundleId ) {
if ( !is_object( $bundleId ) ) {
$this->plugins[$bundleId] =& new $bundleId();
$this->plugins[$bundleId]->theme =& $this;
$this->plugins[$bundleId]->xoInit();
unset( $this->plugins[$k] );
}
}
return true;
}
/**#@-*/
/**
* Generate cache id based on extra information of language and user groups
*
* User groups other than anonymous should be detected to avoid disclosing group sensitive contents
*
* @param string $cache_id raw cache id
* @param string $extraString extra string
*
* @return string complete cache id
*/
function generateCacheId($cache_id, $extraString = '') {
static $extra_string;
if (!$this->use_extra_cache_id) {
return $cache_id;
}
if (empty($extraString)) {
if (empty($extra_string)) {
global $xoopsUser, $xoopsConfig;
// Generate language section
$extra_string = $xoopsConfig['language'];
// Generate group section
if ( !@is_object( $xoopsUser ) ) {
$extra_string .= '|' . XOOPS_GROUP_ANONYMOUS;
} else {
$groups = $xoopsUser->getGroups();
sort($groups);
// Generate group string for non-anonymous groups,
// XOOPS_DB_PASS and XOOPS_DB_NAME (before we find better variables) are used to protect group sensitive contents
$extra_string .= '|' . implode(",", $groups).substr( md5(XOOPS_DB_PASS.XOOPS_DB_NAME), 0, strlen(XOOPS_DB_USER) * 2 );
}
}
$extraString = $extra_string;
}
$cache_id .= '|' . $extraString;
return $cache_id;
}
function checkCache() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -