Location: PHPKode > projects > MJGUEST > mjguest/mjguest.core.php
<?php
	
	/*
	+---------------------------------------------------------------
	|
	|	MJGUEST
	|	============================================================
	|	Copyright (c) 2002-2008 Giacomo "mdsjack" Menni
	|	Terms of agreement and support at www.mdsjack.bo.it
	|
	+---------------------------------------------------------------
	|	[ CORE BASE ]
	|	MJGUEST CORE
	+---------------------------------------------------------------
	*/
	
	#----- Let's check if installation was done -----#
	
	if (!include (mjguest_basedir.'setup.ini.php'))
		include (mjguest_basedir.'error.inc.php');
	
	#----- Enable error tracking in debug mode -----#
	
	if (mjguest_debugmode)
		@ini_set('track_errors', true);
	
	#----- If we are not in debug-mode, we can hide non-critic errors -----#
	
	(mjguest_debugmode == true) ? error_reporting(E_ALL) : error_reporting(E_ALL ^ E_NOTICE);
	
	#----- MJGUEST CORE -----#
	
	class guestbook
	{
		var $_ext = '.inc.php';
		var $db;
		var $settings;
		var $entry;
		var $gui;
		var $user;
		var $sys_dirs;
		var $sys_files;
		var $adv_settings;
		var $processor_in;
		var $processor_out;
	#	var $standalone;
		
		function guestbook($startup = true)
		{
		#	$this->standalone = $startup;
			
			$this->sys_dirs = array
			( 'modules'		=> mjguest_basedir.'modules/'
			, 'db'			=> mjguest_basedir.'database/'
			, 'PEAR'		=> mjguest_basedir.'resources/PEAR/'
			, 'gui'			=> mjguest_basedir.'interface/'
			, 'js'			=> mjguest_basedir.'interface/scripts/'
			, 'emoticons'	=> mjguest_basedir.'interface/emoticons/'
			, 'lang'		=> mjguest_basedir.'interface/language/'/*'../_LANGUAGE/'*/
			, 'theme'		=> ''
			);
			
			$this->sys_files = array
			( 'countries'	=> mjguest_basedir.'resources/countries.db'
			, 'swearwords'	=> mjguest_basedir.'resources/swearwords.db'
			, 'spam'		=> mjguest_basedir.'resources/spam.db'
			, 'timezones'	=> mjguest_basedir.'resources/timezones.csv'
			, 'ip2country'	=> mjguest_basedir.'resources/ip-to-country.db'
			, 'captchafont'	=> mjguest_basedir.'resources/captcha.gdf'
			, 'captcha'		=> mjguest_basedir.'captcha.jpg.php'
			, 'avatar'		=> mjguest_basedir.'avatar.jpg.php'
			);
			
			#################### [ ADVANCED SETTINGS ] ####################
			# Not included in Admin Control Panel. EDIT AT YOUR OWN RISK. #
			
			$this->advanced_settings = array 
			
			// Choose an available language file to use as default, in case automatic detection fails
			( 'default_lang'	=> 'en'		# Language ISO code (Use the prefix of a file inside folder "interface/language/")
			
			// When using Embedded mode, you can have the guestbook looking like a comment system
			, 'comment_system'	=> false	# DEFAULT: false
			
			// Show web link titles instead of addresses inside message bodies (WARNING: the script will slow down considerably!)
			, 'url_titles'		=> false	# DEFAULT: false
			
			// Maximum allowed "new lines" in messages (prevents endless messages)
			, 'msg_maxlines'	=> 15		# DEFAULT: 15
			
			, 'titlelen'		=> 50		# DO NOT EDIT!
			, 'adminmaillen'	=> 80		# DO NOT EDIT!
			
			// Max Width and Height of avatars thumbnails (in pixels)
			, 'userpic' => array # EDIT ACCORDING TO CUSTOM LAYOUT
				( 'width'	=> 75			# Width in pixels	# DEFAULT: 75
				, 'height'	=> 75			# Height in pixels	# DEFAULT: 75
				)
			
			// Available date-time formats (valid patterns for php "date()" function)
			, 'dateformats' => array
				( 'd.m.Y h:ia'		=> 'D.M.Y 12h'		# Business international
				, 'm/d/Y h:ia'		=> 'M/D/Y 12h'		# American
				, 'Y-m-j h:ia'		=> 'Y-M-D 12h'		# Asian
				, 'd.m.Y H:i'		=> 'D.M.Y 24h'		# German
				, 'd/m/Y H:i'		=> 'D/M/Y 24h'		# Italian
				, 'F, jS Y h:ia'	=> 'MM, Dth Y 12h'	# English
				, 'j F Y h:ia'		=> 'D MM Y 12h'		# Generic
				, 'd.m.Y @ .B'		=> 'D.M.Y @ .Beat™'	# Swatch(R) Internet time
				)#	Pattern			=> Representation	# Description
			);
			
			################ [ End of ADVANCED SETTINGS ] #################
			
			
			
			#--dev code
			// Default date-time format (in case automatic detection fails)
		#	, 'dateformat'		=>	'j F Y h:ia'	# DEFAULT: 'j F Y h:ia' (Valid PHP date() format)
			
				/***** Some examples you can use ************\
				'd.m.Y h:ia'	=	25.12.2008 9:53pm
				'd.m.Y H:i'		=	25.12.2008 21:53
				'm/d/Y h:ia'	=	12/25/2008 9:53pm
				'd/m/Y H:i'		=	25/12/2008 21:53
				'Y-m-j h:ia'	=	2008-12-25 9:53pm
				'F, jS Y h:ia'	=	December, 25th 2008 9:53pm
				'j F Y h:ia'	=	31 December 2008 9:53pm
				'd.m.Y @ .B'	=	25.12.2008 @ .911
				\*********************************************/
			
			// Default timezone to use in case automatic detection fails or country recognition is disabled
		#	, 'timezone'		=> +0		# DEFAULT: +0 (Gap in SECONDS from GMT: +1h = +3600, -1/2h = -1800)
			
			
			if (!extension_loaded('zlib'))
			{
				$this->_ext = '.nozip.inc.php';
				
				function gzuncompress($text)
				{
					return $text;
				}
			}
			
			if ($startup)
				$this->__startup();
		}
		
		function loadmodule($mod) // Autoload core modules
		{
		#	if ($GLOBALS['s']) $GLOBALS['s']->cp();
			
			eval(gzuncompress(base64_decode(file_get_contents($this->sys_dirs['modules'].$mod.$this->_ext))));
	#		require $this->sys_dirs['modules'].$mod.'.php'; #dev
		#	require "../_SRC_MODULES/$mod.php"; #dev
		#	require ("_SRC_MODULES/$mod.php"); #dev
			
			$this->$mod = &new $mod($this);
			
		#	if ($GLOBALS['s']) $GLOBALS['s']->checkpoint("Loading: $mod", null);
		}
		
		function db_start() // Initialize database driver
		{### RINOMINA startDB()
			
		#	if ($GLOBALS['s']) $GLOBALS['s']->cp();
			
			if (extension_loaded('pdo_'.db_type))
			{
				require $this->sys_dirs['db'].'pdo.php';
				require $this->sys_dirs['db'].db_type.'/driver_pdo.php';
			}
			
			else
			require $this->sys_dirs['db'].db_type.'/driver.php';
			
			$this->db = &new db_driver();
			
		#	if ($GLOBALS['s']) $GLOBALS['s']->checkpoint("Loading Database", null);
		}
		
		function __startup()
		{
			$this->db_start();
			$this->loadmodule('settings');
			
#	$this->sys_dirs['theme'] = '../_THEMES/theme-hera/'; #--dev
			
			$this->loadmodule('user');
			$this->loadmodule('entry');
			$this->loadmodule('gui');
		}
	}
	
	#----- Multi-purpose function library -----#
	
	/* PHP5
	class tools
	{
		const NL	= "\r\n";
		const SMTP	= 'smtp.blu.it';
		
		public static function
	}
	*/
	
	define('NL',"\r\n");
	
	// Email via PHP
	function email($to, $subject, $msg) 
	{
		@ini_set('SMTP','smtp.blu.it'); #PHP5: self::SMTP
		
		$headers
		= 'MIME-Version: 1.0'.NL #PHP5: self::NL
		. 'From: "MJGUEST"'.NL
		. 'To: '.$to.NL
		. 'X-Mailer: PHP'.NL
		. 'X-Priority: 1'.NL.NL
		;
		
		$bad_headers = array('/content-type:/', '/to:/', '/cc:/', '/bcc:/', '/\r/', '/\n/', '/%0a/', '/%0d/');
		
		return @mail($to, $subject, preg_replace($bad_headers, '', $msg), $headers);
	}
	
	// Converts directory files into array items
	function dir2arr($dir, $ext = '\.[a-zA-Z0-9]+', $search = '[^\.{1,2}]')
	{
		$arr = array();
		
		require_once (mjguest_basedir.'resources/PEAR/scandir.php'); #PHP4
		
		$dir = scandir($dir);
		
	#	return array_filter($dir, create_function('$file',"return (bool) preg_match('#^(.*${search}[^\.]*)(?:${ext})\$#', \$file);"));
		
		foreach ($dir as $file)
			if (preg_match("#^(.*${search}[^\.]*)(?:${ext})$#", $file, $filename))
				$arr[] = $filename[1];
		
		return (empty($arr) ? false : $arr);
	}
	
	// Combines the non-empty values of two arrays with the same number of items
	function array_overlay($r1, $r2)
	{
		foreach($r1 as $k => $v) if (!$v) $r1[$k] = $r2[$k];
		
		return $r1;
	}
	
	// Calculates the average out of an array of values; if empty, returns zero
	function array_avg($r)
	{
		return $r ? (float) array_sum($r)/count($r) : 0;
	}
	
	// PHP MultiByte SubString emulation
//	if (!function_exists('mb_substr'))
//	{
		function substr_mb($text, $start, $length)
		{
			preg_match_all('#.#u', $text, $letters);
			return implode('', array_slice($letters[0], $start, $length));
		}
//	}
	
	// Returns UTC 0 current time in seconds
	function utctime()
	{
		return time() - date('Z');
	}
	
	// Remove magic quotes gpc (recursive)
	function remove_magic_quotes_gpc($value)
	{
		if (get_magic_quotes_gpc())
			$value
			= is_array($value)
			? array_map('remove_magic_quotes_gpc', $value)
			: stripslashes($value)
			;
		
		return $value;
	}
	
	if ($_POST) $_POST = remove_magic_quotes_gpc($_POST);
?>
Return current item: MJGUEST