function bblinks() {
// replace xyz
$this->string = preg_replace(
"=\[url\](.*)\[\/url\]=i",
"<a href=\"$1\">$1</a>",
$this->string
);
// replace text
$this->string = preg_replace(
"=\[url\=\"(.*)\](.*)\[\/url\]=i",
"<a href=\"$1\">$2</a>",
$this->string
);
// replace trext
$this->string = preg_replace(
"=\[url\='(.*)'\](.*)\[\/url\]=i",
"<a href=\"$1\">$2</a>",
$this->string
);
// replace text
$this->string = preg_replace(
"=\[url\=(.*)\](.*)\[\/url\]=i",
"<a href=\"$1\">$2</a>",
$this->string
);
}
function bbimages() {
if(preg_match_all("=\[img\](.*)\[\/img\]=Ui", $this->string, $matches)) {
$width = 'auto';
$height = 'auto';
foreach($matches['1'] AS $img) {
$img = strtolower($img);
$allowed = FALSE;
$url = substr($img, 0,4);
if($this->images_local && $url != 'http' ) {
$allowed = TRUE;
}
if($this->images_url && $url == 'http' {
$allowed = TRUE;
}
if($this->images_dynamik) {
$url_end = substr($img, strlen($img)-3, 3);
if($url_end != 'jpg' && $url_end != 'gif' && $url_end != 'png' {
if(substr($img, strlen($img)-4, 4) != 'jpeg' {
$allowed = FALSE;
}
}
}
if($allowed) {
if($this->images_properties) {
if($this->images_only_local_properties) {
if($url != 'http' {
$imagesize = getimagesize($img);
if($imagesize) {
$width = $imagesize['0'];
$height = $imagesize['1'];
}
}
} else {
$imagesize = getimagesize($img);
if($imagesize) {
$width = $imagesize['0'];
$height = $imagesize['1'];
}
}
}
$this->string = preg_replace(
"=\[img\]".$img."\[\/img\]=",
"<img src=\"".$img."\" alt=\"Image\" style=\"width:".$width.";height:".$height.";border:0px;\" />",
$this->string
);
} else {
$this->string = preg_replace(
"=\[img\]".$img."\[\/img\]=",
"<abbr title=\"Es wurde versucht ein Bild über die Adresse '".$img."' einzubinden.\">IMAGE</abbr> <a class=\"biglink\" href=\"".$img."\">".chr(129)."</a>",
$this->string
);
}
}
}
}
function parse($string) {
$string = htmlspecialchars_decode($string);
$this->string = $string;
#if($this->basic)
#$this->bbbasics();
if($this->links)
$this->bblinks();
if($this->images)
$this->bbimages();
return $this->string;
}
class BB {
var $links = TRUE;
var $images = TRUE;
var $images_local = TRUE;
var $images_url = TRUE;
function bblinks() {
// replace xyz
$this->string = preg_replace('=\[url\](.*)\[/url\]=Ui',
'<a href="$1">$1</a>', $this->string);
// replace text, text
// and text
$this->string = preg_replace('!\[url=((?:\'|"|))(.+)\1'.
'\](.+)\[/url\]!i', '<a href="$2">$3</a>',
$this->string);
}
function bbimages() {
$this->string = preg_replace_callback(
'=\[img\](.+)\[\/img\]=Ui', array($this, 'bbimages_',
$this->string);
}
function bbimages_($m) {
$img = strtolower($m[1]);
$allowed = FALSE;
$scheme = explode('://', $img, 2);
// in anderen Sprachen ginge das direkt...
$scheme = $scheme[0];
// externe Bilder erlauben in alten IE-Versionen eventuell
// XSS! (der IE führt JS-Code auch be <img /> aus, wenn
// der Content-Type passt...
// evtl. lieber weglassen
if (($this->images_local && !$scheme) or
($this->images_url && $scheme == 'http') {
$allowed = TRUE;
}
// den ganzen "Dynamik"-Code hab ich weggelassen, keine Ahnung
// was das sollte?
if (!$allowed) {
return '<abbr title="Es wurde versucht ein Bild über'.
' die Adresse "'.htmlspecialchars($img).
'" einzubinden.">IMAGE</abbr> <a class="'.
'biglink" href="'.htmlspecialchars($img).
'">'.chr(129).'</a>';
}
$width = 'auto';
$height = 'auto';
if ($this->images_properties) {
if (!$this->images_only_local_properties or !$scheme) {
$imagesize = getimagesize($img);
if ($imagesize) {
$width = $imagesize[0];
$height = $imagesize[1];
}
}
}
return '<img src="'.htmlspecialchars($img).'" alt="Image"'.
' style="width:'.$width.';height:'.$height.
';border:0px;" />';
}
function parse($string) {
#$string = htmlspecialchars_decode($string); // ?
$this->string = $string;
#if($this->basic)
#$this->bbbasics();
if ($this->links) {
$this->bblinks();
}
if ($this->images) {
$this->bbimages();
}
return $this->string;
}
}
" target="_blank" class="link">