Chacmool,
You've saved me loads of time by writing this converter, thank you very much!
Here's my contribution ...
The converter was only doing a half-perfect job of converting the message contents in posts - you seem to have overlooked the fact that carriage return and linefeed in MiniBB posts don't mean anything? In PunBB they do - thus, you must first discard any carriage returns and linefeeds before you convert <br> to linefeed, otherwise you get excess whitespace in some messages. The font color tag was not handled. After converting everything possible, I would strip and wipe any excess HTML at the end - this should maybe be optional, for those who allowed HTML in their posts when they were running MiniBB. And finally, for those using "hack_smilies.php" with MiniBB (I was), I made a little conversion function, which will detect smilie images and translate them back to ordinary smilies for PunBB to display.
Here's the modified "functions.php":
<?
function generatedtime($start, $finish){
list( $start1, $start2 ) = explode( ' ', $start );
list( $finish1, $finish2 ) = explode( ' ', $finish );
return sprintf( "%.2f", ($finish1 + $finish2) - ($start1 + $start2) );
} // end function generatedtime
function html_stuff($message){
$pattern = array(
'/>/i',
'/</i',
'/&/i',
'/"/i',
'/'/i'
);
$replace = array(
'>',
'<',
'&',
'"',
"'"
);
return addslashes(preg_replace($pattern, $replace, $message));
}
function convert_smilies($message) {
$smilie_path = '/img/emos/'; // images in this folder will be converted to smilies - this path must including trailing and leading slashes, and may be partial (e.g. you can specify simply "/images/smilies/" instead of "http://www.mysite.com/myforum/images/smilies/")
// map of which GIFs to convert to what smilies:
$smilie_map = array(
'grin.gif' => ":)",
'sad.gif' => ":(",
'shock.gif' => ":o",
'lol.gif' => ":D",
'wink.gif' => ";)",
'tongue.gif' => ":p",
'biglol.gif' => ":biglol:",
'confused.gif' => ":confused:",
'grin.gif' => ":grin:",
'mad.gif' => ":mad:",
'sad.gif' => ":sad:",
'wink.gif' => ":wink:",
'sad.gif' => ":cry:",
'lol.gif' => ":lol:",
'cool.gif' => ":cool:",
'hihi.gif' => ":hihi:",
'biglol.gif' => ":rofl:",
'tongue.gif' => ":tongue:",
'shame.gif' => ":shame:",
'shock.gif' => ":eek:",
'rolleyes.gif' => ":rolleyes:",
'idea.gif' => ":idea:",
'neutral.gif' => ":|"
);
$smilie_path = preg_replace('/\//i', '\\\/', $smilie_path); // escape slashes
foreach($smilie_map as $img => $smilie)
{
$img = preg_replace('/\./i', '\\\.', $img); // escape dots
$message = preg_replace('/\[img\][^\[]*'.$smilie_path.$img.'\[\/img\]/im', $smilie, $message);
}
return($message);
}
function convert_posts($message){
$pattern = array(
// returns and linefeeds
'/\r/i',
'/\n/i',
// <br>
'/<br>/im',
// bold, italic, underline
'/<b>/i', '/<\/b>/i',
'/<i>/i', '/<\/i>/i',
'/<u>/i', '/<\/u>/i',
// Mail
'/<a href="mailto:([^"]+)">([^<]+)<\/a>/im',
// URLs
'/<a href="http:([^"]+)"(?:[^>]*)>([^<]+)<\/a>/im',
// Images
'/<img src="([^"]+)"(?:[^>]*)>/im',
// Font color
'/<font color="(#[0-9,a-f,A-F]{6})">([^<]*)<\/font>/im',
// Illegal HTML
'/<[^>]*>/'
);
$replace = array(
// returns and linefeeds
'',
'',
// <br>
"\n",
// bold, italic, underline
'[b]', '[/b]',
'[i]', '[/i]',
'[u]', '[/u]',
// Mail
'[email=$1]$2[/email]',
// URLs
'[url=http:$1]$2[/url]',
// Images
'[img]$1[/img]',
// Font color
'[color=$1]$2[/color]',
// Illegal HTML
''
);
return html_stuff(convert_smilies(preg_replace($pattern, $replace, $message)));
}
?>
I only added convert_smilies() and modified the two arrays in convert_posts(), so if you already made other changes (mine is based on beta 3), you can simply copy/paste those.
Woot