You are here

function imagepicker_upload_form in Image Picker 7

Same name and namespace in other branches
  1. 5.2 imagepicker.module \imagepicker_upload_form()
  2. 5 imagepicker.module \imagepicker_upload_form()
  3. 6.2 imagepicker.upload.inc \imagepicker_upload_form()
1 string reference to 'imagepicker_upload_form'
imagepicker_quota_ok in ./imagepicker.functions.inc
Checks quotas

File

./imagepicker.upload.inc, line 40

Code

function imagepicker_upload_form($form, &$form_state, $account = FALSE, $admin = FALSE) {

  // multiple uploads
  $max_uploads = imagepicker_variable_get('imagepicker_max_uploads', 1);
  $settings = array(
    'imagepicker_upload_link' => array(
      'max_uploads' => $max_uploads,
    ),
  );
  $imagepicker_jspaths = imagepicker_jspaths_get();
  drupal_add_js($imagepicker_jspaths['imagepicker_upload_link_jspath']);
  drupal_add_js($settings, 'setting');
  if ($account) {
    $user = $account;
  }
  else {
    global $user;
  }
  $form['#attributes'] = array(
    'enctype' => 'multipart/form-data',
  );
  if (imagepicker_variable_get('imagepicker_upload_progress_enabled', 1) && imagepicker_variable_get('imagepicker_uploadprogress_server', '')) {
    $form[IMAGEPICKER_UPLOAD_ID] = array(
      '#type' => 'hidden',
      '#value' => uniqid(),
      '#weight' => -50,
    );
  }
  $form['maxmsg'] = array(
    '#markup' => '',
  );
  for ($ct = 1; $ct <= $max_uploads; $ct++) {
    $form['file_upload_' . $ct] = array(
      '#type' => 'file',
      '#title' => $max_uploads == 1 ? t('Image file') : t('Image file %ct', array(
        '%ct' => $ct,
      )),
      '#required' => $ct == 1 ? TRUE : FALSE,
      '#value' => 1,
      '#size' => 50,
    );
    $form['thumb_' . $ct] = array(
      '#type' => 'textfield',
      '#title' => t('Thumbnail size'),
      '#size' => 10,
      '#default_value' => imagepicker_variable_get('imagepicker_default_thumbnail_size', imagepicker_variable_get('imagepicker_default_thumbnail_size', 100), $user->uid),
      '#description' => t("Size in pixels of thumbnail's bigger side"),
      '#required' => TRUE,
    );

    // enforce a max size
    $max_scale = imagepicker_variable_get('imagepicker_max_scale', '');
    $max_msg = '';
    if ($max_scale) {
      $max_msg = t('Maximum !t', array(
        '!t' => $max_scale . 'px enforced',
      ));
    }
    $form['scale_' . $ct] = array(
      '#type' => 'textfield',
      '#title' => t('Scale image'),
      '#size' => 10,
      '#default_value' => imagepicker_variable_get('imagepicker_default_scale', imagepicker_variable_get('imagepicker_default_scale', ''), $user->uid),
      '#description' => t('Scale image to this size in pixels if not left empty. !m', array(
        '!m' => $max_msg,
      )),
    );
    if (imagepicker_image_check_functions(TRUE) && imagepicker_variable_get('imagepicker_watermark_enable', 0)) {
      if (!imagepicker_variable_get('imagepicker_watermark_image', '') && imagepicker_variable_get('imagepicker_watermark_image', '', $user->uid) && imagepicker_variable_get('imagepicker_watermark_enable', 0, $user->uid)) {
        $form['watermark_' . $ct] = array(
          '#type' => 'checkbox',
          '#title' => t('Use watermark'),
          '#description' => $max_uploads == 1 ? t('Use watermark on this image.') : t('Use watermark on Image file %ct', array(
            '%ct' => $ct,
          )),
          '#default_value' => imagepicker_variable_get('imagepicker_watermark_use', 0, $user->uid),
        );
        $form['watermark_perc_' . $ct] = array(
          '#type' => 'textfield',
          '#title' => t('JPEG quality'),
          '#size' => 10,
          '#maxlength' => 3,
          '#default_value' => imagepicker_variable_get('imagepicker_watermark_perc', variable_get('image_jpeg_quality', 75), $user->uid),
          '#description' => t('Define the image quality for JPEG manipulations. Ranges from 0 to 100. Higher values mean better image quality but bigger files.'),
        );
      }
      elseif (imagepicker_variable_get('imagepicker_watermark_image', '')) {
        $form['watermark_' . $ct] = array(
          '#type' => 'value',
          '#value' => 1,
        );
      }
    }
    $form['title_' . $ct] = array(
      '#type' => 'textfield',
      '#title' => $max_uploads == 1 ? t('Title') : t('Title for Image file %ct', array(
        '%ct' => $ct,
      )),
      '#description' => t('Add a title for your image'),
    );
    $form['description_' . $ct] = array(
      '#type' => 'textarea',
      '#title' => $max_uploads == 1 ? t('Description') : t('Description for Image file %ct', array(
        '%ct' => $ct,
      )),
      '#rows' => 2,
      '#cols' => 80,
      '#description' => t('Add a description for your image, max. 254 characters.'),
    );
    if ($ct < $max_uploads) {
      $form['link_' . $ct] = array(
        '#markup' => '',
      );
    }
  }

  // groups
  if (imagepicker_variable_get('imagepicker_groups_enabled', 1) && imagepicker_variable_get('imagepicker_groups_in_upload_enabled', 1)) {
    $grouplist = imagepicker_get_groups($admin ? $user : FALSE);
    if ($grouplist) {
      $form['grouplist'] = array(
        '#type' => 'checkboxes',
        '#options' => $grouplist,
        '#title' => t('Your Groups'),
        '#description' => t('Select a group to add your image to.'),
      );
    }
  }
  if ($account) {
    $form['account'] = array(
      '#type' => 'value',
      '#value' => $user->uid,
    );
  }
  if ($admin) {
    $form['admin'] = array(
      '#type' => 'value',
      '#value' => 1,
    );
  }
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => t('Upload'),
  );
  if (imagepicker_variable_get('imagepicker_upload_progress_enabled', 1)) {
    $form['#suffix'] = imagepicker_upload_progress_busy();
  }
  return $form;
}