- Fixed bug #5831: added validation for posting to forum containers. Patch

by UnConeD.
4.4.x
Dries Buytaert 2004-02-12 19:04:20 +00:00
parent f137b26979
commit 14b84fa299
4 changed files with 32 additions and 12 deletions

View File

@ -197,12 +197,20 @@ function forum_validate(&$node) {
if ($node->taxonomy) {
// Extract the node's proper topic ID.
$vocabulary = variable_get('forum_nav_vocabulary', '');
$containers = variable_get('forum_containers', array());
foreach ($node->taxonomy as $term) {
if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
$node->tid = $term;
if (in_array($term, $containers)) {
$term = taxonomy_get_term($term);
$error['taxonomy'] = theme('error', t('The item \'%forum\' is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
}
else {
$node->tid = $term;
}
}
}
}
return $error;
}
function forum_form(&$node, &$error) {
@ -211,7 +219,7 @@ function forum_form(&$node, &$error) {
$node->taxonomy[] = arg(3);
}
$output = implode('', taxonomy_node_form('forum', $node));
$output = implode('', taxonomy_node_form('forum', $node, $error));
if ($node->nid) {
// if editing, give option to leave shadows

View File

@ -197,12 +197,20 @@ function forum_validate(&$node) {
if ($node->taxonomy) {
// Extract the node's proper topic ID.
$vocabulary = variable_get('forum_nav_vocabulary', '');
$containers = variable_get('forum_containers', array());
foreach ($node->taxonomy as $term) {
if (db_result(db_query('SELECT COUNT(*) FROM {term_data} WHERE tid = %d AND vid = %d', $term, $vocabulary))) {
$node->tid = $term;
if (in_array($term, $containers)) {
$term = taxonomy_get_term($term);
$error['taxonomy'] = theme('error', t('The item \'%forum\' is only a container for forums. Please select one of the forums below it.', array('%forum' => $term->name)));
}
else {
$node->tid = $term;
}
}
}
}
return $error;
}
function forum_form(&$node, &$error) {
@ -211,7 +219,7 @@ function forum_form(&$node, &$error) {
$node->taxonomy[] = arg(3);
}
$output = implode('', taxonomy_node_form('forum', $node));
$output = implode('', taxonomy_node_form('forum', $node, $error));
if ($node->nid) {
// if editing, give option to leave shadows

View File

@ -299,7 +299,7 @@ function taxonomy_overview() {
return theme("table", $header, $rows);
}
function taxonomy_form($vocabulary_id, $value = 0) {
function taxonomy_form($vocabulary_id, $value = 0, $error = array()) {
$vocabulary = taxonomy_get_vocabulary($vocabulary_id);
if ($vocabulary->required) {
$descriptions = array(t("You must choose one term for this node."), t("You must choose one or more terms for this node."));
@ -312,7 +312,9 @@ function taxonomy_form($vocabulary_id, $value = 0) {
$multiple = intval($vocabulary->multiple);
return _taxonomy_term_select($vocabulary->name, "taxonomy", $value, $vocabulary_id, $descriptions[$multiple], $multiple, $blank);
$description = $descriptions[$multiple] . $error['taxonomy'];
return _taxonomy_term_select($vocabulary->name, 'taxonomy', $value, $vocabulary_id, $description, $multiple, $blank);
}
/*
@ -336,7 +338,7 @@ function taxonomy_get_vocabularies($type = '', $key = "vid") {
}
// return form with current term
function taxonomy_node_form($type, $node = '') {
function taxonomy_node_form($type, $node = '', $error = array()) {
if (!$node->taxonomy) {
if ($node->nid) {
$terms = array_keys(taxonomy_node_get_terms($node->nid));
@ -351,7 +353,7 @@ function taxonomy_node_form($type, $node = '') {
$c = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
while ($vocabulary = db_fetch_object($c)) {
$result[] .= taxonomy_form($vocabulary->vid, $terms);
$result[] .= taxonomy_form($vocabulary->vid, $terms, $error);
}
return $result ? $result : array();
}

View File

@ -299,7 +299,7 @@ function taxonomy_overview() {
return theme("table", $header, $rows);
}
function taxonomy_form($vocabulary_id, $value = 0) {
function taxonomy_form($vocabulary_id, $value = 0, $error = array()) {
$vocabulary = taxonomy_get_vocabulary($vocabulary_id);
if ($vocabulary->required) {
$descriptions = array(t("You must choose one term for this node."), t("You must choose one or more terms for this node."));
@ -312,7 +312,9 @@ function taxonomy_form($vocabulary_id, $value = 0) {
$multiple = intval($vocabulary->multiple);
return _taxonomy_term_select($vocabulary->name, "taxonomy", $value, $vocabulary_id, $descriptions[$multiple], $multiple, $blank);
$description = $descriptions[$multiple] . $error['taxonomy'];
return _taxonomy_term_select($vocabulary->name, 'taxonomy', $value, $vocabulary_id, $description, $multiple, $blank);
}
/*
@ -336,7 +338,7 @@ function taxonomy_get_vocabularies($type = '', $key = "vid") {
}
// return form with current term
function taxonomy_node_form($type, $node = '') {
function taxonomy_node_form($type, $node = '', $error = array()) {
if (!$node->taxonomy) {
if ($node->nid) {
$terms = array_keys(taxonomy_node_get_terms($node->nid));
@ -351,7 +353,7 @@ function taxonomy_node_form($type, $node = '') {
$c = db_query("SELECT * FROM {vocabulary} WHERE nodes LIKE '%%%s%%' ORDER BY weight, name", $type);
while ($vocabulary = db_fetch_object($c)) {
$result[] .= taxonomy_form($vocabulary->vid, $terms);
$result[] .= taxonomy_form($vocabulary->vid, $terms, $error);
}
return $result ? $result : array();
}