updated view_send, vews_php, nodeformcols, email_registratio

This commit is contained in:
Bachir Soussi Chiadmi
2016-11-05 16:53:56 +01:00
parent 0bb339fc99
commit 3b6c7b914d
20 changed files with 318 additions and 130 deletions

View File

@@ -1,3 +1,9 @@
Views Send 7.x-1.2, 2016-03-29
------------------------------
#2237585 by hansfn: Make allowed file extensions for attachments configurable
#2368533 by hansfn: Bypassing views render layer breaks all sort of things (Also fixes #1833608 Views field rewriting)
#2693393 by hansfn: Mailsystem 3.x-dev requires "key" and "module" keys in the mail message
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.

View File

@@ -13,6 +13,15 @@
function views_send_settings() {
$form = array();
if (VIEWS_SEND_MIMEMAIL) {
$form['views_send_attachment_valid_extensions'] = array(
'#type' => 'textfield',
'#title' => t('Valid file extensions for attachments'),
'#default_value' => variable_get('views_send_attachment_valid_extensions', ''),
'#description' => t('A space separated list of allowed file extensions for attachments. Leave the list empty if you want to use the default list from file_save_upload().'),
);
}
$throttle = drupal_map_assoc(array(1, 10, 20, 30, 50, 100, 200, 500, 1000, 2000, 5000, 10000, 20000));
$throttle[0] = t('Unlimited');

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 2014-06-21
version = "7.x-1.1"
; Information added by Drupal.org packaging script on 2016-03-29
version = "7.x-1.2"
core = "7.x"
project = "views_send"
datestamp = "1403371134"
datestamp = "1459239847"

View File

@@ -14,7 +14,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);
$('input[id^="edit-views-send"]:not(:disabled)', table).attr('checked', this.checked).change();
});
}
@@ -23,21 +23,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);
$('input[id^="edit-views-send"]', form).attr('checked', this.checked).change();
// Toggle the "select all" checkbox in grouped tables (if any).
$('.views-send-table-select-all', form).attr('checked', this.checked);
$('.views-send-table-select-all', form).attr('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);
$('.views-send-select-this-page', form).attr('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);
$('.views-send-table-select-all', table).attr('checked', false).change();
}
}
});

View File

@@ -56,7 +56,7 @@ function _views_send_mailsystem_set($key) {
* @return
* The field object if found. Otherwise, FALSE.
*/
function _views_send_get_field($view) {
function _views_send_get_field_selector($view) {
foreach ($view->field as $field_name => $field) {
if ($field instanceof views_send_handler_field_selector) {
// Add in the view object for convenience.
@@ -68,26 +68,30 @@ function _views_send_get_field($view) {
}
/**
* Gets the raw field value from a result row in a view.
* Gets the field value from a result row in a view - rendered value (default),
* plain text or array with mail addresses.
*
* @return
* An array with raw values from the field.
* See description.
*/
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);
}
function _views_send_get_field_value_from_views_row($view, $row_id, $field_id, $type='') {
if (strpos($field_id, 'custom_text') === 0) {
// Handle the special case for custom text fields.
$field_id = str_replace('custom_text', 'nothing', $field_id);
}
$rendered_field = $view->style_plugin->get_field($row_id, $field_id);
if ($type == 'plain_text') {
// Removing HTML tags. Used for names in headers, not body.
$result = strip_tags($rendered_field);
}
elseif ($type == 'mail') {
// Removing HTML tags and entities. Used for e-mail addresses in headers, not body.
$result = explode(',', decode_entities(strip_tags($rendered_field)));
$result = array_map('trim', $result);
}
else {
$result = $rendered_field;
}
return $result;
}
@@ -142,7 +146,7 @@ function theme_views_send_select_all($variables) {
*/
function views_send_form_alter(&$form, &$form_state, $form_id) {
if (strpos($form_id, 'views_form_') === 0) {
$field = _views_send_get_field($form_state['build_info']['args'][0]);
$field = _views_send_get_field_selector($form_state['build_info']['args'][0]);
}
// This form isn't used by Views Send.
if (empty($field)) {
@@ -198,6 +202,10 @@ function views_send_form_alter(&$form, &$form_state, $form_id) {
@TODO: Hide "Sender" (from) if Mandrill is used.
*/
function views_send_config_form($form, &$form_state, $view, $output) {
if (!empty($form_state['configuration'])) {
// Values entered in the "config" step.
$config = $form_state['configuration'];
}
$display = $view->name . ':' . $view->current_display;
$form['display'] = array(
'#type' => 'value',
@@ -213,7 +221,7 @@ function views_send_config_form($form, &$form_state, $view, $output) {
'#type' => 'textfield',
'#title' => t('Sender\'s name'),
'#description' => t("Enter the sender's human readable name."),
'#default_value' => variable_get('views_send_from_name_' . $display, variable_get('site_name', '')),
'#default_value' => isset($config['views_send_from_name']) ? $config['views_send_from_name'] : variable_get('views_send_from_name_' . $display, variable_get('site_name', '')),
'#maxlen' => 255,
);
$form['from']['views_send_from_mail'] = array(
@@ -221,7 +229,7 @@ function views_send_config_form($form, &$form_state, $view, $output) {
'#title' => t('Sender\'s e-mail'),
'#description' => t("Enter the sender's e-mail address."),
'#required' => TRUE,
'#default_value' => variable_get('views_send_from_mail_' . $display, variable_get('site_mail', ini_get('sendmail_from'))),
'#default_value' => isset($config['views_send_from_mail']) ? $config['views_send_from_mail'] : variable_get('views_send_from_mail_' . $display, variable_get('site_mail', ini_get('sendmail_from'))),
'#maxlen' => 255,
);
@@ -246,14 +254,14 @@ function views_send_config_form($form, &$form_state, $view, $output) {
'#title' => t('Field used for recipient\'s name'),
'#description' => t('Select which field from the current view will be used as recipient\'s name.'),
'#options' => $fields_options,
'#default_value' => variable_get('views_send_to_name_' . $display, ''),
'#default_value' => isset($config['views_send_to_name']) ? $config['views_send_to_name'] : variable_get('views_send_to_name_' . $display, ''),
);
$form['to']['views_send_to_mail'] = array(
'#type' => 'select',
'#title' => t('Field used for recipient\'s e-mail'),
'#description' => t('Select which field from the current view will be used as recipient\'s e-mail.'),
'#options' => $fields_options,
'#default_value' => variable_get('views_send_to_mail_' . $display, ''),
'#default_value' => isset($config['views_send_to_mail']) ? $config['views_send_to_mail'] : variable_get('views_send_to_mail_' . $display, ''),
'#required' => TRUE,
);
$form['mail'] = array(
@@ -268,18 +276,28 @@ function views_send_config_form($form, &$form_state, $view, $output) {
'#description' => t('Enter the e-mail\'s subject. You can use tokens in the subject.'),
'#maxlen' => 255,
'#required' => TRUE,
'#default_value' => variable_get('views_send_subject_' . $display, ''),
'#default_value' => isset($config['views_send_subject']) ? $config['views_send_subject'] : variable_get('views_send_subject_' . $display, ''),
);
$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'] : filter_fallback_format(),
'#title' => t('Message'),
'#description' => t('Enter the body of the message. You can use tokens in the message.'),
'#required' => TRUE,
'#rows' => 10,
'#default_value' => isset($saved_message['value']) ? $saved_message['value'] : '',
);
if (isset($config['views_send_message']['value'])) {
$form['mail']['views_send_message'] += array(
'#format' => $config['views_send_message']['format'],
'#default_value' => $config['views_send_message']['value'],
);
}
else {
$saved_message = variable_get('views_send_message_' . $display);
$form['mail']['views_send_message'] += array(
'#format' => isset($saved_message['format']) ? $saved_message['format'] : filter_fallback_format(),
'#default_value' => isset($saved_message['value']) ? $saved_message['value'] : '',
);
}
$form['mail']['token'] = array(
'#type' => 'fieldset',
'#title' => t('Tokens'),
@@ -343,12 +361,12 @@ function views_send_config_form($form, &$form_state, $view, $output) {
VIEWS_SEND_PRIORITY_LOWEST => t('lowest')
),
'#description' => t('Note that e-mail priority is ignored by a lot of e-mail programs.'),
'#default_value' => variable_get('views_send_priority_' . $display, 0),
'#default_value' => isset($config['views_send_priority']) ? $config['views_send_priority'] : variable_get('views_send_priority_' . $display, 0),
);
$form['additional']['views_send_receipt'] = array(
'#type' => 'checkbox',
'#title' => t('Request receipt'),
'#default_value' => variable_get('views_send_receipt_' . $display, 0),
'#default_value' => isset($config['views_send_receipt']) ? $config['views_send_receipt'] : variable_get('views_send_receipt_' . $display, 0),
'#description' => t('Request a Read Receipt from your e-mails. A lot of e-mail programs ignore these so it is not a definitive indication of how many people have read your message.'),
);
$form['additional']['views_send_headers'] = array(
@@ -356,18 +374,18 @@ function views_send_config_form($form, &$form_state, $view, $output) {
'#title' => t('Additional headers'),
'#description' => t("Additional headers to be send with the message. You'll have to enter one per line. Example:<pre>Reply-To: noreply@example.com\nX-MyCustomHeader: Whatever</pre>"),
'#rows' => 4,
'#default_value' => variable_get('views_send_headers_' . $display, ''),
'#default_value' => isset($config['views_send_headers']) ? $config['views_send_headers'] : variable_get('views_send_headers_' . $display, ''),
);
$form['views_send_direct'] = array(
'#type' => 'checkbox',
'#title' => t('Send the message directly using the Batch API.'),
'#default_value' => variable_get('views_send_direct_'. $display, TRUE),
'#default_value' => isset($config['views_send_direct']) ? $config['views_send_direct'] : variable_get('views_send_direct_'. $display, TRUE),
);
$form['views_send_carbon_copy'] = array(
'#type' => 'checkbox',
'#title' => t('Send a copy of the message to the sender.'),
'#default_value' => variable_get('views_send_carbon_copy_' . $display, TRUE),
'#default_value' => isset($config['views_send_carbon_copy']) ? $config['views_send_carbon_copy'] : variable_get('views_send_carbon_copy_' . $display, TRUE),
);
$form['views_send_remember'] = array(
@@ -419,7 +437,7 @@ 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) {
$mail_addresses = _views_send_get_raw_field_from_views_row($view, $row_id, $to_mail_field);
$mail_addresses = _views_send_get_field_value_from_views_row($view, $row_id, $to_mail_field, 'mail');
foreach ($mail_addresses as $mail_address) {
if (!valid_email_address($mail_address)) {
$wrong_addresses[$row_id] = $mail_address;
@@ -495,9 +513,9 @@ function views_send_confirm_form($form, &$form_state, $view, $output) {
$to_mail_field = $configuration['views_send_tokens'][$configuration['views_send_to_mail']];
foreach ($form_state['selection'] as $row_id) {
if ($to_name_field) {
list($to_name) = _views_send_get_raw_field_from_views_row($view, $row_id, $to_name_field);
$to_name = _views_send_get_field_value_from_views_row($view, $row_id, $to_name_field, 'plain_text');
}
$mail_addresses = _views_send_get_raw_field_from_views_row($view, $row_id, $to_mail_field);
$mail_addresses = _views_send_get_field_value_from_views_row($view, $row_id, $to_mail_field, 'mail');
foreach ($mail_addresses as $mail_address) {
$recipients[] = check_plain(empty($to_name) ? $mail_address : trim($to_name) . ' <' . $mail_address . '>');
}
@@ -546,6 +564,11 @@ function views_send_confirm_form($form, &$form_state, $view, $output) {
'#attributes' => array('class' => array('form-actions')),
'#weight' => 999,
);
$form['actions']['back'] = array(
'#type' => 'submit',
'#value' => t('Go back'),
'#submit' => array('views_send_form_back_submit'),
);
$form['actions']['submit'] = array(
'#type' => 'submit',
'#value' => t('Send'),
@@ -560,7 +583,7 @@ function views_send_confirm_form($form, &$form_state, $view, $output) {
* Submit handler for all steps of the Views Send multistep form.
*/
function views_send_form_submit($form, &$form_state) {
$field = _views_send_get_field($form_state['build_info']['args'][0]);
$field = _views_send_get_field_selector($form_state['build_info']['args'][0]);
switch ($form_state['step']) {
case 'views_form_views_form':
@@ -592,7 +615,15 @@ function views_send_form_submit($form, &$form_state) {
// attempt to save the uploaded file
$dir = file_default_scheme() . '://views_send_attachments';
file_prepare_directory($dir, FILE_CREATE_DIRECTORY);
$file = file_save_upload('views_send_attachments', array(), $dir);
$file_extensions = variable_get('views_send_attachment_valid_extensions', FALSE);
if ($file_extensions) {
$file_validators['file_validate_extensions'] = array();
$file_validators['file_validate_extensions'][0] = $file_extensions;
}
else {
$file_validators = array();
}
$file = file_save_upload('views_send_attachments', $file_validators, $dir);
// set error if file was not uploaded
if (!$file) {
//form_set_error('views_send_attachment', 'Error uploading file.');
@@ -619,6 +650,18 @@ function views_send_form_submit($form, &$form_state) {
}
}
/**
* Submit handler that handles back buttons.
*/
function views_send_form_back_submit($form, &$form_state) {
switch ($form_state['step']) {
case 'views_send_confirm_form':
$form_state['step'] = 'views_send_config_form';
$form_state['rebuild'] = TRUE;
break;
}
}
/**
* Assembles the email and queues it for sending.
*
@@ -656,11 +699,11 @@ function views_send_queue_mail($params, $selected_rows, $view) {
$to_name_key = false;
$to_name = '';
}
foreach ($selected_rows as $row_id) {
foreach ($selected_rows as $selected_rows_key => $row_id) {
// To: parts.
$to_mail = implode(',', _views_send_get_raw_field_from_views_row($view, $row_id, $to_mail_key));
$to_mail = implode(',', _views_send_get_field_value_from_views_row($view, $row_id, $to_mail_key, 'mail'));
if ($to_name_key) {
list($to_name) = _views_send_get_raw_field_from_views_row($view, $row_id, $to_name_key);
$to_name = _views_send_get_field_value_from_views_row($view, $row_id, $to_name_key, 'plain_text');
}
$subject = $params['views_send_subject'];
@@ -679,7 +722,7 @@ function views_send_queue_mail($params, $selected_rows, $view) {
$token_keys = $token_values = array();
foreach ($params['views_send_tokens'] as $field_key => $field_name) {
$token_keys[] = VIEWS_SEND_TOKEN_PREFIX . sprintf(VIEWS_SEND_TOKEN_PATTERN, $field_name) . VIEWS_SEND_TOKEN_POSTFIX;
$token_values[] = $view->style_plugin->get_field($row_id, $field_name);
$token_values[] = _views_send_get_field_value_from_views_row($view, $row_id, $field_name);
}
// Views Send specific token replacements
@@ -736,16 +779,23 @@ function views_send_queue_mail($params, $selected_rows, $view) {
}
else {
_views_send_prepare_mail($message, $plain_format, $attachments);
// Queue the message to the spool table.
db_insert('views_send_spool')->fields($message)->execute();
if (module_exists('rules')) {
rules_invoke_event('views_send_email_added_to_spool', $message);
// Only queue the message if it hasn't been cancelled by another module.
if ($message['send']) {
unset($message['send']);
db_insert('views_send_spool')->fields($message)->execute();
if (module_exists('rules')) {
rules_invoke_event('views_send_email_added_to_spool', $message);
}
// Enabled other modules to act just after a message is queued
// by providing the hook 'views_send_mail_queued'.
module_invoke_all('views_send_mail_queued', $message, $view, $row_id);
}
else {
unset($selected_rows[$selected_rows_key]);
}
}
// Enabled other modules to act just after a message is queued
// by providing the hook 'views_send_mail_queued'.
module_invoke_all('views_send_mail_queued', $message, $view, $row_id);
}
if ($params['views_send_direct']) {
@@ -1057,6 +1107,7 @@ function _views_send_prepare_mail(&$message, $plain_format=TRUE, $attachments=ar
$message['from_mail'] = $mail['from'];
$message['subject'] = $mail['subject'];
$message['body'] = $mail['body'];
$message['send'] = $mail['send'];
$message['headers'] = serialize($mail['headers']);
}
@@ -1075,6 +1126,9 @@ function views_send_deliver($message) {
$headers = unserialize($message->headers);
$mail = array(
'id' => 'views_send_' . $key,
'module' => 'views_send',
'key' => $key,
'to' => $message->to_mail,
'from' => $message->from_mail,
'subject' => $message->subject,
@@ -1099,6 +1153,15 @@ function views_send_deliver($message) {
*/
function views_send_batch_deliver($message, $plain_format, $attachments, &$context) {
_views_send_prepare_mail($message, $plain_format, $attachments);
if (!$message['send']) {
$context['results'][] = t('Skipping sending message to %mail.',
array('%mail' => $message['to_mail']));
return;
}
else {
unset($message['send']);
}
$status = views_send_deliver($message);
if ($status) {
@@ -1214,7 +1277,12 @@ function _views_send_get_fields_and_tokens($view, $type) {
if (property_exists($field, 'views_form_callback') || method_exists($field, 'views_form')) {
continue;
}
if (!empty($field->field_info)) {
if ($field instanceof views_handler_field_custom) {
$field_key = $field_name;
// Using a nice field name (for tokens) for custom text fields.
$field_name = str_replace('nothing', 'custom_text', $field_name);;
}
elseif (!empty($field->field_info)) {
$field_key = $field->field_info['field_name'];
}
elseif (property_exists($field, 'field_alias')) {