Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: NekoJonez on May 11, 2014, 06:42:27 AM

Title: Adding option to stop mod from displaying YouTube video's as a video
Post by: NekoJonez on May 11, 2014, 06:42:27 AM
Okay, the title might need some explanation.

I'm using the "Simple Youtube Video Embedder/BBC" mod to render my YouTube video's as a video directly on my forum. (Sadly enough, I don't find it anymore on the mod site. Am I looking wrong?)

Anyways, some of my users have a slow connection and the loading of all those video's make it that their computer has a sort of mini heart attack.

But the users don't want the feature to go away.

Now my question is, how can I add some code where users can toggle an option that makes it that YouTube vids don't render as a video but stay as a link?

Is that possible or not?
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: Kindred on May 12, 2014, 09:09:51 PM
Well. Without looking at the mod specific code, it's hard to say...  You really would need to ask the mod author.

Also, adding a per user setting can be tricky... Since you have to store it in the database.
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: br360 on May 12, 2014, 09:53:46 PM
Quote from: NekoJonez on May 11, 2014, 06:42:27 AM

I'm using the "Simple Youtube Video Embedder/BBC" mod to render my YouTube video's as a video directly on my forum. (Sadly enough, I don't find it anymore on the mod site. Am I looking wrong?)

It looks like the person that wrote the mod had his account deleted; and all of his mods were removed from here as well.
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: Kindred on May 12, 2014, 09:58:18 PM
To be more specific, the individual deleted his own account. We do not typically force delete any accounts other than spammers.
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: margarett on May 12, 2014, 10:39:18 PM
It should be possible to change the bbc parsing so that it opts to add the iframe or not, depending on a user setting.
But that requires a new field to be added in profile. There are other similar mods around, maybe you can poke on of the authors and see what do they have to say...
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: NekoJonez on May 13, 2014, 06:26:15 AM
There is this other YouTube BBC mod, better ask it to that author?
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: margarett on May 14, 2014, 05:11:38 PM
Just YouTube I'm not sure. But there are for sure other auto-embedders ;)

In any case, all of them (IIRC) always embed the content. What you need is a "simple" switch to either embed it not, depending on the user setting... And that's the laborious task, really :)
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: NekoJonez on May 15, 2014, 05:07:18 AM
So, what should I do next?

Also, the current mod I have uses tags to embed the vids. We just need to post a link and it displays like a vid. Should I change anything about that?
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: Kays on May 15, 2014, 06:31:30 AM
Actually, adding to $options isn't that big a deal. And it is possible to disable a bbc tag.

However when I tested this on Suki's mod all that I got was the video id number. Which was not quite what I expected. ::)

Here's a quick test to see what will happen if the [youtube] tag is disabled with the mod you are using. In Subs.php look for:


if ($smileys === 'print')


And add the following before that


if (!empty($context['user']['is_admin']))
$disabled['youtube'] = true;


Then go and view a post with video in it. If it's now a link, then there's hope. :)
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: NekoJonez on May 16, 2014, 10:17:03 AM
Yes, it works perfectly. :) But now, how can I add this as an option for users?
(And if possible, if that option is check, that the Youtube url is seen as a link?)
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: Kays on May 16, 2014, 12:15:04 PM
Cool, I just wanted to verify that you do get a link before getting you to make the code changes. :)

Now replace that code in Subs.php with the following:


// Added to allow the user the option to not embed a YouTube video
global $options;
if (!empty($options['no_embed_youtube']))
$disabled['youtube'] = true;


In Profile.template.php in your theme or the one in the default theme if there isn't one in the theme you are using. Look for:


// Choose WYSIWYG settings?


Add before that:


// Added to allow the user the option to not embed a YouTube video
echo '
<li>
<input type="hidden" name="default_options[no_embed_youtube]" value="0" />
<label for="no_embed_youtube"><input type="checkbox" name="default_options[no_embed_youtube]" id="no_embed_youtube" value="1"', !empty($context['member']['options']['no_embed_youtube']) ? ' checked="checked"' : '', ' class="input_check" /> ', $txt['no_embed_youtube'], '</label>
</li>';


Finally, add the following to Modifications.english.php before the closing ?>


$txt['no_embed_youtube'] = 'Show YouTube videos as a link.';


If not using English for your language, translate that and add it to the Modifications file for your language.

This option now can be found on the "Look and layout" area in the user's profile.
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: NekoJonez on May 17, 2014, 09:44:18 AM
Thanks man :)

It works nicely.
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: Kays on May 18, 2014, 01:40:27 PM
Great, glad to hear that. :)
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: dougiefresh on December 27, 2014, 07:08:44 PM
@Kays: Thanks for the helpful information regarding how to make that mod show a link instead of a video....

Quote from: NekoJonez on May 11, 2014, 06:42:27 AM
I'm using the "Simple Youtube Video Embedder/BBC" mod to render my YouTube video's as a video directly on my forum. (Sadly enough, I don't find it anymore on the mod site. Am I looking wrong?)
I found the mod at GitHub (https://github.com/LinuxPanda/SMF2.0Mod--Simple_Youtube_Video_Embedder_BBC_v2), in the event anybody is interested....
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: NekoJonez on December 28, 2014, 06:07:54 AM
If something like this would be included into SMF 2.1, I think you guys should add this too.
Title: Re: Adding option to stop mod from displaying YouTube video's as a video
Post by: Illori on December 28, 2014, 06:28:10 AM
at this time we have no plans to add youtube support in 2.1.