diff options
author | Dries Buytaert <dries@buytaert.net> | 2001-11-01 22:54:16 +0000 |
---|---|---|
committer | Dries Buytaert <dries@buytaert.net> | 2001-11-01 22:54:16 +0000 |
commit | 4d8b485fad960ea6551111e58f8c59df053b4456 (patch) | |
tree | 51c7738a0ee2d4ac3e63552643de52bab1c41da5 | |
parent | e205fee081d307ee7a3ef2248fbb3ded7fcf003c (diff) | |
download | brdo-4d8b485fad960ea6551111e58f8c59df053b4456.tar.gz brdo-4d8b485fad960ea6551111e58f8c59df053b4456.tar.bz2 |
- Added error handling support to the <node>_form hook.
-rw-r--r-- | modules/blog.module | 15 | ||||
-rw-r--r-- | modules/blog/blog.module | 15 | ||||
-rw-r--r-- | modules/book.module | 2 | ||||
-rw-r--r-- | modules/book/book.module | 2 | ||||
-rw-r--r-- | modules/cloud.module | 9 | ||||
-rw-r--r-- | modules/forum.module | 2 | ||||
-rw-r--r-- | modules/forum/forum.module | 2 | ||||
-rw-r--r-- | modules/node.module | 57 | ||||
-rw-r--r-- | modules/node/node.module | 57 | ||||
-rw-r--r-- | modules/page.module | 2 | ||||
-rw-r--r-- | modules/page/page.module | 2 | ||||
-rw-r--r-- | modules/story.module | 10 | ||||
-rw-r--r-- | modules/story/story.module | 10 |
13 files changed, 113 insertions, 72 deletions
diff --git a/modules/blog.module b/modules/blog.module index a0489928b..397fb56cf 100644 --- a/modules/blog.module +++ b/modules/blog.module @@ -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; } diff --git a/modules/blog/blog.module b/modules/blog/blog.module index a0489928b..397fb56cf 100644 --- a/modules/blog/blog.module +++ b/modules/blog/blog.module @@ -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; } diff --git a/modules/book.module b/modules/book.module index 84c7d00de..3b88c3376 100644 --- a/modules/book.module +++ b/modules/book.module @@ -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.")); diff --git a/modules/book/book.module b/modules/book/book.module index 84c7d00de..3b88c3376 100644 --- a/modules/book/book.module +++ b/modules/book/book.module @@ -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.")); diff --git a/modules/cloud.module b/modules/cloud.module index 4006ac775..8c1612445 100644 --- a/modules/cloud.module +++ b/modules/cloud.module @@ -1,9 +1,6 @@ <?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; } diff --git a/modules/forum.module b/modules/forum.module index f33ad51f5..1eec66753 100644 --- a/modules/forum.module +++ b/modules/forum.module @@ -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); diff --git a/modules/forum/forum.module b/modules/forum/forum.module index f33ad51f5..1eec66753 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -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); diff --git a/modules/node.module b/modules/node.module index c239d9868..c82eaf44a 100644 --- a/modules/node.module +++ b/modules/node.module @@ -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) { diff --git a/modules/node/node.module b/modules/node/node.module index c239d9868..c82eaf44a 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -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) { diff --git a/modules/page.module b/modules/page.module index bb1affd35..f2b9e6834 100644 --- a/modules/page.module +++ b/modules/page.module @@ -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") { diff --git a/modules/page/page.module b/modules/page/page.module index bb1affd35..f2b9e6834 100644 --- a/modules/page/page.module +++ b/modules/page/page.module @@ -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") { diff --git a/modules/story.module b/modules/story.module index 66870c076..1829474fb 100644 --- a/modules/story.module +++ b/modules/story.module @@ -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; } diff --git a/modules/story/story.module b/modules/story/story.module index 66870c076..1829474fb 100644 --- a/modules/story/story.module +++ b/modules/story/story.module @@ -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; } |