--- simplenews.admin.inc Mon Jan 19 23:26:36 1970 +++ simplenews.admin.inc Mon Jan 19 23:26:36 1970 @@ -917,6 +917,13 @@ '#description' => $description, '#default_value' => variable_get('simplenews_format', 'plain'), ); + $form['simplenews_default_options']['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', 'none'), + ); $form['simplenews_default_options']['simplenews_priority'] = array( '#type' => 'select', '#title' => t('Priority'), --- simplenews.install Mon Jan 19 23:26:36 1970 +++ simplenews.install Mon Jan 19 23:26:36 1970 @@ -115,6 +115,13 @@ 'not null' => TRUE, 'default' => '', ), + 'plain_field' => array( + 'description' => 'Custom field for plain text newsletter.', + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), 'priority' => array( 'description' => 'Email priority according to RFC 2156 and RFC 5231 (0 = none; 1 = highest; 2 = high; 3 = normal; 4 = low; 5 = lowest).', 'type' => 'int', @@ -697,6 +704,15 @@ $vocabulary['required'] = TRUE; taxonomy_save_vocabulary($vocabulary); return array(); +} + +/** + * Add plain_field to simplenews_newsletter table. + */ +function simplenews_update_6009() { + $ret = array(); + db_add_field($ret, 'simplenews_newsletters', 'plain_field', array('type' => 'varchar', 'length' => 32, 'not null' => TRUE, 'default' => '')); + return $ret; } --- simplenews.mail.inc Mon Jan 19 23:26:36 1970 +++ simplenews.mail.inc Mon Jan 19 23:26:36 1970 @@ -199,7 +199,8 @@ $message['body'], $plain, $message['headers'], - $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE), + #$plain ? $message['body'] : $message['text_alternative'], + $message['text_alternative'], isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(), $message['id'] ); --- simplenews.module Mon Jan 19 23:26:36 1970 +++ simplenews.module Mon Jan 19 23:26:36 1970 @@ -406,13 +406,14 @@ $s_status = $send_with_permission ? SIMPLENEWS_STATUS_SEND_PENDING : SIMPLENEWS_STATUS_SEND_NOT; db_query(" INSERT INTO {simplenews_newsletters} - (nid, vid, tid, s_status, s_format, priority, receipt) - VALUES (%d, %d, %d, %d, '%s', %d, %d)", + (nid, vid, tid, s_status, s_format, plain_field, priority, receipt) + VALUES (%d, %d, %d, %d, '%s', '%s', %d, %d)", $node->nid, $node->vid, $node->simplenews['tid'], $s_status, $node->simplenews['s_format'], + $node->simplenews['plain_field'], $node->simplenews['priority'], $node->simplenews['receipt']); } @@ -425,6 +426,7 @@ tid = %d, s_status = %d, s_format = '%s', + plain_field = '%s', priority = %d, receipt = %d WHERE nid = %d", @@ -432,7 +434,8 @@ $node->simplenews['tid'], SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], - $node->simplenews['priority'], + $node->simplenews['plain_field'], + $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid); } @@ -441,12 +444,14 @@ UPDATE {simplenews_newsletters} SET tid = %d, s_format = '%s', + plain_field = '%s', priority = %d, receipt = %d WHERE nid = %d", $node->simplenews['tid'], $node->simplenews['s_format'], - $node->simplenews['priority'], + $node->simplenews['plain_field'], + $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid); } @@ -462,12 +467,14 @@ UPDATE {simplenews_newsletters} SET s_status = %d, s_format = '%s', + plain_field = '%s', priority = %d, receipt = %d WHERE nid = %d", SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], - $node->simplenews['priority'], + $node->simplenews['plain_field'], + $node->simplenews['priority'], $node->simplenews['receipt'], $translation->nid); } @@ -686,6 +693,11 @@ '#type' => 'hidden', '#value' => variable_get('simplenews_format', 'plain'), ); + $form['simplenews']['advanced']['plain_field'] = array( + '#type' => 'hidden', + '#value' => variable_get('simplenews_plain_field', 'none'), + ); + $form['simplenews']['advanced']['priority'] = array( '#type' => 'hidden', '#value' => variable_get('simplenews_priority', SIMPLENEWS_PRIORITY_NONE), @@ -697,7 +709,7 @@ } else { // Show newsletter sending options if newsletter has not been send yet. - // If send a nodification is shown. + // If send a notification is shown. if (!isset($simplenews_values['s_status']) || (isset($simplenews_values['s_status']) && $simplenews_values['s_status'] == SIMPLENEWS_STATUS_SEND_NOT)) { // Add dynamic text for send button. @@ -769,7 +781,12 @@ '#value' => key($format_options), ); } - + $form['simplenews']['advanced']['plain_field'] = array( + '#type' => 'select', + '#title' => t('Custom field for plain text newsletter'), + '#default_value' => isset($simplenews_values['plain_field']) ? $simplenews_values['plain_field'] : variable_get('simplenews_plain_field', 'none'), + '#options' => _simplenews_plain_field_options(), + ); $form['simplenews']['advanced']['priority'] = array( '#type' => 'select', '#title' => t('Email priority'), @@ -801,6 +818,11 @@ '#type' => 'hidden', '#value' => $simplenews_values['s_format'], ); + $form['simplenews']['advanced']['plain_field'] = array( + '#type' => 'hidden', + '#value' => $simplenews_values['plain_field'], + ); + $form['simplenews']['advanced']['priority'] = array( '#type' => 'hidden', '#value' => $simplenews_values['priority'], @@ -1746,7 +1774,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; @@ -1847,9 +1875,13 @@ // Build message body, replace tokens. $body = token_replace($body, 'simplenews', $context); // Convert to plain text if required. - if ($context['node']->simplenews['s_format'] == 'plain') { + if ($context['node']->simplenews['s_format'] == 'plain' && $context['node']->simplenews['plain_field'] == 'none') { $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'], $context['node']->simplenews['plain_field']); + } + // Get alternative text field + $message['text_alternative'] = theme('simplenews_newsletter_text_alternative', $context['node'], $context['node']->simplenews['tid'], $context['node']->simplenews['plain_field']); $message['body']['body'] = $body; // Build message footer, replace tokens. @@ -2201,6 +2233,25 @@ return TRUE; } + /** + * 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; +} + /** * Generate default and custom subscription confirmation email text. * @@ -2315,6 +2366,7 @@ $defaults = array( 'advanced' => array( 's_format' => variable_get('simplenews_format', 'plain'), + 'plain_text' => variable_get('simplenews_plain_field', 'none'), 'priority' => variable_get('simplenews_priority', SIMPLENEWS_PRIORITY_NONE), 'receipt' => variable_get('simplenews_receipt', 0), ), @@ -2378,6 +2430,9 @@ 'file' => 'simplenews.admin.inc', 'arguments' => array('status' => NULL, 'source' => NULL, 'already_sent' => NULL, 'sent_subscriber_count' => NULL), ), + 'simplenews_newsletter_text_alternative' => array( + 'arguments' => array('node' => NULL, 'tid' => NULL, 'plain_field' => NULL), + ), 'simplenews_newsletter_subject' => array( 'arguments' => array('name' => NULL, 'title' => NULL, 'language' => NULL), ), @@ -2463,6 +2518,22 @@ // Additional variables $variables['subscribed'] = empty($user->uid) ? FALSE : (simplenews_user_is_subscribed($user->mail, $tid) == TRUE); $variables['user'] = !empty($user->uid); +} + +/** + * 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; }