more module updates

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-20 18:19:49 +02:00
parent 2121a356b3
commit cde7b73a73
39 changed files with 660 additions and 258 deletions

View File

@@ -1,6 +1,14 @@
Views Send 7.x-1.x, xxxx-xx-xx
Views Send 7.x-1.1, 2014-06-21
------------------------------
#2225631 by hansfn: Using filter_fallback_format() instead of hard-coded value for message text format.
#2258947 by hansfn: Call to a member function get_value() on a non-object.
#2089409 by hansfn: Added support for Mandrill.
Views Send 7.x-1.0, 2014-04-15
------------------------------
#2202769 by hansfn: Subject not displaying correctly
#2122909 by hansfn: Unwanted conversion of quotes in fields used for recipient's e-mail and name
#2023977 by hansfn: Views Send overrides Mail System module configuration
#1963960 by hansfn: Add hooks.
#1957442 by hansfn: Token replacement doesn't work for repeated field.
#1939332 by hansfn: Token list doesn't update.

View File

@@ -25,7 +25,7 @@ DEPENDENCIES & INTEGRATION
* Views Send depends on Views.
* The module integrates features from:
o Mime Mail. When the Mime Mail module is enabled, the user can choose to send
rich HTML messages.
rich HTML messages and/or use attachments.
o Tokens. When the Tokens module is enabled, the user can insert context tokens
into the subject or body of the message. Note that row-based tokens are
available even if Tokens module is disabled.

View File

@@ -1,26 +0,0 @@
diff --git a/views_send.module b/views_send.module
index 283d434..58bbff9 100644
--- a/views_send.module
+++ b/views_send.module
@@ -960,8 +960,9 @@ function _views_send_prepare_mail(&$message, $plain_format=TRUE, $attachments=ar
$params['headers'] = $headers;
if (VIEWS_SEND_MIMEMAIL) {
+ $mailsystem = mailsystem_get();
mailsystem_set(array(
- "views_send_$key" => 'MimeMailSystem'
+ "views_send_$key" => $mailsystem['mimemail']
));
$params['attachments'] = $attachments;
if ($plain_format) {
@@ -1010,8 +1011,9 @@ function views_send_deliver($message) {
if (VIEWS_SEND_MIMEMAIL) {
$mail['subject'] = mime_header_encode($message->subject);
+ $mailsystem = mailsystem_get();
mailsystem_set(array(
- "views_send_$key" => 'MimeMailSystem'
+ "views_send_$key" => $mailsystem['mimemail']
));
}

View File

@@ -8,9 +8,9 @@ core = 7.x
files[] = views_send.rules.inc
files[] = views/views_send_handler_field_selector.inc
; Information added by drupal.org packaging script on 2013-05-12
version = "7.x-1.0-rc3"
; Information added by Drupal.org packaging script on 2014-06-21
version = "7.x-1.1"
core = "7.x"
project = "views_send"
datestamp = "1368398411"
datestamp = "1403371134"

View File

@@ -33,9 +33,22 @@ define('VIEWS_SEND_TOKEN_PREFIX', '[');
define('VIEWS_SEND_TOKEN_POSTFIX', ']');
/**
* Detect and store Mime Mail module presence.
* Detect if there is MIME support (thorough modules like Mime Mail or Mandrill).
*/
define('VIEWS_SEND_MIMEMAIL', module_exists('mimemail'));
define('VIEWS_SEND_MIMEMAIL', module_exists('mimemail') || module_exists('mandrill'));
/**
* Sets the mailsystem for Views Send (if not already set).
*/
function _views_send_mailsystem_set($key) {
$mailsystem = mailsystem_get();
$mailsystem_key = "views_send_$key";
if (empty($mailsystem[$mailsystem_key])) {
mailsystem_set(array(
$mailsystem_key => $mailsystem['default-system']
));
}
}
/**
* Gets the selector field if it exists on the passed-in view.
@@ -54,6 +67,31 @@ function _views_send_get_field($view) {
return FALSE;
}
/**
* Gets the raw field value from a result row in a view.
*
* @return
* An array with raw values from the field.
*/
function _views_send_get_raw_field_from_views_row($view, $row_id, $field_id) {
$result = array();
$raw_value = $view->style_plugin->get_field_value($row_id, $field_id);
if (!is_array($raw_value)) {
$result[] = trim($raw_value);
}
else {
foreach ($raw_value as $arr) {
if (isset($arr['value'])) {
$value = $arr['value'];
} else {
list($value) = array_values($arr);
}
$result[] = trim($value);
}
}
return $result;
}
/**
* Implements hook_views_form_substitutions().
*/
@@ -156,6 +194,8 @@ function views_send_form_alter(&$form, &$form_state, $form_id) {
/**
* Multistep form callback for the "configure" step.
*
@TODO: Hide "Sender" (from) if Mandrill is used.
*/
function views_send_config_form($form, &$form_state, $view, $output) {
$display = $view->name . ':' . $view->current_display;
@@ -233,7 +273,7 @@ function views_send_config_form($form, &$form_state, $view, $output) {
$saved_message = variable_get('views_send_message_' . $display);
$form['mail']['views_send_message'] = array(
'#type' => 'text_format',
'#format' => isset($saved_message['format']) ? $saved_message['format'] : 'plain_text',
'#format' => isset($saved_message['format']) ? $saved_message['format'] : filter_fallback_format(),
'#title' => t('Message'),
'#description' => t('Enter the body of the message. You can use tokens in the message.'),
'#required' => TRUE,
@@ -379,12 +419,10 @@ function views_send_config_form_validate($form, &$form_state) {
$to_mail_field = $values['views_send_tokens'][$values['views_send_to_mail']];
foreach ($form_state['selection'] as $row_id) {
$to_mail_rendered = $view->style_plugin->get_field($row_id, $to_mail_field);
$to_mail_arr = explode(',', strip_tags($to_mail_rendered));
foreach ($to_mail_arr as $to_mail) {
$to_mail = trim($to_mail);
if (!valid_email_address($to_mail)) {
$wrong_addresses[$row_id] = $to_mail;
$mail_addresses = _views_send_get_raw_field_from_views_row($view, $row_id, $to_mail_field);
foreach ($mail_addresses as $mail_address) {
if (!valid_email_address($mail_address)) {
$wrong_addresses[$row_id] = $mail_address;
break;
}
}
@@ -422,8 +460,13 @@ function views_send_confirm_form($form, &$form_state, $view, $output) {
$configuration = $form_state['configuration'];
if (!VIEWS_SEND_MIMEMAIL && ($configuration['views_send_message']['format'] != 'plain_text')) {
drupal_set_message(t("Only plain text is supported in the message. Any HTML will be converted to text. If you want to format the message with HTML, you'll have to install and enable the !mimemail module.",
array('!mimemail' => '<a href="http://drupal.org/project/mimemail">Mime Mail</a>'))
drupal_set_message(
t("Only plain text is supported in the message. Any HTML will be converted to text. If you want to format the message with HTML, you'll have to install and enable the !mimemail or !mandrill module.",
array(
'!mimemail' => '<a href="http://drupal.org/project/mimemail">Mime Mail</a>',
'!mandrill' => '<a href="http://drupal.org/project/mandrill">Mandrill</a>'
)
)
);
}
@@ -440,15 +483,23 @@ function views_send_confirm_form($form, &$form_state, $view, $output) {
'</div>',
);
// To: parts. (Mail is mandatory, name is optional.)
$recipients = array();
$to_name_field = $configuration['views_send_tokens'][$configuration['views_send_to_name']];
if (!empty($configuration['views_send_to_name'])) {
$to_name_field = $configuration['views_send_tokens'][$configuration['views_send_to_name']];
}
else {
$to_name_field = false;
$to_name = '';
}
$to_mail_field = $configuration['views_send_tokens'][$configuration['views_send_to_mail']];
foreach ($form_state['selection'] as $row_id) {
$to_name = strip_tags($view->style_plugin->get_field($row_id, $to_name_field));
$to_mail_rendered = $view->style_plugin->get_field($row_id, $to_mail_field);
$to_mail_arr = explode(',', strip_tags($to_mail_rendered));
foreach ($to_mail_arr as $to_mail) {
$recipients[] = check_plain(empty($to_name) ? $to_mail : trim($to_name) . ' <' . $to_mail . '>');
if ($to_name_field) {
list($to_name) = _views_send_get_raw_field_from_views_row($view, $row_id, $to_name_field);
}
$mail_addresses = _views_send_get_raw_field_from_views_row($view, $row_id, $to_mail_field);
foreach ($mail_addresses as $mail_address) {
$recipients[] = check_plain(empty($to_name) ? $mail_address : trim($to_name) . ' <' . $mail_address . '>');
}
}
@@ -563,7 +614,7 @@ function views_send_form_submit($form, &$form_state) {
// Redirect.
$query = drupal_get_query_parameters($_GET, array('q'));
$form_state['redirect'] = array('path' => $field->view->get_url(), array('query' => $query));
$form_state['redirect'] = array($field->view->get_url(), array('query' => $query));
break;
}
}
@@ -596,12 +647,21 @@ function views_send_queue_mail($params, $selected_rows, $view) {
$from_mail = trim($params['views_send_from_mail']);
$from_name = $params['views_send_from_name'];
// To: parts. (Mail is mandatory, name is optional.)
$to_mail_key = $params['views_send_tokens'][$params['views_send_to_mail']];
$to_name_key = $params['views_send_tokens'][$params['views_send_to_name']];
if (!empty($params['views_send_to_name'])) {
$to_name_key = $params['views_send_tokens'][$params['views_send_to_name']];
}
else {
$to_name_key = false;
$to_name = '';
}
foreach ($selected_rows as $row_id) {
// To: parts.
$to_mail = trim(strip_tags($view->style_plugin->get_field($row_id, $to_mail_key)));
$to_name = trim(strip_tags($view->style_plugin->get_field($row_id, $to_name_key)));
$to_mail = implode(',', _views_send_get_raw_field_from_views_row($view, $row_id, $to_mail_key));
if ($to_name_key) {
list($to_name) = _views_send_get_raw_field_from_views_row($view, $row_id, $to_name_key);
}
$subject = $params['views_send_subject'];
$body = $params['views_send_message']['value'];
@@ -658,10 +718,10 @@ function views_send_queue_mail($params, $selected_rows, $view) {
$message = array(
'uid' => $user->uid,
'timestamp' => time(),
'from_name' => $from_name,
'from_mail' => $from_mail,
'to_name' => $to_name,
'to_mail' => $to_mail,
'from_name' => trim($from_name),
'from_mail' => trim($from_mail),
'to_name' => trim($to_name),
'to_mail' => trim($to_mail),
'subject' => strip_tags($subject),
'body' => $body,
'headers' => $headers,
@@ -702,7 +762,7 @@ function views_send_queue_mail($params, $selected_rows, $view) {
);
batch_set($batch);
drupal_set_message(
t('@total messages processed.', array('@total' => count($selected_rows)))
format_plural(count($selected_rows), '1 message processed.', '@count messages processed.')
);
}
else {
@@ -713,7 +773,7 @@ function views_send_queue_mail($params, $selected_rows, $view) {
}
drupal_set_message(
t('@total messages added to the spool.', array('@total' => count($selected_rows)))
format_plural(count($selected_rows), '1 message added to the spool.', '@count messages added to the spool.')
);
if (module_exists('rules')) {
rules_invoke_event('views_send_all_email_added_to_spool', count($selected_rows));
@@ -900,10 +960,26 @@ function _views_send_headers($receipt, $priority, $from, $additional_headers) {
* Build a formatted e-mail address.
*/
function _views_send_format_address($mail, $name, $encode = TRUE) {
$name = trim($name);
// Do not format addres on Windows based PHP systems or when $name is empty.
return ((substr(PHP_OS, 0, 3) == 'WIN') || empty($name)) ? $mail : '"' . ($encode ? mime_header_encode($name) : $name) . '" <' . $mail . '>';
if ((substr(PHP_OS, 0, 3) == 'WIN') || empty($name)) {
return $mail;
}
else {
$name = ($encode ? _views_send_mime_header_encode($name) : $name);
return sprintf('"%s" <%s>', $name, $mail);
}
}
/**
* Returns a mime-encoded string for strings that contain UTF-8.
*
* Simplified and correct version of mime_header_decode.
*/
function _views_send_mime_header_encode($string) {
if (preg_match('/[^\x20-\x7E]/', $string)) {
$string = '=?UTF-8?B?' . base64_encode($string) . '?=';
}
return $string;
}
/**
@@ -960,10 +1036,7 @@ function _views_send_prepare_mail(&$message, $plain_format=TRUE, $attachments=ar
$params['headers'] = $headers;
if (VIEWS_SEND_MIMEMAIL) {
$mailsystem = mailsystem_get();
mailsystem_set(array(
"views_send_$key" => $mailsystem['mimemail']
));
_views_send_mailsystem_set($key);
$params['attachments'] = $attachments;
if ($plain_format) {
$params['plain'] = TRUE;
@@ -1010,13 +1083,13 @@ function views_send_deliver($message) {
);
if (VIEWS_SEND_MIMEMAIL) {
$mail['subject'] = mime_header_encode($message->subject);
$mailsystem = mailsystem_get();
mailsystem_set(array(
"views_send_$key" => $mailsystem['mimemail']
));
_views_send_mailsystem_set($key);
}
// Mime encode the subject before passing to the mail function
// to work around a bug in Drupal's mime_header_encode.
$mail['subject'] = _views_send_mime_header_encode($message->subject);
$system = drupal_mail_system('views_send', $key);
return $system->mail($mail);
}