function biblio_advanced_import_hash in Biblio Advanced Import 7
Same name and namespace in other branches
- 6 biblio_advanced_import.module \biblio_advanced_import_hash()
Helper function to create a hash from a biblio node depending on a configurable duplicate detection strategy.
Parameters
$node: a biblio node
Return value
a md5 hash
See also
biblio_advanced_import_settings_form()
2 calls to biblio_advanced_import_hash()
- biblio_advanced_import_node_presave in ./
biblio_advanced_import.module - Implements hook_node_presave().
- biblio_advanced_import_update_hash in ./
biblio_advanced_import.module - Helper function to update the hash of a biblio node.
File
- ./
biblio_advanced_import.module, line 234 - Biblio add-on.
Code
function biblio_advanced_import_hash($node) {
$hash_string = '';
$duplicate_criteria = variable_get('biblio_advanced_import_duplicate_criteria', array(
'title' => 'title',
'biblio_year' => 'biblio_year',
));
foreach ($duplicate_criteria as $field) {
if ($field) {
$field_value = '';
if (isset($node->{$field})) {
$field_value = $node->{$field};
}
if ('biblio_year' == $field && (empty($field_value) || $field_value == t('Submitted'))) {
// If the year is empty, it will be set to 9999 by biblio on save.
// 9999 => "Submitted"
// Therefore we have to do the same here to not break duplicate detection.
// Furthermore, on load this magic value will is replaced with a translated version
// of the string "Submitted"; we hit this case when we rehash after a configuration change;
// we standardize all these cases on 9999 to arrive at consistent hash values
$field_value = 9999;
}
if ($field_value) {
if (is_array($field_value) || is_object($field_value)) {
$hash_string .= serialize($field_value);
}
else {
$hash_string .= preg_replace("/\\s+/", '', mb_strtolower(mb_substr($field_value, 0, 256)));
}
}
}
}
return md5(strtolower($hash_string));
}