function _freelinking_build_freelink in Freelinking 7.3
Same name and namespace in other branches
- 6.3 freelinking.module \_freelinking_build_freelink()
Construct a link out of the $target with the specified plugin
There are three built-in indicators that will not generate links:
- nowiki: will strip the nowiki-indicator and show the rest;
- showtext: as nowiki, but will also strip double brackets;
- redact: as showtext for logged in users, will redact for anon.
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 292
Code
function _freelinking_build_freelink($freelinking, $plugin_name, $target) {
if ('showtext' == $plugin_name) {
$text = $target['text'] ? $target['text'] : $target['dest'];
return $text;
}
if ('nowiki' == $plugin_name) {
$text = $target['text'] ? $target['text'] : $target['dest'];
return '[[' . $text . ']]';
}
if ('redact' == $plugin_name) {
if (user_is_logged_in()) {
$text = $target['dest'];
}
else {
$text = $target['text'] ? $target['text'] : '******';
}
return $text;
}
$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']) && $link['failover'] != 'error' && $link['failover'] != 'NONE') {
$target = isset($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'])) {
$data = array(
'target' => $target,
'plugin_name' => $plugin_name,
'plugin' => $plugin,
);
drupal_alter('freelink', $link, $data);
}
}
// if empty/false, nothing will happen
return $link;
}