function _subscriptions_mail_mail_alter in Subscriptions 7
Same name and namespace in other branches
- 2.0.x subscriptions_mail/subscriptions_mail.cron.inc \_subscriptions_mail_mail_alter()
Implements hook_mail_alter().
Optionally change links to use HTTPS, but only for Subscriptions mails.
Parameters
$message:
1 call to _subscriptions_mail_mail_alter()
- subscriptions_mail_mail_alter in ./
subscriptions_mail.module - Implements hook_mail_alter().
File
- ./
subscriptions_mail.cron.inc, line 353 - Subscriptions module mail gateway (cron functions).
Code
function _subscriptions_mail_mail_alter(array &$message) {
global $user;
static $site_url = NULL;
static $replacement;
if (!isset($site_url)) {
$site_url = url('', array(
'absolute' => TRUE,
));
if (_subscriptions_get_setting('secure_links', $user) > 0) {
if (strpos($site_url, 'http:') === 0) {
$site_url = $replacement[$site_url] = 'https:' . substr($site_url, 5);
}
}
else {
if (strpos($site_url, 'https:') === 0) {
$site_url = $replacement[$site_url] = 'http:' . substr($site_url, 6);
}
}
}
if (!empty($replacement)) {
$msg = strtr($message['body'][0], $replacement);
while (preg_match("#(?P<before>(.*)(<[aA] +)(href|HREF)=([\"']))/(?P<after>.*)\$#sAD", $msg, $matches)) {
$msg = $matches['before'] . $site_url . $matches['after'];
}
while (preg_match("#(?P<before>(.*)<(img|IMG) +(src|SRC)=([\"']))/(?P<after>.*)\$#sAD", $msg, $matches)) {
$msg = $matches['before'] . $site_url . $matches['after'];
}
$message['body'][0] = $msg;
}
$message['body'][0] = _subscriptions_mail_add_mailkey($message['body'][0], $message['id'], $message['language']->language);
/* Comment this line for debugging...
dpm($message, 'drupal_mail() is disabled in subscriptions_mail_mail_alter(); this would be sent');
$message['to'] = '';
/**/
}