Location: PHPKode > projects > OpenNitro > trunk/Nitro/Common.inc.php
<?php
//
// +---------------------------------------------------------------------------+
// | Nitro :: Common                                                           |
// +---------------------------------------------------------------------------+
// | Copyright (c) 2003 June Systems BV                                        |
// +---------------------------------------------------------------------------+
// | This library is free software; you can redistribute it and/or modify it   |
// | under the terms of the GNU Lesser General Public License as published by  |
// | the Free Software Foundation; either version 2.1 of the License, or (at   |
// | your option) any later version.                                           |
// |                                                                           |
// | This library is distributed in the hope that it will be useful, but       |
// | WITHOUT ANY WARRANTY; without even the implied warranty of                |
// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser   |
// | General Public License for more details.                                  |
// |                                                                           |
// | You should have received a copy of the GNU Lesser General Public License  |
// | along with this library; if not, write to the Free Software Foundation,   |
// | Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA            |
// +---------------------------------------------------------------------------+
// | Authors: Siggi Oskarsson <hide@address.com>                          |
// +---------------------------------------------------------------------------+
//
// $Id: Common.inc.php 231 2008-05-21 13:39:26Z janroel $
//
// Nitro's common function definition
//

/**
 * This file contains the common functions for Nitro
 *
 * @package	Nitro
 * @subpackage	Base
 * @author 		Siggi Oskarsson
 * @version 	$Revision: 1.20 $
 * @copyright	2004 June Systems BV
 */

/**
 * Get all languages allowed
 *
 * This function returns an array of all the languages that have been
 * defined as allowed for the site of the given DB connection.
 *
 * @param	object	$DB	DB connection for site
 */
function NitroGetAllowedLanguages(&$DB)
{
	global $__NitroGetAllowedLanguages_Cache;
	
	if (isset($__NitroGetAllowedLanguages_Cache[$DB->DSN[0]])) {
		$RV = $__NitroGetAllowedLanguages_Cache[$DB->DSN[0]];
	} else {
		$AllowedLanguages = Array();
		$Query = "
			SELECT
				LA.Language,
				L.Name
			FROM LanguageAllowed AS LA
			INNER JOIN Language AS L ON LA.Language = L.Language
			ORDER BY L.Name, LA.Language
		";
		$Result = $DB->query($Query);
		if($Result->numRows()){
			$LanguageStrings = array();
			while($Data = $Result->fetchArray()){
				$AllowedLanguages[$Data["Language"]] = $Data["Name"];
			}
		}else{
			//no results in AllowedLanguagesTable, so allow none
			//$AllowedLanguages["eng"] = "English";
		}
		$Result->free();
		
		$RV = $AllowedLanguages;
		$__NitroGetAllowedLanguages_Cache[$DB->DSN[0]] = $RV;
	}

	return $RV;
}

/**
 * Get active language of current user
 *
 * This function returns the language code of the current
 * user.
 *
 * @return	string	Language code
 */
function NitroGetUserLanguage() {
	global $__NSess;
	return	$__NSess->Language;
}

/**
 * Set active language to given
 *
 * This function sets the language of the environment to
 * that given by $LanguageCode
 *
 * @param	int	$Length	Length of string to create
 * @return	string	Random string of length $Length
 */
function NitroSetUserLanguage($LanguageCode)
{
	global $__NSess, $DB;
	
	$AllowedLanguages = NitroGetAllowedLanguages($DB["Nitro"]);
	$AllowedLanguagesKeys = array_keys($AllowedLanguages);
	
	if (in_array($LanguageCode, $AllowedLanguagesKeys)) {
		Debug("Common", "SetUserLanguage", "Setting user language to: ".$LanguageCode, __FILE__, __LINE__);
		$__NSess->Language = $LanguageCode;
		$RV = TRUE;
	} else {
		Debug("Common", "SetUserLanguage", "Setting of user language ".$LanguageCode." failed, not allowed", __FILE__, __LINE__);
		$RV = FALSE;
	}
	
	return $RV;
}

/**
 * Get Nitro cache dir function
 *
 * This function returns the full path of the cache dir to use.
 * If $SubDir is an array, a directory structure will be created.
 *
 * @param	mixed	$SubDir	String or array of sub directories to use in cache dir
 * @param	string	$CachePath	Cache path to use in stead of the config cache path
 * @return	string	Full path of cachedir to use
 * @todo Clean up code to use NitroMkdirRecursive() in stead if foreach loops and mkdir
 */
function NitroGetCacheDir($SubDir, $CachePath = FALSE)
{
	if (!is_dir(NitroGetConfig("Paths/Cache"))) NitroMkdirRecursive(NitroGetConfig("Paths/Cache"));
	if (!$CachePath) $CachePath = NitroGetConfig("Paths/Cache").DIRECTORY_SEPARATOR.$_SERVER['HTTP_HOST'].DIRECTORY_SEPARATOR.sha1(NITRO_CONFIG);

	if ($CachePath) {
		if (!is_dir($CachePath)) NitroMkdirRecursive($CachePath);
		$NitroBaseCacheDir = $CachePath.DIRECTORY_SEPARATOR."Nitro";
		if (!is_dir($NitroBaseCacheDir)) mkdir($NitroBaseCacheDir);
		if (is_array($SubDir)) {
			$TempDir = FALSE;
			foreach($SubDir AS $Dir) {
				$TempDir.= DIRECTORY_SEPARATOR.$Dir;
				if (!file_exists($NitroBaseCacheDir.DIRECTORY_SEPARATOR.$TempDir)) mkdir($NitroBaseCacheDir.DIRECTORY_SEPARATOR.$TempDir);
			}
			$CacheDir = $NitroBaseCacheDir.DIRECTORY_SEPARATOR.$TempDir;
			unset($TempDir);
		} else {
			if (!file_exists($NitroBaseCacheDir.DIRECTORY_SEPARATOR.$SubDir)) mkdir($NitroBaseCacheDir.DIRECTORY_SEPARATOR.$SubDir);
			$CacheDir = $NitroBaseCacheDir.DIRECTORY_SEPARATOR.$SubDir;
		}
		if (is_writable($CacheDir)) {
			return $CacheDir;
		} else {
			return FALSE;
		}
	} else {
		return FALSE;
	}
}

/**
 * Get Nitro tmp cache dir function
 *
 * This function returns the full path of the tmp cache dir to use.
 * If $SubDir is an array, a directory structure will be created.
 * The tmp cache dir is different from the normal cache dir in that
 * the files written to the tmp cache dir are not needed again, but
 * are only created for performance gains. This is very important in
 * a load balanced situation where one server writes something to the
 * cache and another uses the cache. In that case you should use
 * NitroGetCacheDir() in stead of NitroGetTmpCacheDir()!
 *
 * @param	mixed	$SubDir	String or array of sub directories to use in cache dir
 * @return	string	Full path of cachedir to use
 */
function NitroGetTmpCacheDir($SubDir, $CachePath = FALSE)
{
	if ($CachePath)
		$CachePath = $CachePath; // do nothing
	elseif (NitroGetConfig("Paths/TmpCache"))
		$CachePath = NitroGetConfig("Paths/TmpCache").DIRECTORY_SEPARATOR.$_SERVER['HTTP_HOST'].DIRECTORY_SEPARATOR.sha1(NITRO_CONFIG);
	else
		$CachePath = NitroGetConfig("Paths/Cache").DIRECTORY_SEPARATOR.$_SERVER['HTTP_HOST'].DIRECTORY_SEPARATOR.sha1(NITRO_CONFIG);

	return NitroGetCacheDir($SubDir, $CachePath);
}

/**
 * Get all security groups of user
 *
 * This function creates an array of all the security groups the
 * user given belongs to. If the user does not belong to any security
 * groups, an array with 0 (zero) as the only element will be returned.
 *
 * @param		int		$UserID	User id
 * @return	array	Array of security groups or Array(0) if none
 */
function NitroGetSecurityGroups($UserID)
{
	global $DB, $__NitroGetSecurityGroups_Cache;

	if (isset($__NitroGetSecurityGroups_Cache[$UserID])) {
		$SecurityGroups = $__NitroGetSecurityGroups_Cache[$UserID];
	} else {
		$Query = "SELECT SecurityGroupID
							FROM User_SecurityGroup
							WHERE UserID = ".(int)$UserID."
							";
		$SecurityGroups = $DB["Nitro"]->getCol($Query);
		if (!count($SecurityGroups)) $SecurityGroups[] = 0;
		$__NitroGetSecurityGroups_Cache[$UserID] = $SecurityGroups;
	}

	return $SecurityGroups;
}

/**
 * Prepare string for database query
 *
 * This function prepares the given string for use in a database
 * query. If the string is not an integer, it will be quoted and
 * addslashes will be run in it. If the $Null parameter is TRUE
 * the return value will be (string)"NULL" if the string is empty.
 *
 * @param	string	$String	String to prepare for query
 * @param	boolean	$Null	Can value be NULL, set if $String is empty
 * @param	string	$DBType	For which database to do this (not implemented) (default MySQL)
 * @return	mixed	Return value, string or integer
 */
function NitroPrepareDB($String, $Null = FALSE, $DBType = "MYSQL")
{
	if (strlen($String)) {
		if (!ereg("[^0-9]", $String) && ((int)$String OR $String === 0)) $RV = $String;
		else $RV = "'".addslashes($String)."'";
	} else {
		if ($Null) $RV = "NULL";
		else $RV = "''";
	}
	
	return $RV;
}

/**
 * Get page IDString from SystemIDString
 *
 * This function returns the IDString of the page
 * with the SystemIDString or FALSE on failure.
 *
 * @param	string	$SystemIDString	ID string of object
 * @return	mixed	IDString or FALSE on failure
 */
function NitroGetPageIDString($SystemIDString)
{
	global $DB, $__NitroGetPageIDString_Cache;
	DebugGroup("Base", "NitroGetPageIDString", "Retreiving ID string from system ID ".$SystemIDString, __FILE__, __LINE__, DEBUG_APPL_OK);

	if (isset($__NitroGetPageIDString_Cache[$SystemIDString])) {
		$RV = $__NitroGetPageIDString_Cache[$SystemIDString];
		Debug("Base", "NitroGetPageIDString", "USING CACHE: ".$RV, __FILE__, __LINE__, DEBUG_APPL_OK);
	} else {
		$Query = "SELECT IDString
							FROM Page
							WHERE SystemIDString = ".NitroPrepareDB($SystemIDString)."
							";
		if ($PageIDString = $DB["Nitro"]->getOne($Query)) {
			Debug("Base", "NitroGetPageIDString", "String found: ".$PageIDString, __FILE__, __LINE__, DEBUG_APPL_OK);
			$RV = $PageIDString;
		} else {
			Debug("Base", "NitroGetPageIDString", "String NOT found", __FILE__, __LINE__, DEBUG_APPL_ERR);
			$RV = FALSE;
		}
		$__NitroGetPageIDString_Cache[$SystemIDString] = $RV;
	}

	DebugCloseGroup(DEBUG_APPL_OK);
	return $RV;
}

/**
 * Get object id from SystemIDString
 *
 * This function returns the object ID of the object
 * with the SystemIDString or FALSE on failure.
 *
 * @param	string	$SystemIDString ID string of object
 * @return	mixed	Object ID or FALSE
 */
function NitroGetObjectID($SystemIDString)
{
	global $DB, $__NitroGetObjectID_Cache;
	DebugGroup("Base", "NitroGetObjectID", "Retreiving ObjectID from system ID ".$SystemIDString, __FILE__, __LINE__, DEBUG_APPL_OK);

	if (isset($__NitroGetObjectID_Cache[$SystemIDString])) {
		$RV = $__NitroGetObjectID_Cache[$SystemIDString];
		Debug("Base", "NitroGetObjectID", "USING CACHE: ".$RV, __FILE__, __LINE__, DEBUG_APPL_OK);
	} else {
		$Query = "SELECT ObjectID
							FROM Object
							WHERE SystemIDString = ".NitroPrepareDB($SystemIDString)."
							";
		if ($ObjectID = $DB["Nitro"]->getOne($Query)) {
			Debug("Base", "NitroGetObjectID", "ObjectID found: ".$ObjectID, __FILE__, __LINE__, DEBUG_APPL_OK);
			$RV = $ObjectID;
		} else {
			Debug("Base", "NitroGetObjectID", "ObjectID NOT found", __FILE__, __LINE__, DEBUG_APPL_ERR);
			$RV = FALSE;
		}
		$__NitroGetObjectID_Cache[$SystemIDString] = $RV;
	}

	DebugCloseGroup(DEBUG_APPL_OK);
	return $RV;
}

/**
 * Get object IDString from SystemIDString
 *
 * This function returns the IDString of the object
 * with the SystemIDString or FALSE on failure.
 *
 * @param	string	$SystemIDString	ID string of object
 * @return	mixed	IDString or FALSE on failure
 */
function NitroGetObjectIDString($SystemIDString)
{
	global $DB, $__NitroGetObjectIDString_Cache;
	DebugGroup("Base", "NitroGetObjectIDString", "Retreiving IDString from SystemIDString ".$SystemIDString, __FILE__, __LINE__, DEBUG_APPL_OK);

	if (isset($__NitroGetObjectIDString_Cache[$SystemIDString])) {
		$RV = $__NitroGetObjectIDString_Cache[$SystemIDString];
		Debug("Base", "NitroGetObjectIDString", "USING CACHE: ".$RV, __FILE__, __LINE__, DEBUG_APPL_OK);
	} else {
		$Query = "SELECT IDString
							FROM Object
							WHERE SystemIDString = ".NitroPrepareDB($SystemIDString)."
							";
		if ($IDString = $DB["Nitro"]->getOne($Query)) {
			Debug("Base", "NitroGetObjectIDString", "IDString found: ".$IDString, __FILE__, __LINE__, DEBUG_APPL_OK);
			$RV = $IDString;
		} else {
			Debug("Base", "NitroGetObjectIDString", "IDString NOT found", __FILE__, __LINE__, DEBUG_APPL_ERR);
			$RV = FALSE;
		}
		$__NitroGetObjectIDString_Cache[$SystemIDString] = $RV;
	}

	DebugCloseGroup(DEBUG_APPL_OK);
	return $RV;
}

/**
 * Get object id from IDString
 *
 * This function returns the object ID of the object
 * with the IDString or FALSE on failure.
 *
 * @param	string	$IDString	ID string of object
 * @return	mixed	Object ID or FALSE
 */
function NitroGetObjectIDFromIDString($IDString)
{
	global $DB, $__NitroGetObjectIDFromIDString_Cache;
	DebugGroup('Base', 'NitroGetObjectIDFromIDString', "Retrieving ObjectID from IDString $IDString", __FILE__, __LINE__, DEBUG_APPL_OK);

	if (isset($__NitroGetObjectIDFromIDString_Cache[$IDString])) {
		$RV = $__NitroGetObjectIDFromIDString_Cache[$IDString];
		Debug('Base', 'NitroGetObjectIDFromIDString', "USING CACHE: $RV", __FILE__, __LINE__, DEBUG_APPL_OK);
	} else {
		$Query = "SELECT ObjectID
							FROM `Object`
							WHERE IDString = ".NitroPrepareDB($IDString)."
							";
		if (($ObjectID = $DB['Nitro']->getOne($Query))) {
			Debug('Base', 'NitroGetObjectIDFromIDString', "ObjectID found: $ObjectID", __FILE__, __LINE__, DEBUG_APPL_OK);
			$RV = $ObjectID;
		} else {
			Debug('Base', 'NitroGetObjectIDFromIDString', "ObjectID NOT found", __FILE__, __LINE__, DEBUG_APPL_ERR);
			$RV = FALSE;
		}
		$__NitroGetObjectIDFromIDString_Cache[$IDString] = $RV;
	}

	DebugCloseGroup(DEBUG_APPL_OK);
	return $RV;
}

/**
 * Get all IDString's of pages allowed
 *
 * This function returns an array of IDString's for all pages
 * the current user is allowed to view.
 *
 * @return	array	Page ID strings
 */
function NitroGetAllowedPages($UserID = FALSE)
{
	global $__NSess, $__NitroConf, $DB, $__NitroGetAllowedPages_Cache;
	DebugGroup("Common", "GetAllowedPages", "Checking which pages are allowed to be viewed by user ".$IDString, __FILE__, __LINE__, DEBUG_APPL_OK);

	if (isset($__NitroGetAllowedPages_Cache[$UserID])) {
		$RV = $__NitroGetAllowedPages_Cache[$UserID];
		Debug("Common", "GetAllowedPages", "USING CACHE, pages found: ".count($RV), __FILE__, __LINE__, DEBUG_APPL_OK);
	} else {
		$Sess =& $__NSess;
		$Conf =& $__NitroConf->CONF;
	
		$Security = $Conf["Settings"]["Security"];
	
		if ($Security && $UserID) {
			$SecurityGroups = NitroGetSecurityGroups($UserID);
		} elseif ($Security) {
			$SecurityGroups = $Sess->SecurityGroups;
		} else {
			$SecurityGroups = Array(0);
		}
		$Query = "SELECT DISTINCT IDString
							FROM Page AS P
							".($Security ? ", Page_SecurityGroup AS PSP" : "")."
							WHERE 1
							".($Security ? "	AND PSP.PageID = P.PageID AND PSP.SecurityGroupID IN (".implode(",", $SecurityGroups).")" : "")."
							ORDER BY IDString
							";
		if ($Pages = $DB["Nitro"]->getCol($Query)) {
			Debug("Common", "GetAllowedPages", "Allowed pages found: ".count($Pages), __FILE__, __LINE__, DEBUG_APPL_OK);
			$RV = $Pages;
		} else {
			Debug("Common", "GetAllowedPages", "No allowed pages found", __FILE__, __LINE__, DEBUG_APPL_ERR);
			$RV = FALSE;
		}
		$__NitroGetAllowedPages_Cache[$UserID] = $RV;
	}
	
	DebugCloseGroup(DEBUG_APPL_OK);
	return $RV;
}

/**
 * Check whether certain page is allowed to be viewed by user
 *
 * This function returns a boolean of whether the current user is allowed to
 * view the page given by it's IDString.
 *
 * @param	string	Page ID string
 * @return	boolean	Page allowed or not
 */
function NitroGetPageAllowed($IDString, $UserID = FALSE)
{
	global $__NSess, $__NitroConf, $DB, $__NitroGetPageAllowed_Cache;
	DebugGroup("Common", "GetPageAllowed", "Checking whether page is allowed to be views by user ".$IDString, __FILE__, __LINE__, DEBUG_APPL_OK);

	if (isset($__NitroGetPageAllowed_Cache[$IDString][$UserID])) {
		$RV = $__NitroGetPageAllowed_Cache[$IDString][$UserID];
		Debug("Common", "GetPageAllowed", "USING CACHE: ".($RV ? 'viewable' : 'secured'), __FILE__, __LINE__, DEBUG_APPL_OK);
	} else {
		$Sess =& $__NSess;
		$Conf =& $__NitroConf->CONF;
	
		$Security = $Conf["Settings"]["Security"];
	
		if ($Security && $UserID) {
			$SecurityGroups = NitroGetSecurityGroups($UserID);
		} elseif ($Security) {
			$SecurityGroups = $Sess->SecurityGroups;
		} else {
			$SecurityGroups = Array(0);
		}
	
		$Query = "SELECT P.PageID
							FROM Page AS P
							".($SecurityGroups ? ", Page_SecurityGroup AS PSP" : "")."
							WHERE P.SystemIDString = ".NitroPrepareDB($IDString)."
							".($SecurityGroups ? "	AND PSP.PageID = P.PageID AND PSP.SecurityGroupID IN (".implode(",", $SecurityGroups).")" : "")."
							";
		if ($PageID = $DB["Nitro"]->getOne($Query)) {
			Debug("Common", "GetPageAllowed", "Page secured from user", __FILE__, __LINE__, DEBUG_APPL_OK);
			$RV = TRUE;
		} else {
			Debug("Common", "GetPageAllowed", "Page viewable to user", __FILE__, __LINE__, DEBUG_APPL_ERR);
			$RV = FALSE;
		}

		$__NitroGetPageAllowed_Cache[$IDString][$UserID] = $RV;
	}

	DebugCloseGroup(DEBUG_APPL_OK);
	
	return $RV;
}

function NitroRegenerateSessionID()
{
	// Regenerate session id and delete old session data in dir
	// (PHP < 5.1 leaves the old session data file on the filesystem)
	$oldSessionID = session_id();
	$sess = $_SESSION;
	session_regenerate_id();
	$_SESSION = $sess;
	unset($sess);
	NitroSession_SaveToDisk();
	
	NitroSession_DeleteSessionData($oldSessionID);
}

/**
 * Create a random string
 *
 * Thus function creates a random string of the set length using
 * only numbers, letters and capitals.
 *
 * @param	int	$Length	Length of string to create
 * @return	string	Random string of length $Length
 */
function NitroCreateRandomString($Length)
{
	$String = "";
	for($i = 0; $i < $Length; $i++) {
		$R = rand(0,2);
		if ($R == 0) {
			// int
			$String.= chr(rand(48,57));
		} elseif ($R == 1) {
			// capital letter
			$String.= chr(rand(65,90));
		} else {
			// letter
			$String.= chr(rand(97,122));
		}
	}
	
	return $String;
}

/**
 * Get current microtime
 *
 * This functions returns the current time, accurate to the 
 * micro second. This is used in the debugging to add timer information.
 *
 * @return	float	Current microtime
 */
function NitroGetMicroTime()
{ 
	list($usec, $sec) = explode(" ",microtime()); 
	return ((float)$usec + (float)$sec);
}

/**
 * Get current cpu time for this process
 *
 * This functions returns the current cpu time (user + system), accurate to 1/100 of a second. 
 *
 * @return	float	current cpu time
 */
define ('_SC_CLK_TCK', 100); // sysconf clock ticks per second
function NitroGetCpuTime()
{
	$CpuTime = FALSE;
	
	if (function_exists('posix_times')) {
		$times = posix_times(); // see: man 2 times

		$CpuTime = ($times['utime']+$times['stime']) / _SC_CLK_TCK;
	}
	
	return $CpuTime;
}

/**
 * Space
 *
 * Function to generate spaces. This should be removed!!!! (*Looking @ Joris...*)
*/
function space($Count = 1)
{
	$RV = "";
	
	for($i = 0; $i < $Count; $i++) $RV.= "&nbsp;";
	
	return $RV;
}

/**
 * Get configuration option
 *
 * This function returns the configuration option requested via a string seperated
 * by a "/" (ie. "Paths/Image").
 *
 * @param	string	$Config	Configuration option requested
 * @return	string	Configuration value
 */
function NitroGetConfig($Config)
{
	global $__NitroConf;
	
	$tmp = explode("/", $Config);
	
	if (is_array($__NitroConf->CONF)
		&& array_key_exists($tmp[0], $__NitroConf->CONF)
		&& is_array($__NitroConf->CONF[$tmp[0]])
		&& array_key_exists($tmp[1], $__NitroConf->CONF[$tmp[0]])
	) {
		$RV = $__NitroConf->CONF[$tmp[0]][$tmp[1]];
	} else {
		$RV = FALSE;
	}
	
	return $RV;
}

/**
 * Create dirs recursively
 *
 * This function creates the dir given and all its sub directories as needed.
 *
 * @param	string	$DirName	Name of directory to create
 * @todo	Use built in php function mkdir when using PHP > 5
 */
function NitroMkdirRecursive($DirName)
{
	$SubDir = explode(DIRECTORY_SEPARATOR, $DirName);
	$dir	= '';

	foreach ($SubDir as $part) {
		$dir .= $part.DIRECTORY_SEPARATOR;
		if (!is_dir($dir) && strlen($dir) > 0)
	  	mkdir($dir);
	}
}

/**
 * Clean get string file name for usage
 *
 * This function cleans all disallowed characters from the file name (|, >, <, /./).
 * This function will also translate the /../ to the directory below the previous.
 * If $CheckRoot is given, the function will also check whether the final path is
 * within $CheckRoot.
 *
 * @param	string	$FileName	Name of file path to clean
 * @param	string	$CheckRoot	Path of root to check in file path (see chroot())
 */
function NitroCleanRequestStringFile($FileName, $CheckRoot = FALSE)
{
	$getFile = str_replace(array('<', '>', '|'), '', $FileName);
	$getFile = ereg_replace('/\.\/', '/', $getFile);
	$getFile = ereg_replace('\/+', '/', $getFile);
	$getFile = strip_tags($getFile);

	// Fix paths
	// TODO: use realpath() instead ???
	while (strpos($getFile, '/../')) {
		$getFile = preg_replace('"\/([a-z_-]+)\/\.\.\/"sUi', '/', $getFile);
	}
	$getFile = ereg_replace('\.+', '.', $getFile);

	if ($CheckRoot && strpos($getFile, $CheckRoot) !== 0) $getFile = FALSE;

	return $getFile;
}

/**
 * File exists in include paths.
 *
 * Checks if the given filename exists in any of the set include paths.
 * This is usefull, since file_exists does not check all include paths.
 *
 * @param		string	$fileName	Name of the file to check if it exists.
 * @uses		NitroCleanRequestStringFile
 * @return	mixed		Returns given $fileName if file is not found, else the complete filepath.
 & @access	public
 */
function file_exists_include_path($fileName = FALSE)
{
	if ($fileName !== FALSE)
	{
		$IncludePaths = explode(PATH_SEPARATOR, get_include_path());
		
		foreach ($IncludePaths AS $IncludePath) {
			$FullFilePath = $IncludePath.DIRECTORY_SEPARATOR.$fileName;
			
			if (file_exists($FullFilePath)) {
				return NitroCleanRequestStringFile($FullFilePath, $IncludePath);
			}
		}
	}
	
	return $fileName;
}

/**
 * Wrapper IF-function which returns the value of the given variable,
 * or if the variable is not set, the given default value.
 *
 * Note: Both the $Variable and the $Default parameters are required!
 *
 * @param		mixed	$Variable Variable for which the default should be returned if not set.
 * @param		mixed	$Default	The default value for the variable if not set.
 * @return	mixed	The given variable value or it's given default value.
 * @access	public
 */
function GetDefaultValue($Variable, $Default)
{
	$RV = $Default;
	if (isset($Variable)) $RV = $Variable;
	return $RV;
}
?>
Return current item: OpenNitro