Source for file ThemeUtil.class.php
Documentation is available at ThemeUtil.class.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: pnTheme.php 20730 2006-12-09 15:37:53Z drak $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
define('PNTHEME_FILTER_ALL', 0);
define('PNTHEME_FILTER_USER', 1);
define('PNTHEME_FILTER_SYSTEM', 2);
define('PNTHEME_FILTER_ADMIN', 3);
define('PNTHEME_STATE_ALL', 0);
define('PNTHEME_STATE_ACTIVE', 1);
define('PNTHEME_STATE_INACTIVE', 2);
define('PNTHEME_TYPE_ALL', 0);
define('PNTHEME_TYPE_LEGACY', 1);
define('PNTHEME_TYPE_XANTHIA2', 2);
define('PNTHEME_TYPE_XANTHIA3', 3);
define('PNTHEME_TYPE_AUTOTHEME', 4);
* include theme.php for the requested theme
* @return bool true if successful, false otherwiese
// Lots of nasty globals for back-compatability with older themes
$themeinfo = ThemeUtil::getInfo(ThemeUtil::getIDFromName($theme));
// note - don't use dbutil here since we require the vars in theme.php to be globals
if ($themeinfo['type'] != 3) {
$files[] = WHERE_IS_PERSO . "themes/ $themeinfo[directory]/theme.php ";
$files[] = "themes/ $themeinfo[directory]/theme.php ";
pnModLangLoad('Theme', 'userapi');
foreach ($files as $file) {
if (file_exists($file) && Loader::includeOnce($file)) $result = true;
if (!$result) return false;
$GLOBALS['theme_engine'] = new Theme($themeinfo['name'], true);
$GLOBALS['xanthia_theme'] = true;
// create some dummy functions - TODO fix this code deciding what to do with it
function opentable() { echo $GLOBALS['theme_engine']->themetable(true, 1); }
function closetable() { echo $GLOBALS['theme_engine']->themetable(false, 1); }
function opentable2() { echo $GLOBALS['theme_engine']->themetable(true, 2); }
function closetable2() { echo $GLOBALS['theme_engine']->themetable(false, 2); }
// now lets load the themes language file
* return a theme variable
* @return mixed theme variable value
function getVar($name = null, $default = null)
if (!isset ($themevars) && isset ($GLOBALS['theme_engine']) && is_object($GLOBALS['theme_engine'])) {
// initialise the holding array
// note - don't use dbutil here since we require the vars in theme.php to be globals
if ($themeinfo['type'] == 3) {
// load the config vars direct from the theme engine object
$themevars = $GLOBALS['theme_engine']->get_config_vars();
// load the legacy globals
$globalthemevars = array('bgcolor1', 'bgcolor2' , 'bgcolor3', 'bgcolor4', 'bgcolor5', 'sepcolor', 'textcolor1', 'textcolor2');
foreach ($globalthemevars as $globalthemevar) {
if (isset ($GLOBALS[$globalthemevar])) {
$themevars[$globalthemevar] == $GLOBALS[$globalthemevar];
// if no variable name is present then return all theme vars
// if a name is present and the variable exists return its value
if (isset ($themevars[$name])) {
return $themevars[$name];
// not found the var so return the default
* list all available themes
* possible values of filter are
* PNTHEME_FILTER_ALL - get all themes (default)
* PNTHEME_FILTER_USER - get user themes
* PNTHEME_FILTER_SYSTEM - get system themes
* PNTHEME_FILTER_ADMIN - get admin themes
* @param filter - filter list of returned themes by type
* @return array of available themes
function getAllThemes($filter = PNTHEME_FILTER_ALL, $state = PNTHEME_STATE_ACTIVE, $type = PNTHEME_TYPE_ALL)
static $themesarray = array();
$key = md5((string) $filter.(string) $state.(string) $type);
if (empty($themesarray[$key])) {
$pntable = pnDBGetTables();
$themescolumn = $pntable['themes_column'];
if ($state != PNTHEME_STATE_ALL) {
$whereargs[] = "$themescolumn[state] = '" . DataUtil::formatForStore($state) . "'";
if ($type != PNTHEME_TYPE_ALL) {
$whereargs[] = "$themescolumn[type] = '" . (int) DataUtil::formatForStore($type) . "'";
if ($filter == PNTHEME_FILTER_USER) {
$whereargs[] = "$themescolumn[user] = '1'";
if ($filter == PNTHEME_FILTER_SYSTEM) {
$whereargs[] = "$themescolumn[system] = '1'";
if ($filter == PNTHEME_FILTER_ADMIN) {
$whereargs[] = "$themescolumn[admin] = '1'";
$where = implode($whereargs, ' AND ');
$orderBy = "ORDER BY $themescolumn[name]";
// define the permission filter to apply
$permFilter = array(array('realm' => 0,
'component_left' => 'Theme',
'instance_left' => 'name',
if (!$themesarray[$key]) {
return $themesarray[$key];
* load the language file for a theme
$files[] = WHERE_IS_PERSO. 'themes/' . $_theme. '/lang/' . $_cLang . '/' . $_script . '.php';
$files[] = WHERE_IS_PERSO. 'themes/' . $_theme. '/lang/' . $_lang . '/' . $_script . '.php';
$files[] = 'themes/' . $_theme . '/lang/' . $_cLang . '/' . $_script . '.php';
$files[] = 'themes/' . $_theme . '/lang/' . $_lang . '/' . $_script . '.php';
* get themeID given its name
* @link http://www.markwest.me.uk
* @param 'theme' the name of the theme
// define input, all numbers and booleans to strings
$theme = (isset ($theme) ? strtolower((string) $theme) : '');
if (!is_array($themeid) || !isset ($themeid[$theme])) {
foreach ($themes as $themeinfo) {
$themeid[$tName] = $themeinfo['id'];
if (isset ($themeinfo['displayname']) && $themeinfo['displayname'])
$themeid[$tdName] = $themeinfo['id'];
if (!isset ($themeid[$theme])) {
$themeid[$theme] = false;
if (isset ($themeid[$theme])) {
* Returns information about a theme.
* @param string $themeid Id of the theme
* @return array the theme information
if (!is_array($themeinfo) || !isset ($themeinfo[$themeid])) {
if (!isset ($themeinfo[$themeid])) {
$themeinfo[$themeid] = false;
return $themeinfo[$themeid];
return $themeinfo[$themeid];
* small wrapper function to avoid duplicate sql
* @return array modules table
function getThemesTable()
if (!isset ($themestable) || defined('_PNINSTALLVER')) {
* get the modules stylesheet from several possible sources
*@param string $modname the modules name (optional, defaults to top level module)
*@param string $stylesheet the stylesheet file (optional)
*@return string path of the stylesheet file, relative to PN root folder
// default for the module
// default for the style sheet
if (empty($stylesheet)) {
$stylesheet = pnModGetVar($modname, 'modulestylesheet');
if (empty($stylesheet)) {
$stylesheet = 'style.css';
$configstyledir = 'config/styles';
$configpath = "$configstyledir/$osmodname";
$themepath = "themes/$theme/style/$osmodname";
$modpath = "modules/$osmoddir/pnstyle";
$syspath = "system/$osmoddir/pnstyle";
// search for the style sheet
foreach (array($configpath,
$csssrc = "$path/$osstylesheet";
|