function theme_download_count_formatter_download_count in Download Count 6.2
Same name and namespace in other branches
- 7.2 includes/download_count.theme.inc \theme_download_count_formatter_download_count()
File
- includes/
download_count.theme.inc, line 25 - Theme related functions for the download_count module.
Code
function theme_download_count_formatter_download_count($element) {
if (empty($element['#item']['fid'])) {
return '';
}
global $user;
$file = $element['#item'];
$node = $element['#node'];
$field = content_fields($element['#field_name']);
$filepath = $file['filepath'];
if (user_access('view own download counts') && $user->uid != 1) {
$count = db_result(db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = '%s' AND dc.nid = %d AND dc.uid = %d", $filepath, $node->nid, $user->uid));
}
elseif (user_access('view all download counts')) {
$count = db_result(db_query("SELECT COUNT(dc.dcid) FROM {download_count} dc JOIN {files} f ON dc.fid = f.fid WHERE f.filepath = '%s' AND dc.nid = %d", $filepath, $node->nid));
}
$output = theme('filefield_file', $file);
if ($output) {
if (user_access('view all download counts') || user_access('view own download counts')) {
$text = ' — ';
if ($count) {
$text .= format_plural($count, 'Downloaded 1 time', 'Downloaded @count times');
}
else {
$text .= t('Never downloaded');
}
}
else {
$text = '';
}
if (drupal_substr($output, -6) == '</div>') {
return drupal_substr($output, 0, -6) . $text . '</div>';
}
else {
return $output . $text;
}
}
return $output;
}