BBCodesDefault) OR !isset($this->BBCodesExtra))
{
trigger_error("Es fehlen wichtige Variablen! Bitte kontrollieren Sie die Klasse.");
}
$this->addDefaultBBCodes();
}
private function addDefaultBBCodes()
{
$this->BBCodesDefault = array("b" => array("/\[b\](.*)\[\/b\]/isU" => "$1"),
"i" => array("/\[i\](.*)\[\/i\]/isU" => "$1"),
"u" => array("/\[u\](.*)\[\/u\]/isU" => "$1"),
"hr" => array("/\[hr\]/isU" => "
"),
"br" => array("/\[br\]/isU" => "
"),
"url" => array("/\[url\=(.*)\](.*)\[\/url\]/isU" => "$2"),
"youtube" => array("/\[youtube\](.*)\[\/youtube\]/isU" => ""),
"img" => array("/\[img\](.*)\[\/img\]/isU" => "
"));
}
public function addExtraBBCode($name, $bbCodePattern, $htmlCodePattern)
{
if(!isset($this->BBCodesExtra[$name]))
{
$this->BBCodesExtra[$name] = array($bbCodePattern => $htmlCodePattern);
}
else
{
trigger_error("BBCodename existiert bereits");
}
}
private function parseExtraCode()
{
if(!is_array($this->BBCodesExtra)) return $this->rawText;
foreach($this->BBCodesExtra as $BBCode => $array)
{
foreach($array as $BBCodePattern => $htmlPattern)
{
$this->rawText = preg_replace($BBCodePattern, $htmlPattern, $this->rawText);
}
}
return $this->rawText;
}
private function iniParse($rawText)
{
$this->rawText = $rawText;
foreach($this->BBCodesDefault as $BBCode => $array)
{
if(stripos($this->rawText, "[".$BBCode."]") !== FALSE && stripos($this->rawText, "[/".$BBCode."]") !== FALSE)
{
return true;
}
continue;
}
if(is_array($this->BBCodesExtra))
{
foreach($this->BBCodesExtra as $BBCode => $array)
{
if(stripos($this->rawText, "[".$BBCode."]") !== FALSE && stripos($this->rawText, "[/".$BBCode."]") !== FALSE)
{
return true;
}
continue;
}
}
return false;
}
private function parseCode()
{
if($this->rawText == "")
{
trigger_error("Diese Funktion muss erst durch iniParse() initialisert werden!");
}
foreach($this->BBCodesDefault as $BBCode => $array)
{
foreach($array as $search => $html)
{
$this->rawText = preg_replace($search, $html, $this->rawText);
}
}
return $this->rawText;
}
public function parse($rawText)
{
//$this->rawText = htmlentities($rawText);
if(!$this->iniParse($rawText)) return $this->rawText;
$this->parseCode();
$this->parseExtraCode();
return $this->rawText;
}
}*/
class textparser {
function __construct($parse_smilies=true) {
global $config, $db;
if($config['smilies_table']!=NULL && $config['smilies_table'] != ""){
$this->parse_smilies=$parse_smilies;
if($this->parse_smilies){
$result=$db->query('SELECT * FROM `' . $config['smilies_table']. '`');
while($row=$db->fetch_array($result)){
$find=preg_quote($row['find']);
$this->smilies[$find]='
';
}
}
}
}
function parseParameters ($stringParameter) {
$arrayParameter = array ();
if (is_string ($stringParameter) === TRUE && empty ($stringParameter) === FALSE){
if (preg_match_all ('°(^|\w+)\=(\"?)([^\"]*?)\2(?: |$)°', $stringParameter, $arrayMatches, PREG_SET_ORDER) > 0){
foreach ($arrayMatches AS $integerMatchCount => $arrayMatch){
if (empty ($arrayMatch[1]) === TRUE){
$stringKey = '__INIT__';
}else{
$stringKey = strtolower ($arrayMatch[1]);
}
$arrayParameter[$stringKey] = $arrayMatch[3];
$arrayParameter[$integerMatchCount] = &$arrayParameter[$stringKey];
}
unset ($arrayMatch);
}
}
return $arrayParameter;
}
function parse($mixedInfo) {
$stringCode = '';
$arrayParameter = array ();
$booleanMixedInfoIsArray = FALSE;
if (is_array ($mixedInfo) === TRUE && count ($mixedInfo) == 4){
$stringText = $mixedInfo[3];
$stringCode = strtolower ($mixedInfo[1]);
$arrayParameter = $this->parseParameters ($mixedInfo[2]);
$booleanMixedInfoIsArray = TRUE;
}elseif (is_string ($mixedInfo) === TRUE){
$stringText = $mixedInfo;
$stringText = preg_replace ('°\[(br|hr)]°is','[\1][/\1]',$stringText);
}else{
return '';
}
if ($stringCode != 'noparse'){
$stringText = preg_replace_callback ('°\[(\w+)((?:\s|=)[^]]*)?]((?:[^[]|\[(?!/?\1((?:\s|=)[^]]*)?])|(?R))*)\[/\1]°',array($this,'parse'),$stringText);
}
if ($booleanMixedInfoIsArray === TRUE){
switch ($stringCode){
case 'b':
case 'i':
case 'u':
{
$stringText = '<'.$mixedInfo[1].'>'.$stringText.''.$mixedInfo[1].'>';
break;
}
case 'br':
case 'hr':
{
$stringText = '<'.$mixedInfo[1].' />';
break;
}
case 'url':
{
if (count ($arrayParameter) == 0 || array_key_exists ('__INIT__',$arrayParameter) === FALSE){
$stringText = ''.$stringText.'';
}else{
$stringTitle = '';
if (array_key_exists ('title',$arrayParameter) === TRUE){
$stringTitle = ' title="'.$arrayParameter['title'].'"';
}
$stringText = ''.$stringText.'';
unset ($stringTitle);
}
break;
}
case 'color':
{
$stringText = ''.$stringText.'';
break;
}
default:
{
$stringText = $mixedInfo[0];
break;
}
}
}
if($this->parse_smilies){
foreach($this->smilies as $find=>$replace){
$stringText = @preg_replace('#'.$find.'#s', $replace, $stringText);
}
}
return $stringText;
}
}
?>