Source

Selador / BBCode.php

<?php

/* BBCode.php - utility code for BBCode to HTML conversion
 *
 * Copyright (C) 2006, 2007, 2008 Kevin Read, Simone Schaefer
 *
 * This file is part of Selador, a browser-based fantasy strategy game
 *
 * This program is distributed under the terms of the GNU Affero General Public License.
 *
 *
 *   Selador is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU Affero General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   any later version.
 *
 *   Selador 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 Affero General Public License for more details.
 *
 *   You should have received a copy of the GNU Affero General Public License
 *   along with Selador.  If not, see <http://www.gnu.org/licenses/>.
 **/

// unfinished!

/**************************************
 *
 * this class is used to represent 
 * ally and user descriptions in a
 * nice way
 *
**************************************/
class BBCode
{
	public $content;
	public $valid = array("ally"=>"ally","user"=>"user","b"=>"b","i"=>"i"); //the key is only for internal code. so we can easyily change the bbcode syntax later, if we want
	
	
	
	function checkBBCode($text)
	{
		return mysql_real_escape_string($text);
		
	}	
	
	function displayBBCode($text)
	{
		$text_array = explode(" ",$text);
		foreach ($text_array as $var)
		{
			//if (in_array())
		}
	}
	
	function replaceAllyTag()
	{
		$query = "select tag from allies where";
	}
	
	function BBCode($text, $mode)
	{
		$text = stripslashes($text);
		//when mode is "read", we have to display a given text
		if ($mode=="read")
		{
			$this->content = displayBBCode($text);
		}
		//someone wants to save a text in bbcode. 
		if ($mode=="write")
		{
			$this->content = checkBBCode($text);
		}
		
	}
	
}

?>