Advertisement:

Author Topic: Ohara YouTube Embed  (Read 142424 times)

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Ohara YouTube Embed
« on: December 21, 2011, 03:04:59 PM »
Link to Mod

Ohara YouTube Embed
Author: Suki

Attention:
On install make sure to mark the "Install in Other Themes" checkbox.


Description

For SMF 2.0.x only

Version 1.2.x and above requires PHP 5.3 or greater

You can auto-embed any valid youtube, imgur/gifv or vimeo urls and the mod will automatically convert them to videos.

This mod will also add a BBC tag:  [youtube][/youtube], [gifv][/gifv] and [vimeo][/vimeo]  where you can post your youtube or vimeo urls and it will be converted to a video directly in the message.

You can enable/disable the mod as well as set the width and height for the videos, currently the mod support the following youtube and vimeo urls:

Code: [Select]
http://www.youtube.com/watch?v={ID}
http://www.youtube.com/watch?v={ID}&{Parameters}
http://www.m.youtube.com/watch?v={ID}
http://youtu.be/{ID}
http://www.youtube.com/watch?feature=player_embedded&v=[ID]
http://vimeo.com/[ID]
http://vimeo.com/channels/[channel name]/[ID]
http://vimeo.com/group/[ID]
http://vimeo.com/album/[ID]

License

This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
 



Settings

- Admin->Configuration->Modifications


Languages

-English/utf8
-Spanish_latin/utf8
-Spanish_es/utf8


Changelog
Code: [Select]
1.2.9 - March 12, 2017
- Fix the "/>" appearing on autoembed
- Fix support for gifv
- Add a link to the video if JavaScript is disabled

1.2.8 - Oct 25, 2016
- Improve regex for gifv and youtube urls.
- Pass the ID when using url auto parsing, prevents using another regex to get it.
- Use global scope inside closures.

1.2.7 - Aug 12, 2016,
- Set basedWidth and basedHeight to prevent weird behavior on non responsive themes.

1.2.6 - May 29, 2016,
- Add support for full screen videos.
- Remove multiple calls to this.responsive().
- Check the width and height of parent div before applying changes.

1.2.5 - February 18, 2016,
- Added support for imgur gifv format
- Move the css and js calls to integrate_load_theme hook.

1.2.4 - August 2, 2015,
- Added responsiveness to videos. This will only work on responsive themes.
- Fixed an issue when two or more instances of the same video where posted, none of them would be played.
- Re-wrote the JS code to use prototypes.
- Change the default size values to 480 x 270.

1.2.3 - June 26, 2015,
- Added a minified js file.
- Added support for using the youtube ID as param.
- License change to MPL 2.0.

1.2.2 - April 05, 2015,
- Force loading the oharaEmbed.css file from the default theme.
- Add more options to show video preview images
- Add support for previewing a message
- Improve handling of youtube thumbnails and overall JS improvements.
- Add a setting to enable/disable the autoembed feature. This was suppose to be added a long time ago but dunno why I forgot to do it...
- Missed to check the master setting.

1.2.1 - March 09, 2015,
- Added the option to disable the autoembed feature via $context['ohara_disable'].
- Use closures instead of create_function()
- Change the way youtube videos are displayed, faster pages specially with multiple videos, thanks to Infernuza for the tip.

1.2 - March 05, 2014,
- Added auto-embed feature.
- Add support for old [nobbc][yt][/yt][/nobbc] tags
- Add support for [nobbc][vimeo][/vimeo][/nobbc]

1.1 - April 19, 2013,
- Fix the http/https url issue.
- Fixed the parsing smiles after a video issue.
- Fixed the pass by reference issue.
- Updated the regex to include more valid urls.

1.0.1 - Dic 28, 2011,
-Fix the youtube redirect page error if you use the initial tag alone: [youtube]

1.0 - Sep 25, 2011,
-Initial Release
« Last Edit: August 12, 2016, 12:53:32 PM by Suki »
I'm not a criminal.
I'm not a rapist.

Offline WantSome

  • Jr. Member
  • **
  • Posts: 346
Re: Ohara YouTube Embed
« Reply #1 on: December 28, 2011, 06:07:24 AM »
Hiya!

I love your mod.  Thanks! 

I tested it with great success on my test forum, and then used it on my main forum.  For some reason I've come up with a weird problem.

The first video I embedded using the tags was this one:
http://www.youtube.com/watch?v=wifH74R3yJA 

And now for some reason whenever I go to that thread, I get redirected to youtube.  That is, the topic loads for a second and then redirects to youtube.  From topic view when I click on the topic, it goes to my youtube login page.  When I click 'view the last post' from the topic view, it redirects me to youtube. 

I then thought to access the post from my posts and edit it, but viewing my posts also now directs me to youtube.  What's happening?!

Is there a way I can edit that post without being directed to youtube?  And, is there a way to prevent this from happening again?

Thanks!

(I'm using 2.0.1)

EDIT: 
I think I've fixed it. 

When I was testing it on my forum, it was as part of an announcement to my users about the 'new feature' of being able to embed youtube videos into their posts.  I used [youtube] to illustrate ('youtube' in square brackets) and for some reason this caused the entire thing to redirect everything to youtube.  Weird.

Upon trying to edit the post, the forum page loads for a few seconds before redirecting to youtube.  I used the stop button to make it stop loading, thereby preventing it from forwarding to youtube.  I saw where the prolem lay and edited the [youtube] to exclude the square brackets (except, obviously, where I needed them for the actual video), and that seems to have sorted the problem out.

Is this a bug?
« Last Edit: December 28, 2011, 07:51:41 AM by WantSome »

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #2 on: December 28, 2011, 10:05:56 AM »
How do you used the tag?  can you copy/paste inside the code tag the exactly same code you used.

if you use the tag [youtube][/youtube]   empty then it will show a text string: Not a valid youtube URL


The only thing I see  is the string has a %s  and I should use sprintf() on it, otherwise it will show:

Not a valid youtube URL %s
I'm not a criminal.
I'm not a rapist.

Offline WantSome

  • Jr. Member
  • **
  • Posts: 346
Re: Ohara YouTube Embed
« Reply #3 on: December 28, 2011, 01:23:15 PM »
Thanks for the answer, Suki.

Actually I don't think I explained my solution properly.

In my post, I used the correct [youtube][/youtube] tags around the video link.  But I ALSO used just the word [youtube] in the body of the post.
When I managed to view the post (before it redirected to youtube), it showed a blank box where the video should have been.  This blank box started where the [youtube] was used.

So it looked something like this:

Quote
Announcement concerning [youtube] tags.  You can now use [youtube] tags to embed your youtube videos.
Like this:
[youtube]http://www.youtube.com/watch?v=wifH74R3yJA[/youtube]

The end result was something like this:

Quote
Annoucnement concerning
[BIG BLANK BOX]

When I changed the [youtube] items in the first line of the first example, the big blank box disappeared, and the thread stopped redirecting to youtube, and the video showed as expected.

I hope that's clearer now.  The problem doesn't exist any longer because I took the [youtube] away in the text of my post, and only used the tags around the video link.

So, the only bug that exists now (as far as I can tell and I'm no expert) is if someone uses the exact phrase [youtube] without a link, and without closing the tag with [/youtube], the entire thread will redirect to youtube.

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #4 on: December 28, 2011, 02:03:18 PM »
Thanks for the report, I'll take a look and release a new version.
I'm not a criminal.
I'm not a rapist.

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #5 on: December 28, 2011, 08:26:56 PM »
Found the  issue, open your Sources/OharaYTEmbedphp file, find:

'disabled_content' => '$1',   and after that add:

         'block_level' => true,
         'test' => '(http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?)[/youtube]'


it should be like this:

Code: [Select]
$codes[] = array(
'tag' => 'youtube',
'type' => 'unparsed_content',
'content' => '$1',
'validate' => create_function('&$tag, &$data, $disabled', '
global $txt;

if (empty($data))
$data = $txt[\'OYTE_unvalid_link\'];

else
{
$data = trim(strtr($data, array(\'<br />\' => \'\')));
$data = OYTE_Main($data);
}
'),
'disabled_content' => '$1',
'block_level' => true,
'test' => '(http://(?:www\.)?youtu(?:be\.com/watch\?v=|\.be/)(\w*)(&(amp;)?[\w\?=]*)?)[/youtube]'
);

That should fix the standalone tag.

I'll update the mod with the fix later tonight.
I'm not a criminal.
I'm not a rapist.

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #6 on: December 28, 2011, 08:55:49 PM »
New version 1.0.1:

Changelog

1.0.1 - Dic 28, 2011,
-Fix the youtube redirect page error if you use the initial tag alone: [youtube]

1.0 - Sep 25, 2011,
-Initial Release


To update just uninstall the olf verison and install the new one via the Package Manager.
I'm not a criminal.
I'm not a rapist.

Offline MaXiForum.cz

  • Senior Translator
  • Full Member
  • *
  • Posts: 690
  • Gender: Male
  • Czech SMF support
    • MaxiF√≥rum
Re: Ohara YouTube Embed
« Reply #7 on: December 29, 2011, 08:16:21 AM »
Hi,
what is the difference between this?
http://custom.simplemachines.org/mods/index.php?mod=936
:)

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #8 on: December 29, 2011, 08:55:32 AM »
this one:
written for 2.0.x
Uses hooks, less file edits
Does support the short youtube urls

The other one is marked as "deprecated" and I needed a simple mod for embed youtube videos so I built it.
I'm not a criminal.
I'm not a rapist.

Offline Joomlamz

  • SMF Hero
  • ******
  • Posts: 2,582
  • Gender: Male
  • Suporte SmfPT
    • apllicmz on Facebook
    • apllicmz on GitHub
    • https://www.linkedin.com/in/aplic on LinkedIn
    • @aplichosting on Twitter
    • Webdesign
Re: Ohara YouTube Embed
« Reply #9 on: January 01, 2012, 08:12:01 PM »
Yes nice work
when Update puty portuguese files
thank you




Offline Kryzen

  • Localizer
  • SMF Hero
  • *
  • Posts: 3,977
  • Gender: Male
    • Chistaen on GitHub
Re: Ohara YouTube Embed
« Reply #10 on: January 02, 2012, 07:14:54 AM »
Awesome mod! :)
PHP programmer | Currently learning: Java, C++
DraiWiki | Project Alpha

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #11 on: January 02, 2012, 08:49:13 AM »
Thanks.
I'm not a criminal.
I'm not a rapist.

Offline Hragged

  • Semi-Newbie
  • *
  • Posts: 31
Re: Ohara YouTube Embed
« Reply #12 on: January 07, 2012, 05:01:32 PM »
This is great, thanks! ;D

Noticed a little problem on my forum - whenever I have a smiley after a YouTube video in the same post, the smiley image doesn't appear, just the code for the smiley. They work fine when posted above the video though.

Don't know if this happens on all forums (I'm on 2.0.2, I have a couple of other mods installed and a modified template) but thought I should say anyway, just in case!

Cheers! :D

Edit - tested it here, same issue: http://missallsunday.com/modifications_and_packages/ohara_youtube_embed_52.msg299.html#msg299
« Last Edit: January 07, 2012, 05:18:24 PM by Hragged »

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #13 on: January 07, 2012, 05:28:51 PM »
Thanks for the report, I'll check it out.
I'm not a criminal.
I'm not a rapist.

Offline J.G

  • Semi-Newbie
  • *
  • Posts: 14
Re: Ohara YouTube Embed
« Reply #14 on: January 27, 2012, 03:04:46 PM »
I keep getting the Invalid URL error.  :-\

Do you know why this is? Brilliant Mod by the way.  :laugh:

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #15 on: January 27, 2012, 03:29:12 PM »
what's the url you're trying to use?
I'm not a criminal.
I'm not a rapist.

Offline J.G

  • Semi-Newbie
  • *
  • Posts: 14
Re: Ohara YouTube Embed
« Reply #16 on: January 27, 2012, 04:08:24 PM »
This is the code and URL used.

Code: [Select]
[youtube]http://youtu.be/x1yOGhnmYfI[/youtube]

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #17 on: January 27, 2012, 04:13:33 PM »
Is that the exact same video url?

Do you post something else besides the video url?
I'm not a criminal.
I'm not a rapist.

Offline J.G

  • Semi-Newbie
  • *
  • Posts: 14
Re: Ohara YouTube Embed
« Reply #18 on: January 27, 2012, 04:22:36 PM »
Indeed, it is the exact same URL. I will give it a try with other URLs to see if the problem continues.


Code: [Select]
[youtube]http://youtu.be/V3hxPnG0GeE[/youtube]

[youtube]http://youtu.be/JM2PRqR9WeA[/youtube]

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

Now, the first two codes using the new URL format do not work, while the third one using the old style format works fine.

Offline Suki

  • SMF Super Hero
  • *******
  • Posts: 14,967
  • Kaizoku Jotei
    • SMF mods
Re: Ohara YouTube Embed
« Reply #19 on: January 27, 2012, 04:35:37 PM »
mmm, that is weird, I posted the same urls on my site and on my test site and all of them are working:

http://missallsunday.com/chit_chat/some_tests_94.new.html#new
I'm not a criminal.
I'm not a rapist.