/**
 * load a block
 *
 * @param string $modname module name
 * @param string $block name of the block
 * @return bool true on successful load, false otherwise
 */
function pnBlockLoad($modname, $block)
{
    static $loaded = array();
    if (empty($modname) || $modname == 'Core' || $modname == 'Blocks') {
        $modname = 'Core';
        $moddir = 'includes/blocks';
        $langdir = 'includes/language/blocks';
    } else {
        $modinfo = pnModGetInfo(pnModGetIdFromName($modname));
        $moddir = 'modules/' . pnVarPrepForOS($modinfo['directory']) . '/pnblocks';
        $langdir = 'modules/' . pnVarPrepForOS($modinfo['directory']) . '/pnlang';
    }
    if (isset($loaded["{$modname}/{$block}"])) {
        return true;
    }
    // Load the block
    $incfile = $block . '.php';
    $filepath = $moddir . '/' . pnVarPrepForOS($incfile);
    if (!file_exists($filepath)) {
        return false;
    }
    include_once $filepath;
    $loaded["{$modname}/{$block}"] = 1;
    // Load the block language files
    $currentlangfile = $langdir . '/' . pnVarPrepForOS(pnUserGetLang()) . '/' . pnVarPrepForOS($incfile);
    $defaultlangfile = $langdir . '/' . pnVarPrepForOS(pnConfigGetVar('language')) . '/' . pnVarPrepForOS($incfile);
    if (file_exists($currentlangfile)) {
        include $currentlangfile;
    } elseif (file_exists($defaultlangfile)) {
        include $defaultlangfile;
    }
    // get the block info
    $infofunc = "{$modname}_{$block}block_info";
    if (function_exists($infofunc)) {
        $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'] = $modname;
    }
    $blocks_modules[$block]['mid'] = pnModGetIDFromName($blocks_modules[$block]['module']);
    // 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";
    if (function_exists($initfunc)) {
        $initfunc();
    }
    return true;
}
/**
 * load a block
 * @param the module name
 * @param the name of the block
 */
function pnBlockLoad($modname, $block)
{
    global $blocks_modules;
    static $loaded = array();
    if (isset($loaded["{$modname}{$block}"])) {
        return true;
    }
    if (empty($modname) || $modname == 'Core') {
        $modname = 'Core';
        $moddir = 'includes/blocks';
        $langdir = 'includes/language/blocks';
    } else {
        $modinfo = pnModGetInfo(pnModGetIdFromName($modname));
        $moddir = 'modules/' . pnVarPrepForOS($modinfo['directory']) . '/pnblocks';
        $langdir = 'modules/' . pnVarPrepForOS($modinfo['directory']) . '/pnlang';
    }
    // Load the block
    $incfile = $block . ".php";
    $filepath = $moddir . '/' . pnVarPrepForOS($incfile);
    if (!file_exists($filepath)) {
        return false;
    }
    include_once $filepath;
    $loaded["{$modname}{$block}"] = 1;
    // Load the block language files
    $currentlangfile = $langdir . '/' . pnVarPrepForOS(pnUserGetLang()) . '/' . pnVarPrepForOS($incfile);
    $defaultlangfile = $langdir . '/' . pnVarPrepForOS(pnConfigGetVar('language')) . '/' . pnVarPrepForOS($incfile);
    if (file_exists($currentlangfile)) {
        include $currentlangfile;
    } elseif (file_exists($defaultlangfile)) {
        include "{$defaultlangfile}";
    }
    // Initialise block if required (new-style)
    $initfunc = "{$modname}_{$block}block_init";
    if (function_exists($initfunc)) {
        $initfunc();
    }
    return true;
}