phpBB::callback_html( $field )
This callback processes any custom parser.php attributes and custom code with preg_replace
Description
Source
File: bp-forums/admin/converters/phpBB.php
protected function callback_html( $field ) { // Strips custom phpBB 'magic_url' and 'bbcode_uid' first from $field before parsing $field to parser.php $phpbb_uid = $field; $phpbb_uid = html_entity_decode( $phpbb_uid ); // Replace '[b:XXXXXXX]' with '<strong>' $phpbb_uid = preg_replace( '/\[b:(.*?)\]/', '<strong>', $phpbb_uid ); // Replace '[/b:XXXXXXX]' with '</strong>' $phpbb_uid = preg_replace( '/\[\/b:(.*?)\]/', '</strong>', $phpbb_uid ); // Replace '[i:XXXXXXX]' with '<em>' $phpbb_uid = preg_replace( '/\[i:(.*?)\]/', '<em>', $phpbb_uid ); // Replace '[/i:XXXXXXX]' with '</em>' $phpbb_uid = preg_replace( '/\[\/i:(.*?)\]/', '</em>', $phpbb_uid ); // Replace '[u:XXXXXXX]' with '<u>' $phpbb_uid = preg_replace( '/\[u:(.*?)\]/', '<u>', $phpbb_uid ); // Replace '[/u:XXXXXXX]' with '</u>' $phpbb_uid = preg_replace( '/\[\/u:(.*?)\]/', '</u>', $phpbb_uid ); // Replace '[quote:XXXXXXX]' with '<blockquote>' $phpbb_uid = preg_replace( '/\[quote:(.*?)\]/', '<blockquote>', $phpbb_uid ); // Replace '[quote="$1"]' with '<em>$1 wrote:</em><blockquote>" $phpbb_uid = preg_replace( '/\[quote="(.*?)":(.*?)\]/', '<em>@$1 wrote:</em><blockquote>', $phpbb_uid ); // Replace '[/quote:XXXXXXX]' with '</blockquote>' $phpbb_uid = preg_replace( '/\[\/quote:(.*?)\]/', '</blockquote>', $phpbb_uid ); // Replace '[img:XXXXXXX]' with '<img src="' $phpbb_uid = preg_replace( '/\[img:(.*?)\]/', '<img src="', $phpbb_uid ); // Replace '[/img:XXXXXXX]' with ' alt="">' $phpbb_uid = preg_replace( '/\[\/img:(.*?)\]/', '" alt="">', $phpbb_uid ); // Replace '<!-- s$1 --><img src=\"{SMILIES_PATH}$2 -->' with '$1' $phpbb_uid = preg_replace( '/<!-- s(.*?) --><img src=\"{SMILIES_PATH}(.*?)-->/', '$1', $phpbb_uid ); // Replace '<!-- m --><a class="postlink" href="$1">$1</a><!-- m -->' with '$1' $phpbb_uid = preg_replace( '/\<!-- m --\>\<a class="postlink" href="([^\[]+?)"\>([^\[]+?)\<\/a\>\<!-- m --\>/', '$1', $phpbb_uid ); // Replace '[url:XXXXXXX]$1[/url:XXXXXXX]' with '<a href="http://$1">$1</a>' $phpbb_uid = preg_replace( '/\[url:(?:[^\]]+)\]([^\[]+?)\[\/url:(?:[^\]]+)\]/', '<a href="http://$1">$1</a>', $phpbb_uid ); // Replace '[url=http://$1:XXXXXXX]$3[/url:XXXXXXX]' with '<a href="http://$1">$3</a>' $phpbb_uid = preg_replace( '/\[url\=http\:\/\/(.*?)\:(.*?)\](.*?)\[\/url:(.*?)\]/i', '<a href="http://$1">$3</a>', $phpbb_uid ); // Replace '[url=https://$1:XXXXXXX]$3[/url:XXXXXXX]' with '<a href="http://$1">$3</a>' $phpbb_uid = preg_replace( '/\[url\=https\:\/\/(.*?)\:(.*?)\](.*?)\[\/url:(.*?)\]/i', '<a href="https://$1">$3</a>', $phpbb_uid ); // Replace '[email:XXXXXXX]' with '<a href="mailto:$2">$2</a>' $phpbb_uid = preg_replace( '/\[email:(.*?)\](.*?)\[\/email:(.*?)\]/', '<a href="mailto:$2">$2</a>', $phpbb_uid ); // Replace '<!-- e -->[email protected]<!-- e -->' with '$1' $phpbb_uid = preg_replace( '/\<!-- e --\>(.*?)\<!-- e --\>/', '$1', $phpbb_uid ); // Replace '[code:XXXXXXX]' with '<pre><code>' $phpbb_uid = preg_replace( '/\[code:(.*?)\]/', '<pre><code>', $phpbb_uid ); // Replace '[/code:XXXXXXX]' with '</code></pre>' $phpbb_uid = preg_replace( '/\[\/code:(.*?)\]/', '</code></pre>', $phpbb_uid ); // Replace '[color=$1:XXXXXXXX]' with '<span style="color:$1">' $phpbb_uid = preg_replace( '/\[color=(.*?)\:(.*?)\]/', '<span style="color: $1">', $phpbb_uid ); // Replace '[/color:XXXXXXX]' with '</span>' $phpbb_uid = preg_replace( '/\[\/color:(.*?)\]/', '</span>', $phpbb_uid ); // Replace '[size=$1:XXXXXXXX]' with '<span style="font-size:$1%;">$3</span>' $phpbb_uid = preg_replace( '/\[size=(.*?):(.*?)\]/', '<span style="font-size:$1%;">', $phpbb_uid ); // Replace '[/size:XXXXXXX]' with '' $phpbb_uid = preg_replace( '/\[\/size:(.*?)\]/', '</span>', $phpbb_uid ); // Replace '[list:XXXXXXX]' with '<ul>' $phpbb_uid = preg_replace( '/\[list:(.*?)\]/', '<ul>', $phpbb_uid ); // Replace '[list=a:XXXXXXX]' with '<ol type="a">' $phpbb_uid = preg_replace( '/\[list=a:(.*?)\]/', '<ol type="a">', $phpbb_uid ); // Replace '[list=1:XXXXXXX]' with '<ol>' $phpbb_uid = preg_replace( '/\[list=1:(.*?)\]/', '<ol>', $phpbb_uid ); // Replace '[*:XXXXXXX]' with '<li>' $phpbb_uid = preg_replace( '/\[\*:(.*?)\]/', '<li>', $phpbb_uid ); // Replace '[/*:m:XXXXXXX]' with '</li>' $phpbb_uid = preg_replace( '/\[\/\*:m:(.*?)\]/', '</li>', $phpbb_uid ); // Replace '[/list:u:XXXXXXX]' with '</ul>' $phpbb_uid = preg_replace( '/\[\/list:u:(.*?)\]/', '</ul>', $phpbb_uid ); // Replace '[/list:o:XXXXXXX]' with '</ol>' $phpbb_uid = preg_replace( '/\[\/list:o:(.*?)\]/', '</ol>', $phpbb_uid ); // Now that phpBB's 'magic_url' and 'bbcode_uid' have been stripped put the cleaned HTML back in $field $field = $phpbb_uid; // Parse out any bbCodes in $field with the BBCode 'parser.php' require_once( bbpress()->admin->admin_dir . 'parser.php' ); $bbcode = BBCode::getInstance(); $bbcode->enable_smileys = false; $bbcode->smiley_regex = false; return html_entity_decode( $bbcode->Parse( $field ) ); }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.