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
23b11c71
Commit
23b11c71
authored
Apr 16, 2007
by
Nathan Haug
Browse files
Adding token support to link module.
parent
1b1ea9c3
Changes
1
Hide whitespace changes
Inline
Side-by-side
link.module
View file @
23b11c71
...
@@ -229,7 +229,21 @@ function link_widget($op, &$node, $field, &$node_field) {
...
@@ -229,7 +229,21 @@ function link_widget($op, &$node, $field, &$node_field) {
'#type'
=>
'markup'
,
'#type'
=>
'markup'
,
'#value'
=>
'<div id="'
.
str_replace
(
'_'
,
'-'
,
$field
[
'field_name'
])
.
'-wrapper" class="clear-block"></div>'
,
'#value'
=>
'<div id="'
.
str_replace
(
'_'
,
'-'
,
$field
[
'field_name'
])
.
'-wrapper" class="clear-block"></div>'
,
);
);
// Add token module replacements if available
if
(
module_exists
(
'token'
))
{
$form
[
$field
[
'field_name'
]][
'tokens'
]
=
array
(
'#type'
=>
'fieldset'
,
'#collapsible'
=>
TRUE
,
'#collapsed'
=>
TRUE
,
'#title'
=>
t
(
'Placeholder tokens'
),
'#description'
=>
t
(
"The following placeholder tokens can be used in both paths and titles. When used in a path or title, they will be replaced with the appropriate values."
),
);
$form
[
$field
[
'field_name'
]][
'tokens'
][
'help'
]
=
array
(
'#value'
=>
theme
(
'token_help'
,
'node'
),
);
}
// Add 'More' Javascript Callback
// Add 'More' Javascript Callback
$form
[
$field
[
'field_name'
]][
'more-url'
]
=
array
(
$form
[
$field
[
'field_name'
]][
'more-url'
]
=
array
(
'#type'
=>
'hidden'
,
'#type'
=>
'hidden'
,
...
@@ -496,7 +510,7 @@ function link_field_formatter($field, $item, $formatter, $node) {
...
@@ -496,7 +510,7 @@ function link_field_formatter($field, $item, $formatter, $node) {
}
}
$type
=
link_validate_url
(
$item
[
'url'
]);
$type
=
link_validate_url
(
$item
[
'url'
]);
$url
=
link_cleanup_url
(
$item
[
'url'
]);
$url
=
link_cleanup_url
(
$item
[
'url'
]
,
'http'
,
$node
);
// Seperate out the anchor if any
// Seperate out the anchor if any
if
(
strpos
(
$url
,
'#'
)
!==
FALSE
)
{
if
(
strpos
(
$url
,
'#'
)
!==
FALSE
)
{
...
@@ -519,6 +533,10 @@ function link_field_formatter($field, $item, $formatter, $node) {
...
@@ -519,6 +533,10 @@ function link_field_formatter($field, $item, $formatter, $node) {
}
}
// Build the link with a title
// Build the link with a title
elseif
(
strlen
(
trim
(
$item
[
'title'
])))
{
elseif
(
strlen
(
trim
(
$item
[
'title'
])))
{
// Replace tokens
if
(
module_exists
(
'token'
))
{
$item
[
'title'
]
=
token_replace
(
$item
[
'title'
],
'node'
,
$node
);
}
$output
=
l
(
$item
[
'title'
],
$url
,
$attributes
,
$query
,
$fragment
);
$output
=
l
(
$item
[
'title'
],
$url
,
$attributes
,
$query
,
$fragment
);
}
}
...
@@ -644,9 +662,15 @@ function link_views_protocol_filter_handler($op, $filter, $filterinfo, &$query)
...
@@ -644,9 +662,15 @@ function link_views_protocol_filter_handler($op, $filter, $filterinfo, &$query)
* @param string $url
* @param string $url
* @param string $protocol The protocol to be prepended to the url if one is not specified
* @param string $protocol The protocol to be prepended to the url if one is not specified
*/
*/
function
link_cleanup_url
(
$url
,
$protocol
=
"http"
)
{
function
link_cleanup_url
(
$url
,
$protocol
=
"http"
,
$node
=
NULL
)
{
$url
=
trim
(
$url
);
$url
=
trim
(
$url
);
$type
=
link_validate_url
(
$url
);
$type
=
link_validate_url
(
$url
);
// Replace tokens
if
(
module_exists
(
'token'
))
{
$url
=
token_replace
(
$url
,
'node'
,
$node
);
}
if
(
$type
==
LINK_EXTERNAL
)
{
if
(
$type
==
LINK_EXTERNAL
)
{
// Check if there is no protocol specified
// Check if there is no protocol specified
$protocol_match
=
preg_match
(
"/^([a-z0-9][a-z0-9\.\-_]*:\/\/)/i"
,
$url
);
$protocol_match
=
preg_match
(
"/^([a-z0-9][a-z0-9\.\-_]*:\/\/)/i"
,
$url
);
...
@@ -676,7 +700,7 @@ function link_validate_url($text) {
...
@@ -676,7 +700,7 @@ function link_validate_url($text) {
$allowed_protocols
=
variable_get
(
'filter_allowed_protocols'
,
array
(
'http'
,
'https'
,
'ftp'
,
'news'
,
'nntp'
,
'telnet'
,
'mailto'
,
'irc'
,
'ssh'
,
'sftp'
,
'webcal'
));
$allowed_protocols
=
variable_get
(
'filter_allowed_protocols'
,
array
(
'http'
,
'https'
,
'ftp'
,
'news'
,
'nntp'
,
'telnet'
,
'mailto'
,
'irc'
,
'ssh'
,
'sftp'
,
'webcal'
));
$protocol
=
'(('
.
implode
(
"|"
,
$allowed_protocols
)
.
'):\/\/)'
;
$protocol
=
'(('
.
implode
(
"|"
,
$allowed_protocols
)
.
'):\/\/)'
;
$domain
=
'(([a-z0-9]([a-z0-9\-_]*\.)+)('
.
LINK_DOMAINS
.
'|[a-z]{2}))'
;
$domain
=
'(([a-z0-9]([a-z0-9\-_
\[\]
]*\.)+)('
.
LINK_DOMAINS
.
'|[a-z]{2}))'
;
$ipv4
=
'([0-9]{1,3}(\.[0-9]{1,3}){3})'
;
$ipv4
=
'([0-9]{1,3}(\.[0-9]{1,3}){3})'
;
$ipv6
=
'([0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})'
;
$ipv6
=
'([0-9a-fA-F]{1,4}(\:[0-9a-fA-F]{1,4}){7})'
;
$port
=
'(:([0-9]{1,4}))'
;
$port
=
'(:([0-9]{1,4}))'
;
...
@@ -685,16 +709,16 @@ function link_validate_url($text) {
...
@@ -685,16 +709,16 @@ function link_validate_url($text) {
$external_pattern
=
'/^'
.
$protocol
.
'?'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
' |localhost)'
.
$port
.
'?'
;
$external_pattern
=
'/^'
.
$protocol
.
'?'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
' |localhost)'
.
$port
.
'?'
;
// Pattern specific to internal links
// Pattern specific to internal links
$internal_pattern
=
"/^([a-z0-9_\-+]+)"
;
$internal_pattern
=
"/^([a-z0-9_\-+
\[\]
]+)"
;
$directories
=
"(\/[a-z0-9_\-\.~+%=&,$'():;*@]*)*"
;
$directories
=
"(\/[a-z0-9_\-\.~+%=&,$'():;*@
\[\]
]*)*"
;
$query
=
"(\/?\?[a-z0-9+_\-\.\/%=&,$'():;*@]*)"
;
$query
=
"(\/?\?[a-z0-9+_\-\.\/%=&,$'():;*@
\[\]
]*)"
;
$anchor
=
"(#[a-z0-9_\-\.~+%=&,$'():;*@]*)"
;
$anchor
=
"(#[a-z0-9_\-\.~+%=&,$'():;*@
\[\]
]*)"
;
// the rest of the path for a standard URL
// the rest of the path for a standard URL
$end
=
$directories
.
'?'
.
$query
.
'?'
.
$anchor
.
'?'
.
'$/i'
;
$end
=
$directories
.
'?'
.
$query
.
'?'
.
$anchor
.
'?'
.
'$/i'
;
$user
=
'[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\']+'
;
$user
=
'[a-zA-Z0-9_\-\.\+\^!#\$%&*+\/\=\?\`\|\{\}~\'
\[\]
]+'
;
$email_pattern
=
'/^mailto:'
.
$user
.
'@'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
'|localhost)'
.
$query
.
'$/'
;
$email_pattern
=
'/^mailto:'
.
$user
.
'@'
.
'('
.
$domain
.
'|'
.
$ipv4
.
'|'
.
$ipv6
.
'|localhost)'
.
$query
.
'$/'
;
if
(
preg_match
(
$external_pattern
.
$end
,
$text
))
{
if
(
preg_match
(
$external_pattern
.
$end
,
$text
))
{
...
...
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