function _freelinking_build_freelink in Freelinking 6.3
Same name and namespace in other branches
- 7.3 freelinking.module \_freelinking_build_freelink()
Construct a link out of the $target with the specified plugin
1 call to _freelinking_build_freelink()
- freelinking_get_freelink in ./
freelinking.utilities.inc - Process the target text into a link with the specified plugin.
File
- ./
freelinking.module, line 229
Code
function _freelinking_build_freelink($freelinking, $plugin_name, $target) {
// by default return false so no replacement happens
$plugin =& $freelinking[$plugin_name];
// if a plugin does not exist, go to failure.
if (!$plugin) {
return array(
'error' => t('Plugin %plugin Not Found', array(
'%plugin' => $plugin_name,
)),
);
}
// run the text through translation
if (isset($plugin['translate'])) {
$target['dest'] = strtr($target['dest'], $plugin['translate']);
}
// process simple replacement plugins if no callback exists
if (isset($plugin['replacement']) && !isset($plugin['callback'])) {
// %1 is the token all freelinking replacement strings must include
$url = preg_replace('/%1/', $target['dest'], $plugin['replacement']);
$link = array(
'',
$url,
);
}
// process replacement callback
if (isset($plugin['callback']) && function_exists($plugin['callback'])) {
$link = call_user_func_array($plugin['callback'], array(
$target,
$plugin,
));
}
// Standardize link, grab authoritative "structured" version
// designate the rendered text for display
if (is_array($link)) {
if (isset($link['failover'])) {
if ($link['failover'] == 'showtext') {
$target = $link['target']['text'] ? $link['target']['text'] : $link['target']['dest'];
return $target;
}
elseif ($link['failover'] != 'error' && $link['failover'] != 'none') {
$target = $link['target'] ? $link['target'] : $target;
$target['other']['trace'][] = $plugin_name;
unset($freelinking[$plugin_name]);
return _freelinking_build_freelink($freelinking, $link['failover'], $target);
}
}
if (is_array($link) && !isset($link['error'])) {
drupal_alter('freelink', $link, $target, $plugin_name, $plugin);
}
}
// if empty/false, nothing will happen
return $link;
}