Index: release/project_release.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/project/release/project_release.module,v retrieving revision 1.106 diff -u -r1.106 project_release.module --- release/project_release.module 7 Feb 2009 10:26:42 -0000 1.106 +++ release/project_release.module 13 Feb 2009 12:51:14 -0000 @@ -288,7 +288,7 @@ 'version_major', 'version_minor', 'version_patch', 'version_extra', 'tag', 'version' ); foreach ($release_values as $field) { - $node->project_release[$field] = $release->project_release[$field]; + $node->project_release[$field] = $release->project_release[$field]; } } $release->project_release = $node->project_release; @@ -349,13 +349,8 @@ if (!empty($release->project_release['files'])) { $files = $release->project_release['files']; foreach ($files as $fid => $file) { - // In the case of previews, we only have the fid of the file, - // so check for that and load the file object if necessary. - if (is_numeric($file)) { - $file = project_release_load_file($file); - } $form['project_release_files'][$fid]['file_info'] = array( - '#value' => theme('project_release_download_file', $file, FALSE), + '#value' => theme('project_release_download_file', $release, $fid, FALSE), ); if ($admin) { $form['project_release_files'][$fid]['delete'] = array( @@ -992,8 +987,9 @@ if ($node->created) { $output .= ''. t('First released: !created', array('!created' => format_date($node->created))) .'
'; } + if (!empty($node->project_release['files'])) { - foreach ($node->project_release['files'] as $fid => $file) { + foreach ($node->project_release['files'] as $fid => $file) { // In the case of previews, we only have the fid of the file, // so check for that and load the file object if necessary. if (is_numeric($file)) { @@ -1003,7 +999,7 @@ // then don't display. if (empty($node->project_release_files[$fid]['delete'])) { $output .= '
'; - $output .= theme('project_release_download_file', $file); + $output .= theme('project_release_download_file', $node, $fid); $output .= '
'; } } @@ -1042,14 +1038,18 @@ return db_fetch_object(db_query("SELECT f.*, prf.filehash FROM {project_release_file} prf INNER JOIN {files} f ON prf.fid = f.fid WHERE f.fid = %d", $fid)); } -function theme_project_release_download_file($file, $download_link = TRUE) { - $output = ''; - if ($download_link) { - $output .= ''. t('Download: !file', array('!file' => theme('project_release_download_link', $file->filepath))) .'
'; - } - else { - $output .= ''. t('File: @filepath', array('@filepath' => $file->filepath)) .'
'; +function theme_project_release_download_file($node, $fid) { + $file = $node->project_release['files'][$file]; + + // In the case of previews, we only have the fid of the file, + // so check for that and load the file object if necessary. + // Dries: I think this is a bit of a hack. It was already + // there, it is just slightly more exposed now ... + if (is_numeric($file)) { + $file = project_release_load_file($file); } + + $output = ''. t('Download: !file', array('!file' => theme('project_release_download_link', $node, $fid))) .'
'; $output .= ''. t('Size: !size', array('!size' => format_size($file->filesize))) .'
'; $output .= ''. t('md5_file hash: !filehash', array('!filehash' => $file->filehash)) .'
'; $output .= ''. t('Last updated: !changed', array('!changed' => format_date($file->timestamp))) .'
'; @@ -1658,15 +1658,21 @@ $node->teaser = $node->content['release_info']['#value'] . $node->teaser; // If the release node has a file, include an enclosure attribute for it. if (!empty($node->project_release['files'])) { + $file = reset(); + + // Mke sure array pointer is at the first element. + reset($node->project_release['files']); + // RSS will only take the first file. - $file = reset($node->project_release['files']); - $file_link = theme('project_release_download_link', $file->filepath, NULL, TRUE); + $fid = key($node->project_release['files']); + + $file_link = theme('project_release_download_link', $node, $fid, NULL, TRUE); return array( array( 'key' => 'enclosure', 'attributes' => array( 'url' => $file_link['href'], - 'length' => $file->filesize, + 'length' => $node->project_release['files'][$fid]->filesize, 'type' => 'application/octet-stream', ) ) @@ -1909,6 +1915,9 @@ // TODO: we MUST rewrite this query when multiple files attachments // per release node lands, as it will return a non-unique result set. + // Dries: I think this query will need to be rewritten now. We have + // to make sure that $node->project_release['files'] gets set properly + // or the theme layer will not display any downloads ... $result = db_query(db_rewrite_sql( "SELECT n.nid, n.created, f.filename, f.filepath, f.timestamp, ". "f.filesize, $select r.* FROM {node} n ". @@ -2016,9 +2025,16 @@ 'error' => 'misc/watchdog-error.png', ); } + $links = array(); - if (!empty($release->filepath)) { - $links['project_release_download'] = theme('project_release_download_link', $release->filepath, t('Download'), TRUE); + if (!empty($release->project_release['files'])) { + // Mke sure array pointer is at the first element. + reset($node->project_release['files']); + + // We will only take the first file because of legacy reasons. + $fid = key($node->project_release['files']); + + $links['project_release_download'] = theme('project_release_download_link', $node, $fid, t('Download'), TRUE); } $links['project_release_notes'] = array( 'title' => t('Release notes'), @@ -2367,13 +2383,15 @@ return array( 'project_release_download_file' => array( 'arguments' => array( - 'file' => NULL, + 'node' => NULL, + 'fid' => NULL, 'download_link' => TRUE, ), ), 'project_release_download_link' => array( 'arguments' => array( - 'filepath' => NULL, + 'node' => NULL, + 'fid' => NULL, 'link_text' => NULL, 'as_array' => FALSE, ),