Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
drupal.org
link
Commits
766e6c38
Commit
766e6c38
authored
Sep 04, 2006
by
Nathan Haug
Browse files
Added argument to alter the default protocol in link_cleanup_url
parent
5b0ce76e
Changes
1
Hide whitespace changes
Inline
Side-by-side
link.module
View file @
766e6c38
...
@@ -415,9 +415,10 @@ function link_views_tables() {
...
@@ -415,9 +415,10 @@ function link_views_tables() {
* Forms a valid URL if possible from an entered address.
* Forms a valid URL if possible from an entered address.
* Trims whitespace and automatically adds an http:// to addresses without a protocol specified
* Trims whitespace and automatically adds an http:// to addresses without a protocol specified
*
*
* @param unknown_type $url
* @param string $url
* @param string $protocol The protocol to be prepended to the url if one is not specified
*/
*/
function
link_cleanup_url
(
$url
)
{
function
link_cleanup_url
(
$url
,
$protocol
=
"http"
)
{
$url
=
trim
(
$url
);
$url
=
trim
(
$url
);
// Check if there is no protocol specified
// Check if there is no protocol specified
...
@@ -426,7 +427,7 @@ function link_cleanup_url ($url) {
...
@@ -426,7 +427,7 @@ function link_cleanup_url ($url) {
// But should it be? Add an automatic http:// if it starts with a domain name
// But should it be? Add an automatic http:// if it starts with a domain name
$domain_match
=
preg_match
(
'/^(([a-z0-9]([a-z0-9\-_]*\.)+)(aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|[a-z]{2}))/i'
,
$url
);
$domain_match
=
preg_match
(
'/^(([a-z0-9]([a-z0-9\-_]*\.)+)(aero|arpa|biz|com|coop|edu|gov|info|int|jobs|mil|museum|name|nato|net|org|pro|travel|[a-z]{2}))/i'
,
$url
);
if
(
!
empty
(
$domain_match
))
{
if
(
!
empty
(
$domain_match
))
{
$url
=
"http
://"
.
$url
;
$url
=
$protocol
.
"
://"
.
$url
;
}
}
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment