|
1 <?php |
|
2 // $Id: admin.inc,v 1.5.2.6 2009/02/09 18:24:36 ufku Exp $ |
|
3 |
|
4 /** |
|
5 * Admin main page. |
|
6 */ |
|
7 function imce_admin() { |
|
8 |
|
9 $profiles = variable_get('imce_profiles', array()); |
|
10 if (empty($profiles)) { |
|
11 imce_install_profiles(); |
|
12 } |
|
13 |
|
14 $header = array(t('Profile name'), array('data' => t('Operations'), 'colspan' => 2)); |
|
15 $rows = array(); |
|
16 |
|
17 foreach ($profiles as $pid => $profile) { |
|
18 $rows[] = array($profile['name'], |
|
19 l(t('Edit'), 'admin/settings/imce/profile/edit/'. $pid), |
|
20 $pid == 1 ? '' : l(t('Delete'), 'admin/settings/imce/profile/delete/'. $pid), |
|
21 ); |
|
22 } |
|
23 |
|
24 $rows[] = array('', array('data' => l(t('Add new profile'), 'admin/settings/imce/profile'), 'colspan' => 2)); |
|
25 |
|
26 $output = '<h2 class="title">'. t('Configuration profiles') .'</h2>'; |
|
27 $output .= theme('table', $header, $rows); |
|
28 $output .= drupal_get_form('imce_admin_form'); |
|
29 |
|
30 return $output; |
|
31 } |
|
32 |
|
33 /** |
|
34 * Admin form. |
|
35 */ |
|
36 function imce_admin_form(&$form_state) { |
|
37 //roles profiles |
|
38 $form['roles'] = array('#tree' => TRUE); |
|
39 $roles = imce_sorted_roles(); |
|
40 $form['#weighted'] = count($roles) > 3; |
|
41 |
|
42 foreach ($roles as $rid => $role) { |
|
43 $core = $rid == DRUPAL_ANONYMOUS_RID || $rid == DRUPAL_AUTHENTICATED_RID; |
|
44 $form['roles'][$rid] = imce_role_form($role, $form['#weighted'], $core); |
|
45 } |
|
46 |
|
47 //common settings |
|
48 $form['common'] = array( |
|
49 '#type' => 'fieldset', |
|
50 '#title' => t('Common settings'), |
|
51 '#collapsible' => TRUE, |
|
52 '#collapsed' => TRUE, |
|
53 ); |
|
54 $form['common']['textarea'] = array( |
|
55 '#type' => 'textfield', |
|
56 '#title' => t('Enable inline image/file insertion into plain textareas'), |
|
57 '#default_value' => variable_get('imce_settings_textarea', ''), |
|
58 '#maxlength' => NULL, |
|
59 '#description' => t('If you don\'t use any WYSIWYG editor, this feature will allow you to add your images or files as <strong>html code into any plain textarea</strong>. Enter <strong>comma separated textarea IDs</strong> under which you want to enable a link to IMCE. Hint: ID of Body fields in most node types is edit-body.'), |
|
60 ); |
|
61 $form['common']['absurls'] = array( |
|
62 '#type' => 'checkbox', |
|
63 '#title' => t('Absolute URLs'), |
|
64 '#default_value' => variable_get('imce_settings_absurls', 0), |
|
65 '#description' => t('Check if you want IMCE to return absolute file URLs.'), |
|
66 ); |
|
67 $form['common']['replace'] = array( |
|
68 '#type' => 'radios', |
|
69 '#title' => t('Default behaviour for existing files during file uploads'), |
|
70 '#default_value' => variable_get('imce_settings_replace', FILE_EXISTS_RENAME), |
|
71 '#options' => array( |
|
72 FILE_EXISTS_RENAME => t('Keep the existing file renaming the new one'), |
|
73 FILE_EXISTS_ERROR => t('Keep the existing file rejecting the new one'), |
|
74 FILE_EXISTS_REPLACE => t('Replace the existing file with the new one') |
|
75 ), |
|
76 ); |
|
77 $form['common']['thumb_method'] = array( |
|
78 '#type' => 'radios', |
|
79 '#title' => t('Default method for creating thumbnails'), |
|
80 '#default_value' => variable_get('imce_settings_thumb_method', 'scale_and_crop'), |
|
81 '#options' => array( |
|
82 'scale' => t('Scale the image with respect to the thumbnail dimensions.'), |
|
83 'scale_and_crop' => t('First scale then crop the image to fit the thumbnail dimensions.') |
|
84 ), |
|
85 ); |
|
86 |
|
87 $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); |
|
88 $form['#theme'] = 'imce_admin'; |
|
89 $form['#submit'][] = 'imce_admin_submit'; |
|
90 return $form; |
|
91 } |
|
92 |
|
93 /** |
|
94 * Admin form themed. |
|
95 */ |
|
96 function imce_admin_theme($form = array()) { |
|
97 $u1p = imce_user1_profile(); |
|
98 $header = array(t('User role'), t('Assigned profile')); |
|
99 $keys = array('name', 'pid'); |
|
100 $rows[0] = array(t('user #1'), $u1p['name']); |
|
101 $info = ''; |
|
102 |
|
103 if ($form['#weighted']) { |
|
104 $header[] = t('Weight'); |
|
105 $keys[] = 'weight'; |
|
106 $rows[0][] = t('n/a'); |
|
107 $info = t('For users who have <strong>multiple roles</strong>, <strong>weight</strong> property will determine the assigned profile. Lighter roles that are placed upper will take the precedence. So, an administrator role should be placed over other roles by having a smaller weight, ie. -10.'); |
|
108 } |
|
109 |
|
110 foreach (element_children($form['roles']) as $rid) { |
|
111 $cells = array(); |
|
112 foreach ($keys as $key) { |
|
113 $cells[] = drupal_render($form['roles'][$rid][$key]); |
|
114 } |
|
115 $rows[] = $cells; |
|
116 } |
|
117 |
|
118 $output = '<h2 class="title">'. t('Role-profile assignments') .'</h2>'; |
|
119 $output .= theme('table', $header, $rows); |
|
120 $output .= '<div class="form-item"><div class="description">'. t('Assign profiles to user roles.') .' '. $info .'</div></div>'; |
|
121 $output .= drupal_render($form['common']); |
|
122 $output .= drupal_render($form); |
|
123 return $output; |
|
124 } |
|
125 |
|
126 /** |
|
127 * Submit admin form. |
|
128 */ |
|
129 function imce_admin_submit($form, &$form_state) { |
|
130 $roles = $form_state['values']['roles']; |
|
131 if (count($roles) > 3) { |
|
132 uasort($roles, 'imce_rolesort'); |
|
133 } |
|
134 variable_set('imce_roles_profiles', $roles); |
|
135 variable_set('imce_settings_textarea', $form_state['values']['textarea']); |
|
136 variable_set('imce_settings_absurls', $form_state['values']['absurls']); |
|
137 variable_set('imce_settings_replace', $form_state['values']['replace']); |
|
138 variable_set('imce_settings_thumb_method', $form_state['values']['thumb_method']); |
|
139 drupal_set_message(t('Changes have been saved.')); |
|
140 } |
|
141 |
|
142 /** |
|
143 * Add-Edit-Delete profiles. |
|
144 */ |
|
145 function imce_profile_operations($op = 'add', $pid = 0) { |
|
146 //delete |
|
147 if ($op == 'delete') { |
|
148 drupal_set_title('Delete profile'); |
|
149 return drupal_get_form('imce_profile_delete_form', $pid); |
|
150 } |
|
151 //add-edit |
|
152 if ($pid != 1 || $GLOBALS['user']->uid == 1) { |
|
153 return drupal_get_form('imce_profile_form', $pid); |
|
154 } |
|
155 drupal_access_denied(); |
|
156 } |
|
157 |
|
158 /** |
|
159 * Profile form. |
|
160 */ |
|
161 function imce_profile_form(&$form_state, $pid = 0) { |
|
162 |
|
163 if ($pid && $profile = imce_load_profile($pid)) { |
|
164 drupal_set_title($profile['name']); |
|
165 } |
|
166 else { |
|
167 $pid = 0; |
|
168 $profile = imce_sample_profile(); |
|
169 $profile['name'] = ''; |
|
170 } |
|
171 |
|
172 //import profile |
|
173 if (isset($_GET['import']) && $imported = imce_load_profile($_GET['import'])) { |
|
174 if (empty($form_state['post'])) { |
|
175 drupal_set_message(t('Settings were imported from the profile %name', array('%name' => $imported['name']))); |
|
176 } |
|
177 $imported['name'] = $profile['name']; //preserve the original name. |
|
178 $profile = $imported; |
|
179 } |
|
180 |
|
181 $form_state['profile'] = $profile;//store the original profile just in case. |
|
182 |
|
183 $form = array('#tree' => TRUE); |
|
184 $form['name'] = array( |
|
185 '#type' => 'textfield', |
|
186 '#title' => t('Profile name'), |
|
187 '#default_value' => $profile['name'], |
|
188 '#description' => t('Give a name to this profile.'), |
|
189 '#required' => TRUE, |
|
190 ); |
|
191 $form['import'] = array( |
|
192 '#type' => 'markup', |
|
193 '#value' => imce_profile_import_html($pid), |
|
194 ); |
|
195 $form['filesize'] = array( |
|
196 '#type' => 'textfield', |
|
197 '#title' => t('Maximum file size per upload'), |
|
198 '#default_value' => $profile['filesize'], |
|
199 '#description' => t('Set to 0 to use the maximum value avaliable.') .' '. t('Your PHP settings limit the maximum file size per upload to %size.', array('%size' => format_size(file_upload_max_size()))), |
|
200 '#field_suffix' => t('MB'), |
|
201 ); |
|
202 $form['quota'] = array( |
|
203 '#type' => 'textfield', |
|
204 '#title' => t('Directory quota'), |
|
205 '#default_value' => $profile['quota'], |
|
206 '#description' => t('Define the upload quota per directory. Total user quota is proportional to the number of directories that the user has upload access to.') .' '. t('Set to 0 to use the maximum value avaliable.'), |
|
207 '#field_suffix' => t('MB'), |
|
208 ); |
|
209 $form['tuquota'] = array( |
|
210 '#type' => 'textfield', |
|
211 '#title' => t('Total user quota'), |
|
212 '#default_value' => $profile['tuquota'], |
|
213 '#description' => t('You can force total user quota to be a value independent of directory quota. <strong>This quota is calculated using the files table in the database, so that it will not include the files uploaded via FTP or by previous versions of IMCE(4.7.x and 5.x)</strong>. You can either use both quotations together or safely ignore this by setting the value to 0.'), |
|
214 '#field_suffix' => t('MB'), |
|
215 ); |
|
216 $form['extensions'] = array( |
|
217 '#type' => 'textfield', |
|
218 '#title' => t('Permitted file extensions'), |
|
219 '#default_value' => $profile['extensions'], |
|
220 '#maxlength' => 255, |
|
221 '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.') .' '. t('Set to * to remove the restriction.'), |
|
222 ); |
|
223 $form['dimensions'] = array( |
|
224 '#type' => 'textfield', |
|
225 '#title' => t('Maximum image resolution'), |
|
226 '#default_value' => $profile['dimensions'], |
|
227 '#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'))), |
|
228 '#field_suffix' => '<kbd>'. t('WIDTHxHEIGHT') .'</kbd>' |
|
229 ); |
|
230 $form['filenum'] = array( |
|
231 '#type' => 'textfield', |
|
232 '#title' => t('Maximum number of files per operation'), |
|
233 '#default_value' => $profile['filenum'], |
|
234 '#description' => t('You can allow users to select multiple files for operations such as delete, resize, etc. Entire batch file operation is executed in a single drupal load, which may be good. However there will be an increase in script execution time, cpu load and memory consumption possibly exceeding the limits of your server, which is really bad. For unlimited number of file handling, set this to 0.'), |
|
235 ); |
|
236 |
|
237 //Directories |
|
238 $form['directories']['#theme'] = 'imce_directories'; |
|
239 $form['directories']['#weight'] = 1; |
|
240 for ($i = 0; $i < count($profile['directories']); $i++) { |
|
241 $form['directories'][$i] = imce_directory_form($profile['directories'][$i]); |
|
242 } |
|
243 $form['directories'][$i] = imce_directory_form(); |
|
244 $form['directories'][$i+1] = imce_directory_form(); |
|
245 |
|
246 //Thumbnails |
|
247 $form['thumbnails']['#theme'] = 'imce_thumbnails'; |
|
248 $form['thumbnails']['#weight'] = 2; |
|
249 for ($i = 0; $i < count($profile['thumbnails']); $i++) { |
|
250 $form['thumbnails'][$i] = imce_thumbnail_form($profile['thumbnails'][$i]); |
|
251 } |
|
252 $form['thumbnails'][$i] = imce_thumbnail_form(); |
|
253 $form['thumbnails'][$i+1] = imce_thumbnail_form(); |
|
254 |
|
255 $form = array('profile' => $form); |
|
256 $form['pid'] = array('#type' => 'hidden', '#value' => $pid); |
|
257 $form['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); |
|
258 //$form['#action'] = url('admin/settings/imce/profile/'. $pid); |
|
259 $form['#submit'][] = 'imce_profile_submit'; |
|
260 return $form; |
|
261 } |
|
262 |
|
263 /** |
|
264 * Profile form submit. |
|
265 */ |
|
266 function imce_profile_submit($form, &$form_state) { |
|
267 $profile = $form_state['values']['profile']; |
|
268 $pid = $form_state['values']['pid']; |
|
269 $message = $pid > 0 ? t('The changes have been saved.') : t('Profile has been added.'); |
|
270 |
|
271 //unset empty fields of directories and thumbnails. |
|
272 imce_clean_profile_fields($profile); |
|
273 |
|
274 //save profile. |
|
275 $pid = imce_update_profiles($pid, $profile); |
|
276 |
|
277 drupal_set_message($message); |
|
278 $form_state['redirect'] = 'admin/settings/imce/profile/edit/'. $pid; |
|
279 } |
|
280 |
|
281 /** |
|
282 * directory settings form |
|
283 */ |
|
284 function imce_directory_form($directory = array()) { |
|
285 if (empty($directory)) { |
|
286 $directory = array('name' => '', 'subnav' => 0, 'browse' => 0, 'upload' => 0, 'thumb' => 0, 'delete' => 0, 'resize' => 0); |
|
287 } |
|
288 $form['name'] = array( |
|
289 '#type' => 'textfield', |
|
290 '#default_value' => $directory['name'], |
|
291 '#size' => 24, |
|
292 '#maxlength' => NULL, |
|
293 ); |
|
294 $form['subnav'] = array( |
|
295 '#type' => 'checkbox', |
|
296 '#title' => t('Including subdirectories'), |
|
297 '#default_value' => $directory['subnav'], |
|
298 ); |
|
299 $form['browse'] = array( |
|
300 '#type' => 'checkbox', |
|
301 '#title' => t('Browse'), |
|
302 '#default_value' => $directory['browse'], |
|
303 ); |
|
304 $form['upload'] = array( |
|
305 '#type' => 'checkbox', |
|
306 '#title' => t('Upload'), |
|
307 '#default_value' => $directory['upload'], |
|
308 ); |
|
309 $form['thumb'] = array( |
|
310 '#type' => 'checkbox', |
|
311 '#title' => t('Thumbnails'), |
|
312 '#default_value' => $directory['thumb'], |
|
313 ); |
|
314 $form['delete'] = array( |
|
315 '#type' => 'checkbox', |
|
316 '#title' => t('Delete'), |
|
317 '#default_value' => $directory['delete'], |
|
318 ); |
|
319 $form['resize'] = array( |
|
320 '#type' => 'checkbox', |
|
321 '#title' => t('Resize'), |
|
322 '#default_value' => $directory['resize'], |
|
323 ); |
|
324 return $form; |
|
325 } |
|
326 |
|
327 /** |
|
328 * Directorys form themed. |
|
329 */ |
|
330 function imce_directories_theme($form = array()) { |
|
331 $rows = array(); |
|
332 $root = file_directory_path(); |
|
333 |
|
334 foreach (element_children($form) as $key) { |
|
335 //directory path |
|
336 $row = array('<div class="container-inline">'. $root .'/'. drupal_render($form[$key]['name']) .'</div>'. drupal_render($form[$key]['subnav'])); |
|
337 unset($form[$key]['name'], $form[$key]['subnav']); |
|
338 |
|
339 //permissions |
|
340 $header = array(); |
|
341 foreach (element_children($form[$key]) as $perm) { |
|
342 $header[] = $form[$key][$perm]['#title']; |
|
343 unset($form[$key][$perm]['#title']); |
|
344 $row[] = drupal_render($form[$key][$perm]); |
|
345 } |
|
346 |
|
347 $rows[] = $row; |
|
348 } |
|
349 |
|
350 array_unshift($header, t('Directory path')); |
|
351 |
|
352 $output = '<h3 class="title">'. t('Directories') .'</h3>'; |
|
353 $output .= theme('table', $header, $rows); |
|
354 $output .= '<div class="form-item"><div class="description">'. t('Define directories that users of this profile can access. |
|
355 <ul> |
|
356 <li>Use alphanumeric characters as directory paths.</li> |
|
357 <li>To specify file system root, just enter <strong>.</strong>(dot) character.</li> |
|
358 <li>Use <strong>%uid</strong> as a placeholder for user ID. Ex: <em>users/user%uid</em> creates directories such as <em>users/user1</em>, <em>users/user42</em>, etc.</li> |
|
359 <li>To remove a directory from the list, leave the directory path blank.</li> |
|
360 <li>If you want more flexibility in directory paths you can execute php to return a directory path.<br /> |
|
361 For php execution your directory path must start with <strong>php:</strong> and the rest must be a valid php code that is expected to return the actual directory path. <br />Ex: <strong>php: return \'users/\'.$user->name;</strong> defines <strong>users/USER-NAME</strong> as the directory path.<br /> |
|
362 A multi-level directory example <strong>php: return date(\'Y\', $user->created).\'/\'.date(\'m\', $user->created).\'/\'.$user->uid;</strong> defines <strong>MEMBERSHIP-YEAR/MONTH/USER-ID</strong> as the directory path, resulting in self-categorized user directories based on membership date.<br /> |
|
363 Note that you should use the $user variable instead of $GLOBALS[\'user\'] since they are not always the same object.</li> |
|
364 </ul> |
|
365 <p>Note that thumbnails permission does not affect thumbnail creation on upload. See thumbnails decription below.</p> |
|
366 <p>If you need more fields, just fill all and save, and you will get two more on the next page.</p>') .'</div></div>'; |
|
367 $output .= drupal_render($form); |
|
368 return $output; |
|
369 } |
|
370 |
|
371 /** |
|
372 * thumbnail settings form |
|
373 */ |
|
374 function imce_thumbnail_form($thumb = array()) { |
|
375 if (empty($thumb)) { |
|
376 $thumb = array('name' => '', 'dimensions' => '', 'prefix' => '', 'suffix' => ''); |
|
377 } |
|
378 $form['name'] = array( |
|
379 '#type' => 'textfield', |
|
380 '#default_value' => $thumb['name'], |
|
381 '#size' => 20, |
|
382 ); |
|
383 $form['dimensions'] = array( |
|
384 '#type' => 'textfield', |
|
385 '#default_value' => $thumb['dimensions'], |
|
386 '#size' => 20, |
|
387 ); |
|
388 $form['prefix'] = array( |
|
389 '#type' => 'textfield', |
|
390 '#default_value' => $thumb['prefix'], |
|
391 '#size' => 20, |
|
392 ); |
|
393 $form['suffix'] = array( |
|
394 '#type' => 'textfield', |
|
395 '#default_value' => $thumb['suffix'], |
|
396 '#size' => 20, |
|
397 ); |
|
398 return $form; |
|
399 } |
|
400 |
|
401 /** |
|
402 * Thumbnails form themed. |
|
403 */ |
|
404 function imce_thumbnails_theme($form = array()) { |
|
405 $header = array(t('Name'), t('Dimensions'), t('Prefix'), t('Suffix')); |
|
406 $rows = array(); |
|
407 |
|
408 foreach (element_children($form) as $key) { |
|
409 $rows[] = array( |
|
410 drupal_render($form[$key]['name']), |
|
411 drupal_render($form[$key]['dimensions']), |
|
412 drupal_render($form[$key]['prefix']), |
|
413 drupal_render($form[$key]['suffix']), |
|
414 ); |
|
415 } |
|
416 |
|
417 $output = '<h3 class="title">'. t('Thumbnails') .'</h3>'; |
|
418 $output .= theme('table', $header, $rows); |
|
419 $output .= '<div class="form-item"><div class="description">'. t('You may create a list of thumbnail options that users can choose from. |
|
420 <ul> |
|
421 <li>Use alphanumeric characters as thumbnail names.</li> |
|
422 <li>Specify dimensions as <strong>WidthxHeight</strong>.</li> |
|
423 <li>Prefix and suffix are strings that are added to original file name to create the thumbnail name.</li> |
|
424 <li>An example thumbnail: Name = <strong>Small</strong>, Dimensions = <strong>80x80</strong>, Prefix = <strong>small_</strong></li> |
|
425 </ul> |
|
426 <p>Note that users will always be able to create thumbnails on file upload no matter what the thumbnail permission is. To disable thumbnail creation on file upload you should not define any thumbnails here.</p> |
|
427 <p>If you need more fields, just fill all and save, and you will get two more on the next page.</p>') .'</div></div>'; |
|
428 $output .= drupal_render($form); |
|
429 return $output; |
|
430 } |
|
431 |
|
432 /** |
|
433 * Role-profile form |
|
434 */ |
|
435 function imce_role_form($role, $weight = TRUE, $core = TRUE) { |
|
436 $form['name'] = array( |
|
437 '#type' => 'markup', |
|
438 '#value' => $role['name'], |
|
439 ); |
|
440 if ($weight) { |
|
441 $form['weight'] = $core ? array( |
|
442 '#type' => 'textfield', |
|
443 '#value' => $role['weight'], |
|
444 '#attributes' => array('readonly' => 'readonly', 'style' => 'border: none; width: 2em; background-color: transparent;'), |
|
445 ) : array( |
|
446 '#type' => 'weight', |
|
447 '#default_value' => $role['weight'], |
|
448 ); |
|
449 } |
|
450 $form['pid'] = array( |
|
451 '#type' => 'select', |
|
452 '#options' => imce_profile_options(), |
|
453 '#default_value' => $role['pid'], |
|
454 ); |
|
455 return $form; |
|
456 } |
|
457 |
|
458 /** |
|
459 * Profile delete form |
|
460 */ |
|
461 function imce_profile_delete_form(&$form_state, $pid) { |
|
462 if ($pid > 1 && $profile = imce_load_profile($pid)) { |
|
463 $form['#submit'][] = 'imce_profile_delete_submit'; |
|
464 $form['pid'] = array('#type' => 'hidden', '#value' => $pid); |
|
465 return confirm_form($form, |
|
466 t('Are you sure you want to delete the profile %name?', |
|
467 array('%name' => $profile['name'])), |
|
468 'admin/settings/imce', |
|
469 '', |
|
470 t('Delete'), |
|
471 t('Cancel') |
|
472 ); |
|
473 } |
|
474 drupal_goto('admin/settings/imce'); |
|
475 } |
|
476 |
|
477 /** |
|
478 * Profile delete form submit |
|
479 */ |
|
480 function imce_profile_delete_submit($form, &$form_state) { |
|
481 imce_update_profiles($form_state['values']['pid'], NULL); |
|
482 drupal_set_message(t('Profile has been deleted.')); |
|
483 $form_state['redirect'] = 'admin/settings/imce'; |
|
484 } |
|
485 |
|
486 /** |
|
487 * Profile options. |
|
488 */ |
|
489 function imce_profile_options() { |
|
490 $options = array(t('none')); |
|
491 foreach (variable_get('imce_profiles', array()) as $pid => $profile) { |
|
492 $options[$pid] = $profile['name']; |
|
493 } |
|
494 return $options; |
|
495 } |
|
496 |
|
497 /** |
|
498 * Profile import links. |
|
499 */ |
|
500 function imce_profile_import_html($pid = 0) { |
|
501 $output = ''; |
|
502 $links = array(); |
|
503 |
|
504 foreach (variable_get('imce_profiles', array()) as $id => $profile) { |
|
505 if ($pid != $id) { |
|
506 $links[] = l($profile['name'], $_GET['q'], array('query' => 'import='. $id)); |
|
507 } |
|
508 } |
|
509 |
|
510 if (!empty($links)) { |
|
511 $output = '<p><strong>'. t('Import settings from other profiles') .'</strong>: '; |
|
512 $output .= implode(', ', $links) .'</p>'; |
|
513 } |
|
514 |
|
515 return $output; |
|
516 } |
|
517 |
|
518 /** |
|
519 * Update role-profile assignments. |
|
520 */ |
|
521 function imce_update_roles($pid) { |
|
522 $roles = variable_get('imce_roles_profiles', array()); |
|
523 foreach ($roles as $rid => $role) { |
|
524 if ($role['pid'] == $pid) { |
|
525 $roles[$rid]['pid'] = 0; |
|
526 } |
|
527 else if ($role['pid'] > $pid) { |
|
528 $roles[$rid]['pid']--; |
|
529 } |
|
530 } |
|
531 variable_set('imce_roles_profiles', $roles); |
|
532 } |
|
533 |
|
534 /** |
|
535 * Add, update or delete a profile. |
|
536 */ |
|
537 function imce_update_profiles($pid, $profile = NULL) { |
|
538 $profiles = variable_get('imce_profiles', array()); |
|
539 |
|
540 //add or update |
|
541 if (isset($profile)) { |
|
542 $pid = isset($profiles[$pid]) ? $pid : count($profiles)+1; |
|
543 $profiles[$pid] = $profile; |
|
544 } |
|
545 |
|
546 //delete |
|
547 else if (isset($profiles[$pid]) && $pid > 1) { |
|
548 unset($profiles[$pid]); |
|
549 for ($i = $pid+1; isset($profiles[$i]); $i++) { |
|
550 $profiles[$i-1] = $profiles[$i]; |
|
551 unset($profiles[$i]); |
|
552 } |
|
553 imce_update_roles($pid); |
|
554 } |
|
555 |
|
556 variable_set('imce_profiles', $profiles); |
|
557 return $pid; |
|
558 } |
|
559 |
|
560 /** |
|
561 * Unset empty fields in thumbnails and directory paths. |
|
562 */ |
|
563 function imce_clean_profile_fields(&$profile) { |
|
564 $clean = array(); |
|
565 foreach ($profile['thumbnails'] as $thumb) { |
|
566 if (trim($thumb['name']) != '' && preg_match('/^\d+x\d+$/', $thumb['dimensions'])) { |
|
567 $clean[] = $thumb; |
|
568 } |
|
569 } |
|
570 $profile['thumbnails'] = $clean; |
|
571 |
|
572 $clean = array(); |
|
573 $names = array(); |
|
574 foreach ($profile['directories'] as $dir) { |
|
575 $dir['name'] = trim($dir['name'], '/ '); |
|
576 if ($dir['name'] == '') { |
|
577 continue; |
|
578 } |
|
579 if (isset($names[$dir['name']])) { |
|
580 drupal_set_message(t('Duplicate directory paths are not allowed.'), 'error'); |
|
581 continue; |
|
582 } |
|
583 if (!imce_reg_dir($dir['name'])) { |
|
584 drupal_set_message(t('%dirname is not accepted as a proper directory name.', array('%dirname' => $dir['name'])), 'error'); |
|
585 continue; |
|
586 } |
|
587 $clean[] = $dir; |
|
588 $names[$dir['name']] = 1; |
|
589 } |
|
590 $profile['directories'] = $clean; |
|
591 } |
|
592 |
|
593 /** |
|
594 * Profile load. |
|
595 */ |
|
596 function imce_load_profile($pid) { |
|
597 $profiles = variable_get('imce_profiles', array()); |
|
598 return isset($profiles[$pid]) ? $profiles[$pid] : NULL; |
|
599 } |
|
600 |
|
601 /** |
|
602 * Sort roles according to their weights. |
|
603 */ |
|
604 function imce_sorted_roles() { |
|
605 static $sorted; |
|
606 if (!isset($sorted)) { |
|
607 $sorted = array(); |
|
608 $roles = user_roles(); |
|
609 $profiles = variable_get('imce_profiles', array()); |
|
610 $irp = variable_get('imce_roles_profiles', array()); |
|
611 $irp[DRUPAL_ANONYMOUS_RID]['weight'] = 12; |
|
612 $irp[DRUPAL_AUTHENTICATED_RID]['weight'] = 11; |
|
613 foreach ($roles as $rid => $rname) { |
|
614 $sorted[$rid] = array( |
|
615 'name' => $rname, |
|
616 'weight' => isset($irp[$rid]['weight']) ? $irp[$rid]['weight'] : 0, |
|
617 'pid' => isset($irp[$rid]['pid']) && isset($profiles[$irp[$rid]['pid']]) ? $irp[$rid]['pid'] : 0, |
|
618 ); |
|
619 } |
|
620 uasort($sorted, 'imce_rolesort'); |
|
621 } |
|
622 return $sorted; |
|
623 } |
|
624 |
|
625 /** |
|
626 * Sorting function for roles. |
|
627 */ |
|
628 function imce_rolesort($r1, $r2) { |
|
629 return $r1['weight']-$r2['weight']; |
|
630 } |
|
631 |
|
632 //Include core profile functions. |
|
633 include_once './'. drupal_get_path('module', 'imce') .'/inc/core_profiles.inc'; |