You are here

function node_gallery_taxonomy_compare in Node Gallery 6.3

Compare taxonomy on an unsaved node object versus a node_load()ed object

Parameters

$old: The old node_load()ed object.

$new: The new node object.

Return value

TRUE if the taxo differs, FALSE if not

1 call to node_gallery_taxonomy_compare()
node_gallery_images_check_update in ./node_gallery.pages.inc
Check if we need to update this image;

File

./node_gallery.inc, line 1127
Shared functions for node_gallery

Code

function node_gallery_taxonomy_compare($old, $new) {
  $new->taxonomy = taxonomy_preview_terms($new);
  $new_taxonomy = $new->taxonomy;
  $old_taxonomy = $old->taxonomy;
  if (isset($new_taxonomy['tags'])) {

    // in case of free tagging, the preview function does not return term objects
    $existing_tags = array();
    $term2tid = array();
    foreach ($old_taxonomy as $term) {
      $existing_tags[$term->vid][] = $term->name;
      $term2tid[$term->vid][$term->name] = $term->tid;
    }
    foreach ($new_taxonomy['tags'] as $vid => $tag_string) {
      $tags = drupal_explode_tags($tag_string);
      if (count($tags) != count($existing_tags[$vid])) {
        return TRUE;
      }
      foreach ($tags as $tag) {
        if (!in_array($tag, $existing_tags[$vid])) {
          return TRUE;
        }
        else {
          unset($old_taxonomy[$term2tid[$vid][$tag]]);
        }
      }
    }
    unset($new_taxonomy['tags']);
  }
  if ($new_taxonomy != $old_taxonomy) {

    // difference in non-tag vocab
    return TRUE;
  }
  return FALSE;
}