updated views_send views_bulk_update views_data_export

This commit is contained in:
Bachir Soussi Chiadmi
2017-05-24 19:09:09 +02:00
parent dbd7b88639
commit 542ac42fca
42 changed files with 2939 additions and 264 deletions

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 2016-11-09
version = "7.x-1.3"
; Information added by Drupal.org packaging script on 2017-04-03
version = "7.x-1.6"
core = "7.x"
project = "views_send"
datestamp = "1478685242"
datestamp = "1491222486"

View File

@@ -1,4 +1,11 @@
(function ($) {
// Polyfill for jQuery less than 1.6.
if (typeof $.fn.prop != 'function') {
jQuery.fn.extend({
prop: jQuery.fn.attr
});
}
Drupal.behaviors.viewsSend = {
attach: function(context) {
$('.views-send-selection-form', context).each(function() {
@@ -14,7 +21,7 @@
// This is the "select all" checkbox in (each) table header.
$('.views-send-table-select-all', form).click(function() {
var table = $(this).closest('table')[0];
$('input[id^="edit-views-send"]:not(:disabled)', table).attr('checked', this.checked).change();
$('input[id^="edit-views-send"]:not(:disabled)', table).prop('checked', this.checked).change();
});
}
@@ -23,21 +30,21 @@
$('.views-send-select-all-markup', form).show();
$('.views-send-select-this-page', form).click(function() {
$('input[id^="edit-views-send"]', form).attr('checked', this.checked).change();
$('input[id^="edit-views-send"]', form).prop('checked', this.checked).change();
// Toggle the "select all" checkbox in grouped tables (if any).
$('.views-send-table-select-all', form).attr('checked', this.checked).change();
$('.views-send-table-select-all', form).prop('checked', this.checked).change();
});
$('.views-send-select', form).click(function() {
// If a checkbox was deselected, uncheck any "select all" checkboxes.
if (!this.checked) {
$('.views-send-select-this-page', form).attr('checked', false).change();
$('.views-send-select-this-page', form).prop('checked', false).change();
var table = $(this).closest('table')[0];
if (table) {
// Uncheck the "select all" checkbox in the table header.
$('.views-send-table-select-all', table).attr('checked', false).change();
$('.views-send-table-select-all', table).prop('checked', false).change();
}
}
});

View File

@@ -33,21 +33,20 @@ define('VIEWS_SEND_TOKEN_PREFIX', '[');
define('VIEWS_SEND_TOKEN_POSTFIX', ']');
/**
* Detect if there is MIME support (thorough modules like Mime Mail or Mandrill).
* Detect if there is MIME support (through modules like Mime Mail or Mandrill).
*/
define('VIEWS_SEND_MIMEMAIL', module_exists('mimemail') || module_exists('mandrill'));
switch (true) {
case (module_exists('htmlmail') && module_exists('mailmime')):
case module_exists('mailgun'):
case module_exists('mandrill'):
case module_exists('mimemail'):
case module_exists('sendgrid_integration'):
case module_exists('swiftmailer'):
define('VIEWS_SEND_MIMEMAIL', TRUE);
break;
/**
* 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']
));
}
default:
define('VIEWS_SEND_MIMEMAIL', FALSE);
}
/**
@@ -549,7 +548,7 @@ function views_send_confirm_form($form, &$form_state, $view, $output) {
);
if (VIEWS_SEND_MIMEMAIL && !empty($configuration['views_send_attachments']) && user_access('attachments with views_send')) {
foreach ($configuration['views_send_attachments'] as $attachment) {
$attachments[] = $attachment['filename'];
$attachments[] = check_plain($attachment['filename']);
}
$form['attachments'] = array(
'#type' => 'item',
@@ -609,6 +608,7 @@ function views_send_form_submit($form, &$form_state) {
}
}
$form_state['configuration'] = $form_state['values'];
$form_state['configuration']['views_send_attachments'] = array();
// If a file was uploaded, process it.
if (VIEWS_SEND_MIMEMAIL && user_access('attachments with views_send') && isset($_FILES['files']) && is_uploaded_file($_FILES['files']['tmp_name']['views_send_attachments'])) {
@@ -665,6 +665,8 @@ function views_send_form_back_submit($form, &$form_state) {
/**
* Assembles the email and queues it for sending.
*
* Also email sent directly using the Batch API is handled here.
*
* @param $params
* Data entered in the "config" step of the form.
* @param $selected_rows
@@ -684,8 +686,6 @@ function views_send_queue_mail($params, $selected_rows, $view) {
return;
}
$formats = filter_formats();
// From: parts.
$from_mail = trim($params['views_send_from_mail']);
$from_name = $params['views_send_from_name'];
@@ -699,6 +699,36 @@ function views_send_queue_mail($params, $selected_rows, $view) {
$to_name_key = false;
$to_name = '';
}
$subject = $params['views_send_subject'];
$body = $params['views_send_message']['value'];
$headers = _views_send_headers($params['views_send_receipt'], $params['views_send_priority'], $from_mail, $params['views_send_headers']);
$format = $params['views_send_message']['format'];
$attachments = $params['views_send_attachments'];
$formats = filter_formats();
if (!filter_access($formats[$format])) {
drupal_set_message(t('No mails sent since an illegale format is selected for the message.'));
return;
}
else {
$body = check_markup($body, $format);
}
if ($format == 'plain_text') {
$plain_format = TRUE;
}
else {
$plain_format = FALSE;
}
$message_base = array(
'uid' => $user->uid,
'from_name' => trim($from_name),
'from_mail' => trim($from_mail),
'headers' => $headers,
);
foreach ($selected_rows as $selected_rows_key => $row_id) {
// To: parts.
$to_mail = implode(',', _views_send_get_field_value_from_views_row($view, $row_id, $to_mail_key, 'mail'));
@@ -706,18 +736,6 @@ function views_send_queue_mail($params, $selected_rows, $view) {
$to_name = _views_send_get_field_value_from_views_row($view, $row_id, $to_name_key, 'plain_text');
}
$subject = $params['views_send_subject'];
$body = $params['views_send_message']['value'];
$params['format'] = $params['views_send_message']['format'];
// This shouldn't happen, but better be 100% sure.
if (!filter_access($formats[$params['format']])) {
drupal_set_message(t('No mails sent since an illegale format is selected for the message.'));
return;
}
$body = check_markup($body, $params['format']);
// Populate row/context tokens.
$token_keys = $token_values = array();
foreach ($params['views_send_tokens'] as $field_key => $field_name) {
@@ -726,8 +744,8 @@ function views_send_queue_mail($params, $selected_rows, $view) {
}
// Views Send specific token replacements
$subject = str_replace($token_keys, $token_values, $subject);
$body = str_replace($token_keys, $token_values, $body);
$subject_expanded = str_replace($token_keys, $token_values, $subject);
$body_expanded = str_replace($token_keys, $token_values, $body);
// Global token replacement, and node/user token replacements
// if a nid/uid is found in the views result row.
@@ -738,36 +756,19 @@ function views_send_queue_mail($params, $selected_rows, $view) {
if (property_exists($view->result[$row_id], 'nid')) {
$data['node'] = node_load($view->result[$row_id]->nid);
}
$subject = token_replace($subject, $data);
$body = token_replace($body, $data);
$subject_expanded = token_replace($subject_expanded, $data);
$body_expanded = token_replace($body_expanded, $data);
if (!VIEWS_SEND_MIMEMAIL || (variable_get('mimemail_format', 'plain_text') == 'plain_text')) {
$body = drupal_html_to_text($body);
$body_expanded = drupal_html_to_text($body_expanded);
}
if ($params['format'] == 'plain_text') {
$plain_format = TRUE;
}
else {
$plain_format = FALSE;
}
// We transform receipt, priority in headers,
// merging them to the user defined headers.
$headers = _views_send_headers($params['views_send_receipt'], $params['views_send_priority'], $from_mail, $params['views_send_headers']);
$attachments = isset($params['views_send_attachments']) ? $params['views_send_attachments'] : array();
$message = array(
'uid' => $user->uid,
$message = $message_base + array(
'timestamp' => time(),
'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,
'subject' => strip_tags($subject_expanded),
'body' => $body_expanded,
);
// Enable other modules to alter the actual message before queueing it
@@ -782,6 +783,10 @@ function views_send_queue_mail($params, $selected_rows, $view) {
// Only queue the message if it hasn't been cancelled by another module.
if ($message['send']) {
unset($message['send']);
// Removing stuff add to work around Swifth Mailer issue 2841663
if (module_exists('swiftmailer')) {
unset($message['params']);
}
db_insert('views_send_spool')->fields($message)->execute();
if (module_exists('rules')) {
@@ -1086,7 +1091,6 @@ function _views_send_prepare_mail(&$message, $plain_format=TRUE, $attachments=ar
$params['headers'] = $headers;
if (VIEWS_SEND_MIMEMAIL) {
_views_send_mailsystem_set($key);
$params['attachments'] = $attachments;
if ($plain_format) {
$params['plain'] = TRUE;
@@ -1109,6 +1113,10 @@ function _views_send_prepare_mail(&$message, $plain_format=TRUE, $attachments=ar
$message['body'] = $mail['body'];
$message['send'] = $mail['send'];
$message['headers'] = serialize($mail['headers']);
// Working around a Swifth Mailer issue - see https://www.drupal.org/node/2841663
if (module_exists('swiftmailer')) {
$message['params'] = array('attachments' => $params['attachments']);
}
}
/**
@@ -1135,9 +1143,9 @@ function views_send_deliver($message) {
'body' => $message->body,
'headers' => $headers,
);
if (VIEWS_SEND_MIMEMAIL) {
_views_send_mailsystem_set($key);
// Because of Swifth Mailer issue 2841663
if (module_exists('swiftmailer')) {
$mail['params'] = $message->params;
}
// Mime encode the subject before passing to the mail function
@@ -1217,47 +1225,6 @@ function theme_views_send_token_help($fields) {
return $output;
}
if (module_exists('token')) {
/**
* Implements hook_token_info().
*
* These token are used by Rules and not in the Views form.
*/
function views_send_token_info() {
$data = array();
foreach (_views_send_email_message_property_info() as $key => $info) {
$data[$key] = array(
'name' => $info['label'],
'description' => ''
);
}
$type = array(
'name' => t('Views Send e-mail message'),
'description' => t('Tokens for Views Send e-mail message.'),
'needs-data' => 'views_send_email_message',
);
return array(
'types' => array('views_send_email_message' => $type),
'tokens' => array('views_send_email_message' => $data),
);
}
/**
* Implementation hook_tokens().
*
* These token replacements are used by Rules and not in the Views form.
*/
function views_send_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'views_send_email_message' && !empty($data['views_send_email_message'])) {
foreach ($tokens as $name => $original) {
$replacements[$original] = $data['views_send_email_message']->{$name};
}
}
return $replacements;
}
}
/**
* Generates and returns fields and tokens.
*/

View File

@@ -0,0 +1,45 @@
<?php
/**
* @file
* Token integration for the Views Send module.
*/
/**
* Implements hook_token_info().
*
* These token are used by Rules and not in the Views form.
*/
function views_send_token_info() {
$data = array();
foreach (_views_send_email_message_property_info() as $key => $info) {
$data[$key] = array(
'name' => $info['label'],
'description' => ''
);
}
$type = array(
'name' => t('Views Send e-mail message'),
'description' => t('Tokens for Views Send e-mail message.'),
'needs-data' => 'views_send_email_message',
);
return array(
'types' => array('views_send_email_message' => $type),
'tokens' => array('views_send_email_message' => $data),
);
}
/**
* Implementation hook_tokens().
*
* These token replacements are used by Rules and not in the Views form.
*/
function views_send_tokens($type, $tokens, array $data = array(), array $options = array()) {
$replacements = array();
if ($type == 'views_send_email_message' && !empty($data['views_send_email_message'])) {
foreach ($tokens as $name => $original) {
$replacements[$original] = $data['views_send_email_message']->{$name};
}
}
return $replacements;
}