? NodeRendering.kpf ? node_render.patch ? sites/node Index: includes/common.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/common.inc,v retrieving revision 1.627 diff -u -p -r1.627 common.inc --- includes/common.inc 6 Apr 2007 13:27:20 -0000 1.627 +++ includes/common.inc 13 Apr 2007 14:02:31 -0000 @@ -2186,10 +2186,13 @@ function drupal_alter($type, &$data) { * * @param $elements * The structured array describing the data to be rendered. + * @param $force + * A boolean indicating that the content should be output even if it's + * been rendered already. * @return * The rendered HTML. */ -function drupal_render(&$elements) { +function drupal_render(&$elements, $force = FALSE) { if (!isset($elements) || (isset($elements['#access']) && !$elements['#access'])) { return NULL; } @@ -2239,7 +2242,7 @@ function drupal_render(&$elements) { } // Until now, we rendered the children, here we render the element itself - if (!isset($elements['#printed'])) { + if (!isset($elements['#printed']) || $force) { $content = theme(!empty($elements['#type']) ? $elements['#type'] : 'markup', $elements); $elements['#printed'] = TRUE; } Index: includes/theme.inc =================================================================== RCS file: /cvs/drupal/drupal/includes/theme.inc,v retrieving revision 1.347 diff -u -p -r1.347 theme.inc --- includes/theme.inc 9 Apr 2007 13:43:57 -0000 1.347 +++ includes/theme.inc 13 Apr 2007 14:02:31 -0000 @@ -975,39 +975,25 @@ function theme_help() { * A string containing the node output. */ function theme_node($node, $teaser = FALSE, $page = FALSE) { - if (!$node->status) { - $output = '
'; - } - - if (module_exists('taxonomy')) { - $terms = taxonomy_link('taxonomy terms', $node); - } - - if ($page == 0) { - $output .= t('!title by !name', array('!title' => '

'. check_plain($node->title) .'

', '!name' => theme('username', $node))); + if (!$node['#status']) { + $output .= '
'; } else { - $output .= t('by !name', array('!name' => theme('username', $node))); + $output .= '
'; } - if (count($terms)) { - $output .= ' ('. theme('links', $terms) .')
'; - } - - if ($teaser && $node->teaser) { - $output .= $node->teaser; - } - else { - $output .= $node->body; + if ($page == FALSE) { + if (!empty($node['#title'])) { + $output .= t('!title by !name', array('!title' => '

'. check_plain($node['#title']) .'

', '!name' => theme('username', $node['#node']))); + } + else { + $output .= t('by !name', array('!name' => theme('username', $node['#node']))); + } } - if ($node->links) { - $output .= ''; - } + $output .= empty($node['#children']) ? '' : $node['#children']; - if (!$node->status) { - $output .= '
'; - } + $output .= "\n
\n"; return $output; } Index: modules/comment/comment.module =================================================================== RCS file: /cvs/drupal/drupal/modules/comment/comment.module,v retrieving revision 1.537 diff -u -p -r1.537 comment.module --- modules/comment/comment.module 9 Apr 2007 13:41:10 -0000 1.537 +++ modules/comment/comment.module 13 Apr 2007 14:02:32 -0000 @@ -344,9 +344,8 @@ function theme_comment_block() { */ function comment_link($type, $node = NULL, $teaser = FALSE) { $links = array(); - - if ($type == 'node' && $node->comment) { - + if ($type == 'node' && $node['#node']->comment) { + $node = $node['#node']; if ($teaser) { // Main page: display the number of comments that have been posted. @@ -398,7 +397,7 @@ function comment_link($type, $node = NUL if (variable_get('comment_form_location', COMMENT_FORM_SEPARATE_PAGE) == COMMENT_FORM_SEPARATE_PAGE) { $links['comment_add'] = array( 'title' => t('Add new comment'), - 'href' => "comment/reply/$node->nid", + 'href' => "comment/reply/". $node->nid, 'attributes' => array('title' => t('Share your thoughts and opinions related to this posting.')), 'fragment' => 'comment-form' ); @@ -499,6 +498,14 @@ function comment_nodeapi(&$node, $op, $a } } +function comment_node_alter(&$node, $teaser = FALSE, $page = FALSE) { + if ($node['#node']->comment && $page) { + $node['comments'] = array( + '#value' => comment_render($node['#node']), + ); + } +} + /** * Implementation of hook_user(). */ Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.800 diff -u -p -r1.800 node.module --- modules/node/node.module 10 Apr 2007 12:11:42 -0000 1.800 +++ modules/node/node.module 13 Apr 2007 14:02:32 -0000 @@ -287,7 +287,7 @@ function node_get_types($op = 'types', $ if ($node) { if (is_array($node)) { - $type = $node['type']; + $type = isset($node['#content_type']) ? $node['#content_type'] : $node['type']; } elseif (is_object($node)) { $type = $node->type; @@ -475,8 +475,8 @@ function _node_type_set_defaults($info) * @return * TRUE iff the $hook exists in the node type of $node. */ -function node_hook(&$node, $hook) { - $module = node_get_types('module', $node); +function node_hook(&$node, $hook, $type = NULL) { + $module = isset($type) ? $type : node_get_types('module', $node); if ($module == 'node') { $module = 'node_content'; // Avoid function name collisions. } @@ -730,91 +730,94 @@ function node_save(&$node) { * An HTML representation of the themed node. */ function node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE) { - $node = (object)$node; - - $node = node_build_content($node, $teaser, $page); - - if ($links) { - $node->links = module_invoke_all('link', 'node', $node, !$page); - drupal_alter('link', $node->links, $node); - } - - // Set the proper node part, then unset unused $node part so that a bad - // theme can not open a security hole. - $content = drupal_render($node->content); - if ($teaser) { - $node->teaser = $content; - unset($node->body); - } - else { - $node->body = $content; - unset($node->teaser); - } - - // Allow modules to modify the fully-built node. - node_invoke_nodeapi($node, 'alter', $teaser, $page); - - return theme('node', $node, $teaser, $page); -} - -/** - * Apply filters and build the node's standard elements. - */ -function node_prepare($node, $teaser = FALSE) { - // First we'll overwrite the existing node teaser and body with - // the filtered copies! Then, we'll stick those into the content - // array and set the read more flag if appropriate. - $node->readmore = (strlen($node->teaser) < strlen($node->body)); - - if ($teaser == FALSE) { - $node->body = check_markup($node->body, $node->format, FALSE); - } - else { - $node->teaser = check_markup($node->teaser, $node->format, FALSE); - } - - $node->content['body'] = array( - '#value' => $teaser ? $node->teaser : $node->body, - '#weight' => 0, - ); - - return $node; + $node = node_build($node, $teaser, $page); + return drupal_render($node); } /** - * Builds a structured array representing the node's content. + * Generate a structured array for the node. * - * @param $node - * A node object. + * @param $incoming_node + * A node array or node object. * @param $teaser * Whether to display the teaser only, as on the main page. * @param $page * Whether the node is being displayed by itself as a page. + * @param $links + * Whether or not to display node links. Links are omitted for node previews. * * @return - * An structured array containing the individual elements - * of the node's body. + * A structured Drupal array containing all node data. */ -function node_build_content($node, $teaser = FALSE, $page = FALSE) { +function node_build($incoming_node, $teaser = FALSE, $page = FALSE, $links = TRUE) { + // First we'll set up the basics of the node array and populate + // it with the defaults. + $node = array( + '#type' => 'node', + '#content_type' => $incoming_node->type, + '#title' => check_plain($incoming_node->title), + '#node' => $incoming_node, + '#theme' => 'node', + 'content' => array(), + 'links' => array(), + ); + // Remove the delimiter (if any) that separates the teaser from the body. - $node->body = isset($node->body) ? str_replace('', '', $node->body) : ''; + $incoming_node->body = isset($incoming_node->body) ? str_replace('', '', $incoming_node->body) : ''; // The 'view' hook can be implemented to overwrite the default function // to display nodes. - if (node_hook($node, 'view')) { - $node = node_invoke($node, 'view', $teaser, $page); + if (node_hook($incoming_node, 'view', $incoming_node->type)) { + node_invoke($node, 'view', $teaser, $page); } else { - $node = node_prepare($node, $teaser); + node_prepare($node, $teaser); } - // Allow modules to make their own additions to the node. - node_invoke_nodeapi($node, 'view', $teaser, $page); + $node['submitted'] = array( + '#value' => t('Submitted by !a on @b.', array('!a' => theme('username', $incoming_node), '@b' => format_date($incoming_node->created))), + '#weight' => -20, + ); + + if ($links) { + $link_list = module_invoke_all('link', 'node', $node, !$page); + drupal_alter('link', $link_list, $incoming_node); + $node['links'] = array( + '#theme' => 'links_element', + '#value' => $link_list, + '#weight' => 50, + ); + } + + // We'll call drupal_alter, giving modules a chance to implement + // hook_node_alter(). It's the new alternative to nodeapi op view. + drupal_alter('node', $node, $teaser, $page); + return $node; } /** + * Apply filters and build the node's standard elements. + */ +function node_prepare(&$node, $teaser = FALSE) { + // The absolute basics of node formatting. + $content = ''; + if ($teaser) { + $content = check_markup($node['#node']->teaser, $node['#node']->format, FALSE); + } + else { + $content = check_markup($node['#node']->body, $node['#node']->format, FALSE); + } + + $node['content']['body'] = array( + '#value' => $content, + '#weight' => 0, + ); + $node['#readmore'] = (strlen($node['#node']->teaser) < strlen($node['#node']->body)); +} + +/** * Generate a page displaying a single node, along with its comments. */ function node_show($node, $cid) { @@ -972,15 +975,9 @@ function node_search($op = 'search', $ke foreach ($find as $item) { // Build the node body. $node = node_load($item->sid); - $node = node_build_content($node, FALSE, FALSE); - $node->body = drupal_render($node->content); - - // Fetch comments for snippet - $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index'); - // Fetch terms for snippet - $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index'); $extra = node_invoke_nodeapi($node, 'search result'); + $results[] = array('link' => url('node/'. $item->sid, array('absolute' => TRUE)), 'type' => node_get_types('name', $node), 'title' => $node->title, @@ -1101,7 +1098,7 @@ function node_link($type, $node = NULL, $links = array(); if ($type == 'node') { - if ($teaser == 1 && $node->teaser && $node->readmore) { + if ($teaser == 1 && !empty($node['#teaser']) && !empty($node['#readmore'])) { $links['node_read_more'] = array( 'title' => t('Read more'), 'href' => "node/$node->nid", Index: modules/poll/poll.module =================================================================== RCS file: /cvs/drupal/drupal/modules/poll/poll.module,v retrieving revision 1.226 diff -u -p -r1.226 poll.module --- modules/poll/poll.module 6 Apr 2007 13:27:22 -0000 1.226 +++ modules/poll/poll.module 13 Apr 2007 14:02:32 -0000 @@ -413,21 +413,22 @@ function theme_poll_view_voting($form) { */ function poll_view_results(&$node, $teaser, $page, $block) { // Count the votes and find the maximum + $node_object = $node['#node']; $total_votes = 0; $max_votes = 0; - foreach ($node->choice as $choice) { + foreach ($node_object->choice as $choice) { $total_votes += $choice['chvotes']; $max_votes = max($max_votes, $choice['chvotes']); } $poll_results = ''; - foreach ($node->choice as $i => $choice) { + foreach ($node_object->choice as $i => $choice) { if ($choice['chtext'] != '') { $poll_results .= theme('poll_bar', check_plain($choice['chtext']), round($choice['chvotes'] * 100 / max($total_votes, 1)), format_plural($choice['chvotes'], '1 vote', '@count votes'), $block); } } - return theme('poll_results', check_plain($node->title), $poll_results, $total_votes, isset($node->links) ? $node->links : array(), $block, $node->nid, isset($node->vote) ? $node->vote : NULL); + return theme('poll_results', check_plain($node_object->title), $poll_results, $total_votes, isset($node_object->links) ? $node->links : array(), $block, $node_object->nid, isset($node_object->vote) ? $node_object->vote : NULL); } function theme_poll_results($title, $results, $votes, $links, $block, $nid, $vote) { Index: themes/engines/phptemplate/phptemplate.engine =================================================================== RCS file: /cvs/drupal/drupal/themes/engines/phptemplate/phptemplate.engine,v retrieving revision 1.62 diff -u -p -r1.62 phptemplate.engine --- themes/engines/phptemplate/phptemplate.engine 6 Apr 2007 13:27:23 -0000 1.62 +++ themes/engines/phptemplate/phptemplate.engine 13 Apr 2007 14:02:32 -0000 @@ -246,30 +246,15 @@ function phptemplate_engine_variables_pa * into standard template files. */ function phptemplate_engine_variables_node(&$variables) { - $node = $variables['node']; - if (module_exists('taxonomy')) { - $variables['taxonomy'] = taxonomy_link('taxonomy terms', $node); - } - else { - $variables['taxonomy'] = array(); - } - - if ($variables['teaser'] && $node->teaser) { - $variables['content'] = $node->teaser; - } - elseif (isset($node->body)) { - $variables['content'] = $node->body; - } - else { - $variables['content'] = ''; - } + $node = $variables['node']['#node']; + $variables['title'] = check_plain($node->title); $variables['date'] = format_date($node->created); - $variables['links'] = !empty($node->links) ? theme('links', $node->links, array('class' => 'links inline')) : ''; $variables['name'] = theme('username', $node); $variables['node_url'] = url('node/'. $node->nid); - $variables['terms'] = theme('links', $variables['taxonomy'], array('class' => 'links inline')); - $variables['title'] = check_plain($node->title); + foreach(element_children($variables['node']) as $key) { + $variables[$key] = drupal_render($variables['node'][$key]); + } // Flatten the node object's member fields. $variables = array_merge((array)$node, $variables); @@ -283,8 +268,8 @@ function phptemplate_engine_variables_no $variables['submitted'] = ''; $variables['picture'] = ''; } - $variables['template_files'][] = 'node-'. $node->type; + $variables['node'] = $node; } /**