<?php
function resizeimg($str,$caption,$oldformat){
global $image_maxheight, $image_maxwidth, $adminpath;
$str = str_replace(" ", "%20",$str);
$caption = stripslashes($caption);
list($width, $height, $type, $attr) = getimagesize("$str");
if(!$image_maxheight){ $image_maxheight = $height; }
if(!$image_maxwidth){ $image_maxwidth = $width; }
if($width > $image_maxwidth || $height > $image_maxheight){
if($width > $image_maxwidth || $height > $image_maxheight){
$new_width = $width;
$new_height = $height;
$percent = 0.9;
while($new_width > $image_maxwidth|| $new_height > $image_maxheight){
$new_width = $width * $percent;
$new_height = $height * $percent;
$percent = $percent - 0.01;
}
}else{
$new_width = $width;
$new_height = $height;
}
return "<div class=\"image_container\" style=\"width: $new_width" . "px\"><a href=\"$str\"><img class=\"fullnewsimage\" alt=\"image\" src=\"" . $adminpath . "?action=options&mod=imageuploads&width=$new_width&height=$new_height&thumb=$str\" /></a><br style=\"clear: both\" /><span class=\"image_caption\">$caption</span></div>";
}else{
return "<div class=\"image_container\" style=\"width: $width" . "px\"><img src=\"$str\" class=\"fullnewsimage\" width=\"$width\" alt=\"image\" height=\"$height\" /><br /><span class=\"image_caption\">$caption</span></div>";
}
}
#on-the-fly links
function linkfy($str){
$d = explode("\n",$str);
foreach($d as $url){
if($url !== ""){
$url = str_replace("<br />","",$url);
$newstr .= "<a href=\"$url\">$url</a><br />\n";
}
}
return $newstr;
}
function bb2html($str,$usehtml) {
global $langmsg, $newssmilies;
$bb2html = $str;
if($usehtml == "0"){
$bb2html = htmlentities($bb2html, ENT_NOQUOTES, 'utf-8');
}
$sqlbb = "SELECT keycode,path FROM $newssmilies";
$querybb = mysql_query($sqlbb) or die(mysql_error());
while($rowbb = mysql_fetch_array($querybb)){
$bb2html = str_replace($rowbb['keycode'],"<img src=\"$rowbb[path]\" alt=\"".$rowbb['keycode']."\" />",$bb2html);
}
$bb2html = str_replace("\r",'<br />', $bb2html);
$bb2html = preg_replace("#\[url\](.*?)\[\/url\]#se", "'' . linkfy(\"$1\") . ''", $bb2html);
$bb2html = str_replace('[left]', '<div align="left">', $bb2html);
$bb2html = str_replace('[/left]', '</div>', $bb2html);
$bb2html = str_replace('[center]', '<div align="center">', $bb2html);
$bb2html = str_replace('[/center]', '</div>', $bb2html);
$bb2html = str_replace('[right]', '<div align="right">', $bb2html);
$bb2html = str_replace('[/right]', '</div>', $bb2html);
$bb2html = str_replace('[b]', '<strong>', $bb2html);
$bb2html = str_replace('[/b]', '</strong>', $bb2html);
$bb2html = str_replace('[i]', '<em>', $bb2html);
$bb2html = str_replace('[/i]', '</em>', $bb2html);
$bb2html = str_replace('[u]', '<u>', $bb2html);
$bb2html = str_replace('[/u]', '</u>', $bb2html);
$bb2html = str_replace('[*]', '<li>', $bb2html);
$bb2html = str_replace('[/*]', '</li>', $bb2html);
$bb2html = str_replace('[ul]', '<ul>', $bb2html);
$bb2html = str_replace('[/ul]', '</ul>', $bb2html);
$bb2html = str_replace('[list]', '<ul>', $bb2html);
$bb2html = str_replace('[/list]', '</ul>', $bb2html);
$bb2html = str_replace('[ol]', '<ol>', $bb2html);
$bb2html = str_replace('[/ol]', '</ol>', $bb2html);
$bb2html = str_replace('</li><br />', '</li>', $bb2html);
$bb2html = str_replace('<ul><br />', '<ul>', $bb2html);
$bb2html = str_replace('</ul><br />', '</ul>', $bb2html);
$bb2html = str_replace('<ol><br />', '<ol>', $bb2html);
$bb2html = str_replace('</ol><br />', '</ol>', $bb2html);
$bb2html = str_replace('[/img]<br />', '[/img]', $bb2html);
$bb2html = str_replace('[quote]', "<div class=\"quote\">", $bb2html);
$bb2html = str_replace('[/quote]', '</div>', $bb2html);
$bb2html = preg_replace("/\[size=(\W?)(.*?)(\W?)\](.*?)\[\/size\]/", '<font style="font-size: $2">$4</font>', $bb2html);
$bb2html = preg_replace("/\[email\=(.+?)\](.+?)\[\/email\]/i", '<a href="mailto:$1">$2</a>', $bb2html);
$bb2html = preg_replace("/\[url=(\W?)(.*?)(\W?)\](.*?)\[\/url\]/", '<a href="$2">$4</a>', $bb2html);
$match = array('#\[img=(\W?)(.*?)(\W?)\](.*?)\[\/img\]#se');
$replace = array("'' . resizeimg('$2','$4','') . ''");
$bb2html = preg_replace($match, $replace, $bb2html);
##oldformat [img]http://[/img]
$match = array('#\[img\]http://(.*?)\[\/img\]#se');
$replace = array("'' . resizeimg('http://$1','','true') . ''");
$bb2html = preg_replace($match, $replace, $bb2html);
$bb2html = preg_replace('/\[color\=(.+?)\](.+?)\[\/color\]/is', "<span style=\"color:$1\">$2<!--color--></span>", $bb2html);
return $bb2html;
}
?>