Using the latest version of drupal7.

I am a newbie to both drupal and html, so please bear with me on this.

I want to allow users to post youtube video's in the forum using the embed code from youtube.

I know I can do this by allowing full html, but I don't want all users to have that option.

I also read that I can add the iframe tag to the input field. My question is: where exactly is that?

I went to configuration: content authoring>text formats and the only iframe filter I found was for lightview ( and am unsure of how that syntax would work).

Thanks in advance for any assistance in this.

Comments

dman’s picture

Short answer to your question,
Your contributors should be using an input filter with "Limit allowed HTML tags" on. This is a normal default.
To allow iframes, the edit page for that filter has configurable "Allowed HTML tags"
You can add <iframe> there.

However - that's a bit of a sketchy approach, as it will allow them to embed ANY remote site content, including malware ones into your page. It may be a risk. Not cool.

There are other, better third-part filters, including the super-simple one that just allows users to post a direct link to a youtube URL and the Drupal renderer will turn it into an embed for you!

Embedded Inline Media creates a new filter/input format that will allow users to post a link to a video in the body of a node or comment, and have it automatically display the video instead.

boopish’s picture

Thank you dman! I want to keep my site as safe as possible, so was worried about the allowed html tags bit. I just downloaded that embedded inline media module and will be setting it up! Thanks again for the answer and the link!

Bet

boopish’s picture

Alrighty then, I have installed the embedded media module, and the media module.
I have managed to make a media field for video's in my forum by editing my forum topics content type ( adding the new video field there). This will now allow my members to add youtube video's without having access to the "Full Html" , which is good.

Only question remaining : for the configuration, I noticed that the "Library" now contains all the images that we have on our site. Not good. Should I have edited the configuration of the video allowed file types - omitting the standard image types? Again, forgive my ignorance, if this seems a dumb question. I am a newbie and scared stupid of doing something wrong! LOL

dman’s picture

Pull back.
Although that big module has a lot of goodies, and supports many ways to manage videos, I think that the CCK method may be overkill for both your requirements and your users.

The one component of that larger project I am recommending is *just* the input-filter based process I quoted above.
That has the least overhead, and requires almost no action on the part of your users.

I think that alone is a suitable solution to your original task. The whole cck field thing is much more complex. Powerful, but possibly unnecessary!

boopish’s picture

oooh ... so, just so I understand what you are saying: I have messed up somewhere along the line.

Here is what I did and the order I did it in:

I downloaded and installed the embedded media module BUT it requires the Media Module be installed first. So, that is what I did. The only options available were permissions for the media module ( Media and Media Internet sources). I checked all the boxes and then installed the embedded media field module. Then I saw the embed video module, and thought that was the one you were referring to, so I unchecked all the media module stuff , downloaded this and installed it. I didn't change anything in the configuration except to choose enable under "Enabled" (was unsure as to what it was supposed to be as it is not clear, and no documentation).

Then : went to the forum and tried entering the embedded code from a you tube video into the body of a comment. I was logged in as administrator at the time. It didn't work. I only saw the text I had added as a description of the test video.

I could not, for the life of me figure out how to just add the embedded code copied from Youtube into the body or comment section without having to check the "Full html" text input section (which is only available to admins - not regular members). Which is all I really need for my site.

So ... I tried making adding a field to my forum topics content. I went back to modules, and checked all the media boxes. then went to forum, content type and I opened it, edited the fields and added a new one : video, and chose the media management widget. Then opened the display section for that field and checked Video, unchecked image, then checked youtube. That seemed to work. I logged out of my site as an admin and logged back in as a regular member and added a forum topic, and the add media button was there. I added the embedded code I had copied into my notepad on my desktop. I wrote a short description for the test, and saved it as the default filtered html. The video showed up fine that way.

Obviously, I missed some step at the beginning after I installed the embedded media field module.
What should I have done? I am just learning, so please bear with me here. I am more than game to uninstall it all and start over from scratch to get this right.

vm’s picture

I could not, for the life of me figure out how to just add the embedded code copied from Youtube into the body or comment section without having to check the "Full html" text input section (which is only available to admins - not regular members).

If you don't want to use FULL HTML then you have to add the tags used in the youtube embed code to the text format being used by users in drupal.

the module that dman pointed out, and if I'm understanding correctly, requires you to edit the text format that users are using and include the filter provided by the emfield.module. If you are using an editor of some sort this may or may not require some other fine tuning. I'd disable the editor while getting the embed code working then reenable the editor to make it easier to understand where the problem is occuring.

That siad, you don't need BOTH approaches. The better approach is with a filter.

dman’s picture

First, great issue report! That description really does help ensure we are on the same page. I wish more folk were so detailed when it comes to stuff like this.

Second, what you did was not *wrong*, and is all pretty sensible in itself.
But sorry, it's not quite what I was suggesting. I didn't give enough detail from here.

Also, it looks like the current release of emfield D7 is crippled in this respect. This makes me unhappy.
However, with one line change I was able to bring the old behavior back!

# download and enable emfield (and the numerous extras it wants, eg 'media')
# also get http://drupal.org/project/media_youtube
# edit the input format at /admin/config/content/formats/ and enable "Converts Media tags to Markup"
... It is here that there should have been another option "Convert Media URLs into embed code" but that's gone missing.
# Get that process up pretty high in the list of filters. but probably AFTER the "Limit allowed HTML tags"
# here is the annoyance. About now, the system should be scanning your content and replacing simple youtube-like URLs with the required embed code. Today, that is disabled in code. And no longer available like it used to be in media_filter_info(). However, all the old guts of it are still there! I put it back for now.

In the file media/includes/media.filter.inc
there is a chunk like this


/**
 * Filter callback for media markup filter.
 *
 * @TODO check for security probably pass text through filter_xss
 * @return unknown_type
 */
function media_filter($text) {
  $text = ' ' . $text . ' ';
  $text = preg_replace_callback("/\[\[.*?]]/s", 'media_token_to_markup', $text);

  return $text;
}

/**
 *  Filter callback for media url filter.
 *  @TODO: There are currently problems with this. For instance, if a file is
 *  to be loaded from a remote location here, it will be recreated multiple
 *  times, each time this filter is called. If we want to continue supporting
 *  this feature, we would need to probably create a new stream or other way
 *  to lookup a remote file w/ its local version. Probably best as a contributed
 *  module because of this difficulty. ~ aaron.
 */
function media_url_filter($text, $filter) {
  $text = ' ' . $text . ' ';

  // Need to attach the variables to the callback after the regex.
  $callback = _media_url_curry('_media_url_parse_full_links', 1);

  // Match absolute URLs.
  $text = preg_replace_callback("`(<p>|<li>|<br\s*/?>|[ \n\r\t\(])((http://|https://)([a-zA-Z0-9@:%_+*~#?&=.,/;-]*[a-zA-Z0-9@:%_+*~#&=/;-]))([.,?!]*?)(?=(</p>|</li>|<br\s*/?>|[ \n\r\t\)]))`i", $callback, $text);

  return $text;
}

I'm just going to ignore whatever it is worried about (there's probably an issue in the queue, but whatever)

Insert the following into the first function.

  $text = media_url_filter($text, NULL);

and we get

/**
 * Filter callback for media markup filter.
 *
 * @TODO check for security probably pass text through filter_xss
 * @return unknown_type
 */
function media_filter($text) {
  $text = ' ' . $text . ' ';
  $text = preg_replace_callback("/\[\[.*?]]/s", 'media_token_to_markup', $text);

  // Put URL filter back! ~dman
  $text = media_url_filter($text, NULL);

  return $text;
}

So, for now, things work again for me.

I can
Create a page.
Paste an URL like http://www.youtube.com/watch?v=y3SBSbsdiYg&feature=g-all-esi&context=G24...
straight into the textarea as-is.
And when viewing, I see the whole video embedded in the page.

I apologize, I did not know this feature had been crippled in D7. The project page still described the original behavior.
The hack/patch I describe here doesn't address whatever they thought was broken. but it DOES do what I thought it was supposed to!

boopish’s picture

Thanks dman. Am just doing that now. I had a major problem crop up when I tried to uninstall the you tube module. It didn't uninstall properly and I ended up with a WSOD.

I didn't panic - but used restore to roll back to a previous back up that I made before starting to monkey around. However, the best laid plans went awry. Seems my backup had been corrupted (probably during the dang storms) so had to do a reinstall of everything. Luckily, I don't yet have alot of data on my site - I will be able to rebuild it in a day or so.

SO ... once again I backed up to my desktop, checked to see that it was actually working - it was. Added the modules and enabled them in the correct order. Added the you tube module last. Then followed your instructions.

And it isn't working. All I am getting is the link not the video itself.

UPDATE: got it to work - had to UNCHECK convert URLs to links in admin.config/formats and now it works!!! YEA

dman’s picture

I think it survives as long as the convert-URLs filter is AFTER the media URL processing, but maybe not for you.

A tip. If you find a WSOD after removing a required module (eg, delete it from filesystem before disabling it) there's often a good chance that visiting update.php can recover that. Visiting that page will rebuild the module inventory, and that can often sort out what's missing and disable it properly. Not always (and maybe different in D7) but that's an old trick I've used before.

boopish’s picture

Thanks dman! This web site stuff is a little daunting, but rewarding. Thank you for taking the time to explain things in a very understandable manner! And for the tip! Next time I encounter that WSOD, I will try that!

Betty

dman’s picture

No problem.
An excellent question with all the useful background description is a pleasant one to answer.
Plus not being daunted by a minor patch (without complaining) means you showed positive initiative. I wish all support requests were so!

This is a textbook Q&A, even including the misunderstanding!

boopish’s picture

one last question on this subject.

I was checking my site on my ipad, and was not logged in. The video's showed up and I even played one no problem ( which is how I had set things up - visitors can see them, but not comment, edit or add any thing and they are only in the forum).

I noticed that the name on the video was not youtube but something else (forgot to write it down, but it started with a v). BUT the minute I logged in, the video's disappeared and were replaced with these little grey boxes with a unavailable sign (a play button with an line through it, sort of like a no smoking sign for players! LOL). Thinking this was strange, I logged out. BUT now this was showing the same not available grey box and no video. Cleared my ipad cache, history and cookies and tried viewing the site again and no videos showed up whether I was logged in or not.

Was the video's showing up the first time just a fluke? I checked the media pages for a module similar to the youtube starting with a V and found none there. Did I miss a step in setting this up on my site or is youtube videos from a site like mine just not viewable on ipad? ps... my site is thebabesofskinning.com A desktop customization site.

dman’s picture

I'm guessing you mean Vimeo.

But as for why an ipad may have rendering issues, what with the Flash-vs-HTML5 ongoing developments etc, I can't be sure.
Sounds a little like the video was removed from the hosting site after being posted. Could also be connectivity or a hundred other things. You will have the URL of the target video, so check that.

boopish’s picture

Thanks dan, did that, and still no go on the ipad. I did, however find a vimeo module and installed that. then checked, and still no go for video on the ipad.
There is one more format that won't play on my site or the ipad, Vemo, and no module yet for it.

And I DO have another newbie question regarding the media and links.

Now that I have the media stuff all installed, I had to uncheck the convert url to links - so now I have to manually put in the a href= tags to each and every link that is NOT a video. What do I have to find to get something similar to what is showing on the top of this text entry here on the drupal forums?

Betty

vm’s picture

I believe what you are referring to "at the top of the text entry" is the editor being used. The d.o. editor being used at the time of this comment is http://drupal.org/project/bueditor

boopish’s picture

Thank you! That is exactly what I meant! I am used to e107, where that is built into the cms. so wasn't sure what to look for!

Betty
ps

tried the video on my ipad again. I had it turned off for a hour or so, so turned it on, went to my site, didn't log in. and sure enough, there was the video. I even played it. It said vevo in the corner even though it was from the youtube site (http://youtu.be/BKZqGJONH68) . And sure enough, when I navigated from that page back to the front page and then back again - it was greyed out. I just don't understand how it can play once and then get not a minute after.

vm’s picture

Does it work correctly from a non ipad system?

edit:
I found the page where these videos are displayed and tested in FF and IE on WIN and they do play properly multiple times and after refreshes and revisits. That may point to an issue with the ipad and it's environment or an HTML5 issue in some way. Network traffic issue in some way, or some of the other things dman already alluded to. Difficult to say, and I don't own an iPad to give more information.

boopish’s picture

Thank you. I will have some friends with ipads try it out and see if they get the same funny stuff.
Bet