--- gcg_taxonomy.module 2008-10-16 19:26:55.000000000 -0300 +++ /home/rfay/gcgwa/sites/all/modules/gcg/gcg_taxonomy.module 2008-11-10 23:52:35.432271500 -0300 @@ -97,8 +97,9 @@ function gcg_taxonomy_settings() { $form['texts']['gcg_taxonomy_vocabulary_t'] = array( '#type' => 'textfield', '#title' => t('Vocabulary name'), - '#default_value' => variable_get('gcg_taxonomy_vocabulary_t', 'Addresses in @country'), - '#description' => t('Available variables: @country.'), + '#default_value' => variable_get('gcg_taxonomy_vocabulary_t', 'country'), + #description' => t('Name of Vocabulary that will contain addresses'), + // t('Available variables: @country.'), ); $form['texts']['gcg_taxonomy_country_term_t'] = array( '#type' => 'textfield', @@ -228,32 +229,28 @@ function _gcg_taxonomy_get_vid($country) static $nodes = NULL; static $voc_t = NULL; - if (is_null($countries)) { - $countries = _gcg_country_list(); - $nodes = array(); - foreach (node_get_types() as $type) { - if (variable_get('gcg_node_type_enabled_' . $type->type, 0)) { - $nodes[$type->type] = 1; - } - } - $voc_t = variable_get('gcg_taxonomy_vocabulary_t', 'Addresses in @country'); - } + $voc_t = variable_get('gcg_taxonomy_vocabulary_t', 'Country'); + // rfay simplification - don't use country, just use the vocabs by name + // 2008-11-10 $vids = variable_get('gcg_taxonomy_vocabularies', array()); - if (!isset($vids[$country])) { - $edit = array('name' => t($voc_t, array('@country' => $countries[$country])), 'multiple' => 1, 'required' => 0, 'hierarchy' => 1, 'relations' => 0, 'module' => 'gcg_taxonomy', 'weight' => 0, 'nodes' => $nodes); + + if (!isset($vids[$voc_t])) { + $edit = array('name' => t($voc_t), 'multiple' => 1, 'required' => 0, 'hierarchy' => 1, 'relations' => 0, 'module' => 'gcg_taxonomy', 'weight' => 0, 'nodes' => $nodes); taxonomy_save_vocabulary($edit); - $vids[$country] = $edit['vid']; + $vids[$voc_t] = $edit['vid']; variable_set('gcg_taxonomy_vocabularies', $vids); } - return $vids[$country]; + return $vids[$voc_t]; } function gcg_taxonomy_node_save(&$node) { static $vids = NULL; static $countries = NULL; static $texts = NULL; + $voc_t = variable_get('gcg_taxonomy_vocabulary_t', 'Country'); + gcg_taxonomy_node_delete($node); if (variable_get('gcg_node_type_enabled_' . $node->type, 0) && !gcg_empty($node->gcg_node_address) && !empty($node->gcg_node_address['country'])) { if ($node->gcg_node_address['custom'] && (!variable_get('gcg_taxonomy_custom_results', 1) || !variable_get('gcg_taxonomy_custom_results_' . $node->type, 1))) { @@ -271,18 +268,18 @@ function gcg_taxonomy_node_save(&$node) 'deploc' => variable_get('gcg_taxonomy_deploc_term_t', '@locality - @deploc'), ); } - if (!isset($vids[$node->gcg_node_address['country']])) { - $vids[$node->gcg_node_address['country']] = _gcg_taxonomy_get_vid($node->gcg_node_address['country']); - } - $vid = $vids[$node->gcg_node_address['country']]; - $vocs = taxonomy_get_vocabularies($node->type); - if (isset($vocs[$vid])) { + //if (!isset($vids[$node->gcg_node_address['country']])) { + //$vids[$node->gcg_node_address['country']] = _gcg_taxonomy_get_vid($node->gcg_node_address['country']); + //} + $vid = _gcg_taxonomy_get_vid($voc_t); + if (isset($vid)) { $a = &$node->gcg_node_address; $terms = array(); $vars = array('@country' => $countries[$a['country']]); - $country_tid = gcg_taxonomy_get_term_by_name(t($texts['country'], $vars), 0, $vid); + $country_term_name = t($texts['country'],$vars); + $country_tid = gcg_taxonomy_get_term_by_name($country_term_name, 0, $vid); if (empty($country_tid)) { - $edit = array('vid' => $vid, 'name' => $countries[$a['country']]); + $edit = array('vid' => $vid, 'name' => $country_term_name); taxonomy_save_term($edit); $country_tid = $edit['tid']; } @@ -350,8 +347,8 @@ function gcg_taxonomy_node_save(&$node) } } } - if (!empty($terms)) { - taxonomy_node_delete($node->nid); + if (!empty($terms)) { + unset($node->taxonomy); $node->taxonomy[$vid] = $terms; taxonomy_node_save($node->nid, $node->taxonomy); }