You are here

function _freelinking_store in Freelinking 5

Same name and namespace in other branches
  1. 6 freelinking.module \_freelinking_store()
  2. 6.2 freelinking.module \_freelinking_store()
2 calls to _freelinking_store()
_freelinking_do_filtering in ./freelinking.module
_freelinking_make_link in ./freelinking.module

File

./freelinking.module, line 436

Code

function _freelinking_store($phrase, $path, $args = NULL) {

  // store freelinking pair in the db
  $hash = md5($phrase . $path . $args);
  $query = "SELECT hash FROM {freelinking} WHERE phrase = '%s'";
  $result = db_query($query, $phrase);
  if (!db_num_rows($result)) {

    // not in the db
    $query = "INSERT INTO {freelinking} (hash, phrase, path, args) VALUES ('%s', '%s', '%s', '%s')";
    $result = db_query($query, $hash, $phrase, $path, $args);
  }
  else {

    // in the db, but does it match?
    $dbhash = db_fetch_object($result);
    if ($dbhash->hash != $hash) {

      // hashes don't match, replace db entry with new values
      $query = "UPDATE {freelinking} SET hash = '%s', path = '%s', args = '%s' WHERE phrase = '%s'";
      $result = db_query($query, $hash, $path, $args, $phrase);
    }

    // endif hashes don't match
  }

  // endifelse row found
}