function filehash_node_view in File Hash 7
Implements hook_node_view().
File
- ./
filehash.module, line 127 - Generate hashes for each uploaded file.
Code
function filehash_node_view($node, $view_mode) {
static $fields;
// Add <media:hash> elements for at most one file per RSS item.
if ($view_mode != 'rss') {
return;
}
// The <media:hash> element only supports MD5 and SHA-1.
$algos = filehash_algos();
if (!isset($algos['md5']) && !isset($algos['sha1'])) {
return;
}
if (!isset($fields[$node->type])) {
$fields[$node->type] = field_read_fields(array(
'bundle' => $node->type,
'entity_type' => 'node',
// The following field types are currently supported.
'type' => array(
'file',
'image',
'media',
),
));
}
foreach ($fields[$node->type] as $field) {
if ($items = field_get_items('node', $node, $field['field_name'])) {
foreach ($items as $file) {
// Media fields have a file object rather than a file array.
if ($field['type'] == 'media') {
filehash_rss_elements((array) $file['file'], $node);
return;
}
elseif ($field['type'] == 'image' || $file['display']) {
filehash_rss_elements($file, $node);
return;
}
}
}
}
}