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