function ed_readmore_nodeapi in Read More Link (Drupal 6 and earlier) 6.5
Same name and namespace in other branches
- 5 ed_readmore.module \ed_readmore_nodeapi()
- 6.2 ed_readmore.module \ed_readmore_nodeapi()
- 6.3 ed_readmore.module \ed_readmore_nodeapi()
Implementation of hook_nodeapi().
File
- ./
ed_readmore.module, line 209 - Customize the "Read More" link shown in teasers.
Code
function ed_readmore_nodeapi(&$node, $op, $teaser = NULL, $page = NULL) {
switch ($op) {
case 'view':
$anchor = variable_get('ed_readmore_anchor', FALSE);
if ($teaser) {
/* Teaser */
$display = variable_get('ed_readmore_placement', ED_READMORE_PLACEMENT_DEFAULT);
// Don't do anything if placing the link is disabled.
if ($display == 'disable' || !$node->readmore) {
break;
}
// Is this an RSS feed?
if ($node->build_mode == NODE_BUILD_RSS) {
// If link replacement in RSS feeds is enabled, prevent core from
// adding a second link by setting the readmore flag to NULL.
if (variable_get('ed_readmore_rss', TRUE)) {
$node->readmore = NULL;
}
else {
break;
}
}
// Try to insert the link inline.
if ($display == 'inline') {
$elements_array = variable_get('ed_readmore_elements', array(
'p',
));
$elements = '(?:' . implode('|', $elements_array) . ')';
// Get last position of the last closing marker in teaser.
if (preg_match('!</?' . $elements . '[^>]*>\\s*$!i', $node->content['body']['#value'], $match, PREG_OFFSET_CAPTURE)) {
// Recalculate the position in $teaser. We do this because there may be extra CCK fields appended to the teaser.
$insert_point = strpos($teaser, $node->content['body']['#value']) + $match[0][1];
// Insert the link.
$node->content['body']['#value'] = substr_replace($node->content['body']['#value'], ed_readmore_link_render($node, $display, $anchor), $insert_point, 0);
}
else {
$display = 'after';
}
}
// Append the link to the end of the teaser.
if ($display == 'after') {
$node->content['read_more'] = array(
'#value' => ed_readmore_link_render($node, $display, $anchor),
'#weight' => 10,
);
}
}
else {
if ($anchor) {
/* Full node and anchoring is enabled */
$teaser_rendered = check_markup($node->teaser, $node->format, FALSE);
$node->content['body']['#value'] = substr_replace($node->content['body']['#value'], $teaser_rendered . "\n" . '<a name="more"></a>', 0, strlen($teaser_rendered));
}
}
break;
}
}