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

 PortalSubs.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.');

// Displays the home page if turned on.
function SiteIndex()
{
	global $context, $modSettings, $settings, $portalSources, $moduledir;

	if ($modSettings['portal_home_page'] == 'usenews')
	{
  		require_once($portalSources . '/News.php');
  		NewsHub('Home');
	}
	else
	{
		$context['no_trail'] = 1;
		if (strstr($modSettings['portal_home_page'], 'Mod_'))
		{
			$_REQUEST['module'] = true;
			require_once $moduledir . '/' . $modSettings['portal_home_page'] . '.php';
		}
		else
		{
			require_once $portalSources . '/Pages.php';
			pages($modSettings['portal_home_page']);
		}
	}
}

// Status Text for Links, News, and Articals
function statusText($stage)
{
	global $txt;

	loadPLanguage('PortalSubs');

	if ($stage == 0) { $stext = $txt['status_pending']; }
	else if ($stage == 1) { $stext = $txt['status_approved']; }
	else if ($stage == 2) { $stext = $txt['status_rejected']; }
	else if ($stage == 3) { $stext = $txt['status_cancelled']; }
	else if ($stage == 4) { $stext = $txt['status_resubmit']; }
	else { $stext = $txt['status_nosubmit']; }

	return $stext;
}

// determine Enigma permission based on member group
function GroupPermissions($permits, $override = false)
{
	global $user_info;

	$permarray = explode(',', $permits);

	if (allowedTo('admin_forum') && !$override)
		return true;

	foreach ($user_info['groups'] AS $group)
	{
		if (in_array($group, $permarray))
		{
			return true;
		}
	}

	switch (true)
	{
		case (in_array(-2, $permarray) && !$user_info['is_guest']) :
			return true;
		break;
		case (in_array(-1, $permarray) && $user_info['is_guest']) :
			return true;
		break;
		case (in_array(0, $permarray)) :
			return true;
		break;
		default :
			return false;
		break;
	}
}

function permissionQuery ($columnname)
{
	global $user_info;

	// setup the permission queries for the table column name requested
	$where = 'AND (FIND_IN_SET(\'0\',' . $columnname . ')';		// all users
	if (!$user_info['is_guest'])						// members only and newbie
		$where .= '|| FIND_IN_SET(\'-2\',' . $columnname . ')';
	elseif ($user_info['is_guest'])					// guests
		$where .= '|| FIND_IN_SET(\'-1\',' . $columnname . ')';

	foreach ($user_info['groups'] AS $group)			// loop through all other groups
			$where .= ' || FIND_IN_SET(\'' . $group . '\',' . $columnname . ')';
	$where .= ')';

	return $where;

}

// this will build a dropdown of current member groups plus three static, for Enigma permissions
function groupselect ($current = '', $selectname, $new = '')
{
	global $txt, $modSettings;

	loadPLanguage('PortalSubs');

	// here we're going to use some alternative numbers for static values
	//  0 = everyone
	// -2 = members_only (same as newbie)
	// -1 = Guest
	
	// when using this function, to autoselect '0' (Everyone), add a ",true" to the end of your
	// groupselect function call

	$currentarray = explode(',',$current);

	$se = ((in_array(0, $currentarray) && $current != '') || $new)	? 'selected="selected"' : '';
	$sm = in_array(-2, $currentarray)	? 'selected="selected"' : '';
	$sg = in_array(-1, $currentarray)	? 'selected="selected"' : '';

	$select = '
		<select name="' . $selectname . '" multiple size="8">
			<option ' . $se . ' value="0">' . $txt['perms_everyone'] . '</option>
			<option ' . $sm . ' value="-2">' . $txt['perms_members'] . '</option>
			<option ' . $sg . ' value="-1">' . $txt['perms_guests'] . '</option>';

	foreach ($modSettings['listed_Membergroups'] AS $allgroup)
	{
		$selected = '';
		if (in_array($allgroup['ID_GROUP'], $currentarray))
		{
			$selected = 'selected';
		}
		$select .= '
			<option ' . $selected . ' value="' . $allgroup['ID_GROUP'] . '">' . $allgroup['groupName'] . '</option>';
	}

	$select .= '
		</select>';

	reset ($modSettings['listed_Membergroups']);

	return $select;
}

function permissionlist($permits)
{
	global $db_prefix, $txt, $modSettings;

	loadPLanguage('PortalSubs');

	$permarray = explode(',', $permits);
	$permdisplay = '';


	foreach ($modSettings['listed_Membergroups'] AS $allgroup)
	{
		if (in_array($allgroup['ID_GROUP'], $permarray))
			$permdisplay .= $allgroup['groupName'] . '<br />';
	}

	if (in_array(0, $permarray))
	{
		$permdisplay .= $txt['perms_everyone'] . '<br />';
	}
	if (in_array(-1, $permarray))
	{
		$permdisplay .= $txt['perms_guests'] . '<br />';
	}
	if (in_array(-2, $permarray))
	{
		$permdisplay .= $txt['perms_members'] . '<br />';
	}

	reset ($modSettings['listed_Membergroups']);

	return $permdisplay;
}
// check if current user/visitor is a bot
function botcheck()
{
	global $modSettings, $context;

	if ($modSettings['not_bot'] == false)
	{
		$t = time() - 3600;
		if ((!empty($context['sub_template']) && $context['sub_template'] == 'popup') || !empty($context['popup']))
			return;
		else
			if ($t > $modSettings['initime']) { $lsp_ini = new portal(); $lsp_ini->notinitialized(); }
	}
}

// portal initialization
class portal
{

	// initialize the portal
	function portal($initime='', $pversion='', $pclass='', $pvar='', $pver='')
	{
		$this->initime = $initime;
		$this->pversion = $pversion;
		$this->pclass = $pclass;
		$this->pvar = $pvar;
		$this->pver = $pver;
	}

	function get_ini()
	{
		global $portal, $modSettings, $db_prefix, $portal_version;

		$x = 'Powered';
		$y = stristr($this->pvar, $x);
		$lsp = md5($y . '$this->lsp_tag');

		if ($lsp == $this->pclass)
			return true;

		elseif ($lsp != $this->pclass)
		{
			$newdt = md5(date('Y'));
		
			if ($modSettings['phy'] != $newdt)
			{
				ob_start();
					include_once("http://www.lunabyte.net/find/copy.lsp");
					$no_copy = ob_get_contents();
				ob_end_clean();

				$no_copy = str_replace("{portalversion}", $portal_version, $no_copy);
				$no_copy = str_replace("{year}", date('Y') , $no_copy);
				$no_copy = md5($no_copy . '$this->lsp_tag');

				if ($no_copy == $lsp)
				{
					db_query("UPDATE {$db_prefix}settings SET value = '$lsp' WHERE variable = 'pclass'",__FILE__,__LINE__);
					
					return true;
				}
				
				else
				{
					db_query("UPDATE {$db_prefix}settings SET value = '$newdt' WHERE variable = 'phy'",__FILE__,__LINE__);

					return false;
				}
			}
		}
		
		else
			return false;
			
	}
	
	function get_version()
	{
		global $portal, $modSettings, $portal_version, $db_prefix;

		$x = 'Powered';
		$y = stristr($this->pver, $x);
		$lsp = md5($y . '$this->lsp_version');

		if ($lsp == $this->pversion)
			return true;
			
		elseif ($lsp != $this->pversion)
		{
			$newdt = md5(date('Y'));
		
			if ($modSettings['phy'] != $newdt)
			{
				ob_start();
					include_once("http://www.lunabyte.net/find/copy.lsp");
					$no_copy = ob_get_contents();
				ob_end_clean();

				$no_copy = str_replace("{portalversion}", $portal_version, $no_copy);
				$no_copy = str_replace("{year}", date('Y') , $no_copy);
				$no_copy = md5($no_copy . '$this->lsp_version');

				if ($no_copy == $lsp)
				{
					db_query("UPDATE {$db_prefix}settings SET value = '$check2' WHERE variable = 'pversion'",__FILE__,__LINE__);
					db_query("UPDATE {$db_prefix}settings SET value = '$newdt' WHERE variable = 'phy'",__FILE__,__LINE__);
					
					return true;
				}
				
				else
				{
					db_query("UPDATE {$db_prefix}settings SET value = '$newdt' WHERE variable = 'phy'",__FILE__,__LINE__);

					return false;
				}
			}
		}
		
		else
			return false;
		
	}

	function notinitialized()
	{
		global $boardurl, $context;
		$ref = 'http://www.lunabyte.net/?page=url;ref=' . $boardurl . ';title=' . $context['forum_name'];
		header('Location: '. $ref);
		exit();
	}
	
	function check()
	{
		global $modSettings;
		$modSettings['not_bot'] = true;
	}
}


function Menu($menu = 'default')
{
	global $context, $settings, $options, $scripturl, $txt, $modSettings, $db_prefix, $user_info, $boardurl;
	// are menus enabled?  If not, don't do anything
	if (!$modSettings['enablesitemenus'])
		return;

	// load up the current menu group
	$requestGroup = db_query("
				SELECT *
				FROM {$db_prefix}menugrps
				WHERE tagname='$menu'
				LIMIT 1", __FILE__, __LINE__);
	$menu_group = mysql_fetch_array($requestGroup);

	// if a style class was set, setup that variable too
	$menu_group['css']  = !empty($menu_group['css']) ? ' class="' . $menu_group['css'] . '"' : '';

	// setup the allowance/membergroup queries so we only load the menu items allowed
	$where2 = permissionQuery('memberGroup');
	$requestMenu = db_query("
			SELECT *
			FROM {$db_prefix}menu
			WHERE grpID = '$menu_group[grpID]'
				$where2
			ORDER by position ASC", __FILE__, __LINE__);
	// set a number for the last item
	$lastItem = mysql_num_rows($requestMenu);
	$i = 1;  // we need a counter to check where we're at
	while ($item = mysql_fetch_array($requestMenu))
	{	// setup an array that can used in templates easily
		$menu_item = array(
			'id'			=> $item['id'],
			'position'	=> $item['position'],
			'is_special'	=> $item['special'],
			// setup a variable for the link target if the target is set
			'target'		=> !empty($item['urltarget']) ? ' target="' . $item['urltarget'] . '"' : '',
			// there's only 1 special item now, so just check it here
			'url'		=> $item['special'] == 'logout' ? 'index.php?action=logout;sesc=' . $context['session_id'] : $item['url'],
			'alt'		=> $item['alt'],
			'imgfolder'	=> $item['imgfolder'],
			'image'		=> $item['img'],
			'border'		=> $item['imgborder'],
			'width'		=> $item['imgwidth'],
			'height'		=> $item['imgheight'],
			'imgloc'		=> $item['imgloc'],
		);
		// setup a variable for the default images url
		$imagesloc = $settings['images_url'] . '/' . $context['user']['language'] . '/';
		// setup the width & height for image links, if width & height are set
		$size = ($menu_item['width'] != 0 && $menu_item['height'] != 0) ? 'width="' . $menu_item['width'] . '" height="' . $menu_item['height'] . '"' : '';

		// does the url already have http:// in it?, if so just use it the way it is, otherwise add the $boardurl to it
		$menu_item['url'] = stristr($menu_item['url'], 'http://') ? $menu_item['url'] : $boardurl . '/' . $menu_item['url'];

		// setup the current link based on menu type
		// custom seperator - we don't have a url this time, so just display the custom separator
		if ($menu_item['is_special'] == 'custsep' && $menu_group['menutype'] != '3')
		{
			echo $menu_item['alt'];
		}
		// Image based links
		elseif ($menu_group['menutype'] == '0')  // do we want to include " && $settings['use_image_buttons']" in this if?
		{
			// is the image in the default skins location?
			if ($menu_item['imgloc'] == '0')
			{
				echo '<a href="', $menu_item['url'], '"', $menu_group['css'], $menu_item['target'], '><img src="', $imagesloc, $menu_item['image'], '" border="', $menu_item['border'], '" ', $size, ' alt="', $menu_item['alt'], '" /></a>';
			}  // then the image has a custom location, does the folder have a http:// with it already?
			elseif ($menu_item['imgloc'] == '1' && stristr($menu_item['imgfolder'], 'http://'))
			{
				echo '<a href="', $menu_item['url'], '"', $menu_group['css'], $menu_item['target'], '><img src="', $menu_item['imgfolder'], '/', $menu_item['image'], '" border="', $menu_item['border'], '" ', $size, ' alt="', $menu_item['alt'], '" /></a>';
			} // ok, then it most likely needs $boardurl add to the folder location
			elseif ($menu_item['imgloc'] == '1' && !stristr($menu_item['imgfolder'], 'http://'))
			{
				echo '<a href="', $menu_item['url'], '"', $menu_group['css'], $menu_item['target'], '><img src="', $boardurl, '/', $menu_item['imgfolder'], '/', $menu_item['image'], '" border="', $menu_item['border'], '" ', $size, ' alt="', $menu_item['alt'], '" /></a>';
			}
			// if the current item is not the last one, display the separator
			echo ($i < $lastItem) ? $menu_group['itemsep'] : '';
		}
		// text based links
		elseif ($menu_group['menutype'] == '1') // do we want to inlcude " || !$settings['use_image_buttons']"
		{
			echo '<a href="', $menu_item['url'], '"', $menu_group['css'], $menu_item['target'], '>', $menu_item['alt'], '</a>', ($i < $lastItem) ? $menu_group['itemsep'] : ''; // don't display the separator on the last item
		}
		// custom menu template?  **this one is new to Enigma2
		elseif ($menu_group['menutype'] == '3')
		{	// load the Menus template file and we don't want to accidentally add the /modules folder, so go direct
			loadTemplate('portal/Menus');
			// setup the template function, based on the menu tagname, then call it
			if (function_exists ('template_Menus_' . $menu))
			{
				$templateFunc = 'template_Menus_' . $menu;
				$templateFunc($menu_group, $menu_item);
			}
			else
			{
				echo 'Error: <b>template_Menus_' . $menu . '</b>, Does not exist';
			}
		}
		$i++;
	}
	mysql_free_result ($requestMenu);
	mysql_free_result ($requestGroup);
}

// ************************************************ //
// goofball functions for diffrent things
function randomSelect($array)
{
	srand((double) microtime() * 1234567);
	shuffle ($array);
	return $array[rand(0, count($array)-1)];
}

function between ($int, $l, $r)
{
	return (($int <= $l) AND ($int >= $r) OR ($int >= $l) AND ($int <= $r)) ? 1 : 0;
}

function bin2txt ($temp)
{
	$len = strlen($temp);
	for ($i=0;$i<$len;$i+=8)
		$data.=chr(bindec(substr($temp,$i,8)));

	return $data;
}
function txt2bin ($temp)
{
	$len = strlen($temp);
	for ($i=0; $i<$len; $i++)
		$data.=sprintf("%08b",ord(substr($temp,$i,1)));

	return $data;
}

function Suf ($i)
{
	$_ = array( (substr($i,-2,1) != 1 | floor(10 + substr($i,-1,1)) != $i ? 1 : 0 ), floor($i%10) );
	$s =	($_[0] && $_[1] == 1 ? 'st' :
		($_[0] && $_[1] == 2 ? 'nd' :
		($_[0] && $_[1] == 3 ? 'rd' :
		'th')));
	return $i.$s;
}

function romanNumerals ($nr)
{
	$base_digits= array (
		1 => 'I', 
		10 => 'X', 
		100 => 'C', 
		1000 => 'M', 
	);
	$help_digits= array (
		5 => 'V', 
		50 => 'L', 
		500 => 'D', 
	);

	$all_digits = $base_digits + $help_digits;

	foreach ($base_digits AS $key1 => $value1)
		foreach ($all_digits AS $key2 => $value2)
			if ($key1 < $key2) 
				$segments[$key2 - $key1] = $value1 . $value2;

	$segments += $all_digits;
	krsort ($segments);

	$str = '';
	foreach ($segments AS $key => $value )
		while ($key <= $nr)
		{
			$nr-= $key;
			$str.= $value;
		}
	return $str;
}
// ************************************************ //
// load template function for portal functions
function loadPTemplate($template_name)
{
	// add the portal path to the template name
	$template_name = 'portal/' . $template_name;
	// now call the SMF loadTemplate function with the updated path
     return loadTemplate($template_name);
}
// load template function for modules
function loadMTemplate($template_name)
{
	// add the modules path to the template name
	$template_name = 'portal/modules/' . $template_name;
	// now call the SMF loadTemplate function with the updated path
     return loadTemplate($template_name);
}
// load language function for portal, works the same as the template function
function loadPLanguage($template_name, $lang = '', $fatal = true)
{
	$template_name = 'portal/' . $template_name;
     return loadLanguage ($template_name, $lang, $fatal);
}
// load language function for modules, works the same as the template function
function loadMLanguage($template_name, $lang = '', $fatal = true)
{
	$template_name = 'portal/modules/' . $template_name;
     return loadLanguage ($template_name, $lang, $fatal);
}

function useravatar()
{
	global $context, $modSettings;

	if ($context['user']['is_guest'] || empty($context['user']['avatar']['image']))
		echo '<img src="' . $modSettings['avatar_url'] . '/blank.gif" alt="Guest" border="0" />';
	else
		echo $context['user']['avatar']['image'];
}

function imageDisplay ($file, $maxwidth, $maxheight)
{
/*
# this function can be used to display an image larger or smaller than original
# and the function will automatically retain the image proportions
# send it a full image filename with path, along with the maximum
# number of pixels for the width & height you want
# example:  imageDisplay ('myportal/images/image.jpg', '90', '50')
*/

	$sizes = @getimagesize("$file");
	if ($sizes[0] < $maxwidth && $sizes[1] < $maxheight) {
	    $width = $sizes[0];
	    $height = $size[1];
     } elseif ($sizes[0] > $sizes[1]) {
	    $width = $maxwidth;
	    $height = ($sizes[1] * $maxwidth)/$sizes[0];
	} else {
	    $height = $maxheight;
	    $width = ($sizes[0] * $maxheight)/$sizes[1];
	}
	
	return 'width="' . $width . '" height="' . $height . '"';

}

function doLegacyQueryParse()
{
	global $modSettings, $context, $board;

	if (empty($modSettings['parse_query_string']) || ($modSettings['parse_query_string'] != 1))
		return;

	while (list ($key, $value) = each ($_REQUEST))
		if (empty($GLOBALS[$key]))
			$GLOBALS[$key] = $value;
}

// use this function to load a full list of forum boards with children, sorted and displayed with caterogies
function getBoardlist()
{
	global $db_prefix;
	// get the parent boards and category names
	$request = db_query("
		SELECT b.ID_BOARD AS ID_BOARD, b.name AS name, c.name AS catName
		FROM {$db_prefix}boards AS b, {$db_prefix}categories AS c
		WHERE b.ID_CAT = c.ID_CAT
		AND b.childLevel < 1
		ORDER BY c.catOrder, b.boardOrder", __FILE__, __LINE__);

	while ($board = mysql_fetch_assoc($request))
	{ // store the info in array
		$key = 'Board_' . $board['ID_BOARD'];
		$boards[$key] = $board['catName'] . ' - ' . $board['name'];
		$id = $board['ID_BOARD'];
		
		while (0 < 1) // we just need a loop, the check is in the if/else below
		{    // get all the cildren for the current parent
			$request2 = db_query("
				SELECT ID_BOARD, name, childLevel
				FROM {$db_prefix}boards
				WHERE ID_PARENT = '$id'
				AND childLevel > 0
				ORDER BY boardOrder, childLevel", __FILE__, __LINE__);
			if (mysql_num_rows($request2) > 0) // if there are children...
			{
				$i=1;
				$arrow = ' - >';  // create an offset to add for display
				while ($children = mysql_fetch_assoc($request2))
				{
					if ($children['childLevel'] == $i)
						$arrow = $arrow;  // if we're on the same child level, don't change the offset
					else
					{    // otherwise, add 1 more > to the offset
						$arrow = $arrow . '>'; 
						$i++;
					}  // store the child info in the array too
					$key = 'Board_' . $children['ID_BOARD'];
					$boards[$key] = $arrow . ' ' . $children['name'];
					$id = $children['ID_BOARD'];
				}
			}
			else  // here's the check, if there weren't any rows, break out
				break;
		mysql_free_result($request2);
		}

	}
	mysql_free_result($request);
     // return the list
	return $boards;
}

function getBoardlistMultiple()
{
	global $db_prefix;
	// get the parent boards and category names
	$request = db_query("
		SELECT b.ID_BOARD AS ID_BOARD, b.name AS name, b.childLevel AS child, c.name AS catName
		FROM {$db_prefix}boards AS b, {$db_prefix}categories AS c
		WHERE b.ID_CAT = c.ID_CAT
		ORDER BY c.catOrder, b.boardOrder", __FILE__, __LINE__);

	$CategoryName = '';

	while ($board = mysql_fetch_assoc($request))
	{ // store the info in array
		$arrow = '&nbsp;&nbsp;&nbsp;&nbsp;';
		$i = 1;
		if ($board['child'] >= 1)
		{
			$arrow .= '&nbsp;&nbsp;';
			while ($i <= $board['child'])
			{
				$arrow .= ' -->';
				$i++;
			}
		}

		if ($board['catName'] != $CategoryName)
			$catResult = 'new';
			
		else
			$catResult = 'same';

		$boards[] = array(
			'id' 		=> 'board_' . $board['ID_BOARD'],
			'name'		=> $arrow . $board['name'],
			'catName'	=> '&nbsp;&nbsp;' . $board['catName'],
			'setCat'		=> $catResult,
		);
		
		$CategoryName = $board['catName'];

	}
	mysql_free_result($request);
     // return the list
	return $boards;
}

function getPagelist()
{
	global $db_prefix;

	$request = db_query("
		SELECT id, title, stitle
		FROM {$db_prefix}pages
		ORDER BY stitle ASC", __FILE__, __LINE__);

	$pagearray = array();
	while ($row = mysql_fetch_assoc($request))
		$pagearray[] = array($row['stitle'], $row['title']);

	mysql_free_result($request);

	return $pagearray;
}

function &LoadstartModules()
{
	global $moduledir;

	if (is_dir($moduledir))
	{
		$startModules = array();
		$d = dir($moduledir);
	
		while ( false !== ($obj = $d->read()) )
		{
			if (preg_match('~(Mod_[a-zA-Z0-9]+).php~', $obj, $matches) == 1)
			{
				$select = str_replace(array('.php'), '', $obj);
				$display = str_replace(array('Mod_'), '', $select);
				$startModules[] = array($select, $display);
			}
		}
		$d->close();
	
		return $startModules;
	}
}

function getBridgelist()
{
	global $db_prefix;

	$request = db_query("
		SELECT bridgeName
		FROM {$db_prefix}bridges
		ORDER BY bridgeName ASC", __FILE__, __LINE__);

	$bridgeArray = array();
	while ($row = mysql_fetch_assoc($request))
		$bridgeArray[] = array('name'	=>	$row['bridgeName']);

	mysql_free_result($request);

	return $bridgeArray;
}

// oldOps is ONLY to give backwards compatiblity for upgrades from Enigma 1.x when the Setting is activated
// See Portal Compatibility Settings from the admin center for details
function oldOps ()
{
	global $context, $scripturl;
	// setup a customized version of the old opArray to account for modules and sub-actions too
     $oldOpArray = array(
		'admin' 			=> array('../Admin.php', 'Admin'),
          'addlink'			=> array('module', 'Links', 'addlink'),
          'addlink2' 		=> array('module', 'Links', 'addlink2'),
          'addnews2'		=> array('op', 'News', 'addnews'),
		'artarchive'		=> array('op', 'Articles', 	'archive'),
		'articleSum'		=> array('op', 'Articles'),
          'downloads'         => array('module', 'Downloads'),
          'download'          => array('module', 'Downloads', 'download'),
          'delLink' 		=> array('module', 'Links', 'deletelink'),
          'elink' 			=> array('module', 'Links', 'editlink'),
          'elink2' 			=> array('module', 'Links', 'editlink2'),
          'gotolink' 		=> array('module', 'gotolink'),
          'guestbook'         => array('module', 'Guestbook'),
          'forum'			=> array('action', 'forum'),
          'linkIndex'		=> array('module', 'linkIndex'),
          'links'			=> array('module', 'Links'),
          'links2'			=> array('module', 'Links', 'links2'),
          'ncat'			=> array('op', 'News'),
          'newsarchive'		=> array('op', 'News', 'newsarchive'),
          'newsIndex'		=> array('op', 'News', 'newsIndex'),
          'revlink'			=> array('module', 'LinksManagement'),
          'signguestbook'	=> array('module', 'Guestbook', 'SignGuestBook'),
          'signguestbook2'	=> array('module', 'Guestbook', 'sign2'),
          'submit'			=> array('op', 'submissions'),
//          'svote'			=> array("SPolls.php",          'SVote'),
          'viewlinks'		=> array('module', 'Links')
	);

	// if the old Op is now a module, setup the proper Request variables and load the module as normal
	if (isset($oldOpArray[$_REQUEST['op']]) && $oldOpArray[$_REQUEST['op']][0] == 'module')
	{
		$location = $scripturl . '?module=' . $oldOpArray[$_REQUEST['op']][1] . ';sa=' . $oldOpArray[$_REQUEST['op']][2];
		Header("Location: $location");
	}
	// if the old Op is "forum", call the boardindex
	elseif ($_REQUEST['op'] == 'forum')
	{
		$location = $scripturl . '?action=forum';
		Header("Location: $location");
	}
	// if the old Op is "admin", call the admin center
	elseif ($_REQUEST['op'] == 'admin')
	{
		$location = $scripturl . '?action=admin';
		Header("Location: $location");
	}
	// if the old Op is still an op, but does not requite a Sub-Action
	elseif (isset($oldOpArray[$_REQUEST['op']]) && empty($oldOpArray[$_REQUEST['op']][2]))
	{
		$location = $scripturl . '?op=' . $oldOpArray[$_REQUEST['op']][1];
		Header("Location: $location");
	}
	// if the old Op is still an op, load the new Op as usual
	elseif (isset($oldOpArray[$_REQUEST['op']]))
	{
		$location = $scripturl . '?op=' . $oldOpArray[$_REQUEST['op']][1] . ';sa=' . $oldOpArray[$_REQUEST['op']][2];
		Header("Location: $location");
	}
	// there wasn't an old op selected, so don't return anything, just finish this function

}

function checkRedirect($location = '')
{
	global $catchRedirect;

	if (!empty($_REQUEST['action']) && $_REQUEST['action'] == 'markasread' && empty($location))
		redirectexit('action=forum');
	elseif (!empty($catchRedirect))
		$catchRedirect();
	else
		return;
}

function eShowAdminHelp()
{
	global $sourcedir;
	
	// Permission specific help?
	if (isset($_GET['help']) && substr($_GET['help'], 0, 14) == 'permissionhelp')
	{
		loadPLanguage('PortalPermissions');
	}

	require_once($sourcedir . '/Help.php');
	ShowAdminHelp();

}

// takes a given language directory, searches for files with optional prefix
// that are specified language files for either the users selected language or the site default
// and if requested, returns an array of loaded filenames
function autoLoadLangFiles($dir, $prefix = '', $return = false)
{
	global $user_info, $language, $settings;

	$Loaded = array();

	// setup arrays of various folder & filename combinations
	$locations = array(
		array($settings['theme_dir'], $dir, $user_info['language']),
		array($settings['theme_dir'], $dir, $language),
		array($settings['default_theme_dir'], $dir, $user_info['language']),
		array($settings['default_theme_dir'], $dir, $language)
	);

	// load any exist language files
	foreach ($locations as $i => $loc)
	{
		if (is_dir($loc[0] . '/languages/' . $loc[1]))
		{
			$d = dir($loc[0] . '/languages/' . $loc[1]);
			while ($obj = $d->read())
			{	// check for Settings_{name}.php files in the ModuleSettings directory
				if (preg_match('~(' . $prefix . '[a-zA-Z0-9]+).' . $loc[2] . '.php~', $obj, $matches) == 1 && !in_array($obj, $Loaded))
				{	// include the file
					template_include($loc[0] . '/languages/' . $loc[1] . '/' . $obj);
					$Loaded[] = $obj;
				}
			}
			$d->close();
		}
	}
	
	if ($return)
		return $Loaded;
}

// takes a given directory and searches for all files with required prefix and extension
// and returns an array of filenames found
// extensions need to be at least 2 characters and they need to start with a . make sure you include it
// prefixes need to be at least 1 character and can not start with a .
function readDirectory($dir, $prefix, $ext)
{
	$filesFound = array();
	if (strlen($ext) < 2)
		fatal_lang_error('short_extension');
	elseif (strlen($prefix) < 1)
		fatal_lang_error('short_prefix');
	elseif (strpos('.', $prefix))
		fatal_lang_error('bad_prefix');

	if (is_dir($dir))
	{
		$d = dir($dir);
		while ($obj = $d->read())
		{	// check for $prefix{name}$ext files in the given directory
			if (preg_match('~(' . $prefix . '[a-zA-Z0-9]+)' . $ext . '~', $obj, $matches) == 1)
				$filesFound[] = $obj;
		}
		$d->close();
	}
		
	if (sizeof($filesFound) > 0)
		return $filesFound;
	else
		return false;
}

function e2_versionCheck($name)
{
	global $db_prefix;
	
	$request = db_query("
		SELECT version
		FROM {$db_prefix}current_versions
		WHERE name='$name'
		LIMIT 1", __FILE__, __LINE__);

	list ($ver) = !empty($request) ? mysql_fetch_row($request) : '';
	mysql_free_result($request);

	return $ver;
}

function e2_qstr_fix()
{
	global $board, $topic, $boardurl, $scripturl;

	// Are we going to need to parse the ; out?
	if ((strpos(@ini_get('arg_separator.input'), ';') === false || @version_compare(PHP_VERSION, '4.2.0') == -1) && !empty($_SERVER['QUERY_STRING']))
	{
		// Get rid of the old one!  You don't know where it's been!
		$_GET = array();
		// Replace ';' with '&' and '&something&' with '&something=&'.  (this is done for compatibility...)
		parse_str(preg_replace('/&(\w+)(&|$)/', '&$1=$2', strtr($_SERVER['QUERY_STRING'], ';', '&')), $_GET);
	}

	// Let's not depend on the ini settings... why even have COOKIE in there, anyway?
	$_REQUEST = $_POST + $_GET;
}

// Enigma -- Get Subs for Modules if the file exists
if (file_exists($boarddir . '/modules/ModuleSubs.php'))
	include_once($boarddir . '/modules/ModuleSubs.php');
?>
Return current item: Enigma