Filter to automatically add rel="lightvideo" to youtube links to use with lightbox

flipwuk - June 29, 2009 - 19:49

Hi Everyone,

I've just installed the Lightbox module and am impressed with how the rel="lightvideo' attribute allows youtube etc videos to be shown in the lightbox.

It would be great if links to youtube videos could automatically be turned into 'lightvideo' links. I thought of writing a filter to do this but couldn't really find much documentation and I'm not much of a coder.

All the filter would have to do is seek out links to youtube.com and add in the rel='lightbox' attribute to them. This would be useful as it'd keep visitors on the site rather than sending them off to youtube where they might get distracted and remain.

Does anyone have any ideas of how I'd do this, or know of an existing solution that I may have missed?

Thanks,

Phil

are u saying the emfield

mm167 - June 30, 2009 - 07:46

are u saying the emfield module which can embed youtube video in a node?

http://drupal.org/project/emfield

---------------------------------------------------------
toll free is good, but pay toll may go faster ...
we go the drupalway. how about u?
www.drupalway.com - pay toll to go faster

We go the drupal way. How about you?
http://www.drupalway.com

No, not quite.I don't want

flipwuk - June 30, 2009 - 17:03

No, not quite.

I don't want the youtube link to be turned into an embedded player, I would just like the code of the link to be modified so that the player opens up in a lightbox window, like the video examples at http://www.stellapower.net/lightbox2 (towards the bottom of the page).

The filter would just have to be (I guess) a regular expression that finds <a href="http://www.youtube.com/watch?v=ANYTHINGHERE"> and replaces it with <a href="http://www.youtube.com/watch?v=ANYTHINGHERE" rel="lightvideo">.

http://drupal.org/node/88192 has some tips (especially towards the bottom) on good reg exs to use for youTube.

Hi there. I've made a filter

ecstasy2 - June 30, 2009 - 19:37

Hi there.
I've made a filter that do exactly that a month ago.
It will require some modification to apply it only to youtube links.
Contact me through my contact form if you're interested.
If you're interested, i can give it to you.
Cheer.

Been a Top Drupal Project Manager one step at the time.

I've uploaded the module

ecstasy2 - July 1, 2009 - 10:05

I've uploaded the module there: http://www.debrid-all.net/addrel_filter.zip

There a feature that allow you to modify only certains link (using a php regular expression).

I'm planning to commit the modul to the CVS and add some features.
Please provide feedback.

How to use.

Hi. Here is the filter module.
Just install.
To configure it: add the filter to a Input format and go to the configure form of the input format.
There willbe to new textfield:

Rel: enter the rel value to be added (lightvideo).
Regex: Enter the regular expression to match against href attribute of the anchore tag: this one will do the trick for you (without quote): /youtube\.com\/watch\?v=([^&]+)/ie

I'm waiting for feedback.

edit

There was an error inside the code, it is corrected now.

Been a Top Drupal Project Manager one step at the time.

Thanks so much, that works

flipwuk - July 1, 2009 - 20:54

Thanks so much, that works really really well.

For anyone unclear about what to put in the regex field, I just pasted in this below:

/youtube\.com\/watch\?v=([^&]+)/ie

--------------------------------

My only feedback is just from how the module appears when viewed at admin/modules/list:

'Add Rel to Anchore tags 6.x-1.0 A filter to add a css class to all links in the input'

Anchor should be spelled without the e, and instead of css class it should say rel (I'm guessing thats left over from a previous module). Other than that, it's great and thank you very much!

'Add Rel to Anchore tags

ecstasy2 - July 2, 2009 - 10:49

'Add Rel to Anchore tags 6.x-1.0 A filter to add a css class to all links in the input'

Anchor should be spelled without the e, and instead of css class it should say rel (I'm guessing thats left over from a previous module). Other than that, it's great and thank you very much!

Thanks you, i'll change it.
As you guessed: i used the module to add a specifique class to all anchors tags (with a minor change). Actualy, what i'm planning is to create a more general module that will modify (append, replace) any attribute of any html tag that match a given regular expression.

I'm posting this to what people think about that (is it usefule?).

Note: actually the Regex value in the input format configuration for is mandatory, i'll manage to change it soon.

Been a Top Drupal Project Manager one step at the time.

 
 

Drupal is a registered trademark of Dries Buytaert.