Improving performance measuring for the bbcode parser.
This commit is contained in:
parent
df880f7fd2
commit
30548dfeed
|
@ -852,9 +852,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
} while ($oldtext != $Text);
|
||||
}
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
// Handle attached links or videos
|
||||
$Text = bb_attachment($Text, ($simplehtml != 4) AND ($simplehtml != 0), $tryoembed);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);
|
||||
|
||||
if($preserve_nl)
|
||||
|
@ -884,10 +888,14 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
if ($simplehtml == 5)
|
||||
$Text = preg_replace("/[^#@]\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '[url]$1[/url]', $Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
// Perform URL Search
|
||||
if ($tryoembed)
|
||||
$Text = preg_replace_callback("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'tryoembed',$Text);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
if ($simplehtml == 5)
|
||||
$Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url]$1[/url]',$Text);
|
||||
else
|
||||
|
@ -896,6 +904,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
// Handle Diaspora posts
|
||||
$Text = preg_replace_callback("&\[url=/posts/([^\[\]]*)\](.*)\[\/url\]&Usi", 'bb_DiasporaLinks', $Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
// if the HTML is used to generate plain text, then don't do this search, but replace all URL of that kind to text
|
||||
if (!$forplaintext)
|
||||
$Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="_blank">$2</a>', $Text);
|
||||
|
@ -907,6 +917,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
if ($tryoembed)
|
||||
$Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
$Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$1</a>', $Text);
|
||||
$Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||
//$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
|
||||
|
@ -1078,8 +1090,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
$Text = preg_replace("/\[video\](.*?\.(ogg|ogv|oga|ogm|webm|mp4))\[\/video\]/ism", '<video src="$1" controls="controls" width="' . $a->videowidth . '" height="' . $a->videoheight . '"><a href="$1">$1</a></video>', $Text);
|
||||
$Text = preg_replace("/\[audio\](.*?\.(ogg|ogv|oga|ogm|webm|mp4|mp3))\[\/audio\]/ism", '<audio src="$1" controls="controls"><a href="$1">$1</a></audio>', $Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
$Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
|
||||
$Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
} else {
|
||||
$Text = preg_replace("/\[video\](.*?)\[\/video\]/",
|
||||
'<a href="$1" target="_blank">$1</a>', $Text);
|
||||
|
@ -1097,9 +1114,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
|
||||
// Youtube extensions
|
||||
if ($tryoembed) {
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
$Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
|
||||
$Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
|
||||
$Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
}
|
||||
|
||||
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
|
||||
|
@ -1113,8 +1134,12 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
'<a href="https://www.youtube.com/watch?v=$1" target="_blank">https://www.youtube.com/watch?v=$1</a>', $Text);
|
||||
|
||||
if ($tryoembed) {
|
||||
$Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
|
||||
$Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
$Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
|
||||
$Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
}
|
||||
|
||||
$Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
|
||||
|
@ -1128,10 +1153,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
|
|||
|
||||
// $Text = preg_replace("/\[youtube\](.*?)\[\/youtube\]/", '<object width="425" height="350" type="application/x-shockwave-flash" data="http://www.youtube.com/v/$1" ><param name="movie" value="http://www.youtube.com/v/$1"></param><!--[if IE]><embed src="http://www.youtube.com/v/$1" type="application/x-shockwave-flash" width="425" height="350" /><![endif]--></object>', $Text);
|
||||
|
||||
$a->save_timestamp($stamp1, "parser");
|
||||
|
||||
// oembed tag
|
||||
$Text = oembed_bbcode2html($Text);
|
||||
|
||||
$stamp1 = microtime(true);
|
||||
|
||||
// Avoid triple linefeeds through oembed
|
||||
$Text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $Text);
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user