1

Topic: Allow specific embed video source

Hello!

I was wondering if there is any way to allow a specific source for embeding videos.

For example I want to allow videos ONLY from youtube.

The reason I want to do this is to make sure that the user will not try to include a dodgy url with a custom html/javascript/php script..


Thanks!

2

Re: Allow specific embed video source

There are a couple of different ways to handle this.

If the concern is only about embedded videos that are placed using <embed> tag, then htmLawed's 'spec' argument can be used to make sure that only Youtube videos are allowed in 'src' attribute of <embed> -- see this topic. In your case, this should work

$spec = 'embed=src(match="
      `^https?://(www\.)?(youtube)\.com/`i
      ")';

A similar strategy can be used to check value of 'src' attribute of <iframe> tag, if the videos are embedded using this tag instead of <embed>.

If videos are embedded using <object> and <param> tags, then, because <param> tags get used for things other than video sources, you can have a small custom function to use with 'hook_tag' parameter of the 'config' argument of htmLawed. This function will check that if the 'name' attribute of a <param> tag is set to 'movie', then only a Youtube source is permitted in the 'value' attribute of the tag.

Permitting only Youtube video links (in <a> tags) will however be difficult because non-video links in <a> tags will get affected as well.

I can help more with exact codes if you can tell me the kind of HTML tags that are used for embedding the videos.