3 require_once("include/oembed.php");
4 require_once('include/event.php');
6 function bb_cleanstyle($st) {
7 return "<span style=\"".cleancss($st[1]).";\">".$st[2]."</span>";
10 function bb_cleanclass($st) {
11 return "<span class=\"".cleancss($st[1])."\">".$st[2]."</span>";
14 function cleancss($input) {
18 $input = strtolower($input);
20 for ($i = 0; $i < strlen($input); $i++) {
21 $char = substr($input, $i, 1);
23 if (($char >= "a") and ($char <= "z"))
26 if (!(strpos(" #;:0123456789", $char) === false))
33 function stripcode_br_cb($s) {
34 return '[code]' . str_replace('<br />', '', $s[1]) . '[/code]';
37 function tryoembed($match){
38 $url = ((count($match)==2)?$match[1]:$match[2]);
39 // logger("tryoembed: $url");
41 $o = oembed_fetch_url($url);
43 //echo "<pre>"; var_dump($match, $url, $o); killme();
45 if ($o->type=="error") return $match[0];
47 $html = oembed_format_object($o);
48 return $html; //oembed_iframe($html,$o->width,$o->height);
52 // [noparse][i]italic[/i][/noparse] turns into
53 // [noparse][ i ]italic[ /i ][/noparse],
54 // to hide them from parser.
56 function bb_spacefy($st) {
57 $whole_match = $st[0];
59 $spacefied = preg_replace("/\[(.*?)\]/", "[ $1 ]", $captured);
60 $new_str = str_replace($captured, $spacefied, $whole_match);
64 // The previously spacefied [noparse][ i ]italic[ /i ][/noparse],
65 // now turns back and the [noparse] tags are trimed
66 // returning [i]italic[/i]
68 function bb_unspacefy_and_trim($st) {
69 $whole_match = $st[0];
71 $unspacefied = preg_replace("/\[ (.*?)\ ]/", "[$1]", $captured);
75 function bb_find_open_close($s, $open, $close, $occurance = 1) {
81 for($i = 1; $i <= $occurance; $i++) {
82 if( $start_pos !== false)
83 $start_pos = strpos($s, $open, $start_pos + 1);
86 if( $start_pos === false)
89 $end_pos = strpos($s, $close, $start_pos);
91 if( $end_pos === false)
94 $res = array( 'start' => $start_pos, 'end' => $end_pos );
99 function get_bb_tag_pos($s, $name, $occurance = 1) {
105 for($i = 1; $i <= $occurance; $i++) {
106 if( $start_open !== false)
107 $start_open = strpos($s, '[' . $name, $start_open + 1); // allow [name= type tags
110 if( $start_open === false)
113 $start_equal = strpos($s, '=', $start_open);
114 $start_close = strpos($s, ']', $start_open);
116 if( $start_close === false)
121 $end_open = strpos($s, '[/' . $name . ']', $start_close);
123 if( $end_open === false)
126 $res = array( 'start' => array('open' => $start_open, 'close' => $start_close),
127 'end' => array('open' => $end_open, 'close' => $end_open + strlen('[/' . $name . ']')) );
128 if( $start_equal !== false)
129 $res['start']['equal'] = $start_equal + 1;
134 function bb_tag_preg_replace($pattern, $replace, $name, $s) {
139 $pos = get_bb_tag_pos($string, $name, $occurance);
140 while($pos !== false && $occurance < 1000) {
142 $start = substr($string, 0, $pos['start']['open']);
143 $subject = substr($string, $pos['start']['open'], $pos['end']['close'] - $pos['start']['open']);
144 $end = substr($string, $pos['end']['close']);
148 $subject = preg_replace($pattern, $replace, $subject);
149 $string = $start . $subject . $end;
152 $pos = get_bb_tag_pos($string, $name, $occurance);
158 if(! function_exists('bb_extract_images')) {
159 function bb_extract_images($body) {
161 $saved_image = array();
166 $img_start = strpos($orig_body, '[img');
167 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
168 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
169 while(($img_st_close !== false) && ($img_end !== false)) {
171 $img_st_close++; // make it point to AFTER the closing bracket
172 $img_end += $img_start;
174 if(! strcmp(substr($orig_body, $img_start + $img_st_close, 5), 'data:')) {
175 // This is an embedded image
177 $saved_image[$cnt] = substr($orig_body, $img_start + $img_st_close, $img_end - ($img_start + $img_st_close));
178 $new_body = $new_body . substr($orig_body, 0, $img_start) . '[$#saved_image' . $cnt . '#$]';
183 $new_body = $new_body . substr($orig_body, 0, $img_end + strlen('[/img]'));
185 $orig_body = substr($orig_body, $img_end + strlen('[/img]'));
187 if($orig_body === false) // in case the body ends on a closing image tag
190 $img_start = strpos($orig_body, '[img');
191 $img_st_close = ($img_start !== false ? strpos(substr($orig_body, $img_start), ']') : false);
192 $img_end = ($img_start !== false ? strpos(substr($orig_body, $img_start), '[/img]') : false);
195 $new_body = $new_body . $orig_body;
197 return array('body' => $new_body, 'images' => $saved_image);
200 if(! function_exists('bb_replace_images')) {
201 function bb_replace_images($body, $images) {
206 foreach($images as $image) {
207 // We're depending on the property of 'foreach' (specified on the PHP website) that
208 // it loops over the array starting from the first element and going sequentially
209 // to the last element
210 $newbody = str_replace('[$#saved_image' . $cnt . '#$]', '<img src="' . $image .'" alt="' . t('Image/photo') . '" />', $newbody);
217 function bb_ShareAttributes($match) {
219 $attributes = $match[1];
222 preg_match("/author='(.*?)'/ism", $attributes, $matches);
223 if ($matches[1] != "")
224 $author = html_entity_decode($matches[1],ENT_QUOTES,'UTF-8');
226 preg_match('/author="(.*?)"/ism', $attributes, $matches);
227 if ($matches[1] != "")
228 $author = $matches[1];
231 preg_match("/link='(.*?)'/ism", $attributes, $matches);
232 if ($matches[1] != "")
235 preg_match('/link="(.*?)"/ism', $attributes, $matches);
236 if ($matches[1] != "")
240 preg_match("/avatar='(.*?)'/ism", $attributes, $matches);
241 if ($matches[1] != "")
242 $avatar = $matches[1];
244 preg_match('/avatar="(.*?)"/ism', $attributes, $matches);
245 if ($matches[1] != "")
246 $avatar = $matches[1];
249 preg_match("/profile='(.*?)'/ism", $attributes, $matches);
250 if ($matches[1] != "")
251 $profile = $matches[1];
253 preg_match('/profile="(.*?)"/ism', $attributes, $matches);
254 if ($matches[1] != "")
255 $profile = $matches[1];
257 $headline = '<div class="shared_header">';
260 $headline .= '<img src="'.$avatar.'" height="32" width="32" >';
262 $headline .= sprintf(t('<span><a href="%s" target="external-link">%s</a> wrote the following <a href="%s" target="external-link">post</a>:</span>'), $profile, $author, $link);
264 $headline .= "</div>";
266 $text = $headline.'<blockquote class="shared_content">'.trim($match[2])."</blockquote>";
271 // BBcode 2 HTML was written by WAY2WEB.net
272 // extended to work with Mistpark/Friendica - Mike Macgirvin
274 function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
278 // Hide all [noparse] contained bbtags by spacefying them
279 // POSSIBLE BUG --> Will the 'preg' functions crash if there's an embedded image?
281 $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_spacefy',$Text);
282 $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_spacefy',$Text);
283 $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_spacefy',$Text);
286 // Move all spaces out of the tags
287 $Text = preg_replace("/\[(\w*)\](\s*)/ism", '$2[$1]', $Text);
288 $Text = preg_replace("/(\s*)\[\/(\w*)\]/ism", '[/$2]$1', $Text);
290 // Extract the private images which use data url's since preg has issues with
291 // large data sizes. Stash them away while we do bbcode conversion, and then put them back
292 // in after we've done all the regex matching. We cannot use any preg functions to do this.
294 $extracted = bb_extract_images($Text);
295 $Text = $extracted['body'];
296 $saved_image = $extracted['images'];
298 // If we find any event code, turn it into an event.
299 // After we're finished processing the bbcode we'll
300 // replace all of the event code with a reformatted version.
302 $ev = bbtoevent($Text);
305 // Replace any html brackets with HTML Entities to prevent executing HTML or script
306 // Don't use strip_tags here because it breaks [url] search by replacing & with amp
308 $Text = str_replace("<", "<", $Text);
309 $Text = str_replace(">", ">", $Text);
311 // remove some newlines before the general conversion
312 $Text = preg_replace("/\s?\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","[share$1]$2[/share]",$Text);
313 $Text = preg_replace("/\s?\[quote(.*?)\]\s?(.*?)\s?\[\/quote\]\s?/ism","[quote$1]$2[/quote]",$Text);
315 $Text = preg_replace("/\n\[code\]/ism", "[code]", $Text);
316 $Text = preg_replace("/\[\/code\]\n/ism", "[/code]", $Text);
318 // when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
320 $Text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","\n[share$1$2]$3[/share]",$Text);
322 // Convert new line chars to html <br /> tags
324 // nlbr seems to be hopelessly messed up
325 // $Text = nl2br($Text);
330 $Text = str_replace("\r\n","\n", $Text);
332 // removing multiplicated newlines
333 // $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]");
334 // $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]");
337 // $Text = str_replace($search, $replace, $Text);
338 // } while ($oldtext != $Text);
341 $Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);
344 $Text = str_replace(array("\n","\r"), array('',''),$Text);
348 // Set up the parameters for a URL search string
349 $URLSearchString = "^\[\]";
350 // Set up the parameters for a MAIL search string
351 $MAILSearchString = $URLSearchString;
354 // Perform URL Search
356 $Text = preg_replace("/([^\]\='".'"'."]|^)(https?\:\/\/[a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1<a href="$2" target="external-link">$2</a>', $Text);
359 $Text = preg_replace_callback("/\[bookmark\=([^\]]*)\].*?\[\/bookmark\]/ism",'tryoembed',$Text);
361 $Text = preg_replace("/\[bookmark\=([^\]]*)\](.*?)\[\/bookmark\]/ism",'[url=$1]$2[/url]',$Text);
364 $Text = preg_replace_callback("/\[url\]([$URLSearchString]*)\[\/url\]/ism",'tryoembed',$Text);
366 $Text = preg_replace("/\[url\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="external-link">$1</a>', $Text);
367 $Text = preg_replace("/\[url\=([$URLSearchString]*)\](.*?)\[\/url\]/ism", '<a href="$1" target="external-link">$2</a>', $Text);
368 //$Text = preg_replace("/\[url\=([$URLSearchString]*)\]([$URLSearchString]*)\[\/url\]/ism", '<a href="$1" target="_blank">$2</a>', $Text);
370 // we may need to restrict this further if it picks up too many strays
371 // link acct:user@host to a webfinger profile redirector
373 $Text = preg_replace('/acct:(.*?)@(.*?)([ ,])/', '<a href="' . $a->get_baseurl() . '/acctlink?addr=' . "$1@$2"
374 . '" target="extlink" >acct:' . "$1@$2$3" . '</a>',$Text);
376 // Perform MAIL Search
377 $Text = preg_replace("/\[mail\]([$MAILSearchString]*)\[\/mail\]/", '<a href="mailto:$1">$1</a>', $Text);
378 $Text = preg_replace("/\[mail\=([$MAILSearchString]*)\](.*?)\[\/mail\]/", '<a href="mailto:$1">$2</a>', $Text);
380 // Check for bold text
381 $Text = preg_replace("(\[b\](.*?)\[\/b\])ism",'<strong>$1</strong>',$Text);
383 // Check for Italics text
384 $Text = preg_replace("(\[i\](.*?)\[\/i\])ism",'<em>$1</em>',$Text);
386 // Check for Underline text
387 $Text = preg_replace("(\[u\](.*?)\[\/u\])ism",'<u>$1</u>',$Text);
389 // Check for strike-through text
390 $Text = preg_replace("(\[s\](.*?)\[\/s\])ism",'<strike>$1</strike>',$Text);
392 // Check for over-line text
393 $Text = preg_replace("(\[o\](.*?)\[\/o\])ism",'<span class="overline">$1</span>',$Text);
395 // Check for colored text
396 $Text = preg_replace("(\[color=(.*?)\](.*?)\[\/color\])ism","<span style=\"color: $1;\">$2</span>",$Text);
398 // Check for sized text
399 // [size=50] --> font-size: 50px (with the unit).
400 $Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1px;\">$2</span>",$Text);
401 $Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1;\">$2</span>",$Text);
403 // Check for centered text
404 $Text = preg_replace("(\[center\](.*?)\[\/center\])ism","<div style=\"text-align:center;\">$1</div>",$Text);
406 // Check for list text
407 $Text = str_replace("[*]", "<li>", $Text);
409 // Check for style sheet commands
410 $Text = preg_replace_callback("(\[style=(.*?)\](.*?)\[\/style\])ism","bb_cleanstyle",$Text);
412 // Check for CSS classes
413 $Text = preg_replace_callback("(\[class=(.*?)\](.*?)\[\/class\])ism","bb_cleanclass",$Text);
415 // handle nested lists
418 while ((((strpos($Text, "[/list]") !== false) && (strpos($Text, "[list") !== false)) ||
419 ((strpos($Text, "[/ol]") !== false) && (strpos($Text, "[ol]") !== false)) ||
420 ((strpos($Text, "[/ul]") !== false) && (strpos($Text, "[ul]") !== false)) ||
421 ((strpos($Text, "[/li]") !== false) && (strpos($Text, "[li]") !== false))) && (++$endlessloop < 20)) {
422 $Text = preg_replace("/\[list\](.*?)\[\/list\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
423 $Text = preg_replace("/\[list=\](.*?)\[\/list\]/ism", '<ul class="listnone" style="list-style-type: none;">$1</ul>' ,$Text);
424 $Text = preg_replace("/\[list=1\](.*?)\[\/list\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
425 $Text = preg_replace("/\[list=((?-i)i)\](.*?)\[\/list\]/ism",'<ul class="listlowerroman" style="list-style-type: lower-roman;">$2</ul>' ,$Text);
426 $Text = preg_replace("/\[list=((?-i)I)\](.*?)\[\/list\]/ism", '<ul class="listupperroman" style="list-style-type: upper-roman;">$2</ul>' ,$Text);
427 $Text = preg_replace("/\[list=((?-i)a)\](.*?)\[\/list\]/ism", '<ul class="listloweralpha" style="list-style-type: lower-alpha;">$2</ul>' ,$Text);
428 $Text = preg_replace("/\[list=((?-i)A)\](.*?)\[\/list\]/ism", '<ul class="listupperalpha" style="list-style-type: upper-alpha;">$2</ul>' ,$Text);
429 $Text = preg_replace("/\[ul\](.*?)\[\/ul\]/ism", '<ul class="listbullet" style="list-style-type: circle;">$1</ul>' ,$Text);
430 $Text = preg_replace("/\[ol\](.*?)\[\/ol\]/ism", '<ul class="listdecimal" style="list-style-type: decimal;">$1</ul>' ,$Text);
431 $Text = preg_replace("/\[li\](.*?)\[\/li\]/ism", '<li>$1</li>' ,$Text);
434 $Text = preg_replace("/\[th\](.*?)\[\/th\]/sm", '<th>$1</th>' ,$Text);
435 $Text = preg_replace("/\[td\](.*?)\[\/td\]/sm", '<td>$1</td>' ,$Text);
436 $Text = preg_replace("/\[tr\](.*?)\[\/tr\]/sm", '<tr>$1</tr>' ,$Text);
437 $Text = preg_replace("/\[table\](.*?)\[\/table\]/sm", '<table>$1</table>' ,$Text);
439 $Text = preg_replace("/\[table border=1\](.*?)\[\/table\]/sm", '<table border="1" >$1</table>' ,$Text);
440 $Text = preg_replace("/\[table border=0\](.*?)\[\/table\]/sm", '<table border="0" >$1</table>' ,$Text);
442 $Text = str_replace('[hr]','<hr />', $Text);
444 // This is actually executed in prepare_body()
446 $Text = str_replace('[nosmile]','',$Text);
448 // Check for font change text
449 $Text = preg_replace("/\[font=(.*?)\](.*?)\[\/font\]/sm","<span style=\"font-family: $1;\">$2</span>",$Text);
451 // Declare the format for [code] layout
453 // $Text = preg_replace_callback("/\[code\](.*?)\[\/code\]/ism",'stripcode_br_cb',$Text);
455 $CodeLayout = '<code>$1</code>';
456 // Check for [code] text
457 $Text = preg_replace("/\[code\](.*?)\[\/code\]/ism","$CodeLayout", $Text);
459 // Declare the format for [spoiler] layout
460 $SpoilerLayout = '<blockquote class="spoiler">$1</blockquote>';
462 // Check for [spoiler] text
463 // handle nested quotes
465 while ((strpos($Text, "[/spoiler]") !== false) and (strpos($Text, "[spoiler]") !== false) and (++$endlessloop < 20))
466 $Text = preg_replace("/\[spoiler\](.*?)\[\/spoiler\]/ism","$SpoilerLayout", $Text);
468 // Check for [spoiler=Author] text
470 $t_wrote = t('$1 wrote:');
472 // handle nested quotes
474 while ((strpos($Text, "[/spoiler]")!== false) and (strpos($Text, "[spoiler=") !== false) and (++$endlessloop < 20))
475 $Text = preg_replace("/\[spoiler=[\"\']*(.*?)[\"\']*\](.*?)\[\/spoiler\]/ism",
476 "<br /><strong class=".'"spoiler"'.">" . $t_wrote . "</strong><blockquote class=".'"spoiler"'.">$2</blockquote>",
479 // Declare the format for [quote] layout
480 $QuoteLayout = '<blockquote>$1</blockquote>';
482 // Check for [quote] text
483 // handle nested quotes
485 while ((strpos($Text, "[/quote]") !== false) and (strpos($Text, "[quote]") !== false) and (++$endlessloop < 20))
486 $Text = preg_replace("/\[quote\](.*?)\[\/quote\]/ism","$QuoteLayout", $Text);
488 // Check for [quote=Author] text
490 $t_wrote = t('$1 wrote:');
492 // handle nested quotes
494 while ((strpos($Text, "[/quote]")!== false) and (strpos($Text, "[quote=") !== false) and (++$endlessloop < 20))
495 $Text = preg_replace("/\[quote=[\"\']*(.*?)[\"\']*\](.*?)\[\/quote\]/ism",
496 "<br /><strong class=".'"author"'.">" . $t_wrote . "</strong><blockquote>$2</blockquote>",
499 // [img=widthxheight]image source[/img]
500 //$Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '<img src="$3" style="height: $2px; width: $1px;" >', $Text);
501 $Text = preg_replace("/\[img\=([0-9]*)x([0-9]*)\](.*?)\[\/img\]/ism", '<img src="$3" style="width: $1px;" >', $Text);
504 // [img]pathtoimage[/img]
505 $Text = preg_replace("/\[img\](.*?)\[\/img\]/ism", '<img src="$1" alt="' . t('Image/photo') . '" />', $Text);
508 $Text = preg_replace_callback("/\[share(.*?)\](.*?)\[\/share\]/ism","bb_ShareAttributes",$Text);
510 $Text = preg_replace("/\[crypt\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . t('Encrypted content') . '" /><br />', $Text);
511 $Text = preg_replace("/\[crypt=(.*?)\](.*?)\[\/crypt\]/ism",'<br/><img src="' .$a->get_baseurl() . '/images/lock_icon.gif" alt="' . t('Encrypted content') . '" title="' . '$1' . ' ' . t('Encrypted content') . '" /><br />', $Text);
516 $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);
517 $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);
519 $Text = preg_replace_callback("/\[video\](.*?)\[\/video\]/ism", 'tryoembed', $Text);
520 $Text = preg_replace_callback("/\[audio\](.*?)\[\/audio\]/ism", 'tryoembed', $Text);
522 $Text = preg_replace("/\[video\](.*?)\[\/video\]/", '$1', $Text);
523 $Text = preg_replace("/\[audio\](.*?)\[\/audio\]/", '$1', $Text);
526 // html5 video and audio
530 $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '<iframe src="$1" width="' . $a->videowidth . '" height="' . $a->videoheight . '"><a href="$1">$1</a></iframe>', $Text);
532 $Text = preg_replace("/\[iframe\](.*?)\[\/iframe\]/ism", '<a href="$1">$1</a>', $Text);
534 // Youtube extensions
536 $Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
537 $Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
538 $Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
541 $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
542 $Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
543 $Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
546 $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
548 $Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text);
552 $Text = preg_replace_callback("/\[vimeo\](https?:\/\/player.vimeo.com\/video\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
553 $Text = preg_replace_callback("/\[vimeo\](https?:\/\/vimeo.com\/[0-9]+).*?\[\/vimeo\]/ism",'tryoembed',$Text);
556 $Text = preg_replace("/\[vimeo\]https?:\/\/player.vimeo.com\/video\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
557 $Text = preg_replace("/\[vimeo\]https?:\/\/vimeo.com\/([0-9]+)(.*?)\[\/vimeo\]/ism",'[vimeo]$1[/vimeo]',$Text);
560 $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="http://player.vimeo.com/video/$1" frameborder="0" ></iframe>', $Text);
562 $Text = preg_replace("/\[vimeo\]([0-9]+)(.*?)\[\/vimeo\]/ism", "http://vimeo.com/$1", $Text);
564 // $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);
568 $Text = oembed_bbcode2html($Text);
570 // Avoid triple linefeeds through oembed
571 $Text = str_replace("<br style='clear:left'></span><br /><br />", "<br style='clear:left'></span><br />", $Text);
573 // If we found an event earlier, strip out all the event code and replace with a reformatted version.
574 // Replace the event-start section with the entire formatted event. The other bbcode is stripped.
575 // Summary (e.g. title) is required, earlier revisions only required description (in addition to
576 // start which is always required). Allow desc with a missing summary for compatibility.
578 if((x($ev,'desc') || x($ev,'summary')) && x($ev,'start')) {
579 $sub = format_event_html($ev);
581 $Text = preg_replace("/\[event\-summary\](.*?)\[\/event\-summary\]/ism",'',$Text);
582 $Text = preg_replace("/\[event\-description\](.*?)\[\/event\-description\]/ism",'',$Text);
583 $Text = preg_replace("/\[event\-start\](.*?)\[\/event\-start\]/ism",$sub,$Text);
584 $Text = preg_replace("/\[event\-finish\](.*?)\[\/event\-finish\]/ism",'',$Text);
585 $Text = preg_replace("/\[event\-location\](.*?)\[\/event\-location\]/ism",'',$Text);
586 $Text = preg_replace("/\[event\-adjust\](.*?)\[\/event\-adjust\]/ism",'',$Text);
589 // Unhide all [noparse] contained bbtags unspacefying them
590 // and triming the [noparse] tag.
592 $Text = preg_replace_callback("/\[noparse\](.*?)\[\/noparse\]/ism", 'bb_unspacefy_and_trim',$Text);
593 $Text = preg_replace_callback("/\[nobb\](.*?)\[\/nobb\]/ism", 'bb_unspacefy_and_trim',$Text);
594 $Text = preg_replace_callback("/\[pre\](.*?)\[\/pre\]/ism", 'bb_unspacefy_and_trim',$Text);
597 $Text = preg_replace('/\[\&\;([#a-z0-9]+)\;\]/','&$1;',$Text);
598 $Text = preg_replace('/\&\#039\;/','\'',$Text);
599 $Text = preg_replace('/\"\;/','"',$Text);
601 // fix any escaped ampersands that may have been converted into links
602 $Text = preg_replace("/\<(.*?)(src|href)=(.*?)\&\;(.*?)\>/ism",'<$1$2=$3&$4>',$Text);
603 $Text = preg_replace("/\<(.*?)(src|href)=\"[^hfm](.*?)\>/ism",'<$1$2="">',$Text);
606 $Text = bb_replace_images($Text, $saved_image);
608 // Clean up the HTML by loading and saving the HTML with the DOM
609 // Only do it when it has to be done - for performance reasons
611 $doc = new DOMDocument();
612 $doc->preserveWhiteSpace = false;
614 $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8");
616 $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
617 @$doc->loadHTML($doctype."<html><body>".$Text."</body></html>");
619 $Text = $doc->saveHTML();
620 $Text = str_replace(array("<html><body>", "</body></html>", $doctype), array("", "", ""), $Text);
622 $Text = str_replace('<br></li>','</li>', $Text);
624 $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES');
627 call_hooks('bbcode',$Text);