[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/modules/diff/includes/ -> taxonomy.inc (source)

   1  <?php
   2  // $Id: taxonomy.inc,v 1.1.2.2 2010/08/12 16:34:08 yhahn Exp $
   3  
   4  /**
   5   * @file
   6   * Implementation of hook_diff() for taxonomy.
   7   */
   8  
   9  /**
  10   * Implementation of hook_diff() for taxonomy.
  11   */
  12  function taxonomy_diff($old_node, $new_node) {
  13    $result = array();
  14    // TODO: make taxonomy by category not only by whole taxonomy?
  15    $old_taxonomy = array();
  16    $new_taxonomy = array();
  17    if (isset($old_node->taxonomy) && $old_node->taxonomy) {
  18      foreach ($old_node->taxonomy as $term) {
  19        $old_taxonomy[] = $term->name;
  20      }
  21    }
  22    if (isset($new_node->taxonomy) && $new_node->taxonomy) {
  23      foreach ($new_node->taxonomy as $id => $entry) {
  24        if (is_array($entry)) {
  25          // During editing the taxonomy is built up as a list of vocabulary ids as keys
  26          // and a list of term ids per array entry.
  27          if (is_numeric($id)) {
  28            foreach ($entry as $tid) {
  29              $term = taxonomy_get_term($tid);
  30              $new_taxonomy[] = $term->name;
  31            }
  32          }
  33          else {
  34            // If the id is not numeric than it has to be 'tags' which denotes freetagging
  35            // vocabularies. These are stored as an array which map the vocabulary id to
  36            // a string of terms.
  37            foreach ($entry as $taglist) {
  38              // The regular expression is taken from taxonomy.module.
  39              preg_match_all('%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x', $taglist, $matches);
  40              foreach ($matches[1] as $term) {
  41                $new_taxonomy[] = $term;
  42              }
  43            }
  44          }
  45        }
  46        elseif (is_numeric($entry)) {
  47          // During editing, taxonomy is a single id.
  48          $term = taxonomy_get_term($entry);
  49          $new_taxonomy[] = $term->name;
  50        }
  51        else {
  52          // Not during editing the taxonomy list is a list of terms.
  53          $new_taxonomy[] = $entry->name;
  54        }
  55      }
  56    }
  57    $result['taxonomy'] = array(
  58      '#name' => t('Taxonomy'),
  59      '#old' => $old_taxonomy,
  60      '#new' => $new_taxonomy,
  61      '#weight' => -3,
  62      '#format' => array(
  63        'show_header' => FALSE,
  64      )
  65    );
  66    return $result;
  67  }


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7