Link Filter Drupal Module

Here's yet another URL Link Filter for Drupal.
Versions:
Drupal 7: linkfilter-7.x-1.3beta.zip [Not tested - looking for someone to help with testing]
Drupal 6: linkfilter-6.x-1.2.zip
Drupal 4 and 5: linkfilter-4.x-5.x-1.1.zip

The goal for this filter is to be somewhat like the URL filter included with Drupal, with the additional requirement to be Drupal installation directory independent as well as domain independent so that the URLs in Drupal nodes don't have to be re-edited when a Drupal site is moved to a different sub-directory or a different domain. Additionally, it allows for link text to be specified for the URL, and it preserves the input characters as much as possible, performing no or minimal HTML entity conversions of the input characters. Finally - it distinguishes various links with classes, which can be used to display link icons for specific links. If the link filter tag points to internal Drupal node, then a class containing the type of the node is generated, for example, class="linkfilter-drupal-node-image", which can be used to show distinguishing icons based on Drupal node type. This site uses this filter, and the link icons are displayed based on the class generated by the filter: for external links (linkfilter-urlfull class), images (linkfilter-drupal-node-acidfree or linkfilter-drupal-node-image class), mailto links (linkfilter-mailto class).

Link filter tags [l:URL text] in the input text will be replaced with a link to the given URL, which can be a Drupal link, an external web link, or a local non-Drupal link. Prefixes representing the site url and the Drupal directory are added, as appropriate:
1) Site url is prefixed if URL begins with a / character
2) No prefix is added if the URL has a : in it, as in http: or ftp: etc
3) Site url with Drupal base directory is prefixed in all other cases, this is handled by calling the Drupal l() function.

Examples, assuming site is at http://example.com, and Drupal is installed in a sub-directory named drupal:
 [l:node/281 Blue <em>Sun</em>] → <a href="http://example.com/drupal/travel/blue-sun" ...>Blue <em>Sun</em></a>
Above example assumes that node/281 is aliased to travel/blue-sun
 [l:travel/blue-sun] → <a href="http://example.com/drupal/travel/blue-sun" ...>Blue Sun</a>
Above example assumes that the title of the travel/blue-sun node is Blue Sun.
 [l:/pub/download.zip Download] → <a href="http://example.com/pub/download.zip" ...>Download</a>
 [l:http://www.example.com/ Example Web Site!] → <a href="http://www.example.com/" ...>Example Web Site!</a>

Online help with tips is available when this module is installed. Install instructions are in the README file.

The key difference between other link filter modules already available for Drupal and this linkfilter module is in that both Drupal and non-Drupal paths are handled appropriately. Non-Drupal paths with special characters, query strings, and local site non-drupal paths when Drupal is installed in a sub-directory cause other filters to run into problems, resulting in mangled URL links, which was the main reason for creating this filter. The Drupal l() and url() functions are the key issue - while they claim to handle non-Drupal links, they don't that easily For example, they require that the URL be parsed to split the query string and "fragment" (anchor tag). They also use PHP urlencode instead of the more RFC-compliant rawurlencode(). Comments in the Drupal forum suggest that it is best to stick to processing Drupal paths with l() and url() Drupal APIs. Therefore, this linkfilter module handles all this by calling Drupal l() for Drupal paths, and directly processing non-Drupal paths.

Comments

Upgrade to linkfilter

Hi,
thanks for linkfilter, it's helped a lot to get our internal links right (I copy the live database to a different subdir for testing and absolute links all break :-( )

However I wanted it to do popups as well to support cue-card type help for some of my nodes (webforms in particular). So I now have a version that handles [p:url text] and modifies the link into a popup (new browser if no javascript, js popup if javascript available).

Do you want me to send you the new version?

yes send it over

Send it to the author's email address in the package.

One open issue would be whether to use a entirely new tag id p: or to add some other way of identifying this - maybe attributes?

Instead of
[ p:url text ]

use:

[ l-popup:url text ]

or

[ l:url text option=popup ]

The final syntax could also be used to add class= values, or other attributes for the HTML a tag.

etc?

What's the status?

Did you receive the pop-up enabled version? I'm looking for a little module like this to pass other filter's trying to filter away window.open function, I thought that this might work best if it has popup parsing.
Is this function already in the latest version?

use the Interwiki module for the same purpose

Adding a simple "l:" prefix for your Interwiki modul and setting it's value to your site's url will do the trick, too. So if you already have this module installed, you might save some time by using this.

not really

The distinction is that a single prefix l: will handle two types of substitutions - those starting with / are treated as web site paths, and without / are treated as Drupal paths. This is a distinction that is useful for those who install Drupal in a sub-directory.

Of course, that may be handled in InterWiki by creating two keywords, and mapping them differently, assuming it handles special characters correctly.

The key difference with many other link filter modules already available for Drupal and this linkfilter module is in that both Drupal and non-Drupal paths are handled appropriately. Non-Drupal paths with special characters, query strings, and local web non-drupal paths when Drupal is installed in a sub-directory cause other filters to run into problems, resulting in mangled URL links, which was the main reason for creating this filter. The Drupal l() and url() functions are the key issue - while they claim to handle non-Drupal links, they really don't. Comments in the Drupal forum suggest that it is best to stick to processing Drupal paths with l() and url() Drupal APIs.

How to install

Hi, I enabled the module but the [l: ] tag stilll doesn't work. Do I need to do something else before I can use them?

input format enabled?

Were all the steps in the README followed? Step 4 for example:
4) Drupal 4.x: Go to administer -> Input Formats, click on "configure" for Filtered HTML (and all other required input formats), and enable the "Link Filter".
Drupal 6.x: administer >> site configuration >> input formats is where Link Filter can be enabled.

You can check if linkfilter is enabled when you create new content, and look at the Input Format section, you should see a line explaining linkfilter, and a link to LinkFilter Tips.

tnx, got it working. I had

tnx, got it working. I had to enable it in the full html also, otherwise it did not work.

Drupal 5 version

Hi,
Will there also be a drupal 5 version please?
Thanks a lot in advance for considering this!

greetings,
Martijn

Contribute linkfilter on drupal.org

would you consider adding this as a contributed module on d.o?

mechanics of uploading

> would you consider adding this as a contributed module on d.o?

I did not try - it requires registration, etc, so I just skipped that step. Maybe someone else who has already registered an account there could add it there, though - with a pointer back to this site to people can send bug reports or enhancement requests.

sure

I'd be willing to help with contributing this on d.o (in general), with a link back to this site etc. I guess the question would be whether or not to try to join forces with one of the other similar modules already out there.

However, unless I'm missing something major, I don't see many other viable link-filter options that deal with both internal and external. I mean, there is Linodef (which rocks! but doesn't handle external links), and LinkToContent (but struggling with it's port to D6), and Ulink, which is maybe the closest to this project.

I'd like to see a Link Filter integrate with the Wysiwyg API, but not sure how far we should take this. What do you think, do you want to get it contributed on d.o and see where to go from there?

If so, send me a message on my d.o contact form (I'm not sure if i get email notifications about comments here). Cheers, Scott

form requires registration

I tried using the contact form, but that Drupal page requires registration too!

As to merging with other similar Drupal modules - I had pinged some (don't remember names now), but many authors were interested in more features and database stores, etc. This plugin tries to avoid using databases (since they cause upgrade problems), and it is not really necessary. So, have kept this plugin going.

ok, let's submit it then

i won't argue with you about subscribing to drupal.org - i think it's pretty painless, and zero spam... but whatever works best for you :)

Regarding my last comment, I still think this would be a useful contrib module - as an option among others. The code would need a bit of a cleanup - and there are specific things in here that are unnecessary, or handled by other modules - i'd suggest suggest stripping those out too, and could help with this. If you're cool with that, I'll be happy to help submit to d.o.

BTW, here's another related module to add to the list above: http://drupal.org/project/tinymce_node_picker - which looks promising. I would think a comparison page on d.o is in order... but first let's get Link Filter up there with the others.

If you want a contact me, here's a form that doesn't require registration: http://basekamp.com/info/contact

Scott

auto create links with tags

did you have any way to achive the aim: get the tags,and then auto creat links to the tags in the entry...
I now do it with a filter,and I don't want to use [keywords] or [keywords|url],I want to input the text normally,and the links will creat auto...

thx...

Interesting idea. A simple

Interesting idea. A simple implementation would be very expensive - it would have to do a text search for every existing article in the post text, so it would get slower and slower as the number of articles at a site increased, and also for long articles. And it would need a opposite notion to [] to avoid making links where the poster did not want one. No plans yet to do this...

I Agree

I use this module on all of my Drupal 6 sites and find it invaluable for maintaining links within Drupal's flexible and dynamic path aliasing framework. In other words, I'd like to see this project committed to CVS at drupal.org for all to use. There really is no better alternative that I know of.

extlink module

great module - always include it when building a site, would you consider adding a feature that allows pdfs to be open in a new window or an extra bit in the syntax that will allow 'target = new' to be added

Thanks

Joe

CSS3 has target-new

This seems like a user (browser) configurable item - certainly the best way to do this would be using the soon-to-arrive CSS3 target-new features and just styles to do this. It does require a minor enhancement to linkfilter to create a specific style name for pdf files - but that fits in the current functionality, so is not much of a conflict.

Other options - like accepting a target="new" text as is, or with a code, within the l: tag is somewhat more obtrusive. It would imply that writers would need to permanently embed that text in the node text, hard to edit or remove etc. Or linkfilter could store user options in a database to turn things like this on/off - that is a major change to linkfilter, which has tried hard not to require any database (causes problems on Drupal upgrade, etc). So, a lot to consider to make this work well, not sure yet of the best way to implement this, within linkfilter without the new CSS3 stuff.