miniBB ® 

miniBB

®
Support Forums
  
 | Start | Register | Search | Statistics | File Bank | Manual |
Official Addons and Solutions miniBB Support Forums / Official Addons and Solutions /  
 

YouTube BB code

 
 
Page  Page 1 of 6:  1  2  3  4  5  6  Next »

Author Paul
Lead Developer 
#1 | Posted: 2 Nov 2006 05:04 
I've provided the short solution in the package available to Download now.

The solution consists of 3 steps:

1) Copy YouTube image button
2) Modify bb_codes.php functions
3) Paste the code for the button in the post form template

Report here if something is wrong... it works on my side.

Author Anonymous
Guest
#2 | Posted: 2 Nov 2006 09:53 
OMG trying right now...

Author tom322
Active Member
#3 | Posted: 2 Nov 2006 10:11 
OMG trying right now...
Does it work as you expected? :)

Author Anonymous
Guest
#4 | Posted: 2 Nov 2006 10:20 
hmm, i cant get it to work. can i have instructions on how to paste the code? i dont understand anything in the bbcodes file. it bb code but it doesn't embed the video.

Author tom322
Active Member
#5 | Posted: 2 Nov 2006 10:37 
can i have instructions on how to paste the code?
highlight the text from , copy, and paste.. check youtube_codes.txt for instructions..

Author Anonymous
Guest
#6 | Posted: 2 Nov 2006 12:34 
i pasted it in the bbcodes file, but i need details on where to paste which parts and if there's anything else i need to change, etc.

Author Paul
Lead Developer 
#7 | Posted: 2 Nov 2006 13:30 
Well, I don't know what's difficult there.

Instruction already says:

edit /forum_folder/bb_codes.php and modify the functions (paste before $msg=preg_replace...)

Can you locate the string beginning with $msg=preg_replace ...?

I don't know how to say it easier.

Author Anonymous
Guest
#8 | Posted: 2 Nov 2006 13:40 
well, i pasted it before that and it resulted in an error, where my forum page wouldnt load. i'll post my bbcode so you can see how it looks, maybe there's an inconsistency.

-------------HOW MY FILE IS RIGHT NOW (NO YOUTUBE ALTERATIONS------

<?php
/*
This file is part of miniBB. miniBB is free discussion forums/message board software, without any warranty. See COPYING file for more details. Copyright (C) 2004 Paul Puzyrev, Sergei Larionov. www.minibb.com
Latest File Update: 2006-Apr-10
*/

$imgsWidth=150; //static width for shrinking images

function enCodeBB($msg,$admin) {

$pattern=array(); $replacement=array();

$pattern[]="/\[url[=]?\](.+?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\1</a>";

$pattern[]="/\[url=((f|ht)tp[s]?:\/\/[^<> \n]+?)\](.*?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\3</a>";

/* New [IMG] tag code - with fixed width */
$pattern[]="/\[imgs\](http:\/\/([^<> \n]+?)\.?(gif|jpg|jpeg|png)?)\[\/imgs\]/i";
$replacement[]='<a href="\\1" target="_blank" rel="nofollow"><img src="\\1" alt="" style="width:'.$GLOBALS['imgsWidth'].'px" /></a>';

/* Old [IMG] tag code - without fixed width. */
$pattern[]="/\[img\](http:\/\/([^<> \n]+?)\.?(gif|jpg|jpeg|png)?)\[\/img\]/i";
$replacement[]='<img src="\\1" alt="" />';

$pattern[]="/\[[bB]\](.+?)\[\/[bB]\]/s";
$replacement[]='<strong>\\1</strong>';

$pattern[]="/\[[iI]\](.+?)\[\/[iI]\]/s";
$replacement[]='<em>\\1</em>';

$pattern[]="/\[[uU]\](.+?)\[\/[uU]\]/s";
$replacement[]='<u>\\1</u>';

$pattern[]="/\[align(left|right|center)](.+?)\[\/align\]/is";
$replacement[]='<div style=\"text-align:\\1\">\\2</div>';

if($admin==1) {

$pattern[]="/\[font(#[A-F0-9]{6})\](.+?)\[\/font\]/is";
$replacement[]='<span style="color:\\1">\\2</font>';

}

if($admin==1 or $GLOBALS['isMod']==1){

$pattern[]="/\[urlc=((f|ht)tp[s]?:\/\/[^<> \n]+?)\](.*?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\">\\3</a>";

}

$msg=preg_replace($pattern, $replacement, $msg);

if(substr_count($msg,'<img')>0) $msg=str_replace('align=""', '', $msg);
if(substr_count($msg,'"nofollow"></a>')>0) $msg=str_replace('"nofollow"></a>', '"nofollow">URL</a>', $msg);

return $msg;
}

//--------------->
function deCodeBB($msg) {

$pattern=array(); $replacement=array();

/* New [IMGs] tag code - with fixed width */
$pattern[]="/<a href=\"([^<>\n\r ]+?)\" target=\"_blank\" rel=\"nofollow\">[ ]<img src=\"(.+?)\" alt=\"\" style=\"width:[0-9]+px\" \/><\/a>/i";
$replacement[]="[imgs]\\1[/imgs]";

/* Old [IMG] tag code - without fixed width. */
$pattern[]="/<img src=\"(.+?)\" alt=\"\" \/>/i";
$replacement[]="[img]\\1[/img]";

$pattern[]="/<a href=\"([^<>\n\r ]+?)\" target=\"(_new|_blank)\"( rel=\"nofollow\")?>(.+?)<\/a>/i";
$replacement[]="[url=\\1]\\4[/url]";

$pattern[]="/<strong>(.+?)<\/strong>/is";
$replacement[]="\\1";

$pattern[]="/<em>(.+?)<\/em>/is";
$replacement[]="\\1";

$pattern[]="/<[uU]>(.+?)<\/[uU]>/s";
$replacement[]="\\1";

$pattern[]="/<span style=\"color:\"(#[A-F0-9]{6})\">(.+?)<\/span>/is";
$replacement[]='[font\\1]\\2[/font]';

$pattern[]="/<div style=\"text-align:(left|right|center)\">(.+?)<\/div>/is";
$replacement[]='[align\\1]\\2[/align]';

$msg=preg_replace($pattern, $replacement, $msg);
$msg=str_replace ('<br />', "\n", $msg);
if(substr_count($msg, '[img\\2]')>0) $msg=str_replace('[img\\2]', '[img]', $msg);

if(function_exists('smileThis')) $msg=smileThis(FALSE,TRUE,$msg);

return $msg;
}

?>

-------------HOW IT WAS WHEN I FOLLOWED THE INSTRUCTIONS------

<?php
/*
This file is part of miniBB. miniBB is free discussion forums/message board software, without any warranty. See COPYING file for more details. Copyright (C) 2004 Paul Puzyrev, Sergei Larionov. www.minibb.com
Latest File Update: 2006-Apr-10
*/

$imgsWidth=150; //static width for shrinking images

function enCodeBB($msg,$admin) {

$pattern=array(); $replacement=array();

$pattern[]="/\[url[=]?\](.+?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\1</a>";

$pattern[]="/\[url=((f|ht)tp[s]?:\/\/[^<> \n]+?)\](.*?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\3</a>";

/* New [IMG] tag code - with fixed width */
$pattern[]="/\[imgs\](http:\/\/([^<> \n]+?)\.?(gif|jpg|jpeg|png)?)\[\/imgs\]/i";
$replacement[]='<a href="\\1" target="_blank" rel="nofollow"><img src="\\1" alt="" style="width:'.$GLOBALS['imgsWidth'].'px" /></a>';

/* Old [IMG] tag code - without fixed width. */
$pattern[]="/\[img\](http:\/\/([^<> \n]+?)\.?(gif|jpg|jpeg|png)?)\[\/img\]/i";
$replacement[]='<img src="\\1" alt="" />';

$pattern[]="/\[[bB]\](.+?)\[\/[bB]\]/s";
$replacement[]='<strong>\\1</strong>';

$pattern[]="/\[[iI]\](.+?)\[\/[iI]\]/s";
$replacement[]='<em>\\1</em>';

$pattern[]="/\[[uU]\](.+?)\[\/[uU]\]/s";
$replacement[]='<u>\\1</u>';

$pattern[]="/\[align(left|right|center)](.+?)\[\/align\]/is";
$replacement[]='<div style=\"text-align:\\1\">\\2</div>';

if($admin==1) {

$pattern[]="/\[font(#[A-F0-9]{6})\](.+?)\[\/font\]/is";
$replacement[]='<span style="color:\\1">\\2</font>';

}

if($admin==1 or $GLOBALS['isMod']==1){

$pattern[]="/\[urlc=((f|ht)tp[s]?:\/\/[^<> \n]+?)\](.*?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\">\\3</a>";

}

enCodeBB() function:

/* YouTube code */
$pattern[]="/\[youtube=http:\/\/www\.youtube\.com\/([\/a-zA-Z0-9-]+)\] /i";
$replacement[]="<object width=\"297\" height=\"245\"><param name=\"movie\" value=\"http://www.youtube.com/\\1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/\\1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"297\" height=\"245\"></embed></object>";
/* --YouTube code */

deCodeBB() function:

/* YouTube code */
$pattern[]="/<object width=\"297\" height=\"245\"><param name=\"movie\" value=\"http:\/\/www\.youtube\.com\/([\/a-zA-Z0-9-]+)\"><\/param><para m name=\"wmode\" value=\"transparent\"><\/param><embed src=\"http:\/\/www\.youtube\.com\/([\/a-zA-Z0-9-]+)\" type=\"application\/x-shockwave-flash\" wmode=\"transparent\" width=\"297\" height=\"245\"><\/embed><\/object>/i";
$replacement[]="[youtube=http://www.youtube.com/\\1]";
/* --YouTube code */

$msg=preg_replace($pattern, $replacement, $msg);

if(substr_count($msg,'<img')>0) $msg=str_replace('align=""', '', $msg);
if(substr_count($msg,'"nofollow"></a>')>0) $msg=str_replace('"nofollow"></a>', '"nofollow">URL</a>', $msg);

return $msg;
}

//--------------->
function deCodeBB($msg) {

$pattern=array(); $replacement=array();

/* New [IMGs] tag code - with fixed width */
$pattern[]="/<a href=\"([^<>\n\r ]+?)\" target=\"_blank\" rel=\"nofollow\">[ ]<img src=\"(.+?)\" alt=\"\" style=\"width:[0-9]+px\" \/><\/a>/i";
$replacement[]="[imgs]\\1[/imgs]";

/* Old [IMG] tag code - without fixed width. */
$pattern[]="/<img src=\"(.+?)\" alt=\"\" \/>/i";
$replacement[]="[img]\\1[/img]";

$pattern[]="/<a href=\"([^<>\n\r ]+?)\" target=\"(_new|_blank)\"( rel=\"nofollow\")?>(.+?)<\/a>/i";
$replacement[]="[url=\\1]\\4[/url]";

$pattern[]="/<strong>(.+?)<\/strong>/is";
$replacement[]="\\1";

$pattern[]="/<em>(.+?)<\/em>/is";
$replacement[]="\\1";

$pattern[]="/<[uU]>(.+?)<\/[uU]>/s";
$replacement[]="\\1";

$pattern[]="/<span style=\"color:\"(#[A-F0-9]{6})\">(.+?)<\/span>/is";
$replacement[]='[font\\1]\\2[/font]';

$pattern[]="/<div style=\"text-align:(left|right|center)\">(.+?)<\/div>/is";
$replacement[]='[align\\1]\\2[/align]';

$msg=preg_replace($pattern, $replacement, $msg);
$msg=str_replace ('<br />', "\n", $msg);
if(substr_count($msg, '[img\\2]')>0) $msg=str_replace('[img\\2]', '[img]', $msg);

if(function_exists('smileThis')) $msg=smileThis(FALSE,TRUE,$msg);

return $msg;
}

?>

Author Anonymous
Guest
#9 | Posted: 2 Nov 2006 20:22 
is something wrong with my bbcodes?

Author lime
Partaker
#10 | Posted: 2 Nov 2006 23:29 
Anonymous
Yes, I think you've misunderstood. You have to put the encode function part into the encode function part and the decode function part into the decode function part, like so:

--- modified bb_codes.php ---
<?php
/*
This file is part of miniBB. miniBB is free discussion forums/message board software, without any warranty. See COPYING file for more details. Copyright (C) 2004 Paul Puzyrev, Sergei Larionov. www.minibb.com
Latest File Update: 2006-Apr-10
*/

$imgsWidth=150; //static width for shrinking images

function enCodeBB($msg,$admin) {

$pattern=array(); $replacement=array();

$pattern[]="/\[url[=]?\](.+?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\1</a>";

$pattern[]="/\[url=((f|ht)tp[s]?:\/\/[^<> \n]+?)\](.*?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\" rel=\"nofollow\">\\3</a>";

/* New [IMG] tag code - with fixed width */
$pattern[]="/\[imgs\](http:\/\/([^<> \n]+?)\.?(gif|jpg|jpeg|png)?)\[\/imgs\]/i";
$replacement[]='<a href="\\1" target="_blank" rel="nofollow"><img src="\\1" alt="" style="width:'.$GLOBALS['imgsWidth'].'px" /></a>';

/* Old [IMG] tag code - without fixed width. */
$pattern[]="/\[img\](http:\/\/([^<> \n]+?)\.?(gif|jpg|jpeg|png)?)\[\/img\]/i";
$replacement[]='<img src="\\1" alt="" />';

$pattern[]="/\[[bB]\](.+?)\[\/[bB]\]/s";
$replacement[]='<strong>\\1</strong>';

$pattern[]="/\[[iI]\](.+?)\[\/[iI]\]/s";
$replacement[]='<em>\\1</em>';

$pattern[]="/\[[uU]\](.+?)\[\/[uU]\]/s";
$replacement[]='<u>\\1</u>';

$pattern[]="/\[align(left|right|center)](.+?)\[\/align\]/is";
$replacement[]='<div style=\"text-align:\\1\">\\2</div>';

if($admin==1) {

$pattern[]="/\[font(#[A-F0-9]{6})\](.+?)\[\/font\]/is";
$replacement[]='<span style="color:\\1">\\2</font>';

}

if($admin==1 or $GLOBALS['isMod']==1){

$pattern[]="/\[urlc=((f|ht)tp[s]?:\/\/[^<> \n]+?)\](.*?)\[\/url\]/i";
$replacement[]="<a href=\"\\1\" target=\"_blank\">\\3</a>";

}

/* YouTube code */
$pattern[]="/\[youtube=http:\/\/www\.youtube\.com\/([\/a-zA-Z0-9-]+)\] /i";
$replacement[]="<object width=\"297\" height=\"245\"><param name=\"movie\" value=\"http://www.youtube.com/\\1\"></param><param name=\"wmode\" value=\"transparent\"></param><embed src=\"http://www.youtube.com/\\1\" type=\"application/x-shockwave-flash\" wmode=\"transparent\" width=\"297\" height=\"245\"></embed></object>";
/* --YouTube code */

$msg=preg_replace($pattern, $replacement, $msg);


if(substr_count($msg,'<img')>0) $msg=str_replace('align=""', '', $msg);
if(substr_count($msg,'"nofollow"></a>')>0) $msg=str_replace('"nofollow"></a>', '"nofollow">URL</a>', $msg);

return $msg;
}

//--------------->
function deCodeBB($msg) {

$pattern=array(); $replacement=array();

/* New [IMGs] tag code - with fixed width */
$pattern[]="/<a href=\"([^<>\n\r ]+?)\" target=\"_blank\" rel=\"nofollow\">[ ]<img src=\"(.+?)\" alt=\"\" style=\"width:[0-9]+px\" \/><\/a>/i";
$replacement[]="[imgs]\\1[/imgs]";

/* Old [IMG] tag code - without fixed width. */
$pattern[]="/<img src=\"(.+?)\" alt=\"\" \/>/i";
$replacement[]="[img]\\1[/img]";

$pattern[]="/<a href=\"([^<>\n\r ]+?)\" target=\"(_new|_blank)\"( rel=\"nofollow\")?>(.+?)<\/a>/i";
$replacement[]="[url=\\1]\\4[/url]";

$pattern[]="/<strong>(.+?)<\/strong>/is";
$replacement[]="\\1";

$pattern[]="/<em>(.+?)<\/em>/is";
$replacement[]="\\1";

$pattern[]="/<[uU]>(.+?)<\/[uU]>/s";
$replacement[]="\\1";

$pattern[]="/<span style=\"color:\"(#[A-F0-9]{6})\">(.+?)<\/span>/is";
$replacement[]='[font\\1]\\2[/font]';

$pattern[]="/<div style=\"text-align:(left|right|center)\">(.+?)<\/div>/is";
$replacement[]='[align\\1]\\2[/align]';

/* YouTube code */
$pattern[]="/<object width=\"297\" height=\"245\"><param name=\"movie\" value=\"http:\/\/www\.youtube\.com\/([\/a-zA-Z0-9-]+)\"><\/param><para m name=\"wmode\" value=\"transparent\"><\/param><embed src=\"http:\/\/www\.youtube\.com\/([\/a-zA-Z0-9-]+)\" type=\"application\/x-shockwave-flash\" wmode=\"transparent\" width=\"297\" height=\"245\"><\/embed><\/object>/i";
$replacement[]="[youtube=http://www.youtube.com/\\1]";
/* --YouTube code */

$msg=preg_replace($pattern, $replacement, $msg);

$msg=str_replace ('<br />', "\n", $msg);
if(substr_count($msg, '[img\\2]')>0) $msg=str_replace('[img\\2]', '[img]', $msg);

if(function_exists('smileThis')) $msg=smileThis(FALSE,TRUE,$msg);

return $msg;
}
?>
--- end modified bb_codes.php ---

I think this is how it's supposed to be done but I haven't tried it myself so try it and see if it works.

Author Anonymous
Guest
#11 | Posted: 3 Nov 2006 09:52 
i did it like you said, and it still didn't work. hmm

Author Paul
Lead Developer 
#12 | Posted: 3 Nov 2006 15:13 
lime, is it workin on your side?

Author lime
Partaker
#13 | Posted: 3 Nov 2006 18:28 
Hi Paul,

I just tried it to see if it works but it doesn't. The button works so that when you click on it the javascript popup asks for the youtube link.

When I tried it with this youtube link:
http://www.youtube.com/watch?v=QmroaYVD_so

the forum post showed this:
[youtube=http://www.youtube.com/watch?v=QmroaYVD_s o]

Notice the space between the s and o? That shows up every time.

Hope this helps you to troubleshoot.

Lime

Author Paul
Lead Developer 
#14 | Posted: 4 Nov 2006 11:40 
Sorry, I thought only about URLs like //www.youtube.com/v/r-DomnRg72Q... so as if they would contain only letters, digits and slashes. So we need to extend the regular expression. I've fixed my code for bb_codes.php, please check out now.

Cool movie, by the way :-) I usually eat pets like this.

Joke :-)

Author Anonymous
Guest
#15 | Posted: 4 Nov 2006 12:54 
hmm it works with the last youtube url you posted

"youtube.com/v/r-DomnRg72Q"

but not with some others.

where has the code been changed?

Page  Page 1 of 6:  1  2  3  4  5  6  Next » 
Official Addons and Solutions miniBB Support Forums / Official Addons and Solutions /
 YouTube BB code
 Share Topic's Link

Your Reply Click this icon to move up to the quoted message


  ?
Post as a Guest, leaving the Password field blank. You could also enter a Guest name, if it's not taken by a member yet. Sign-in and post at once, or just sign-in, bypassing the message's text.


Before posting, make sure your message is compliant with forum rules; otherwise it could be locked or removed with no explanation.

 

 
 
miniBB Support Forums Powered by Forum Software miniBB ® Home  Features  Requirements  Demo  Download  Showcase  Gallery of Arts
Compiler  Premium Extensions  Premium Support  License  Contact Us
Install the Captcha add-on: protect your miniBB-forums from the automated spam and flood.


  ⇑