Index: pathauto_node.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_node.inc,v retrieving revision 1.29 diff -u -r1.29 pathauto_node.inc --- pathauto_node.inc 11 Nov 2006 23:34:51 -0000 1.29 +++ pathauto_node.inc 9 Dec 2006 20:18:18 -0000 @@ -153,15 +153,65 @@ $placeholders[t('[bookpath]')] = ''; } - // And now taxonomy, which is a bit more work + // And now taxonomy, which is a *bit* more work if (module_exists('taxonomy') && is_array($node->taxonomy) && count($node->taxonomy) > 0) { - // When editing a node, the taxonomy array might have one or more zero - // term IDs. Ignore them... - foreach ($node->taxonomy as $firsttermid) { - if ($firsttermid) { + $firsttermid = FALSE; + watchdog('gjktax','
'. print_r($node->taxonomy,true) .'
'); + //we loop through the array assuming it's in wheigh order, which is false, but close enough TODO: fix that + + foreach ($node->taxonomy as $key => $value) { //I'd use more descriptive variables, but the content isn't always a tid + if($key == 'tags') { //it's a freetag so make sure that there is a value in the array + //shamelessly stolen from taxonomy_node_save - most of it should be refactored out of that + //so it can be easily reused, but until then: copy-paste-antipattern here we come! + + $typed_input = $value; + foreach ($typed_input as $vid => $vid_value) { + if ($firsttermid) {break;} + // This regexp allows the following types of user input: + // this, "somecmpany, llc", "and ""this"" w,o.rks", foo bar + $regexp = '%(?:^|,\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x'; + preg_match_all($regexp, $vid_value, $matches); + $typed_terms = array_unique($matches[1]); + + + $inserted = array(); + foreach ($typed_terms as $typed_term) { + if ($firsttermid) {break;} + // If a user has escaped a term (to demonstrate that it is a group, + // or includes a comma or quote character), we remove the escape + // formatting so to save the term into the DB as the user intends. + $typed_term = str_replace('""', '"', preg_replace('/^"(.*)"$/', '\1', $typed_term)); + $typed_term = trim($typed_term); + if ($typed_term == "") { continue; } + + // See if the term exists in the chosen vocabulary + // and return the tid, otherwise, add a new record. + $possibilities = taxonomy_get_term_by_name($typed_term); + $typed_term_tid = NULL; // tid match if any. + foreach ($possibilities as $possibility) { + if ($possibility->vid == $vid) { + $firsttermid = $possibility->tid; + break; //we've got our first term ID, get out of here + } + } + } + } + } //not freetagging (or not yet) + // When editing a node, a multiselect vocabulary with nothing selected will have a "zero"" + // term IDs. Ignore them... + elseif (is_array($value)) { + $temptid = array_shift($value); + if($temptid) { + $firsttermid = $temptid; + break; + } + } + elseif ($value) { + $firsttermid = $value; break; } } + watchdog('gjkfirsttid','
'. print_r($firsttermid,true) .'
'); $term = taxonomy_get_term($firsttermid); $placeholders[t('[cat]')] = pathauto_cleanstring($term->name); @@ -175,12 +225,12 @@ } $catpath = ''; - $parents = taxonomy_get_parents_all($firsttermid); + $parents = taxonomy_get_parents_all($$firsttermid); foreach ($parents as $parent) { $catpath = pathauto_cleanstring($parent->name).'/'.$catpath; } $placeholders[t('[catpath]')] = $catpath; - } + } else { $placeholders[t('[cat]')] = ''; $placeholders[t('[catpath]')] = '';