phpBB mods: bbcode for ifilm, youtube and google video embedding
I wanted to be able to embed videos from various services into forum posts on CoopersGuns Health, Fitness & BodyBuilding Forums so I decided to have a play with modifying the bbcode processor and here’s what I’ve come up with..
Modification instructions
Make the following modifications to forum/includes/bbcode.php
- Find the bbencode_first_pass function
- Locate the end of the function
// Remove our padding from the string..
return substr($text, 1);
- Add the following just before the above:
// [ifilm] and [/ifilm]
$text = preg_replace("#\[ifilm=([0-9]+[,][0-9]+[,][0-9]+)\](.*?)\[/ifilm\]#si", "[ifilm=\\1:$uid]\\2[/ifilm:$uid]", $text);
// [youtube] and [/youtube]
$text = preg_replace("#\[youtube=([0-9]+[,][0-9]+[,][0-9a-z\-_]+)\](.*?)\[/youtube\]#si", "[youtube=\\1:$uid]\\2[/youtube:$uid]", $text);
// [gvid] and [/gvid]
$text = preg_replace("#\[gvid=([0-9]+[,][0-9]+[,][0-9a-z\-_]+)\](.*?)\[/gvid\]#si", "[gvid=\\1:$uid]\\2[/gvid:$uid]", $text);
- Find the bbencode_second_pass function
- Locate the part that deals with [QUOTE]
// [QUOTE] and [/QUOTE] for posting replies with quote, or just for quoting stuff.
$text = str_replace("[quote:$uid]", $bbcode_tpl['quote_open'], $text);
$text = str_replace("[/quote:$uid]", $bbcode_tpl['quote_close'], $text);
- Add the following code after the above:
// [ifilm] and [/ifilm]
$text = preg_replace("#\[ifilm=([0-9]+)[,]([0-9]+)[,]([0-9]+):$uid\](.*?)\[/ifilm:$uid\]#si", "<embed allowScriptAccess=\"never\" width=\"\\1\" height=\"\\2\" src=\"http://www.ifilm.com/efp\" quality=\"high\" bgcolor=\"000000\" name=\"efp\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" flashvars=\"flvBaseClip=\\3\""."[/ifilm:$uid]", $text);
$text = str_replace("[/ifilm:$uid]", " />", $text);
// [youtube] and [/youtube]
$text = preg_replace("#\[youtube=([0-9]+)[,]([0-9]+)[,]([0-9a-z\-_]+):$uid\](.*?)\[/youtube:$uid\]#si", "<object width=\"\\1\" height=\"\\2\"><param name=\"movie\" value=\"http://www.youtube.com/v/\\3\"></param><embed src=\"http://www.youtube.com/v/\\3\" type=\"application/x-shockwave-flash\" width=\"\\1\" height=\"\\2\"></embed></object>"."[/youtube:$uid]", $text);
$text = str_replace("[/youtube:$uid]", "", $text);
// [gvid] and [/gvid]
$text = preg_replace("#\[gvid=([0-9]+)[,]([0-9]+)[,]([0-9a-z\-_]+):$uid\](.*?)\[/gvid:$uid\]#si", "<embed style=\"width:\\1px; height:\\2px;\" id=\"VideoPlayback\" type=\"application/x-shockwave-flash\" src=\"http://video.google.com/googleplayer.swf?docId=\\3&hl=en\"> </embed>"."[/gvid:$uid]", $text);
$text = str_replace("[/gvid:$uid]", "", $text);
- Save your changes to bbcode.php and upload the modified file (if you downloaded it to modify)
That’s it.. you can now embed iFilm, YouTube and Google Video videos into your forum posts
Usage
The syntax is similar for all three:
[ifilm=width,height,id]description[/ifilm]
[youtube=width,height,id]description[/youtube]
[gvid=width,height,id]description[/gvid]
Example:
CoopersGuns Health, Fitness & BodyBuilding Forums Post
October 18th, 2006 at 10:17 pm
Thanks for the great tip! My users have been asking for a way to put videos on the forum for a long time. This has worked great for us!
October 19th, 2006 at 10:34 pm
what would be an example of how the Syntax should look with a YouTube Video.
Thanks
November 4th, 2006 at 1:57 am
Hey all
Does anybody know how to switch off the data execution prevention feature in Windows XP?
November 23rd, 2006 at 10:42 pm
Hey guys,
I have an iMac G5 running tiger 10.4.7 and I an having a wierd problem. Whenever I go to a site that has an embedded youtube, flash or some kind of video, there is no sound. If it a quicktime file there is no problem. There is not sound no matter what broswer I use, firefox, camino, safari, or shiira. And keep in mind that about a week ago I was not having this issue.
Help Would be awesome
Thanks!
December 20th, 2006 at 9:22 pm
Heya Clark, here’s an example:
http://www.youtube.com/watch?v=Z_TvkB1-XeE
The embed code is important, holds what you need.
The code from the above mod, for the above link, would be:
[youtube=424,350,Z_TvkB1-XeE]Unicorn spotted in New York?[/youtube]
Hope that helps!
January 21st, 2007 at 6:27 pm
Is that possible to expand your mod to play full screen google or youtube video ?
January 24th, 2007 at 12:34 pm
I can’t get this to work, is this compatible with v2.0.22 of the phpBB code?
March 18th, 2007 at 1:46 pm
doesnt work
April 11th, 2007 at 7:44 pm
Wow you don’t understand how long I have been looking for a simple youtube mod like this!! Thank you thank you thank you!! this is straight foward to the point AND ONLY TOW STEPS!!. All the other sites have broken links to mods and crappy directions! anyway thought I would send you some props for this entry so thank you once again!!!
May 6th, 2007 at 11:52 am
Hey do you know how to modify the code so users will only have to put the url given in youtube inside [youtube] tags?
for example,
[youtube]http://www.youtube.com/watch?v=Z_TvkB1-XeE[/youtube]
instead of specifying the width,, height and all? that will be better
June 16th, 2007 at 7:51 pm
hi i want to stream flash videos from my phpbb, if you can help email stevepip888@aol.com
June 26th, 2007 at 3:35 pm
Doesn’t work.
Beforeyougopostal.com
November 22nd, 2007 at 5:22 pm
“Hey do you know how to modify the code so users will only have to put the url given in youtube inside [youtube] tags?”
Here is the code for utube without size parameters.
// [youtube] and [/youtube]
$text = preg_replace(”#\[youtube=([0-9a-z\-_]+):$uid\](.*?)\[/youtube:$uid\]#si”, “”.”[/youtube:$uid]“, $text);
$text = str_replace(”[/youtube:$uid]“, “”, $text);
// [youtube] and [/youtube]
$text = preg_replace(”#\[youtube=([0-9]+[,][0-9]+[,][0-9a-z\-_]+)\](.*?)\[/youtube\]#si”, “[youtube=\\1:$uid]\\2[/youtube:$uid]“, $text);
So you would enter it like this:
[youtube=Z_TvkB1-XeE]unicorn[/youtube]
still working on the other variatons…
November 22nd, 2007 at 5:23 pm
disregard above post…it won’t let me display the code correctly!
October 12th, 2008 at 11:33 am
You should authorized “embed” and “object” html tag in your forum configuration :p