Youtube, google video embed bbcode..

Submitted by Anonymous on Wed, 10/25/2006 - 03:39
Written by
sarangan

Dear Friends out there..
I just want to ask you about is it possible to make a bbcode to embed google videos and/or youtube videos in usebb forum.

Example of the bbcode will look like this:

Full Url:

[youtube]http://www.youtube.com/watch?v=WoE6J0IHauA[/youtube]

Or Video ID only:

[youtube]WoE6J0IHauA[/youtube]

The original html code looks like this by youtube:


<object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/WoE6J0IHauA"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/WoE6J0IHauA" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>

When we run a new forum as new starter it is difficult to fill our forum with many content. Even when we start a new thread with questions or something like no one will use their time on a new forum because there already many forums with millions of content out there.

I thinks this the only way to cover many people.
Please help me to do this bbcode.

I believe it is easy.

Next-Step

Wed, 10/25/2006 - 18:09

Yes, it is easy. Just open "<root>/sources/functions.php" and seek this code:

// [google=keyword]text[/google]
"#\[google=(.*?)\](.*?)\[/google\]#is" => '<a href="http://www.google.com/search?q="'.$rel.'></a>',

When you find it (ignore whitespaces!) add after the code below:

// [youtube]text[/youtube]
"#\[youtube\](.*?)\[/youtube\]#is" => '<object width="425" height="350"><param name="movie" value="\\\\1"></param><param name="wmode" value="transparent"></param><embed src="\\\\1" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>',

To use it, just type:

[youtube]http://www.youtube.com/v/WoE6J0IHauA[/youtube]

:)

I changed your code, as it was missing some references. Also, it's a bit tricky to post code with backslashes over here, yet another issue that will be resolved with v2.

Hi again.. Thanks for the code hack..
I have tested it today and I am unable to play the video.. The video just showing in the forum and I cannot play it.. Play button is doesn`t work..

Please test it and tell me what the problem is.. Thank you.. ;)

Next-Step

Wed, 10/25/2006 - 22:29

I have tested it before posting ;)

The code works OK, if you click the play button the video will load. At least that happened with my locally hosted retail usebb. Just refresh the page, it might work.

Hi Next Step. It works perfectly in Internet Explorer. The problem is when I tried it on Firefox Browser.
Please check it on Firefox too.. Let me hear what is the problem.

Thank you so much..

Next-Step

Thu, 10/26/2006 - 14:28

I don't know what's wrong here, sorry. I never use IE, I have tested it on Mozilla Firefox 2.

In fact, I wouldn't be surprised if there where any bugs with IE (crappy soft) but in FF it works for sure.

Could you please ask one of your forum users if it works for them? It might be your system configuration.

Thank you for the idea Next Step. It works now.. I have asked all of my forum members to test it and no one have any problem only me who had the problem.

I now have found out that and solved. Thanks again.

I've been working on this tonight and here is what I've done (step by step) using a YouTube Theme option. Which has been resized proportionality down from 560x349 to 480x399 to suite videos being quoted and the narrow width of UseBB.

Instead of entering the full YouTube URL, you only enter the code like this example below (red part is code).

http://www.youtube.com/watch?v=JOddp-nlNvQ

YouTube TAGS are added using a new BBCode button as well added.

====

1: Open "languages/lang_English.php"

Find This:

$lang['Size'] = 'Size';

Add below It:

$lang['YouTube'] = 'YouTube';

Save and upload.

2: Open "sources/functions.php"

Find This:

	/**
* Removes BBCode
*
* @param string $string Text string to clean
* @returns string Cleaned text
*/
function bbcode_clear($string) {

$existing_tags = array('code', 'b', 'i', 'u', 's', 'img', 'url', 'mailto', 'color', 'size', 'google', 'quote');
return preg_replace('#\[/?(?:'.join('|', $existing_tags).')(?:=[^\]]*)?\]#i', '', $string);

Add The Red Part:

/**
* Removes BBCode
*
* @param string $string Text string to clean
* @returns string Cleaned text
*/
function bbcode_clear($string) {

$existing_tags = array('code', 'b', 'i', 'u', 's', 'img', 'url', 'mailto', 'color', 'size', 'youtube', 'google', 'quote');
return preg_replace('#\[/?(?:'.join('|', $existing_tags).')(?:=[^\]]*)?\]#i', '', $string);

Find This:

	function bbcode_prepare($string) {

$string = trim($string);
$existing_tags = array('code', 'b', 'i', 'u', 's', 'img', 'url', 'mailto', 'color', 'size', 'youtube', 'google', 'quote');

Add The Red Part:

function bbcode_prepare($string) {

$string = trim($string);
$existing_tags = array('code', 'b', 'i', 'u', 's', 'img', 'url', 'mailto', 'color', 'size', 'youtube', 'google', 'quote');

Find This:

				// [google=keyword]text[/google]
"#\[google=(.*?)\](.*?)\[/google\]#is" => '<a href="http://www.google.com/search?q=\\1"'.$rel.'>\\2</a>',

Add below It:

				// [youtube]text[/youtube]
"#\[youtube\](.*?)\[/youtube\]#is" => '<iframe width="480" height="299" style="padding: 2px; background-color: #FFF; border: 1px solid silver;" src="http://www.youtube.com/embed/\\1?theme=light&amp;color=red&amp;fs=0" frameborder="0"></iframe>',

Find This:

		$controls = array_merge($controls, array(
array('[color=red]', '[/color]', $lang['Color'], ''),
array('[size=14]', '[/size]', $lang['Size'], '')

Replace code with this:

		$controls = array_merge($controls, array(
array('[color=red]', '[/color]', $lang['Color'], ''),
array('[size=14]', '[/size]', $lang['Size'], ''),
array('[youtube]', '[/youtube]', $lang['YouTube'], '')

Save and upload.

Demo can be seen of working here: YouTube Video mod test added.