function taxonomy_manager_term_data_edit in Taxonomy Manager 5
Same name and namespace in other branches
- 6.2 taxonomy_manager.admin.inc \taxonomy_manager_term_data_edit()
- 6 taxonomy_manager.admin.inc \taxonomy_manager_term_data_edit()
callback handler for updating term data
Parameters
$vid:
1 string reference to 'taxonomy_manager_term_data_edit'
- taxonomy_manager_menu in ./
taxonomy_manager.module - Implementation of hook_menu
File
- ./
taxonomy_manager.module, line 1007 - Taxonomy Manager
Code
function taxonomy_manager_term_data_edit($vid) {
$param = $_POST;
$tid = $param['tid'];
$values = $param['value'];
$attr_type = $param['attr_type'];
$op = $param['op'];
$term = taxonomy_get_term($tid);
if ($term->vid != $vid) {
return;
}
if ($op == 'add') {
if ($attr_type == 'synonym') {
$regexp = '%(?:^|,\\ *)("(?>[^"]*)(?>""[^"]* )*"|(?: [^",]*))%x';
preg_match_all($regexp, $values, $matches);
$synonyms = array_unique($matches[1]);
$values = array();
foreach ($synonyms as $syn) {
$values[] = trim($syn);
}
}
else {
$typed_term_tids = array();
$typed_term_tids = taxonomy_manager_autocomplete_tags_get_tids($values, $term->vid);
$values = array();
foreach ($typed_term_tids as $term_info) {
$values[] = $term_info['tid'];
}
}
}
switch ($attr_type) {
case 'name':
db_query("UPDATE {term_data} SET name = '%s' WHERE tid = %d", $values, $tid);
break;
case 'description':
db_query("UPDATE {term_data} SET description = '%s' WHERE tid = %d", $values, $tid);
break;
case 'parent':
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
db_query("DELETE FROM {term_hierarchy} WHERE parent = %d AND tid = %d", $value, $tid);
if ($op == 'add') {
db_query("INSERT INTO {term_hierarchy} (parent, tid) VALUES (%d, %d)", $value, $tid);
}
}
if ($op == 'delete') {
$parents = taxonomy_get_parents($tid);
if (count($parents) == 0) {
//ensure that a term has a least parent 0
db_query("DELETE FROM {term_hierarchy} WHERE parent = 0 AND tid = %d", $tid);
db_query("INSERT INTO {term_hierarchy} (parent, tid) VALUES (0, %d)", $tid);
}
}
else {
if ($op == 'add') {
db_query("DELETE FROM {term_hierarchy} WHERE parent = 0 AND tid = %d", $tid);
}
}
break;
case 'related':
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
if ($value != 0) {
db_query("DELETE FROM {term_relation} WHERE tid1 = %d AND tid2 = %d", $tid, $value);
db_query("DELETE FROM {term_relation} WHERE tid2 = %d AND tid1 = %d", $tid, $value);
if ($op == 'add') {
db_query('INSERT INTO {term_relation} (tid1, tid2) VALUES (%d, %d)', $tid, $value);
}
}
}
break;
case 'synonym':
if (!is_array($values)) {
$values = array(
$values,
);
}
foreach ($values as $value) {
db_query("DELETE FROM {term_synonym} WHERE tid = %d AND name = '%s'", $tid, $value);
if ($op == 'add') {
db_query("INSERT INTO {term_synonym} (tid, name) VALUES (%d, '%s')", $tid, $value);
}
}
break;
case 'weight':
if (is_numeric($values)) {
db_query("UPDATE {term_data} SET weight = %d WHERE tid = %d", $values, $tid);
}
break;
}
module_invoke_all('taxonomy', 'update', 'term', (array) taxonomy_get_term($tid));
exit;
}