Commit 27496c46 authored by Steven Wittens's avatar Steven Wittens

- Changed the node_get_object() and node_get_array() functions to allow multiple conditions

- Added the "delete" hook for node-modules. When called, a module should do additional clean-up if necessary.

- Updated all node-modules
parent db2a5697
......@@ -3,10 +3,14 @@
$status = array(dumped => 0, expired => 1, queued => 2, posted => 3);
$rstatus = array(0 => dumped, 1 => expired, 2 => queued, 3 => posted);
function _node_get($field, $value) {
$result = db_query("SELECT lid, type FROM node WHERE $field = '$value'");
function _node_get($conditions) {
foreach ($conditions as $key => $value) {
$where[] = "$key = '$value'";
$nwhere[] = "n.$key = '$value'";
}
$result = db_query("SELECT lid, type FROM node WHERE " . implode(", ", $where));
if ($node = db_fetch_object($result)) {
return db_query("SELECT n.*, l.*, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE n.$field = '$value' ORDER BY n.timestamp DESC");
return db_query("SELECT n.*, l.*, u.userid FROM node n LEFT JOIN $node->type l ON n.lid = l.lid AND n.nid = l.nid LEFT JOIN users u ON n.author = u.id WHERE " . implode(", ", $nwhere) . " ORDER BY n.timestamp DESC");
}
}
......@@ -25,18 +29,19 @@ function node_submission_status($index = -1) {
return $index < 0 ? $status : $status[$index];
}
function node_get_object($field, $value) {
return db_fetch_object(_node_get($field, $value));
function node_get_object($conditions) {
return db_fetch_object(_node_get($conditions));
}
function node_get_array($field, $value) {
return db_fetch_array(_node_get($field, $value));
function node_get_array($conditions) {
return db_fetch_array(_node_get($conditions));
}
function node_del($field, $value) {
function node_del($conditions) {
global $status;
if ($node = node_get_object($field, $value)) {
if ($node = node_get_object($conditions)) {
if ($node->status == $status[dumped]) {
module_invoke($node->type, "delete", $node);
db_query("DELETE FROM node WHERE nid = '$node->nid'");
db_query("DELETE FROM $node->type WHERE lid = '$node->lid' AND nid = '$node->nid'");
db_query("DELETE FROM comments WHERE lid = '$node->nid'");
......@@ -57,7 +62,7 @@ function node_save($node, $filter) {
$rows = array(nid, pid, lid, cid, tid, log, type, title, score, votes, author, status, comment, promote, moderate, timestamp);
if ($node[nid] > 0) {
$n = node_get_object("nid", $node[nid]);
$n = node_get_object(array("nid" => $node[nid]));
$u1 = array();
$u2 = array();
......@@ -82,7 +87,7 @@ function node_save($node, $filter) {
return $node[nid];
}
else {
$duplicate = node_get_object("title", $node[title]);
$duplicate = node_get_object(array("title" => $node[title]));
if ($duplicate && (time() - $duplicate->timestamp < 60)) {
watchdog("warning", "node: duplicate '$node[title]'");
......
......@@ -17,7 +17,7 @@
$theme->header();
while ($node = db_fetch_object($result)) {
node_view(node_get_object("nid", $node->nid), 1);
node_view(node_get_object(array("nid" => $node->nid)), 1);
}
$theme->footer();
......
......@@ -109,7 +109,7 @@ function book_form($edit = array()) {
$form .= form_item(t("Category"), category_form_select("book", $edit));
if ($edit[pid]) {
$node = node_get_object("nid", $edit[pid]);
$node = node_get_object(array("nid" => $edit[pid]));
$form .= form_item(t("Parent"), "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A>", t("The parent subject or category the page belongs in."));
$form .= form_hidden("parent", $edit[parent]);
}
......@@ -157,7 +157,7 @@ function book_save($edit) {
function book_parent($nid) {
global $status;
if ($node = node_get_object("nid", $nid)) {
if ($node = node_get_object(array("nid" => $nid))) {
$list[$nid] = $nid;
}
if ($node->pid) {
......@@ -205,7 +205,7 @@ function book_admin() {
print book_form();
break;
case "edit":
print book_form(node_get_array(nid, $id));
print book_form(node_get_array(array(nid => $id)));
break;
case "listing":
print node_listing(book_query());
......@@ -246,7 +246,7 @@ function book_page() {
function book_update($id) {
global $status;
if ($node = node_get_object("nid", $id)) {
if ($node = node_get_object(array("nid" => $id))) {
if ($node->status != $status[posted]) {
return t("You can only update accepted pages: pages that are still queued or already expired can not be updated.");
}
......
......@@ -109,7 +109,7 @@ function book_form($edit = array()) {
$form .= form_item(t("Category"), category_form_select("book", $edit));
if ($edit[pid]) {
$node = node_get_object("nid", $edit[pid]);
$node = node_get_object(array("nid" => $edit[pid]));
$form .= form_item(t("Parent"), "<A HREF=\"node.php?id=$node->id\">". check_output($node->title) ."</A>", t("The parent subject or category the page belongs in."));
$form .= form_hidden("parent", $edit[parent]);
}
......@@ -157,7 +157,7 @@ function book_save($edit) {
function book_parent($nid) {
global $status;
if ($node = node_get_object("nid", $nid)) {
if ($node = node_get_object(array("nid" => $nid))) {
$list[$nid] = $nid;
}
if ($node->pid) {
......@@ -205,7 +205,7 @@ function book_admin() {
print book_form();
break;
case "edit":
print book_form(node_get_array(nid, $id));
print book_form(node_get_array(array(nid => $id)));
break;
case "listing":
print node_listing(book_query());
......@@ -246,7 +246,7 @@ function book_page() {
function book_update($id) {
global $status;
if ($node = node_get_object("nid", $id)) {
if ($node = node_get_object(array("nid" => $id))) {
if ($node->status != $status[posted]) {
return t("You can only update accepted pages: pages that are still queued or already expired can not be updated.");
}
......
......@@ -48,7 +48,7 @@ function forum_page() {
$output .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
$output .= " <TR><TH>". t("Forum") ."</TH><TH>". t("Comments") ."</TH><TH>". t("Last comment") ."</TH><TH>". t("Moderators") ."</TH></TR>";
while ($node = db_fetch_object($result)) {
$node = node_get_object("nid", $node->nid);
$node = node_get_object(array("nid" => $node->nid));
$output .= " <TR><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A><BR><SMALL>". check_output($node->body, 1) ."</SMALL></TD><TD ALIGN=\"center\">". forum_num_comments($node->nid) ."</TD><TD ALIGN=\"center\">". forum_last_comment($node->nid) ."</TD><TD ALIGN=\"center\"><SMALL>". check_output($node->moderate) ."</SMALL></TD></TR>";
}
$output .= "</TABLE>\n";
......@@ -72,7 +72,7 @@ function forum_admin() {
print forum_form();
break;
case "edit":
print forum_form(node_get_array(nid, $id));
print forum_form(node_get_array(array(nid => $id)));
break;
case t("Submit"):
print status(forum_save($edit));
......
......@@ -48,7 +48,7 @@ function forum_page() {
$output .= "<TABLE BORDER=\"0\" CELLSPACING=\"4\" CELLPADDING=\"4\">\n";
$output .= " <TR><TH>". t("Forum") ."</TH><TH>". t("Comments") ."</TH><TH>". t("Last comment") ."</TH><TH>". t("Moderators") ."</TH></TR>";
while ($node = db_fetch_object($result)) {
$node = node_get_object("nid", $node->nid);
$node = node_get_object(array("nid" => $node->nid));
$output .= " <TR><TD><A HREF=\"node.php?id=$node->nid\">". check_output($node->title) ."</A><BR><SMALL>". check_output($node->body, 1) ."</SMALL></TD><TD ALIGN=\"center\">". forum_num_comments($node->nid) ."</TD><TD ALIGN=\"center\">". forum_last_comment($node->nid) ."</TD><TD ALIGN=\"center\"><SMALL>". check_output($node->moderate) ."</SMALL></TD></TR>";
}
$output .= "</TABLE>\n";
......@@ -72,7 +72,7 @@ function forum_admin() {
print forum_form();
break;
case "edit":
print forum_form(node_get_array(nid, $id));
print forum_form(node_get_array(array(nid => $id)));
break;
case t("Submit"):
print status(forum_save($edit));
......
......@@ -31,7 +31,7 @@ function moderate_overview($query = array()) {
function moderate_node($edit, $name) {
global $user;
$node = node_get_array("nid", $edit[nid]);
$node = node_get_array(array("nid" => $edit[nid]));
if ($node && strstr($node[moderate], $user->userid)) {
$edit[type] = $node[type];
return node_invoke($edit, $name);
......@@ -86,7 +86,7 @@ function moderate_admin() {
default:
switch ($op) {
case "edit":
print moderate_node_edit(node_get_array("nid", $id));
print moderate_node_edit(node_get_array(array("nid" => $id)));
break;
case t("Preview"):
print moderate_node_edit($edit);
......
......@@ -56,7 +56,7 @@ function node_overview($query = array()) {
}
function node_admin_view($id) {
$node = node_get_object("nid", $id);
$node = node_get_object(array("nid" => $id));
$form .= form_item("Title", check_output($node->title));
$form .= form_item("Author", format_username($node->userid));
......@@ -74,7 +74,7 @@ function node_admin_view($id) {
function node_admin_edit($id) {
global $user;
$node = node_get_object("nid", $id);
$node = node_get_object(array("nid" => $id));
$form .= form_item("Title", check_output($node->title));
$form .= form_select("Author", "author", $node->author, array($node->author => $node->userid, $user->id => $user->userid));
......
......@@ -56,7 +56,7 @@ function node_overview($query = array()) {
}
function node_admin_view($id) {
$node = node_get_object("nid", $id);
$node = node_get_object(array("nid" => $id));
$form .= form_item("Title", check_output($node->title));
$form .= form_item("Author", format_username($node->userid));
......@@ -74,7 +74,7 @@ function node_admin_view($id) {
function node_admin_edit($id) {
global $user;
$node = node_get_object("nid", $id);
$node = node_get_object(array("nid" => $id));
$form .= form_item("Title", check_output($node->title));
$form .= form_select("Author", "author", $node->author, array($node->author => $node->userid, $user->id => $user->userid));
......
......@@ -66,7 +66,7 @@ function page_admin() {
print page_form();
break;
case "edit":
print page_form(node_get_array(nid, $id));
print page_form(node_get_array(array(nid => $id)));
break;
case "listing":
print node_listing(page_query());
......
......@@ -66,7 +66,7 @@ function page_admin() {
print page_form();
break;
case "edit":
print page_form(node_get_array(nid, $id));
print page_form(node_get_array(array(nid => $id)));
break;
case "listing":
print node_listing(page_query());
......
......@@ -13,12 +13,12 @@ function Poll($poll) {
}
function poll_cron() {
$result = _node_get("type", "poll");
$result = _node_get(array("type" => "poll"));
while ($poll = db_fetch_array($result)) {
if ($poll[active]) {
if (($poll[timestamp] + $poll[runtime]) < time()) {
$poll[active] = 0;
node_save($poll, array(filter));
node_save($poll, array(active));
}
}
}
......@@ -98,10 +98,10 @@ function poll_view($node, $main = 0, $block = 0) {
if (($node->active) && (!field_get($node->voters, $user->userid))) {
$result = db_query("UPDATE poll_choices SET chvotes=chvotes+1 WHERE nid='" . $node->nid . "' && chid='" . check_input($chid) . "'");
if (($result) && ($user)) {
$new = node_get_array("nid", $node->nid);
$new = node_get_array(array("nid" => $node->nid));
$new[voters] = field_set($node->voters, $user->userid,1);
node_save($new, array(voters));
$node = node_get_object("nid", $node->nid);
$node = node_get_object(array("nid" => $node->nid));
}
}
......@@ -228,10 +228,7 @@ function poll_save($edit) {
}
function poll_block() {
$result = _node_get("type", "poll");
while ($poll = db_fetch_object($result)) {
if ($poll->active) break;
}
$poll = node_get_object(array("type" => "poll", "active" => 1));
if ($poll) {
$poll = poll_view($poll, 0, 1);
$output = "<b>" . $poll[title] . "</b><br>" . $poll[content];
......@@ -266,7 +263,7 @@ function poll_admin() {
print poll_overview(poll_query($type));
break;
case "edit":
print poll_form(poll_get_choices_array(node_get_array("nid", check_input($id))));
print poll_form(poll_get_choices_array(node_get_array(array("nid" => check_input($id)))));
break;
case "help":
poll_help();
......
......@@ -13,12 +13,12 @@ function Poll($poll) {
}
function poll_cron() {
$result = _node_get("type", "poll");
$result = _node_get(array("type" => "poll"));
while ($poll = db_fetch_array($result)) {
if ($poll[active]) {
if (($poll[timestamp] + $poll[runtime]) < time()) {
$poll[active] = 0;
node_save($poll, array(filter));
node_save($poll, array(active));
}
}
}
......@@ -98,10 +98,10 @@ function poll_view($node, $main = 0, $block = 0) {
if (($node->active) && (!field_get($node->voters, $user->userid))) {
$result = db_query("UPDATE poll_choices SET chvotes=chvotes+1 WHERE nid='" . $node->nid . "' && chid='" . check_input($chid) . "'");
if (($result) && ($user)) {
$new = node_get_array("nid", $node->nid);
$new = node_get_array(array("nid" => $node->nid));
$new[voters] = field_set($node->voters, $user->userid,1);
node_save($new, array(voters));
$node = node_get_object("nid", $node->nid);
$node = node_get_object(array("nid" => $node->nid));
}
}
......@@ -228,10 +228,7 @@ function poll_save($edit) {
}
function poll_block() {
$result = _node_get("type", "poll");
while ($poll = db_fetch_object($result)) {
if ($poll->active) break;
}
$poll = node_get_object(array("type" => "poll", "active" => 1));
if ($poll) {
$poll = poll_view($poll, 0, 1);
$output = "<b>" . $poll[title] . "</b><br>" . $poll[content];
......@@ -266,7 +263,7 @@ function poll_admin() {
print poll_overview(poll_query($type));
break;
case "edit":
print poll_form(poll_get_choices_array(node_get_array("nid", check_input($id))));
print poll_form(poll_get_choices_array(node_get_array(array("nid" => check_input($id)))));
break;
case "help":
poll_help();
......
......@@ -18,7 +18,7 @@ function queue_score($id) {
function queue_vote($id, $vote) {
global $status, $user;
if ($node = node_get_object(nid, $id)) {
if ($node = node_get_object(array(nid => $id))) {
if (!field_get($node->users, $user->userid)) {
......@@ -63,7 +63,7 @@ function queue_node($id) {
global $theme, $user;
$node = node_get_object(nid, $id);
$node = node_get_object(array(nid => $id));
if ($user->id == $node->author || field_get($node->users, $user->userid)) {
header("Location: node.php?id=$node->nid");
......@@ -72,7 +72,7 @@ function queue_node($id) {
$queue_votes = array("neutral (+0)" => "+ 0", "post it (+1)" => "+ 1", "dump it (-1)" => "- 1");
// The keys of this associative array are displayed in each submission's selection box whereas the corresponding values represent the mathematical calculation to be performed to update a comment's value.
if ($n = node_get_object("nid", $node->pid)) {
if ($n = node_get_object(array("nid" => $node->pid))) {
$output .= " ". t("The above node is a proposed update of an existing node:") ." \"<A HREF=\"node.php?id=$n->nid\">". check_output($n->title) ."</A>\".";
}
......
......@@ -135,7 +135,7 @@ function story_admin() {
print story_overview(story_query($type));
break;
case "edit":
print story_form(node_get_array("nid", check_input($id)));
print story_form(node_get_array(array("nid" => check_input($id))));
break;
case "help":
story_help();
......
......@@ -135,7 +135,7 @@ function story_admin() {
print story_overview(story_query($type));
break;
case "edit":
print story_form(node_get_array("nid", check_input($id)));
print story_form(node_get_array(array("nid" => check_input($id))));
break;
case "help":
story_help();
......
......@@ -72,7 +72,7 @@ function node_history($node) {
$output .= "<DT><B>". format_date($node->timestamp) ." by ". format_username($node->userid) .":</B></DT><DD>". check_output($node->log, 1) ."<P></DD>";
}
if ($node->pid) {
$output .= node_history(node_get_object("nid", $node->pid));
$output .= node_history(node_get_object(array("nid" => $node->pid)));
}
return $output;
}
......@@ -93,7 +93,7 @@ function node_history($node) {
$theme->footer();
}
elseif ($number) {
$node = ($title ? node_get_object(title, check_input($title)) : node_get_object(nid, check_input($id)));
$node = ($title ? node_get_object(array("title" => check_input($title))) : node_get_object(nid, check_input($id)));
if ($node && node_visible($node)) {
switch ($op) {
case "history":
......
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