You are here

function freelinking_path_callback in Freelinking 7.3

Builds a link to an internal url

Return value

array with link properties

1 string reference to 'freelinking_path_callback'
freelinking_path.inc in plugins/freelinking_path.inc

File

plugins/freelinking_path.inc, line 31

Code

function freelinking_path_callback($target, $plugin) {

  // the first character is not a forward slash
  $pos = strpos($target['dest'], '/');
  if ($pos === FALSE || $pos > 0) {
    $path = variable_get('freelinking_path_basepath', $_GET['q']) . '/' . $target['dest'];
  }
  elseif ($pos == 0) {

    // scrape off the starting slash that marks this as an unmodified path from site root.
    $path = substr($target['dest'], 1);
  }

  //$node_cache_path = &drupal_static(__FUNCTION__ . '_node_cache', array());

  // Check if we already loaded this node.
  $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;
}