00001 <?php
00002
00003
00007 function upload_admin_settings_validate($form, &$form_state) {
00008 if (($form_state['values']['upload_max_resolution'] != '0')) {
00009 if (!preg_match('/^[0-9]+x[0-9]+$/', $form_state['values']['upload_max_resolution'])) {
00010 form_set_error('upload_max_resolution', t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
00011 }
00012 }
00013
00014 $default_uploadsize = $form_state['values']['upload_uploadsize_default'];
00015 $default_usersize = $form_state['values']['upload_usersize_default'];
00016
00017 $exceed_max_msg = t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) . '<br/>';
00018 $more_info = t("Depending on your server environment, these settings may be changed in the system-wide php.ini file, a php.ini file in your Drupal root directory, in your Drupal site's settings.php file, or in the .htaccess file in your Drupal root directory.");
00019
00020 if (!is_numeric($default_uploadsize) || ($default_uploadsize <= 0)) {
00021 form_set_error('upload_uploadsize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
00022 }
00023 if (!is_numeric($default_usersize) || ($default_usersize < 0)) {
00024 form_set_error('upload_usersize_default', t('The %role file size limit must be a number zero or greater.', array('%role' => t('default'))));
00025 }
00026 if ($default_uploadsize * 1024 * 1024 > file_upload_max_size()) {
00027 form_set_error('upload_uploadsize_default', $exceed_max_msg . $more_info);
00028 $more_info = '';
00029 }
00030 if ($default_usersize && $default_uploadsize > $default_usersize) {
00031 form_set_error('upload_uploadsize_default', t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => t('default'))));
00032 }
00033
00034 foreach ($form_state['values']['roles'] as $rid => $role) {
00035 $uploadsize = $form_state['values']['upload_uploadsize_' . $rid];
00036 $usersize = $form_state['values']['upload_usersize_' . $rid];
00037
00038 if (!is_numeric($uploadsize) || ($uploadsize <= 0)) {
00039 form_set_error('upload_uploadsize_' . $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
00040 }
00041 if (!is_numeric($usersize) || ($usersize < 0)) {
00042 form_set_error('upload_usersize_' . $rid, t('The %role file size limit must be a number zero or greater.', array('%role' => $role)));
00043 }
00044 if ($uploadsize * 1024 * 1024 > file_upload_max_size()) {
00045 form_set_error('upload_uploadsize_' . $rid, $exceed_max_msg . $more_info);
00046 $more_info = '';
00047 }
00048 if ($usersize && $uploadsize > $usersize) {
00049 form_set_error('upload_uploadsize_' . $rid, t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => $role)));
00050 }
00051 }
00052 }
00053
00057 function upload_admin_settings() {
00058 $upload_extensions_default = variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
00059 $upload_uploadsize_default = variable_get('upload_uploadsize_default', 1);
00060 $upload_usersize_default = variable_get('upload_usersize_default', 1);
00061
00062 $form['settings_general'] = array(
00063 '#type' => 'fieldset',
00064 '#title' => t('General settings'),
00065 '#collapsible' => TRUE,
00066 );
00067 $form['settings_general']['upload_max_resolution'] = array(
00068 '#type' => 'textfield',
00069 '#title' => t('Maximum resolution for uploaded images'),
00070 '#default_value' => variable_get('upload_max_resolution', 0),
00071 '#size' => 15,
00072 '#maxlength' => 10,
00073 '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0 for no restriction. If an <a href="!image-toolkit-link">image toolkit</a> is installed, files exceeding this value will be scaled down to fit.', array('!image-toolkit-link' => url('admin/settings/image-toolkit'))),
00074 '#field_suffix' => '<kbd>' . t('WIDTHxHEIGHT') . '</kbd>'
00075 );
00076 $form['settings_general']['upload_list_default'] = array(
00077 '#type' => 'select',
00078 '#title' => t('List files by default'),
00079 '#default_value' => variable_get('upload_list_default', 1),
00080 '#options' => array(0 => t('No'), 1 => t('Yes')),
00081 '#description' => t('Display attached files when viewing a post.'),
00082 );
00083
00084 $form['settings_general']['upload_extensions_default'] = array(
00085 '#type' => 'textfield',
00086 '#title' => t('Default permitted file extensions'),
00087 '#default_value' => $upload_extensions_default,
00088 '#maxlength' => 255,
00089 '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'),
00090 );
00091 $form['settings_general']['upload_uploadsize_default'] = array(
00092 '#type' => 'textfield',
00093 '#title' => t('Default maximum file size per upload'),
00094 '#default_value' => $upload_uploadsize_default,
00095 '#size' => 5,
00096 '#maxlength' => 5,
00097 '#description' => t('The default maximum file size a user can upload. If an image is uploaded and a maximum resolution is set, the size will be checked after the file has been resized.'),
00098 '#field_suffix' => t('MB'),
00099 );
00100 $form['settings_general']['upload_usersize_default'] = array(
00101 '#type' => 'textfield',
00102 '#title' => t('Default total file size per user'),
00103 '#default_value' => $upload_usersize_default,
00104 '#size' => 7,
00105 '#maxlength' => 7,
00106 '#description' => t('The default maximum size of all files a user can have on the site. Set to 0 for no restriction. The least restrictive limit is used, so setting this to 0 will disable any role-specific total file size limits.'),
00107 '#field_suffix' => t('MB'),
00108 );
00109
00110 $form['settings_general']['upload_max_size'] = array('#value' => '<p>' . t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) . '</p>');
00111
00112 $roles = user_roles(FALSE, 'upload files');
00113 $form['roles'] = array('#type' => 'value', '#value' => $roles);
00114
00115 foreach ($roles as $rid => $role) {
00116 $form['settings_role_' . $rid] = array(
00117 '#type' => 'fieldset',
00118 '#title' => t('Settings for @role', array('@role' => $role)),
00119 '#collapsible' => TRUE,
00120 '#collapsed' => TRUE,
00121 );
00122 $form['settings_role_' . $rid]['upload_extensions_' . $rid] = array(
00123 '#type' => 'textfield',
00124 '#title' => t('Permitted file extensions'),
00125 '#default_value' => variable_get('upload_extensions_' . $rid, $upload_extensions_default),
00126 '#maxlength' => 255,
00127 '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'),
00128 );
00129 $form['settings_role_' . $rid]['upload_uploadsize_' . $rid] = array(
00130 '#type' => 'textfield',
00131 '#title' => t('Maximum file size per upload'),
00132 '#default_value' => variable_get('upload_uploadsize_' . $rid, $upload_uploadsize_default),
00133 '#size' => 5,
00134 '#maxlength' => 5,
00135 '#description' => t('The maximum size of a file a user can upload. If an image is uploaded and a maximum resolution is set, the size will be checked after the file has been resized.'),
00136 '#field_suffix' => t('MB'),
00137 );
00138 $form['settings_role_' . $rid]['upload_usersize_' . $rid] = array(
00139 '#type' => 'textfield',
00140 '#title' => t('Total file size per user'),
00141 '#default_value' => variable_get('upload_usersize_' . $rid, $upload_usersize_default),
00142 '#size' => 7,
00143 '#maxlength' => 7,
00144 '#description' => t('The maximum size of all files a user can have on the site. Set to 0 for no restriction.'),
00145 '#field_suffix' => t('MB'),
00146 );
00147 }
00148
00149 $form['#validate'] = array('upload_admin_settings_validate');
00150
00151 return system_settings_form($form);
00152 }