| 1 |
<?php
|
| 2 |
// $Id: subscriptions_mail.module,v 1.29 2009/09/28 11:01:59 salvis Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Subscriptions module mail gateway.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_menu().
|
| 11 |
*
|
| 12 |
* Registers a callback to purge the queue.
|
| 13 |
*/
|
| 14 |
function subscriptions_mail_menu() {
|
| 15 |
$items['admin/settings/subscriptions/purge-queue'] = array(
|
| 16 |
'file' => 'subscriptions_mail.admin.inc',
|
| 17 |
'page callback' => 'drupal_get_form',
|
| 18 |
'page arguments' => array('_subscriptions_mail_purge_queue_form'),
|
| 19 |
'access arguments' => array('administer site configuration'),
|
| 20 |
'type' => MENU_CALLBACK,
|
| 21 |
);
|
| 22 |
return $items;
|
| 23 |
}
|
| 24 |
|
| 25 |
/**
|
| 26 |
* Implementation of hook_cron().
|
| 27 |
*
|
| 28 |
* Takes items from {subscriptions_queue} and generates notification emails.
|
| 29 |
*/
|
| 30 |
function subscriptions_mail_cron() {
|
| 31 |
|
| 32 |
// set_time_limit(3600); drupal_set_message('DON\'T FORGET TO REMOVE THE TIME LIMIT EXTENSION!!!');
|
| 33 |
|
| 34 |
include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.cron.inc';
|
| 35 |
_subscriptions_mail_cron();
|
| 36 |
}
|
| 37 |
|
| 38 |
/**
|
| 39 |
* Return the 'From:' address to use for sending e-mail.
|
| 40 |
*/
|
| 41 |
function _subscriptions_mail_site_mail($address_only = FALSE) {
|
| 42 |
$email = variable_get('subscriptions_site_mail', '');
|
| 43 |
if (empty($email)) {
|
| 44 |
$email = variable_get('site_mail', ini_get('sendmail_from'));
|
| 45 |
}
|
| 46 |
if (!$address_only && ($name = variable_get('subscriptions_site_mail_name', FALSE))) {
|
| 47 |
$email = '"'. $name .'" <'. $email .'>';
|
| 48 |
}
|
| 49 |
return $email;
|
| 50 |
}
|
| 51 |
|
| 52 |
/**
|
| 53 |
* Implementation of hook_form_alter().
|
| 54 |
*
|
| 55 |
* Adds to the Mail templates form at admin/build/mail-edit if old D5 tables are found.
|
| 56 |
*/
|
| 57 |
function subscriptions_mail_form_mail_edit_list_form_alter(&$form, $form_state) {
|
| 58 |
if (db_table_exists('subscriptions_mail_edit') ||
|
| 59 |
db_table_exists('mail_edit_d5') && db_result(db_query("SELECT COUNT(*) FROM {mail_edit_d5} WHERE mailkey LIKE 'subscriptions-%'")) > 0) {
|
| 60 |
include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.mail_edit_D5.inc';
|
| 61 |
_subscriptions_mail_form_mail_edit_list_form_alter($form, $form_state);
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
/**
|
| 66 |
* Implementation of hook_form_alter().
|
| 67 |
*
|
| 68 |
* Adds to the General Settings part at admin/settings/subscriptions.
|
| 69 |
*/
|
| 70 |
function subscriptions_mail_form_subscriptions_settings_form_alter(&$form, &$form_state) {
|
| 71 |
include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.admin.inc';
|
| 72 |
_subscriptions_mail_form_subscriptions_settings_form_alter($form, $form_state);
|
| 73 |
}
|
| 74 |
|
| 75 |
/**
|
| 76 |
* Form builder for the purge Subscriptions queue confirmation form.
|
| 77 |
*/
|
| 78 |
function _subscriptions_mail_purge_queue_form(&$form_state) {
|
| 79 |
$form['#submit'][] = 'subscriptions_purge_queue';
|
| 80 |
return confirm_form($form, t('Are you sure you want to purge the !Module queue?', array('!Module' => 'Subscriptions')), array('path' => $_GET['destination'], 'fragment' => 'edit-purge-queue'), NULL, t('Purge the queue'));
|
| 81 |
}
|
| 82 |
|
| 83 |
/**
|
| 84 |
* Purge the Subscriptions queue.
|
| 85 |
*/
|
| 86 |
function subscriptions_purge_queue() {
|
| 87 |
db_query("DELETE FROM {subscriptions_queue}");
|
| 88 |
$variables = array('!Module' => 'Subscriptions', '%count' => db_affected_rows());
|
| 89 |
drupal_set_message(t('All %count items have been purged.', $variables));
|
| 90 |
$watchdog = 'watchdog'; // keep potx from translating 'cron'
|
| 91 |
$watchdog('cron', t('!Module: all %count items have been purged.', $variables), NULL, WATCHDOG_WARNING);
|
| 92 |
}
|
| 93 |
|
| 94 |
/**
|
| 95 |
* Implementation of hook_mailkeys().
|
| 96 |
*
|
| 97 |
* Provide mailkeys for mail_edit.
|
| 98 |
*
|
| 99 |
* @ingroup hooks
|
| 100 |
*/
|
| 101 |
function subscriptions_mail_mailkeys() {
|
| 102 |
$mailkeys['digest'] = t('Digest subscriptions notifications');
|
| 103 |
return $mailkeys;
|
| 104 |
}
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Implementation of hook_mail_edit_tokens_list().
|
| 108 |
*
|
| 109 |
* Provide replacable tokens for mail_edit.
|
| 110 |
*
|
| 111 |
* @ingroup hooks
|
| 112 |
*/
|
| 113 |
function subscriptions_mail_mail_edit_tokens_list($mailkey, $options = array()) {
|
| 114 |
//$tokens = module_invoke('subscriptions_content', 'mail_edit_tokens_list', $mailkey, $options);
|
| 115 |
$tokens = subscriptions_mail_subscriptions_tokens_list($mailkey, $options);
|
| 116 |
$tokens += array(
|
| 117 |
'!bodies' => t('The digested items (separated by a separator), as defined below:'),
|
| 118 |
);
|
| 119 |
return $tokens;
|
| 120 |
}
|
| 121 |
|
| 122 |
/**
|
| 123 |
* Implementation of hook_subscriptions_tokens_list().
|
| 124 |
*
|
| 125 |
* Provide replacable tokens for mail_edit.
|
| 126 |
* mail_edit calls only the hook in the module that registered the mailkey,
|
| 127 |
* but we call this hook function from there to add some common tokens.
|
| 128 |
*
|
| 129 |
* @ingroup hooks
|
| 130 |
*/
|
| 131 |
function subscriptions_mail_subscriptions_tokens_list($mailkey, $options = array()) {
|
| 132 |
$tokens = array();
|
| 133 |
switch ($mailkey) {
|
| 134 |
case 'digest':
|
| 135 |
break;
|
| 136 |
default:
|
| 137 |
$tokens += array(
|
| 138 |
'!site' => t('The name of the site.'),
|
| 139 |
'!recipient_name' => t('Name of the recipient.'),
|
| 140 |
'!recipient_page' => t('The user page of the recipient.'),
|
| 141 |
'!manage_url' => t('The URL where the user can manage her subscriptions.'),
|
| 142 |
);
|
| 143 |
}
|
| 144 |
if (isset($options['tokens'])) {
|
| 145 |
$tokens += $options['tokens'];
|
| 146 |
}
|
| 147 |
return $tokens;
|
| 148 |
}
|
| 149 |
|
| 150 |
/**
|
| 151 |
* Implementation of hook_mail_edit_text().
|
| 152 |
*
|
| 153 |
* Provide default templates for mail_edit.
|
| 154 |
*
|
| 155 |
* @ingroup hooks
|
| 156 |
*/
|
| 157 |
function subscriptions_mail_mail_edit_text($mailkey, $language) {
|
| 158 |
include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.templates.inc';
|
| 159 |
$return = array();
|
| 160 |
$return['subject'] = subscriptions_mail_template('DSUBJ', $language->language);
|
| 161 |
$return['body'] = subscriptions_mail_template('DBODY', $language->language);
|
| 162 |
return $return;
|
| 163 |
}
|
| 164 |
|
| 165 |
/**
|
| 166 |
* Implementation of hook_subscriptions_mail_text().
|
| 167 |
*
|
| 168 |
* Provide default templates for mail_edit.
|
| 169 |
*
|
| 170 |
* @ingroup hooks
|
| 171 |
*/
|
| 172 |
function subscriptions_mail_subscriptions_mail_text($mailkey, $language) {
|
| 173 |
include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.templates.inc';
|
| 174 |
$return = array();
|
| 175 |
$return['subject'] = subscriptions_mail_template('SUBJ', $language->language);
|
| 176 |
$return['body'] = subscriptions_mail_template('BODY', $language->language);
|
| 177 |
return $return;
|
| 178 |
}
|
| 179 |
|
| 180 |
/**
|
| 181 |
* Implementation of hook_form_alter().
|
| 182 |
*
|
| 183 |
* Add the digest parts to the subscriptions_mail_digest mail_edit page.
|
| 184 |
*
|
| 185 |
* @ingroup hooks
|
| 186 |
* @ingroup form
|
| 187 |
*/
|
| 188 |
function subscriptions_mail_form_mail_edit_trans_alter(&$form, &$form_state) {
|
| 189 |
|
| 190 |
include_once drupal_get_path('module', 'subscriptions_mail') .'/subscriptions_mail.admin.inc';
|
| 191 |
_subscriptions_mail_form_mail_edit_trans_alter($form, $form_state);
|
| 192 |
}
|
| 193 |
|
| 194 |
/**
|
| 195 |
* Get the sanitized value of the 'subscriptions_cron_percent' variable.
|
| 196 |
*/
|
| 197 |
function subscriptions_mail_get_cron_percentage() {
|
| 198 |
return max(array(0, intval(variable_get('subscriptions_cron_percent', 50))));
|
| 199 |
}
|
| 200 |
|