Skip to content
Snippets Groups Projects
Commit a95c2a68 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- import.module:

    + Improved input filtering; this should make the news items look
      more consistent in terms of mark-up.

    + Quoted all array indices: converted all instances of $foo[bar]
      to $foo["bar"].  Made various other changes to make the import
      module compliant with the coding style.

- theme.inc:

    + Fixed small XHTML glitch

- comment system:

    + Made it possible for users to edit their comments (when certain
      criteria are matched).

    + Renamed the SQL table field "lid" to "nid" and updated the code
      to reflect this change: this is a rather /annoying/ change that
      has been asked for a few times.  It will impact the contributed
      BBS/forum modules and requires a tiny SQL update:

        sql> ALTER TABLE comments CHANGE lid nid int(10) NOT NULL;

    + Moved most (all?) of the comment related logic from node.php to
      comment.module where it belongs.  This also marks a first step
      towards removing/reducing "node.php".

    + Added a delete button to the comment admin form and made it so
      that Drupal prompts for confirmation prior to deleting a comment
      from the database.  This behavior is similar to that of deleting
      nodes.

    + Disabled comment moderation for now.

    + Some of the above changes will make it easier to integrate the
      upcomcing mail-to-web and web-to-mail gateways.  They are part
      of a bigger plan.  ;)

- node system:

    + Made it so that updating nodes (like for instance updating blog
      entries) won't trigger the submission rate throttle.

    + Fixed a small glitch where a node's title wasn't always passed
      to the $theme->header() function.

    + Made "node_array()" and "node_object()" more generic and named
      them "object2array()" and "array2object()".

    + Moved most (all?) of the comment related logic from node.php to
      comment.module where it belongs.  This also marks a first step
      towards removing/reducing "node.php".

- misc:

    + Applied three patches by Foxen.  One to improve performance of
      the book module, and two other patches to fix small glitches in
      common.inc.  Thanks Foxen!
parent 7a673ac3
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -50,6 +50,34 @@ function throttle($type, $rate) {
}
}
function array2object($node) {
if (is_array($node)) {
foreach ($node as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $node;
}
return $object;
}
function object2array($node) {
if (is_object($node)) {
foreach ($node as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $node;
}
return $array;
}
function path_uri() {
global $HTTP_HOST, $REQUEST_URI;
return "http://". $HTTP_HOST . substr($REQUEST_URI, 0, strrpos($REQUEST_URI, "/")) ."/";
......@@ -287,7 +315,7 @@ function check_input($text) {
}
function check_output($text, $nl2br = 0) {
return ($text) ? ($nl2br ? nl2br(stripslashes($text)) : stripslashes($text)) : message_na();
return ($text) ? ($nl2br ? str_replace("\r", "", str_replace("\n", "<br />", stripslashes($text))) : stripslashes($text)) : message_na();
}
function check_file($filename) {
......@@ -542,14 +570,16 @@ function link_node($node, $main = 0) {
function timer_start() {
global $timer;
$timer = explode(" ", microtime());
list($usec, $sec) = explode(" ", microtime());
$timer = (float)$usec + (float)$sec;
}
function timer_print() {
global $timer;
$stop = explode(" ", microtime());
$diff = $stop[0] - $timer[0];
print "<pre>execution time: $diff ms</pre>";
list($usec, $sec) = explode(" ", microtime());
$stop = (float)$usec + (float)$sec;
$diff = $stop - $timer;
print "<pre>execution time: $diff sec</pre>";
}
function query_print() {
......
......@@ -27,7 +27,7 @@ function user($region) {
if ($user->uid) {
// Display account settings:
$output .= "<div width=\"125\">\n";
$output .= "<div style=\"width: 125;\">\n";
foreach (module_list() as $name) {
if (module_hook($name, "link")) {
......
This diff is collapsed.
This diff is collapsed.
......@@ -423,7 +423,7 @@ function book_toc_recurse($nid, $indent, $toc, $children) {
return $toc;
}
function book_toc($parent = "", $indent = "", $toc = array()) {
function book_toc($parent = 0, $indent = "", $toc = array()) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = '1' ORDER BY b.weight, n.title");
......@@ -446,46 +446,43 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
** Iterate root book nodes:
*/
$toc = book_toc_recurse(0, $indent, $toc, $children, $titles);
$toc = book_toc_recurse($parent, $indent, $toc, $children);
return $toc;
}
function book_tree($parent = "", $depth = 0) {
if ($depth < 3) {
function book_tree_recurse($nid, $depth, $children) {
/*
** Select all child nodes and render them into a table of contents:
*/
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = book_revision_load($node, array("moderate" => 0, "status" => 1));
}
if ($node) {
// output the content:
if ($depth > 1) {
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
$output .= "<li><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></li>";
// build the sub-tree of each child:
$output .= book_tree($node->nid, $depth + 1);
$output .= book_tree_recurse($node->nid, $depth - 1, $children);
}
}
}
return $output;
}
$output = "<ul>$output</ul>";
function book_tree($parent = 0, $depth = 3) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = '1' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array();
array_push($list, $node);
$children[$node->parent] = $list;
}
$output = book_tree_recurse($parent, $depth, $children);
$output = "<ul>$output</ul>";
return $output;
}
function book_render() {
global $theme;
......
......@@ -423,7 +423,7 @@ function book_toc_recurse($nid, $indent, $toc, $children) {
return $toc;
}
function book_toc($parent = "", $indent = "", $toc = array()) {
function book_toc($parent = 0, $indent = "", $toc = array()) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = '1' ORDER BY b.weight, n.title");
......@@ -446,46 +446,43 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
** Iterate root book nodes:
*/
$toc = book_toc_recurse(0, $indent, $toc, $children, $titles);
$toc = book_toc_recurse($parent, $indent, $toc, $children);
return $toc;
}
function book_tree($parent = "", $depth = 0) {
if ($depth < 3) {
function book_tree_recurse($nid, $depth, $children) {
/*
** Select all child nodes and render them into a table of contents:
*/
$result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
while ($page = db_fetch_object($result)) {
// load the node:
$node = node_load(array("nid" => $page->nid));
// take the most recent approved revision:
if ($node->moderate) {
$node = book_revision_load($node, array("moderate" => 0, "status" => 1));
}
if ($node) {
// output the content:
if ($depth > 1) {
if ($children[$nid]) {
foreach ($children[$nid] as $foo => $node) {
$output .= "<li><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></li>";
// build the sub-tree of each child:
$output .= book_tree($node->nid, $depth + 1);
$output .= book_tree_recurse($node->nid, $depth - 1, $children);
}
}
}
return $output;
}
$output = "<ul>$output</ul>";
function book_tree($parent = 0, $depth = 3) {
$result = db_query("SELECT n.nid, n.title, b.parent FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = '1' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) {
$list = $children[$node->parent] ? $children[$node->parent] : array();
array_push($list, $node);
$children[$node->parent] = $list;
}
$output = book_tree_recurse($parent, $depth, $children);
$output = "<ul>$output</ul>";
return $output;
}
function book_render() {
global $theme;
......
This diff is collapsed.
This diff is collapsed.
......@@ -58,12 +58,12 @@ function forum_form(&$node, &$help, &$error) {
function forum_num_comments($nid) {
$value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE lid = '$nid'"));
$value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE nid = '$nid'"));
return ($value) ? $value->count : 0;
}
function forum_last_comment($nid) {
$value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE lid = '$nid' ORDER BY timestamp DESC LIMIT 1"));
$value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE nid = '$nid' ORDER BY timestamp DESC LIMIT 1"));
return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
}
......
......@@ -58,12 +58,12 @@ function forum_form(&$node, &$help, &$error) {
function forum_num_comments($nid) {
$value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE lid = '$nid'"));
$value = db_fetch_object(db_query("SELECT COUNT(cid) AS count FROM comments WHERE nid = '$nid'"));
return ($value) ? $value->count : 0;
}
function forum_last_comment($nid) {
$value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE lid = '$nid' ORDER BY timestamp DESC LIMIT 1"));
$value = db_fetch_object(db_query("SELECT timestamp FROM comments WHERE nid = '$nid' ORDER BY timestamp DESC LIMIT 1"));
return ($value) ? format_date($value->timestamp, "small") : "&nbsp;";
}
......
This diff is collapsed.
......@@ -19,7 +19,7 @@ function node_index() {
}
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"));
$comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '$nid' GROUP BY n.nid"));
return $comment->number ? $comment->number : 0;
}
......@@ -67,34 +67,6 @@ function node_invoke($node, $name, $arg = 0) {
}
}
function node_object($node) {
if (is_array($node)) {
foreach ($node as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $node;
}
return $object;
}
function node_array($node) {
if (is_object($node)) {
foreach ($node as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $node;
}
return $array;
}
function node_load($conditions) {
/*
......@@ -232,9 +204,7 @@ function node_save($node, $filter) {
function node_view($node, $main = 0) {
global $theme;
if (is_array($node)) {
$node = node_object($node);
}
$node = array2object($node);
/*
** The "view" hook can be implemented to overwrite the default function
......@@ -265,9 +235,7 @@ function node_access($op, $node = 0) {
** Convert the node to an object if necessary:
*/
if (is_array($node)) {
$node = node_object($node);
}
$node = array2object($node);
/*
** Construct a function:
......@@ -720,7 +688,7 @@ function node_validate($node, &$error) {
** Convert the node to an object if necessary:
*/
$node = node_object($node);
$node = array2object($node);
/*
** Validate the title field:
......@@ -950,7 +918,7 @@ function node_preview($node) {
** Convert the array to an object:
*/
$node = node_object($node);
$node = array2object($node);
/*
** Load the user's name when needed:
......@@ -1007,13 +975,6 @@ function node_submit($node) {
if (user_access("post content")) {
/*
** Verify a user's submission rate and avoid duplicate nodes being
** inserted:
*/
throttle("node", variable_get("max_node_rate", 900));
/*
** Fixup the node when required:
*/
......@@ -1067,6 +1028,13 @@ function node_submit($node) {
if (node_access("create", $node)) {
/*
** Verify a user's submission rate and avoid duplicate nodes being
** inserted:
*/
throttle("node", variable_get("max_node_rate", 900));
/*
** Compile a list of the node fields and their default values that users
** and administrators are allowed to save when inserting a new node.
......@@ -1135,7 +1103,7 @@ function node_delete($edit) {
*/
db_query("DELETE FROM node WHERE nid = '$node->nid'");
db_query("DELETE FROM comments WHERE lid = '$node->nid'");
db_query("DELETE FROM comments WHERE nid = '$node->nid'");
/*
** Call the node specific callback (if any):
......
......@@ -19,7 +19,7 @@ function node_index() {
}
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"));
$comment = db_fetch_object(db_query("SELECT COUNT(c.nid) AS number FROM node n LEFT JOIN comments c ON n.nid = c.nid WHERE n.nid = '$nid' GROUP BY n.nid"));
return $comment->number ? $comment->number : 0;
}
......@@ -67,34 +67,6 @@ function node_invoke($node, $name, $arg = 0) {
}
}
function node_object($node) {
if (is_array($node)) {
foreach ($node as $key => $value) {
$object->$key = $value;
}
}
else {
$object = $node;
}
return $object;
}
function node_array($node) {
if (is_object($node)) {
foreach ($node as $key => $value) {
$array[$key] = $value;
}
}
else {
$array = $node;
}
return $array;
}
function node_load($conditions) {
/*
......@@ -232,9 +204,7 @@ function node_save($node, $filter) {
function node_view($node, $main = 0) {
global $theme;
if (is_array($node)) {
$node = node_object($node);
}
$node = array2object($node);
/*
** The "view" hook can be implemented to overwrite the default function
......@@ -265,9 +235,7 @@ function node_access($op, $node = 0) {
** Convert the node to an object if necessary:
*/
if (is_array($node)) {
$node = node_object($node);
}
$node = array2object($node);
/*
** Construct a function:
......@@ -720,7 +688,7 @@ function node_validate($node, &$error) {
** Convert the node to an object if necessary:
*/
$node = node_object($node);
$node = array2object($node);
/*
** Validate the title field:
......@@ -950,7 +918,7 @@ function node_preview($node) {
** Convert the array to an object:
*/
$node = node_object($node);
$node = array2object($node);
/*
** Load the user's name when needed:
......@@ -1007,13 +975,6 @@ function node_submit($node) {
if (user_access("post content")) {
/*
** Verify a user's submission rate and avoid duplicate nodes being
** inserted:
*/
throttle("node", variable_get("max_node_rate", 900));
/*
** Fixup the node when required:
*/
......@@ -1067,6 +1028,13 @@ function node_submit($node) {
if (node_access("create", $node)) {
/*
** Verify a user's submission rate and avoid duplicate nodes being
** inserted:
*/
throttle("node", variable_get("max_node_rate", 900));
/*
** Compile a list of the node fields and their default values that users
** and administrators are allowed to save when inserting a new node.
......@@ -1135,7 +1103,7 @@ function node_delete($edit) {
*/
db_query("DELETE FROM node WHERE nid = '$node->nid'");
db_query("DELETE FROM comments WHERE lid = '$node->nid'");
db_query("DELETE FROM comments WHERE nid = '$node->nid'");
/*
** Call the node specific callback (if any):
......
......@@ -16,20 +16,20 @@ function tracker_comments($id = 0) {
$period = time() - 259200; // all comments of the past 3 days
if ($id) {
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.lid = n.nid WHERE c.timestamp > $period AND c.uid = '". check_input($id) ."' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.nid = n.nid WHERE c.timestamp > $period AND c.uid = '". check_input($id) ."' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
}
else {
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.lid = n.nid WHERE c.timestamp > $period GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.nid = n.nid WHERE c.timestamp > $period GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
}
while ($node = db_fetch_object($sresult)) {
$output .= format_plural($node->comments, "comment", "comments") ." ". t("attached to node") ." <a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a>:\n";
if ($id) {
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND uid = '". check_input($id) ."' AND lid = '$node->nid' ORDER BY cid DESC");
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND uid = '". check_input($id) ."' AND nid = '$node->nid' ORDER BY cid DESC");
}
else {
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND lid = '$node->nid' ORDER BY cid DESC");
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND nid = '$node->nid' ORDER BY cid DESC");
}
$output .= "<ul>";
......
......@@ -16,20 +16,20 @@ function tracker_comments($id = 0) {
$period = time() - 259200; // all comments of the past 3 days
if ($id) {
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.lid = n.nid WHERE c.timestamp > $period AND c.uid = '". check_input($id) ."' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.nid = n.nid WHERE c.timestamp > $period AND c.uid = '". check_input($id) ."' GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
}
else {
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.lid = n.nid WHERE c.timestamp > $period GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
$sresult = db_query("SELECT n.nid, n.title, COUNT(n.nid) AS comments, MAX(c.timestamp) AS last_comment FROM comments c LEFT JOIN node n ON c.nid = n.nid WHERE c.timestamp > $period GROUP BY n.nid, n.title DESC ORDER BY last_comment DESC LIMIT 10");
}
while ($node = db_fetch_object($sresult)) {
$output .= format_plural($node->comments, "comment", "comments") ." ". t("attached to node") ." <a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a>:\n";
if ($id) {
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND uid = '". check_input($id) ."' AND lid = '$node->nid' ORDER BY cid DESC");
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND uid = '". check_input($id) ."' AND nid = '$node->nid' ORDER BY cid DESC");
}
else {
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND lid = '$node->nid' ORDER BY cid DESC");
$cresult = db_query("SELECT * FROM comments WHERE timestamp > $period AND nid = '$node->nid' ORDER BY cid DESC");
}
$output .= "<ul>";
......
......@@ -10,56 +10,16 @@ function node_render($node) {
if (user_access("access content")) {
$theme->header(check_output($node->title));
node_view($node);
if ($node->comment) {
switch($op) {
case t("Preview comment"):
$theme->header();
comment_preview($edit);
$theme->footer();
break;
case t("Post comment"):
comment_post($edit);
$theme->header(check_output($node->title));
node_view($node);
comment_render($edit[id], $cid);
$theme->footer();
break;
case "comment":
$theme->header();
comment_reply(check_query($cid), check_query($id));
$theme->footer();
break;
case "reply":
$theme->header();
comment_reply(check_query($pid), check_query($id));
$theme->footer();
break;
case t("Update settings"):
comment_settings(check_query($mode), check_query($order), check_query($threshold));
$theme->header(check_output($node->title));
node_view($node);
comment_render($id, $cid);
$theme->footer();
break;
case t("Update ratings"):
comment_moderate($moderate["comment"]);
$theme->header(check_output($node->title));
node_view($node);
comment_render($id, $cid);
$theme->footer();
break;
default:
$theme->header(check_output($node->title));
node_view($node);
comment_render($id, $cid);
$theme->footer();
}
}
else {
$theme->header();
node_view($node);
$theme->footer();
comment_render($id, $cid);
}
$theme->footer();
}
else {
$theme->header();
......
......@@ -40,6 +40,7 @@
"2001-12-09" => "update_13",
"2001-12-16" => "update_14",
"2001-12-24" => "update_15",
"2001-12-30" => "update_16",
);
// Update functions
......@@ -291,6 +292,10 @@ function update_15() {
update_sql("ALTER TABLE feed DROP uncache;");
}
function update_16() {
update_sql("ALTER TABLE comments CHANGE lid nid int(10) NOT NULL;");
}
// System functions
function update_sql($sql) {
global $edit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment