Link Filter Drupal Module

Here's yet another URL Link Filter for Drupal, latest version can be downloaded from: linkfilter-4.x-5.x-1.1.zip

Drupal 6.x version is available here: linkfilter-6.x-1.2.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?

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