Location: PHPKode > projects > Enigma > Enigma2/Enigma2_Install/PortalSources/LoadModule.php
<?php
/*
*****************************************************************

 LoadModule.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 ModuleHub($calledModule='')
{
	global $context, $moduledir, $txt, $modSettings;

	$_MODULE	= ($calledModule) ? $calledModule : $context['module'];
	$_MODULE_PATH	= $moduledir;
	$_FILE		= !empty($_REQUEST['file']) ? $_REQUEST['file'] : '';

	if (preg_match('[\.|\.\.]', $_MODULE) || preg_match('[\.|\.\.]', $_FILE))
		fatal_error ('<b>WOW!</b> a new Script Kiddie!<br />Leaving the Modules Directory is not allowed and allready thought of.<br />Please take up a new hobbie!');

	// Check if Modules are enable or this is an Admin.
	if ($modSettings['enablemodules'] == '1' || AllowedTo('admin_forum'))
	{
		// Check if this is an internal/template based module.
		if (!empty($_REQUEST['code']) && $_REQUEST['code'] == 'true' && file_exists($_MODULE_PATH . '/Module_' . $_MODULE . '.php'))
		{
			require_once $_MODULE_PATH . '/Module_' . $_MODULE . '.php';
		}
		elseif (file_exists($_MODULE_PATH . '/Mod_' . $_MODULE . '.php'))
		{
			require_once $_MODULE_PATH . '/Mod_' . $_MODULE . '.php';
		}
		elseif (is_dir($_MODULE_PATH . '/' . $_MODULE) && file_exists($_MODULE_PATH . '/' . $_MODULE . '/Mod_' . $_MODULE . '.php'))
		{
			require_once $_MODULE_PATH . '/' . $_MODULE . '/Mod_' . $_MODULE . '.php';
		}
		elseif (is_dir($_MODULE_PATH . '/' . $_MODULE) && $d = dir($_MODULE_PATH . '/' . $_MODULE))
		{
			while ( false !== ($obj = $d->read()) )
			{
				if ($_FILE . '.php' == $obj)
				{
					// Set data file to a requested file of this module.
					$context['datafile'] = $_MODULE_PATH . '/' . $_MODULE . '/' . $obj;
				}
				elseif (preg_match('~(Mod_[a-zA-Z0-9]+).php~', $obj, $matches) == 1)
				{
					// Set data file to the bridge script of this module.
					$context['datafile'] = $_MODULE_PATH . '/' . $_MODULE . '/' . $obj;
				}
			}
			$d->close();

			// well...
			if (empty($context['datafile']) && (true === @file_exists($_MODULE_PATH . '/' . $_MODULE . '/index.php')))
			{
				$context['datafile'] = $_MODULE_PATH . '/' . $_MODULE . '/index.php';
			}
			elseif (empty($context['datafile']) && (false === @file_exists($_MODULE_PATH . '/' . $_MODULE . '/index.php')))
			{
				// well lets hide the undefined datafile by sending them back to the site index.
				redirectexit();
			}

			/*
			   one last thing a title,
			   first we'll see if there is an module-info.xml file
			   if not we'll set it to the name of the module.
			*/
			if (file_exists($_MODULE_PATH . '/' . $_MODULE . '/module-info.xml'))
			{
				$module_info = implode('', file($_MODULE_PATH . '/' . $_MODULE . '/module-info.xml'));

				if (preg_match('~<title>(?:<!\[CDATA\[)?(.+?)(?:\]\]>)?</title>~', $module_info, $match) == 1)
					$context['page_title'] = $match[1];
			}
			else
				$context['page_title'] = 'Modules: ' . $_MODULE;

			// Load module templates for module inclusion
			loadMTemplate('modules');
			$context['template_layers'][] = 'module';
			$context['sub_template'] = 'include_data';
		}
		else
			redirectexit();
	}
	else
		redirectexit();
}
?>
Return current item: Enigma