You are here

function _freelinking_exists in Freelinking 6

Same name and namespace in other branches
  1. 5 freelinking.module \_freelinking_exists()
  2. 6.2 freelinking.module \_freelinking_exists()
3 calls to _freelinking_exists()
freelinking_nodeapi in ./freelinking.module
freelinking_page_form in ./freelinking.module
_freelinking_make_link in ./freelinking.module

File

./freelinking.module, line 537

Code

function _freelinking_exists($thetitle) {

  // helper function for freelinking_page
  global $language;

  // looks through the db for nodes matching $title. Returns the nid if such a node exists, otherwise, returns 0
  $title = urldecode($thetitle);
  $query = "SELECT nid FROM {node} WHERE title = '%s'";
  if (module_exists('locale')) {
    $query .= " AND (language = '{$language->language}' OR language = '')";
  }
  $noderestrict = variable_get('freelinking_restriction', array(
    'none',
  ));
  if (is_array($noderestrict) && !in_array('none', $noderestrict)) {

    // need to add the where clause
    foreach ($noderestrict as $restrictedtype) {
      $clauseparts[] = 'type = \'' . $restrictedtype . '\'';
    }
    $restrictions = implode(' OR ', $clauseparts);
    $query .= " AND (" . $restrictions . ')';
  }
  $result = db_query($query, $title);

  // FIXME ***
  while ($node = db_fetch_object($result)) {

    // only one, I hope... what if there's more than one?
    $nid = $node->nid;
  }
  return empty($nid) ? 0 : $nid;
}