Index: modules/upload.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/upload.module,v
retrieving revision 1.44
diff -u -r1.44 upload.module
--- modules/upload.module 22 Jul 2005 19:06:19 -0000 1.44
+++ modules/upload.module 28 Jul 2005 21:12:53 -0000
@@ -1,5 +1,5 @@
files = upload_load($node);
-
- // Double check existing files:
- if (is_array($node->list)) {
- foreach ($node->list as $key => $value) {
- if ($file = file_check_upload($key)) {
- $node->files[$file->source] = $file;
- $node->files[$key]->list = $node->list[$key];
- $node->files[$key]->remove = $node->remove[$key];
- if ($file->source) {
- $filesize += $file->filesize;
- }
- }
- }
- }
- else {
- foreach ($node->files as $key => $file) {
- $node->list[$key] = $file->list;
- }
- }
-
- if (($file = file_check_upload('upload')) && user_access('upload files')) {
- global $user;
-
- $file = _upload_image($file);
-
- // Don't do any checks for uid #1.
- if ($user->uid != 1) {
- // Validate file against all users roles. Only denies an upload when
- // all roles prevent it.
- $total_usersize = upload_space_used($user->uid) + $filesize;
- foreach ($user->roles as $rid => $name) {
- $extensions = variable_get("upload_extensions_$rid", 'jpg jpeg gif png txt html doc xls pdf ppt pps');
- $uploadsize = variable_get("upload_uploadsize_$rid", 1) * 1024 * 1024;
- $usersize = variable_get("upload_usersize_$rid", 1) * 1024 * 1024;
-
- $regex = '/\.('. ereg_replace(' +', '|', preg_quote($extensions)) .')$/i';
-
- if (!preg_match($regex, $file->filename)) {
- $error['extension']++;
- }
-
- if ($uploadsize && $file->filesize > $uploadsize) {
- $error['uploadsize']++;
- }
-
- if ($usersize && $total_usersize + $file->filesize > $usersize) {
- $error['usersize']++;
- }
- }
- }
-
- // Rename possibly executable scripts to prevent accidental execution.
- // Uploaded files are attachments and should be shown in their original
- // form, rather than run.
- if (preg_match('/\.(php|pl|py|cgi|asp)$/i', $file->filename)) {
- $file->filename .= '.txt';
- $file->filemime = 'text/plain';
- }
-
- if ($error['extension'] == count($user->roles) && $user->uid != 1) {
- form_set_error('upload', t('The selected file %name can not be attached to this post, because it is only possible to attach files with the following extensions: %files-allowed.', array('%name' => theme('placeholder', $file->filename), '%files-allowed' => theme('placeholder', $extensions))));
- }
- elseif ($error['uploadsize'] == count($user->roles) && $user->uid != 1) {
- form_set_error('upload', t('The selected file %name can not be attached to this post, because it exceeded the maximum filesize of %maxsize.', array('%name' => theme('placeholder', $file->filename), '%maxsize' => theme('placeholder', format_size($uploadsize)))));
- }
- elseif ($error['usersize'] == count($user->roles) && $user->uid != 1) {
- form_set_error('upload', t('The selected file %name can not be attached to this post, because the disk quota of %quota has been reached.', array('%name' => theme('placeholder', $file->filename), '%quota' => theme('placeholder', format_size($usersize)))));
- }
- else {
- $key = 'upload_'. count($_SESSION['file_uploads']);
- $file->source = $key;
- $file->list = 1;
- $file = file_save_upload($file);
- $node->files[$key] = $file;
- }
- }
+ $node = _upload_validate($node);
break;
case 'form post':
@@ -230,43 +155,8 @@
case 'view':
if ($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 $file) {
- if ($file->list) {
- $rows[] = array(
- ''. check_plain($file->filename) .'',
- format_size($file->filesize)
- );
- // We save the list of files still in preview for later
- if (!$file->fid) {
- $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).
- if (!variable_get('clean_url', 0)) {
- foreach ($previews as $file) {
- $old = file_create_filename($file->filename, file_create_path());
- $new = url($old);
- $node->body = str_replace($old, $new, $node->body);
- $node->teaser = str_replace($old, $new, $node->teaser);
- }
- }
-
- $teaser = $arg;
- // Add the attachments list
- if (count($rows) && !$teaser) {
- $node->body .= theme('table', $header, $rows, array('id' => 'attachments'));
- }
+ $node = _upload_table($node);
+ $node = _upload_inline($node);
}
break;
@@ -305,26 +195,15 @@
return $output;
}
-/**
- * Determine how much disk space is occupied by a user's uploaded files.
- *
- * @param $uid
- * The integer user id of a user.
- * @return
- * The ammount of disk space used by the user in bytes.
- */
-function upload_space_used($uid) {
- return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE uid = %d', $uid));
-}
+function upload_count_size($uid = 0) {
+ if ($uid) {
+ $result = db_query("SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid WHERE uid = %d", $uid);
+ }
+ else {
+ $result = db_query("SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid");
+ }
-/**
- * Determine how much disk space is occupied by uploaded files.
- *
- * @return
- * The ammount of disk space used by uploaded files in bytes.
- */
-function upload_total_space_used() {
- return db_result(db_query('SELECT SUM(f.filesize) FROM {files} f INNER JOIN {node} n ON f.nid = n.nid'));
+ return db_result($result);
}
function upload_save($node) {
@@ -336,8 +215,8 @@
// Insert new files:
if ($file = file_save_upload($file, $file->filename)) {
$fid = db_next_id('{files}_fid');
- db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list) VALUES (%d, %d, '%s', '%s', '%s', %d, %d)",
- $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key]);
+ db_query("INSERT INTO {files} (fid, nid, filename, filepath, filemime, filesize, list, inline) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, %d)",
+ $fid, $node->nid, $file->filename, $file->filepath, $file->filemime, $file->filesize, $node->list[$key], $node->inline[$key]);
}
}
else {
@@ -349,6 +228,9 @@
if ($file->list != $node->list[$key]) {
db_query("UPDATE {files} SET list = %d WHERE fid = %d", $node->list[$key], $key);
}
+ if ($file->inline != $node->inline[$key]) {
+ db_query("UPDATE {files} SET inline = %d WHERE fid = %d", $node->inline[$key], $key);
+ }
}
}
return;
@@ -363,14 +245,16 @@
}
function upload_form($node) {
- $header = array(t('Delete'), t('List'), t('Url'), t('Size'));
+ $header = array(t('Delete'), t('List'), t('Inline'), t('Url'), t('Size'));
$rows = array();
if (is_array($node->files)) {
foreach ($node->files as $key => $file) {
+ $is_image = ereg('^(image/)', $file->filemime);
$rows[] = array(
form_checkbox('', "remove][$key", 1, $file->remove),
form_checkbox('', "list][$key", 1, $file->list),
+ form_checkbox('', "inline][$key", 1, $file->inline, '', $is_image ? '' : array('disabled'=>'disabled')),
$file->filename ."
". file_create_url(($file->fid ? $file->filepath : file_create_filename($file->filename, file_create_path()))) ."",
format_size($file->filesize)
);
@@ -385,7 +269,7 @@
$output .= form_button(t('Attach'), 'fileop');
}
- return '