freelinking_nid.inc in Freelinking 7.3
File
plugins/freelinking_nid.inc
View source
<?php
$freelinking['nid'] = array(
'indicator' => '/(n(id|ode)?)$/A',
'callback' => 'freelinking_nid_callback',
'tip' => t('Click to view a local node.'),
'run on view' => TRUE,
);
function freelinking_nid_callback($target, $plugin) {
$node_cache_nid =& drupal_static(__FUNCTION__ . '_node_cache', array());
$nid = $target['dest'];
$nodes =& drupal_static(__FUNCTION__, array());
if (in_array($nid, $nodes)) {
$key = array_search($nid, $node_cache_nid['nid']);
$value = array(
$target['text'],
'node/' . $nid,
array(
'attributes' => array(
'title' => $target['tooltip'],
),
),
);
return $value;
}
$node = node_load($nid);
if ($node) {
if (node_access('view', $node)) {
$title = $target['text'] ? $target['text'] : $node->title;
$tooltip = $target['tooltip'] ? $target['tooltip'] : $plugin['tip'];
$value = array(
check_plain($title),
'node/' . $nid,
array(
'attributes' => array(
'title' => $tooltip,
),
),
);
$nodes[] = $nid;
$node_cache_nid['nid'][] = $node->nid;
}
}
if (!isset($value)) {
$value = array(
'failover' => 'error',
'message' => t('Invalid Node ID “!nid”', array(
'!nid' => $nid,
)),
);
}
return $value;
}