You are here

function photos_editlist_form in Album Photos 7.3

Edit list form.

3 string references to 'photos_editlist_form'
_photos_edit_page_node in inc/photos.edit.inc
Sub-album image management page.
_photos_edit_page_single_image in inc/photos.edit.inc
Album image management page.
_photos_prep_editlist in inc/photos.edit.inc
Prepare photos editlist form.

File

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

Code

function photos_editlist_form($form, &$form_state, $images = array(), $type = 'album') {
  global $user;

  // Check for node id.
  if (empty($images)) {
    $nid = arg(1);
  }
  else {
    if (isset($images[0]->info['nid'])) {
      $nid = $images[0]->info['nid'];
    }
    else {
      $nid = $images[0]->info['pid'];
    }
  }
  if ($type == 'album') {
    $album_update = '';
    if (isset($images[0]) && $user->uid != $images[0]->info['uid']) {
      $title = isset($images[0]->info['title']) ? $images[0]->info['title'] : '';
      $album_update = array(
        $nid,
        $images[0]->info['title'],
      );
    }
    else {
      $album_update = '';
    }
    $uid = isset($images[0]) ? $images[0]->uid : $user->uid;
    $album_pid = _photos_useralbum_option($uid, $album_update);
    $del_label = _photos_del_checkbox(0, t('Delete'));
    if (isset($images[0]->fid)) {
      $form['cover_fid'] = array(
        '#type' => 'hidden',
        '#default_value' => $images[0]->fid,
      );
    }
    $form['oldpid'] = array(
      '#type' => 'hidden',
      '#default_value' => $nid,
    );
    $submit = 'photos_editlist_submit';
  }
  else {
    $del_label = _photos_del_checkbox(0, t('Move out'));
    $submit = 'photos_editlist_submit_node';
    $form['nid'] = array(
      '#type' => 'hidden',
      '#default_value' => $nid,
    );
  }
  $form['photos']['#tree'] = TRUE;
  $thumb = variable_get('photos_title_0', FALSE);
  foreach ($images as $image) {
    $form['photos'][$image->fid]['del'] = $del_label;
    $image->user = user_load($image->uid);
    $image->href = 'photos/image/' . $image->fid;
    $item = array();
    $title = $image->title;
    $style_name = variable_get('photos_thumb_size', 'thumbnail');
    $image_view = theme('image_style', array(
      'style_name' => $style_name,
      'path' => $image->uri,
      'alt' => $title,
      'title' => $title,
    ));
    $item[] = l($image_view, $image->href, array(
      'html' => TRUE,
      'attributes' => array(
        'title' => $title,
      ),
    ));
    if ($type == 'album' && $images[0]->fid != $image->fid) {
      $item[] = l(t('Set to Cover'), 'node/' . $image->pid . '/photos/cover/' . $image->fid);
    }
    if (isset($image->filesize)) {
      $item[] = t('Filesize: !size KB', array(
        '!size' => round($image->filesize / 1024),
      ));
    }
    if (isset($image->count)) {
      $item[] = t('Visits: !count', array(
        '!count' => $image->count,
      ));
    }
    if (isset($image->comcount)) {
      $item[] = t('Comments: !count', array(
        '!count' => $image->comcount,
      ));
    }
    $form['photos'][$image->fid]['path']['#markup'] = theme('item_list', array(
      'items' => $item,
    ));
    $form['photos'][$image->fid]['des'] = array(
      '#title' => t('Image description'),
      '#type' => 'textarea',
      '#default_value' => isset($image->des) ? $image->des : '',
      '#cols' => 40,
      '#rows' => 4,
    );
    $form['photos'][$image->fid]['title'] = array(
      '#title' => t('Image title'),
      '#type' => 'textfield',
      '#default_value' => isset($image->title) ? $image->title : '',
      '#required' => FALSE,
    );
    $form['photos'][$image->fid]['wid'] = array(
      '#title' => t('Weight'),
      '#type' => 'textfield',
      '#size' => 5,
      '#default_value' => isset($image->wid) ? $image->wid : NULL,
    );
    $form['photos'][$image->fid]['filepath'] = array(
      '#type' => 'value',
      '#value' => $image->uri,
    );
    if ($type == 'album') {
      $upload_info = t('Uploaded on !time by !name', array(
        '!name' => theme('username', array(
          'account' => $image->user,
        )),
        '!time' => format_date($image->timestamp, 'small'),
      ));
      $form['photos'][$image->fid]['pid'] = array(
        '#title' => t('Move to the album'),
        '#type' => 'select',
        '#options' => $album_pid,
        '#default_value' => $image->pid,
        '#required' => TRUE,
      );
    }
    else {
      $upload_info = t('Uploaded by !name on !time to !title', array(
        '!name' => theme('username', array(
          'account' => $image->user,
        )),
        '!time' => format_date($image->timestamp, 'small'),
        '!title' => l($image->album_title, 'node/' . $image->pid),
      ));
    }
    $form['photos'][$image->fid]['time']['#markup'] = $upload_info;
    $form['photos'][$image->fid]['uid'] = array(
      '#type' => 'hidden',
      '#default_value' => $image->uid,
    );
    $form['photos'][$image->fid]['oldtitle'] = array(
      '#type' => 'hidden',
      '#default_value' => $image->title,
    );
  }
  if (!empty($images)) {
    $form['submit'] = array(
      '#type' => 'submit',
      '#value' => t('Confirm changes'),
      '#submit' => array(
        $submit,
      ),
    );
  }
  return $form;
}