function _download_count_get_nodes_by_filefield in Download Count 7.2
Same name and namespace in other branches
- 6.2 download_count.module \_download_count_get_nodes_by_filefield()
2 calls to _download_count_get_nodes_by_filefield()
- download_count_file_download in ./download_count.module
- Implements hook_file_download().
- _download_count_is_accessible_by_filefield in ./download_count.module
File
- ./download_count.module, line 353
- Tracks file downloads for files stored in the drupal files table using the private files setting or custom private filefield.
Code
function _download_count_get_nodes_by_filefield($file) {
if (!function_exists('filefield_view_access')) {
return NULL;
}
$result = db_query("SELECT * FROM {files} WHERE filepath = :filepath", array(
':filepath' => $file,
));
if (!($file = db_fetch_object($result))) {
return NULL;
}
$cck_files = array();
foreach (content_fields() as $field) {
if ($field['type'] == 'filefield' || $field['type'] == 'image') {
$db_info = content_database_info($field);
$table = $db_info['table'];
$fid_column = $db_info['columns']['fid']['column'];
$columns = array(
'vid',
'nid',
);
foreach ($db_info['columns'] as $property_name => $column_info) {
$columns[] = $column_info['column'] . ' AS ' . $property_name;
}
$result = db_query("SELECT " . implode(', ', $columns) . "\n FROM {" . $table . "}\n WHERE " . $fid_column . " = %d", $file->fid);
while ($content = db_fetch_array($result)) {
$content['field'] = $field;
$cck_files[$field['field_name']][$content['vid']] = $content;
}
}
}
if (empty($cck_files)) {
return NULL;
}
foreach ($cck_files as $field_name => $field_files) {
if (!filefield_view_access($field_name)) {
return FALSE;
}
}
$nodes = array();
$denied = FALSE;
foreach ($cck_files as $field_name => $field_files) {
foreach ($field_files as $revision_id => $content) {
if (isset($nodes[$content['nid']])) {
continue;
}
if ($denied == FALSE && ($node = node_load($content['nid'])) && node_access('view', $node) == FALSE) {
$denied = TRUE;
}
$nodes[$content['nid']] = $node;
}
if ($denied) {
return FALSE;
}
}
return $nodes;
}