[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/image_fupload/includes/ -> images.previewlist.image.inc (source)

   1  <?php
   2  // $Id: images.previewlist.image.inc,v 1.3 2009/03/14 10:26:19 grandcat Exp $
   3  
   4  /*
   5  * Provide a list (queue) of uploaded images; all captions can be edited at the same time
   6  */
   7  function fupload_list_images_image(&$form_state, $node_type) {
   8    global $user;
   9    $count = 0;  
  10    
  11    $node_type = str_replace("-", "_", $node_type);
  12    $image_node_types = variable_get('image_node_types', array());
  13    $type = node_get_types('type', $node_type);
  14    $field_name = $image_node_types[$node_type]['fieldname'];
  15    $field_settings = variable_get('fupload_previewlist_field_settings', array('title' => 'Title', 'body' => 'Body'));
  16    
  17    $result = db_query("SELECT nid, title FROM {node} WHERE type = '%s' AND uid = %d AND status = '0' AND created > %d", $node_type, $user->uid, time() - 86400); // only entries which are one day or newer
  18    while ($node = db_fetch_object($result)) {
  19      $count += 1;
  20      // Get all node infos, also image paths
  21      $node_image = node_load($node->nid);
  22      
  23      // only use this image node if it was produced by image_fupload
  24      if ($node_image->body == image_fupload_image_status($field_name, IMAGE_NOT_COMPLETED)) {
  25        $image_nodes[] = $node_image->nid;
  26      
  27        $form[$node_image->nid] = array(
  28          '#type' => 'fieldset',
  29          '#title' => t('Image @count', array('@count' => $count)),
  30          '#collapsible' => FALSE,
  31          '#collapsed' => FALSE,
  32        );
  33        $form[$node_image->nid]['preview_image'] = array(
  34          '#prefix' => '<div class="image_fupload_preview">',
  35          '#value' => _fupload_imagepreview($node_image, $node_type),
  36          '#suffix' => '</div>',
  37          '#weight' => 1,        
  38        );      
  39        $form[$node_image->nid]['title_' .$node_image->nid] = array(
  40          '#type' => 'textfield',
  41          '#title' => check_plain($type->title_label),
  42          '#default_value' => isset($form_state['values']['title_' .$node_image->nid]) ? $form_state['values']['title_' .$node_image->nid] : $node_image->title,
  43          '#size' => 60,
  44          '#required' => $field_settings['title'], // disabled fields don't send any data via form_state [#227966] =/
  45          '#disabled' => !$field_settings['title'],
  46          '#weight' => 3,
  47        );
  48        if ($type->has_body) {
  49          $form[$node_image->nid]['body_' .$node_image->nid] = array(
  50            '#type' => 'textarea',
  51            '#title' => check_plain($type->body_label),
  52            '#default_value' => isset($form_state['values']['body_' .$node_image->nid]) ? $form_state['values']['body_' .$node_image->nid] : '',
  53            '#rows' => 5,           
  54            //'#required' => ($type->min_word_count > 0),
  55            // will be checked later via validation hook
  56            '#disabled' => !$field_settings['body'],
  57            '#weight' => 5,
  58          );
  59          $form[$node_image->nid]['format_' .$node_image->nid] = filter_form($node_image->format, NULL, array('format_' .$node_image->nid));
  60          $form[$node_image->nid]['format_' .$node_image->nid]['#weight'] = 6;
  61        }
  62      }
  63    }
  64    
  65    if (!empty($image_nodes)) {
  66      // are there any images to edit?
  67      $form['text'] = array('#value' => t('In this step, you can edit the captions of all uploaded images. To complete this task, click the button "Done Editing" at the bottom of this page.'), '#weight' => -19);
  68      $form['#redirect'] = 'node/add/' .arg(2); // redirect to first upload page again
  69      $form['field_name'] = array('#type' => 'value', '#value' => $field_name);
  70      $form['image_nodes'] = array('#type' => 'value', '#value' => implode(';', $image_nodes));
  71      $form['#validate'][] = 'fupload_list_images_image_validate'; // some additonal validation of body field
  72      $form['submit'] = array('#type' => 'submit', '#value' => t('Done Editing'));
  73    } else {
  74      // no images in queue
  75      $form['text'] = array('#value' => t('No images yet in queue.'), '#weight' => -19);
  76      drupal_set_message(t('No images have been found in queue, probably no images have been uploaded yet. Please return to !upload_page if you want to upload some images.', array('!upload_page' => l(t('image upload page'), 'node/add/' .arg(2)))), 'warning');
  77    }
  78    
  79    // variable_set('image_node_types', array('imagefield_bild' => array('title' => 'ImageField', 'fieldname' => 'field_imagefile', 'image_selection' => '', 'imagecache_preset' => 'fupload_preview', 'image_dimension' => '127x200')));  
  80    return $form;
  81  }
  82  
  83  function fupload_list_images_image_validate($form, &$form_state) {
  84    // only validate body field, rest is already validated; code partially taken from function "node_validate" (D6)
  85    // get nids of images and start batch process (validation)
  86    $type = node_get_types('type', str_replace("-", "_", check_plain(arg(2))));
  87    $image_nids = explode(';', $form_state['values']['image_nodes']);
  88    
  89    for ($i = 0; $i < count($image_nids); $i++) {  
  90      if (!empty($type->min_word_count) && isset($form_state['values']['body_' .$image_nids[$i]]) && count(explode(' ', $form_state['values']['body_' .$image_nids[$i]])) < $type->min_word_count) {
  91        form_set_error('body_' .$image_nids[$i], t('The body of the @img_number. image is too short. You need at least %words words.', array('%words' => $type->min_word_count, '@img_number' => $i + 1)));
  92      }  
  93    } 
  94  }
  95  
  96  function fupload_list_images_image_submit($form, &$form_state) {  
  97    // get nids of images and start batch process (saving)
  98    $image_nids = explode(';', $form_state['values']['image_nodes']); 
  99    // name of image field
 100    $field_name = $form_state['values']['field_name'];
 101    for ($i = 0; $i < count($image_nids); $i++) { 
 102      // load full node object  
 103      $node = node_load($image_nids[$i]);    
 104      // new changes to node object
 105      $node->status = 1; // publish node
 106      $node->title = !empty($form_state['values']['title_' .$image_nids[$i]]) ? $form_state['values']['title_' .$image_nids[$i]] : $node->title; // work around [#227966]
 107      $node->body = $form_state['values']['body_' .$image_nids[$i]];
 108      if ($node->body == image_fupload_image_status($field_name, IMAGE_NOT_COMPLETED) || !isset($form_state['values']['body_' .$image_nids[$i]])) // nothing changed ==> empty body field
 109        $node->body = "";
 110      $node->teaser = node_teaser($node->body, $form_state['values']['format_' .$image_nids[$i]]);    
 111      $node->format = $form_state['values']['format_' .$image_nids[$i]];    
 112      // save new node object
 113      node_save($node);
 114    }
 115    drupal_set_message(t('All images have been saved and published.'));
 116    drupal_set_message(t('Additonal images can be selected and uploaded now.'));
 117    drupal_redirect_form($form);  
 118  }
 119  
 120  function _fupload_imagepreview($node_image, $node_type) {
 121    $image_node_types = variable_get('image_node_types', array());
 122    $attributes = variable_get('fupload_previewlist_img_attributes', '');
 123    /** need to split image module and other cck related imagemodules to be able to provide the right
 124       *     preview handling 
 125       */
 126    switch ($node_type) {    
 127      case 'image':
 128        // image module
 129        if (!empty($image_node_types['image']['imagecache_preset'])) {
 130          // using ImageCache
 131          $content = theme('imagecache', $image_node_types['image']['imagecache_preset'], $node_image->images['_original'], $node_image->title, $node_image->title, $attributes);
 132        } else {
 133          // using a ready-to-use Image size of Image module
 134          $image = $node_image->images[$image_node_types['image']['image_selection']];
 135          $content = theme('fupload_imagepreview_image', $image, image_get_info($image), $node_image, $attributes);
 136        }
 137        break;
 138      
 139      default:
 140        // imagefield cck module
 141        if (!empty($image_node_types[$node_type]['imagecache_preset'])) {
 142          // using ImageCache
 143          $field_name = $image_node_types[$node_type]['fieldname'];
 144          $image = $node_image->$field_name;
 145          
 146          $content = theme('imagecache', $image_node_types[$node_type]['imagecache_preset'], $image[0]['filepath'], $node_image->title, $node_image->title, $attributes);
 147        }
 148        break;
 149    }
 150    
 151    return $content;
 152  }
 153  
 154  /**
 155  * Custom theme for preview image (not imagecache image)
 156  **/
 157  
 158  function theme_fupload_imagepreview_image($image, $image_info, $node_image, $attributes) {
 159    $content = '<img src="' .file_create_url(file_create_path($image)). '" width="' .$image_info['width']. '" height="' .$image_info['height']. '" title="' .$node_image->title. '" alt="' .$node_image->title. '" class="image_fupload_preview_image"' .(!empty($attributes) ? (" " .$attributes) : "").' />';
 160    return $content;
 161  }


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