Commit 20b4b716 authored by Dries's avatar Dries

- 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.
parent 2b01b838
......@@ -118,7 +118,6 @@ function node_load($conditions) {
}
return $node;
}
function node_save($node, $filter) {
......
......@@ -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();
......
......@@ -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();
......
This diff is collapsed.
This diff is collapsed.
......@@ -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>";
}
......@@ -539,6 +542,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();
......
......@@ -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>";
}
......@@ -539,6 +542,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();
......
<?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;
}
......
<?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;
}
......
<?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;
}
?>