-
-
Save LookedPath/9fb01e599850fb4e1f5eb8e323fae3e0 to your computer and use it in GitHub Desktop.
phpbb_prepare_message function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function phpbb_prepare_message($message) | |
{ | |
global $phpbb_root_path, $phpEx, $db, $convert, $user, $config, $cache, $convert_row, $message_parser; | |
if (!$message) | |
{ | |
$convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = 0; | |
return ''; | |
} | |
if (!empty($convert_row['pid'])) | |
{ | |
ipb_reformat_inline_attach($message, $convert_row['pid']); | |
} | |
// Already the new user id ;) | |
$user_id = $convert->row['poster_id']; | |
$board_url = generate_board_url(); | |
// Adjust font styles. | |
$message = preg_replace_callback('#<span style="font\-size:([0-9]+)px;">(.*?)</span>#s', 'ipb_fix_font_size', $message); | |
$message = preg_replace_callback('#<span style="font\-family:(.*?);">(.*?)</span>#is', 'ipb_fix_font_family', $message); | |
$bbcodes = array( | |
'#<p style="text\-align:center;">(.*?)</p>#is' => '[align=center]$1[/align]', | |
'#<p style="text\-align:right;">(.*?)</p>#is' => '[align=right]$1[/align]', | |
'#<span style="font\-family:(.*?);">(.*?)</span>#is' => '[font=$1]$2[/font]', | |
'#<a(?:.*?)href=\'(.*?)\'>(.*?)</a>#' => '[url=$1]$2[/url]', | |
'#<img src="(.*?)"(:?.*?)>#' => '[img]$1[/img]', | |
'#<span style="color:([\#0-9a-zA-Z]+);">(.*?)</span>#s' => '[color=$1]$2[/color]', | |
'#<pre(?:.*?)?>(.*?)</pre>#s' => '[code]$1[/code]', | |
'#<blockquote(?:\s)+class="ipsBlockquote" data\-author="(.*?)"(?:.*?)>(?:\s)+<div>(.*?)</div>(?:\s)+</blockquote>#s' => '[quote="$1"]$2[/quote]', | |
'#<blockquote(?:\s)+class="ipsBlockquote"><br><p> </p>(.*?)</blockquote>#s' => '[quote]$1[/quote]', | |
'#<br(?:\s)+?/?>#i' => "\n", | |
'#<p style="margin-left:([0-9]+)px;">(.*?)</p>#' => '[indent=$1]$2[/indent]', | |
'#\[member=\'(.*?)\'\]#' => "[url={$board_url}/memberlist.{$phpEx}?mode=viewprofile&un=$1]$1[/url]", | |
'#\[twitter\](.*?)\[/twitter\]#' => '[url=https://twitter.com/$1]@$1[/url]', | |
'#\[post=\'([0-9]+)\'\](.*?)\[/post\]#' => "[url={$board_url}/viewtopic.{$phpEx}?p=$1#p$1]$2[/url]", | |
'#\[topic=\'([0-9]+)\'\](.*?)\[/topic\]#' => "[url={$board_url}/viewtopic.{$phpEx}?t=$1]$2[/url]", | |
'#\[(sql|html)\](.*?)\[/\1]#' => '[code]$2[/code]', | |
// Remove remaining junk span tags. | |
'#<span(:?.*?)>#is' => '', | |
); | |
$message = preg_replace(array_keys($bbcodes), $bbcodes, $message); | |
$bbcodes = array( | |
'<p>' => '', | |
'</p>' => '', | |
'<ol>' => '[list=1]', | |
'</ol>' => '[/list]', | |
'<ul>' => '[list]', | |
'</ul>' => '[/list]', | |
'<strong>' => '[b]', | |
'</strong>' => '[/b]', | |
'<em>' => '[i]', | |
'</em>' => '[/i]', | |
'<u>' => '[u]', | |
'</u>' => '[/u]', | |
'<strike>' => '[s]', | |
'</strike>' => '[/s]', | |
'<sub>' => '[sub]', | |
'</sub>' => '[/sub]', | |
'<sup>' => '[sup]', | |
'</sup>' => '[/sup]', | |
'<li><br></li>' => '', // Get rid of these nasty things. | |
'<li>' => '[*]', | |
'</li>' => '', | |
'</span>' => '', | |
'<br>' => "\n", | |
'<' => '<', | |
'>' => '>', | |
'[php]' => '[code=php]', | |
'[/php]' => '[/code]', | |
'[hr]' => '[hr][/hr]', | |
); | |
$message = str_replace(array_keys($bbcodes), $bbcodes, $message); | |
// make the post UTF-8 | |
$message = phpbb_set_encoding($message); | |
$message_parser->warn_msg = array(); // Reset the errors from the previous message | |
$message_parser->bbcode_uid = make_uid($convert->row['post_date']); | |
$message_parser->message = $message; | |
unset($message); | |
// Make sure options are set. | |
$enable_bbcode = (!isset($convert->row['enable_bbcode'])) ? true : $convert->row['enable_bbcode']; | |
$enable_smilies = (!isset($convert->row['use_emo'])) ? true : $convert->row['use_emo']; | |
$enable_magic_url = (!isset($convert->row['enable_magic_url'])) ? true : $convert->row['enable_magic_url']; | |
// parse($allow_bbcode, $allow_magic_url, $allow_smilies, $allow_img_bbcode = true, $allow_flash_bbcode = true, $allow_quote_bbcode = true, $allow_url_bbcode = true, $update_this_message = true, $mode = 'post') | |
$message_parser->parse($enable_bbcode, $enable_magic_url, $enable_smilies); | |
if (sizeof($message_parser->warn_msg)) | |
{ | |
$msg_id = isset($convert->row['post_id']) ? $convert->row['post_id'] : $convert->row['privmsgs_id']; | |
$convert->p_master->error('<span style="color:red">' . $user->lang['POST_ID'] . ': ' . $msg_id . ' ' . $user->lang['CONV_ERROR_MESSAGE_PARSER'] . ': <br /><br />' . implode('<br />', $message_parser->warn_msg), __LINE__, __FILE__, true); | |
} | |
$convert->row['mp_bbcode_bitfield'] = $convert_row['mp_bbcode_bitfield'] = $message_parser->bbcode_bitfield; | |
$message = $message_parser->message; | |
unset($message_parser->message); | |
return $message; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment