<?php
/*
*****************************************************************
BlockSubs.php
*****************************************************************
LSP: Lunabyte Systems Portal
Open-Source Project Inspired by Zef Hemel (hide@address.com)
*****************************************************************
Software Version: LSP 2.0 "Enigma 2"
Software by: Lunabyte Systems (http://www.lunabyte.net)
Copyright 2002-2005 by: Lunabyte Systems (http://www.lunabyte.net)
Support, News, Updates at: http://www.lunabyte.net
*****************************************************************
This program is free software; you may redistribute it and/or modify it
under the terms of the provided license as published by Lunabyte Systems.
This program is distributed in the hope that it is and will be useful,
but WITHOUT ANY WARRANTIES; without even any implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the "LSP_license.txt" file for details of the LSP license.
The latest version can always be found at http://www.lunabyte.net.
*****************************************************************
*/
if (!defined('ENIGMA'))
die('<b>Access Violation</b><br />Direct Access to this location is not allowed.');
function loadBlocks ()
{
global $context, $db_prefix, $modSettings, $txt, $board, $topic, $user_info;
$karma = ($modSettings['karmaMode'] == '0') ? "AND type != 'karmaActions'" : '';
// is an op set?, check all the current ops in the array
if (isset($_REQUEST['op']) && $_REQUEST['op'] != '')
{
if (strstr($_REQUEST['op'], 'Management'))
$screen = 'admin';
else
switch ($_REQUEST['op']) {
case "PortalAdmin":
$screen = 'admin';
break;
case "News": case "news2":
$screen = 'news';
break;
case "submissions":
$screen = 'submissions';
break;
case "PageListing": case "page":
$screen = 'pages';
break;
default:
$screen = 'misc';
}
$screen2 = '';
} // are we in the forum via a board or topic variable only? select any individual board displays or forum
elseif ($board > 0 || $topic > 0)
{
$screen = 'Board_' . $board;
$screen2 = 'forum';
} // how about an action in that monster action array? find the right one....
elseif (isset($_REQUEST['action']) && $_REQUEST['action'] != '')
{
switch ($_REQUEST['action']) {
case "admin": case "ban": case "boardrecount": case "detailedversion": case "dumpdb": case "editagreement": case "editnews":
case "mailing": case "maintain": case "manageattachments": case "manageboards": case "membergroups": case "modifycat":
case "modifyModSettings": case "modlog": case "modsettings": case "optimizetables": case "packageget": case "packages":
case "permissions": case "pgadd": case "pgremove": case "pgbrowse": case "pgdownload": case "pgupload": case "repairboards":
case "setcensor": case "setreserve": case "smileys": case "trackip": case "viewErrorlog": case "viewmembers":
case "modifyModSettings2": case "modlog2": case "modsettings2": case "removeoldtopics": case "setcensor2":
case "setreserve2": case "viewErrorLog": case "regcenter": case "modsettings": case "theme":
$screen = 'admin';
break;
case "calendar":
$screen = 'calendar';
break;
case "announce": case "collapse": case "deletemsg": case "display": case "dlattach": case "editpoll": case "lock":
case "lockVoting": case "markasread": case "mergetopics": case "modifykarma": case "movetopic": case "notify":
case "notifyboard": case "post": case "quotefast": case "quickmod": case "recent": case "reporttm": case "search":
case "sendtopic": case "spellcheck": case "splittopics": case "sticky": case "unread": case "unreadreplies": case "vote":
case "editpoll2": case "movetopic2": case "post2": case "quickmod2": case "removetopic2": case "search2": case "forum":
$screen = 'forum';
break;
case "im":
$screen = 'im';
break;
case "profile": case "profile2": case "theme": case "viewprofile":
$screen = 'profile';
break;
case "stats": case "who":
$screen = 'stats';
break;
default:
$screen = 'misc';
}
$screen2 = '';
} // no action, how about a page or all pages?
elseif (isset($_REQUEST['page']) && $_REQUEST['page'] != '')
{
$screen = 'Page_' . $_REQUEST['page'];
$screen2 = 'pages';
} // still going? how about module(s)
elseif (isset($_REQUEST['module']) && $_REQUEST['module'] != '')
{
if (strstr($_REQUEST['module'], 'Management') || (!empty($_REQUEST['sa']) && $_REQUEST['sa'] == 'Admin'))
{
$screen = 'admin';
$screen2 = '';
}
else
{
$screen = 'Mod_' . $_REQUEST['module'];
$screen2 = 'modules';
}
}
// Better check to see if we're in bridge mode!
elseif (defined('E2_BRIDGED'))
{
$screen = E2_BRIDGED;
$screen2 = 'bridged';
}
// Nothing else was found, so we have to be on the home page.
else
{
$screen = 'home';
$screen2 = '';
}
// setup the allowance/membergroup queries
$where2 = permissionQuery('allowance');
// now find blocks visible on all screens and the screens we set
$result = db_query("
SELECT phpe, type, name, contents, side, templateName
FROM {$db_prefix}blocks
WHERE (FIND_IN_SET('$screen',visible)!=0 || FIND_IN_SET('all',visible)!=0 || FIND_IN_SET('$screen2',visible)!=0)
AND active = '1'
$where2
$karma
ORDER BY side,border ASC", __FILE__, __LINE__);
while ($blocks = mysql_fetch_assoc($result))
{ // setup the block array
$context['blocks'][$blocks['side']][] = array(
'phpe' => $blocks['phpe'],
'type' => $blocks['type'],
'name' => $blocks['name'],
'contents'=> $blocks['contents'],
'template'=> $blocks['templateName'],
);
}
mysql_free_result($result);
}
// call the Block table templates and call the Contents from inside the Template
function Blocks($side)
{
global $context, $txt;
// variable that can be set to overide right, center and bottom block display
if ($context['block_override'])
return;
// load the blocks template file from the Blocks folder
loadBlockTemplate('Blocks');
// setup the block template function name, based on the current side being displayed
$templateFunc = 'template_Blocks_' . ucwords($side);
foreach ($context['blocks'][$side] AS $block)
{ // if there is a custom template for this block table, call that
if ($block['template'])
{
$templateCustom = 'template_Blocks_' . $block['template'];
if (function_exists($templateCustom))
$templateCustom($block);
else
echo '<p>', $templateCustom, '()<br />
<br />',
$txt['no_blocktemplate'], '</p>';
}
// otherwise, call the normal template for the current side
else
$templateFunc($block);
}
}
// determine what to do with block contents
function blockContents($block)
{
global $context, $settings, $modSettings, $blockdir, $txt, $blockTemplate;
$currentBlock = '';
// php enabled and a custom block?, evaluate the code and display
if ($block['phpe'] && $block['type'] == 'custom')
return eval(un_htmlspecialchars($block['contents']));
// just a custom block without php?, display the contents
elseif ($block['type'] == 'custom')
return un_htmlspecialchars($block['contents']);
// check if function has been defined for this Block and call it
elseif (function_exists($block['type']))
return $block['type']();
// not custom, and no function yet, load the block file, then call the function
else
{
// setup the current block name
$currentBlock = 'Block_' . $block['type'];
// load the block file if it exists
if (file_exists($blockdir . '/' . $currentBlock . '.php'))
require_once($blockdir . '/' . $currentBlock . '.php');
// if this block has a language file, load it...
// false tells the load function not to error if the file doesn't exist
loadPLanguage('blocks/' . $currentBlock, '', false);
// let's check to make sure the function was defined in the block file before calling it
if (function_exists($currentBlock))
{ // is there a template for this blocks contents?
if (isset($blockTemplate) && $blockTemplate === true)
{ // clear the var
$blockTemplate = '';
// load the template file if it exists
loadBlockTemplate($currentBlock);
// if the file was loaded....
if (empty($settings['no_block_templatefile']))
{ // setup the func name
$templateFunction = 'template_' . $currentBlock;
// check if the function exists
if (function_exists($templateFunction))
{ // call the block function
$currentBlock();
// return the template output
return $templateFunction();
}
else // no template function, reutrn an error message
return $txt['no_blocktemplate'] . ' - ' . $templateFunction;
}
else // template file didn't exist, display an error message
return $txt['no_blocktemplate_file'] . ' - ' . $currentBlock . '.template.php';
}
else // no template defined, just call the block function
return $currentBlock();
}
else
return $txt['no_blockfunction'] . ' - ' . $currentBlock;
}
// if we get here, nothing has been defined or displayed, so there is no block.
// Return a nice message saying so.
return $txt['no_block'];
}
// special and simple load template function for blocks only so we don't go crash the site
function loadBlockTemplate($template)
{
global $context, $settings, $boarddir;
// check current theme
if (file_exists($settings['theme_dir'] . '/portal/blocks/' . $template . '.template.php'))
template_include($settings['theme_dir'] . '/portal/blocks/' . $template . '.template.php', true);
// check the default theme
elseif (file_exists($settings['default_theme_dir'] . '/portal/blocks/' . $template . '.template.php'))
template_include($settings['default_theme_dir'] . '/portal/blocks/' . $template . '.template.php', true);
// check the "default" theme directory
elseif (Is_dir($boarddir . '/Themes/default/portal/blocks') && file_exists($boarddir . '/Themes/default/portal/blocks/' . $template . '.template.php'))
template_include($boarddir . '/Themes/default/portal/blocks/' . $template_name . '.template.php', true);
// still doesn't exist? set a variable so blocks don't crash the site
else
$settings['no_block_templatefile'] = (int) true;
}
?>