/[drupal]/contributions/modules/webfm/webfm.admin.inc
ViewVC logotype

Contents of /contributions/modules/webfm/webfm.admin.inc

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


Revision 1.4 - (show annotations) (download) (as text)
Wed Aug 19 15:33:48 2009 UTC (3 months ago) by robmilne
Branch: MAIN
CVS Tags: DRUPAL-6--2-11, DRUPAL-6--2-10, HEAD
Changes since 1.3: +64 -2 lines
File MIME type: text/x-php
Add control to enable/disable owner column in browser
Add OG stuff from node 249487
1 <?php
2 // $Id: webfm.admin.inc,v 1.3 2009/07/21 17:45:09 robmilne Exp $
3
4 /**
5 * @file
6 * Provides the administration page for Web File Manager.
7 */
8
9 /**
10 * Implementation of hook_settings().
11 */
12 function webfm_admin_settings() {
13 global $user;
14
15 $modulepath = drupal_get_path('module', 'webfm');
16
17 $form['webfm_root_dir'] =
18 array('#type' => 'textfield',
19 '#title' => t('WebFM root directory'),
20 '#default_value' => variable_get('webfm_root_dir', ''),
21 '#maxlength' => '100',
22 '#size' => '70',
23 '#description' => t('Root directory used to present the filebrowser user interface.
24 <br />This path is relative to "File system path" set in admin/settings/file-system.
25 <br />If this directory path is compound (ie: path/to/root) then the path must already
26 <br />exist for this setting to validate (ie: path/to).')
27
28 );
29 $form['webfm_icon_dir'] =
30 array('#type' => 'textfield',
31 '#title' => t('Icon directory'),
32 '#default_value' => variable_get('webfm_icon_dir', $modulepath. '/image/icon'),
33 '#maxlength' => '100',
34 '#size' => '70',
35 '#description' => t('Name of directory where file type icons are stored (relative to base url).')
36 );
37 $form['webfm_max_resolution'] =
38 array('#type' => 'textfield',
39 '#title' => t('Maximum resolution for uploaded images'),
40 '#default_value' => variable_get('webfm_max_resolution', 0),
41 '#size' => 15,
42 '#maxlength' => 10,
43 '#description' => t('The maximum allowed image size (e.g. 640x480). Set to 0 for no restriction.'),
44 '#field_suffix' => '<kbd>'. t('WIDTHxHEIGHT') .'</kbd>'
45 );
46
47 $form['webfm_date_format'] =
48 array('#type' => 'radios',
49 '#title' => t('Date Format'),
50 '#default_value' => variable_get('webfm_date_format', WEBFM_DATE_FORMAT_DAY),
51 '#options' => array(WEBFM_DATE_FORMAT_DAY => t('dd/mm/yy'), WEBFM_DATE_FORMAT_MONTH => t('mm/dd/yy')),
52 '#description' => t('Set the order of day/month in date fields.')
53 );
54
55 $form['webfm_display_title'] =
56 array('#type' => 'checkbox',
57 '#title' => t('Display metadata title'),
58 '#default_value' => variable_get('webfm_display_title', ''),
59 '#description' => t('Check this box to display the metadata title in the browser instead of the filename.
60 <br />If a metadata title doesn\'t exist, the filename is used and rename functions normally.
61 <br />If metadata title is used, renaming is available inside the metadata editor.')
62 );
63
64 $form['webfm_display_owner'] =
65 array('#type' => 'checkbox',
66 '#title' => t('Display file owner column in browser'),
67 '#default_value' => variable_get('webfm_display_owner', ''),
68 '#description' => t('Check this box to display the file owner column in the browser.')
69 );
70
71 $form['file_perm'] =
72 array('#type' => 'fieldset',
73 '#title' => t('Default File Permissions'),
74 '#collapsible' => TRUE,
75 '#collapsed' => TRUE,
76 '#description' => t('Default permissions applied to a file when inserted into the database.
77 <br />If all boxes are unchecked only the file owner and administrators will have
78 <br />access to the file via the filebrowser. File owners and admins can change
79 <br />these settings for each individual file within the filebrowser UI.')
80 );
81
82 $form['file_perm']['webfm_file_perm_role'] =
83 array('#type' => 'checkbox',
84 '#title' => t('Role View Access'),
85 '#default_value' => variable_get('webfm_file_perm_role', ''),
86 '#description' => t('File is viewable/downloadable in the filebrowser by role.')
87 );
88
89 $form['file_perm']['webfm_file_perm_mod'] =
90 array('#type' => 'checkbox',
91 '#title' => t('Role Full Access'),
92 '#default_value' => variable_get('webfm_file_perm_mod', ''),
93 '#description' => t('Roles that can access this file via the filebrowser have the same access rights as the
94 <br />file owner except for the right to change the file permissions.')
95 );
96
97 $form['file_perm']['webfm_file_perm_attach'] =
98 array('#type' => 'checkbox',
99 '#title' => t('Role Attach Access'),
100 '#default_value' => variable_get('webfm_file_perm_attach', ''),
101 '#description' => t('Roles that can access this file via the filebrowser have the right to attach it to content.')
102 );
103
104 $form['file_perm']['webfm_file_public'] =
105 array('#type' => 'checkbox',
106 '#title' => t('Public Access'),
107 '#default_value' => variable_get('webfm_file_public', ''),
108 '#description' => t('File is downloadable anonymously via webfm_send.')
109 );
110
111 $roles = user_roles(0,'access webfm');
112 $form['roles'] = array('#type' => 'value', '#value' => $roles);
113
114 // Flush extensions regex cache for upload and db enum
115 webfm_get_extensions_regex(WEBFM_FLUSH);
116
117 foreach ($roles as $rid => $role) {
118 if(variable_get("root_dir_".$rid, '') == '') {
119 drupal_set_message(t('Role root directory not set for @role role', array('@role' => $role)), 'error');
120 }
121
122 $form["settings_role_".$rid] =
123 array('#type' => 'fieldset',
124 '#title' => t('Settings for @role role', array('@role' => $role)),
125 '#collapsible' => TRUE,
126 '#collapsed' => TRUE
127 );
128
129 $form["settings_role_".$rid]["root_dir_".$rid] =
130 array('#type' => 'textfield',
131 '#title' => t('Role Root directory'),
132 '#default_value' => variable_get("root_dir_".$rid, ''),
133 '#maxlength' => '100',
134 '#size' => '70',
135 '#description' => t('Root directory for this role.
136 <br />This path is relative to "WebFM Root directory" set above.
137 <br />If this directory path is compound then the path must already exist for this
138 <br />setting to validate.')
139 );
140
141 $form["settings_role_".$rid]["webfm_extensions_".$rid] =
142 array('#type' => 'textfield',
143 '#title' => t('Permitted file extensions'),
144 '#default_value' => variable_get("webfm_extensions_".$rid, "jpg jpeg gif png txt html htm doc xls pdf ppt pps dwg zip gz"),
145 '#maxlength' => 255,
146 '#description' => t('Extensions that users in this role can upload. Separate extensions with a space
147 <br />and do not include the leading dot.')
148 );
149
150 $form["settings_role_".$rid]["webfm_uploadsize_".$rid] =
151 array('#type' => 'textfield',
152 '#title' => t('Maximum file size per upload'),
153 '#default_value' => variable_get("webfm_uploadsize_".$rid, 4),
154 '#size' => 5,
155 '#maxlength' => 5,
156 '#description' => t('The maximum size of a file a user can upload (in megabytes).
157 <br />Cannot exceed %size limit set in php.ini.', array('%size' => format_size(file_upload_max_size())))
158 );
159 $form["settings_role_".$rid]["webfm_usersize_".$rid] =
160 array('#type' => 'textfield',
161 '#title' => t('Total file size per user'),
162 '#default_value' => variable_get("webfm_usersize_".$rid, 200),
163 '#size' => 5,
164 '#maxlength' => 5,
165 '#description' => t('The maximum size of all files a user can have on the site (in megabytes).')
166 );
167 }
168
169 if (module_exists('og')) {
170 // Per group settings
171 $groups = og_all_groups_options();
172 $form['groups'] = array('#type' => 'value', '#value' => $groups);
173 $form['webfm_og_auto'] = array(
174 '#type' => 'checkbox',
175 '#default_value' => variable_get('webfm_og_auto', 0),
176 '#title' => t('Create new group folders'),
177 '#description' => t('Automatically create a new group folder when a group is created.'),
178 );
179 foreach ($groups as $gid => $group) {
180 if (variable_get("root_dir_group_".$gid, '') == '') {
181 drupal_set_message(t('Group root directory not set for @group group', array('@group' => $group)), 'error');
182 }
183 $form["settings_group_". $gid] =
184 array('#type' => 'fieldset',
185 '#title' => t('Settings for @group group', array('@group' => $group)),
186 '#collapsible' => TRUE,
187 '#collapsed' => TRUE
188 );
189 $form["settings_group_". $gid]["root_dir_group_". $gid] =
190 array('#type' => 'textfield',
191 '#title' => t('Group Root directory'),
192 '#default_value' => variable_get("root_dir_group_". $gid, ''),
193 '#maxlength' => '100',
194 '#size' => '70',
195 '#description' => t('Root directory for this group.
196 <br />This path is relative to "WebFM Root directory" set above.
197 <br />If this directory path is compound then the path must already exist for this
198 <br />setting to validate.'),
199 );
200 }
201 }
202
203
204 $form['attach'] =
205 array('#type' => 'fieldset',
206 '#title' => t('WebFM attachments'),
207 '#collapsible' => TRUE,
208 '#collapsed' => TRUE
209 );
210 $form['attach']['webfm_attach_body'] =
211 array('#type' => 'checkbox',
212 '#title' => t('Append file links to Node Body'),
213 '#default_value' => variable_get('webfm_attach_body', ''),
214 '#description' => t('Check this box to append file attachments table to the node body.
215 <br />This setting does not affect the attachment block.')
216 );
217 $form['attach']['webfm_attach_new_window'] =
218 array('#type' => 'checkbox',
219 '#title' => t('Open attachments in a new browser window'),
220 '#default_value' => variable_get('webfm_attach_new_window', '')
221 );
222 $form['attach']['attrib'] =
223 array('#type' => 'fieldset',
224 '#title' => t('Attachment List Properties'),
225 );
226 $form['attach']['attrib']['webfm_attach_desc'] =
227 array('#type' => 'checkbox',
228 '#title' => t('Include file description metadata'),
229 '#default_value' => variable_get('webfm_attach_desc', ''),
230 '#description' => t('Check this box to add file description metadata beneath the attachment title.')
231 );
232 $form['attach']['attrib']['webfm_attach_date'] =
233 array('#type' => 'checkbox',
234 '#title' => t('Enable file date column'),
235 '#default_value' => variable_get('webfm_attach_date', ''),
236 '#description' => t('Check this box to add a create date column to the attachment table.')
237 );
238 $form['attach']['attrib']['webfm_attach_size'] =
239 array('#type' => 'checkbox',
240 '#title' => t('Enable file size column'),
241 '#default_value' => variable_get('webfm_attach_size', ''),
242 '#description' => t('Check this box to add a file size column to the attachment table.')
243 );
244 if($user->uid == 1) {
245 //only user #1 gets this access
246 $form['ie'] =
247 array('#type' => 'fieldset',
248 '#title' => t('IE Drag-and-Drop Normalization'),
249 '#collapsible' => TRUE,
250 '#collapsed' => TRUE,
251 '#description' => t('number of pixels to offset drag objects from cursor position in IE browser.<br />This quantity is usually related to relative positioning used by the css.')
252 );
253 $form['ie']['webfm_ie_dd_list_offset'] =
254 array('#type' => 'textfield',
255 '#title' => t('IE drag and drop x-axis offset for right hand listing draggables'),
256 '#default_value' => variable_get('webfm_ie_dd_list_offset', '-190'),
257 '#maxlength' => '10',
258 '#size' => '10',
259 );
260 $form['ie']['webfm_ie_dd_tree_offset'] =
261 array('#type' => 'textfield',
262 '#title' => t('IE drag and drop x-axis offset for directory tree draggables'),
263 '#default_value' => variable_get('webfm_ie_dd_tree_offset', '-34'),
264 '#maxlength' => '10',
265 '#size' => '10',
266 );
267
268 $form['debug'] =
269 array('#type' => 'fieldset',
270 '#title' => t('WebFM debug'),
271 '#collapsible' => TRUE,
272 '#collapsed' => TRUE
273 );
274 $form['debug']['webfm_debug'] =
275 array('#type' => 'checkbox',
276 '#title' => t('WebFM javascript debug'),
277 '#default_value' => variable_get('webfm_debug', ''),
278 '#description' => t('Check this box for javascript debug messaging.')
279 );
280 $form['debug']['webfm_cron'] =
281 array('#type' => 'checkbox',
282 '#title' => t('WebFM cron'),
283 '#default_value' => variable_get('webfm_cron', ''),
284 '#description' => t('Check this box to enable cleanup of orphaned file records in the database.
285 <br />NOTE: Use with caution - behaviour is to delete all file records without a
286 <br />valid file path. Manually renaming a WebFM directory (ie: via OS shell)
287 <br />and then running cron will delete all webfm_file table entries for that
288 <br />directory and it\'s sub-directories.')
289 );
290 }
291
292 $form['#validate'] = array('webfm_admin_settings_validate');
293 return system_settings_form($form);
294 }
295
296 /**
297 * Form API callback to validate the webfm settings form.
298 */
299 function webfm_admin_settings_validate($form, $form_state) {
300 $valid_webfm_root = FALSE;
301 $webfm_root_dir_name = $form_state['values']['webfm_root_dir'];
302 if(!empty($webfm_root_dir_name)) {
303 if(!preg_match('/^[0-9a-zA-Z]/', $webfm_root_dir_name)) {
304 form_set_error('webfm_root_dir'. $rid, t('The leading character of the webfm root directory name must be alphanumeric.'));
305 } else if(preg_match('[\.]', $webfm_root_dir_name)) {
306 form_set_error('webfm_root_dir'. $rid, t('The webfm root directory name is not valid.'));
307 } else {
308 $webfm_root_dir = file_directory_path()."/".$webfm_root_dir_name;
309 $valid_webfm_root = file_check_directory($webfm_root_dir, FILE_CREATE_DIRECTORY, 'webfm_root_dir');
310 }
311 }
312
313 if(($form_state['values']['webfm_max_resolution'] != '0')) {
314 if(!preg_match('/^[0-9]+[xX][0-9]+$/', $form_state['values']['webfm_max_resolution'])) {
315 form_set_error('webfm_max_resolution', t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
316 }
317 }
318
319 $exceed_max_msg = t('Your PHP settings limit the maximum file size per upload to %size MB.', array('%size' => file_upload_max_size())).'<br/>';
320 $more_info = t("Depending on your sever 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.");
321 $max_upload_size = file_upload_max_size()/(1024*1024);
322 foreach($form_state['values']['roles'] as $rid => $role) {
323 $uploadsize = $form_state['values']['webfm_uploadsize_'. $rid];
324 $usersize = $form_state['values']['webfm_usersize_'. $rid];
325 $role_root_dir_name = $form_state['values']['root_dir_'.$rid];
326
327 if(!empty($role_root_dir_name)) {
328 if($valid_webfm_root) {
329 if(!preg_match('/^[0-9a-zA-Z]/', $role_root_dir_name)) {
330 form_set_error('root_dir_'. $rid, t('The leading character of the %role root directory must be alphanumeric.', array('%role' => $role)));
331 } else if(preg_match('[\.]', $role_root_dir_name)) {
332 form_set_error('root_dir_'. $rid, t('The %role root directory name is not valid.', array('%role' => $role)));
333 } else {
334 $role_root_dir = $webfm_root_dir."/".$role_root_dir_name;
335 file_check_directory($role_root_dir, FILE_CREATE_DIRECTORY, 'root_dir_'.$rid);
336 }
337 } else {
338 form_set_error('root_dir_'. $rid, t('The WebFM root directory must be valid for the %role root directory name to be valid.', array('%role' => $role)));
339 }
340 }
341
342 if(!is_numeric($uploadsize) || ($uploadsize <= 0)) {
343 form_set_error('webfm_uploadsize_'. $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
344 }
345 if(!is_numeric($usersize) || ($usersize <= 0)) {
346 form_set_error('webfm_usersize_'. $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
347 }
348 if($uploadsize > $max_upload_size) {
349 form_set_error('webfm_uploadsize_'. $rid, $exceed_max_msg . $more_info);
350 $more_info = '';
351 }
352 if($uploadsize > $usersize) {
353 form_set_error('webfm_uploadsize_'. $rid, t('The %role maximum file size per upload is greater than the total file size allowed per user', array('%role' => $role)));
354 }
355 }
356
357 if (module_exists('og')) {
358 foreach ($form_state['values']['groups'] as $gid => $group) {
359 $group_root_dir_name = $form_state['values']['root_dir_group_'. $gid];
360 if (!empty($group_root_dir_name)) {
361 if ($valid_webfm_root) {
362 if (!preg_match('/^[0-9a-zA-Z]/', $group_root_dir_name)) {
363 form_set_error('root_dir_group_'. $gid, t('The leading character of the %group root directory must be alphanumeric.', array('%group' => $group)));
364 } else if(preg_match('[\.]', $group_root_dir_name)) {
365 form_set_error('root_dir_group_'. $gid, t('The %group root directory name is not valid.', array('%group' => $group)));
366 } else {
367 $group_root_dir = $webfm_root_dir ."/". $group_root_dir_name;
368 file_check_directory($group_root_dir, FILE_CREATE_DIRECTORY, 'root_dir_group_'.$gid);
369 }
370 } else {
371 form_set_error('root_dir_group_'. $gid, t('The WebFM root directory must be valid for the %group root directory name to be valid.', array('%group' => $group)));
372 }
373 }
374 }
375 }
376 }

  ViewVC Help
Powered by ViewVC 1.1.2