You are here

function freelinking_freelink_alter in Freelinking 6.3

Same name and namespace in other branches
  1. 7.3 freelinking.module \freelinking_freelink_alter()

Implementation of hook_freelink_alter(). Used here to clean up and standardize links.

File

./freelinking.module, line 139

Code

function freelinking_freelink_alter(&$link, $target, $plugin_name, $plugin) {

  // not a valid link
  if (!isset($link[1])) {
    $link['error'] = t('Invalid Link');
    return;
  }

  // title text is empty, insert from target or use URL
  if (!$link[0]) {
    $link[0] = $target['text'] ? $target['text'] : $target['target'];
  }

  // support html link text unless plugin overrides
  if ($plugin['html'] !== FALSE) {
    $link[2]['html'] = TRUE;
  }

  // Set an empty tooltip as the URL (unless the target has one)
  if (!isset($link[2]['attributes']['title'])) {
    $link[2]['attributes']['title'] = $target['tooltip'] ? $target['tooltip'] : $link[1];
  }

  // standard set of CSS classes
  if (isset($link[2]['attributes']['class'])) {
    $classes = $link[2]['attributes']['class'];
  }
  else {
    $classes = '';
  }
  $link[2]['attributes']['class'] = rtrim('freelink freelink-' . strtr($plugin_name, ' ', '-') . ' ' . $classes);

  // There was more than one effort to generate the link
  if (isset($target['other']['trace'])) {
    $link[2]['attributes']['class'] .= ' notfound';
  }

  // Is this an internal or external link?
  $parts = parse_url($link[1]);
  if (isset($parts['host']) && $parts['host'] != $_SERVER['SERVER_NAME']) {
    $link[2]['attributes']['class'] .= ' freelink-external';
  }
  else {
    $link[2]['attributes']['class'] .= ' freelink-internal';
  }
}