<?php
class parse {
var $urldetect=1;
var $urlcut=1;
var $urlmaxwidth=60;
var $urlwidth1=45;
var $urlwidth2=-15;
var $censoruse=1;
var $censorreplace='*';
var $bbhash='';
var $smiliehash='';
var $urltag=array('tag'=>'url','html'=>'<a target="_blank" href="{option}">{text}</a>');
var $imagetags=array(
array('tag'=>'img','html'=>'<img border="0" alt="" src="{image}" />'),
array('tag'=>'imgr','html'=>'<img border="0" alt="" src="{image}" align="right" />'),
array('tag'=>'imgl','html'=>'<img border="0" alt="" src="{image}" align="left" />'));
function bbdefine () {
global $lang;
$this->bbhash=array(
array('tag'=>'hr','html'=>'<hr />'),
array('tag'=>'\*','html'=>'<li>'),
array('tag'=>'list','html'=>'<ul>{text}</ul>'),
array('tag'=>'list=1','html'=>'<ol type="1">{text}</ol>'),
array('tag'=>'list=a','html'=>'<ol type="a">{text}</ol>'),
array('tag'=>'b','html'=>'<b>{text}</b>'),
array('tag'=>'i','html'=>'<i>{text}</i>'),
array('tag'=>'u','html'=>'<u>{text}</u>'),
array('tag'=>'d','html'=>'<strike>{text}</strike>'),
array('tag'=>'h2','html'=>'<h2>{text}</h2>'),
array('tag'=>'h3','html'=>'<h3>{text}</h3>'),
array('tag'=>'h4','html'=>'<h4>{text}</h4>'),
array('tag'=>'p','html'=>'<p>{text}</p>'),
array('tag'=>'sub','html'=>'<sub>{text}</sub>'),
array('tag'=>'sup','html'=>'<sup>{text}</sup>'),
//
//Denksmiley Hack by CheFFe (c)
http://www.flori-times.de
//
array('tag'=>'denk','html'=>'<table style="font-family: arial; color: #000000;"><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=25 height=14><img src=images/blase1.gif align=center border=0></td><td width=100 background=images/blase5.gif></td><td width=25><img src=images/blase2.gif align=center border=0></td></tr><tr><td colspan=3 width=150><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1 bgcolor=#000000><td><table cellpadding=4 cellspacing=0 width=100% bgcolor=#000000><tr><td align=center bgcolor=#FFFFFF style="font-family: arial; color: #000000;"><b>{text}</b></td></tr></table></td><td width=1 bgcolor=#000000></td></tr></table></td></tr><tr><td width=25 height=14><img src=images/blase3.gif align=center border=0></td><td background=images/blase6.gif></td><td width=25><img src=images/blase4.gif align=center border=0></td></tr><tr><td colspan=3><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td colspan=2 width=116></td><td height=17 width=34 align=center><img src=images/denk.gif align=center border=0></td></tr></table></td></tr></table></td></tr></table>'),
array('tag'=>'denkcool','html'=>'<table style="font-family: arial; color: #000000;"><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=25 height=14><img src=images/blase1.gif align=center border=0></td><td width=100 background=images/blase5.gif></td><td width=25><img src=images/blase2.gif align=center border=0></td></tr><tr><td colspan=3 width=150><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1 bgcolor=#000000><td><table cellpadding=4 cellspacing=0 width=100% bgcolor=#000000><tr><td align=center bgcolor=#FFFFFF style="font-family: arial; color: #000000;"><b>{text}</b></td></tr></table></td><td width=1 bgcolor=#000000></td></tr></table></td></tr><tr><td width=25 height=14><img src=images/blase3.gif align=center border=0></td><td background=images/blase6.gif></td><td width=25><img src=images/blase4.gif align=center border=0></td></tr><tr><td colspan=3><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td colspan=2 width=116></td><td height=17 width=34 align=center><img src=images/cool.gif align=center border=0></td></tr></table></td></tr></table></td></tr></table>'),
array('tag'=>'denksceptic','html'=>'<table style="font-family: arial; color: #000000;"><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=25 height=14><img src=images/blase1.gif align=center border=0></td><td width=100 background=images/blase5.gif></td><td width=25><img src=images/blase2.gif align=center border=0></td></tr><tr><td colspan=3 width=150><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1 bgcolor=#000000><td><table cellpadding=4 cellspacing=0 width=100% bgcolor=#000000><tr><td align=center bgcolor=#FFFFFF style="font-family: arial; color: #000000;"><b>{text}</b></td></tr></table></td><td width=1 bgcolor=#000000></td></tr></table></td></tr><tr><td width=25 height=14><img src=images/blase3.gif align=center border=0></td><td background=images/blase6.gif></td><td width=25><img src=images/blase4.gif align=center border=0></td></tr><tr><td colspan=3><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td colspan=2 width=116></td><td height=17 width=34 align=center><img src=images/skeptisch.gif align=center border=0></td></tr></table></td></tr></table></td></tr></table>'),
array('tag'=>'denktrue','html'=>'<table style="font-family: arial; color: #000000;"><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=25 height=14><img src=images/blase1.gif align=center border=0></td><td width=100 background=images/blase5.gif></td><td width=25><img src=images/blase2.gif align=center border=0></td></tr><tr><td colspan=3 width=150><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1 bgcolor=#000000><td><table cellpadding=4 cellspacing=0 width=100% bgcolor=#000000><tr><td align=center bgcolor=#FFFFFF style="font-family: arial; color: #000000;"><b>{text}</b></td></tr></table></td><td width=1 bgcolor=#000000></td></tr></table></td></tr><tr><td width=25 height=14><img src=images/blase3.gif align=center border=0></td><td background=images/blase6.gif></td><td width=25><img src=images/blase4.gif align=center border=0></td></tr><tr><td colspan=3><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td colspan=2 width=116></td><td height=17 width=34 align=center><img src=images/true.gif align=center border=0></td></tr></table></td></tr></table></td></tr></table>'),
array('tag'=>'denkwonder','html'=>'<table style="font-family: arial; color: #000000;"><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=25 height=14><img src=images/blase1.gif align=center border=0></td><td width=100 background=images/blase5.gif></td><td width=25><img src=images/blase2.gif align=center border=0></td></tr><tr><td colspan=3 width=150><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1 bgcolor=#000000><td><table cellpadding=4 cellspacing=0 width=100% bgcolor=#000000><tr><td align=center bgcolor=#FFFFFF style="font-family: arial; color: #000000;"><b>{text}</b></td></tr></table></td><td width=1 bgcolor=#000000></td></tr></table></td></tr><tr><td width=25 height=14><img src=images/blase3.gif align=center border=0></td><td background=images/blase6.gif></td><td width=25><img src=images/blase4.gif align=center border=0></td></tr><tr><td colspan=3><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td colspan=2 width=116></td><td height=17 width=34 align=center><img src=images/huu.gif align=center border=0></td></tr></table></td></tr></table></td></tr></table>'),
array('tag'=>'denkfuck','html'=>'<table style="font-family: arial; color: #000000;"><tr><td><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=25 height=14><img src=images/blase1.gif align=center border=0></td><td width=100 background=images/blase5.gif></td><td width=25><img src=images/blase2.gif align=center border=0></td></tr><tr><td colspan=3 width=150><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td width=1 bgcolor=#000000><td><table cellpadding=4 cellspacing=0 width=100% bgcolor=#000000><tr><td align=center bgcolor=#FFFFFF style="font-family: arial; color: #000000;"><b>{text}</b></td></tr></table></td><td width=1 bgcolor=#000000></td></tr></table></td></tr><tr><td width=25 height=14><img src=images/blase3.gif align=center border=0></td><td background=images/blase6.gif></td><td width=25><img src=images/blase4.gif align=center border=0></td></tr><tr><td colspan=3><table border=0 cellpadding=0 cellspacing=0 width=100%><tr><td colspan=2 width=116></td><td height=17 width=34 align=center><img src=images/fuckyou.gif align=center border=0></td></tr></table></td></tr></table></td></tr></table>'),
//
//Ende Denksmiley Hack by CheFFe (c)
http://www.flori-times.de
//
array('tag'=>'left','html'=>'<div align="left">{text}</div>'),
array('tag'=>'center','html'=>'<div align="center">{text}</div>'),
array('tag'=>'right','html'=>'<div align="right">{text}</div>'),
array('tag'=>'block','html'=>'<div align="justify">{text}</div>'),
array('tag'=>'code','html'=>'<code>{text}</code>'),
array('tag'=>'quote','html'=>'<table class="quote" width="98%" cellpadding="4" cellspacing="1" align="center"><tr><td class="quote"><b>'.$lang['quote'].'</b><br /><font class="quote">{text}</font></td></tr></table><br />'),
array('tag'=>'white','html'=>'
{text}'),
array('tag'=>'gray','html'=>'
{text}'),
array('tag'=>'dimgray','html'=>'
{text}'),
array('tag'=>'navy','html'=>'
{text}'),
array('tag'=>'royalblue','html'=>'
{text}'),
array('tag'=>'red','html'=>'
{text}'),
array('tag'=>'orange','html'=>'
{text}'),
array('tag'=>'yellow','html'=>'
{text}'),
array('tag'=>'yello2','html'=>'
{text}'),
array('tag'=>'green','html'=>'
{text}'),
array('tag'=>'white','html'=>'
{text}'),
array('tag'=>'color','html'=>'<font style="color: {option}">{text}</font>'),
array('tag'=>'flash','html'=>'<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" width="240" height="192"> <param name="movie" value="{text}"> <param name="quality" value="high"> <param name="scale" value="exactfit"> <param name="menu" value="true"> <param name="bgcolor" value="#FFFFFF"> <embed src="{text}" quality="high" scale"exatfit" menue="false" bgstyle="color: FFFFFF" width="550" HEIGHT="400" type="application/x-shockwave-flash" pluginspace=http://www.macromedia.com/go/getflashplayer"></embed></object>'),
array('tag'=>'email','html'=>'<a href="mailto:{text}">{text}</a>'),
array('tag'=>'email','html'=>'<a href="mailto:{option}">{text}</a>'));
}
function definesmilies() {
global $DB, $db_tab;
$getsmilies=$DB->query("SELECT * FROM ".$db_tab['smilies']);
while ($smilies=$DB->fetch_array($getsmilies)) {$this->smiliehash[$smilies['smilie_id']]=$smilies;}
}
function parse($text='', $html='', $bb='', $smilies='',$images='',$censor='') {
$text=trim($text);
if ($text!='') {
$text=preg_replace('/[&|?]'.session_name().'=([a-z0-9A-Z]{0,32})[^&|\w|\n|\#|\]|\[]*/','',$text);
if ($censor==1) $text=$this->textcensor($text);
if ($this->urldetect==1) $text=$this->urldetect($text);
if ($html!=1) $text=htmlentities($text);
else $text=$this->preparehtml($text);
if ($images!=1) $text=$this->removeimages($text);
if ($bb==1) $text=$this->bbcode($text);
if ($smilies==1) $text=$this->smilies($text);
$text=$this->parseimages($text);
$text=$this->urlparse($text);
$text=$this->returntext($text);
if ($html==1) $text=str_replace('"','"',$text);
return $text;
}
else return FALSE;
}
function urldetect($text) {
$text=eregi_replace("([ \r\n])http://([^ ,\r\n]*)","\\1
http://\\2",$text);
$text=eregi_replace("([ \r\n])https://([^ ,\r\n]*)","\\1
https://\\2",$text);
$text=eregi_replace("([ \r\n])ftp://([^ ,\r\n]*)","\\1
ftp://\\2",$text);
$text=eregi_replace("([ \r\n])www\\.([^ ,\r\n]*)","\\1
http://www.\\2",$text);
$text=eregi_replace("^http://([^ ,\r\n]*)","
http://\\1",$text);
$text=eregi_replace("^https://([^ ,\r\n]*)","
https://\\1",$text);
$text=eregi_replace("^ftp://([^ ,\r\n]*)","
ftp://\\1",$text);
$text=eregi_replace("^www\\.([^ ,\r\n]*)","
http://www.\\1",$text);
return $text;
}
function urlparse($text='') {
$code=$this->urltag;
$text=preg_replace("#\[".$code['tag']."=(.*)\]([^\]|\[]*)\[/".$code['tag']."\]#eiU","\$this->urlrewrite('$code[html]','\\1','\\2')",$text);
$text=preg_replace("#\[".$code['tag']."\](.*)\[/".$code['tag']."\]#esiU","\$this->urlrewrite('$code[html]','\\1')",$text);
return $text;
}
function urlrewrite($html='', $url='', $text='') {
if ($text=='') $text=$url;
if ($this->urlcut==1 && strlen(trim($text) && preg_match("([^<>\[\]])",$text))>$this->urlmaxwidth) $text=substr(trim($text),0,$this->urlwidth1)."...".substr(trim($text),$this->urlwidth2);
$rewritedurl=str_replace("\\\"","\"",str_replace("{option}",trim($url),str_replace("{text}",trim($text),$html)));
return $rewritedurl;
}
function parseimages ($text='') {
$tags=$this->imagetags;
foreach ($tags as $code) {
$text=preg_replace("#\[".$code['tag']."]([^\"\?\&]*\.(gif|jpg|jpeg|bmp|png))\[\/".$code['tag']."\]#eiU","\$this->image('$code[html]','\\1')",$text);
}
return $text;
}
function bbcode($text='') {
if ($this->bbhash=='') $this->bbdefine();
if (is_array($this->bbhash)) {
foreach($this->bbhash as $code) {
if (strstr($code['html'],'{option}')) $text=preg_replace("#\[".$code['tag']."=(.*)\](.*)\[/".$code['tag']."\]#eisUS","\$this->bbreplace('$code[html]','\\2','\\1')",$text);
elseif (strstr($code['html'],'{text}')) {
$pattern="#\[".$code['tag']."\](.*)\[/".$code['tag']."\]#eisUS";
while(preg_match($pattern,$text)) {$text=preg_replace($pattern,"\$this->bbreplace('$code[html]','\\1')",$text);}
}
else $text=preg_replace("/\[".$code['tag']."\]/",$code['html'],$text);
}
}
return $text;
}
function bbreplace($html='',$text='',$option='') {
if ($option!='') $text=str_replace("{option}",$option,str_replace("{text}",$text,$html));
else $text=str_replace("{text}",$text,$html);
return $text;
}
function image($html='', $url='') {
return str_replace("{image}",$url,$html);
}
function removeimages($text='') {
return preg_replace("#\[[img|imgr|imgl]\]#i","
",preg_replace("#\[/[img|imgr|imgl]\]#i","",$text));
}
function smilies ($text='') {
if ($this->smiliehash=='') $this->definesmilies();
if (is_array($this->smiliehash)) {
foreach ($this->smiliehash as $smilie) {
if ($smilie_size=@getimagesize($smilie['smilie_path'])) $smilie_size=$smilie_size[3];
else unset($smilie_size);
$text=str_replace($smilie['smilie_code'],'<img src="'.$smilie['smilie_path'].'" border="0" alt="'.$smilie['smilie_title'].'" '.$smilie_size.' />',$text);
}
}
return $text;
}
function textcensor($text='') {
global $config;
if ($config['censor_badword']!='' && $this->censoruse==1) {
$r=$this->censorreplace;
$censorlist=explode("\n",$config['censor_badword']);
foreach($censorlist as $c) {
$c=trim($c);
if ($c!='') {
$cc=strlen($c);
if (preg_match("#\{(.*)\}#isU",$c)) {
$cc=$cc-2;
while($cc>0) {$rr.=$r; $cc--;}
$text=preg_replace($c," ".$rr." ",$text);
}
else {
while($cc>0) {$rr.=$r; $cc--;}
$text=eregi_replace($c,$rr,$text);
}
}
unset($cc); unset($rr);
}
}
return $text;
}
function preparehtml($text='') {
$text=preg_replace("#<table(.*)>([ |\n|\r\s]{1,})<tr#iUs","<table\\1><tr",$text);
$text=preg_replace("#<tr(.*)>([ |\n|\r\s]{1,})<td#iUs","<tr\\1><td",$text);
$text=preg_replace("#</td>([ |\n|\r\s]{1,})</tr>#iUs","</td></tr>",$text);
$text=preg_replace("#</tr>([ |\n|\r\s]{1,})</table>#iUs","</tr></table>",$text);
return str_replace('"',""",$text);
}
function returntext($text='') {
return preg_replace("/javascript:/i","java script:",preg_replace("/vb script:/i","vb script:",nl2br($text)));
}
}
?>