Commit 1687dd07 authored by Dries's avatar Dries

- Patch 5049 by JonBob: allow a module to define multiple node types.
parent f99eb4dc
...@@ -8,13 +8,8 @@ function blog_settings() { ...@@ -8,13 +8,8 @@ function blog_settings() {
return $output; return $output;
} }
function blog_node($field) { function blog_node_name($node) {
global $user; return t("personal blog entry");
$info["name"] = t("personal blog entry");
$info["description"] = t("A blog is a regularly updated journal made up of individual entries, often called posts, that are time stamped and typically arranged by the day, with the newest on top (a diary is the reverse). They tend to be quite personal, often containing links to things you've seen, or to editorials that you find interesting. Some blogs also contain original material written solely for the blog. Since a Blog is personal, you and only you have full control over what you publish. The most interesting blog entries or those blog entries that fit the site's topic well might get promoted to the front page by the community or by users with the access do this.");
return $info[$field];
} }
function blog_perm() { function blog_perm() {
...@@ -85,6 +80,9 @@ function blog_help($section) { ...@@ -85,6 +80,9 @@ function blog_help($section) {
case 'node/add/blog': case 'node/add/blog':
$output = variable_get('blog_help', ''); $output = variable_get('blog_help', '');
break; break;
case 'node/add#blog':
$output = t("A blog is a regularly updated journal made up of individual entries, often called posts, that are time stamped and typically arranged by the day, with the newest on top (a diary is the reverse). They tend to be quite personal, often containing links to things you've seen, or to editorials that you find interesting. Some blogs also contain original material written solely for the blog. Since a Blog is personal, you and only you have full control over what you publish. The most interesting blog entries or those blog entries that fit the site's topic well might get promoted to the front page by the community or by users with the access do this.");
break;
} }
return $output; return $output;
......
...@@ -8,13 +8,8 @@ function blog_settings() { ...@@ -8,13 +8,8 @@ function blog_settings() {
return $output; return $output;
} }
function blog_node($field) { function blog_node_name($node) {
global $user; return t("personal blog entry");
$info["name"] = t("personal blog entry");
$info["description"] = t("A blog is a regularly updated journal made up of individual entries, often called posts, that are time stamped and typically arranged by the day, with the newest on top (a diary is the reverse). They tend to be quite personal, often containing links to things you've seen, or to editorials that you find interesting. Some blogs also contain original material written solely for the blog. Since a Blog is personal, you and only you have full control over what you publish. The most interesting blog entries or those blog entries that fit the site's topic well might get promoted to the front page by the community or by users with the access do this.");
return $info[$field];
} }
function blog_perm() { function blog_perm() {
...@@ -85,6 +80,9 @@ function blog_help($section) { ...@@ -85,6 +80,9 @@ function blog_help($section) {
case 'node/add/blog': case 'node/add/blog':
$output = variable_get('blog_help', ''); $output = variable_get('blog_help', '');
break; break;
case 'node/add#blog':
$output = t("A blog is a regularly updated journal made up of individual entries, often called posts, that are time stamped and typically arranged by the day, with the newest on top (a diary is the reverse). They tend to be quite personal, often containing links to things you've seen, or to editorials that you find interesting. Some blogs also contain original material written solely for the blog. Since a Blog is personal, you and only you have full control over what you publish. The most interesting blog entries or those blog entries that fit the site's topic well might get promoted to the front page by the community or by users with the access do this.");
break;
} }
return $output; return $output;
......
<?php <?php
// $Id$ // $Id$
function book_node($field) { function book_node_name($node) {
global $user; return t("book page");
$info["name"] = t("book page");
$info["description"] = t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
return $info[$field];
} }
function book_perm() { function book_perm() {
...@@ -901,6 +896,9 @@ function book_help($section = "admin/help#book") { ...@@ -901,6 +896,9 @@ function book_help($section = "admin/help#book") {
case 'admin/node/book/orphan': case 'admin/node/book/orphan':
$output = t("Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are refered to as 'orphan pages'. On this page, administrators can review their books for orphans and reattach those pages as desired."); $output = t("Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are refered to as 'orphan pages'. On this page, administrators can review their books for orphans and reattach those pages as desired.");
break; break;
case 'node/add#book':
$output = t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
break;
} }
return $output; return $output;
......
<?php <?php
// $Id$ // $Id$
function book_node($field) { function book_node_name($node) {
global $user; return t("book page");
$info["name"] = t("book page");
$info["description"] = t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
return $info[$field];
} }
function book_perm() { function book_perm() {
...@@ -901,6 +896,9 @@ function book_help($section = "admin/help#book") { ...@@ -901,6 +896,9 @@ function book_help($section = "admin/help#book") {
case 'admin/node/book/orphan': case 'admin/node/book/orphan':
$output = t("Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are refered to as 'orphan pages'. On this page, administrators can review their books for orphans and reattach those pages as desired."); $output = t("Pages in a book are like a tree. As pages are edited, reorganized and removed, child pages might be left with no link to the rest of the book. Such pages are refered to as 'orphan pages'. On this page, administrators can review their books for orphans and reattach those pages as desired.");
break; break;
case 'node/add#book':
$output = t("A book is a collaborative writing effort: users can collaborate writing the pages of the book, positioning the pages in the right order, and reviewing or modifying pages previously written. So when you have some information to share or when you read a page of the book and you didn't like it, or if you think a certain page could have been written better, you can do something about it.");
break;
} }
return $output; return $output;
......
...@@ -23,16 +23,16 @@ function forum_help($section = "admin/help#forum") { ...@@ -23,16 +23,16 @@ function forum_help($section = "admin/help#forum") {
case 'node/add/forum': case 'node/add/forum':
$output = variable_get('forum_help', ''); $output = variable_get('forum_help', '');
break; break;
case 'node/add#forum':
$output = t("A forum is a threaded discussion, enabling users to communicate about a particular topic.");
break;
} }
return $output; return $output;
} }
function forum_node($field) { function forum_node_name($node) {
$info["name"] = t("forum topic"); return t("forum topic");
$info["description"] = t("A forum is a threaded discussion, enabling users to communicate about a particular topic.");
return $info[$field];
} }
function forum_access($op, $node) { function forum_access($op, $node) {
......
...@@ -23,16 +23,16 @@ function forum_help($section = "admin/help#forum") { ...@@ -23,16 +23,16 @@ function forum_help($section = "admin/help#forum") {
case 'node/add/forum': case 'node/add/forum':
$output = variable_get('forum_help', ''); $output = variable_get('forum_help', '');
break; break;
case 'node/add#forum':
$output = t("A forum is a threaded discussion, enabling users to communicate about a particular topic.");
break;
} }
return $output; return $output;
} }
function forum_node($field) { function forum_node_name($node) {
$info["name"] = t("forum topic"); return t("forum topic");
$info["description"] = t("A forum is a threaded discussion, enabling users to communicate about a particular topic.");
return $info[$field];
} }
function forum_access($op, $node) { function forum_access($op, $node) {
......
...@@ -32,9 +32,9 @@ function node_help($section = "admin/help#node") { ...@@ -32,9 +32,9 @@ function node_help($section = "admin/help#node") {
<p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/system/modules/node"))); <p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/system/modules/node")));
if ($mod == "admin") { if ($mod == "admin") {
foreach (node_list() as $type => $module) { foreach (node_list() as $type) {
$output .= "<h3>". t("Node type: %module", array("%module" => module_invoke($module, "node", "name", $type))). "</h3>"; $output .= "<h3>". t("Node type: %module", array("%module" => node_invoke($type, "node_name"))). "</h3>";
$output .= module_invoke($module, "node", "description", $type); $output .= implode("\n", module_invoke_all("help", "node/add#". $type));
} }
} }
break; break;
...@@ -227,51 +227,50 @@ function node_teaser($body) { ...@@ -227,51 +227,50 @@ function node_teaser($body) {
*/ */
function node_get_module_name($node) { function node_get_module_name($node) {
if (is_array($node)) { if (is_array($node)) {
if ($pos = strpos($node["type"], ".")) { if ($pos = strpos($node["type"], "/")) {
return substr($node["type"], 0, $pos); return substr($node["type"], 0, $pos);
} else { } else {
return $node["type"]; return $node["type"];
} }
} }
else if (is_object($node)) { else if (is_object($node)) {
if ($pos = strpos($node->type, ".")) { if ($pos = strpos($node->type, "/")) {
return substr($node->type, 0, $pos); return substr($node->type, 0, $pos);
} else { } else {
return $node->type; return $node->type;
} }
} }
else if (is_string($node)) { else if (is_string($node)) {
if ($pos = strpos($node, ".")) { if ($pos = strpos($node, "/")) {
return substr($node, 0, $pos); return substr($node, 0, $pos);
} else { } else {
return $node; return $node;
} }
} }
} // node_get_module_name }
/* /*
* Get a list of all the defined node types. * Get a list of all the defined node types.
* *
* @return * @return
* An associative list in which the keys are node types and the values * An list of all node types.
* are the names of the modules that define them.
*/ */
function node_list() { function node_list() {
$types = array(); $types = array();
foreach (module_list() as $module) { foreach (module_list() as $module) {
if (module_hook($module, "node")) { if (module_hook($module, "node_name")) {
$module_types = module_invoke($module, "node", "types"); $module_types = module_invoke($module, "node_types");
if ($module_types) { if ($module_types) {
foreach ($module_types as $type) { foreach ($module_types as $type) {
$types[$type] = $module; $types[] = $type;
} }
} else { } else {
$types[$module] = $module; $types[] = $module;
} }
} }
} }
return $types; return $types;
} // node_list }
/* /*
* Determine whether a node hook exists. * Determine whether a node hook exists.
...@@ -724,7 +723,7 @@ function node_admin_nodes() { ...@@ -724,7 +723,7 @@ function node_admin_nodes() {
$header = array(NULL, t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); $header = array(NULL, t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$rows[] = array(form_checkbox(NULL, "status][$node->nid", 1, 0), l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke(node_get_module_name($node), "node", "name", $node->type), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); $rows[] = array(form_checkbox(NULL, "status][$node->nid", 1, 0), l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), node_invoke($node, "node_name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid"));
} }
if ($pager = theme("pager", NULL, 50, 0)) { if ($pager = theme("pager", NULL, 50, 0)) {
...@@ -762,19 +761,19 @@ function node_admin_settings($edit) { ...@@ -762,19 +761,19 @@ function node_admin_settings($edit) {
} }
$header = array_merge(array(t("type")), array_keys(node_invoke_nodeapi($node, "settings"))); $header = array_merge(array(t("type")), array_keys(node_invoke_nodeapi($node, "settings")));
foreach (node_list() as $type => $module) { foreach (node_list() as $type) {
$node->type = $type; $node->type = $type;
$cols = array(); $cols = array();
foreach (node_invoke_nodeapi($node, "settings") as $setting) { foreach (node_invoke_nodeapi($node, "settings") as $setting) {
$cols[] = array("data" => $setting, "align" => "center", "width" => 55); $cols[] = array("data" => $setting, "align" => "center", "width" => 55);
} }
$rows[] = array_merge(array(module_invoke($module, "node", "name", $type)), $cols); $rows[] = array_merge(array(node_invoke($node, "node_name")), $cols);
} }
$output .= theme("table", $header, $rows); $output .= theme("table", $header, $rows);
/* This is an idea for the future. /* This is an idea for the future.
foreach (node_list() as $type => $module) { foreach (node_list() as $type) {
$node->type = $type; $node->type = $type;
// Create theme("table", ) data: // Create theme("table", ) data:
...@@ -784,7 +783,7 @@ function node_admin_settings($edit) { ...@@ -784,7 +783,7 @@ function node_admin_settings($edit) {
$cols[] = array("data" => $setting, "align" => "center", "width" => 75); $cols[] = array("data" => $setting, "align" => "center", "width" => 75);
} }
$output .= "<h2>". module_invoke($module, "node", "name", $type) ."</h2>"; $output .= "<h2>". node_invoke($node, "node_name") ."</h2>";
$output .= theme("table", $header, array($cols)); $output .= theme("table", $header, array($cols));
$output .= "<br /><br />"; $output .= "<br /><br />";
} }
...@@ -1278,11 +1277,11 @@ function node_add($type) { ...@@ -1278,11 +1277,11 @@ function node_add($type) {
** Compile a list with the different node types and their explanation: ** Compile a list with the different node types and their explanation:
*/ */
foreach (node_list() as $type => $module) { foreach (node_list() as $type) {
if (node_access("create", $type)) { if (node_access("create", $type)) {
$output .= "<li>"; $output .= "<li>";
$output .= " ". l(module_invoke($module, "node", "name", $type), "node/add/$type", array("title" => t("Add a new %s.", array("%s" => module_invoke($module, "node", "name", $type))))); $output .= " ". l(node_invoke($type, "node_name"), "node/add/$type", array("title" => t("Add a new %s.", array("%s" => node_invoke($type, "node_name")))));
$output .= " <div style=\"margin-left: 20px;\">". module_invoke($module, "node", "description", $type) ."</div>"; $output .= " <div style=\"margin-left: 20px;\">". implode("\n", module_invoke_all("help", "node/add#". $type)) ."</div>";
$output .= "</li>"; $output .= "</li>";
} }
} }
...@@ -1373,7 +1372,7 @@ function node_preview($node, $error = NULL) { ...@@ -1373,7 +1372,7 @@ function node_preview($node, $error = NULL) {
$output .= node_form($node, $error); $output .= node_form($node, $error);
$name = module_invoke($node->type, "node", "name"); $name = node_invoke($node, "node_name");
drupal_set_breadcrumb(array(l(t("Home"), NULL), l(t("create content"), "node/add"), l(t("Submit %name", array("%name" => $name)), "node/add/$node->type"))); drupal_set_breadcrumb(array(l(t("Home"), NULL), l(t("create content"), "node/add"), l(t("Submit %name", array("%name" => $name)), "node/add/$node->type")));
return $output; return $output;
...@@ -1411,7 +1410,7 @@ function node_submit($node) { ...@@ -1411,7 +1410,7 @@ function node_submit($node) {
if (node_access("update", $node)) { if (node_access("update", $node)) {
$node->nid = node_save($node); $node->nid = node_save($node);
watchdog("special", "$node->type: updated '$node->title'", l(t("view post"), "node/view/$node->nid")); watchdog("special", "$node->type: updated '$node->title'", l(t("view post"), "node/view/$node->nid"));
$msg = t("the %name was updated.", array ("%name" => module_invoke(node_get_module_name($node), "node", "name", $node->type))); $msg = t("the %name was updated.", array ("%name" => node_invoke($node, "node_name")));
} }
} }
else { else {
...@@ -1432,7 +1431,7 @@ function node_submit($node) { ...@@ -1432,7 +1431,7 @@ function node_submit($node) {
$node->nid = node_save($node); $node->nid = node_save($node);
watchdog("special", "$node->type: added '$node->title'", l(t("view post"), "node/view/$node->nid")); watchdog("special", "$node->type: added '$node->title'", l(t("view post"), "node/view/$node->nid"));
$msg = t("your %name was created.", array ("%name" => module_invoke($node->type, "node", "name"))); $msg = t("your %name was created.", array ("%name" => node_invoke($node, "node_name")));
} }
} }
...@@ -1486,8 +1485,6 @@ function node_delete($edit) { ...@@ -1486,8 +1485,6 @@ function node_delete($edit) {
} }
function node_page() { function node_page() {
global $id, $user, $or, $and;
$op = $_POST["op"]; $op = $_POST["op"];
$edit = $_POST["edit"]; $edit = $_POST["edit"];
...@@ -1505,11 +1502,17 @@ function node_page() { ...@@ -1505,11 +1502,17 @@ function node_page() {
$node = node_load(array("nid" => arg(2), "status" => 1), $_GET["revision"]); $node = node_load(array("nid" => arg(2), "status" => 1), $_GET["revision"]);
} }
$name = module_invoke(node_get_module_name(arg(2)), "node", "name", arg(2)); if ($op == "add" && arg(3)) {
$type = arg(2) . "/" . arg(3);
}
else {
$type = arg(2);
}
$name = node_invoke($type, "node_name");
switch ($op) { switch ($op) {
case "add": case "add":
print theme("page", node_add(arg(2)), arg(2) ? t("Submit %name", array("%name" => $name)) : t("create content")); print theme("page", node_add($type), arg(2) ? t("Submit %name", array("%name" => $name)) : t("create content"));
break; break;
case "edit": case "edit":
print theme("page", node_edit(arg(2)), t("Edit %name", array("%name" => $name))); print theme("page", node_edit(arg(2)), t("Edit %name", array("%name" => $name)));
......
...@@ -32,9 +32,9 @@ function node_help($section = "admin/help#node") { ...@@ -32,9 +32,9 @@ function node_help($section = "admin/help#node") {
<p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/system/modules/node"))); <p>Now that you know what is in a node, here are some of the types of nodes available.</p>", array("%teaser" => url("admin/system/modules/node")));
if ($mod == "admin") { if ($mod == "admin") {
foreach (node_list() as $type => $module) { foreach (node_list() as $type) {
$output .= "<h3>". t("Node type: %module", array("%module" => module_invoke($module, "node", "name", $type))). "</h3>"; $output .= "<h3>". t("Node type: %module", array("%module" => node_invoke($type, "node_name"))). "</h3>";
$output .= module_invoke($module, "node", "description", $type); $output .= implode("\n", module_invoke_all("help", "node/add#". $type));
} }
} }
break; break;
...@@ -227,51 +227,50 @@ function node_teaser($body) { ...@@ -227,51 +227,50 @@ function node_teaser($body) {
*/ */
function node_get_module_name($node) { function node_get_module_name($node) {
if (is_array($node)) { if (is_array($node)) {
if ($pos = strpos($node["type"], ".")) { if ($pos = strpos($node["type"], "/")) {
return substr($node["type"], 0, $pos); return substr($node["type"], 0, $pos);
} else { } else {
return $node["type"]; return $node["type"];
} }
} }
else if (is_object($node)) { else if (is_object($node)) {
if ($pos = strpos($node->type, ".")) { if ($pos = strpos($node->type, "/")) {
return substr($node->type, 0, $pos); return substr($node->type, 0, $pos);
} else { } else {
return $node->type; return $node->type;
} }
} }
else if (is_string($node)) { else if (is_string($node)) {
if ($pos = strpos($node, ".")) { if ($pos = strpos($node, "/")) {
return substr($node, 0, $pos); return substr($node, 0, $pos);
} else { } else {
return $node; return $node;
} }
} }
} // node_get_module_name }
/* /*
* Get a list of all the defined node types. * Get a list of all the defined node types.
* *
* @return * @return
* An associative list in which the keys are node types and the values * An list of all node types.
* are the names of the modules that define them.
*/ */
function node_list() { function node_list() {
$types = array(); $types = array();
foreach (module_list() as $module) { foreach (module_list() as $module) {
if (module_hook($module, "node")) { if (module_hook($module, "node_name")) {
$module_types = module_invoke($module, "node", "types"); $module_types = module_invoke($module, "node_types");
if ($module_types) { if ($module_types) {
foreach ($module_types as $type) { foreach ($module_types as $type) {
$types[$type] = $module; $types[] = $type;
} }
} else { } else {
$types[$module] = $module; $types[] = $module;
} }
} }
} }
return $types; return $types;
} // node_list }
/* /*
* Determine whether a node hook exists. * Determine whether a node hook exists.
...@@ -724,7 +723,7 @@ function node_admin_nodes() { ...@@ -724,7 +723,7 @@ function node_admin_nodes() {
$header = array(NULL, t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); $header = array(NULL, t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2));
while ($node = db_fetch_object($result)) { while ($node = db_fetch_object($result)) {
$rows[] = array(form_checkbox(NULL, "status][$node->nid", 1, 0), l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), module_invoke(node_get_module_name($node), "node", "name", $node->type), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid")); $rows[] = array(form_checkbox(NULL, "status][$node->nid", 1, 0), l($node->title, "node/view/$node->nid") ." ". (node_is_new($node->nid, $node->changed) ? theme_mark() : ""), node_invoke($node, "node_name"), format_name($node), ($node->status ? t("published") : t("not published")), l(t("edit node"), "admin/node/edit/$node->nid"), l(t("delete node"), "admin/node/delete/$node->nid"));
} }
if ($pager = theme("pager", NULL, 50, 0)) { if ($pager = theme("pager", NULL, 50, 0)) {
...@@ -762,19 +761,19 @@ function node_admin_settings($edit) { ...@@ -762,19 +761,19 @@ function node_admin_settings($edit) {
} }