Source for file pnBlocks.php
Documentation is available at pnBlocks.php
* Zikula Application Framework
* @copyright (c) 2001, Zikula Development Team
* @link http://www.zikula.org
* @version $Id: pnBlocks.php 24342 2008-06-06 12:03:14Z markwest $
* @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
* display all blocks in a block position
* @param $side block position to render
static $blockplacements = array();
static $positions = array();
// get the block position
if (!isset ($positions[$side])) {
// get the blocks in this block position
if (empty($blockplacements)) {
// get variables from input
// loop around the blocks display only the ones we need
if (!isset ($currentlang)) {
foreach ($blockplacements as $blockplacement) {
// don't display a block if it's not in this block position
if ($blockplacement['pid'] != $positions[$side]['pid']) continue;
// get the full block info
if (!empty($blockinfo['filter']['modules']) ||
!empty($blockinfo['filter']['type']) ||
!empty($blockinfo['filter']['func']) ||
!empty($blockinfo['filter']['customargs'])) {
if (!empty($blockinfo['filter']['modules']) && !in_array($modname, $blockinfo['filter']['modules'])) continue;
// check the function type
if (!empty($blockinfo['filter']['type'])) {
$blockinfo['filter']['type'] = explode(',', $blockinfo['filter']['type']);
if (!in_array($type, $blockinfo['filter']['type'])) continue;
// check the function name
if (!empty($blockinfo['filter']['functions'])) {
$blockinfo['filter']['functions'] = explode(',', $blockinfo['filter']['functions']);
if (!in_array($func, $blockinfo['filter']['functions'])) continue;
if (!empty($blockinfo['filter']['customargs'])) {
$blockinfo['filter']['customargs'] = explode (',', $blockinfo['filter']['customargs']);
static $filtervars = array('module', 'name', 'type', 'func', 'theme', 'authid');
foreach ($_GET as $var => $value) {
if (!in_array($var, $filtervars)) {
$customargs[] = DataUtil::formatForOS(strip_tags($var)). '='. DataUtil::formatForOS(strip_tags($value));
if (!array_intersect($customargs, $blockinfo['filter']['customargs'])) continue;
// dont display the block if it's not active or not in matching langauge
if (!$blockinfo['active'] || (!empty($blockinfo['language']) && $blockinfo['language'] != $currentlang)) continue;
$blockinfo['position'] = $positions[$side]['name'];
// get the module info and display the block
$modinfo['name'] = 'Legacy';
echo pnBlockShow($modinfo['name'], $blockinfo['bkey'], $blockinfo);
$blockoutput[] = pnBlockShow($modinfo['name'], $blockinfo['bkey'], $blockinfo);
return implode("\n", $blockoutput);
* @param string $modname module name
* @param string $block name of the block
* @param array $blockinfo information parameters
* @return mixed blockinfo array or null
function pnBlockShow($modname, $block, $blockinfo = array())
if (empty($modname) || $modname == 'Core') {
$displayfunc = "{ $modname}_{$block}block_display";
return $displayfunc($blockinfo);
if (isset ($blocks_modules[0][$block]['func_display'])) {
return $blocks_modules[0][$block]['func_display']($blockinfo);
$blockinfo['title'] = "Block Type $block Not Found";
$blockinfo['content'] = "The block type $block doesn't seem to exist. Please check corresponding blocks directory.";
* Display a block based on the current theme
static $themeinfo, $themedir, $upb, $downb;
if (!isset ($row['bid'])) {
if (!isset ($row['title'])) {
if (!isset ($themeinfo)) {
// check for collapsable menus being enabled, and setup the collapsable menu image.
if (file_exists('themes/'. $themedir. '/images/upb.gif')) {
$upb = '<img src="themes/'. $themedir. '/images/upb.gif" alt="" />';
$upb = '<img src="images/global/upb.gif" alt="" />';
if (file_exists('themes/'. $themedir. '/images/downb.gif')) {
$downb = '<img src="themes/'. $themedir. '/images/downb.gif" alt="" />';
$downb = '<img src="images/global/downb.gif" alt="" />';
if (pnUserLoggedIn() && pnModGetVar('Blocks', 'collapseable') == 1 && isset ($row['collapsable']) && ($row['collapsable'] == '1')) {
if (pnCheckUserBlock($row) == '1') {
if (!empty($row['title'])) {
if (!empty($row['title'])) {
// end collapseable menu config
if ($themeinfo['type'] == 3) {
* @param string $modname module name
* @param string $block name of the block
* @return bool true on successful load, false otherwise
static $loaded = array();
if (empty($modname) || $modname == 'Core') {
if (isset ($loaded["$modname/ $block"])) {
$blockdir = $moddir . '/pnblocks';
$langdir = $moddir . '/pnlang';
if ($modinfo['type'] == 3) {
$files[] = 'system/' . $blockdir . '/' . $incfile;
} elseif ($modinfo['type'] == 2 || $modinfo['type'] == 1) {
$files[] = 'modules/' . $blockdir . '/' . $incfile;
// load any old style block - don't use loader because this will
// break the scope of the blocks_modules variable
include 'config/blocks/' . $incfile;
$loaded["$modname/$block"] = 1;
// Load the block language files
if ($modinfo['type'] == 3) {
// This directory is for easy of use when developing language packs.
// See http://community.zikula.org/index.php?module=Wiki&tag=LanguagePack
if (isset ($GLOBALS['PNConfig']['System']['development']) && $GLOBALS['PNConfig']['System']['development'])
$files[] = 'config/languages/' . $usrlang . '/system/' . $langdir . '/' . $usrlang . '/' . $incfile;
$files[] = 'system/' . $langdir . '/' . $usrlang . '/' . $incfile;
$files[] = 'system/' . $langdir . '/' . $syslang . '/' . $incfile;
} elseif ($modinfo['type'] == 2 || $modinfo['type'] == 1) {
// This directory is for easy of use when developing language packs.
// See http://community.zikula.org/index.php?module=Wiki&tag=LanguagePack
if (isset ($GLOBALS['PNConfig']['System']['development']) && $GLOBALS['PNConfig']['System']['development'])
$files[] = 'config/languages/' . $usrlang . '/modules/' . $langdir . '/' . $usrlang . '/' . $incfile;
$files[] = 'modules/' . $langdir . '/' . $usrlang . '/' . $incfile;
$files[] = 'modules/' . $langdir . '/' . $syslang . '/' . $incfile;
$files[] = 'config/blocks/lang/' . $usrlang . '/' . $incfile;
$files[] = 'config/blocks/lang/' . $syslang . '/' . $incfile;
$infofunc = "{ $modname}_{ $block}block_info ";
$blocks_modules[$block] = $infofunc();
// set the module and keys for the new block
$blocks_modules[$block]['bkey'] = $block;
if (!isset ($blocks_modules[$block]['module'])) {
$blocks_modules[$block]['module'] = 'Legacy';
$blocks_modules[$block]['mid'] = 0;
$blocks_modules[$block]['module'] = $modname;
// merge the blockinfo in the global list of blocks
if (!isset ($GLOBALS['blocks_modules'])) {
$GLOBALS['blocks_modules'] = array();
$GLOBALS['blocks_modules'][$blocks_modules[$block]['mid']][$block] = $blocks_modules[$block];
// Initialise block if required (new-style)
$initfunc = "{ $modname}_{ $block}block_init ";
* @return array array of blocks
static $blockdirs = array();
// Load new-style blocks from system and modules tree
$mods = pnModGetAllMods();
foreach ($mods as $mod) {
$moddir = DataUtil::formatForOS($mod['directory']);
if (!isset ($blockdirs[$modname])) {
$blockdirs[$modname] = array ();
$blockdirs[$modname][] = 'system/' . $moddir . '/pnblocks';
$blockdirs[$modname][] = 'modules/' . $moddir . '/pnblocks';
foreach ($blockdirs[$modname] as $dir) {
if (file_exists($dir) && is_dir($dir) && is_readable($dir)) {
while (($f = readdir($dh)) !== false) {
if (substr($f, - 4) == '.php') {
$block = substr($f,0,- 4);
while (($f = readdir($dh)) !== false) {
if (substr($f, - 4) == '.php') {
// Return information gathered
return $GLOBALS['blocks_modules'];
* extract an array of config variables out of the content field of a
* @param the $ content from the db
// Assume serialized content ends in a ";" followed by some curly-end-braces
foreach ($links as $link) {
$vars[$var[0]] = $var[1];
* put an array of config variables in the content field of a block
* @param the $ config vars array, in key->value form
* Checks if user controlled block state
* Checks if the user has a state set for a current block
* Sets the default state for that block if not present
function pnCheckUserBlock($row)
if (!isset ($row['bid'])) {
$column = $pntable['userblocks_column'];
return true; // FIXME: should this really return true (RNG)
$obj = array('uid' => $uid,
'active' => $row['defaultstate']);
return true; // FIXME: should this really return true (RNG)
return true; // FIXME: should this really return true (RNG)
return $result['active'];
* @param value the value to search for
* @param assocKey the field in which we look for the value (optional) (default='bid')
* @return array array of block information
* @param value the value to search for
* @param assocKey the field in which we look for the value (optional) (default='bid')
* @return array array of block information
static $blockinfo = array();
if (!isset ($blockinfo[$assocKey]) || empty($blockinfo[$assocKey])) {
$blockinfo[$assocKey] = array();
$blocks = pnBlocksGetInfo();
$ak = array_keys($blocks);
$key = $blocks[$k][$assocKey];
$blocks[$k]['filter'] = strlen($blocks[$k]['filter']) > 0 ? (array) unserialize($blocks[$k]['filter']) : array();
$blockinfo[$assocKey][$key] = $blocks[$k];
if (isset ($blockinfo[$assocKey][$value])) {
return $blockinfo[$assocKey][$value];
* @param title the block title
* @return array array of block information
* alias to pnBlockDisplayPosition
* alias to pnBlockDisplayPosition
|