summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2001-12-06 17:33:05 +0000
committerDries Buytaert <dries@buytaert.net>2001-12-06 17:33:05 +0000
commit20b4b7166f851221eef4c845d396af2efd581822 (patch)
treed922952bac8cdacae68139b8ffa9008fe19b3174
parent2b01b838c802226ad8f097aa5b7f4512de73d8e7 (diff)
downloadbrdo-20b4b7166f851221eef4c845d396af2efd581822.tar.gz
brdo-20b4b7166f851221eef4c845d396af2efd581822.tar.bz2
- book.module:
+ Added (1) support for "PHP pages" (dynamic pages), and (2) made it possible to link other node types into the book's tree/outline. It works just fine, yet the only (obvious) downside of (2) is that the navigation tree/links gets "interrupted" when you view non-book pages in the book. [SQL update required, see update.php] + Tidied up the book table. [SQL update required, see update.php] - various updates: + Fine-tuned the new node system. + Updated the inline/code documentation. + Improved teaser handling of all node types. + Made several small usability improvements to the node admin pages.
-rw-r--r--includes/node.inc1
-rw-r--r--modules/blog.module12
-rw-r--r--modules/blog/blog.module12
-rw-r--r--modules/book.module193
-rw-r--r--modules/book/book.module193
-rw-r--r--modules/node.module66
-rw-r--r--modules/node/node.module66
-rw-r--r--modules/page.module65
-rw-r--r--modules/page/page.module65
-rw-r--r--modules/story.module178
-rw-r--r--modules/story/story.module178
-rw-r--r--update.php6
12 files changed, 704 insertions, 331 deletions
diff --git a/includes/node.inc b/includes/node.inc
index 6af45c6d2..c23a3a6bd 100644
--- a/includes/node.inc
+++ b/includes/node.inc
@@ -118,7 +118,6 @@ function node_load($conditions) {
}
return $node;
-
}
function node_save($node, $filter) {
diff --git a/modules/blog.module b/modules/blog.module
index f8cdb7922..7e7662a4f 100644
--- a/modules/blog.module
+++ b/modules/blog.module
@@ -227,7 +227,6 @@ function blog_page_last() {
function blog_form(&$node, &$help, &$error) {
global $nid, $iid;
-
if (isset($node->body)) {
/*
@@ -260,6 +259,10 @@ function blog_form(&$node, &$help, &$error) {
}
}
+ if ($node->teaser) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
+ }
+
$output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
return $output;
@@ -311,7 +314,12 @@ function blog_link($type, $node = 0) {
}
if ($type == "node" && $node->type == "blog") {
- $links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\">". strtr(t("%a's blog"), array("%a" => $node->name)) ."</a>";
+ if (blog_access("update", $node)) {
+ $links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\">". t("update this blog") ."</a>";
+ }
+ else {
+ $links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\">". strtr(t("%a's blog"), array("%a" => $node->name)) ."</a>";
+ }
}
return $links ? $links : array();
diff --git a/modules/blog/blog.module b/modules/blog/blog.module
index f8cdb7922..7e7662a4f 100644
--- a/modules/blog/blog.module
+++ b/modules/blog/blog.module
@@ -227,7 +227,6 @@ function blog_page_last() {
function blog_form(&$node, &$help, &$error) {
global $nid, $iid;
-
if (isset($node->body)) {
/*
@@ -260,6 +259,10 @@ function blog_form(&$node, &$help, &$error) {
}
}
+ if ($node->teaser) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
+ }
+
$output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
return $output;
@@ -311,7 +314,12 @@ function blog_link($type, $node = 0) {
}
if ($type == "node" && $node->type == "blog") {
- $links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\">". strtr(t("%a's blog"), array("%a" => $node->name)) ."</a>";
+ if (blog_access("update", $node)) {
+ $links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\">". t("update this blog") ."</a>";
+ }
+ else {
+ $links[] = "<a href=\"module.php?mod=blog&op=view&id=$node->uid\">". strtr(t("%a's blog"), array("%a" => $node->name)) ."</a>";
+ }
}
return $links ? $links : array();
diff --git a/modules/book.module b/modules/book.module
index 3e841c1b2..58ae523b9 100644
--- a/modules/book.module
+++ b/modules/book.module
@@ -25,18 +25,26 @@ function book_access($op, $node) {
}
if ($op == "create") {
- return 1;
+ /*
+ ** Only registered users can create book pages. Given the nature
+ ** of the book module this is considered to be a good/safe idea.
+ */
+
+ return $user->uid;
}
if ($op == "update") {
-
/*
- ** Everyone can upate a book page if there are no suggested updates
- ** of that page waiting for approval and as long as the "create new
- ** revision"-bit is set; that is, only updates that don't overwrite
- ** the current or pending information are allowed.
+ ** Only registered users can update book pages. Given the nature
+ ** of the book module this is considered to be a good/safe idea.
+ ** One can only upate a book page if there are no suggested updates
+ ** of that page waiting for approval, when it is not a PHP-page and
+ ** as long as the "create new revision"-bit is set. That is, only
+ ** updates that don't overwrite the current or pending information
+ ** are allowed.
*/
- return !$node->moderate && $node->revision;
+
+ return $user->uid && !$node->moderate && !$node->format && $node->revision;
}
}
@@ -48,7 +56,7 @@ function book_save($op, $node) {
}
if ($op == "create") {
- return array("moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight");
+ return array("format", "moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight");
}
if ($op == "decline") {
@@ -60,10 +68,10 @@ function book_save($op, $node) {
/*
** If a regular user updates a book page, we always create a new
** revision. All new revisions have to be approved (moderation)
- ** and are not promoted by derault. See also: book_load().
+ ** and are not promoted by default. See also: book_load().
*/
- return array("created" => time(), "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight");
+ return array("created" => time(), "format", "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight");
}
else if (user_access("adminster nodes")) {
/*
@@ -74,7 +82,7 @@ function book_save($op, $node) {
** regular user.
*/
- return array("parent", "weight");
+ return array("format", "parent", "weight");
}
}
@@ -89,7 +97,7 @@ function book_link($type, $node = 0, $main = 0) {
$links[] = "<a href=\"admin.php?mod=book\">". t("collaborative book") ."</a>";
}
- if ($main == 0 && $type == "node" && $node->type == "book") {
+ if ($type == "node" && $node->type == "book" && book_access("update", $node)) {
$links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\">". t("update this book page") ."</a>";
}
@@ -99,7 +107,7 @@ function book_link($type, $node = 0, $main = 0) {
function book_load($node) {
global $user, $REQUEST_URI;
- $book = db_fetch_object(db_query("SELECT parent, weight FROM book WHERE nid = '$node->nid'"));
+ $book = db_fetch_object(db_query("SELECT format, parent, weight FROM book WHERE nid = '$node->nid'"));
if (strstr($REQUEST_URI, "module.php?mod=node&op=edit")) {
@@ -118,41 +126,56 @@ function book_load($node) {
$book->uid = 0;
$book->name = "";
}
+ }
- /*
- ** We set the revision field to indicate that we have to create
- ** a new revision when updating this book page.
- */
-
- $book->revision = 1;
+ /*
+ ** We set the revision field to indicate that we have to create
+ ** a new revision when updating this book page. We enable this
+ ** always such that the "update this book page"-links appear.
+ */
- }
+ $book->revision = 1;
return $book;
}
function book_insert($node) {
- db_query("INSERT INTO book (nid, parent, weight) VALUES ('$node->nid', '$node->parent', '$node->weight')");
+ if (!user_access("administer nodes")) {
+ $node->format = 0;
+ $node->weight = 0;
+ }
+
+ db_query("INSERT INTO book (nid, format, parent, weight) VALUES ('$node->nid', '$node->format', '$node->parent', '$node->weight')");
}
function book_update($node) {
- db_query("UPDATE book SET parent = '$node->parent', weight = '$node->weight' WHERE nid = '$node->nid'");
+ if (!user_access("administer nodes")) {
+ $node->format = 0;
+ $node->weight = 0;
+ }
+
+ db_query("UPDATE book SET format = '$node->format', parent = '$node->parent', weight = '$node->weight' WHERE nid = '$node->nid'");
}
function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = '$node->nid'");
}
-
function book_form(&$node, &$help, &$error) {
global $user;
$output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in."));
- $output .= form_textarea(t("Content"), "body", $node->body, 60, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
+
+ if ($node->teaser && !$node->format) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
+ }
+
+ $output .= form_textarea(t("Body"), "body", $node->body, 60, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
$output .= form_textarea(t("Log message"), "history", $node->history, 60, 5, t("An explanation of the additions or updates being made to help the group understand your motivations."));
if (user_access("administer nodes")) {
- $output .= form_select(t("Weight"), "weight", $node->weight, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top."));
+ $output .= form_select(t("Weight"), "weight", $node->weight, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier pages will sink and the lighter pages will be positioned nearer the top."));
+ $output .= form_select("Type", "format", $node->format, array(0 => "HTML / text", 1 => "PHP"));
}
else {
@@ -173,6 +196,57 @@ function book_form(&$node, &$help, &$error) {
return $output;
}
+function book_node_link($node = 0) {
+ global $user, $op, $edit;
+
+ if ($node->type != "book") {
+
+ if ($edit["nid"]) {
+ $node = node_load(array("nid" => $edit["nid"]));
+ }
+
+ if ($op == t("Add to book outline")) {
+ db_query("INSERT INTO book (nid, parent, weight) VALUES ('$node->nid', '". check_query($edit["parent"]) ."', '". check_query($edit["weight"]) ."')");
+ $output .= status(t("added the node to the book."));
+ }
+
+ if ($op == t("Update book outline")) {
+ db_query("UPDATE book SET parent = '". check_query($edit["parent"]) ."', weight = '". check_query($edit["weight"]) ."' WHERE nid = '$node->nid'");
+ $output .= status(t("updated the book outline."));
+ }
+
+ if ($op == t("Remove from book outline")) {
+ db_query("DELETE FROM book WHERE nid = '$node->nid'");
+ $output .= status(t("removed the node form the book."));
+ }
+
+ $output .= "<h3>". t("Edit book outline") ."</h3>";
+
+ if ($edit["nid"]) {
+ $page = db_fetch_object(db_query("SELECT * FROM book WHERE nid = '$node->nid'"));
+
+ $output .= form_select(t("Parent"), "parent", $page->parent, book_toc(), t("The parent subject or category the page belongs in."));
+ $output .= form_select(t("Weight"), "weight", $page->weight, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier pages will sink and the lighter pages will be positioned nearer the top."));
+
+ if ($page->nid) {
+ $output .= form_submit(t("Update book outline"));
+ $output .= form_submit(t("Remove from book outline"));
+ }
+ else {
+ $output .= form_submit(t("Add to book outline"));
+ }
+
+ }
+ else {
+ $output .= form_submit(t("Edit book outline"));
+ }
+
+ $output .= form_hidden("nid", $node->nid);
+
+ return form($output, "post", "admin.php?mod=book&op=outline");
+ }
+}
+
/*
** Return the the most recent revision that matches the specified
** conditions.
@@ -221,20 +295,55 @@ function book_location($node, $nodes = array()) {
return $nodes;
}
+function book_body($node) {
+ global $theme, $op;
+
+ if ($node->format == 1) {
+ /*
+ ** Make sure only authorized users can preview PHP pages.
+ */
+
+ if ($op == t("Preview") && !user_access("adminster nodes")) {
+ return;
+ }
+
+ ob_start();
+ eval($node->body);
+ $output = ob_get_contents();
+ ob_end_clean();
+ }
+ else {
+ $output = check_output($node->body, 1);
+ }
+
+ return $output;
+}
+
function book_view($node, $main = 0) {
global $theme, $mod;
/*
** Always display the most recently approved revision of a node
- ** unless we have to display it in the context of the moderation
- ** queue.
+ ** (if any) unless we have to display this page in the context of
+ ** the moderation queue.
*/
if ($node->moderate && $mod != "queue") {
- $node = book_revision_load($node, array("moderate" => 0, "status" => 1));
+ $revision = book_revision_load($node, array("moderate" => 0, "status" => 1));
+
+ if ($revision) {
+ $node = $revision;
+ }
}
/*
+ ** Extract the page body. If body is dynamic (using PHP code), the body
+ ** will be generated.
+ */
+
+ $node->body = book_body($node);
+
+ /*
** Display the node. If not displayed on the main page, we render
** the node as a page in the book with extra links to the previous
** and the next page.
@@ -244,6 +353,10 @@ function book_view($node, $main = 0) {
$theme->node($node, $main);
}
else {
+ /*
+ ** Construct the "next" and "previous" links:
+ */
+
if ($node->nid && $node->parent) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$node->parent' AND (b.weight > '$node->weight' OR (b.weight = '$node->weight' AND n.title > '". check_query($node->title) ."')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC"));
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$node->parent' AND (b.weight < '$node->weight' OR (b.weight = '$node->weight' AND n.title < '". check_query($node->title) ."')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight DESC, n.title DESC"));
@@ -263,7 +376,7 @@ function book_view($node, $main = 0) {
}
if ($node->body) {
- $output .= " <tr><td colspan=\"3\"><br />". check_output($node->body, 1) ."</td></tr>";
+ $output .= " <tr><td colspan=\"3\"><br />$node->body</td></tr>";
}
if ($node->nid) {
@@ -287,7 +400,7 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
** Select all child nodes:
*/
- $result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
+ $result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
/*
** If the user is an administrator, add the root node; only
@@ -318,7 +431,7 @@ function book_tree($parent = "", $depth = 0) {
** 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 n.type = 'book' AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
+ $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:
@@ -361,7 +474,7 @@ function book_render() {
if ($node) {
// output the content:
- $output .= "<dt><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></dt><dd>". check_output($node->body, 1) ."<br /><br /></dd>";
+ $output .= "<dt><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></dt><dd>". book_body($node) ."<br /><br /></dd>";
}
}
@@ -390,7 +503,7 @@ function book_page() {
}
function book_export_html($id = "", $depth = 1) {
- $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ." AND (n.moderate = 0 OR n.revisions != '')'");
+ $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = '". check_input($id) ." AND (n.moderate = 0 OR n.revisions != '')'");
while ($page = db_fetch_object($result)) {
// load the node:
@@ -406,7 +519,7 @@ function book_export_html($id = "", $depth = 1) {
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) {
- $output .= "<ul>". check_output($node->body, 1) ."</ul>";
+ $output .= "<ul>". book_body($node) ."</ul>";
}
}
}
@@ -417,7 +530,7 @@ function book_export_html($id = "", $depth = 1) {
}
function book_export_html_recursive($parent = "", $depth = 1) {
- $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
+ $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
while ($page = db_fetch_object($result)) {
// load the node:
@@ -433,7 +546,7 @@ function book_export_html_recursive($parent = "", $depth = 1) {
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) {
- $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
+ $output .= "<ul>". book_body($node) ."</ul>";
}
$output .= book_export_html_recursive($node->nid, $depth + 1);
@@ -473,7 +586,7 @@ function book_admin_view_line($node, $depth = 0) {
function book_admin_view_book($nid, $depth = 1) {
$weight = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30);
- $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$nid' ORDER BY b.weight, n.title");
+ $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = '$nid' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) {
$node = node_load(array("nid" => $node->nid));
@@ -543,6 +656,12 @@ function book_admin() {
print "<small>". implode(" &middot; ", $links) ."</small><hr />";
switch ($op) {
+ case t("Edit book outline"):
+ case t("Add to book outline"):
+ case t("Remove from book outline"):
+ case t("Update book outline"):
+ print book_node_link();
+ break;
case "orphan":
print book_admin_orphan();
break;
diff --git a/modules/book/book.module b/modules/book/book.module
index 3e841c1b2..58ae523b9 100644
--- a/modules/book/book.module
+++ b/modules/book/book.module
@@ -25,18 +25,26 @@ function book_access($op, $node) {
}
if ($op == "create") {
- return 1;
+ /*
+ ** Only registered users can create book pages. Given the nature
+ ** of the book module this is considered to be a good/safe idea.
+ */
+
+ return $user->uid;
}
if ($op == "update") {
-
/*
- ** Everyone can upate a book page if there are no suggested updates
- ** of that page waiting for approval and as long as the "create new
- ** revision"-bit is set; that is, only updates that don't overwrite
- ** the current or pending information are allowed.
+ ** Only registered users can update book pages. Given the nature
+ ** of the book module this is considered to be a good/safe idea.
+ ** One can only upate a book page if there are no suggested updates
+ ** of that page waiting for approval, when it is not a PHP-page and
+ ** as long as the "create new revision"-bit is set. That is, only
+ ** updates that don't overwrite the current or pending information
+ ** are allowed.
*/
- return !$node->moderate && $node->revision;
+
+ return $user->uid && !$node->moderate && !$node->format && $node->revision;
}
}
@@ -48,7 +56,7 @@ function book_save($op, $node) {
}
if ($op == "create") {
- return array("moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight");
+ return array("format", "moderate" => 1, "parent", "promote" => 0, "status" => 1, "weight");
}
if ($op == "decline") {
@@ -60,10 +68,10 @@ function book_save($op, $node) {
/*
** If a regular user updates a book page, we always create a new
** revision. All new revisions have to be approved (moderation)
- ** and are not promoted by derault. See also: book_load().
+ ** and are not promoted by default. See also: book_load().
*/
- return array("created" => time(), "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight");
+ return array("created" => time(), "format", "moderate" => 1, "parent", "promote" => 0, "score" => 0, "status" => 1, "users" => "", "revisions", "votes" => 0, "weight");
}
else if (user_access("adminster nodes")) {
/*
@@ -74,7 +82,7 @@ function book_save($op, $node) {
** regular user.
*/
- return array("parent", "weight");
+ return array("format", "parent", "weight");
}
}
@@ -89,7 +97,7 @@ function book_link($type, $node = 0, $main = 0) {
$links[] = "<a href=\"admin.php?mod=book\">". t("collaborative book") ."</a>";
}
- if ($main == 0 && $type == "node" && $node->type == "book") {
+ if ($type == "node" && $node->type == "book" && book_access("update", $node)) {
$links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\">". t("update this book page") ."</a>";
}
@@ -99,7 +107,7 @@ function book_link($type, $node = 0, $main = 0) {
function book_load($node) {
global $user, $REQUEST_URI;
- $book = db_fetch_object(db_query("SELECT parent, weight FROM book WHERE nid = '$node->nid'"));
+ $book = db_fetch_object(db_query("SELECT format, parent, weight FROM book WHERE nid = '$node->nid'"));
if (strstr($REQUEST_URI, "module.php?mod=node&op=edit")) {
@@ -118,41 +126,56 @@ function book_load($node) {
$book->uid = 0;
$book->name = "";
}
+ }
- /*
- ** We set the revision field to indicate that we have to create
- ** a new revision when updating this book page.
- */
-
- $book->revision = 1;
+ /*
+ ** We set the revision field to indicate that we have to create
+ ** a new revision when updating this book page. We enable this
+ ** always such that the "update this book page"-links appear.
+ */
- }
+ $book->revision = 1;
return $book;
}
function book_insert($node) {
- db_query("INSERT INTO book (nid, parent, weight) VALUES ('$node->nid', '$node->parent', '$node->weight')");
+ if (!user_access("administer nodes")) {
+ $node->format = 0;
+ $node->weight = 0;
+ }
+
+ db_query("INSERT INTO book (nid, format, parent, weight) VALUES ('$node->nid', '$node->format', '$node->parent', '$node->weight')");
}
function book_update($node) {
- db_query("UPDATE book SET parent = '$node->parent', weight = '$node->weight' WHERE nid = '$node->nid'");
+ if (!user_access("administer nodes")) {
+ $node->format = 0;
+ $node->weight = 0;
+ }
+
+ db_query("UPDATE book SET format = '$node->format', parent = '$node->parent', weight = '$node->weight' WHERE nid = '$node->nid'");
}
function book_delete(&$node) {
db_query("DELETE FROM book WHERE nid = '$node->nid'");
}
-
function book_form(&$node, &$help, &$error) {
global $user;
$output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in."));
- $output .= form_textarea(t("Content"), "body", $node->body, 60, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
+
+ if ($node->teaser && !$node->format) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
+ }
+
+ $output .= form_textarea(t("Body"), "body", $node->body, 60, 20, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
$output .= form_textarea(t("Log message"), "history", $node->history, 60, 5, t("An explanation of the additions or updates being made to help the group understand your motivations."));
if (user_access("administer nodes")) {
- $output .= form_select(t("Weight"), "weight", $node->weight, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier nodes will sink and the lighter nodes will be positioned nearer the top."));
+ $output .= form_select(t("Weight"), "weight", $node->weight, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier pages will sink and the lighter pages will be positioned nearer the top."));
+ $output .= form_select("Type", "format", $node->format, array(0 => "HTML / text", 1 => "PHP"));
}
else {
@@ -173,6 +196,57 @@ function book_form(&$node, &$help, &$error) {
return $output;
}
+function book_node_link($node = 0) {
+ global $user, $op, $edit;
+
+ if ($node->type != "book") {
+
+ if ($edit["nid"]) {
+ $node = node_load(array("nid" => $edit["nid"]));
+ }
+
+ if ($op == t("Add to book outline")) {
+ db_query("INSERT INTO book (nid, parent, weight) VALUES ('$node->nid', '". check_query($edit["parent"]) ."', '". check_query($edit["weight"]) ."')");
+ $output .= status(t("added the node to the book."));
+ }
+
+ if ($op == t("Update book outline")) {
+ db_query("UPDATE book SET parent = '". check_query($edit["parent"]) ."', weight = '". check_query($edit["weight"]) ."' WHERE nid = '$node->nid'");
+ $output .= status(t("updated the book outline."));
+ }
+
+ if ($op == t("Remove from book outline")) {
+ db_query("DELETE FROM book WHERE nid = '$node->nid'");
+ $output .= status(t("removed the node form the book."));
+ }
+
+ $output .= "<h3>". t("Edit book outline") ."</h3>";
+
+ if ($edit["nid"]) {
+ $page = db_fetch_object(db_query("SELECT * FROM book WHERE nid = '$node->nid'"));
+
+ $output .= form_select(t("Parent"), "parent", $page->parent, book_toc(), t("The parent subject or category the page belongs in."));
+ $output .= form_select(t("Weight"), "weight", $page->weight, array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30), t("The heavier pages will sink and the lighter pages will be positioned nearer the top."));
+
+ if ($page->nid) {
+ $output .= form_submit(t("Update book outline"));
+ $output .= form_submit(t("Remove from book outline"));
+ }
+ else {
+ $output .= form_submit(t("Add to book outline"));
+ }
+
+ }
+ else {
+ $output .= form_submit(t("Edit book outline"));
+ }
+
+ $output .= form_hidden("nid", $node->nid);
+
+ return form($output, "post", "admin.php?mod=book&op=outline");
+ }
+}
+
/*
** Return the the most recent revision that matches the specified
** conditions.
@@ -221,20 +295,55 @@ function book_location($node, $nodes = array()) {
return $nodes;
}
+function book_body($node) {
+ global $theme, $op;
+
+ if ($node->format == 1) {
+ /*
+ ** Make sure only authorized users can preview PHP pages.
+ */
+
+ if ($op == t("Preview") && !user_access("adminster nodes")) {
+ return;
+ }
+
+ ob_start();
+ eval($node->body);
+ $output = ob_get_contents();
+ ob_end_clean();
+ }
+ else {
+ $output = check_output($node->body, 1);
+ }
+
+ return $output;
+}
+
function book_view($node, $main = 0) {
global $theme, $mod;
/*
** Always display the most recently approved revision of a node
- ** unless we have to display it in the context of the moderation
- ** queue.
+ ** (if any) unless we have to display this page in the context of
+ ** the moderation queue.
*/
if ($node->moderate && $mod != "queue") {
- $node = book_revision_load($node, array("moderate" => 0, "status" => 1));
+ $revision = book_revision_load($node, array("moderate" => 0, "status" => 1));
+
+ if ($revision) {
+ $node = $revision;
+ }
}
/*
+ ** Extract the page body. If body is dynamic (using PHP code), the body
+ ** will be generated.
+ */
+
+ $node->body = book_body($node);
+
+ /*
** Display the node. If not displayed on the main page, we render
** the node as a page in the book with extra links to the previous
** and the next page.
@@ -244,6 +353,10 @@ function book_view($node, $main = 0) {
$theme->node($node, $main);
}
else {
+ /*
+ ** Construct the "next" and "previous" links:
+ */
+
if ($node->nid && $node->parent) {
$next = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$node->parent' AND (b.weight > '$node->weight' OR (b.weight = '$node->weight' AND n.title > '". check_query($node->title) ."')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight ASC, n.title ASC"));
$prev = db_fetch_object(db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$node->parent' AND (b.weight < '$node->weight' OR (b.weight = '$node->weight' AND n.title < '". check_query($node->title) ."')) AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight DESC, n.title DESC"));
@@ -263,7 +376,7 @@ function book_view($node, $main = 0) {
}
if ($node->body) {
- $output .= " <tr><td colspan=\"3\"><br />". check_output($node->body, 1) ."</td></tr>";
+ $output .= " <tr><td colspan=\"3\"><br />$node->body</td></tr>";
}
if ($node->nid) {
@@ -287,7 +400,7 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
** Select all child nodes:
*/
- $result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
+ $result = db_query("SELECT n.nid, n.title FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
/*
** If the user is an administrator, add the root node; only
@@ -318,7 +431,7 @@ function book_tree($parent = "", $depth = 0) {
** 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 n.type = 'book' AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight, n.title");
+ $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:
@@ -361,7 +474,7 @@ function book_render() {
if ($node) {
// output the content:
- $output .= "<dt><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></dt><dd>". check_output($node->body, 1) ."<br /><br /></dd>";
+ $output .= "<dt><a href=\"node.php?id=$node->nid\">". check_output($node->title) ."</a></dt><dd>". book_body($node) ."<br /><br /></dd>";
}
}
@@ -390,7 +503,7 @@ function book_page() {
}
function book_export_html($id = "", $depth = 1) {
- $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND n.nid = '". check_input($id) ." AND (n.moderate = 0 OR n.revisions != '')'");
+ $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND n.nid = '". check_input($id) ." AND (n.moderate = 0 OR n.revisions != '')'");
while ($page = db_fetch_object($result)) {
// load the node:
@@ -406,7 +519,7 @@ function book_export_html($id = "", $depth = 1) {
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) {
- $output .= "<ul>". check_output($node->body, 1) ."</ul>";
+ $output .= "<ul>". book_body($node) ."</ul>";
}
}
}
@@ -417,7 +530,7 @@ function book_export_html($id = "", $depth = 1) {
}
function book_export_html_recursive($parent = "", $depth = 1) {
- $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
+ $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.status = 1 AND b.parent = '$parent' AND (n.moderate = 0 OR n.revisions != '') ORDER BY b.weight");
while ($page = db_fetch_object($result)) {
// load the node:
@@ -433,7 +546,7 @@ function book_export_html_recursive($parent = "", $depth = 1) {
$output .= "<h$depth>". check_output($node->title) ."</h$depth>";
if ($node->body) {
- $output .= "<blockquote>". check_output($node->body, 1) ."</blockquote>";
+ $output .= "<ul>". book_body($node) ."</ul>";
}
$output .= book_export_html_recursive($node->nid, $depth + 1);
@@ -473,7 +586,7 @@ function book_admin_view_line($node, $depth = 0) {
function book_admin_view_book($nid, $depth = 1) {
$weight = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30);
- $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE n.type = 'book' AND b.parent = '$nid' ORDER BY b.weight, n.title");
+ $result = db_query("SELECT n.nid FROM node n LEFT JOIN book b ON n.nid = b.nid WHERE b.parent = '$nid' ORDER BY b.weight, n.title");
while ($node = db_fetch_object($result)) {
$node = node_load(array("nid" => $node->nid));
@@ -543,6 +656,12 @@ function book_admin() {
print "<small>". implode(" &middot; ", $links) ."</small><hr />";
switch ($op) {
+ case t("Edit book outline"):
+ case t("Add to book outline"):
+ case t("Remove from book outline"):
+ case t("Update book outline"):
+ print book_node_link();
+ break;
case "orphan":
print book_admin_orphan();
break;
diff --git a/modules/node.module b/modules/node.module
index f6a550862..f60e2858d 100644
--- a/modules/node.module
+++ b/modules/node.module
@@ -33,7 +33,14 @@ function node_access($op, $node = 0) {
** Construct a function:
*/
- $function = $node->type ."_access";
+ if ($node->type) {
+ $type = $node->type;
+ }
+ else {
+ $type = $node;
+ }
+
+ $function = $type ."_access";
if (function_exists($function)) {
return $function($op, $node);
@@ -142,14 +149,10 @@ function node_link($type, $node = 0, $main = 0) {
$links = $node->links;
}
- if ($main && $node->teaser != $node->body) {
+ if ($main == 1 && $node->teaser != $node->body) {
$links[] = "<a href=\"node.php?id=$node->nid\">". t("read more") ."</a>";
}
- if (module_invoke($node->type, "access", "update", $node)) {
- $links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\">". t("edit") ."</a>";
- }
-
if (user_access("administer nodes")) {
$links[] = "<a href=\"admin.php?mod=node&op=edit&id=$node->nid\">". t("administer") ."</a>";
}
@@ -540,6 +543,14 @@ function node_form($edit) {
$edit = node_validate($edit, $error);
/*
+ ** Generate a teaser when necessary:
+ */
+
+ if ($edit->body && !$edit->teaser) {
+ $edit->teaser = node_teaser($edit->body);
+ }
+
+ /*
** Get the node specific bits:
*/
@@ -566,14 +577,6 @@ function node_form($edit) {
$output .= form_textfield(t("Title"), "title", $edit->title, 60, 64, $error["title"]);
- if ($edit->body && !$edit->teaser) {
- $edit->teaser = node_teaser($edit->body);
- }
-
- if ($edit->teaser) {
- $output .= form_textarea(t("Teaser"), "teaser", $edit->teaser, 60, 5, $error["teaser"]);
- }
-
/*
** Add the node specific fields:
*/
@@ -647,7 +650,7 @@ function node_add($type) {
** (valid) node type has been provied, display a node type overview.
*/
- if (module_hook($type, "node")) {
+ if ($type && node_access("create", $type)) {
$output = node_form(array("uid" => $user->uid, "name" => $user->name, "type" => $type));
}
else {
@@ -723,10 +726,10 @@ function node_preview($edit) {
*/
foreach ($edit as $key => $value) {
- $node->$key = check_output($value);
+ $node->$key = check_output($value);
/*
** NOTE: we can't do a check_query() or check_input() here as they
- ** add slashes which results in breakage.
+ ** add slashes which results in breakage.
*/
}
@@ -740,7 +743,7 @@ function node_preview($edit) {
}
function node_submit($node) {
- global $user;
+ global $theme, $user;
if (user_access("post content")) {
@@ -792,7 +795,7 @@ function node_submit($node) {
$fields = array("nid", "uid" => ($user->uid ? $user->uid : 0), "body", "teaser", "title", "type" => $node->type);
}
- node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
+ $nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
watchdog("special", "$node->type: updated '$node->title'");
$output = t("The node has been updated.");
@@ -824,7 +827,7 @@ function node_submit($node) {
$fields = array("uid" => ($user->uid ? $user->uid : 0), "body", "comment" => 1, "teaser", "title", "type" => $node->type);
}
- node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
+ $nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
watchdog("special", "$node->type: added '$node->title'");
$output = t("Thanks for your submission.");
@@ -835,9 +838,30 @@ function node_submit($node) {
}
}
+ /*
+ ** Reload the node from the database:
+ */
+
+ $node = node_load(array("nid" => $nid));
+
+ /*
+ ** For usability's sake, make sure to present the user with some
+ ** useful links as where to go next.
+ */
+
if ($referer = referer_load()) {
- $output .= "<p><a href=\"$referer\">". t("return") ."</a></p>";
+ $links[] = "<a href=\"$referer\">". t("return") ."</a>";
+ }
+
+ if ($nid && node_access("view", $node)) {
+ $links[] = "<a href=\"node.php?id=$nid\">". t("view") ."</a>";
+ }
+
+ if ($nid && node_access("update", $node)) {
+ $links[] = "<a href=\"module.php?mod=node&op=edit&id=$nid\">". t("edit") ."</a>";
}
+
+ $output .= "<p>". $theme->links($links) ."</p>";
}
else {
$output = message_access();
diff --git a/modules/node/node.module b/modules/node/node.module
index f6a550862..f60e2858d 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -33,7 +33,14 @@ function node_access($op, $node = 0) {
** Construct a function:
*/
- $function = $node->type ."_access";
+ if ($node->type) {
+ $type = $node->type;
+ }
+ else {
+ $type = $node;
+ }
+
+ $function = $type ."_access";
if (function_exists($function)) {
return $function($op, $node);
@@ -142,14 +149,10 @@ function node_link($type, $node = 0, $main = 0) {
$links = $node->links;
}
- if ($main && $node->teaser != $node->body) {
+ if ($main == 1 && $node->teaser != $node->body) {
$links[] = "<a href=\"node.php?id=$node->nid\">". t("read more") ."</a>";
}
- if (module_invoke($node->type, "access", "update", $node)) {
- $links[] = "<a href=\"module.php?mod=node&op=edit&id=$node->nid\">". t("edit") ."</a>";
- }
-
if (user_access("administer nodes")) {
$links[] = "<a href=\"admin.php?mod=node&op=edit&id=$node->nid\">". t("administer") ."</a>";
}
@@ -540,6 +543,14 @@ function node_form($edit) {
$edit = node_validate($edit, $error);
/*
+ ** Generate a teaser when necessary:
+ */
+
+ if ($edit->body && !$edit->teaser) {
+ $edit->teaser = node_teaser($edit->body);
+ }
+
+ /*
** Get the node specific bits:
*/
@@ -566,14 +577,6 @@ function node_form($edit) {
$output .= form_textfield(t("Title"), "title", $edit->title, 60, 64, $error["title"]);
- if ($edit->body && !$edit->teaser) {
- $edit->teaser = node_teaser($edit->body);
- }
-
- if ($edit->teaser) {
- $output .= form_textarea(t("Teaser"), "teaser", $edit->teaser, 60, 5, $error["teaser"]);
- }
-
/*
** Add the node specific fields:
*/
@@ -647,7 +650,7 @@ function node_add($type) {
** (valid) node type has been provied, display a node type overview.
*/
- if (module_hook($type, "node")) {
+ if ($type && node_access("create", $type)) {
$output = node_form(array("uid" => $user->uid, "name" => $user->name, "type" => $type));
}
else {
@@ -723,10 +726,10 @@ function node_preview($edit) {
*/
foreach ($edit as $key => $value) {
- $node->$key = check_output($value);
+ $node->$key = check_output($value);
/*
** NOTE: we can't do a check_query() or check_input() here as they
- ** add slashes which results in breakage.
+ ** add slashes which results in breakage.
*/
}
@@ -740,7 +743,7 @@ function node_preview($edit) {
}
function node_submit($node) {
- global $user;
+ global $theme, $user;
if (user_access("post content")) {
@@ -792,7 +795,7 @@ function node_submit($node) {
$fields = array("nid", "uid" => ($user->uid ? $user->uid : 0), "body", "teaser", "title", "type" => $node->type);
}
- node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
+ $nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "update", $node)));
watchdog("special", "$node->type: updated '$node->title'");
$output = t("The node has been updated.");
@@ -824,7 +827,7 @@ function node_submit($node) {
$fields = array("uid" => ($user->uid ? $user->uid : 0), "body", "comment" => 1, "teaser", "title", "type" => $node->type);
}
- node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
+ $nid = node_save($node, array_merge($fields, module_invoke($node->type, "save", "create", $node)));
watchdog("special", "$node->type: added '$node->title'");
$output = t("Thanks for your submission.");
@@ -835,9 +838,30 @@ function node_submit($node) {
}
}
+ /*
+ ** Reload the node from the database:
+ */
+
+ $node = node_load(array("nid" => $nid));
+
+ /*
+ ** For usability's sake, make sure to present the user with some
+ ** useful links as where to go next.
+ */
+
if ($referer = referer_load()) {
- $output .= "<p><a href=\"$referer\">". t("return") ."</a></p>";
+ $links[] = "<a href=\"$referer\">". t("return") ."</a>";
+ }
+
+ if ($nid && node_access("view", $node)) {
+ $links[] = "<a href=\"node.php?id=$nid\">". t("view") ."</a>";
+ }
+
+ if ($nid && node_access("update", $node)) {
+ $links[] = "<a href=\"module.php?mod=node&op=edit&id=$nid\">". t("edit") ."</a>";
}
+
+ $output .= "<p>". $theme->links($links) ."</p>";
}
else {
$output = message_access();
diff --git a/modules/page.module b/modules/page.module
index 70d00b49b..d715de045 100644
--- a/modules/page.module
+++ b/modules/page.module
@@ -1,8 +1,6 @@
<?php
// $Id$
-$GLOBALS["format"] = array(0 => "HTML", 1 => "PHP", 2 => "text");
-
function page_node($field) {
$info["name"] = t("static page");
$info["description"] = t("If you just want to add a static page with a link in the menu to your site, this would be the best choice. Unlike a story, a page by-passes the submission queue.");
@@ -17,6 +15,7 @@ function page_access($op, $node) {
}
function page_save($op, $node) {
+
if ($op == "approve") {
return array("status" => 1);
}
@@ -48,6 +47,8 @@ function page_delete(&$node) {
function page_load($node) {
$page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'"));
+
+
return $page;
}
@@ -62,31 +63,59 @@ function page_link($type) {
return $links ? $links : array();
}
-function page_view($node, $main = 0) {
- global $format, $theme;
-
- switch ($format[$node->format]) {
- case "PHP":
- print eval($node->body);
- break;
- case "text":
- $theme->box($node->title, nl2br(htmlentities($node->body)));
- break;
- default:
- $theme->box($node->title, check_output($node->body, 1));
+function page_body($node) {
+ global $theme, $op;
+
+ if ($node->format) {
+ /*
+ ** Make sure only authorized users can preview PHP pages.
+ */
+
+ if ($op == t("Preview") && !user_access("adminster nodes")) {
+ return;
+ }
+
+ ob_start();
+ eval($node->body);
+ $output = ob_get_contents();
+ ob_end_clean();
}
+ else {
+ $output = check_output($node->body, 1);
+ }
+
+ return $output;
+}
+
+function page_view($node, $main = 0) {
+ global $theme;
+
+ /*
+ ** Extract the page body. If body is dynamic (using PHP code), the body
+ ** will be generated.
+ */
+
+ $theme->box($node->title, page_body($body));
}
function page_form(&$node, &$help, &$error) {
- global $format, $op;
+ global $op;
- if ($op != t("Preview") && $format[$node->format] == "PHP") {
- $node->body = addslashes($node->body);
+ if ($node->teaser && !$node->format) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
}
+ /*
+ ** Q: s this still required?
+ **
+ ** if ($op != t("Preview") && $node->format) {
+ ** $node->body = addslashes($node->body);
+ ** }
+ */
+
$output .= form_textarea("Body", "body", $node->body, 60, 20);
$output .= form_textfield("Link", "link", $node->link, 60, 64);
- $output .= form_select("Type", "format", $node->format, $format);
+ $output .= form_select("Type", "format", $node->format, array(0 => "HTML / text", 1 => "PHP"));
return $output;
}
diff --git a/modules/page/page.module b/modules/page/page.module
index 70d00b49b..d715de045 100644
--- a/modules/page/page.module
+++ b/modules/page/page.module
@@ -1,8 +1,6 @@
<?php
// $Id$
-$GLOBALS["format"] = array(0 => "HTML", 1 => "PHP", 2 => "text");
-
function page_node($field) {
$info["name"] = t("static page");
$info["description"] = t("If you just want to add a static page with a link in the menu to your site, this would be the best choice. Unlike a story, a page by-passes the submission queue.");
@@ -17,6 +15,7 @@ function page_access($op, $node) {
}
function page_save($op, $node) {
+
if ($op == "approve") {
return array("status" => 1);
}
@@ -48,6 +47,8 @@ function page_delete(&$node) {
function page_load($node) {
$page = db_fetch_object(db_query("SELECT format, link FROM page WHERE nid = '$node->nid'"));
+
+
return $page;
}
@@ -62,31 +63,59 @@ function page_link($type) {
return $links ? $links : array();
}
-function page_view($node, $main = 0) {
- global $format, $theme;
-
- switch ($format[$node->format]) {
- case "PHP":
- print eval($node->body);
- break;
- case "text":
- $theme->box($node->title, nl2br(htmlentities($node->body)));
- break;
- default:
- $theme->box($node->title, check_output($node->body, 1));
+function page_body($node) {
+ global $theme, $op;
+
+ if ($node->format) {
+ /*
+ ** Make sure only authorized users can preview PHP pages.
+ */
+
+ if ($op == t("Preview") && !user_access("adminster nodes")) {
+ return;
+ }
+
+ ob_start();
+ eval($node->body);
+ $output = ob_get_contents();
+ ob_end_clean();
}
+ else {
+ $output = check_output($node->body, 1);
+ }
+
+ return $output;
+}
+
+function page_view($node, $main = 0) {
+ global $theme;
+
+ /*
+ ** Extract the page body. If body is dynamic (using PHP code), the body
+ ** will be generated.
+ */
+
+ $theme->box($node->title, page_body($body));
}
function page_form(&$node, &$help, &$error) {
- global $format, $op;
+ global $op;
- if ($op != t("Preview") && $format[$node->format] == "PHP") {
- $node->body = addslashes($node->body);
+ if ($node->teaser && !$node->format) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
}
+ /*
+ ** Q: s this still required?
+ **
+ ** if ($op != t("Preview") && $node->format) {
+ ** $node->body = addslashes($node->body);
+ ** }
+ */
+
$output .= form_textarea("Body", "body", $node->body, 60, 20);
$output .= form_textfield("Link", "link", $node->link, 60, 64);
- $output .= form_select("Type", "format", $node->format, $format);
+ $output .= form_select("Type", "format", $node->format, array(0 => "HTML / text", 1 => "PHP"));
return $output;
}
diff --git a/modules/story.module b/modules/story.module
index d9c71214c..747259463 100644
--- a/modules/story.module
+++ b/modules/story.module
@@ -1,87 +1,91 @@
-<?php
-// $Id$
-
-function story_conf_options() {
- $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 55, 4, "This text will be displayed at the top of the story submission form. Useful for helping or instructing your users.");
- $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_story_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal story entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post."));
-
- return $output;
-}
-
-function story_node($field) {
- $info["name"] = t("story");
- $info["description"] = t("A story is a post that is submitted to the attention of other users and is queued in the submission queue. Users and moderators vote on the posts they like or dislike, promoting or demoting them. When a post gets above a certain threshold it gets authomatically published to front page.");
-
- return $info[$field];
-}
-
-function story_access($op, $node) {
- if ($op == "view") {
- return $node->status;
- }
-
- if ($op == "create") {
- return 1;
- }
-}
-
-function story_save($op, $node) {
-
- if ($op == "approve") {
- return array("status" => 1, "promote" => 1);
- }
-
- if ($op == "create") {
- return array("moderate" => 1);
- }
-
- if ($op == "decline") {
- return array("status" => 0, "promote" => 0);
- }
-
- if ($op == "update") {
- return array("status");
- }
-
-}
-
-function story_help() {
- ?>
- // TODO: update documentation, outdated
-
- //<p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p>
- //<p>Posted stories: published stories accessible to all visitors.</p>
- //<p>Dumped stories: rejected stories that are no longer available to visitors.</p>
- <?php
-}
-
-function story_form(&$node, &$help, &$error) {
-
- if (isset($node->body)) {
-
- /*
- ** Validate the size of the story:
- */
-
- if (count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) {
- $error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>";
- }
-
- }
- else {
-
- /*
- ** Carry out some explanation or submission guidelines:
- */
-
- $help = variable_get("story_help", "");
-
- }
-
- $output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
-
- return $output;
-}
-
-
-?>
+<?php
+// $Id$
+
+function story_conf_options() {
+ $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 55, 4, "This text will be displayed at the top of the story submission form. Useful for helping or instructing your users.");
+ $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_story_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal story entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post."));
+
+ return $output;
+}
+
+function story_node($field) {
+ $info["name"] = t("story");
+ $info["description"] = t("A story is a post that is submitted to the attention of other users and is queued in the submission queue. Users and moderators vote on the posts they like or dislike, promoting or demoting them. When a post gets above a certain threshold it gets authomatically published to front page.");
+
+ return $info[$field];
+}
+
+function story_access($op, $node) {
+ if ($op == "view") {
+ return $node->status;
+ }
+
+ if ($op == "create") {
+ return 1;
+ }
+}
+
+function story_save($op, $node) {
+
+ if ($op == "approve") {
+ return array("status" => 1, "promote" => 1);
+ }
+
+ if ($op == "create") {
+ return array("moderate" => 1);
+ }
+
+ if ($op == "decline") {
+ return array("status" => 0, "promote" => 0);
+ }
+
+ if ($op == "update") {
+ return array("status");
+ }
+
+}
+
+function story_help() {
+ ?>
+ // TODO: update documentation, outdated
+
+ //<p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p>
+ //<p>Posted stories: published stories accessible to all visitors.</p>
+ //<p>Dumped stories: rejected stories that are no longer available to visitors.</p>
+ <?php
+}
+
+function story_form(&$node, &$help, &$error) {
+
+ if (isset($node->body)) {
+
+ /*
+ ** Validate the size of the story:
+ */
+
+ if (count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) {
+ $error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>";
+ }
+
+ }
+ else {
+
+ /*
+ ** Carry out some explanation or submission guidelines:
+ */
+
+ $help = variable_get("story_help", "");
+
+ }
+
+ if ($node->teaser) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
+ }
+
+ $output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
+
+ return $output;
+}
+
+
+?>
diff --git a/modules/story/story.module b/modules/story/story.module
index d9c71214c..747259463 100644
--- a/modules/story/story.module
+++ b/modules/story/story.module
@@ -1,87 +1,91 @@
-<?php
-// $Id$
-
-function story_conf_options() {
- $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 55, 4, "This text will be displayed at the top of the story submission form. Useful for helping or instructing your users.");
- $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_story_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal story entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post."));
-
- return $output;
-}
-
-function story_node($field) {
- $info["name"] = t("story");
- $info["description"] = t("A story is a post that is submitted to the attention of other users and is queued in the submission queue. Users and moderators vote on the posts they like or dislike, promoting or demoting them. When a post gets above a certain threshold it gets authomatically published to front page.");
-
- return $info[$field];
-}
-
-function story_access($op, $node) {
- if ($op == "view") {
- return $node->status;
- }
-
- if ($op == "create") {
- return 1;
- }
-}
-
-function story_save($op, $node) {
-
- if ($op == "approve") {
- return array("status" => 1, "promote" => 1);
- }
-
- if ($op == "create") {
- return array("moderate" => 1);
- }
-
- if ($op == "decline") {
- return array("status" => 0, "promote" => 0);
- }
-
- if ($op == "update") {
- return array("status");
- }
-
-}
-
-function story_help() {
- ?>
- // TODO: update documentation, outdated
-
- //<p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p>
- //<p>Posted stories: published stories accessible to all visitors.</p>
- //<p>Dumped stories: rejected stories that are no longer available to visitors.</p>
- <?php
-}
-
-function story_form(&$node, &$help, &$error) {
-
- if (isset($node->body)) {
-
- /*
- ** Validate the size of the story:
- */
-
- if (count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) {
- $error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>";
- }
-
- }
- else {
-
- /*
- ** Carry out some explanation or submission guidelines:
- */
-
- $help = variable_get("story_help", "");
-
- }
-
- $output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
-
- return $output;
-}
-
-
-?>
+<?php
+// $Id$
+
+function story_conf_options() {
+ $output .= form_textarea("Explanation or submission guidelines", "story_help", variable_get("story_help", ""), 55, 4, "This text will be displayed at the top of the story submission form. Useful for helping or instructing your users.");
+ $output .= form_select(t("Minimum number of words"), "minimum_story_size", variable_get("minimum_story_size", 0), array(0 => "0 words", 10 => "10 words", 25 => "25 words", 50 => "50 words", 75 => "75 words", 100 => "100 words", 125 => "125 words", 150 => "150 words", 175 => "175 words", 200 => "200 words"), t("The minimum number of words a personal story entry should consist of. This can be useful to rule out submissions that do not meet the site's standards, such as short test post."));
+
+ return $output;
+}
+
+function story_node($field) {
+ $info["name"] = t("story");
+ $info["description"] = t("A story is a post that is submitted to the attention of other users and is queued in the submission queue. Users and moderators vote on the posts they like or dislike, promoting or demoting them. When a post gets above a certain threshold it gets authomatically published to front page.");
+
+ return $info[$field];
+}
+
+function story_access($op, $node) {
+ if ($op == "view") {
+ return $node->status;
+ }
+
+ if ($op == "create") {
+ return 1;
+ }
+}
+
+function story_save($op, $node) {
+
+ if ($op == "approve") {
+ return array("status" => 1, "promote" => 1);
+ }
+
+ if ($op == "create") {
+ return array("moderate" => 1);
+ }
+
+ if ($op == "decline") {
+ return array("status" => 0, "promote" => 0);
+ }
+
+ if ($op == "update") {
+ return array("status");
+ }
+
+}
+
+function story_help() {
+ ?>
+ // TODO: update documentation, outdated
+
+ //<p>Queued stories: user-contributed stories are automatically whisked away to a submission queue for moderators (i.e. registered user) to frown at. Moderators vote whether or not a story should be posted to the front page for discussion.</p>
+ //<p>Posted stories: published stories accessible to all visitors.</p>
+ //<p>Dumped stories: rejected stories that are no longer available to visitors.</p>
+ <?php
+}
+
+function story_form(&$node, &$help, &$error) {
+
+ if (isset($node->body)) {
+
+ /*
+ ** Validate the size of the story:
+ */
+
+ if (count(explode(" ", $node->body)) < variable_get("minimum_story_size", 0)) {
+ $error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>";
+ }
+
+ }
+ else {
+
+ /*
+ ** Carry out some explanation or submission guidelines:
+ */
+
+ $help = variable_get("story_help", "");
+
+ }
+
+ if ($node->teaser) {
+ $output .= form_textarea(t("Teaser"), "teaser", $node->teaser, 60, 5, $error["teaser"]);
+ }
+
+ $output = form_textarea(t("Body"), "body", $node->body, 60, 15, $error["body"] ? $error["body"] : t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
+
+ return $output;
+}
+
+
+?>
diff --git a/update.php b/update.php
index 80bd9771a..e71bd0ff6 100644
--- a/update.php
+++ b/update.php
@@ -18,6 +18,7 @@ $mysql_updates = array(
"2001-11-04" => "update_9",
"2001-11-17: distributed authentication" => "update_10",
"2001-12-01" => "update_11",
+ "2001-12-06" => "update_12",
);
// Update functions
@@ -241,6 +242,11 @@ function update_11() {
update_sql("ALTER TABLE users ADD session TEXT;");
}
+function update_12() {
+ update_sql("ALTER TABLE book DROP revision;");
+ update_sql("ALTER TABLE book ADD format tinyint(2) DEFAULT '0';");
+}
+
// System functions
function update_sql($sql) {
global $edit;