Location: PHPKode > projects > vuBB Community Forums > includes/functions.php
<?php
/**
 * vuBB
 * Copyright 2005-2006 the vuBB Group
 *
 * http://www.vubb.com/
 * http://community.vubb.com/
 */
// Connect  to the database
function database_connect($db_host, $db_user, $db_pass, $db)
{
	global $hard_config;
	if (isset($hard_config['pconnect']) && $hard_config['pconnect']) {
		@mysql_pconnect($db_host, $db_user, $db_pass);
	} else {
		@mysql_connect($db_host, $db_user, $db_pass);
	}
	
	@mysql_select_db($db);
}

// Menu
function menu()
{
	global $lang, $menu, $site, $stat, $site_config, $portal_config;
	
	// Portal.
	$site = '';
	if ($portal_config['on'])
	{
		$site .= '<a href="'.makeurl('portal').'" class="tlinks">'.$site_config['site_name'].' '.$lang['title']['portal'].'</a>';
	}
	
	// Website.
	if ($site_config['website_link'] && $site_config['website_name'])
	{
		$site = ($site) ? $site.' - ' : $site;
		$site .= '<a href="'.$site_config['website_link'].'" class="tlinks">'.$site_config['website_name'].'</a>';
	}
	
	// check to see if we need to show them the logged in menu
	if (isset($_SESSION['user']) && isset($_SESSION['user']))
	{
		$menu = $lang['text']['welcome'] . " " . $stat['user'] . " " . "- <a href='".makeurl('usercp')."' class='tlinks'>" . $lang['text']['usercp'] . "</a> - <a href='".makeurl('logout')."' class='tlinks'>" . $lang['text']['logout'] . "</a>";
	}
	
	// check if they are admin to show admin link
	if (isset($_SESSION['user']) && isset($_SESSION['user']) && $stat['group'] == '4')
	{
		$menu .= " - <a href='admin.php' class='tlinks'>" . $lang['text']['admin'] . "</a>";
	}
		
	// check if there not logged in so we can show them the guest menu
	if (!isset($_SESSION['user']) && !isset($_SESSION['user']))
	{
		$menu = $lang['text']['not_logged'] . " " .  "- <a href='".makeurl('login')."' class='tlinks'>" . $lang['text']['login'] . "</a> - <a href='".makeurl('register')."' class='tlinks'>" . $lang['mix']['register'] . "</a>";
	}
}

// Pagination
// $table - what table to use
// $where - any WHERE statements to add
// $order_by - any ORDER BY statements to add
// $limit - amount per page
// $page - page its on
// $and - any &something to use in $page
function pagination_start($table, $where, $order_by, $limit, $page, $and="")
{
	// make it global so we can use it outside of function
	global $pagination_query, $pagination_link;
	
	$pg = isset($_GET['pg']) ? intval($_GET['pg']) : 1;
	
	$start = ($pg - 1) * $limit;
	  
	$pagination_query = mysql_query("SELECT * FROM `" . $table . "` " . $where . " " . $order_by . " LIMIT " . $start . ", " . $limit);

	if(floor(mysql_num_rows($pagination_query)/$limit>0))
	{
		$pages = ceil(mysql_num_rows(mysql_query("SELECT * FROM `" . $table . "` " . $where . " " . $order_by . ""))/$limit);
		$prev_page = $pg - '1';
		$next_page = $pg + '1';
		
		// if the current page is not equal to 1 then show a pevious page link
        if($pg != '1')
        {
            $pagination_link .= "<a href='" . makeurl('pagination', $page, $prev_page) ."'>&laquo</a> ";
        }
        
        for($index=1; $index<=$pages; $index++)
        {
            // if page is different to the index (page 1) then display a link to main index (page 1)
            if($index != $pg)
            {
                $pagination_link .= "<a href='" . makeurl('pagination', $page, $index) ."'>" . $index . "</a> ";
            }
            
            // else page is index then just show index (page 1)
            else
            {
                $pagination_link .= $index . " ";
            }
        }
        
        // if current page is not equal to number of pages display next page link
        if($pg != $pages)
        {
            $pagination_link .= "<a href='" . makeurl('pagination', $page, $next_page) ."'>&raquo</a>";
        }
        
        // else display nothing
        else
        {
            $pagination_link .= "";
        }
    } 
}

// Grab smilies
function display_clickable_smilies_bbcode()
{
	global $smilies, $bbcode, $lang, $site_config;
	
	$grab_smilies = mysql_query("SELECT * FROM `smilies` ORDER BY `id`");
	$count = 0;
	while ($echo_smilies = mysql_fetch_array($grab_smilies))
	{
		
		if ($count == 4) {
			
			$smilies .= '<br />';
			$count = 0;
		}
		
		$echo_smilies['code'] = htmlspecialchars($echo_smilies['code']);
		$echo_smilies['code'] = stripslashes($echo_smilies['code']);
		$smilies .= '<a href="#goto" onclick="javascript:insertSmiley(\'';
		// rather than adding slashes to all things, just to single quotes.
		$smilies .= str_replace('\'', '\\\'', $echo_smilies['code']);
		$smilies .= '\')">';
		$smilies .= '<img src="';
		$smilies .= $site_config['site_url'];
		$smilies .= $echo_smilies['image'];
		$smilies .= '" border="0" alt="smilie">';
		$smilies .= '</a> ';
		
		$count++;
	}
	
	$bbcode = "
	<a href='#goto' onclick='bbCode(this)' name='b' title='B'>" . $lang['text']['bold'] . "</a>
	<a href='#goto' onclick='bbCode(this)' name='u' title='U'>" . $lang['text']['underline'] . "</a>
	<a href='#goto' onclick='bbCode(this)' name='i' title='I'>" . $lang['text']['italic'] . "</a>
	<a href='#goto' onclick='bbcURL(this)' name='url' title='URL'>" . $lang['text']['url'] . "</a>
	<a href='#goto' onclick='bbCode(this)' name='img' title='IMG'>" . $lang['text']['image'] . "</a>
	<a href='#goto' onclick='bbCode(this)' name='quote' title='QUOTE'>" . $lang['text']['quote'] . "</a>
	<a href='#goto' onclick='bbCode(this)' name='code' title='CODE'>" . $lang['text']['code'] . "</a>
	";
}

// Register
function register($user, $email, $vemail, $pass, $vpass)
{
	global $site_config, $fadyd, $lang, $ip;
	
	if (isset($_GET['action']) && $_GET['action'] == "register") 
	{
	
	    $email_invalid = false;
	    // Check for valid email address.
		if (!eregi('@',$email) || !eregi('.',$email))
        {
		    $email_invalid = true;
		}
	    $em = explode('.',$email);
	    foreach ($em as $val) 
		{
		    if (empty($val)) {
			    $email_invalid = true;
			}
		}
	 	$em = explode('@',$email);
	    foreach ($em as $val) 
		{
		    if (empty($val)) {
			    $email_invalid = true;
			}
		}
	
		// Check for duplicates
		$dupe_user = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `user` = '".$user."'"));
		$dupe_email = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `email` = '".$email."'"));
		
		// count username
		$count_user = strlen($user);
	
		if (empty($user) || empty($email) || empty($vemail) || empty($pass) || empty($vpass) || !isset($_POST['agree'])) 
		{
			redirect(-1);
			message($lang['title']['missing'],$lang['text']['fill_all_fields']);
		} 
		
		else if ($email_invalid)
		{
			redirect(-1);
		    error($lang['title']['error'], $lang['text']['invalid_email']);
		}
		
		else if ($count_user > '32')
		{
			redirect(-1);
			message($lang['title']['error'], $lang['text']['user_too_long']);
		}
		
		else if ($dupe_user > '0') 
		{
			redirect(-1);
			message($lang['title']['error'], $lang['text']['user_taken']);
		}
		
		else if ($dupe_email > '0') 
		{
			redirect(-1);
			message($lang['title']['error'], $lang['text']['email_taken']);
		}
		
		else if ($email != $vemail) 
		{
			redirect(-1);
			message($lang['title']['error'], $lang['text']['email_not_match']);
		}
		
		else if ($pass != $vpass) 
		{
			redirect(-1);
			message($lang['title']['error'], $lang['text']['pass_not_match']);
		}
		
		else
		{
			// Prevents sql injection.
			$user = strip_tags($user);
			$user = addslashes($user);
			$user = htmlspecialchars($user, ENT_QUOTES);
			
			// Random password.
			$rpass = $user.'_'.rand(100000, 999999);
			
			$welcomeMessage = 'Welcome to '.$site_config['site_name'].', '.$user.
			"\n\n".'Your registration details are as follows:'."\n".
			'Username: '.$user."\n".
			'Password: '.$rpass."\n".
			'You can login at '.$site_config['site_url'].'index.php?act=login'."\n\n\n".
			'(You opted-in for this email upon signing up for an account at '.$site_config['site_name'].')';
			
			if (@mail($email, 'Registration Details', $welcomeMessage, "From: No-Reply <no-reply@".$_SERVER['SERVER_NAME'].">\r\n")) {
				$encrypted_pass = md5($rpass);
			} else {
				$encrypted_pass = md5($pass);
			}
			
			$email = addslashes($email);
			$email = strip_tags($email);
		
			mysql_query("INSERT INTO `members` SET `user` = '".$user."', `email` = '".$email."', `pass` = '".$encrypted_pass."', `avatar_link` = '".$site_config['site_url'].'images/noav.jpg'."', `datereg` = '".$fadyd."', `ip` = '".$ip."'") or die("Could not register.");
			
			message($lang['title']['welcome'] . ' ' . $site_config['site_name'], $lang['text']['reg_welcome']);
		}
	}
}

// Login
function login($user = '', $pass = '')
{	
	global $lang;
	
	// Make sure they have enter in a username and password
	if (empty($user) || empty($pass)) 
	{
		message($lang['title']['missing'], $lang['text']['fill_all_fields']);
	}
	
	else
	{
		// Replace nasty things to stop sql injection
		$user = addslashes($user);
		$user = strip_tags($user);
		$user = htmlspecialchars($user, ENT_QUOTES);
		$encrypted_pass = md5($pass);
		
		
		$login_check = mysql_num_rows(mysql_query("SELECT * FROM `members` WHERE `user` = '" . $user . "' AND `pass` = '" . $encrypted_pass . "'"));
		$lock_check  = mysql_fetch_array(mysql_query("SELECT * FROM `members` WHERE `locked` = '1' AND `user` = '" . $user . "'"));
		
		if ($login_check <= '0')
		{
			message($lang['title']['loggin_failed'], $lang['text']['login_failed']);
		} 
		
		else if ($lock_check)
		{
			message($lang['title']['locked'], $lang['text']['account_locked']);
			
			$_SESSION['user'] = $user;
			$_SESSION['pass'] = $encrypted_pass;
		}
		
		else 
		{		
			$_SESSION['user'] = $user;
			$_SESSION['pass'] = $encrypted_pass;
			
			redirect(makeurl('index'));
			message($lang['title']['logged'], $lang['text']['logged_in']);
		}
	}
}

// logout
function logout()
{
	global $site_config;
	
	setcookie('vubb_user', $_SESSION['user'], 1000, '/', str_replace('www', '', $_SERVER['HTTP_HOST']));
	setcookie('vubb_pass', $_SESSION['pass'], 1000, '/', str_replace('www', '', $_SERVER['HTTP_HOST']));
	
	unset($_SESSION["user"]);
	unset($_SESSION["pass"]);
	session_unset();
	session_destroy();
}

// Set cookie
function set_cookie()
{
	global $site_config;
	if (isset($_SESSION['user']) && isset($_SESSION['pass']))
	{
		setcookie('vubb_user', $_SESSION['user'], time()+3600*24*365, '/', str_replace('www', '', $_SERVER['HTTP_HOST']));
		setcookie('vubb_pass', $_SESSION['pass'], time()+3600*24*365, '/', str_replace('www', '', $_SERVER['HTTP_HOST']));
	}
}

// Check cookie
function check_cookie()
{
	if (isset($_COOKIE['vubb_user']) && isset($_COOKIE['vubb_pass']))
	{
		$_SESSION['user'] = $_COOKIE['vubb_user'];
		$_SESSION['pass'] = $_COOKIE['vubb_pass'];	
	}
}

// Make sure there not locked (banned)
function lock_checker()
{
	global $lang, $stat, $act;
	
	if (isset($_SESSION['user']) && isset($_SESSION['pass']))
	{
		$lock_check = mysql_fetch_array(mysql_query("SELECT * FROM `members` WHERE `locked` = '1' AND `user` = '".$stat['user']."'"));
		if ($lock_check)
		{
			
			if ($act != 'login')
			{
				menu();
				global $site_config, $urls, $menu, $site;
				echo eval(get_template('header'));
			}
			
			error($lang['title']['locked'], $lang['text']['account_locked']);
		}
	}
}

// users online
function update_users_online()
{
	global $stat;
	
	// Current time
	$ctime = time();
	
	if (isset($_SESSION['user']) && isset($_SESSION['pass']))
	{
		mysql_query("UPDATE `members` SET `lpv` = '" . $ctime . "' WHERE `id` = '" . $stat['id'] . "'");
		
		$check1 = mysql_query("SELECT `id`,`lpv` FROM `members` ORDER BY `id`");
		
		while ($info = mysql_fetch_array($check1))
		{
			// do the check
			$check2 = ($ctime - $info['lpv']);
			
			if ($check2 <= '300')
			{
				mysql_query("UPDATE `members` SET `online` = '1' WHERE `id` = '" . $info['id'] . "'");
			}
			
			else if ($check2 > '300')
			{
				mysql_query("UPDATE `members` SET `online` = '0' WHERE `id` = '" . $info['id'] . "'");
			}
		}
	}
}

// guests online
function update_guests_online()
{
	global $ip;
	
	// how long you want before a guest is inactive.
	// 300 secs = 5mins
	$info['life'] = '300';
	
	// Do not edit below, unless you know how too
	$info['time'] = time();
	$info['time_work'] = $info['time'] - $info['life'];
	
	mysql_query("DELETE FROM `guests_online` WHERE `time` < '" . $info['time_work'] . "'");
	
	$check = mysql_fetch_array(mysql_query("SELECT COUNT(*) AS `count` FROM `guests_online` WHERE `ip` = '" . $ip . "'"));
	
	if ($check['count'] >= '1' && isset($_SESSION['user']) && isset($_SESSION['pass']))
	{
		 mysql_query("DELETE FROM `guests_online` WHERE `ip` = '" . $ip . "'");
	}
	
	else if ($check['count'] >= '1' && !isset($_SESSION['user']) && !isset($_SESSION['pass']))
	{
		 mysql_query("UPDATE `guests_online` SET `time` = '" . $info['time'] . "' WHERE `ip` = '" . $ip . "'");
	}
	
	else if ($check['count'] != '1' && !isset($_SESSION['user']) && !isset($_SESSION['pass']))
	{
		 mysql_query("INSERT INTO `guests_online` SET `ip` = '" . $ip . "', `time` = '" . $info['time'] . "'");
	}
}

// Errors
function error($title, $message)
{
	global $copyright, $lang, $site_config, $vubbcollapse, $version, $breadcrumb, $vubb, $act;
	
	echo eval(get_template('breadcrumb'));
	echo eval(get_template('message'));

	include('includes/footer.php');
	exit;
}

function admin_error($title, $message, $show_breadcrumb = true)
{
	global $copyright, $start_time, $lang, $site_config, $breadcrumb, $act;
	
	if ($show_breadcrumb)
	{
		echo eval(get_template('breadcrumb'));
	}
	echo eval(get_template('message'));
	exit;
}

// Messages
function message($title, $message, $show_breadcrumb = true)
{	
	global $site_config, $breadcrumb;

	if ($show_breadcrumb)
	{
		echo eval(get_template('breadcrumb'));
	}
	echo eval(get_template('message'));
}

// Html Decode
function htmldecode($encoded)
{
	return strtr($encoded, array_flip(get_html_translation_table(HTML_ENTITIES)));
}

// Urls.
function makeurl($module)
{
	global $hard_config, $site_config, $portal_config;
	
	// Arguments.
	$argc = func_num_args();
	$args = func_get_args();

	switch ($module) {
	
		case 'index':
			if ($portal_config['as_default'] && file_exists('./modules/portal.php'))
			{
				return $hard_config['file'].'?act=forum';
			}
			else
			{
				return $hard_config['file'];
			}
		break;
	
		case 'member':
			return $hard_config['file'].'?act='.$module.'&amp;m='.$args[1];
		break;
		
		case 'mod_actions':
			return $hard_config['file'].'?act='.$module.'&amp;t='.$args[1].'&amp;f='.$args[2].
			(isset($args[3]) && $args[3] ? '&amp;action='.$args[3] : '').
			(isset($args[4]) && $args[4] ? '&amp;r='.$args[4] : '');
		break;
		
		case 'editpost':
			return $hard_config['file'].'?act='.$module.'&amp;t='.$args[1].'&amp;f='.$args[2].'&amp;reply='.$args[3].
			(isset($args[4]) && $args[4] ? '&amp;action='.$args[4] : '');
		break;
		
		case 'viewtopic':
			return $hard_config['file'].'?act='.$module.'&amp;t='.$args[1].'&amp;f='.$args[2];
		break;
		
		case 'viewforum':
			return $hard_config['file'].'?act='.$module.'&amp;f='.$args[1];
		break;
		
		case 'newreply':
			return $hard_config['file'].'?act='.$module.'&amp;t='.$args[1].'&amp;f='.$args[2].
			(isset($args[3]) && $args[3] ? '&amp;action='.$args[3] : '');
		break;
		
		case 'newtopic':
			return $hard_config['file'].'?act='.$module.'&amp;f='.$args[1].
			(isset($args[2]) && $args[2] ? '&amp;action='.$args[2] : '');
		break;
		
		case 'newpoll':
			return $hard_config['file'].'?act='.$module.'&amp;f='.$args[1].
			(isset($args[2]) && $args[2] ? '&amp;action='.$args[2] : '');
		break;
		
		case 'pagination':
			return $args[1].'&amp;pg='.$args[2];
		break;
		
		case 'register':
			return $hard_config['file'].'?act='.$module.
			(isset($args[1]) && $args[1] ? '&amp;action='.$args[1] : '');
		break;
		
		case 'login':
			return $hard_config['file'].'?act='.$module.
			(isset($args[1]) && $args[1] ? '&amp;action='.$args[1] : '');
		break;
		
		case 'members':
			return $hard_config['file'].'?act='.$module;
		break;
		
		case 'logout':
			return $hard_config['file'].'?logout=yes';
		break;
			
		case 'usercp':
			return $hard_config['file'].'?act='.$module.
			(isset($args[1]) && $args[1] ? '&amp;view='.$args[1] : '').
			(isset($args[2]) && $args[2] ? '&amp;action='.$args[2] : '');
		break;
		
		// Portal.
		case 'portal':
			if ($portal_config['as_default'] && file_exists('./modules/portal.php'))
			{
				return $hard_config['file'];
			}
			else if (file_exists('./modules/portal.php'))
			{
				return $hard_config['file'].'?act='.$module;
			}
			else
			{
				return $hard_config['file'];
			}
		break;
	}
}

// Breadcrumb.
function addnav($text, $url)
{
	global $breadcrumb;
	
	if (!eregi('"'.$url.'"', $breadcrumb)) {
		$breadcrumb .= ' &raquo <a href="'.stripslashes($url).'">'.stripslashes($text).'</a>';
	}
	
}

// Redirect.
function redirect($url, $timeout = 4, $echo = true)
{
	$timeout = $timeout * 1000;
	$url = str_replace('&amp;', '&', $url);
	if ($url < 0) {
		
		if ($echo) {
			echo '<script type="text/javascript">window.setTimeout("history.go('.$url.')", '.$timeout.');</script>';
		} else {
			return '<script type="text/javascript">window.setTimeout("history.go('.$url.')", '.$timeout.');</script>';
		}
		
	} else {
		
		if ($echo) {
			echo '<script type="text/javascript">window.setTimeout("document.location = \''.$url.'\';", '.$timeout.');</script>';
		} else {
			return '<script type="text/javascript">window.setTimeout("document.location = \''.$url.'\';", '.$timeout.');</script>';
		}
		
	}
}

function smile($txt)
{
	global $site_config;
	
    // Gimme smilies!
    $grab_smilies = mysql_query("SELECT * FROM `smilies` ORDER BY `id`");
    while ($echo_smilies = mysql_fetch_array($grab_smilies))
    {
        $txt = str_replace($echo_smilies['code'], '<img src="'.$site_config['site_url'].$echo_smilies['image'].'" />', $txt);
    }
	
	return $txt;
}

function postify($message, $allowbbcode = true, $allowsmilies = true, $allowimgcode = true)
{
    // Get global Variables.
	global $site_config;
	
	// Believe It or Not!™ This is actually used!
	$bballow      = $allowbbcode  ? true : false;
    $smiliesallow = $allowsmilies ? true : false;
	
	// Just incase..
    if ($bballow) {
        $message = stripslashes($message);

		// Array (used for checking for both sets of BBCode tags)
        $begin = array (
                0     => '[b]',
                1     => '[i]',
                2     => '[u]',
                3     => '[poem]',
                4     => '[marquee]',
                5     => '[blink]',
                6     => '[strike]',
                7     => '[quote]',
                8     => '[code]',
                9     => '[list]',
                10    => '[list=1]',
                11    => '[list=a]',
                12    => '[list=A]',
        );

        $end = array (
                0     => '[/b]',
                1     => '[/i]',
                2     => '[/u]',
                3     => '[/poem]',
                4     => '[/marquee]',
                5     => '[/blink]',
                6     => '[/strike]',
                7     => '[/quote]',
                8     => '[/code]',
                9     => '[/list]',
                10    => '[/list=1]',
                11    => '[/list=a]',
                12    => '[/list=A]',
        );

		// Check for BOTH matching BBCode tags.
        foreach ($begin as $key=>$value) {
            $check = substr_count($message, $value) - substr_count($message, $end[$key]);
            if ($check > 0) {
                $message = $message.str_repeat($end[$key], $check);
            } else if ($check < 0) {
                $message = str_repeat($value, abs($check)).$message;
            }
        }
		
		// The BBCode Array.
		$find = array(
			0   => '[b]',
			1   => '[/b]',
			2   => '[i]',
			3   => '[/i]',
			4   => '[poem]',
			5   => '[/poem]',
			6   => '[u]',
			7   => '[/u]',
			8   => '[marquee]',
			9   => '[/marquee]',
			10  => '[blink]',
			11  => '[/blink]',
			12  => '[strike]',
			13  => '[/strike]',
			14  => '[quote]',
			15  => '[/quote]',
			16  => '[code]',
			17  => '[/code]',
			18  => '[list]',
			19  => '[/list]',
			20  => '[list=1]',
			21  => '[list=a]',
			22  => '[list=A]',
			23  => '[/list=1]',
			24  => '[/list=a]',
			25  => '[/list=A]',
			26  => '[credits]',
			27  => '[*]',
			28  => '[center]',
			29  => '[/center]',
			
			998  => '<br/>',
			999  => '<br>',
		);

		$replace = array(
			0   => '<strong>',
			1   => '</strong>',
			2   => '<em>',
			3   => '</em>',
			4   => '<div align=\"center\"><em>',
			5   => '</div></em>',
			6   => '<u>',
			7   => '</u>',
			8   => '<marquee>',
			9   => '</marquee>',
			10  => '<blink>',
			11  => '</blink>',
			12  => '<strike>',
			13  => '</strike>',
			14  => '<div class="quote">',
			15  => '</div>',
			16  => '<div class="code">',
			17  => '</div>',
			18  => '<ul type="square">',
			19  => '</ul>',
			20  => '<ol type="1">',
			21  => '<ol type="A">',
			22  => '<ol type="A">',
			23  => '</ol>',
			24  => '</ol>',
			25  => '</ol>',
			26  => '<a href="http://vubb.com" target="_blank">vuBB</a> Main Developers - Detruire, Wimpie, 2$CoMpLiCaTeD$4u.',
			27  => '<li />',
			28  => '<div align="center">',
			29  => '</div>',
			
			998 => '<br />',
			999 => '<br />',
		);

        $message = str_replace($find, $replace, $message);
   
        $patterns       = array();
        $replacements   = array();
		
		//$patterns[]     = "#vubb#Ssi";
		//$replacements[] = '<a href="http://vubb.com/" target="_blank" style="cursor:help;">vuBB</a>';
		
        $patterns[]     = "#\[color=([a-z0-9\#]+)\](.*?)\[/color\]#Ssi";
        $replacements[] = '<font color="\1">\2</font>';

		$patterns[]     = "#\[size=([a-z0-9\%]+)px\](.*?)\[/size\]#Ssi";
        $replacements[] = '<font style="font-size: \1px">\2</font>';
        $patterns[]     = "#\[size=([a-z0-9\%]+)\](.*?)\[/size\]#Ssi";
        $replacements[] = '<font size="\1">\2</font>';

        $patterns[]     = "#\[font=([a-z\r\n\t 0-9]+)\](.*?)\[/font\]#Ssi";
        $replacements[] = '<font face="\1">\2</font>';

        $patterns[]     = "#\[align=([a-z]+)\](.*?)\[/align\]#Ssi";
        $replacements[] = '<p align="\1">\2</p>';

		// URL Filter.
		$url_filter     = '(http[s]?://|ftp[s]?://|irc://|gopher://|ed2k://)([a-zA-Z0-9\.-])([a-zA-Z0-9_\.;\#%=,? -/@]+)';
		$email_filter   = '([a-z0-9_\.-]+)@([a-z0-9-]+).([a-z0-9\.-]+)';
		
        if ($allowimgcode) {
            if (!stristr($message, 'javascript:') && (stristr($message, 'jpg[/img]') || stristr($message, 'jpeg[/img]') || stristr($message, 'gif[/img]') || stristr($message, 'png[/img]') || stristr($message, 'bmp[/img]') || stristr($message, 'php[/img]'))) {
            	$patterns[]     = '#\[img\]'.$url_filter.'\[/img\]#Smi';
            	$replacements[] = '<img src="\1\2\3" alt="\1\2\3" style="border:0px;" />';

            	$patterns[]     = '#\[img='.$url_filter.'\]'.$url_filter.'\[/img\]#Smi';
            	$replacements[] = '<img src="\1\2\3" alt="\4" style="border:0px;" />';        
			}
        } else {
			// Strip image code.
        	$patterns[]     = '#\[img\](.*?)\[/img\]#Smi';
        	$replacements[] = '';
        	$patterns[]     = '#\[img=(.*?)\]\[/img\]#Smi';
        	$replacements[] = '';
		}
		
        $patterns[]     = '#\[url\]'.$url_filter.'\[/url\]#Smi';
        $replacements[] = '<a href="\1\2\3" target="_blank">\1\2\3</a>';

        $patterns[]     = '#\[url='.$url_filter.'](.*?)\[/url\]#Smi';
        $replacements[] = '<a href="\1\2\3" target="_blank">\4</a>';

        $patterns[]     = '#\[email\]'.$email_filter.'\[/email\]#Smie';
        $replacements[] = '"<a href=\"mailto:".ascii_encode(\'\1@\2.\3\')."\">".ascii_encode(\'\1@\2.\3\')."</a>"';
		
        $patterns[]     = '#\[email='.$email_filter.'\](.*?)\[/email\]#Smie';
        $replacements[] = '"<a href=\"mailto:".ascii_encode(\'\1@\2.\3\')."\">\4</a>"';

        $message = preg_replace($patterns, $replacements, $message);
		
		if ($smiliesallow) {
            $message = smile($message);
        }
		
    } else {
		
		$message = stripslashes($message);
        if ($smiliesallow) {
            $message = smile($message);
        }
			
    }

	// The MUST-DO of the BBCode world. Turn \n into <br />!
    return nl2br($message);
}
?>
Return current item: vuBB Community Forums