drupal/includes/node.inc

202 lines
6.6 KiB
PHP
Raw Normal View History

<?php
$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'");
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");
}
}
function node_comment_status($index = -1) {
$status = array("disabled", "enabled");
return $index < 0 ? $status : $status[$index];
}
function node_promote_status($index = -1) {
$status = array("disabled", "enabled");
return $index < 0 ? $status : $status[$index];
}
function node_submission_status($index = -1) {
$status = array("auto-post new submissions", "moderate new submissions");
return $index < 0 ? $status : $status[$index];
}
function node_get_object($field, $value) {
return db_fetch_object(_node_get($field, $value));
}
function node_get_array($field, $value) {
return db_fetch_array(_node_get($field, $value));
}
function node_del($field, $value) {
global $status;
if ($node = node_get_object($field, $value)) {
if ($node->status == $status[dumped]) {
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'");
watchdog("message", "node: deleted '$node->title'");
return $node;
}
}
}
function node_get_comments($nid) {
$comment = db_fetch_object(db_query("SELECT COUNT(c.lid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.lid WHERE n.nid = '$nid' GROUP BY n.nid"));
return $comment->number ? $comment->number : 0;
}
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, timestamp);
2001-03-31 13:18:57 +00:00
if ($node[nid] > 0) {
$n = node_get_object("nid", $node[nid]);
$u1 = array();
$u2 = array();
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 ($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'");
2001-03-31 18:38:01 +00:00
2001-04-08 16:29:58 +00:00
watchdog("special", "node: modified '$n->title'");
return $node[nid];
}
else {
$duplicate = node_get_object("title", $node[title]);
if ($duplicate && (time() - $duplicate->timestamp < 60)) {
watchdog("warning", "node: duplicate '$node[title]'");
}
else {
// verify submission rate:
throttle("post node", variable_get(max_node_rate, 900));
// prepare queries:
foreach ($filter as $field=>$value) {
$k = check_input(is_numeric($field) ? $value : $field);
$v = check_input(is_numeric($field) ? $node[$value] : $filter[$field]);
if (in_array($k, $rows)) {
$f1[] = $k;
$v1[] = "'$v'";
}
else {
$f2[] = $k;
$v2[] = "'$v'";
}
}
$f1 = implode(", ", $f1);
$v1 = implode(", ", $v1);
$f2 = implode(", ", $f2);
$v2 = implode(", ", $v2);
// insert data, try to roll-back when something goes wrong:
2001-05-17 19:51:42 +00:00
$result = db_query("INSERT INTO node ($f1) VALUES ($v1)");
if ($result && $nid = db_insert_id()) {
2001-05-17 19:51:42 +00:00
$result = db_query("INSERT INTO $filter[type] ($f2, nid) VALUES ($v2, $nid)");
if ($result && $lid = db_insert_id()) {
2001-05-17 19:51:42 +00:00
$result = db_query("UPDATE node SET lid = '$lid' WHERE nid = '$nid'");
if ($result) {
2001-03-31 18:38:01 +00:00
if (($node[pid]) && ($node[status] == $status[posted])) {
2001-05-17 19:51:42 +00:00
db_query("UPDATE node SET status = '$status[expired]' WHERE nid = '$node[pid]'");
2001-03-31 18:38:01 +00:00
}
2001-04-08 16:29:58 +00:00
watchdog("special", "node: added '$node[title]'");
}
else {
watchdog("warning", "node: added '$node[title]' - failed");
}
}
else {
2001-05-17 19:51:42 +00:00
db_query("DELETE FROM node WHERE nid = '$nid'");
watchdog("warning", "node: added '$node[title]' - failed");
}
}
else {
watchdog("warning", "node: added '$node[title]' - failed");
}
}
return $nid;
}
}
function node_invoke($node, $name, $arg = 0) {
if ($node[type]) $function = $node[type] ."_$name";
if ($node->type) $function = $node->type ."_$name";
if (function_exists($function)) return ($arg ? $function($node, $arg) : $function($node));
}
function node_view($node, $main = 0) {
return node_invoke($node, "view", $main);
}
function node_form($node) {
return node_invoke($node, "form");
}
function node_status($node, $index = -1) {
$status = array(dumped, expired, queued, posted);
return $index < 0 ? array_intersect($status, node_invoke($node, "status")) : $status[$index];
}
function node_control($node) {
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
global $user, $REQUEST_URI;
?>
<SCRIPT>
<!--//
function visit(site) {
if (site != "") {
parent.location = site
}
}
//-->
</SCRIPT>
<?php
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
if ($user->id) {
$choices = array("node.php?id=$node->nid" => t("view node"), "submit.php?mod=$node->type" => t("add node"), "submit.php?mod=$node->type&op=update&id=$node->nid" => t("update node"), "node.php?op=history&id=$node->nid" => t("view history"));
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
}
else {
$choices = array("node.php?id=$node->nid" => t("view node"), "node.php?op=history&id=$node->nid" => t("view history"));
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
}
$output .= "<FORM METHOD=\"get\" ACTION=\"\">\n";
foreach ($choices as $key => $value) $options .= "<OPTION VALUE=\"$key\"". (strstr($REQUEST_URI,"/$key") ? " SELECTED" : "") .">". check_select($value) ."</OPTION>\n";
$output .= " <SELECT NAME=\"op\" ONCHANGE=\"visit(this.options[this.selectedIndex].value)\">$options</SELECT>\n";
$output .= "</FORM>\n";
return $output;
}
function node_visible($node) {
global $user, $status;
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
return ($node->status == $status[posted]) || ($node->status == $status[queued] && $user->id) || user_access($user, $node->type) || user_access($user, "node");
}
function node_access($account, $node) {
return strstr($node->moderate, $account->userid);
}
Welp. Large commit ahead. CHANGES: - Added "read" and "write" permissions into drupal but removed it again because - when finished after 3 hours of work - it was considered nothing but added complexity that didn't buy us anything. :I (I'll explain this in detail on the mailing list, I guess.) - Added a very simple help.module to group all available documentation on a single page. - Fixed bug in node_control(), book.module: UnConeD forgot to global $user when updating the combobox code. - Removed static wishlist.module: in future, the wishlist can be maintained as a page in our collaborative book. - Revised most of settings.module: tidied up the code and the descriptions to accompany the settings and introduced a new "default maximum number of nodes to display on the main page" variable. - Revised most of comment.module: the administration interface looks better now, integrated node permissions, and -finally- made it possible to delete comments. - Polished on: + account.module + structure.module + locale.module + module.module + forum.module - Form-ified: + account.php + account.module + setting.module + cvs.module + submit.php + comment.module + forum.module + book.module + page.module + locale.module - Updated CHANGELOG INFO: - Designed a "generic tracker system with optional backends" on paper. The idea is to allow registered users to hot-list certain topics, individual nodes or threads (comments) and to "plug-in" output backends like - for instance - an e-mail digest. The design requires "intelligent blocks" though. TODO: - I want to tidy up the headline.module and backend.class as well as merge in headlineRSS10.module. Julian spent quite some time working on headline.module but I'm not sure what he changed and whether he'd contribute it back?
2001-04-30 17:13:08 +00:00
?>