You are here

function node_gallery_images_check_update in Node Gallery 6.3

Same name and namespace in other branches
  1. 6.2 node_gallery.pages.inc \node_gallery_images_check_update()

Check if we need to update this image;

Parameters

unknown_type $old_image:

unknown_type $new_image:

unknown_type $compare_fields:

Return value

unknown

1 call to node_gallery_images_check_update()
node_gallery_manage_images_submit in ./node_gallery.pages.inc

File

./node_gallery.pages.inc, line 455
Handles displaying of Node gallery pages.

Code

function node_gallery_images_check_update($old_image, $_new_image, $compare_fields) {

  // a list of node attributes that are flattened one level by node_save
  $flattened_attributes = array(
    'options',
  );
  $new_image = drupal_clone($_new_image);
  $new_image = node_submit($new_image);
  if ($extra = node_invoke($new_image, 'presave')) {
    foreach ($extra as $key => $value) {
      $new_image->{$key} = $value;
    }
  }
  if ($extra = node_invoke_nodeapi($new_image, 'presave')) {
    foreach ($extra as $key => $value) {
      $new_image->{$key} = $value;
    }
  }
  if ($extra = node_invoke($old_image, 'presave')) {
    foreach ($extra as $key => $value) {
      $old_image->{$key} = $value;
    }
  }
  if ($extra = node_invoke_nodeapi($old_image, 'presave')) {
    foreach ($extra as $key => $value) {
      $old_image->{$key} = $value;
    }
  }
  foreach ($compare_fields as $f) {
    if (in_array($f, $flattened_attributes)) {

      // We make the old node look like the new one, ie $old_node->options['status'] = $old_node->status
      foreach (array_keys($new_image->{$f}) as $option) {
        $old_image->{$f}[$option] = $old_image->{$option};
      }
    }

    //a hack for cck field validate;
    if (is_array($new_image->{$f})) {
      foreach ($new_image->{$f} as &$ff) {
        if (is_array($ff)) {
          unset($ff['_error_element']);
        }
      }
    }

    // special case for taxonomy, as its representation in form_state is different than in the node object.
    if ($f == 'taxonomy') {
      if (node_gallery_taxonomy_compare($old_image, $new_image)) {
        return TRUE;
      }
      else {
        continue;
      }
    }
    if ($new_image->{$f} != $old_image->{$f}) {
      return TRUE;
    }
  }
  return FALSE;
}