You are here

function freelinking_nodetitle_nid_from_title in Freelinking 6.3

Grab the nid associated with the title. Attempt some degree of language sensibility.

1 call to freelinking_nodetitle_nid_from_title()
freelinking_nodetitle_callback in plugins/freelinking_nodetitle.inc
Replacement callback for nodetitle plugin

File

plugins/freelinking_nodetitle.inc, line 103

Code

function freelinking_nodetitle_nid_from_title(&$target) {
  $params['title'] = $target['dest'];
  $default_type = variable_get('freelinking_nodetitle_searchcontenttype', 'none');
  if (isset($target['type'])) {
    $params['type'] = $target['type'];
  }
  elseif ($default_type != 'none') {
    $params['type'] = $default_type;
  }
  $set = node_load($params);
  if (is_object($set)) {
    $set = array(
      $set,
    );
  }
  if (empty($set)) {
    return NULL;
  }

  // language restriction. Includes next-best-language logic.
  $language = array(
    language_default('language'),
    '',
  );
  if (module_exists('locale')) {
    if ($target['language']) {
      array_unshift($language, $target['language']);
    }
    foreach ($language as $priority) {
      foreach ($set as $node) {
        if ($priority == $node->language) {
          $retn = $node;
          break 2;
        }
      }
    }
  }
  else {
    $retn = $set[0];
  }
  if (node_access('view', $retn)) {
    return $retn;
  }
}