vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   Mini Mods - Auto Youtube Link-Converter (https://vborg.vbsupport.ru/showthread.php?t=261296)

Disasterpiece 03-31-2011 10:00 PM

Auto Youtube Link-Converter
 
1 Attachment(s)
So basically this is a total easy-to-implement plugin, which converts standard youtube links to video-embeds on the fly without urging users to use the video-button because I think it is unnecessary.


On post display, the plugin checks if the post contains at least 1 youtube link in the form of
Code:

<a href="http://www.youtube.com/watch?v=somecode&some=params">http://www.youtube.com/watch?v=somecode&some=params</a>
and converts them using the default vB video bbcode parser.

Code can be modified to fit your needs, altough there shouldn't be much to add.
If you're the special performance-freak, I'm curious if you can enhance data/query-performance. So let me know if you do.

INSTALL:

- Download attached XML File and import it as an addon.

Code:

Changes since 1.3:
- Now works properly on iPad

Changes since 1.2:
- Supports mobile devices with fallback-display if browser doesn't support flash/embed codes
- Allows the user to specify the above mentioned replacement code for mobile browsers
- Minor improvements & Fixes

Changes since 1.1:
- Moved regular expression and index position into admincp settings to allow easier changing in the future
- supports new youtube link format: "http://youtu.be/*somevideocode*"

Changes since 1.0: (or: why should I download that mod again?)
- Added Link parsing in post-preview mode and in post reviewbits (the latest posts you see under the new reply form)


Now every post containing youtube-links should display the embedded video instead.
Works with any number of youtube-links and any kind of text surrounding them.

Let me know if you have trouble/questions.

voglermc 04-01-2011 04:55 PM

Sweet! Nominated!

fragov 04-01-2011 05:06 PM

You da man! :)

fragov 04-01-2011 06:00 PM

How it can be changed to replace link to bbcode on newpost & newreply not in quotes?

New Joe 04-02-2011 03:30 AM

Works as it says.

Sforums 04-02-2011 12:14 PM

Great job!
5 star and nominated.

grc 04-02-2011 01:21 PM

10 second install! Works as described. Good job!

I wonder if the code can be modified to do the same with links to Picasa web albums, presenting them as slide shows?

Disasterpiece 04-02-2011 07:40 PM

@grc: sure it can. It basically checks for an occurence in the html-string, grabs a part of it (in this case the video-id) and replaces it with another string.
If you can give me specific information on how that picasa thing is formed, I can write you a plugin for that purpose.

thr45h3r 04-02-2011 07:55 PM

Thanks works great

Gemma 04-02-2011 10:12 PM

Thanks a lot :)

SpeedyHire 04-03-2011 08:19 AM

nice one, thanks

ProFifaLeagues 04-03-2011 09:52 AM

Will this work below 4.1.2????

Disasterpiece 04-03-2011 05:18 PM

Quote:

Originally Posted by rammieone (Post 2180354)
Will this work below 4.1.2????

It should work, yes. Only one way to find out :P
I started and developed the plugin on vB 4.1.2 so I can't guarantee it works with older versions.

zelnik 04-03-2011 05:41 PM

brilliant thanks

grc 04-03-2011 05:43 PM

Quote:

Originally Posted by Disasterpiece (Post 2180193)
@grc: sure it can. It basically checks for an occurence in the html-string, grabs a part of it (in this case the video-id) and replaces it with another string.
If you can give me specific information on how that picasa thing is formed, I can write you a plugin for that purpose.

Cool - here's a link to a slide show:

PHP Code:

<embed type="application/x-shockwave-flash" src="https://picasaweb.google.com/s/c/bin/slideshow.swf" width="400" height="267" flashvars="host=picasaweb.google.com&hl=en_US&feat=flashalbum&RGB=0x000000&feed=https%3A%2F%2Fpicasaweb.google.com%2Fdata%2Ffeed%2Fapi%2Fuser%2Fnazarenealvin%2Falbumid%2F5440810094021987121%3Falt%3Drss%26kind%3Dphoto%26hl%3Den_US" pluginspage="http://www.macromedia.com/go/getflashplayer"></embed

username: nazarenealvin
albumname: 2010NewCross

Is it do-able?

Disasterpiece 04-03-2011 06:30 PM

Quote:

Originally Posted by grc (Post 2180484)
Cool - here's a link to a slide show:

PHP Code:

https://picasaweb.google.com/nazarenealvin/2010NewCross?feat=directlink 

username: nazarenealvin
albumname: 2010NewCross

Is it do-able?

I don't see any kind of embed-code. How does it work?

grc 04-03-2011 06:54 PM

Quote:

Originally Posted by Disasterpiece (Post 2180504)
I don't see any kind of embed-code. How does it work?

Sorry, grabbed the wrong code - I just edited the post to include the embed code. If it's too much, no worries - thanks for thinking about it.

BadgerDog 04-03-2011 08:21 PM

Great idea .... :up:

Just installed and for testing on 4.04pl1 ....

Seems to be working just fine .... :)

Really valuable addition to our site and saves me a lot of time checking posts and converting the manual links to BBCode [video] links .... :)

Slick the way it does the conversion during the "submit" part of the post creation or editing ...

Thanks for this ...

Regards,
Doug

ProFifaLeagues 04-03-2011 08:33 PM

Quote:

Originally Posted by Disasterpiece (Post 2180475)
It should work, yes. Only one way to find out :P
I started and developed the plugin on vB 4.1.2 so I can't guarantee it works with older versions.


Installed and working fine on 4.0.6
Thanks mate saves a lot of work for us

Disasterpiece 04-05-2011 01:16 AM

Just updated with newer version.

I missed the conversion in post preview and the reviewbits, so here they are.

Same procedure, now there are 3 plugins. You can enable/disable the plugins by itself if you want to disable a specific feature.

Juggernaut 04-05-2011 01:40 AM

Really useful mod :D

Goodfather 04-05-2011 09:46 AM

Installed and working fine on 4.1.2
thanks :)

Nominated!

YkudzA 04-05-2011 12:11 PM

installed and nominated !

Brandon Sheley 04-05-2011 04:05 PM

works as it should on 4.1.2

thanks :)

[high]* Brandon Sheley clicks install[/high]

BadgerDog 04-05-2011 05:55 PM

Just installed 1.1 update and testing on 4.04pl1 .... :)

Appears to be operating just fine ...

I like smart and intuitive add-ons that substitute for unnecessary steps for the end user and this is one of those ... :up:

Regards,
Doug

Edit: oooppps.... found a problem. Have started to get emails from members saying that they're seeing YouTube videos being duplicated in just some posts, primarily older ones. Traced cause to a conflict with a mod we've been using for 5 years which is a BBCode [youtube]xxx[/youtube] add-on to handle YouTube videos even before vb4 did with their [video]xxx[/video] button.

Any way to have this mod ignore that old mod (too many posts for us to change) and not translate, adding a second duplicate video? .. or, can we make an SQL pass on the database and change all posts to something else to be compatible with his mod?

Rofo 04-06-2011 12:34 AM

Works fairly well. I've noticed some YouTube links won't auto embedd. Example,

http://www.youtube.com/user/tdwpplaya - Will no embed automatically

http://www.youtube.com/watch?v=0ABGIJwiGBc - Will embed automatically.

Is it because the first link is "user"/ and not watch?v= ?

Either way, very nice Mod. This is the kinda stuff I don't understand why is not built in to the vB software. Clicking the [video] button is completely (or should be) unnecessary!

Disasterpiece 04-06-2011 01:11 AM

1 Attachment(s)
Quote:

Originally Posted by BadgerDog (Post 2181198)
Edit: oooppps.... found a problem. Have started to get emails from members saying that they're seeing YouTube videos being duplicated in just some posts, primarily older ones. Traced cause to a conflict with a mod we've been using for 5 years which is a BBCode [youtube]xxx[/youtube] add-on to handle YouTube videos even before vb4 did with their [video]xxx[/video] button.

Any way to have this mod ignore that old mod (too many posts for us to change) and not translate, adding a second duplicate video? .. or, can we make an SQL pass on the database and change all posts to something else to be compatible with his mod?

Funny that you mention that, I had exactly the same problem. We didn't use video tags, just the [youtube=title]videoid[/youtube] thingy which caused above mentioned problem.
I made a script for myself which changed all [youtube]...[/youtube] tags to full urls like
http://www.youtube.com/watch?v=*videoid*
to solve this problem. I attached it below.

USE AT YOUR OWN RISK!
Backup your database before running the query, disabling your forum might be a good idea, place it anywhere and delete it afterwards.
Edit the file before you run it with your database credentials and modify the table-prefix/name accordingly. Hit the "continue" link until the script doesn't make any more queries.
Oh and I had troubles with singlequotes in postings which messed up my query, so I simply escaped it. I didn't discover any problems with that, keep in mind that if your language makes excessive use of the ' character, you might want to find a way around that, I did not.

Will only work with old youtube tags in the form of:
Code:

[youtube]6mXM-oGggrM[/youtube]
and:
Code:

[youtube="hey check this out!"]6mXM-oGggrM[/youtube]
If you used a different tag, send me a PM and I try to help you out with the correct replacement.


Quote:

Originally Posted by Rofo (Post 2181367)
Works fairly well. I've noticed some YouTube links won't auto embedd. Example,

http://www.youtube.com/user/tdwpplaya - Will no embed automatically

http://www.youtube.com/watch?v=0ABGIJwiGBc - Will embed automatically.

Is it because the first link is "user"/ and not watch?v= ?

Either way, very nice Mod. This is the kinda stuff I don't understand why is not built in to the vB software. Clicking the [video] button is completely (or should be) unnecessary!

Thanks for your feedback :)

The user-link will only display the profile page of the user, not a specific video. Which means, if that particlular user uploads a new video, the new video will be shown on this site. I'm not aware if the vB video tag translates this kind of url too, I find it rather unintuitive and uncommon and due to the lack of a video-ID in the url, it's not really supposed to be embedded :p

Rofo 04-06-2011 01:48 AM

Quote:

Originally Posted by Disasterpiece (Post 2181376)
Funny that you mention that, I had exactly the same problem. We didn't use video tags, just the [youtube=title]videoid[/youtube] thingy which caused above mentioned problem.
I made a script for myself which changed all [youtube]...[/youtube] tags to full urls like
http://www.youtube.com/watch?v=*videoid*
to solve this problem. I attached it below.

USE AT YOUR OWN RISK!
Backup your database before running the query, disabling your forum might be a good idea, place it anywhere and delete it afterwards.
Edit the file before you run it with your database credentials and modify the table-prefix/name accordingly. Hit the "continue" link until the script doesn't make any more queries.
Oh and I had troubles with singlequotes in postings which messed up my query, so I simply escaped it. I didn't discover any problems with that, keep in mind that if your language makes excessive use of the ' character, you might want to find a way around that, I did not.

Will only work with old youtube tags in the form of:
Code:

[youtube]6mXM-oGggrM[/youtube]
and:
Code:

[youtube="hey check this out!"]6mXM-oGggrM[/youtube]
If you used a different tag, send me a PM and I try to help you out with the correct replacement.



Thanks for your feedback :)

The user-link will only display the profile page of the user, not a specific video. Which means, if that particlular user uploads a new video, the new video will be shown on this site. I'm not aware if the vB video tag translates this kind of url too, I find it rather unintuitive and uncommon and due to the lack of a video-ID in the url, it's not really supposed to be embedded :p

Gotcha. Not really that big of a deal, as most YouTube links don't have that User/. Thank you for the Mod, this was a much needed one. Now if some of the other videos would auto embed!

Installed/Rated/Voted

GeorgeEcuador 04-06-2011 02:38 AM

Functional v4.03.. Fine... Installed..

BadgerDog 04-06-2011 01:10 PM

Quote:

Originally Posted by Disasterpiece (Post 2181376)
Funny that you mention that, I had exactly the same problem. We didn't use video tags, just the [youtube=title]videoid[/youtube] thingy which caused above mentioned problem.
I made a script for myself which changed all [youtube]...[/youtube] tags to full urls like
http://www.youtube.com/watch?v=*videoid*
to solve this problem. I attached it below.

USE AT YOUR OWN RISK!
Backup your database before running the query, disabling your forum might be a good idea, place it anywhere and delete it afterwards.
Edit the file before you run it with your database credentials and modify the table-prefix/name accordingly. Hit the "continue" link until the script doesn't make any more queries.
Oh and I had troubles with singlequotes in postings which messed up my query, so I simply escaped it. I didn't discover any problems with that, keep in mind that if your language makes excessive use of the ' character, you might want to find a way around that, I did not.

Will only work with old youtube tags in the form of:
Code:

[youtube]6mXM-oGggrM[/youtube]
and:
Code:

[youtube="hey check this out!"]6mXM-oGggrM[/youtube]
If you used a different tag, send me a PM and I try to help you out with the correct replacement.

Thanks partner ... appreciate that ... :)

Those two BBCodes are EXACTLY the ones that we used for years, so there's a LOT of old YouTube links with them.

So, I simply execute that PHP file you attached and it will go through our entire database, altering them to something else?

I have no database prefix .... it just shows in the config file for vBulletin as ' ' with no prefix in between the single quotes. Just leave it as two single quotes in your PHP file?

BTW, my language is English ..

Regards,
Doug

Disasterpiece 04-06-2011 01:26 PM

Quote:

So, I simply execute that PHP file you attached and it will go through our entire database, altering them to something else?
Correct. Keep in mind that the execution starts the moment you open the url in your browser. So enter the database credentials before you run the url.

Quote:

I have no database prefix .... it just shows in the config file for vBulletin as ' ' with no prefix in between the single quotes. Just leave it as two single quotes in your PHP file?
Righto, just leave it as '' then. (without space)

Quote:

BTW, my language is English ..
I know, just wanted to point that out in case other users want to use the script as well :)

BadgerDog 04-06-2011 08:55 PM

Quote:

Originally Posted by Disasterpiece (Post 2181532)
Correct. Keep in mind that the execution starts the moment you open the url in your browser. So enter the database credentials before you run the url.

Righto, just leave it as '' then. (without space)

Understood ... will try this out after a full backup and advise ... :)

Regards,
Doug

BadgerDog 04-07-2011 02:58 PM

Quote:

Originally Posted by BadgerDog (Post 2181678)
Understood ... will try this out after a full backup and advise ... :)

Regards,
Doug

Hi.... :)

Entered our specific information, backed up and then executed PHP file.

All it came back with was the phrase No query result and no [youtube] records weres changed?

Am I doing something wrong?

Regards,
Doug

Disasterpiece 04-07-2011 05:46 PM

give me a few examples how your youtube tag works and I'll try to sort it out

BadgerDog 04-07-2011 06:09 PM

Quote:

Originally Posted by Disasterpiece (Post 2182038)
give me a few examples how your youtube tag works and I'll try to sort it out

Special BBCodes were added to our site over the years so that they appear in posts like this:

[youtube=QT7kEMxSdZU]British Training Film[/youtube]

.. or, like this ...

[youtube]QT7kEMxSdZU[/youtube]

Now, these videos appear twice (they repeat) in each post with your excellent new YouTube mod installed, except yours presents a wide screen video, where the old ones were 4x3. Yours is better..... :D

Is this what you mean by examples?

Regards,
Doug

Disasterpiece 04-07-2011 07:05 PM

Then modify the convyt.php like the following:

Replace the $ytpreg = ... line with each one of those:
PHP Code:

$ytpreg "/\[youtube=([a-zA-Z0-9_-]+)\&?\](.*)\[\/youtube\]/i";
$ytpreg "/\[youtube\]([a-zA-Z0-9_-]+)\&?\[\/youtube\]/i"

You'll have to run the script 2 times, each time with one of those lines.

That should do the trick then.

BadgerDog 04-07-2011 09:15 PM

Quote:

Originally Posted by Disasterpiece (Post 2182060)
Then modify the convyt.php like the following:

Replace the $ytpreg = ... line with each one of those:
PHP Code:

$ytpreg "/\[youtube=([a-zA-Z0-9_-]+)\&?\](.*)\[\/youtube\]/i";
$ytpreg "/\[youtube\]([a-zA-Z0-9_-]+)\&?\[\/youtube\]/i"

You'll have to run the script 2 times, each time with one of those lines.

That should do the trick then.

Hi... :)

I changed the individual line as above and created two different PHP files. I then ran each one and in both cases, the PHP execution returned No query result.....

I'm not sure what else could be wrong because the BBCode it should be locating is exactly as above, but if I emailed you the three files, one of which would be my config.php for vBulletin, perhaps could have a quick look?

Appreciate your support .... :up:

I did notice that your PHP file refers to:

$database = xxxxx

.. but then the line that opens the database says:

$db = mysql_connect($host, $username, $password);
mysql_select_db($database_name);

Is that correct? .. or should it be:

mysql_select_db($database);

Regards,
Doug

Disasterpiece 04-07-2011 11:48 PM

heh, I'm afraid you're right. Must've missed that.

ofc
PHP Code:

mysql_select_db($database); 

would make more sense. Try that out.

cheers

alfanexus 04-08-2011 12:05 PM

Would be great if this also worked in blogs and not just forums :)

BadgerDog 04-08-2011 02:03 PM

Quote:

Originally Posted by Disasterpiece (Post 2182147)
heh, I'm afraid you're right. Must've missed that.

ofc
PHP Code:

mysql_select_db($database); 

would make more sense. Try that out.

cheers

Yup ... :up:

That got it running, although after passing 150,000 posts and then checking one with a duplicate, the post content using this BBCode syntax still shows a duplicate. Your real-time wide screen conversion, plus the old BBCode using this syntax.

[youtube]-QIO_G9gs0A[/youtube]

I'm using these (one at a time):

Replace the $ytpreg = ... line with each one of those:
PHP Code:

$ytpreg "/\[youtube=([a-zA-Z0-9_-]+)\&?\](.*)\[\/youtube\]/i";
$ytpreg "/\[youtube\]([a-zA-Z0-9_-]+)\&?\[\/youtube\]/i"

Any ideas?

Thanks .. :)

Regards,
Doug


All times are GMT. The time now is 06:13 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01629 seconds
  • Memory Usage 1,864KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (8)bbcode_code_printable
  • (7)bbcode_php_printable
  • (17)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (2)pagenav_pagelink
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (40)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete