You are here

function simplenews_node_prepare in Simplenews 5

Prepare node for sending

2 calls to simplenews_node_prepare()
simplenews_send_test in ./simplenews.module
Send a test newsletter
_simplenews_send in ./simplenews.module
Send the newsletter

File

./simplenews.module, line 1162

Code

function simplenews_node_prepare($nid, $vid, $tid) {

  // node_load() sometimes returns empty nodes. The cause of this problem is yet unknown.
  if (!($node = node_load($nid, $vid, TRUE))) {
    return FALSE;
  }
  $node = simplenews_replace_vars($node, FALSE);

  // To play well with other modules that add content to the node,
  // simplenews_node_prepare() must mimic node_view() as far as possible.
  // Following is adapted from node_view().
  $node = node_build_content($node, FALSE, TRUE);
  $content = drupal_render($node->content);
  $node->body = $content;
  unset($node->teaser);
  node_invoke_nodeapi($node, 'alter', FALSE, TRUE);
  $node = theme('simplenews_newsletter', $node, $tid);

  // TODO: Probably should refactor the whole processing, but check here for
  // mimemail and don't mess with body if we're gonna pass it to mimemail().
  if ($node->s_format == 'plain' || !module_exists('mimemail')) {
    $node->body = simplenews_html_to_text($node->body, variable_get('simplenews_hyperlinks_' . $tid, 1));
  }
  simplenews_set_from($node, $tid);
  return $node;
}