Commit 0e36182c authored by Dries's avatar Dries
Browse files

- Code improvements by Stefan:

   + " -> '
   + Using form_set_error() instead of drupal_set_message().
   + Removed dead code.
parent 77515308
...@@ -43,17 +43,17 @@ function upload_menu() { ...@@ -43,17 +43,17 @@ function upload_menu() {
function upload_admin() { function upload_admin() {
system_settings_save(); system_settings_save();
$group .= form_textfield(t("Maximum total file size"), "upload_maxsize_total", variable_get("upload_maxsize_total", 0), 5, 5, t("The maximum size of a file a user can upload in megabytes. Enter 0 for unlimited.")); $group .= form_textfield(t('Maximum total file size'), 'upload_maxsize_total', variable_get('upload_maxsize_total', 0), 5, 5, t('The maximum size of a file a user can upload in megabytes. Enter 0 for unlimited.'));
$output = form_group(t('General settings'), $group); $output = form_group(t('General settings'), $group);
$roles = user_roles(0, 'upload files'); $roles = user_roles(0, 'upload files');
foreach ($roles as $rid => $role) { foreach ($roles as $rid => $role) {
$group = form_textfield(t("Permitted file extensions"), "upload_extensions_$rid", variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"), 60, 255, t("Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.")); $group = form_textfield(t('Permitted file extensions'), "upload_extensions_$rid", variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"), 60, 255, t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'));
$group .= form_textfield(t("Maximum file size per upload"), "upload_uploadsize_$rid", variable_get("upload_uploadsize_$rid", 1), 5, 5, t("The maximum size of a file a user can upload (in megabytes).")); $group .= form_textfield(t('Maximum file size per upload'), "upload_uploadsize_$rid", variable_get("upload_uploadsize_$rid", 1), 5, 5, t('The maximum size of a file a user can upload (in megabytes).'));
$group .= form_textfield(t("Total file size per user"), "upload_usersize_$rid", variable_get("upload_usersize_$rid", 10), 5, 5, t("The maximum size of all files a user can have on the site (in megabytes).")); $group .= form_textfield(t('Total file size per user'), "upload_usersize_$rid", variable_get("upload_usersize_$rid", 10), 5, 5, t('The maximum size of all files a user can have on the site (in megabytes).'));
$output .= form_group(t("Settings for '%role'", array('%role' => $role)), $group); $output .= form_group(t('Settings for %role', array('%role' => "<em>$role</em>")), $group);
} }
print theme('page', system_settings_form($output)); print theme('page', system_settings_form($output));
...@@ -121,14 +121,14 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -121,14 +121,14 @@ function upload_nodeapi(&$node, $op, $arg) {
if ($maxsize && $total_size > $maxsize) { if ($maxsize && $total_size > $maxsize) {
drupal_set_message(t("Error attaching file '%name': total file size exceeded", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: total file size exceeded', array('%name' => "<em>$file->filename</em>")));
break; break;
} }
// Validate file against all users roles. Only denies an upload when // Validate file against all users roles. Only denies an upload when
// all roles prevent it. // all roles prevent it.
foreach ($user->roles as $rid => $name) { foreach ($user->roles as $rid => $name) {
$extensions = variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"); $extensions = variable_get("upload_extensions_$rid", 'jpg jpeg gif png txt html doc xls pdf ppt pps');
$uploadsize = variable_get("upload_uploadsize_$rid", 1); $uploadsize = variable_get("upload_uploadsize_$rid", 1);
$usersize = variable_get("upload_usersize_$rid", 1); $usersize = variable_get("upload_usersize_$rid", 1);
...@@ -148,13 +148,13 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -148,13 +148,13 @@ function upload_nodeapi(&$node, $op, $arg) {
} }
if ($error['extension'] == count($user->roles)) { if ($error['extension'] == count($user->roles)) {
drupal_set_message(t("error attaching file '%name': invalid extension", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: invalid extension', array('%name' => "<em>$file->filename</em>")));
} }
elseif ($error['uploadsize'] == count($user->roles)) { elseif ($error['uploadsize'] == count($user->roles)) {
drupal_set_message(t("error attaching file '%name': exceeds maximum file size", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: exceeds maximum file size', array('%name' => "<em>$file->filename</em>")));
} }
elseif ($error['usersize'] == count($user->roles)) { elseif ($error['usersize'] == count($user->roles)) {
drupal_set_message(t("error attaching file '%name': exceeds maximum file size", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: exceeds maximum file size', array('%name' => "<em>$file->filename</em>")));
} }
else { else {
$key = 'upload_'. count($_SESSION['file_uploads']); $key = 'upload_'. count($_SESSION['file_uploads']);
...@@ -177,7 +177,7 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -177,7 +177,7 @@ function upload_nodeapi(&$node, $op, $arg) {
break; break;
case 'view': case 'view':
if ($node->files) { if ($node->files) {
$header = array(t('Attachment'), t('Size')); $header = array(t('attachment'), t('size'));
$rows = array(); $rows = array();
$previews = array(); $previews = array();
...@@ -204,7 +204,7 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -204,7 +204,7 @@ function upload_nodeapi(&$node, $op, $arg) {
foreach ($previews as $file) { foreach ($previews as $file) {
$old = file_create_filename($file->filename, file_create_path()); $old = file_create_filename($file->filename, file_create_path());
$new = url($old); $new = url($old);
drupal_set_message("debug: $old $new"); //drupal_set_message("debug: $old $new");
$node->body = str_replace($old, $new, $node->body); $node->body = str_replace($old, $new, $node->body);
$node->teaser = str_replace($old, $new, $node->teaser); $node->teaser = str_replace($old, $new, $node->teaser);
} }
...@@ -312,15 +312,4 @@ function upload_load($node) { ...@@ -312,15 +312,4 @@ function upload_load($node) {
return $files; return $files;
} }
function theme_upload_attached($file, $temp = 0) {
if ($temp) {
$file = variable_get('file_directory_path', 'files') . FILE_SEPARATOR . $file->filename .' ('. format_size($file->filesize) .')<br />';
}
else {
$file = file_create_path($file->filepath) .' ('. format_size($file->filesize) .")<br />";
}
return $file;
}
?> ?>
...@@ -43,17 +43,17 @@ function upload_menu() { ...@@ -43,17 +43,17 @@ function upload_menu() {
function upload_admin() { function upload_admin() {
system_settings_save(); system_settings_save();
$group .= form_textfield(t("Maximum total file size"), "upload_maxsize_total", variable_get("upload_maxsize_total", 0), 5, 5, t("The maximum size of a file a user can upload in megabytes. Enter 0 for unlimited.")); $group .= form_textfield(t('Maximum total file size'), 'upload_maxsize_total', variable_get('upload_maxsize_total', 0), 5, 5, t('The maximum size of a file a user can upload in megabytes. Enter 0 for unlimited.'));
$output = form_group(t('General settings'), $group); $output = form_group(t('General settings'), $group);
$roles = user_roles(0, 'upload files'); $roles = user_roles(0, 'upload files');
foreach ($roles as $rid => $role) { foreach ($roles as $rid => $role) {
$group = form_textfield(t("Permitted file extensions"), "upload_extensions_$rid", variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"), 60, 255, t("Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.")); $group = form_textfield(t('Permitted file extensions'), "upload_extensions_$rid", variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"), 60, 255, t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'));
$group .= form_textfield(t("Maximum file size per upload"), "upload_uploadsize_$rid", variable_get("upload_uploadsize_$rid", 1), 5, 5, t("The maximum size of a file a user can upload (in megabytes).")); $group .= form_textfield(t('Maximum file size per upload'), "upload_uploadsize_$rid", variable_get("upload_uploadsize_$rid", 1), 5, 5, t('The maximum size of a file a user can upload (in megabytes).'));
$group .= form_textfield(t("Total file size per user"), "upload_usersize_$rid", variable_get("upload_usersize_$rid", 10), 5, 5, t("The maximum size of all files a user can have on the site (in megabytes).")); $group .= form_textfield(t('Total file size per user'), "upload_usersize_$rid", variable_get("upload_usersize_$rid", 10), 5, 5, t('The maximum size of all files a user can have on the site (in megabytes).'));
$output .= form_group(t("Settings for '%role'", array('%role' => $role)), $group); $output .= form_group(t('Settings for %role', array('%role' => "<em>$role</em>")), $group);
} }
print theme('page', system_settings_form($output)); print theme('page', system_settings_form($output));
...@@ -121,14 +121,14 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -121,14 +121,14 @@ function upload_nodeapi(&$node, $op, $arg) {
if ($maxsize && $total_size > $maxsize) { if ($maxsize && $total_size > $maxsize) {
drupal_set_message(t("Error attaching file '%name': total file size exceeded", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: total file size exceeded', array('%name' => "<em>$file->filename</em>")));
break; break;
} }
// Validate file against all users roles. Only denies an upload when // Validate file against all users roles. Only denies an upload when
// all roles prevent it. // all roles prevent it.
foreach ($user->roles as $rid => $name) { foreach ($user->roles as $rid => $name) {
$extensions = variable_get("upload_extensions_$rid", "jpg jpeg gif png txt html doc xls pdf ppt pps"); $extensions = variable_get("upload_extensions_$rid", 'jpg jpeg gif png txt html doc xls pdf ppt pps');
$uploadsize = variable_get("upload_uploadsize_$rid", 1); $uploadsize = variable_get("upload_uploadsize_$rid", 1);
$usersize = variable_get("upload_usersize_$rid", 1); $usersize = variable_get("upload_usersize_$rid", 1);
...@@ -148,13 +148,13 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -148,13 +148,13 @@ function upload_nodeapi(&$node, $op, $arg) {
} }
if ($error['extension'] == count($user->roles)) { if ($error['extension'] == count($user->roles)) {
drupal_set_message(t("error attaching file '%name': invalid extension", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: invalid extension', array('%name' => "<em>$file->filename</em>")));
} }
elseif ($error['uploadsize'] == count($user->roles)) { elseif ($error['uploadsize'] == count($user->roles)) {
drupal_set_message(t("error attaching file '%name': exceeds maximum file size", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: exceeds maximum file size', array('%name' => "<em>$file->filename</em>")));
} }
elseif ($error['usersize'] == count($user->roles)) { elseif ($error['usersize'] == count($user->roles)) {
drupal_set_message(t("error attaching file '%name': exceeds maximum file size", array('%name' => $file->filename)), 'error'); form_set_error('upload', t('Error attaching file %name: exceeds maximum file size', array('%name' => "<em>$file->filename</em>")));
} }
else { else {
$key = 'upload_'. count($_SESSION['file_uploads']); $key = 'upload_'. count($_SESSION['file_uploads']);
...@@ -177,7 +177,7 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -177,7 +177,7 @@ function upload_nodeapi(&$node, $op, $arg) {
break; break;
case 'view': case 'view':
if ($node->files) { if ($node->files) {
$header = array(t('Attachment'), t('Size')); $header = array(t('attachment'), t('size'));
$rows = array(); $rows = array();
$previews = array(); $previews = array();
...@@ -204,7 +204,7 @@ function upload_nodeapi(&$node, $op, $arg) { ...@@ -204,7 +204,7 @@ function upload_nodeapi(&$node, $op, $arg) {
foreach ($previews as $file) { foreach ($previews as $file) {
$old = file_create_filename($file->filename, file_create_path()); $old = file_create_filename($file->filename, file_create_path());
$new = url($old); $new = url($old);
drupal_set_message("debug: $old $new"); //drupal_set_message("debug: $old $new");
$node->body = str_replace($old, $new, $node->body); $node->body = str_replace($old, $new, $node->body);
$node->teaser = str_replace($old, $new, $node->teaser); $node->teaser = str_replace($old, $new, $node->teaser);
} }
...@@ -312,15 +312,4 @@ function upload_load($node) { ...@@ -312,15 +312,4 @@ function upload_load($node) {
return $files; return $files;
} }
function theme_upload_attached($file, $temp = 0) {
if ($temp) {
$file = variable_get('file_directory_path', 'files') . FILE_SEPARATOR . $file->filename .' ('. format_size($file->filesize) .')<br />';
}
else {
$file = file_create_path($file->filepath) .' ('. format_size($file->filesize) .")<br />";
}
return $file;
}
?> ?>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment