From b85eb11e113396490720572d11d30cd83c772ba1 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Fri, 23 Jan 2004 18:42:43 +0000 Subject: Patch 5287 by Stefan: multiline help texts should become inside a single $output. --- modules/node/node.module | 209 +++++++++++++++++++++++++++++------------------ 1 file changed, 129 insertions(+), 80 deletions(-) (limited to 'modules/node/node.module') diff --git a/modules/node/node.module b/modules/node/node.module index 61ee57c88..7b0bd1cb0 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -8,36 +8,33 @@ function node_help($section = "admin/help#node") { switch ($section) { case 'admin/help#node': - $output .= "

Nodes

"; - $output .= "

The core of the Drupal system is the node. All of the contents of the system are placed in nodes, or extensions of nodes."; - $output .= "A base node contains:

"; - $output .= "
A Title
Up to 128 characters of text that titles the node.
"; - $output .= "
A Teaser
A small block of text that is meant to get you interested in the rest of node. Drupal will automatically pull a small amount of the body of the node to make the teaser (To configure how long the teaser will be click here). The teaser can be changed if you don't like what Drupal grabs.
"; - $output .= "
The Body
The main text that comprises your content.
"; - $output .= "
A Type
What kind of node is this? Blog, book, forum, comment, unextended, etc.
"; - $output .= "
An Author
The author's name. It will either be \"anonymous\" or a valid user. You cannot set it to an arbitrary value.
"; - $output .= "
Authored on
The date the node was written.
"; - $output .= "
Changed
The last time this node was changed.
"; - $output .= "
Static on front page
The front page is configured to show the teasers from only a few of the total nodes you have on your site (To configure how many teasers click here), but if you think a node is important enough that you want it to stay on the front page enable this.
"; - $output .= "
Allow user comments
A node can have comments. These comments can be written by other users (Read-write), or only by admins (Read-only).
"; - $output .= "
Attributes
A way to sort nodes.
"; - $output .= "
Revisions
Drupal has a revision system so that you can \"roll back\" to an older version of a post if the new version is not what you want.
"; - $output .= "
Promote to front page
To get people to look at the new stuff on your site you can choose to move it to the front page.
"; - $output .= "
In moderation queue
Drupal has a moderation system. If it is active, a node is in one of three states: approved and published, approved and unpublished, and awaiting approval. If you are moderating a node it should be in the moderation queue.
"; - $output .= "
Votes
If you are moderating a node this counts how many votes the node has gotten. Once a node gets a certain number of vote it will either be approved or dropped."; - $output .= "
Score
The score of the node is gotten by the votes it is given.
"; - $output .= "
Users
The list of users who have voted on a moderated node.
"; - $output .= "
Published
When using Drupal's moderation system a node remains unpublished -- unavaliable to non-moderators -- until it is marked Published.
"; - $output .= "

Now that you know what is in a node, here are some of the types of nodes available.

"; - - $output = t($output, array("%teaser" => url("admin/system/modules/node"))); + $output .= t(" +

Nodes

+

The core of the Drupal system is the node. All of the contents of the system are placed in nodes, or extensions of nodes. + A base node contains:

+
A Title
Up to 128 characters of text that titles the node.
+
A Teaser
A small block of text that is meant to get you interested in the rest of node. Drupal will automatically pull a small amount of the body of the node to make the teaser (To configure how long the teaser will be click here). The teaser can be changed if you don't like what Drupal grabs.
+
The Body
The main text that comprises your content.
+
A Type
What kind of node is this? Blog, book, forum, comment, unextended, etc.
+
An Author
The author's name. It will either be \"anonymous\" or a valid user. You cannot set it to an arbitrary value.
+
Authored on
The date the node was written.
+
Changed
The last time this node was changed.
+
Static on front page
The front page is configured to show the teasers from only a few of the total nodes you have on your site (To configure how many teasers click here), but if you think a node is important enough that you want it to stay on the front page enable this.
+
Allow user comments
A node can have comments. These comments can be written by other users (Read-write), or only by admins (Read-only).
+
Attributes
A way to sort nodes.
+
Revisions
Drupal has a revision system so that you can \"roll back\" to an older version of a post if the new version is not what you want.
+
Promote to front page
To get people to look at the new stuff on your site you can choose to move it to the front page.
+
In moderation queue
Drupal has a moderation system. If it is active, a node is in one of three states: approved and published, approved and unpublished, and awaiting approval. If you are moderating a node it should be in the moderation queue.
+
Votes
If you are moderating a node this counts how many votes the node has gotten. Once a node gets a certain number of vote it will either be approved or dropped. +
Score
The score of the node is gotten by the votes it is given.
+
Users
The list of users who have voted on a moderated node.
+
Published
When using Drupal's moderation system a node remains unpublished -- unavaliable to non-moderators -- until it is marked Published.
+

Now that you know what is in a node, here are some of the types of nodes available.

", array("%teaser" => url("admin/system/modules/node"))); if ($mod == "admin") { - foreach (module_list() as $name) { - if (module_hook($name, "node") && $name != "node") { - $output .= "

". t("Node type: %module", array("%module" => module_invoke($name, "node", "name"))) ."

"; - $output .= module_invoke($name, "node", "description"); - } + foreach (node_list() as $type => $module) { + $output .= "

". t("Node type: %module", array("%module" => module_invoke($module, "node", "name", $type))). "

"; + $output .= module_invoke($module, "node", "description", $type); } } break; @@ -219,16 +216,93 @@ function node_teaser($body) { return substr($body, 0, $size); } -function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { + +/* + * Determines the module that defines the node type of the given node. + * + * @param &$node + * Either a node object, node array, or a string containing the node type. + * @return + * A string containing the name of the defining module. + */ +function node_get_module_name($node) { if (is_array($node)) { - $function = $node["type"] ."_$hook"; + if ($pos = strpos($node["type"], ".")) { + return substr($node["type"], 0, $pos); + } else { + return $node["type"]; + } } else if (is_object($node)) { - $function = $node->type ."_$hook"; + if ($pos = strpos($node->type, ".")) { + return substr($node->type, 0, $pos); + } else { + return $node->type; + } } else if (is_string($node)) { - $function = $node ."_$hook"; + if ($pos = strpos($node, ".")) { + return substr($node, 0, $pos); + } else { + return $node; + } } +} // node_get_module_name + +/* + * Get a list of all the defined node types. + * + * @return + * An associative list in which the keys are node types and the values + * are the names of the modules that define them. + */ +function node_list() { + $types = array(); + foreach (module_list() as $module) { + if (module_hook($module, "node")) { + $module_types = module_invoke($module, "node", "types"); + if ($module_types) { + foreach ($module_types as $type) { + $types[$type] = $module; + } + } else { + $types[$module] = $module; + } + } + } + return $types; +} // node_list + +/* + * Determine whether a node hook exists. + * + * @param &$node + * Either a node object, node array, or a string containing the node type. + * @param $hook + * A string containing the name of the hook. + * @return + * TRUE iff the $hook exists in the node type of $node. + */ +function node_hook(&$node, $hook) { + $function = node_get_module_name($node) ."_$hook"; + + return function_exists($function); +} + +/* + * Invoke a node hook. + * + * @param &$node + * Either a node object, node array, or a string containing the node type. + * @param $hook + * A string containing the name of the hook. + * @param $a2, $a3, $a4 + * Arguments to pass on to the hook, after the $node argument. + * @return + * The returned value of the invoked hook is returned. + */ +function node_invoke(&$node, $hook, $a2 = NULL, $a3 = NULL, $a4 = NULL) { + $function = node_get_module_name($node) ."_$hook"; if (function_exists($function)) { return ($function($node, $a2, $a3, $a4)); @@ -403,7 +477,7 @@ function node_view($node, $main = 0, $page = 0) { ** to display nodes. */ - if (module_hook($node->type, "view")) { + if (node_hook($node, "view")) { return node_invoke($node, "view", $main, $page); } else { @@ -461,20 +535,9 @@ function node_access($op, $node = 0) { $node = array2object($node); - /* - ** Construct a function: - */ - - if ($node->type) { - $type = $node->type; - } - else { - $type = $node; - } - // Can't use node_invoke: // the access hook takes the $op parameter before the $node parameter. - return module_invoke($type, "access", $op, $node); + return module_invoke(node_get_module_name($node), "access", $op, $node); } function node_perm() { @@ -661,7 +724,7 @@ function node_admin_nodes() { $header = array(NULL, t("title"), t("type"), t("author"), t("status"), array("data" => t("operations"), "colspan" => 2)); 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->type, "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")); + $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")); } if ($pager = theme("pager", NULL, 50, 0)) { @@ -699,23 +762,20 @@ function node_admin_settings($edit) { } $header = array_merge(array(t("type")), array_keys(node_invoke_nodeapi($node, "settings"))); - foreach (module_list() as $name) { - if (module_hook($name, "node")) { - $node->type = $name; - $cols = array(); - foreach (node_invoke_nodeapi($node, "settings") as $setting) { - $cols[] = array("data" => $setting, "align" => "center", "width" => 55); - } - $rows[] = array_merge(array(module_invoke($name, "node", "name")), $cols); + foreach (node_list() as $type => $module) { + $node->type = $type; + $cols = array(); + foreach (node_invoke_nodeapi($node, "settings") as $setting) { + $cols[] = array("data" => $setting, "align" => "center", "width" => 55); } + $rows[] = array_merge(array(module_invoke($module, "node", "name", $type)), $cols); } $output .= theme("table", $header, $rows); /* This is an idea for the future. - foreach (module_list() as $name) { - if (module_hook($name, "node")) { - $node->type = $name; + foreach (node_list() as $type => $module) { + $node->type = $type; // Create theme("table", ) data: $header = array_keys(node_invoke_nodeapi($node, "settings")); @@ -724,7 +784,7 @@ function node_admin_settings($edit) { $cols[] = array("data" => $setting, "align" => "center", "width" => 75); } - $output .= "

". module_invoke($name, "node", "name") ."

"; + $output .= "

". module_invoke($module, "node", "name", $type) ."

"; $output .= theme("table", $header, array($cols)); $output .= "

"; } @@ -1090,7 +1150,7 @@ function node_form($edit, $error = NULL) { // Can't use node_invoke: // $error and $param must be passed by reference. - $function = $edit->type ."_form"; + $function = node_get_module_name($edit) ."_form"; if (function_exists($function)) { $form .= $function($edit, $error, $param); } @@ -1218,11 +1278,11 @@ function node_add($type) { ** Compile a list with the different node types and their explanation: */ - foreach (module_list() as $name) { - if (module_hook($name, "node") && node_access("create", $name)) { + foreach (node_list() as $type => $module) { + if (node_access("create", $type)) { $output .= "
  • "; - $output .= " ". l(module_invoke($name, "node", "name"), "node/add/$name", array("title" => t("Add a new %s.", array("%s" => module_invoke($name, "node", "name"))))); - $output .= "
    ". module_invoke($name, "node", "description") ."
    "; + $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 .= "
    ". module_invoke($module, "node", "description", $type) ."
    "; $output .= "
  • "; } } @@ -1296,30 +1356,19 @@ function node_preview($node, $error = NULL) { $node->teaser = node_teaser($node->body); - /* - ** Apply the required filters: - */ - - if ($node->nid) { - $view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "update", $node))); - } - else { - $view = array2object(array_merge(object2array($node), module_invoke($node->type, "save", "create", $node))); - } - /* ** Display a preview of the node: */ - if ($view->teaser && $view->teaser != $view->body) { + if ($node->teaser && $node->teaser != $node->body) { $output = "

    ". t("Preview trimmed version") ."

    "; - $output .= node_view($view, 1); + $output .= node_view($node, 1); $output .= "

    ". t("The trimmed version of your post shows how your post looks like when promoted to the main page or when exported for syndication. You can insert a delimiter '<!--break-->' (without the quotes) to fine-tune where your post gets split.") ."

    "; $output .= "

    ". t("Preview full version") ."

    "; - $output .= node_view($view, 0); + $output .= node_view($node, 0); } else { - $output .= node_view($view, 0); + $output .= node_view($node, 0); } $output .= node_form($node, $error); @@ -1362,7 +1411,7 @@ function node_submit($node) { if (node_access("update", $node)) { $node->nid = node_save($node); 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->type, "node", "name"))); + $msg = t("the %name was updated.", array ("%name" => module_invoke(node_get_module_name($node), "node", "name", $node->type))); } } else { @@ -1456,7 +1505,7 @@ function node_page() { $node = node_load(array("nid" => arg(2), "status" => 1), $_GET["revision"]); } - $name = module_invoke(arg(2), "node", "name"); + $name = module_invoke(node_get_module_name(arg(2)), "node", "name", arg(2)); switch ($op) { case "add": -- cgit v1.2.3