You are here

function photos_upload_form in Album Photos 7.3

Same name and namespace in other branches
  1. 6.2 inc/photos.edit.inc \photos_upload_form()

Upload form.

3 string references to 'photos_upload_form'
photos_edit_page in inc/photos.edit.inc
Image management.
photos_edit_upload in inc/photos.edit.inc
Photos upload and edit page.
photos_swfu_form_alter in photos_swfu/photos_swfu.module
Implements hook_form_alter().

File

inc/photos.edit.inc, line 62
Handles uploading and editing images.

Code

function photos_upload_form($form, &$form_state, $node = FALSE, $edit = array()) {
  global $user;
  $form['new'] = array(
    '#title' => t('Image upload'),
    '#weight' => -4,
    '#type' => 'fieldset',
    '#collapsible' => TRUE,
  );
  $allow_zip = variable_get('photos_upzip', 0) ? ' zip' : '';
  if (isset($node->type) && $node->type == 'photos' || photos_get_count('user_album', $user->uid)) {

    // Check if plubload is installed.
    if (variable_get('photos_plupload_status', 0)) {
      $form['new']['plupload'] = array(
        '#type' => 'plupload',
        '#title' => t('Upload photos'),
        '#description' => t('Upload multiple images.'),
        '#autoupload' => TRUE,
        '#submit_element' => '#edit-submit',
        '#upload_validators' => array(
          'file_validate_extensions' => array(
            'jpg jpeg gif png' . $allow_zip,
          ),
        ),
        '#plupload_settings' => array(
          'chunk_size' => '1mb',
        ),
      );
    }
    else {
      $form['new']['#description'] = t('Allow the type:') . ' jpg gif png jpeg' . $allow_zip;
      for ($i = 0; $i < variable_get('photos_num', 5); ++$i) {
        $form['new']['images_' . $i] = array(
          '#type' => 'file',
        );
        $form['new']['title_' . $i] = array(
          '#type' => 'textfield',
          '#title' => t('Image title'),
        );
        $form['new']['des_' . $i] = array(
          '#type' => 'textarea',
          '#title' => t('Image description'),
          '#cols' => 40,
          '#rows' => 3,
        );
      }
    }
  }
  else {
    drupal_set_message(t('You must first !create an album to upload images.', array(
      '!create' => l(t('create'), 'node/add/photos', array(
        'query' => drupal_get_destination(),
      )),
    )));
    return $form;
  }
  if (isset($node->type) && $node->type == 'photos') {
    $form['new']['pid'] = array(
      '#type' => 'value',
      '#value' => $node->nid,
    );
  }
  else {
    $form['#attached']['js'][] = drupal_get_path('module', 'photos') . '/js/min/photos_editlist.min.js';
    $form['new']['pid'] = array(
      '#title' => t('Upload to album'),
      '#type' => 'select',
      '#options' => _photos_useralbum_option($user->uid),
      '#default_value' => isset($_GET['pid']) ? $_GET['pid'] : NULL,
      '#required' => TRUE,
      '#prefix' => '<div id="photos-pid">',
      '#suffix' => '</div>',
      '#weight' => -5,
    );
  }
  if (isset($node->nid)) {
    $form['new']['nid'] = array(
      '#type' => 'value',
      '#value' => $node->nid,
    );
  }
  if ($edit['submit']) {
    $form['new']['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Confirm upload'),
      '#weight' => 10,
      '#submit' => array(
        'photos_upload_form_submit',
      ),
    );
    $form['#action'] = url($_GET['q'], array(
      'query' => drupal_get_destination(),
    ));
    $form['#attributes']['enctype'] = 'multipart/form-data';
  }
  return $form;
}