You are here

function biblio_hash in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 biblio.module \biblio_hash()
  2. 6 biblio.module \biblio_hash()
  3. 7.2 biblio.module \biblio_hash()
1 call to biblio_hash()
biblio_insert in ./biblio.module
Implements hook_insert().

File

./biblio.module, line 2315
Bibliography Module for Drupal.

Code

function biblio_hash($node) {
  static $sums = array();
  $duplicate = NULL;
  if (empty($sums)) {
    $res = db_query("SELECT nid, biblio_md5 FROM {biblio} ");
    foreach ($res as $md5) {
      $sums[$md5->biblio_md5] = $md5->nid;
    }
  }
  $hash_string = str_replace(' ', '', drupal_strtolower($node->title));
  if (isset($node->biblio_contributors[0]['lastname'])) {
    $hash_string .= str_replace(' ', '', drupal_strtolower($node->biblio_contributors[0]['lastname']));
  }
  $hash_string .= $node->biblio_year;
  $sum = md5($hash_string);
  if (isset($sums[$sum])) {
    $duplicate = $sums[$sum];
  }
  else {
    $sums[$sum] = $node->nid;
  }
  $node->biblio_md5 = $sum;

  // Return the nid of the potential duplicate.
  return $duplicate;
}