freelinking_path.inc in Freelinking 7.3
File
plugins/freelinking_path.inc
View source
<?php
$freelinking['path'] = array(
'indicator' => '/path|alias/i',
'callback' => 'freelinking_path_callback',
'settings' => 'freelinking_path_settings',
'tip' => t('Click to view a local node.'),
'failover' => array(
'search',
),
);
function freelinking_path_callback($target, $plugin) {
$pos = strpos($target['dest'], '/');
if ($pos === FALSE || $pos > 0) {
$path = variable_get('freelinking_path_basepath', $_GET['q']) . '/' . $target['dest'];
}
elseif ($pos == 0) {
$path = substr($target['dest'], 1);
}
$item = menu_get_item(drupal_get_normal_path($path));
if (NULL == $item || !$item['access']) {
return array(
'failover' => variable_get('freelinking_path_failover', 'error'),
'message' => t('path “%path” not found', array(
'%path' => $target['dest'],
)),
);
}
if ($target['text']) {
$title = $target['text'];
}
elseif ($item) {
$title = $item['title'];
}
else {
$title = $path;
}
$value = array(
$title,
$path,
array(
'attributes' => array(
'title' => $target['tooltip'],
),
),
);
return $value;
}
function freelinking_path_settings() {
$form['freelinking_path_basepath'] = array(
'#type' => 'textfield',
'#title' => t('Starting path for relative links'),
'#default_value' => variable_get('freelinking_path_basepath', ''),
'#description' => t('Set the “base directory” internal to the site that all relative path links will build from (e.g. “node”). Leave empty for site root. (Relative path links have no initial slash or ending slash.)'),
);
return $form;
}