FINAL suepr merge step : added all modules to this super repos
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
name = "Mime Mail Action"
|
||||
description = "Provide actions for Mime Mail."
|
||||
package = Mail
|
||||
dependencies[] = mimemail
|
||||
dependencies[] = trigger
|
||||
core = 7.x
|
||||
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-09-06
|
||||
version = "7.x-1.0-alpha2+30-dev"
|
||||
core = "7.x"
|
||||
project = "mimemail"
|
||||
datestamp = "1378431585"
|
||||
|
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Provide actions for Mime Mail.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_action_info().
|
||||
*/
|
||||
function mimemail_action_info() {
|
||||
return array(
|
||||
'mimemail_send_email_action' => array(
|
||||
'type' => 'system',
|
||||
'label' => t('Send HTML e-mail'),
|
||||
'configurable' => TRUE,
|
||||
'triggers' => array('any'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements a configurable Drupal action. Sends an email.
|
||||
*/
|
||||
function mimemail_send_email_action($entity, $context) {
|
||||
if (empty($context['node'])) {
|
||||
$context['node'] = $entity;
|
||||
}
|
||||
|
||||
$to = token_replace($context['to'], $context);
|
||||
|
||||
// If the recipient is a registered user with a language preference, use
|
||||
// the recipient's preferred language. Otherwise, use the system default
|
||||
// language.
|
||||
$account = user_load_by_mail($to);
|
||||
if ($account) {
|
||||
$language = user_preferred_language($account);
|
||||
}
|
||||
else {
|
||||
$language = language_default();
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'context' => array(
|
||||
'subject' => token_replace($context['subject'], $context),
|
||||
'body' => token_replace($context['body'], $context),
|
||||
),
|
||||
'key' => $context['key'],
|
||||
'cc' => $context['cc'],
|
||||
'bcc' => $context['bcc'],
|
||||
'reply-to' => $context['reply-to'],
|
||||
'plaintext' => token_replace($context['plaintext'], $context),
|
||||
'attachments' => $context['attachments'],
|
||||
);
|
||||
|
||||
drupal_mail('mimemail', $context['key'], $to, $language, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Form for configurable Drupal action to send an HTML mail.
|
||||
*/
|
||||
function mimemail_send_email_action_form($context) {
|
||||
$context += array(
|
||||
'key' => '',
|
||||
'to' => '',
|
||||
'cc' => '',
|
||||
'bcc' => '',
|
||||
'reply-to' => '',
|
||||
'subject' => '',
|
||||
'body' => '',
|
||||
'format' => filter_fallback_format(),
|
||||
'plaintext' => '',
|
||||
'attachments' => ''
|
||||
);
|
||||
|
||||
$form['key'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Key'),
|
||||
'#default_value' => $context['key'],
|
||||
'#description' => t('A key to identify the e-mail sent.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['to'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Recipient'),
|
||||
'#default_value' => $context['to'],
|
||||
'#maxlength' => 254,
|
||||
'#description' => t('The email address to which the message should be sent OR enter [node:author:mail], [comment:author:mail], etc. if you would like to send an e-mail to the author of the original post.'),
|
||||
'#required' => TRUE,
|
||||
);
|
||||
$form['cc'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('CC Recipient'),
|
||||
'#default_value' => $context['cc'],
|
||||
'#description' => t("The mail's carbon copy address. You may separate multiple addresses with comma."),
|
||||
'#required' => FALSE,
|
||||
);
|
||||
$form['bcc'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('BCC Recipient'),
|
||||
'#default_value' => $context['bcc'],
|
||||
'#description' => t("The mail's blind carbon copy address. You may separate multiple addresses with comma."),
|
||||
'#required' => FALSE,
|
||||
);
|
||||
$form['reply-to'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Reply e-mail address'),
|
||||
'#default_value' => $context['reply-to'],
|
||||
'#description' => t("The address to reply to. Leave it empty to use the sender's address."),
|
||||
'#required' => FALSE,
|
||||
);
|
||||
$form['subject'] = array(
|
||||
'#type' => 'textfield',
|
||||
'#title' => t('Subject'),
|
||||
'#maxlength' => 254,
|
||||
'#default_value' => $context['subject'],
|
||||
'#description' => t("The subject of the message."),
|
||||
);
|
||||
$form['body'] = array(
|
||||
'#type' => 'text_format',
|
||||
'#title' => t('Body'),
|
||||
'#default_value' => $context['body'],
|
||||
'#format' => $context['format'],
|
||||
'#description' => t('The HTML message that should be sent. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
|
||||
);
|
||||
$form['plaintext'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Plain text body'),
|
||||
'#default_value' => $context['plaintext'],
|
||||
'#description' => t('Optional plaintext portion of a multipart message. You may include placeholders like [node:title], [user:name], and [comment:body] to represent data that will be different each time message is sent. Not all placeholders will be available in all contexts.'),
|
||||
);
|
||||
$form['attachments'] = array(
|
||||
'#type' => 'textarea',
|
||||
'#title' => t('Attachments'),
|
||||
'#default_value' => $context['attachments'],
|
||||
'#description' => t('A list of attachments, one file per line e.g. "files/images/mypic.png" without quotes.'),
|
||||
);
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate the action form.
|
||||
*/
|
||||
function mimemail_send_email_action_validate($form, $form_state) {
|
||||
$to = trim($form_state['values']['to']);
|
||||
if (!valid_email_address($to) && strpos($to, ':mail') === FALSE) {
|
||||
form_set_error('to', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
|
||||
}
|
||||
|
||||
$cc = explode(',', $form_state['values']['cc']);
|
||||
foreach ($cc as $recipient) {
|
||||
$recipient = trim($recipient);
|
||||
if (!empty($recipient) && !valid_email_address($recipient) && strpos($recipient, ':mail') === FALSE) {
|
||||
form_set_error('cc', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
|
||||
}
|
||||
}
|
||||
|
||||
$bcc = explode(',', $form_state['values']['bcc']);
|
||||
foreach ($bcc as $recipient) {
|
||||
$recipient = trim($recipient);
|
||||
if (!empty($recipient) && !valid_email_address($recipient) && strpos($recipient, ':mail') === FALSE) {
|
||||
form_set_error('bcc', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
|
||||
}
|
||||
}
|
||||
|
||||
$reply_to = trim($form_state['values']['reply-to']);
|
||||
if (!empty($reply_to) && !valid_email_address($reply_to) && strpos($reply_to, ':mail') === FALSE) {
|
||||
form_set_error('reply-to', t('Enter a valid email address or use a token e-mail address such as %author.', array('%author' => '[node:author:mail]')));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle submission of the action form.
|
||||
*/
|
||||
function mimemail_send_email_action_submit($form, $form_state) {
|
||||
$form_values = $form_state['values'];
|
||||
|
||||
$params = array(
|
||||
'key' => $form_values['key'],
|
||||
'to' => $form_values['to'],
|
||||
'cc' => $form_values['cc'],
|
||||
'bcc' => $form_values['bcc'],
|
||||
'reply-to' => $form_values['reply-to'],
|
||||
'subject' => $form_values['subject'],
|
||||
'body' => $form_values['body']['value'],
|
||||
'format' => $form_values['body']['format'],
|
||||
'plaintext' => $form_values['plaintext'],
|
||||
'attachments' => $form_values['attachments'],
|
||||
);
|
||||
|
||||
return $params;
|
||||
}
|
@@ -0,0 +1,259 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Converts CSS styles into inline style attributes.
|
||||
*
|
||||
* Code based on Emogrifier by Pelago Design (http://www.pelagodesign.com).
|
||||
*/
|
||||
|
||||
/**
|
||||
* Separate CSS from HTML for processing
|
||||
*/
|
||||
function mimemail_compress_clean_message($message) {
|
||||
$parts = array();
|
||||
preg_match('|(<style[^>]+)>(.*)</style>|mis', $message, $matches);
|
||||
if (isset($matches[0]) && isset($matches[2])) {
|
||||
$css = str_replace('<!--', '', $matches[2]);
|
||||
$css = str_replace('-->', '', $css);
|
||||
$css = preg_replace('|\{|', "\n{\n", $css);
|
||||
$css = preg_replace('|\}|', "\n}\n", $css);
|
||||
$html = str_replace($matches[0], '', $message);
|
||||
$parts = array('html' => $html, 'css' => $css);
|
||||
}
|
||||
return $parts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compress HTML and CSS into combined message
|
||||
*/
|
||||
class mimemail_compress {
|
||||
private $html = '';
|
||||
private $css = '';
|
||||
private $unprocessable_tags = array('wbr');
|
||||
|
||||
public function mimemail_compress($html = '', $css = '') {
|
||||
$this->html = $html;
|
||||
$this->css = $css;
|
||||
}
|
||||
|
||||
// There are some HTML tags that DOMDocument cannot process,
|
||||
// and will throw an error if it encounters them.
|
||||
// These functions allow you to add/remove them if necessary.
|
||||
// It only strips them from the code (does not remove actual nodes).
|
||||
public function add_unprocessable_tag($tag) {
|
||||
$this->unprocessable_tags[] = $tag;
|
||||
}
|
||||
|
||||
public function remove_unprocessable_tag($tag) {
|
||||
if (($key = array_search($tag, $this->unprocessable_tags)) !== FALSE) {
|
||||
unset($this->unprocessableHTMLTags[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
public function compress() {
|
||||
if (!class_exists('DOMDocument', FALSE)) {
|
||||
return $this->html;
|
||||
}
|
||||
|
||||
$body = $this->html;
|
||||
// Process the CSS here, turning the CSS style blocks into inline CSS.
|
||||
if (count($this->unprocessable_tags)) {
|
||||
$unprocessable_tags = implode('|', $this->unprocessable_tags);
|
||||
$body = preg_replace("/<($unprocessable_tags)[^>]*>/i", '', $body);
|
||||
}
|
||||
|
||||
$err = error_reporting(0);
|
||||
$doc = new DOMDocument();
|
||||
|
||||
// Try to set character encoding.
|
||||
if (function_exists('mb_convert_encoding')) {
|
||||
$body = mb_convert_encoding($body, 'HTML-ENTITIES', "UTF-8");
|
||||
$doc->encoding= "UTF-8";
|
||||
}
|
||||
|
||||
$doc->strictErrorChecking = FALSE;
|
||||
$doc->formatOutput = TRUE;
|
||||
$doc->loadHTML($body);
|
||||
$doc->normalizeDocument();
|
||||
|
||||
$xpath = new DOMXPath($doc);
|
||||
|
||||
// Get rid of comments.
|
||||
$css = preg_replace('/\/\*.*\*\//sU', '', $this->css);
|
||||
|
||||
// Process the CSS file for selectors and definitions.
|
||||
preg_match_all('/^\s*([^{]+){([^}]+)}/mis', $css, $matches);
|
||||
|
||||
$all_selectors = array();
|
||||
foreach ($matches[1] as $key => $selector_string) {
|
||||
// If there is a blank definition, skip.
|
||||
if (!strlen(trim($matches[2][$key]))) continue;
|
||||
// Else split by commas and duplicate attributes so we can sort by selector precedence.
|
||||
$selectors = explode(',', $selector_string);
|
||||
foreach ($selectors as $selector) {
|
||||
// Don't process pseudo-classes.
|
||||
if (strpos($selector, ':') !== FALSE) continue;
|
||||
$all_selectors[] = array(
|
||||
'selector' => $selector,
|
||||
'attributes' => $matches[2][$key],
|
||||
'index' => $key, // Keep track of where it appears in the file, since order is important.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Now sort the selectors by precedence.
|
||||
usort($all_selectors, array('self', 'sort_selector_precedence'));
|
||||
|
||||
// Before we begin processing the CSS file, parse the document for inline
|
||||
// styles and append the normalized properties (i.e., 'display: none'
|
||||
// instead of 'DISPLAY: none') as selectors with full paths (highest
|
||||
// precedence), so they override any file-based selectors.
|
||||
$nodes = @$xpath->query('//*[@style]');
|
||||
if ($nodes->length > 0) {
|
||||
foreach ($nodes as $node) {
|
||||
$style = preg_replace_callback('/[A-z\-]+(?=\:)/S', create_function('$matches', 'return strtolower($matches[0]);'), $node->getAttribute('style'));
|
||||
$all_selectors[] = array(
|
||||
'selector' => $this->calculateXPath($node),
|
||||
'attributes' => $style,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($all_selectors as $value) {
|
||||
// Query the body for the xpath selector.
|
||||
$nodes = $xpath->query($this->css_to_xpath(trim($value['selector'])));
|
||||
|
||||
foreach ($nodes as $node) {
|
||||
// If it has a style attribute, get it, process it, and append (overwrite) new stuff.
|
||||
if ($node->hasAttribute('style')) {
|
||||
// Break it up into an associative array.
|
||||
$old_style = $this->css_style_to_array($node->getAttribute('style'));
|
||||
$new_style = $this->css_style_to_array($value['attributes']);
|
||||
// New styles overwrite the old styles (not technically accurate, but close enough).
|
||||
$compressed = array_merge($old_style, $new_style);
|
||||
$style = '';
|
||||
foreach ($compressed as $k => $v) {
|
||||
$style .= (drupal_strtolower($k) . ':' . $v . ';');
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Otherwise create a new style.
|
||||
$style = trim($value['attributes']);
|
||||
}
|
||||
$node->setAttribute('style', $style);
|
||||
}
|
||||
}
|
||||
|
||||
// This removes styles from your email that contain display:none. You could comment these out if you want.
|
||||
$nodes = $xpath->query('//*[contains(translate(@style," ",""), "display:none")]');
|
||||
foreach ($nodes as $node) {
|
||||
$node->parentNode->removeChild($node);
|
||||
}
|
||||
|
||||
if (variable_get('mimemail_preserve_class', 0) == FALSE) {
|
||||
$nodes = $xpath->query('//*[@class]');
|
||||
foreach ($nodes as $node) {
|
||||
$node->removeAttribute('class');
|
||||
}
|
||||
}
|
||||
|
||||
error_reporting($err);
|
||||
|
||||
return $doc->saveHTML();
|
||||
}
|
||||
|
||||
private static function sort_selector_precedence($a, $b) {
|
||||
$precedenceA = self::get_selector_precedence($a['selector']);
|
||||
$precedenceB = self::get_selector_precedence($b['selector']);
|
||||
|
||||
// We want these sorted ascendingly so selectors with lesser precedence get processed first and selectors with greater precedence get sorted last.
|
||||
return ($precedenceA == $precedenceB) ? ($a['index'] < $b['index'] ? -1 : 1) : ($precedenceA < $precedenceB ? -1 : 1);
|
||||
}
|
||||
|
||||
private static function get_selector_precedence($selector) {
|
||||
$precedence = 0;
|
||||
$value = 100;
|
||||
// Ids: worth 100, classes: worth 10, elements: worth 1.
|
||||
$search = array('\#', '\.', '');
|
||||
|
||||
foreach ($search as $s) {
|
||||
if (trim($selector == '')) break;
|
||||
$num = 0;
|
||||
$selector = preg_replace('/' . $s . '\w+/', '', $selector, -1, $num);
|
||||
$precedence += ($value * $num);
|
||||
$value /= 10;
|
||||
}
|
||||
|
||||
return $precedence;
|
||||
}
|
||||
|
||||
/**
|
||||
* Right now we only support CSS 1 selectors, but include CSS2/3 selectors are fully possible.
|
||||
*
|
||||
* @see http://plasmasturm.org/log/444
|
||||
*/
|
||||
private function css_to_xpath($selector) {
|
||||
if (drupal_substr($selector, 0, 1) == '/') {
|
||||
// Already an XPath expression.
|
||||
return $selector;
|
||||
}
|
||||
// Returns an Xpath selector.
|
||||
$search = array(
|
||||
'/\s+>\s+/', // Matches any F element that is a child of an element E.
|
||||
'/(\w+)\s+\+\s+(\w+)/', // Matches any F element that is a child of an element E.
|
||||
'/\s+/', // Matches any F element that is a descendant of an E element.
|
||||
'/(\w)\[(\w+)\]/', // Matches element with attribute.
|
||||
'/(\w)\[(\w+)\=[\'"]?(\w+)[\'"]?\]/', // Matches element with EXACT attribute.
|
||||
'/(\w+)?\#([\w\-]+)/e', // Matches id attributes.
|
||||
'/(\w+|\*)?((\.[\w\-]+)+)/e', // Matches class attributes.
|
||||
);
|
||||
$replace = array(
|
||||
'/',
|
||||
'\\1/following-sibling::*[1]/self::\\2',
|
||||
'//',
|
||||
'\\1[@\\2]',
|
||||
'\\1[@\\2="\\3"]',
|
||||
"(strlen('\\1') ? '\\1' : '*').'[@id=\"\\2\"]'",
|
||||
"(strlen('\\1') ? '\\1' : '*').'[contains(concat(\" \",normalize-space(@class),\" \"),concat(\" \",\"'.implode('\",\" \"))][contains(concat(\" \",normalize-space(@class),\" \"),concat(\" \",\"',explode('.',substr('\\2',1))).'\",\" \"))]'",
|
||||
);
|
||||
return '//' . preg_replace($search, $replace, trim($selector));
|
||||
}
|
||||
|
||||
private function css_style_to_array($style) {
|
||||
$definitions = explode(';', $style);
|
||||
$css_styles = array();
|
||||
foreach ($definitions as $def) {
|
||||
if (empty($def) || strpos($def, ':') === FALSE) continue;
|
||||
list($key, $value) = explode(':', $def, 2);
|
||||
if (empty($key) || empty($value)) continue;
|
||||
$css_styles[trim($key)] = trim($value);
|
||||
}
|
||||
return $css_styles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the full path to a DOM node.
|
||||
*
|
||||
* @param DOMNode $node
|
||||
* The node to analyze.
|
||||
*
|
||||
* @return string
|
||||
* The full xpath to a DOM node.
|
||||
*
|
||||
* @see http://stackoverflow.com/questions/2643533/php-getting-xpath-of-a-domnode
|
||||
*/
|
||||
function calculateXPath(DOMNode $node) {
|
||||
$xpath = '';
|
||||
$q = new DOMXPath($node->ownerDocument);
|
||||
|
||||
do {
|
||||
$position = 1 + $q->query('preceding-sibling::*[name()="' . $node->nodeName . '"]', $node)->length;
|
||||
$xpath = '/' . $node->nodeName . '[' . $position . ']' . $xpath;
|
||||
$node = $node->parentNode;
|
||||
}
|
||||
while (!$node instanceof DOMDocument);
|
||||
|
||||
return $xpath;
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
name = Mime Mail CSS Compressor
|
||||
description = Converts CSS to inline styles in an HTML message. (Requires the PHP DOM extension.)
|
||||
package = Mail
|
||||
dependencies[] = mimemail
|
||||
core = 7.x
|
||||
|
||||
files[] = mimemail_compress.inc
|
||||
|
||||
; Information added by drupal.org packaging script on 2013-09-06
|
||||
version = "7.x-1.0-alpha2+30-dev"
|
||||
core = "7.x"
|
||||
project = "mimemail"
|
||||
datestamp = "1378431585"
|
||||
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Install, update and uninstall functions for Mime Mail Compress module.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements hook_requirements().
|
||||
*/
|
||||
function mimemail_compress_requirements($phase) {
|
||||
$requirements = array();
|
||||
// Ensure translations don't break at install time.
|
||||
$t = get_t();
|
||||
|
||||
// Test PHP DOM extension.
|
||||
if (extension_loaded('dom')) {
|
||||
$requirements['dom']['value'] = $t('Enabled');
|
||||
}
|
||||
else {
|
||||
$requirements['dom'] = array(
|
||||
'description' => $t('Mime Mail Compress requires the PHP DOM extension to be enabled.'),
|
||||
'severity' => REQUIREMENT_ERROR,
|
||||
'value' => $t('Disabled'),
|
||||
);
|
||||
}
|
||||
|
||||
$requirements['dom']['title'] = $t('PHP DOM extension');
|
||||
|
||||
return $requirements;
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Component module for sending Mime-encoded emails.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implements mail_post_process().
|
||||
*/
|
||||
function mimemail_compress_mail_post_process(&$message, $mailkey) {
|
||||
module_load_include('inc', 'mimemail_compress');
|
||||
// Separate CSS from HTML for processing.
|
||||
$parts = mimemail_compress_clean_message($message);
|
||||
// Compress HTML and CSS into combined message.
|
||||
if (!empty($parts)) {
|
||||
$output = new mimemail_compress($parts['html'], $parts['css']);
|
||||
$output = $output->compress();
|
||||
$message = $output;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user