Index: includes/simplenews.mail.inc
===================================================================
--- includes/simplenews.mail.inc (revision 301)
+++ includes/simplenews.mail.inc (working copy)
@@ -198,14 +198,15 @@
$message['body'],
$plain,
$message['headers'],
- $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
+ $message['text_alternative'],
isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
$message['id']
);
// Mimemail has changed its API (see http://drupal.org/node/808518) but we keep backward compatibility
if (is_array($mimemail_result)) {
$message = $mimemail_result;
- } else {
+ }
+ else {
$message['result'] = $mimemail_result;
}
}
Index: simplenews.module
===================================================================
--- simplenews.module (revision 301)
+++ simplenews.module (working copy)
@@ -355,8 +355,8 @@
}
}
- // Show newsletter sending options if newsletter has not been send yet.
- // If send a nodification is shown.
+ // Show newsletter sending options if newsletter has not been sent yet.
+ // If sent a nodification is shown.
if (!isset($simplenews_values['s_status']) || (isset($simplenews_values['s_status']) && $simplenews_values['s_status'] == SIMPLENEWS_STATUS_SEND_NOT)) {
$options[SIMPLENEWS_COMMAND_SEND_TEST] = t('Send one test newsletter to the test address');
$options[SIMPLENEWS_COMMAND_SEND_NOW] = t('Send newsletter');
@@ -788,12 +788,12 @@
}
// Simplenews newsletter node form
- elseif (isset($form['type']) && isset($form['#node']) && strpos($form_id, '_node_form')) {
+ if (isset($form['type']) && isset($form['#node']) && strpos($form_id, '_node_form')) {
if (in_array($form['type']['#value'], variable_get('simplenews_content_types', array('simplenews')))) {
// Available variables are based on user_mail_tokens().
// But uses only those which can be used with uid = 0 since simplenews also sends to anonymous users.
if (isset($form['body_field'])) {
- $form['body_field']['body']['#description'] = t("This will be the body of your newsletter. See 'Replacement patterns' for available variables.)");
+ $form['body_field']['body']['#description'] = t("This will be the body of your newsletter. See 'Replacement patterns' for available variables.");
}
$form['simplenews_subscription']['subscription_mail']['token_help'] = array(
'#title' => t('Replacement patterns'),
@@ -806,7 +806,7 @@
$form['simplenews_subscription']['subscription_mail']['token_help']['help'] = array(
'#value' => theme('token_help', 'simplenews'),
);
-
+
$vocabulary = taxonomy_vocabulary_load(variable_get('simplenews_vid', ''));
if (!empty($vocabulary) && !isset($vocabulary->nodes[$form['type']['#value']])) {
drupal_set_message(t('Invalid vocabulary setting detected. Check and save the Simplenews general settings.', array(
@@ -816,6 +816,26 @@
}
}
}
+
+ // add selector per node type for Plain Text field
+ if ($form_id == "node_type_form") {
+ if (!in_array($form['#node_type']->type, variable_get("simplenews_content_types", array()))) return;
+
+ $form['simplenews'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Simplenews'),
+ '#collapsed' => true,
+ );
+
+ $form['simplenews']['simplenews_plain_field'] = array(
+ '#type' => 'select',
+ '#title' => t('Custom field for plain text newsletter'),
+ '#options' => _simplenews_plain_field_options(),
+ '#description' => t('Choose a text field wich contains the custom plain text content of the newsletter. If no field is chosen, the plain text version of the newsletter
+ is automatically generated.'),
+ '#default_value' => variable_get('simplenews_plain_field_' . $form['#node_type']->type, 'none'),
+ );
+ }
}
/**
@@ -1713,7 +1733,7 @@
// $message buffer is node and language specific.
static $messages = array();
- // By default the the node is send which is supplied in the function call.
+ // By default the node is send which is supplied in the function call.
// When translation is used, the availability of translations is checked
// and when available the translation of the preferred language is selected.
$nid = $context['node']->nid;
@@ -1794,8 +1814,7 @@
node_invoke_nodeapi($node, 'alter', FALSE, TRUE);
unset($node->simplenews_mail);
- $body = theme(array('simplenews_newsletter_body__' . $context['node']->simplenews['tid'],
- 'simplenews_newsletter_body'), $node, $message['language']);
+ $body = theme(array('simplenews_newsletter_body__' . $context['node']->simplenews['tid'], 'simplenews_newsletter_body'), $node, $message['language']);
// Buffer body text node and language specific
$messages[$nid][$langcode]['body'] = $body;
@@ -1804,8 +1823,7 @@
// TODO: Unsubscribe links are broken if key=='test' && $context['snid']==0
// We might pass snid / context to theme functions.
// Build and buffer message footer
- $footer = theme(array('simplenews_newsletter_footer__' . $context['node']->simplenews['tid'],
- 'simplenews_newsletter_footer'), $context, $key, $message['language']);
+ $footer = theme(array('simplenews_newsletter_footer__' . $context['node']->simplenews['tid'], 'simplenews_newsletter_footer'), $context, $key, $message['language']);
$messages[$nid][$langcode]['footer'] = $footer;
}
@@ -1826,14 +1844,26 @@
// Build message body, replace tokens.
$body = token_replace($body, 'simplenews', $context);
// Convert to plain text if required.
- if ($context['node']->simplenews['s_format'] == 'plain') {
+ $field_plaintext = variable_get('simplenews_plain_field_' . $node->type, 'none');
+ if ($context['node']->simplenews['s_format'] == 'plain' && !trim($context['node']->{$field_plaintext}[0]['value'])) {
$body = simplenews_html_to_text($body, variable_get('simplenews_hyperlinks_' . $context['node']->simplenews['tid'], 1));
}
+ else if ($context['node']->simplenews['s_format'] == 'plain') {
+ $body = theme('simplenews_newsletter_text_alternative', $context['node'], $context['node']->simplenews['tid'], $field_plaintext);
+ }
+
$message['body']['body'] = $body;
// Build message footer, replace tokens.
$footer = token_replace($footer, 'simplenews', $context);
$message['body']['footer'] = $footer;
+
+ // Get alternative text field (i.e. plain text part to be added to multipart with mimemail
+ $plain_text = theme('simplenews_newsletter_text_alternative', $context['node'], $context['node']->simplenews['tid'], $field_plaintext);
+ $message['text_alternative'] = token_replace($plain_text, 'simplenews', $context);
+
+ // Add cleaned version of footer to text alternative
+ $message['text_alternative'] .= simplenews_html_to_text($footer);
// Add user specific header data.
$message ['headers']['List-Unsubscribe'] = '<' . token_replace('[simplenews-unsubscribe-url]', 'simplenews', $context) . '>';
@@ -2378,6 +2408,9 @@
'arguments' => array('name' => NULL, 'title' => NULL, 'language' => NULL),
'path' => $path . '/theme',
),
+ 'simplenews_newsletter_text_alternative' => array(
+ 'arguments' => array('node' => NULL, 'tid' => NULL, 'plain_field' => NULL),
+ ),
'simplenews_newsletter_body' => array(
'template' => 'simplenews-newsletter-body',
'arguments' => array('node' => NULL, 'language' => NULL),
@@ -2447,6 +2480,22 @@
}
/**
+* Theme the newsletter message subject and body.
+*/
+function theme_simplenews_newsletter_text_alternative($node, $tid, $plain_field) {
+ // In an override of this function, $text can be loaded with other field from the node.
+ $text = $node->title . "\n\n";
+ if ($plain_field == 'body') {
+ $text .= $node->body . "\n\n";
+ }
+ else {
+ $plain = $node->$plain_field;
+ $text .= $plain[0]['value'] . "\n\n";
+ }
+ return $text;
+}
+
+/**
* Process variables to format the simplenews newsletter footer.
*
* $variables are empty:
@@ -2522,3 +2571,22 @@
break;
}
}
+
+/**
+* Determine possible plain text field options.
+*
+* The CCK module must be installed to use CCK fields.
+*/
+function _simplenews_plain_field_options() {
+ $options = array('none' => t('none'));
+ $options['body'] = t('body');
+ if (module_exists('content')) {
+ $fields = content_fields();
+ foreach($fields as $field){
+ if ($field['type'] == 'text') {
+ $options[$field['field_name']] = $field['field_name'];
+ }
+ }
+ }
+ return $options;
+}
\ No newline at end of file