Index: modules/node/content_types.inc =================================================================== RCS file: /cvs/drupal/drupal/modules/node/content_types.inc,v retrieving revision 1.84 diff -u -r1.84 content_types.inc --- modules/node/content_types.inc 29 Jul 2009 06:39:34 -0000 1.84 +++ modules/node/content_types.inc 6 Aug 2009 07:37:01 -0000 @@ -16,7 +16,7 @@ $rows = array(); foreach ($names as $key => $name) { - $type = $types[$key]; + $type = $types[$key]; if (node_hook($type->type, 'form')) { $type_url_str = str_replace('_', '-', $type->type); $row = array(theme('node_admin_overview', $name, $type)); @@ -37,7 +37,7 @@ if (empty($rows)) { $rows[] = array(array('data' => t('No content types available. Add content type.', array('@link' => url('admin/structure/types/add'))), 'colspan' => '5', 'class' => 'message')); } - + $build['node_table'] = array( '#theme' => 'table', '#header' => $header, @@ -182,12 +182,23 @@ '#description' => t('Enable the submitted by Username on date text.'), ); $form['display']['teaser_length'] = array( - '#type' => 'select', + '#type' => 'select', '#title' => t('Length of trimmed posts'), '#default_value' => variable_get('teaser_length_' . $type->type, 600), '#options' => drupal_map_assoc(array(0, 200, 400, 600, 800, 1000, 1200, 1400, 1600, 1800, 2000), '_node_characters'), '#description' => t("The maximum number of characters used in the trimmed version of content.") ); + $form['display']['teaser_read_more_location'] = array( + '#type' => 'radios', + '#title' => t('Read more link'), + '#default_value' => variable_get('teaser_read_more_location_' . $type->type, 'inline'), + '#options' => array( + 'hidden' => t('Disabled'), + 'inline' => t('Display in node summary'), + 'link' => t('Display in links section'), + ), + '#description' => t('Determine the location of "read more" links which allow a user to click through to the full post from the trimmed post.'), + ); $form['old_type'] = array( '#type' => 'value', '#value' => $type->type, Index: modules/node/node.module =================================================================== RCS file: /cvs/drupal/drupal/modules/node/node.module,v retrieving revision 1.1090 diff -u -r1.1090 node.module --- modules/node/node.module 31 Jul 2009 19:01:02 -0000 1.1090 +++ modules/node/node.module 6 Aug 2009 07:37:03 -0000 @@ -106,6 +106,9 @@ 'node_admin_overview' => array( 'arguments' => array('name' => NULL, 'type' => NULL), ), + 'node_read_more' => array( + 'arguments' => array('link' => NULL, 'inline' => FALSE), + ), ); } @@ -1145,11 +1148,17 @@ // to know when a teaser view is different than a full view. $links = array(); if ($build_mode == 'teaser') { - $links['node_readmore'] = array( - 'title' => t('Read more'), - 'href' => 'node/' . $node->nid, - 'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title)) - ); + $read_more_location = variable_get('teaser_read_more_location_' . $node->type, 'inline'); + if ($read_more_location == 'link') { + $links['node_readmore'] = array( + 'title' => t('Read more'), + 'href' => 'node/' . $node->nid, + 'attributes' => array('rel' => 'tag', 'title' => strip_tags($node->title)) + ); + } + else if ($read_more_location == 'inline') { + $node->content['body']['items'][0]['#post_render'][] = 'node_teaser_add_read_more_link'; + } } $node->content['links']['node'] = array( '#theme' => 'links', @@ -1601,14 +1610,16 @@ $links = array(); if ($type == 'node') { - if ($build_mode == 'teaser') { - $links['node_read_more'] = array( - 'title' => t('Read more'), - 'href' => "node/$node->nid", - // The title attribute gets escaped when the links are processed, so - // there is no need to escape here. - 'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title))) - ); + if (variable_get('teaser_read_more_location_' . $node->type, 'inline') == 'link') { + if ($build_mode == 'teaser') { + $links['node_read_more'] = array( + 'title' => t('Read more'), + 'href' => "node/$node->nid", + // The title attribute gets escaped when the links are processed, so + // there is no need to escape here. + 'attributes' => array('title' => t('Read the rest of !title.', array('!title' => $node->title))) + ); + } } } @@ -3163,3 +3174,55 @@ ); return $requirements; } + +function theme_node_read_more($link, $inline = FALSE) { + $element = ($inline ? 'span' : 'div'); + return ' <'. $element .' class="read-more">' . $link . ''; +} + +function node_teaser_add_read_more_link($children, $elements) { + $summary = $children; + + if ($summary) { + // Define the tags that allow the read more link to be inserted right before their + // closing tag. If the summary ends with any other tag, the read more link will be + // appended at the end of the summary instead. + $inline_tags = array('p'); + + $htmlDom = DOMDocument::loadHTML($summary); + + // The result of DOMDocument::saveXML($bodyNode) is a partial (X)HTML document. + // We only need what is inside the body tag. + $bodyNode = $htmlDom->getElementsByTagName('body')->item(0); + + // Fetch the last element in the summary. + $node = $bodyNode->lastChild; + // Determine how to insert the read more link into the summary. Inline means the + // the link will be inserted before the ending tag of the last element in the summary, + // otherwise the link will be appended to the summary as a stand-alone element. + $inline = in_array($node->tagName, $inline_tags); + + // Create and theme the read more link. + $link = $htmlDom->createDocumentFragment(); + $link->appendXml(theme('node_read_more', l(t('Read more'), 'node/' . $elements['#object']->nid), $inline)); + + // Add the read more link to the summary. + if ($inline && $node) { + $node->appendChild($link); + } + else { + $bodyNode->appendChild($link); + } + + // DOM manipulation treats our fragment as a full document. Extract the contents of + // the element, as we are only interested in that. + if (preg_match("|^]*>(.*)$|s", $htmlDom->saveXML($bodyNode), $matches)) { + $summary = $matches[1]; + } + } + else { + $summary = theme('node_read_more', l(t('Read more'), 'node/' . $elements['#object']->nid), $inline); + } + + return $summary; +} \ No newline at end of file