function post_bbcode_clean($str) { global $mybb; $str = preg_replace('/\\[php\\](.*?)\\[\\/php\\]/sei', "'[ttcode]'.base64_encode('\$1').'[/ttcode]'", $str); $str = preg_replace('/\\[code\\](.*?)\\[\\/code\\]/sei', "'[ttcode]'.base64_encode('\$1').'[/ttcode]'", $str); $array_reg = array(array('reg' => '/\\[color=(.*?)\\](.*?)\\[\\/color\\]/sei', 'replace' => "mobi_color_convert('\$1','\$2' ,false)"), array('reg' => '/\\[align=(.*?)\\](.*?)\\[\\/align\\]/si', replace => " \$2 "), array('reg' => '/\\[email\\](.*?)\\[\\/email\\]/si', replace => "[url]\$1[/url]")); foreach ($array_reg as $arr) { $str = preg_replace($arr['reg'], $arr['replace'], $str); } $str = tt_covert_list($str, '/\\[list=1\\](.*?)\\[\\/list\\]/si', '2'); $str = tt_covert_list($str, '/\\[list\\](.*?)\\[\\/list\\]/si', '1'); if (!empty($mybb->settings['tapatalk_custom_replace'])) { $replace_arr = explode("\n", $mybb->settings['tapatalk_custom_replace']); foreach ($replace_arr as $replace) { preg_match('/^\\s*(\'|")((\\#|\\/|\\!).+\\3[ismexuADUX]*?)\\1\\s*,\\s*(\'|")(.*?)\\4\\s*$/', $replace, $matches); if (count($matches) == 6) { $temp_post = $str; $str = @preg_replace($matches[2], $matches[5], $str); if (empty($str)) { $str = $temp_post; } } } } return $str; }
function process_bbcode($message, $uid) { global $user; // process bbcode: code $message = str_replace('[code:' . $uid . ']', '[quote]', $message); $message = str_replace('[/code:' . $uid . ']', '[/quote]', $message); // process bbcode: quote $quote_wrote_string = $user->lang['WROTE']; $message = str_replace('[/quote:' . $uid . ']', '[/quote]', $message); $message = preg_replace_callback('/\\[quote(?:="(.*?)")?:' . $uid . '\\]/is', create_function('$matches', ' $userid = get_user_id_by_name($matches[1]); return "[quote uid=".$userid." name=\\"".$matches[1]."\\" ]";'), $message); //$message = preg_replace('/\[quote(?:="(.*?)")?:'.$uid.'\]/ise', "'[quote uid=$uid name=\"$1\"]' . ('$1' ? '$1' . ' $quote_wrote_string:\n' : '\n')", $message); $blocks = preg_split('/(\\[\\/?quote\\])/i', $message, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $quote_level = 0; $message = ''; foreach ($blocks as $block) { if ($block == '[quote]') { if ($quote_level == 0) { $message .= $block; } $quote_level++; } else { if ($block == '[/quote]') { if ($quote_level <= 1) { $message .= $block; } if ($quote_level >= 1) { $quote_level--; } } else { if ($quote_level <= 1) { $message .= $block; } } } } // prcess bbcode: list $message = preg_replace('/\\[\\*:' . $uid . '\\]/si', '[*]', $message); $message = preg_replace('/\\[\\/\\*:(m:)?' . $uid . '\\]/si', '', $message); $message = tt_covert_list($message, '/\\[list:' . $uid . '\\](.*?)\\[\\/list:u:' . $uid . '\\]/si', '1', $uid); $message = tt_covert_list($message, '/\\[list=[^\\]]*?:' . $uid . '\\](.*?)\\[\\/list:o:' . $uid . '\\]/si', '2', $uid); // process video bbcode\ $message = preg_replace('/\\[(youtube|yt|video|googlevideo|gvideo):' . $uid . '\\](.*?)\\[\\/\\1:' . $uid . '\\]/sie', "video_bbcode_format('\$1', '\$2')", $message); $message = preg_replace('/\\[(BBvideo)[\\d, ]+:' . $uid . '\\](.*?)\\[\\/\\1:' . $uid . '\\]/si', "[url=\$2]YouTube Video[/url]", $message); $message = preg_replace('/\\[(spoil|spoiler):' . $uid . '\\](.*?)\\[\\/\\1:' . $uid . '\\]/si', "[spoiler]\$2[/spoiler]", $message); $message = preg_replace('/\\[HiddenText=(.*?)\\](.*?)\\[\\/HiddenText\\]/si', '[spoiler]$2[/spoiler]', $message); $message = preg_replace('/\\[b:' . $uid . '\\](.*?)\\[\\/b:' . $uid . '\\]/si', '[b]$1[/b]', $message); $message = preg_replace('/\\[i:' . $uid . '\\](.*?)\\[\\/i:' . $uid . '\\]/si', '[i]$1[/i]', $message); $message = preg_replace('/\\[u:' . $uid . '\\](.*?)\\[\\/u:' . $uid . '\\]/si', '[u]$1[/u]', $message); $message = preg_replace('/\\[color=(\\#[\\da-fA-F]{3}|\\#[\\da-fA-F]{6}|[A-Za-z]{1,20}|rgb\\(\\d{1,3}, ?\\d{1,3}, ?\\d{1,3}\\)):' . $uid . '\\](.*?)\\[\\/color:' . $uid . '\\]/si', '[color=$1]$2[/color]', $message); $message = preg_replace('/\\[mp3preview:' . $uid . '\\](.*?)\\[\\/mp3preview:' . $uid . '\\]/si', '[url=$1]MP3 Preview[/url]', $message); return $message; }