summaryrefslogtreecommitdiff
path: root/modules/node
diff options
context:
space:
mode:
Diffstat (limited to 'modules/node')
-rw-r--r--modules/node/node.api.php4
-rw-r--r--modules/node/node.module81
-rw-r--r--modules/node/node.pages.inc6
3 files changed, 63 insertions, 28 deletions
diff --git a/modules/node/node.api.php b/modules/node/node.api.php
index 68050065d..8b8343d2e 100644
--- a/modules/node/node.api.php
+++ b/modules/node/node.api.php
@@ -81,7 +81,7 @@ function hook_node_access_records($node) {
return;
}
- // We only care about the node if it's been marked private. If not, it is
+ // We only care about the node if it has been marked private. If not, it is
// treated just like any other node and we completely ignore it.
if ($node->private) {
$grants = array();
@@ -169,7 +169,7 @@ function hook_node_operations() {
* @return
* None.
*/
-function hook_nodeapi_alter($node, $teaser, $page) {
+function hook_nodeapi_alter($node, $teaser) {
}
/**
diff --git a/modules/node/node.module b/modules/node/node.module
index 3936359ad..3629e2209 100644
--- a/modules/node/node.module
+++ b/modules/node/node.module
@@ -96,7 +96,7 @@ function node_help($path, $arg) {
function node_theme() {
return array(
'node' => array(
- 'arguments' => array('node' => NULL, 'teaser' => FALSE, 'page' => FALSE),
+ 'arguments' => array('elements' => NULL),
'template' => 'node',
),
'node_list' => array(
@@ -1126,24 +1126,28 @@ function node_delete($nid) {
}
/**
- * Generate a display of the given node.
+ * Generate an array for rendering the given node.
*
* @param $node
* A node array or node object.
* @param $teaser
* Whether to display the teaser only or the full form.
- * @param $links
- * Whether or not to display node links. Links are omitted for node previews.
*
* @return
- * An HTML representation of the themed node.
+ * An array as expected by drupal_render().
*/
-function node_view($node, $teaser = FALSE) {
+function node_build($node, $teaser = FALSE) {
$node = (object)$node;
$node = node_build_content($node, $teaser);
- return theme('node', $node, $teaser);
+ $build = $node->content;
+ $build += array(
+ '#theme' => 'node',
+ '#node' => $node,
+ '#teaser' => $teaser,
+ );
+ return $build;
}
/**
@@ -1205,25 +1209,31 @@ function node_build_content($node, $teaser = FALSE) {
node_invoke_nodeapi($node, 'view', $teaser);
// Allow modules to modify the structured node.
- drupal_alter('node_view', $node, $teaser);
+ drupal_alter('node_build', $node, $teaser);
return $node;
}
/**
- * Generate a page displaying a single node.
+ * Generate an array which displays a node detail page.
+ *
+ * @param $node
+ * A node object.
+ * @param $message
+ * A flag which sets a page title relevant to the revision being viewed.
+ * @return
+ * A $page element suitable for use by drupal_page_render().
*/
function node_show($node, $message = FALSE) {
if ($message) {
drupal_set_title(t('Revision of %title from %date', array('%title' => $node->title, '%date' => format_date($node->revision_timestamp))), PASS_THROUGH);
}
- $output = node_view($node, FALSE, TRUE);
-
// Update the history table, stating that this user viewed this node.
node_tag_new($node->nid);
- return $output;
+ // For markup consistency with other pages, use node_build_multiple() rather than node_build().
+ return drupal_get_page(node_build_multiple(array($node), FALSE));
}
/**
@@ -1905,20 +1915,43 @@ function node_feed($nids = FALSE, $channel = array()) {
}
/**
+ * Construct a drupal_render() style array from an array of loaded nodes.
+ *
+ * @param $nodes
+ * An array of nodes as returned by node_load_multiple().
+ * @param $teaser
+ * Display nodes into teaser view or full view.
+ * @param $weight
+ * An integer representing the weight of the first node in the list.
+ * @return
+ * An array in the format expected by drupal_render().
+ */
+function node_build_multiple($nodes, $teaser = TRUE, $weight = 0) {
+ $build = array();
+ foreach ($nodes as $node) {
+ $build['nodes'][$node->nid] = node_build($node, $teaser);
+ $build['nodes'][$node->nid]['#weight'] = $weight;
+ $weight++;
+ }
+ $build['nodes']['#sorted'] = TRUE;
+ return $build;
+}
+
+/**
* Menu callback; Generate a listing of promoted nodes.
*/
function node_page_default() {
- $nids = pager_query(db_rewrite_sql('SELECT n.nid FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10))->fetchCol();
+ $nids = pager_query(db_rewrite_sql('SELECT n.nid, n.sticky, n.created FROM {node} n WHERE n.promote = 1 AND n.status = 1 ORDER BY n.sticky DESC, n.created DESC'), variable_get('default_nodes_main', 10))->fetchCol();
if (!empty($nids)) {
$nodes = node_load_multiple($nids);
- $output = '';
- foreach ($nodes as $node) {
- $output .= node_view($node, TRUE);
- }
+ $build = node_build_multiple($nodes);
$feed_url = url('rss.xml', array('absolute' => TRUE));
drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') . ' ' . t('RSS'));
- $output .= theme('pager', NULL, variable_get('default_nodes_main', 10));
+ $build['pager'] = array(
+ '#markup' => theme('pager', NULL, variable_get('default_nodes_main', 10)),
+ '#weight' => 5,
+ );
}
else {
$default_message = '<h1 class="title">' . t('Welcome to your new Drupal website!') . '</h1>';
@@ -1930,12 +1963,14 @@ function node_page_default() {
$default_message .= '<li>' . t('<strong>Start posting content</strong> Finally, you can <a href="@content">create content</a> for your website. This message will disappear once you have promoted a post to the front page.', array('@content' => url('node/add'))) . '</li>';
$default_message .= '</ol>';
$default_message .= '<p>' . t('For more information, please refer to the <a href="@help">help section</a>, or the <a href="@handbook">online Drupal handbooks</a>. You may also post at the <a href="@forum">Drupal forum</a>, or view the wide range of <a href="@support">other support options</a> available.', array('@help' => url('admin/help'), '@handbook' => 'http://drupal.org/handbooks', '@forum' => 'http://drupal.org/forum', '@support' => 'http://drupal.org/support')) . '</p>';
-
- $output = '<div id="first-time">' . $default_message . '</div>';
+ $build['default_message'] = array(
+ '#markup' => $default_message,
+ '#prefix' => '<div id="first-time">',
+ '#suffix' => '</div>',
+ );
}
drupal_set_title('');
-
- return $output;
+ return drupal_get_page($build);
}
/**
@@ -2969,7 +3004,7 @@ function node_unpublish_by_keyword_action_submit($form, $form_state) {
*/
function node_unpublish_by_keyword_action($node, $context) {
foreach ($context['keywords'] as $keyword) {
- if (strstr(node_view(clone $node), $keyword) || strstr($node->title, $keyword)) {
+ if (strstr(drupal_render(node_build(clone $node)), $keyword) || strstr($node->title, $keyword)) {
$node->status = 0;
watchdog('action', 'Set @type %title to unpublished.', array('@type' => node_get_types('name', $node), '%title' => $node->title));
break;
diff --git a/modules/node/node.pages.inc b/modules/node/node.pages.inc
index 28aff234a..a6e5d34bf 100644
--- a/modules/node/node.pages.inc
+++ b/modules/node/node.pages.inc
@@ -415,12 +415,12 @@ function theme_node_preview($node) {
if ($preview_trimmed_version) {
drupal_set_message(t('The trimmed version of your post shows what your post looks like when promoted to the main page or when exported for syndication.<span class="no-js"> You can insert the delimiter "&lt;!--break--&gt;" (without the quotes) to fine-tune where your post gets split.</span>'));
$output .= '<h3>' . t('Preview trimmed version') . '</h3>';
- $output .= node_view(clone $node, 1, FALSE);
+ $output .= drupal_render(node_build(clone $node, TRUE));
$output .= '<h3>' . t('Preview full version') . '</h3>';
- $output .= node_view($node, 0, FALSE);
+ $output .= drupal_render(node_build($node, FALSE));
}
else {
- $output .= node_view($node, 0, FALSE);
+ $output .= drupal_render(node_build($node, FALSE));
}
$output .= "</div>\n";