/[drupal]/drupal/modules/upload/upload.admin.inc
ViewVC logotype

Contents of /drupal/modules/upload/upload.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.16 - (show annotations) (download) (as text)
Sat Sep 5 15:05:05 2009 UTC (2 months, 3 weeks ago) by dries
Branch: MAIN
CVS Tags: DRUPAL-7-0-UNSTABLE-10, DRUPAL-7-0-UNSTABLE-9, HEAD
Changes since 1.15: +3 -3 lines
File MIME type: text/x-php
- Patch by #565496 by dropcube, pwolanin: changed Allow dynamic attaching of other types of stuff to render() structures.
1 <?php
2 // $Id: upload.admin.inc,v 1.15 2009/08/22 09:48:34 dries Exp $
3
4 /**
5 * @file
6 * This file creates the administration form for the upload module.
7 */
8
9 /**
10 * Form API callback to validate the upload settings form.
11 */
12 function upload_admin_settings_validate($form, &$form_state) {
13 if (!is_numeric($form_state['values']['upload_max_resolution_x'])) {
14 form_set_error('upload_max_resolution_x', t('The maximum allowed image width should be entered as a numeric value. Set to 0 for no restriction.'));
15 }
16 if (!is_numeric($form_state['values']['upload_max_resolution_y'])) {
17 form_set_error('upload_max_resolution_y', t('The maximum allowed image height should be entered as a numeric value. Set to 0 for no restriction.'));
18 }
19
20 $default_uploadsize = $form_state['values']['upload_uploadsize_default'];
21 $default_usersize = $form_state['values']['upload_usersize_default'];
22
23 $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/>';
24 $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.");
25
26 if (!is_numeric($default_uploadsize) || ($default_uploadsize <= 0)) {
27 form_set_error('upload_uploadsize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
28 }
29 if (!is_numeric($default_usersize) || ($default_usersize < 0)) {
30 form_set_error('upload_usersize_default', t('The %role file size limit must be a number zero or greater.', array('%role' => t('default'))));
31 }
32 if ($default_uploadsize * 1024 * 1024 > file_upload_max_size()) {
33 form_set_error('upload_uploadsize_default', $exceed_max_msg . $more_info);
34 $more_info = '';
35 }
36 if ($default_usersize && $default_uploadsize > $default_usersize) {
37 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'))));
38 }
39
40 foreach ($form_state['values']['roles'] as $rid => $role) {
41 $uploadsize = $form_state['values']['upload_uploadsize_' . $rid];
42 $usersize = $form_state['values']['upload_usersize_' . $rid];
43
44 if (!is_numeric($uploadsize) || ($uploadsize <= 0)) {
45 form_set_error('upload_uploadsize_' . $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
46 }
47 if (!is_numeric($usersize) || ($usersize < 0)) {
48 form_set_error('upload_usersize_' . $rid, t('The %role file size limit must be a number zero or greater.', array('%role' => $role)));
49 }
50 if ($uploadsize * 1024 * 1024 > file_upload_max_size()) {
51 form_set_error('upload_uploadsize_' . $rid, $exceed_max_msg . $more_info);
52 $more_info = '';
53 }
54 if ($usersize && $uploadsize > $usersize) {
55 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)));
56 }
57 }
58 }
59
60 /**
61 * Menu callback for the upload settings form.
62 */
63 function upload_admin_settings() {
64 $upload_extensions_default = variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
65 $upload_uploadsize_default = variable_get('upload_uploadsize_default', 1);
66 $upload_usersize_default = variable_get('upload_usersize_default', 1);
67
68 $form['settings_general'] = array(
69 '#type' => 'fieldset',
70 '#title' => t('General settings'),
71 '#collapsible' => TRUE,
72 '#attached'=> array(
73 'css' => array(drupal_get_path('module', 'upload') . '/upload.admin.css'),
74 ),
75 );
76 $form['settings_general']['upload_max_resolution'] = array(
77 '#type' => 'item',
78 '#title' => t('Maximum resolution for uploaded images'),
79 '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0x0 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/config/media/image-toolkit'))),
80 '#prefix' => '<div class="form-item-wrapper form-item-resolution">',
81 '#suffix' => '</div>',
82 );
83 $form['settings_general']['upload_max_resolution']['upload_max_resolution_x'] = array(
84 '#type' => 'textfield',
85 '#title' => t('Width'),
86 '#default_value' => variable_get('upload_max_resolution_x', 0),
87 '#size' => 5,
88 '#maxlength' => 5,
89 '#field_suffix' => t('x'),
90 );
91 $form['settings_general']['upload_max_resolution']['upload_max_resolution_y'] = array(
92 '#type' => 'textfield',
93 '#title' => t('Height'),
94 '#default_value' => variable_get('upload_max_resolution_y', 0),
95 '#size' => 5,
96 '#maxlength' => 5,
97 '#field_suffix' => t('px'),
98 );
99 $form['settings_general']['upload_list_default'] = array(
100 '#type' => 'select',
101 '#title' => t('List files by default'),
102 '#default_value' => variable_get('upload_list_default', 1),
103 '#options' => array(0 => t('No'), 1 => t('Yes')),
104 '#description' => t('Display attached files when viewing a post.'),
105 );
106
107 $form['settings_general']['upload_extensions_default'] = array(
108 '#type' => 'textfield',
109 '#title' => t('Default permitted file extensions'),
110 '#default_value' => $upload_extensions_default,
111 '#maxlength' => 255,
112 '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'),
113 );
114 $form['settings_general']['upload_uploadsize_default'] = array(
115 '#type' => 'textfield',
116 '#title' => t('Default maximum file size per upload'),
117 '#default_value' => $upload_uploadsize_default,
118 '#size' => 5,
119 '#maxlength' => 5,
120 '#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.'),
121 '#field_suffix' => t('MB'),
122 );
123 $form['settings_general']['upload_usersize_default'] = array(
124 '#type' => 'textfield',
125 '#title' => t('Default total file size per user'),
126 '#default_value' => $upload_usersize_default,
127 '#size' => 7,
128 '#maxlength' => 7,
129 '#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.'),
130 '#field_suffix' => t('MB'),
131 );
132
133 $form['settings_general']['upload_max_size'] = array('#markup' => '<p>' . t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))) . '</p>');
134
135 $roles = user_roles(FALSE, 'upload files');
136 $form['roles'] = array('#type' => 'value', '#value' => $roles);
137
138 foreach ($roles as $rid => $role) {
139 $form['settings_role_' . $rid] = array(
140 '#type' => 'fieldset',
141 '#title' => t('Settings for @role', array('@role' => $role)),
142 '#collapsible' => TRUE,
143 '#collapsed' => TRUE,
144 );
145 $form['settings_role_' . $rid]['upload_extensions_' . $rid] = array(
146 '#type' => 'textfield',
147 '#title' => t('Permitted file extensions'),
148 '#default_value' => variable_get('upload_extensions_' . $rid, $upload_extensions_default),
149 '#maxlength' => 255,
150 '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'),
151 );
152 $form['settings_role_' . $rid]['upload_uploadsize_' . $rid] = array(
153 '#type' => 'textfield',
154 '#title' => t('Maximum file size per upload'),
155 '#default_value' => variable_get('upload_uploadsize_' . $rid, $upload_uploadsize_default),
156 '#size' => 5,
157 '#maxlength' => 5,
158 '#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.'),
159 '#field_suffix' => t('MB'),
160 );
161 $form['settings_role_' . $rid]['upload_usersize_' . $rid] = array(
162 '#type' => 'textfield',
163 '#title' => t('Total file size per user'),
164 '#default_value' => variable_get('upload_usersize_' . $rid, $upload_usersize_default),
165 '#size' => 7,
166 '#maxlength' => 7,
167 '#description' => t('The maximum size of all files a user can have on the site. Set to 0 for no restriction.'),
168 '#field_suffix' => t('MB'),
169 );
170 }
171
172 $form['#validate'] = array('upload_admin_settings_validate');
173
174 return system_settings_form($form, FALSE);
175 }

  ViewVC Help
Powered by ViewVC 1.1.2