1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | | PHP-Quelltext <?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 class="contentbody_link" 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>'),
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'=>'green','html'=>'{text}'),
array('tag'=>'white','html'=>'{text}'),
array('tag'=>'gold','html'=>'{text}'),
array('tag'=>'color','html'=>'<font style="color: {option}">{text}</font>'),
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]*)","\\1http://\\2",$text);
$text=eregi_replace("([ \r\n])https://([^ ,\r\n]*)","\\1https://\\2",$text);
$text=eregi_replace("([ \r\n])ftp://([^ ,\r\n]*)","\\1ftp://\\2",$text);
$text=eregi_replace("([ \r\n])www\\.([^ ,\r\n]*)","\\1http://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='') {
$tags_open = array('table','tr','tbody'); // Öffnende Tags eintragen
$tags_closed = array('table','tr','td','th','tbody'); // Schliessende Tags eintragen
// Anfänge
for($i=0;$i<count($tags_open);$i++) {
if(isset($open) AND $open != "") $open .= "|";
$open .= $tags_open[$i];
}
eval("\$text=preg_replace(\"#<(".$open."){1,}(.*)>([\\r|\\n])[\\s]{1,}#iUs\",\"<\\\\1\\\\2>\",\$text);");
// Abschlüsse
for($i=0;$i<count($tags_closed);$i++) {
if(isset($closed) AND $closed != "") $closed .= "|";
$closed .= $tags_closed[$i];
}
eval("\$text=preg_replace(\"#</(".$closed."){1,}>([\\r|\\n])[\\s]{1,}#iUs\",\"</\\\\1>\",\$text);");
return str_replace('"','"',$text);
}
function returntext($text='') {
return preg_replace("/javascript:/i","java script:",preg_replace("/vb script:/i","vb script:",nl2br($text)));
}
}
?> |