DevNetwork Forums

The Developer's Network
It is currently Mon Feb 08, 2010 10:11 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: youtube auto-embedding for phpBB
PostPosted: Fri Dec 22, 2006 2:46 pm 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
I just wrote some code for a phpBB installation (I guess it's a MOD, sort-of) that I thought people could pitch-in to if they find it useful:

This MOD replaces URLs to youTube videos with their embedded counterparts.

Edit 'includes/bbcode.php' and find:
  1. function make_clickable($text)
  2. {
  3.     $text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
  4.  
  5.     // pad it with a space so we can match things at the start of the 1st line.
  6.     $ret = ' ' . $text;

then add:

  1.    // youtube code..
  2.     $ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://(www\.)?youtube\.com/watch\?v=([a-zA-Z0-9\-_]+)(</a>)?#im",' <!-- BEGIN youtube --><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$4"></param><embed src="http://www.youtube.com/v/$4" type="application/x-shockwave-flash" width="425" height="350"></embed></object><br /><a href="http://youtube.com/watch?v=$4" target="_blank">http://youtube.com/watch?v=$4</a><!-- END youtube -->', $ret);

This works with plaintext URLs and already linked URLs, and with or without the "www".

If anyone wants to improve this code, my suggestion would be to not embed the video if it's quoted.

Any takers?

Maybe after we're done here one of the mods would drop this in the snippets section?

Cheers,
Kieran


Last edited by Kieran Huggins on Sat Feb 02, 2008 6:19 am, edited 1 time in total.

Top
 Profile E-mail  
 
 Post subject:
PostPosted: Fri Dec 22, 2006 8:42 pm 
Offline
DevNet Master
User avatar

Joined: Mon Oct 25, 2004 9:29 pm
Posts: 3699
Location: New Jersey, US
If someone linked to the youtube video, they probably want it to stay a link. This should be implemented as a custom BBcode tag.

_________________
HTML Purifier for Standards-Compliant HTML Filtering


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 9:53 am 
Offline
Forum Newbie

Joined: Sat Dec 30, 2006 9:46 am
Posts: 3
Hi,
youtube auto-embedding is perfect for me. Could you write a similar code for google videos auto-embedding?
Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 5:13 pm 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
I'll make you a deal - if you try to write it and post it here, I'll help fix it if it's broken 8)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 7:47 pm 
Offline
Forum Newbie

Joined: Sat Dec 30, 2006 9:46 am
Posts: 3
:D OK I've tried

$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://video.google.com/videoplay\?docid=([a-zA-Z0-9\-_]+)(</a>)?#im",'<!-- BEGIN GVideo --><object width="425" height="350"><param name="movie" value="http://video.google.com/googleplayer.swf?docId=$4"></param><embed src="http://video.google.com/googleplayer.swf?docId=$4" type="application/x-shockwave-flash" width="425" height="350"></embed></object></p><!-- END Gvideo -->', $ret);


The first part is ok, I can see the player, but don't know how to link a movie... :?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 8:06 pm 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
not quite.. if you check out google's embed code, it's quite different from youtube:

  1. // google video code...
  2. $ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://video.google.com/videoplay\?docid=([0-9]+)(</a>)?#im",'<!-- BEGIN GVideo --><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.com/googleplayer.swf?docId=$3"> </embed><br /><a href="http://video.google.com/videoplay?docid=$3" target="_blank">http://video.google.com/videoplay?docid=$3</a><!-- END Gvideo -->', $ret);

also, the "docid" is only numeric in GV's case


Last edited by Kieran Huggins on Sat Feb 02, 2008 6:19 am, edited 1 time in total.

Top
 Profile E-mail  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 8:26 pm 
Offline
Forum Newbie

Joined: Sat Dec 30, 2006 9:46 am
Posts: 3
Great!
Thank you very much


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 30, 2006 9:33 pm 
Offline
Forum Contributor

Joined: Thu Jul 20, 2006 11:00 am
Posts: 425
freebies for all!.
Would be cool for a newer version that you just have to select from which video hosting site your linking (like the 5 biggest one)
instead of having 5 mods

_________________
thiscatis? This Cat is A Landmine - 65daysofstatic


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 31, 2006 5:11 am 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
thiscatis wrote:
freebies for all!.
Would be cool for a newer version that you just have to select from which video hosting site your linking (like the 5 biggest one)
instead of having 5 mods

You can just paste these next to one another in 'includes/bbcode.php'... I don't know how to make it any simpler :-)


Top
 Profile E-mail  
 
 Post subject:
PostPosted: Sun Mar 25, 2007 8:36 am 
Offline
Forum Newbie

Joined: Sun Mar 25, 2007 7:58 am
Posts: 1
Thanks for the code.
little modifications for your sripts so it works with al language codes. for my with video.google.nl


[php] // google video code...
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://video.google.([a-z]+)/videoplay\?docid=([0-9\-_]+)(</a>)?#im",'<embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" src="http://video.google.$3/googleplayer.swf?docId=$4"> </embed><br /><a href="http://video.google.$3/videoplay?docid=$4" target="_blank">http://video.google.$3/videoplay?docid=$4</a>, $ret);[/php]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 26, 2007 2:42 am 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
a welcome addition ;-) Thanks tvleeuwen

_________________
My name is Kieran... and I heart jQuery and this real-time regex evaluator // DevNet Awards '07/08: Funniest /*looking*/ // 基兰既不说话也不写着中文
Image


Top
 Profile E-mail  
 
 Post subject: Re: youtube auto-embedding for phpBB
PostPosted: Fri Apr 20, 2007 6:15 am 
Offline
Forum Newbie

Joined: Fri Apr 20, 2007 6:08 am
Posts: 2
Kieran Huggins wrote:
I just wrote some code for a phpBB installation (I guess it's a MOD, sort-of) that I thought people could pitch-in to if they find it useful:

This MOD replaces URLs to youTube videos with their embedded counterparts.

Edit 'includes/bbcode.php' and find:
[php]function make_clickable($text)
{
$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);

// pad it with a space so we can match things at the start of the 1st line.
$ret = ' ' . $text;[/php]
then add:

[php] // youtube code..
$ret = preg_replace("#(^|[\n ]|<a(.*?)>)http://(www\.)?youtube\.com/watch\?v=([a-zA-Z0-9\-_]+)(</a>)?#im",' <!-- BEGIN youtube --><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/$4"></param><embed src="http://www.youtube.com/v/$4" type="application/x-shockwave-flash" width="425" height="350"></embed></object><br /><a href="http://youtube.com/watch?v=$4" target="_blank">http://youtube.com/watch?v=$4</a><!-- END youtube -->', $ret);[/php]
This works with plaintext URLs and already linked URLs, and with or without the "www".

If anyone wants to improve this code, my suggestion would be to not embed the video if it's quoted.

Any takers?

Maybe after we're done here one of the mods would drop this in the snippets section?

Cheers,
Kieran


Hello Kieran,

I changed the bbcode.php, but I don't see the videoplayer of youtube on my page.
What am I doing wrong?
http://tina-turner.nl/phpBB2/viewtopic.php?p=324#324

Johanna


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 20, 2007 9:15 am 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
seems to be working...

_________________
My name is Kieran... and I heart jQuery and this real-time regex evaluator // DevNet Awards '07/08: Funniest /*looking*/ // 基兰既不说话也不写着中文
Image


Top
 Profile E-mail  
 
 Post subject: Works now
PostPosted: Fri Apr 20, 2007 9:36 am 
Offline
Forum Newbie

Joined: Fri Apr 20, 2007 6:08 am
Posts: 2
Kieran Huggins wrote:
seems to be working...


Hello Kieran,

Yes I just had to insert the complete embed code. I thought I only had to write down an url.
Thanks,

Johanna :D


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 21, 2007 2:23 am 
Offline
DevNet Master
User avatar

Joined: Wed Dec 06, 2006 5:14 pm
Posts: 3598
Location: Toronto, Canada
I just type in the URL... the code above should transform it into the embed code

_________________
My name is Kieran... and I heart jQuery and this real-time regex evaluator // DevNet Awards '07/08: Funniest /*looking*/ // 基兰既不说话也不写着中文
Image


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group