Published on A C Zoom (http://www.aczoom.com/cms)
Link Filter Drupal Module
By ac
Created 2008-04-02 20:54

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

Drupal 6.x version is available here: linkfilter-6.x-1.2.zip [2].

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.


Source URL (retrieved on 2008-11-20 17:00): http://www.aczoom.com/cms/software/web/link-filter-drupal-module

Links:
[1] http://www.aczoom.com/pub/tools/linkfilter-4.x-5.x-1.1.zip
[2] http://www.aczoom.com/pub/tools/linkfilter-6.x-1.2.zip