home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / CMS / drupal-6.0.exe / drupal-6.0 / modules / upload / upload.admin.inc next >
Encoding:
Text File  |  2008-01-10  |  7.5 KB  |  153 lines

  1. <?php
  2. // $Id: upload.admin.inc,v 1.7 2008/01/10 20:22:57 goba Exp $
  3.  
  4. /**
  5.  * Form API callback to validate the upload settings form.
  6.  */
  7. function upload_admin_settings_validate($form, &$form_state) {
  8.   if (($form_state['values']['upload_max_resolution'] != '0')) {
  9.     if (!preg_match('/^[0-9]+x[0-9]+$/', $form_state['values']['upload_max_resolution'])) {
  10.       form_set_error('upload_max_resolution', t('The maximum allowed image size expressed as WIDTHxHEIGHT (e.g. 640x480). Set to 0 for no restriction.'));
  11.     }
  12.   }
  13.  
  14.   $default_uploadsize = $form_state['values']['upload_uploadsize_default'];
  15.   $default_usersize = $form_state['values']['upload_usersize_default'];
  16.  
  17.   $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/>';
  18.   $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.");
  19.  
  20.   if (!is_numeric($default_uploadsize) || ($default_uploadsize <= 0)) {
  21.     form_set_error('upload_uploadsize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
  22.   }
  23.   if (!is_numeric($default_usersize) || ($default_usersize <= 0)) {
  24.     form_set_error('upload_usersize_default', t('The %role file size limit must be a number and greater than zero.', array('%role' => t('default'))));
  25.   }
  26.   if ($default_uploadsize * 1024 * 1024 > file_upload_max_size()) {
  27.     form_set_error('upload_uploadsize_default', $exceed_max_msg . $more_info);
  28.     $more_info = '';
  29.   }
  30.   if ($default_uploadsize > $default_usersize) {
  31.     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'))));
  32.   }
  33.  
  34.   foreach ($form_state['values']['roles'] as $rid => $role) {
  35.     $uploadsize = $form_state['values']['upload_uploadsize_'. $rid];
  36.     $usersize = $form_state['values']['upload_usersize_'. $rid];
  37.  
  38.     if (!is_numeric($uploadsize) || ($uploadsize <= 0)) {
  39.       form_set_error('upload_uploadsize_'. $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
  40.     }
  41.     if (!is_numeric($usersize) || ($usersize <= 0)) {
  42.       form_set_error('upload_usersize_'. $rid, t('The %role file size limit must be a number and greater than zero.', array('%role' => $role)));
  43.     }
  44.     if ($uploadsize * 1024 * 1024 > file_upload_max_size()) {
  45.       form_set_error('upload_uploadsize_'. $rid, $exceed_max_msg . $more_info);
  46.       $more_info = '';
  47.     }
  48.     if ($uploadsize > $usersize) {
  49.       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)));
  50.     }
  51.   }
  52. }
  53.  
  54. /**
  55.  * Menu callback for the upload settings form.
  56.  */
  57. function upload_admin_settings() {
  58.   $upload_extensions_default = variable_get('upload_extensions_default', 'jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp');
  59.   $upload_uploadsize_default = variable_get('upload_uploadsize_default', 1);
  60.   $upload_usersize_default = variable_get('upload_usersize_default', 1);
  61.  
  62.   $form['settings_general'] = array(
  63.     '#type' => 'fieldset',
  64.     '#title' => t('General settings'),
  65.     '#collapsible' => TRUE,
  66.   );
  67.   $form['settings_general']['upload_max_resolution'] = array(
  68.     '#type' => 'textfield',
  69.     '#title' => t('Maximum resolution for uploaded images'),
  70.     '#default_value' => variable_get('upload_max_resolution', 0),
  71.     '#size' => 15,
  72.     '#maxlength' => 10,
  73.     '#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'))),
  74.     '#field_suffix' => '<kbd>'. t('WIDTHxHEIGHT') .'</kbd>'
  75.   );
  76.   $form['settings_general']['upload_list_default'] = array(
  77.     '#type' => 'select',
  78.     '#title' => t('List files by default'),
  79.     '#default_value' => variable_get('upload_list_default', 1),
  80.     '#options' => array(0 => t('No'), 1 => t('Yes')),
  81.     '#description' => t('Display attached files when viewing a post.'),
  82.   );
  83.  
  84.   $form['settings_general']['upload_extensions_default'] = array(
  85.     '#type' => 'textfield',
  86.     '#title' => t('Default permitted file extensions'),
  87.     '#default_value' => $upload_extensions_default,
  88.     '#maxlength' => 255,
  89.     '#description' => t('Default extensions that users can upload. Separate extensions with a space and do not include the leading dot.'),
  90.   );
  91.   $form['settings_general']['upload_uploadsize_default'] = array(
  92.     '#type' => 'textfield',
  93.     '#title' => t('Default maximum file size per upload'),
  94.     '#default_value' => $upload_uploadsize_default,
  95.     '#size' => 5,
  96.     '#maxlength' => 5,
  97.     '#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.'),
  98.     '#field_suffix' => t('MB'),
  99.   );
  100.   $form['settings_general']['upload_usersize_default'] = array(
  101.     '#type' => 'textfield',
  102.     '#title' => t('Default total file size per user'),
  103.     '#default_value' => $upload_usersize_default,
  104.     '#size' => 5,
  105.     '#maxlength' => 5,
  106.     '#description' => t('The default maximum size of all files a user can have on the site.'),
  107.     '#field_suffix' => t('MB'),
  108.   );
  109.  
  110.   $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>');
  111.  
  112.   $roles = user_roles(FALSE, 'upload files');
  113.   $form['roles'] = array('#type' => 'value', '#value' => $roles);
  114.  
  115.   foreach ($roles as $rid => $role) {
  116.     $form['settings_role_'. $rid] = array(
  117.       '#type' => 'fieldset',
  118.       '#title' => t('Settings for @role', array('@role' => $role)),
  119.       '#collapsible' => TRUE,
  120.       '#collapsed' => TRUE,
  121.     );
  122.     $form['settings_role_'. $rid]['upload_extensions_'. $rid] = array(
  123.       '#type' => 'textfield',
  124.       '#title' => t('Permitted file extensions'),
  125.       '#default_value' => variable_get('upload_extensions_'. $rid, $upload_extensions_default),
  126.       '#maxlength' => 255,
  127.       '#description' => t('Extensions that users in this role can upload. Separate extensions with a space and do not include the leading dot.'),
  128.     );
  129.     $form['settings_role_'. $rid]['upload_uploadsize_'. $rid] = array(
  130.       '#type' => 'textfield',
  131.       '#title' => t('Maximum file size per upload'),
  132.       '#default_value' => variable_get('upload_uploadsize_'. $rid, $upload_uploadsize_default),
  133.       '#size' => 5,
  134.       '#maxlength' => 5,
  135.       '#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.'),
  136.       '#field_suffix' => t('MB'),
  137.     );
  138.     $form['settings_role_'. $rid]['upload_usersize_'. $rid] = array(
  139.       '#type' => 'textfield',
  140.       '#title' => t('Total file size per user'),
  141.       '#default_value' => variable_get('upload_usersize_'. $rid, $upload_usersize_default),
  142.       '#size' => 5,
  143.       '#maxlength' => 5,
  144.       '#description' => t('The maximum size of all files a user can have on the site.'),
  145.       '#field_suffix' => t('MB'),
  146.     );
  147.   }
  148.  
  149.   $form['#validate'] = array('upload_admin_settings_validate');
  150.  
  151.   return system_settings_form($form);
  152. }
  153.