rah_urltolink
Published under current TXP projects
The plugin is able automatically change text formated URLs into real clickable (X)HTML links. This can be accomplished by simply wrapping the content with a one rah-prefixed Textpattern tag. Generated URLs’ output is customizable by the tag’s attributes.
Image: rah_urltolink
Intro and description
A Textpattern plugin used to automatically change text URLs into real clickable (X)HTML links, aka a elements. The output provided by the plugin can be customized by attributes that allow to set (X)HTML classes, labels, rels and link titles.
For example http://example.com would be converted into <a href="http://example.com">www.example.com</a>.
List of features
- Converts URLs to (X)HTML links.
- Supports and converts following URL formats:
- http://example.com
- https://example.com
- ftp://example.com
- ftps://example.com
- www.example.com
- john.doe@example.com
Requirements
- PHP 4.3.0+
- Textpattern 4.x.x+
Installation and usage
The general behavior stands: paste plugin code to the plugin installer textarea and run the automatic setup. Then just activate the plugin and you are ready to use new tags that plugin includes like others.
For usage, basically just put wrap (contain) content in your pages/forms/articles with <txp:rah_urltolink></txp:rah_urltolink>- container tags, and customize output with your desired attributes. All email/www/http/https/ftp/ftps-URLs after with space (space is the fastest and simplest way to validate links and avoid turning links into links again) in the contained content will be turned into links.
Attributes
The tag is <txp:rah_urltolink> and attributes for it follow.
language
XHTML link’s, a, language attribute/value fi, en, de, se.
Example: language="en" Default: ""
class
XHTML class assigned to links.
Example: class="link" Default: ""
label
Link’s anchor element: label. If unset (empty), link with out leading http will be used as an anchor.
Example: label="[link]" Default: ""
rel
Link’s rel attribute.
Example: rel="nofollow" Default: ""
title
Link’s title attribute.
Example: title="Click link" Default: ""
protocols
Select appending protocols that are included in URL-to-Link conversion. Valid values: http, https, ftp, ftps, www, and mail. Comma seperated if multiple.
Default: protocols="http,https,ftp,ftps,www,mail" Example: "www,http"
Example
<txp:rah_urltolink>
We have some content here.
<txp:article />
</txp:rah_urltolink>
Changelog
Version 0.4.4
- Fixed the issue from 0.4.3 to 0.4.1. Now URLs in links are not turned into links, only links right after
>or space are converted.
Version 0.4.3
- Fixed: Put back the appending space requirement, to avoid turning URLs in link to links.
Version 0.4.2
- Changed: Removed two letter domain requirement.
Version 0.4.1
- Fixed: Now additional attributes (
rel,labeletc) are escaped correctly. Thanks txpnisti.
Version 0.4
- Added
protocolsattribute. Now you can select what type of URL to turn into link. - Fixed: Now won’t eat pending spaces before links.
- Fixed: Now URLs right after (X)HTML tags (
>char), dots, and so on, are turned into links: No more requires appending space. Even link middle of a word is turned into link.
Version 0.3
- Fixed: Now “special chars”, including
?,&,(,), won’t cut the URL. - Fixed: Now (X)HTML tags don’t get cut into the URL when a tag is located right after the URL.
- Improved parsing speed.
Version 0.2
- Minor POSIX regular expression update: uses substrings instead of blasting whole string; avoids some faults.
Version 0.1
- First release