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

Comments

mm167’s picture

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

Phil Wolstenholme’s picture

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.

ecstasy2’s picture

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.

ecstasy2’s picture

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.

Phil Wolstenholme’s picture

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!

ecstasy2’s picture

'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.

overaph’s picture

Hi, I realy appreciate the module you has linked long time ago. Know the link is corrupted.
Can you re-link it please?

Thank you very much!

Funkymoses’s picture

No offense to the guy with the module above but this is a core use case for Custom Filter:
http://drupal.org/project/customfilter

here's my regex:
#<a href="http://www.youtube\.com\/watch\?v=([^&"]+)#i

and the replacement:
<a href="http://www.youtube.com/watch?v=$1" rel="lightvideo