Commit f9298125 authored by Dries's avatar Dries

- Fixed inconsistent behavior of 'node_save()' and simplified the

  algorithm a bit. --> Needs testing!  I improved this last night
  and only got around to testing this rather briefly/quickly.  It
  was to late already. ;-)

  (This is part of a larger set of changes I'm slowly working on
  which I will feed to CVS in steps after more testing.)

- Added 2 new node functions called 'node_attribute_edit()' and
  'node_attribute_save()' used to 'hook in' any indexing system
  including your home-brewed stuff if you'd want to.
parent 1383729e
......@@ -63,30 +63,26 @@ function node_get_comments($nid) {
}
function node_save($node, $filter) {
global $user, $status;
$rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, promote, moderate, attribute, timestamp, timestamp_posted, timestamp_queued, timestamp_hidden);
if ($node[nid] > 0) {
$n = node_get_object(array("nid" => $node[nid]));
$u1 = array();
$u2 = array();
foreach ($filter as $field=>$value) {
$f = check_input(is_numeric($field) ? $value : $field);
$v = check_input(is_numeric($field) ? $node[$value] : $filter[$field]);
foreach ($node as $field=>$value) {
if (in_array("$field", $filter)) {
if (in_array("$field", $rows)) {
array_push($u1, check_input($field) ." = '". check_input($value) ."'");
}
else {
array_push($u2, check_input($field) ." = '". check_input($value) ."'");
}
if (in_array($f, $rows)) {
$u1[] = check_input($f) ." = '". check_input($v) ."'";
}
else {
$u2[] = check_input($f) ." = '". check_input($v) ."'";
}
}
if ($u1 = implode(", ", $u1)) db_query("UPDATE node SET $u1 WHERE nid = '$node[nid]'");
if ($u2 = implode(", ", $u2)) db_query("UPDATE $n->type SET $u2 WHERE nid = '$node[nid]'");
if ($n->pid && ($node[status] == $status[posted])) db_query("UPDATE node SET status = '$status[expired]' WHERE nid = '$n->pid'");
if ($u1) db_query("UPDATE node SET ". implode(", ", $u1) ." WHERE nid = '$node[nid]'");
if ($u2) db_query("UPDATE $n->type SET ". implode(", ", $u2) ." WHERE nid = '$node[nid]'");
if ($n->pid && ($node[status] == node_status("posted"))) db_query("UPDATE node SET status = '". node_status("expired") ."' WHERE nid = '$n->pid'");
return $node[nid];
}
......@@ -98,19 +94,19 @@ function node_save($node, $filter) {
}
else {
// verify submission rate:
throttle("post node", variable_get(max_node_rate, 900));
throttle("post node", variable_get("max_node_rate", 900));
// prepare queries:
foreach ($filter as $field=>$value) {
$k = check_input(is_numeric($field) ? $value : $field);
$f = check_input(is_numeric($field) ? $value : $field);
$v = check_input(is_numeric($field) ? $node[$value] : $filter[$field]);
if (in_array($k, $rows)) {
$f1[] = $k;
if (in_array($f, $rows)) {
$f1[] = $f;
$v1[] = "'$v'";
}
else {
$f2[] = $k;
$f2[] = $f;
$v2[] = "'$v'";
}
}
......@@ -127,8 +123,8 @@ function node_save($node, $filter) {
if ($result && $lid = db_insert_id()) {
$result = db_query("UPDATE node SET lid = '$lid' WHERE nid = '$nid'");
if ($result) {
if (($node[pid]) && ($node[status] == $status[posted])) {
db_query("UPDATE node SET status = '$status[expired]' WHERE nid = '$node[pid]'");
if (($node[pid]) && ($node[status] == node_status("posted"))) {
db_query("UPDATE node SET status = '". node_status(expired) ."' WHERE nid = '$node[pid]'");
}
}
else {
......@@ -215,6 +211,19 @@ function node_preview($node) {
return $node;
}
function node_attributes_edit($edit) {
return index_collection_form("section", ($edit[section] ? $edit[section] : "section:". field_get($edit[attribute], "section")));
}
function node_attributes_save($edit) {
if ($edit[nid] && $node = node_get_array(array("nid" => $edit[nid]))) {
return field_merge($node[attribute], $edit[section]);
}
else {
return $edit[section];
}
}
function node_visible($node) {
global $user, $status;
return ($node->status == $status[posted]) || ($node->status == $status[queued] && $user->id) || user_access($user, $node->type) || user_access($user, "node");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment