Index: modules/upload.module =================================================================== RCS file: /cvs/drupal/drupal/modules/upload.module,v retrieving revision 1.92 diff -F^f -u -u -F^f -r1.92 upload.module --- modules/upload.module 11 Apr 2006 11:33:15 -0000 1.92 +++ modules/upload.module 13 Apr 2006 14:26:11 -0000 @@ -341,30 +341,20 @@ function upload_nodeapi(&$node, $op, $ar case 'view': if (is_array($node->files) && user_access('view uploaded files')) { - $header = array(t('Attachment'), t('Size')); - $rows = array(); - $previews = array(); - // Build list of attached files - foreach ($node->files as $key => $file) { - if ($file->list) { - $rows[] = array( - ''. check_plain($file->description ? $file->description : $file->filename) .'', - format_size($file->filesize) - ); - // We save the list of files still in preview for later - if (strpos($file->fid, 'upload') !== false) { - $previews[] = $file; - } - } - } - - // URLs to files being previewed are actually Drupal paths. When Clean - // URLs are disabled, the two do not match. We perform an automatic - // replacement from temporary to permanent URLs. That way, the author - // can use the final URL in the body before having actually saved (to - // place inline images for example). + // first, manipulate so that inline references work in preview... if (!variable_get('clean_url', 0)) { + $previews = array(); + foreach ($node->files as $file) { + if (strpos($file->fid, 'upload') !== false) { + $previews[] = $file; + } + } + // URLs to files being previewed are actually Drupal paths. When Clean + // URLs are disabled, the two do not match. We perform an automatic + // replacement from temporary to permanent URLs. That way, the author + // can use the final URL in the body before having actually saved (to + // place inline images for example). foreach ($previews as $file) { $old = file_create_filename($file->filename, file_create_path()); $new = url($old); @@ -373,15 +363,16 @@ function upload_nodeapi(&$node, $op, $ar } } + // next, display the attached files $teaser = $arg; - // Add the attachments list - if (count($rows) && !$teaser) { - $node->body .= theme('table', $header, $rows, array('id' => 'attachments')); - } - } + // Add the attachments list to node body + if (count($node->files) && !$teaser) { + $node->body .= theme('upload_attachments', $node->files); + } + } break; - - case 'insert': + + case 'insert': case 'update': if (user_access('upload files')) { upload_save($node); @@ -422,6 +413,24 @@ function upload_nodeapi(&$node, $op, $ar } /** + * Displays file attachments in table + */ +function theme_upload_attachments($files) { + $header = array(t('Attachment'), t('Size')); + $rows = array(); + foreach ($files as $file) { + if ($file->list) { + $href = check_url(($file->fid ? file_create_url($file->filepath) : url(file_create_filename($file->filename, file_create_path())))); + $text = check_plain($file->description ? $file->description : $file->filename); + $rows[] = array(l($text, $href), format_size($file->filesize)); + } + } + if (count($rows)) { + return theme('table', $header, $rows, array('id' => 'attachments')); + } +} + +/** * Determine how much disk space is occupied by a user's uploaded files. * * @param $uid