[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/modules/upload/ -> upload.admin.inc (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7