Yet Another YouTube BBCode Tag

Started by dougiefresh, December 10, 2014, 06:09:01 PM

Previous topic - Next topic

dougiefresh

Link to Mod



YET ANOTHER YOUTUBE BBCODE TAG v4.14
By Dougiefresh -> Link to Mod



Introduction
This modification adds a BBCode to the forum that shows a YouTube video in your post.

These BBCode takes these forms:

[youtube]{youtube link}[/youtube]
[youtube width=x height=y]{youtube link}[/youtube]
[yt]{youtube ID}[/yt]
[yt {parameters}]{youtube ID}[/yt]
[yt_user]{username}[/yt_user]
[yt_user {parameters}]{username}[/yt_user]
[yt_search]{search query}[/yt_search]
[yt_search {parameters}]{search query}[/yt_search]

where width and height is specified by x and y.  If width and height aren't specified, width is 100% of the post display area and height in a 16:9 ratio to the width.

The yt_user bbcode will show videos by the specified YouTube username.

The yt_search bbcode will show videos matching the provided search phrase.

This mod should be able to display a valid YouTube video when passing URLs.  For example, all of the following will display the YouTube video at http://www.youtube.com/v/fA4cphzsjn8.
Quote
For YouTube Videos:
fA4cphzsjn8
http://www.youtube.com/fA4cphzsjn8
http://www.youtube.com/embed/fA4cphzsjn8
http://www.youtube.com/embed?v=fA4cphzsjn8
http://www.youtube.com/embed?feature=player_embedded&v=fA4cphzsjn8
http://www.youtube.com/watch?v=fA4cphzsjn8
http://www.youtube.com/v/fA4cphzsjn8
http://www.youtube.com/e/fA4cphzsjn8
http://www.youtube.com/?v=fA4cphzsjn8
http://www.youtube.com/user/username#p/u/11/fA4cphzsjn8
http://www.youtube.com/sandalsResorts#p/c/54B8C800269D7C1B/0/fA4cphzsjn8
http://www.youtube.com/watch?feature=player_embedded&v=fA4cphzsjn8
http://www.youtube.com/?feature=player_embedded&v=fA4cphzsjn8

For YouTube PlayLists:
PL55713C70BA91BD6E
PLquckZj9TVRFKWqM6LJI4a_dgvN48jZGk
http://www.youtube.com/e/PL55713C70BA91BD6E
http://www.youtube.com/p/PL55713C70BA91BD6E
http://www.youtube.com/embed/PL55713C70BA91BD6E
http://www.youtube.com/embed?list=PL55713C70BA91BD6E
http://www.youtube.com/embed?feature=player_embedded&list=PL55713C70BA91BD6E
http://www.youtube.com/watch?v=OPf0YbXqDm0&list=PL55713C70BA91BD6E
http://www.youtube.com/?list=PL55713C70BA91BD6E
http://www.youtube.com/?feature=player_embedded&list=PL55713C70BA91BD6E
https://www.youtube.com/embed/videoseries?list=PLquckZj9TVRFKWqM6LJI4a_dgvN48jZGk
https://www.youtube.com/watch?v=Ni4ZclaiOtY&list=PLquckZj9TVRFKWqM6LJI4a_dgvN48jZGk
Substituting http://youtube.com, http://www.youtube-nocookies.com, http://youtu.be, and http://www.youtu.be also works.  https:// works instead of http://.  Please note any other parameters specified in the URL are ignored.

Optional parameters and values for all YouTube bbcodes are:
o width = Specifies the width of the iframe area.
o height = Specifies the height of the iframe area.
o start = Specifies how far into the video to start at.  Valid formats: "Seconds" or "Minutes:Seconds"
o end = Specifies how far into the video to stop at.  Valid formats: "Seconds" or "Minutes:Seconds"
o autoplay = 1, yes, on or true
o color = red or white
o theme = dark or light
o loop = 1, yes, on or true
o controls = 0, no, off, hide or false
o showinfo = 0, no, off, hide or false
o privacy = 1, yes, on or true

Profile Settings
There is a new option under Profile => Look and Layout called Show YouTube videos as a link.  Checking this box makes the mod create links instead of embedded videos in your post.

Admin Settings
This BBCode may be disabled by going into the Admin => Forum => Posts and Topics => Bulletin Board Code and unchecking the bbcodes you don't want to use.  You may also be uninstall this mod in order to disable it.

Related Discussions
o Adding option to stop mod from displaying YouTube video's as a video
o Youtube I.D parsing for new URL formats
o Need help with a Regular Expression for YouTube links....

Extra Credits Go Out To:
o Sapozhnik for code assistance
o karavan2 for providing code assistance
o kelvincool for Regular Expression assistance

Translators
o Spanish Latin: Rock Lee [BC]

Compatibility Notes
This mod was tested on SMF 2.0.10, but should work on SMF 2.1 Beta 3, as well as SMF 2.0 and up.  SMF 2.1 Beta 2 and SMF 1.x will not be supported.

Changelog
The changelog can be viewed at XPtsp.com.

License
Copyright (c) 2015 - 2018, Douglas Orend
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

dougiefresh

Uploaded v1.1 - December 10th, 2014
o Added button for the bbcode.

dougiefresh

Uploaded v1.2 - December 11th, 2014
o Fixed incorrect strings added by the mod.

lordrene

Quote from: dougiefresh on December 11, 2014, 04:18:48 AM
Uploaded v1.2 - December 11th, 2014
o Fixed incorrect strings added by the mod.
I have the default 2.9 theme and when I try to install the mod, It give me this error

kat

http://wiki.simplemachines.org/smf/Error_in_mod_installation

The link might fail, a few times, coz the wiki's crap, at the moment, for some reason. Keep trying, though, and it'll load, eventually.

dougiefresh

Quote from: lordrene on December 12, 2014, 04:15:06 AM
Quote from: dougiefresh on December 11, 2014, 04:18:48 AM
Uploaded v1.2 - December 11th, 2014
o Fixed incorrect strings added by the mod.
I have the default 2.9 theme and when I try to install the mod, It give me this error

Okay, these lines have to do with the parsers' ability to accept only the youtube bbcode (and contents) as the only content in the post.  In other words, you put this in your post:
[youtube]{some id here}[/youtube]
and that's all and the editor will accept it.  If you have another mod that makes the same alteration to these areas, then you should be fine skipping those operations.  Although, I find it weird that the first operation works and the second doesn't.....

NekoJonez

Does this mod display "link invalid" when it's actually invalid?
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

dougiefresh

At present time, entering an invalid link only gets you a blank square....  I'll figure out something to make this work correctly for that situation....

dougiefresh

Uploaded v1.3 - December 17th, 2014
o Rewrote mod to use one validation function for all bbcodes forms in this mod.
o Modified code to return "Invalid YouTube Link" if the link isn't valid...

Quote from: NekoJonez on December 16, 2014, 06:31:22 AM
Does this mod display "link invalid" when it's actually invalid?
@NekoJonez: This update provides this additional functionality.

dougiefresh

Uploaded v1.4 - December 19th, 2014
o Fixed typo that resulted in errors being logged in the admin panel...

NekoJonez

Awesome, my next site update will replace the mod I had with this one :)
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

Dream of Omnimaga

Does this support https links or just http?

NekoJonez

#12
Feature request: could you add an option for users so that when they have eg a slow internet they can load the vids as links?

This topic could help: http://www.simplemachines.org/community/index.php?topic=522345.msg3695157#msg3695157
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

dougiefresh

Quote from: DJ Omnimaga on December 27, 2014, 12:26:37 AM
Does this support https links or just http?
Yes, this mod also supports the https form of the YouTube links.

Quote from: NekoJonez on December 27, 2014, 09:30:10 AM
Feature request: could you add an option for users so that when they have eg a slow internet they can load the vids as links?

This topic could help: http://www.simplemachines.org/community/index.php?topic=522345.msg3695157#msg3695157
Yes, I can do that for you.  And thanks for the helpful link to the solution....

NekoJonez

Awesome. I can't wait until you get the option working :D. Would mean a great deal to me.
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

dougiefresh

Uploaded v1.5 - December 28th, 2014
o Added yt bbcode, which uses same syntax as the youtube bbcode.
o Added option to disable the embedding of YouTube videos on a per-user basis.
o Modified to use link provided when YouTube bbcode is disabled.

NekoJonez

Is there already a feature to install the picture of the button into other themes?
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

NekoJonez

Bug report:

  • The mod doesn't look for other themes to place the img for the button in.
  • When v1.5 is installed, the bbc codes get messed up. I couldn't get color to work and ALL my url tags where displayed as links.
Retro video game blogger, writer, actor, podcaster and general amazing dude.

Twitter
My Blog

dougiefresh

Quote from: NekoJonez on December 29, 2014, 11:03:58 AM
  • The mod doesn't look for other themes to place the img for the button in.
I've got this bug report fixed for the next version....

Quote from: NekoJonez on December 29, 2014, 11:03:58 AM
  • When v1.5 is installed, the bbc codes get messed up. I couldn't get color to work and ALL my url tags where displayed as links.
Crap....  I messed up in the package-info.xml file and replace instead of after....  I've fixed this bug report for the next version....  Sorry about that!

dougiefresh

Uploaded v1.6 - December 29th, 2014
o Fixed image install locations within package-info.xml.
o Replaced replace with after in install.xml for new code in v1.5...

Advertisement: