Commit 4d8b485f authored by Dries's avatar Dries

- Added error handling support to the <node>_form hook.
parent e205fee0
......@@ -178,20 +178,25 @@ function blog_page_last() {
$theme->box(t("User blogs"), $output, "main");
}
function blog_form($edit) {
function blog_form($node, $error) {
global $nid, $iid;
if (!$edit->body) {
if ($node->body) {
if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) {
$error["body"] = "<div style=\"color: red;\">". t("The body of your blog is too short.") ."</div>";
}
}
else {
if ($nid && $blog = node_load(array("nid" => $nid))) {
$edit->body = "<i>". $blog->body ."</i> [<a href=\"module.php?mod=blog&id=$blog->uid&date=$blog->created\">$blog->name</a>]";
$node->body = "<i>". $blog->body ."</i> [<a href=\"module.php?mod=blog&id=$blog->uid&date=$blog->created\">$blog->name</a>]";
}
if ($iid && $item = db_fetch_object(db_query("SELECT i.*, f.title as ftitle, f.link as flink FROM item i, feed f WHERE i.iid = '". check_input($iid) ."' AND i.fid = f.fid"))) {
$edit->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
$node->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
}
}
$output = form_textarea(t("Body"), "body", $edit->body, 60, 15, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
$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;
}
......
......@@ -178,20 +178,25 @@ function blog_page_last() {
$theme->box(t("User blogs"), $output, "main");
}
function blog_form($edit) {
function blog_form($node, $error) {
global $nid, $iid;
if (!$edit->body) {
if ($node->body) {
if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) {
$error["body"] = "<div style=\"color: red;\">". t("The body of your blog is too short.") ."</div>";
}
}
else {
if ($nid && $blog = node_load(array("nid" => $nid))) {
$edit->body = "<i>". $blog->body ."</i> [<a href=\"module.php?mod=blog&id=$blog->uid&date=$blog->created\">$blog->name</a>]";
$node->body = "<i>". $blog->body ."</i> [<a href=\"module.php?mod=blog&id=$blog->uid&date=$blog->created\">$blog->name</a>]";
}
if ($iid && $item = db_fetch_object(db_query("SELECT i.*, f.title as ftitle, f.link as flink FROM item i, feed f WHERE i.iid = '". check_input($iid) ."' AND i.fid = f.fid"))) {
$edit->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
$node->body = "<a href=\"$item->link\">$item->title</a> - <i>". check_output($item->description) ."</i> [<a href=\"$item->flink\">$item->ftitle</a>]\n";
}
}
$output = form_textarea(t("Body"), "body", $edit->body, 60, 15, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
$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;
}
......
......@@ -155,7 +155,7 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
return $toc;
}
function book_form($node) {
function book_form($node, $error) {
global $user;
$output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in."));
......
......@@ -155,7 +155,7 @@ function book_toc($parent = "", $indent = "", $toc = array()) {
return $toc;
}
function book_form($node) {
function book_form($node, $error) {
global $user;
$output .= form_select(t("Parent"), "parent", $node->parent, book_toc(), t("The parent subject or category the page belongs in."));
......
<?php
// $Id$
function cloud_help() {
}
function cloud_cron() {
if (time() % 250 == 0) {
$result = db_query("SELECT * FROM site");
......@@ -139,15 +136,15 @@ function cloud_page() {
if (user_access("access site cloud")) {
$theme->header();
$theme->box(t("Updated sites"), cloud_list(100));
$theme->box(t("Site rolling"), cloud_list(100));
$theme->footer();
}
}
function cloud_block() {
$block[0]["subject"] = t("Sites");
$block[0]["subject"] = t("Site rolling");
$block[0]["content"] = cloud_list(20);
$block[0]["info"] = t("Sites");
$block[0]["info"] = t("Site rolling");
return $block;
}
......
......@@ -30,7 +30,7 @@ function forum_view($node) {
$theme->box(t("Discussion forum"), $output);
}
function forum_form($node) {
function forum_form($node, $error) {
$output .= form_textarea("Body", "body", $node->body, 60, 10);
......
......@@ -30,7 +30,7 @@ function forum_view($node) {
$theme->box(t("Discussion forum"), $output);
}
function forum_form($node) {
function forum_form($node, $error) {
$output .= form_textarea("Body", "body", $node->body, 60, 10);
......
......@@ -54,7 +54,9 @@ function node_search($keys) {
}
function node_conf_options() {
$output .= form_select("Default number of nodes to display", "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), "The default maximum number of nodes to display on the main page.");
$output .= form_select(t("Default number of nodes to display"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of nodes to display on the main page."));
$output .= form_select(t("Minimum number of words in a node"), "minimum_node_size", variable_get("minimum_node_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 node should have. This can be useful to stop test post."));
return $output;
}
......@@ -283,7 +285,7 @@ function node_feed() {
}
function node_fixup($edit) {
function node_validate($node, $error) {
global $user;
......@@ -291,13 +293,13 @@ function node_fixup($edit) {
** Convert the node to an object if necessary:
*/
$edit = node_object($edit);
$node = node_object($node);
/*
** Validate the title field:
*/
if (($edit->nid || $edit->body) && !$edit->title) {
if (($node->nid || $node->body) && !$node->title) {
$error["title"] = "<div style=\"color: red;\">". t("You have to specify a valid title.") ."</div>";
}
......@@ -307,47 +309,56 @@ function node_fixup($edit) {
** Setup default values if required:
*/
if (!$edit->name) {
$edit->name = $user->name;
if (!$node->name) {
$node->name = $user->name;
}
if (!$edit->created) {
$edit->created = time();
if (!$node->created) {
$node->created = time();
}
if (!$edit->date) {
$edit->date = date("M j, Y g:i a", $edit->created);
if (!$node->date) {
$node->date = date("M j, Y g:i a", $node->created);
}
/*
** Validate the "authored by"-field:
*/
if ($account = user_load(array("name" => $edit->name))) {
$edit->uid = $account->uid;
if ($account = user_load(array("name" => $node->name))) {
$node->uid = $account->uid;
}
else {
$error["name"] = "<div style=\"color: red;\">". sprintf(t("The name '%s' does not exist."), $edit->name) ."</div>";
$error["name"] = "<div style=\"color: red;\">". sprintf(t("The name '%s' does not exist."), $node->name) ."</div>";
}
/*
** Validate the "authored on"-field:
*/
if (strtotime($edit->date) > 1000) {
$edit->created = strtotime($edit->date);
if (strtotime($node->date) > 1000) {
$node->created = strtotime($node->date);
}
else {
$error["date"] = "<div style=\"color: red;\">". t("You have to specifiy a valid date.") ."</div>";
}
/*
** Validate the "teaser"-field:
*/
if ($node->teaser && count(explode(" ", $node->teaser)) < variable_get("minimum_node_size", 0)) {
$error["teaser"] = "<div style=\"color: red;\">". t("Your teaser is too short.") ."</div>";
}
}
return $error;
return $node;
}
function node_form($edit) {
$error = node_fixup(&$edit);
$edit = node_validate($edit, &$error);
$output .= "<div style=\"margin-right: 40px; float: left;\">";
......@@ -362,14 +373,17 @@ function node_form($edit) {
}
if ($edit->teaser) {
$output .= form_textarea(t("Teaser"), "teaser", $edit->teaser, 60, 5);
$output .= form_textarea(t("Teaser"), "teaser", $edit->teaser, 60, 5, $error["teaser"]);
}
/*
** Add the node specific parts:
*/
$output .= module_invoke($edit->type, "form", $edit);
$function = $edit->type ."_form";
if (function_exists($function)) {
$output .= $function($edit, &$error);
}
/*
** Add the hidden fields:
......@@ -430,8 +444,6 @@ function node_add($type) {
$output = node_form(array("uid" => $user->uid, "type" => $type));
}
else {
// TODO: make building a node list generic and find an easy way to associate post permissions with them
$links = array();
foreach (module_list() as $name) {
......@@ -450,7 +462,6 @@ function node_edit($id) {
global $user;
$node = node_load(array("nid" => $id));
// TODO: make this generic for all node types - temporary solution
if (node_access("update", $node)) {
$output = node_form($node);
......@@ -502,7 +513,7 @@ function node_submit($node) {
** Fixup the node when required:
*/
node_fixup(&$node);
$node = node_validate($node);
if ($node->nid) {
......
......@@ -54,7 +54,9 @@ function node_search($keys) {
}
function node_conf_options() {
$output .= form_select("Default number of nodes to display", "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), "The default maximum number of nodes to display on the main page.");
$output .= form_select(t("Default number of nodes to display"), "default_nodes_main", variable_get("default_nodes_main", 10), array(1 => 1, 2 => 2, 3 => 3, 4 => 4, 5 => 5, 6 => 6, 7 => 7, 8 => 8, 9 => 9, 10 => 10, 15 => 15, 20 => 20, 25 => 25, 30 => 30), t("The default maximum number of nodes to display on the main page."));
$output .= form_select(t("Minimum number of words in a node"), "minimum_node_size", variable_get("minimum_node_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 node should have. This can be useful to stop test post."));
return $output;
}
......@@ -283,7 +285,7 @@ function node_feed() {
}
function node_fixup($edit) {
function node_validate($node, $error) {
global $user;
......@@ -291,13 +293,13 @@ function node_fixup($edit) {
** Convert the node to an object if necessary:
*/
$edit = node_object($edit);
$node = node_object($node);
/*
** Validate the title field:
*/
if (($edit->nid || $edit->body) && !$edit->title) {
if (($node->nid || $node->body) && !$node->title) {
$error["title"] = "<div style=\"color: red;\">". t("You have to specify a valid title.") ."</div>";
}
......@@ -307,47 +309,56 @@ function node_fixup($edit) {
** Setup default values if required:
*/
if (!$edit->name) {
$edit->name = $user->name;
if (!$node->name) {
$node->name = $user->name;
}
if (!$edit->created) {
$edit->created = time();
if (!$node->created) {
$node->created = time();
}
if (!$edit->date) {
$edit->date = date("M j, Y g:i a", $edit->created);
if (!$node->date) {
$node->date = date("M j, Y g:i a", $node->created);
}
/*
** Validate the "authored by"-field:
*/
if ($account = user_load(array("name" => $edit->name))) {
$edit->uid = $account->uid;
if ($account = user_load(array("name" => $node->name))) {
$node->uid = $account->uid;
}
else {
$error["name"] = "<div style=\"color: red;\">". sprintf(t("The name '%s' does not exist."), $edit->name) ."</div>";
$error["name"] = "<div style=\"color: red;\">". sprintf(t("The name '%s' does not exist."), $node->name) ."</div>";
}
/*
** Validate the "authored on"-field:
*/
if (strtotime($edit->date) > 1000) {
$edit->created = strtotime($edit->date);
if (strtotime($node->date) > 1000) {
$node->created = strtotime($node->date);
}
else {
$error["date"] = "<div style=\"color: red;\">". t("You have to specifiy a valid date.") ."</div>";
}
/*
** Validate the "teaser"-field:
*/
if ($node->teaser && count(explode(" ", $node->teaser)) < variable_get("minimum_node_size", 0)) {
$error["teaser"] = "<div style=\"color: red;\">". t("Your teaser is too short.") ."</div>";
}
}
return $error;
return $node;
}
function node_form($edit) {
$error = node_fixup(&$edit);
$edit = node_validate($edit, &$error);
$output .= "<div style=\"margin-right: 40px; float: left;\">";
......@@ -362,14 +373,17 @@ function node_form($edit) {
}
if ($edit->teaser) {
$output .= form_textarea(t("Teaser"), "teaser", $edit->teaser, 60, 5);
$output .= form_textarea(t("Teaser"), "teaser", $edit->teaser, 60, 5, $error["teaser"]);
}
/*
** Add the node specific parts:
*/
$output .= module_invoke($edit->type, "form", $edit);
$function = $edit->type ."_form";
if (function_exists($function)) {
$output .= $function($edit, &$error);
}
/*
** Add the hidden fields:
......@@ -430,8 +444,6 @@ function node_add($type) {
$output = node_form(array("uid" => $user->uid, "type" => $type));
}
else {
// TODO: make building a node list generic and find an easy way to associate post permissions with them
$links = array();
foreach (module_list() as $name) {
......@@ -450,7 +462,6 @@ function node_edit($id) {
global $user;
$node = node_load(array("nid" => $id));
// TODO: make this generic for all node types - temporary solution
if (node_access("update", $node)) {
$output = node_form($node);
......@@ -502,7 +513,7 @@ function node_submit($node) {
** Fixup the node when required:
*/
node_fixup(&$node);
$node = node_validate($node);
if ($node->nid) {
......
......@@ -62,7 +62,7 @@ function page_view($node, $main = 0) {
}
function page_form($node) {
function page_form($node, $error) {
global $format, $op;
if ($op != t("Preview") && $format[$node->format] == "PHP") {
......
......@@ -62,7 +62,7 @@ function page_view($node, $main = 0) {
}
function page_form($node) {
function page_form($node, $error) {
global $format, $op;
if ($op != t("Preview") && $format[$node->format] == "PHP") {
......
......@@ -39,9 +39,15 @@ function story_help() {
<?php
}
function story_form($node) {
function story_form($node, $error) {
$output = form_textarea(t("Body"), "body", $node->body, 60, 15, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
if ($node->body) {
if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) {
$error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>";
}
}
$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;
}
......
......@@ -39,9 +39,15 @@ function story_help() {
<?php
}
function story_form($node) {
function story_form($node, $error) {
$output = form_textarea(t("Body"), "body", $node->body, 60, 15, t("Allowed HTML tags") .": ". htmlspecialchars(variable_get("allowed_html", "")));
if ($node->body) {
if (count(explode(" ", $node->body)) < variable_get("minimum_node_size", 0)) {
$error["body"] = "<div style=\"color: red;\">". t("The body of your story is too short.") ."</div>";
}
}
$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;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment