function freelinking_freelink_alter in Freelinking 7.3
Same name and namespace in other branches
- 6.3 freelinking.module \freelinking_freelink_alter()
Implements hook_freelink_alter(). Used here to clean up and standardize links.
File
- ./
freelinking.module, line 235
Code
function freelinking_freelink_alter(&$link, $context) {
$target = $context['target'];
$plugin_name = $context['plugin_name'];
$plugin = $context['plugin'];
// not a valid link
if (!array_key_exists(1, $link)) {
$link['error'] = t('Invalid Link');
return;
}
// title text is empty, insert from target or use URL
if (empty($link[0])) {
$link[0] = $target['text'] ? $target['text'] : $target['dest'];
}
// support html link text unless plugin overrides
if (isset($plugin['html']) && $plugin['html'] == TRUE) {
$link[2]['html'] = TRUE;
}
// Set an empty tooltip
if (!isset($link[2]['attributes']['title'])) {
if (isset($context['plugin']['tip'])) {
$link[2]['attributes']['title'] = $context['plugin']['tip'];
}
else {
$link[2]['attributes']['title'] = $link[1];
}
}
// standard set of CSS classes
$link[2]['attributes']['class'][] = 'freelink';
$link[2]['attributes']['class'][] = 'freelink-' . strtr($plugin_name, ' ', '-');
// There was more than one effort to generate the link
if (isset($target['other']['trace'])) {
$link[2]['attributes']['class'][] = 'notfound';
}
// Is this an internal or external link?
$parts = parse_url($link[1]);
if (isset($parts['host']) && $parts['host'] != $_SERVER['SERVER_NAME']) {
$link[2]['attributes']['class'][] = 'freelink-external';
}
else {
$link[2]['attributes']['class'][] = 'freelink-internal';
}
}