[drupal-devel] [feature] Handle external URLs
syscrusher
drupal-devel at drupal.org
Sat Apr 2 02:42:31 UTC 2005
Issue status update for http://drupal.org/node/19842
Project: Drupal
Version: cvs
Component: base system
Category: feature requests
Priority: normal
Assigned to: chx
Reported by: chx
Updated by: syscrusher
Status: patch
I don't know if this will help you, but here's some with a pregexp patch
that I wrote to handle this problem for a contrib add-on (field_url.inc)
for the CVS version of Flexinode. Perhaps you can adapt this to work in
your situation:
function flexinode_field_url_format($field, $node, $brief = 0) {
$fieldname = 'flexinode_'. $field->field_id;
$output = drupal_specialchars($node->$fieldname);
if (strlen($output) && ! preg_match('%^(\w+://|\w*/)%',$output)) {
$output = 'http://' . $output;
}
return $output ? ''. $output .' [1]' : '';
}
The regular expression works with any arbitrary protocol spec, because
it will match any "word class" character. So http, mailto, ftp, irc,
and so on will all be matched properly.
People who helped test this for me as I contributed to the Flexinode
team found no bugs; everyone who tested it reported that it worked as
intended, though of course I can't say it has been tested with every
conceivable URL.
I hope this is useful to you; if not, I apologize for the bandwidth
consumption.
--Scott (scott at 4th dot com)
[1] http://drupal.org/'. $output .'
syscrusher
Previous comments:
------------------------------------------------------------------------
April 1, 2005 - 18:50 : chx
Attachment: http://drupal.org/files/issues/externalurl.patch (448 bytes)
This very simple patch lets you add external URLs to your menu or
wherever, 'cos I patched url() itself.
Please consider for 4.6.
------------------------------------------------------------------------
April 1, 2005 - 19:02 : Morbus Iff
Too naive, IMO. Needs ftp, nntp, irc, aim, blah blah blah.
------------------------------------------------------------------------
April 1, 2005 - 19:02 : Morbus Iff
Oh, and mailto.
------------------------------------------------------------------------
April 1, 2005 - 20:11 : chx
Attachment: http://drupal.org/files/issues/externalurl_0.patch (571 bytes)
and e2dk or whatever. A path is external if a) it begins with mailto: b)
method: followed by a slash. method is loosely defined as a sequence of
any characters but slash. This will evaluate a Drupal path
foor:bar/this/that external. However trackerpage/http://whatever has a
slash before the : so it will be an internal URL.
------------------------------------------------------------------------
April 1, 2005 - 20:13 : chx
Attachment: http://drupal.org/files/issues/externalurl_1.patch (480 bytes)
Oh, bad patch version :( again :(
------------------------------------------------------------------------
April 1, 2005 - 20:18 : asimmonds
I'm fairly certain external URLs already work in with url() if you have
Clean URLs enabled.
IMO http://drupal.org/node/10888 is a cleaner solution for people who
can't use Clean URLs.
More information about the drupal-devel
mailing list