Page 1 of 2

embed youtube ration videos to postings

Posted: Tue Dec 04, 2007 12:34 pm
by olli
i tested some php modifications to embed youtube videos in forum postings,
this one is very easy to install and shuold work with mreinfo board.

if it is installed, just add the video URL to the posting, as a plain text whitout BB tags, the mod will automaticly generate the video.

for example:
http://www.youtube-guide.de/forum/viewtopic.php?t=51

i was thinkin about this, as i was readin this posting from kato japan:
viewtopic.php?t=1220

and there is no traffic until the video gets started, just a preview image, its youtube traffic anyway...

----

file to change:

/includes/bbcode.php

Code: Select all

# 
#-----[ FIND ]------------------------------------------ 
# 
   $ret = ' ' . $text; 
# 
#-----[ AFTER, ADD ]------------------------------------------ 
# 

//-- mod : videos in posts ----------------------------------------------------- 
//-- add 
      // standard video table 
      global $lang; 
      $directurl = '<table border="0" cellpadding="0" cellspacing="2"><tr><td align="left"><a href="'; 
      $object = '</td><td align="right"><span class="gensmall"><a href="http://www.phpbb-de.com" target="_blank" title="phpBB">phpBB</a> Plugin</span></td></tr><tr><td colspan="2">'; 
      $tableend = '</td></tr></table>'; 
      // match a google video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://video\.google\.[\w\.]+?/videoplay\?docid=)([\w-]+)([&][\w=+&;-]*)*(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4" target="_blank" class="postlink">' . $lang['Jump_to'] . ' Google Video</a>' . $object . '<object><param name="wmode" value="transparent"></param><embed style="width:400px; height:326px;" id="VideoPlayback" type="application/x-shockwave-flash" wmode="transparent" src="http://video.google.com/googleplayer.swf?docId=\\3" flashvars=""></embed></object>' . $tableend, $ret); 
      // match a youtube video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://)(www\.youtube|youtube)(\.[\w\.]+?/watch\?v=)([\w-]+)([&][\w=+&;%]*)*(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4\\5\\6" target="_blank" class="postlink">' . $lang['Jump_to'] . ' Youtube</a>' . $object . '<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/\\5"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/\\5" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>' . $tableend, $ret); 
      // match a myvideo video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://)(www\.myvideo|myvideo)(\.[\w\.]+?/watch/)([\w]+)(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4\\5" target="_blank" class="postlink">' . $lang['Jump_to'] . ' MyVideo</a>' . $object . '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="470" height="406"><param name="movie" value="http://www.myvideo.de/movie/\\5"></param><param name="wmode" value="transparent"></param><embed src="http://www.myvideo.de/movie/\\5" width="470" height="406" type="application/x-shockwave-flash" wmode="transparent"></embed></object>' . $tableend, $ret); 
      // match a clipfish video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://)(www\.clipfish|clipfish)(\.[\w\.]+?/player\.php\?videoid=)([\w%]+)([&][\w=+&;]*)*(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4\\5\\6" target="_blank" class="postlink">' . $lang['Jump_to'] . ' Clipfish</a>' . $object . '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="464" height="380" id="player" align="middle"><param name="allowScriptAccess" value="sameDomain" /><param name="movie" value="http://www.clipfish.de/videoplayer.swf?as=0&videoid=\\5&r=1" /><param name="wmode" value="transparent"><embed src="http://www.clipfish.de/videoplayer.swf?as=0&videoid=\\5&r=1" width="464" height="380" name="player" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" /></object>' . $tableend, $ret); 
      // match a sevenload video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://[\w.]+?\.sevenload\.com/videos/)([\w]+?)(/[\w-]+)(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4" target="_blank" class="postlink">' . $lang['Jump_to'] . ' Sevenload</a>' . $object . '<object width="425" height="350"><param name="FlashVars" value="slxml=de.sevenload.com"/><param name="movie" value="http://de.sevenload.com/pl/\\3/425x350/swf" /><embed src="http://de.sevenload.com/pl/\\3/425x350/swf" type="application/x-shockwave-flash" width="425" height="350" FlashVars="slxml=de.sevenload.com"></embed></object>' . $tableend, $ret); 
      // match a metacafe video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://)(www\.metacafe|metacafe)(\.com/watch/)([\w]+?)(/)([\w-]+?)(/)(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4\\5\\6\\7" target="_blank" class="postlink">' . $lang['Jump_to'] . ' Metacafe</a>' . $object . '<embed src="http://www.metacafe.com/fplayer/\\5/\\7.swf" width="400" height="345" wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>' . $tableend, $ret); 
      // match a streetfire video URL and replace it 
      $ret = preg_replace("#(^|[\n ])([\w]+?://videos\.streetfire\.net/.*?/)([\w-]+?)(\.htm)(^[\t <\n\r\]\[])*#is", '\\1' . $directurl . '\\2\\3\\4" target="_blank" class="postlink">' . $lang['Jump_to'] . ' Streetfire</a>' . $object . '<embed src="http://videos.streetfire.net/vidiac.swf" FlashVars="video=\\3" quality="high" bgcolor="#ffffff" width="428" height="352" name="ePlayer" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed>' . $tableend, $ret); 
//-- fin mod : videos in posts -------------------------------------------------

Posted: Tue Dec 04, 2007 12:39 pm
by kman
Great suggestion, olli. Thanks for doing all the legwork on this. Let me check it out and see about getting the code integrated.

Posted: Tue Dec 04, 2007 12:49 pm
by olli

Posted: Tue Dec 04, 2007 12:53 pm
by kman
When searching for parts of that code, I also found this post:

http://www.phpbb-de.com/videos-in-beitraegen-t536.html

Do those look like the same thing to you? The link above has a little more detail about installation and seems to point to changing a few more things.

Posted: Tue Dec 04, 2007 12:56 pm
by kman
Ah...nevermind that last message. I ran that forum thread through babelfish so I could actually understand it :-) and it looks like the code you posted is what I need for regular phpBB.

Posted: Tue Dec 04, 2007 1:02 pm
by olli
cool, xD

best thing is flash animation after ending the video, on youtube they have just a share and replay button, this one is much better...

Posted: Tue Dec 04, 2007 1:05 pm
by kman
Seems to work ok. I just need to make a few small changes - for starters, it's not working with jp.youtube.com.

Posted: Tue Dec 04, 2007 1:17 pm
by olli
Really?

looks like i have to do the same thing then, to get it running on de.youtube.com

Posted: Tue Dec 04, 2007 1:25 pm
by kman
Here's all I changed to fix it:

On the second line of the YouTube section:

from: (www\.youtube|youtube)

to: (www\.youtube|youtube|jp\.youtube|de\.youtube)

I'm basically just adding a couple of new OR conditions. There's probably a cleaner way of doing this, but I didn't want to hack it up too much and break something else.

Posted: Tue Dec 04, 2007 1:28 pm
by kman
Ok guys - the testing is done and it seems to work.

In case you were wondering, this change only affects new posts - or edited older posts. So if you have an old post with a video link in it and you want it display the videos inline, just click "Edit" and then "Save" and it should work.

Thanks again, olli!