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 16:11:36 -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(); + + // Make 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'])) { + // Make 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'), @@ -2029,7 +2045,7 @@ 'title' => t('Edit'), 'href' => "node/$release->nid/edit", ); - } + }f // Figure out the class for the table row $row_class = $release->rebuild ? 'release-dev' : 'release'; // Now, set the row color and help text, based on the release attributes. @@ -2237,8 +2253,10 @@ * function takes the 'project_release_download_base' setting into * account, so it should be used everywhere a download link is made. * - * @param $filepath - * The path to the download file, as stored in the database. + * @param $node + * The release node with the release information and the release files. + * @param $fid + * The index of the file for the download link. * @param $link_text * The text to use for the download link. If NULL, the basename * of the given $filepath is used. @@ -2247,7 +2265,10 @@ * @return * The link itself, as a structured array. */ -function theme_project_release_download_link($filepath, $link_text = NULL, $as_array = FALSE) { +function theme_project_release_download_link($node, $fid, $link_text = NULL, $as_array = FALSE) { + // Load the filepath. + $filepath = $node->project_release['files'][$fid]->filepath; + if (empty($link_text)) { $link_text = basename($filepath); } @@ -2367,13 +2388,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, ),