Source for file pnTheme.class.php
Documentation is available at pnTheme.class.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: pnTheme.class.php 24433 2008-07-03 12:06:19Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
var $regid; // registration id
var $user; // user capable
// vars to identify our page
function Theme($theme, $usefilters = true)
// first, get a native pnRender object object
// store our theme directory
foreach ($themeinfo as $key => $value) {
// change some base settings from our parent class
// assign all our base template variables
// define the plugin directories
// load the theme configuration
// check for cached output
// turn on caching, check for cached output and then disable caching
// to prevent blocks from being cached
// Assign all theme variables
// register page vars output filter
// register short urls output filter
// register trim whitespace output filter if requried
// register output filter to make urls clickable if requried
// register output filter to add MultiHook environment if requried
// Start the output buffering to capture module output
* display the page output
// end output buffering and get module output
// add the module wrapper
if (!$this->system && (!isset ($this->themeconfig['modulewrapper']) || $this->themeconfig['modulewrapper'])) {
// Assign the main content area to the template engine
// render the page using the correct template
// assign the block information
$position = $block['position'];
// fix block positions - for now....
if ($position == 'l') $position = 'left';
if ($position == 'c') $position = 'center';
if ($position == 'r') $position = 'right';
// HACK: Save/restore output filters - we don't want to output-filter blocks
$outputfilters = $this->_plugins['outputfilter'];
$this->_plugins['outputfilter'] = array();
// HACK: Save/restore cache settings
// determine the correct template and construct the output
if (isset ($this->themeconfig['blockinstances'][$bid]) && !empty($this->themeconfig['blockinstances'][$bid])) {
$return .= $this->fetch($this->themeconfig['blockinstances'][$bid]);
} elseif (isset ($this->themeconfig['blocktypes'][$bkey]) && !empty($this->themeconfig['blocktypes'][$bkey])) {
$return .= $this->fetch($this->themeconfig['blocktypes'][$bkey]);
} else if (isset ($this->themeconfig['blockpositions'][$position]) && !empty($this->themeconfig['blockpositions'][$position])) {
$return .= $this->fetch($this->themeconfig['blockpositions'][$position]);
} else if (isset ($this->themeconfig['block']) && !empty($this->themeconfig['block'])) {
$return .= $this->fetch($this->themeconfig['block']);
if (!empty($block['title'])) {
$return .= '<h4>'. pnML($block['title'], array(), true) . ' ' . $block['minbox']. '</h4>';
$return .= $block['content'];
// HACK: Save/restore output filters
$this->_plugins['outputfilter'] = $outputfilters;
// HACK: Save/restore cache settings
if (!isset ($this->themeconfig['blockwrapper']) || $this->themeconfig['blockwrapper']) {
* render the legacy open/close table functions
* @param string $template
// Start the output buffer
// Get the buffer contents and end buffering
if (isset ($this->themeconfig['table'.(int) $tablenum])) {
// assign the table content
$this->assign('tablecontent', $tablecontent);
$return = $this->fetch($this->themeconfig['table'.(int) $tablenum]);
$return = '<div class="pn-box'.(int) $tablenum. '">'. $tablecontent. '</div>';
* Checks which path to use for required template
* @param string $template
if (isset ($cache[$template])) {
return $cache[$template];
// get the theme path to templates
// Define the locations in which we will look for templates
// 1. Master template path
$masterpath = "themes/ $os_theme/templates ";
// 2. The module template path
$modulepath = "themes/ $os_theme/templates/modules ";
// 4. The block template path
$blockpath = "themes/ $os_theme/templates/blocks ";
$ostemplate = DataUtil::formatForOS($template);
$search_path = array($masterpath,
foreach ($search_path as $path) {
if (file_exists("$path/ $ostemplate") && is_readable("$path/ $ostemplate")) {
$cache[$template] = $path;
// when we arrive here, no path was found
* define all our plugin directories
// add our basic engine plugin path
// add theme specific plugins directories, if they exist
$themepath = 'themes/'. $this->directory. '/plugins';
* assign template vars for base theme paths and other useful variables
// get variables from input
// set some basic class variables from the PN environemnt
// Assign the query string
$this->qstring = isset ($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
// Assign the current script
// assign some basic paths for the engine
// now strip any non-ascii characters from the page id
// set vars based on the module structures
$this->type = !empty($type) ? $type : 'user';
$this->func = !empty($func) ? $func : 'main';
$this->home = (empty($module) && empty($name)) ? true : false;
// identify and assign the page type
} else if (empty($name) && empty($module)) {
// make the base vars available to all templates
$this->assign('uid', $this->uid);
$this->assign('func', $this->func);
* load the base theme configuration
// set the config directory
// load the page configurations
$pageconfigurations = pnModAPIFunc('Theme', 'user', 'getpageconfigurations', array('theme' => $this->name));
// parse the query string into individual arguments discarding common arguments
// common arguments are ones that we don't want affecting our url matching or ones that are
// already considered; These are same args defined as reserved by the MDG.
// remove the base uri, entrypoint, module name and, if it exists, the function name from the string
$customargs = str_replace("/{$entrypoint}/", '/', $customargs);
$qstring = trim($qstring, '-');
$argsarray = explode('-', $qstring);
foreach ($argsarray as $argarray) {
$customargs[] = implode('=', $argarray);
$customargs = '/' . implode('/', $customargs);
foreach ($queryparts as $querypart) {
$customargs .= '/'. $querypart;
// identify and load the correct module configuration
if (stristr($_SERVER['PHP_SELF'], 'user') && isset ($pageconfigurations['*user'])) {
$file = $pageconfigurations['*user']['file'];
} else if (!stristr($_SERVER['PHP_SELF'], 'user') && !stristr($_SERVER['PHP_SELF'], 'admin.php') && $this->home && isset ($pageconfigurations['*home'])) {
$file = $pageconfigurations['*home']['file'];
} else if (stristr($_SERVER['PHP_SELF'], 'admin.php') && isset ($pageconfigurations['*admin'])) {
$this->cachepage = false;
$file = $pageconfigurations['*admin']['file'];
// find any page configurations that match in a sub string comparison
foreach ($pageconfigurations as $pageconfiguration => $pageconfigurationarray) {
if (stristr($customargs, $pageconfiguration) && $matchlength < strlen($pageconfiguration)) {
$match = $pageconfiguration;
$matchlength = strlen($match);
if((strtolower($this->type) == 'admin') && isset ($pageconfigurations['*admin'])&& (!stristr($match,'admin'))) {
$this->cachepage = false;
$file = $pageconfigurations[$match]['file'];
$file = $pageconfigurations['master']['file'];
// load the page configuration
$this->themeconfig = pnModAPIFunc('Theme', 'user', 'getpageconfiguration', array('theme' => $this->name, 'filename' => $file));
// check if we've not got a valid theme configation
if (!$this->themeconfig) {
$this->themeconfig = pnModAPIFunc('Theme', 'user', 'getpageconfiguration', array('theme' => $this->name, 'filename' => 'master.ini'));
if (isset ($this->themeconfig['filters']) && !empty($this->themeconfig['filters'])) {
if (isset ($this->themeconfig['filters']['outputfilters']) && !empty($this->themeconfig['filters']['outputfilters'])) {
$this->themeconfig['filters']['outputfilters'] = explode(',', $this->themeconfig['filters']['outputfilters']);
foreach ($this->themeconfig['filters']['outputfilters'] as $filter) {
if (isset ($this->themeconfig['filters']['prefilters']) && !empty($this->themeconfig['filters']['prefilters'])) {
$this->themeconfig['filters']['prefilters'] = explode(',', $this->themeconfig['filters']['prefilters']);
foreach ($this->themeconfig['filters']['prefilters'] as $filter) {
if (isset ($this->themeconfig['filters']['postfilters']) && !empty($this->themeconfig['filters']['postfilters'])) {
$this->themeconfig['filters']['postfilters'] = explode(',', $this->themeconfig['filters']['postfilters']);
foreach ($this->themeconfig['filters']['postfilters'] as $filter) {
// load the theme settings
$this->config_load('file:themevariables.ini', 'variables');
if (isset ($this->themeconfig['palette'])) {
$this->config_load('file:themepalettes.ini', $this->themeconfig['palette']);
$this->assign('palette', isset ($this->themeconfig['palette']) ? $this->themeconfig['palette'] : null);
* set the config directory for this theme
function _set_configdir()
// check for a running configuration in the pnTemp/Xanthia_Config directory
|