You are here

function ed_readmore_link_render in Read More Link (Drupal 6 and earlier) 6.5

Prepares the link for theming and returns a rendered link.

XSS checking and other safety measures are performed here to prevent themers from omitting them.

1 call to ed_readmore_link_render()
ed_readmore_nodeapi in ./ed_readmore.module
Implementation of hook_nodeapi().

File

./ed_readmore.module, line 279
Customize the "Read More" link shown in teasers.

Code

function ed_readmore_link_render($node, $display, $anchor) {

  // Allowed tags borrowed largely from filter_xss_admin().
  // See http://api.drupal.org/api/function/filter_xss_admin
  $allowed_tags = array(
    'abbr',
    'acronym',
    'b',
    'big',
    'cite',
    'code',
    'del',
    'em',
    'font',
    'i',
    'img',
    'ins',
    'small',
    'span',
    'strong',
    'sub',
    'sup',
  );

  // Filter link text for cross-site scripting (XSS).
  // We sanitize the link text here despite it being passed to l() later on
  // because the theme function that calls l() might be changed to allow HTML.
  $link_text = variable_get('ed_readmore_text_prepend', ED_READMORE_TEXT_PREPEND_DEFAULT);
  $link_text .= t(variable_get('ed_readmore_text', ED_READMORE_TEXT_DEFAULT));
  $link_text .= variable_get('ed_readmore_text_append', ED_READMORE_TEXT_APPEND_DEFAULT);
  $link_text = filter_xss($link_text, $allowed_tags);

  // We don't need to run check_plain() here because it's passed to l(),
  // which handles this for us.
  $link_title = t(variable_get('ed_readmore_title', ''));

  // Mimic node.module's default link title.
  if (empty($link_title)) {
    $link_title = t('Read the rest of !title.', array(
      '!title' => $node->title,
    ));
  }

  // Replace tokens with values if the Token module and the token options are enabled.
  if (module_exists('token') && variable_get('ed_readmore_tokens', FALSE)) {
    $link_text = token_replace($link_text, 'node', $node);
    $link_title = token_replace($link_title, 'node', $node);
  }

  // Build link options array.
  $link_options = array(
    'attributes' => array(
      'title' => $link_title,
    ),
    'html' => TRUE,
  );

  // Add anchor to link if the option is enabled.
  if ($anchor) {
    $link_options['fragment'] = 'more';
  }

  // Add rel="nofollow" to link if the option is enabled.
  if (variable_get('ed_readmore_nofollow', TRUE)) {
    $link_options['attributes']['rel'] = 'nofollow';
  }

  // Add target="blank" to link if the option is enabled.
  if (variable_get('ed_readmore_newwindow', FALSE)) {
    $link_options['attributes']['target'] = '_blank';
  }

  // Send prepared data to the theme function.
  return theme('ed_readmore_link', $node, $link_text, $link_options, $display);
}