Index: filefield.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/filefield/filefield.module,v retrieving revision 1.186 diff -u -r1.186 filefield.module --- filefield.module 30 Mar 2009 16:08:54 -0000 1.186 +++ filefield.module 31 Mar 2009 05:15:09 -0000 @@ -774,3 +774,43 @@ } return $references; } + +/** + * Get all FileField files connected to a node ID. + * + * @param $nid + * The node object. + * @param $field_name + * Optional. The CCK field name. + * @return + * An array of all files attached to that field (or all fields). + */ +function filefield_get_node_files($node, $field_name = NULL) { + $files = array(); + + // Get a list of fields. If $field_name is NULL, all fields are returned. + $fields = content_fields($field_name, $node->type); + if (isset($field_name)) { + $fields = array($fields); + } + + // Get the file rows. + $files = array(); + foreach ($fields as $field) { + if ($field['field_type'] != 'filefield') { + continue; + } + + $db_info = content_database_info($field); + $sql = "SELECT f.* FROM {files} f INNER JOIN {" . $db_info['table'] . "} c ON f.fid = c." . $db_info['columns']['fid']['column']; + if (isset($nid)) { + $sql .= ' AND c.vid = %d'; + } + $result = db_query($sql, $node->vid); + while ($file = db_fetch_array($file)) { + $files[$file['fid']] = $file; + } + } + + return $files; +}