View source
<?php
define('SIMPLENEWS_PRIORITY_NONE', 0);
define('SIMPLENEWS_PRIORITY_HIGHEST', 1);
define('SIMPLENEWS_PRIORITY_HIGH', 2);
define('SIMPLENEWS_PRIORITY_NORMAL', 3);
define('SIMPLENEWS_PRIORITY_LOW', 4);
define('SIMPLENEWS_PRIORITY_LOWEST', 5);
define('SIMPLENEWS_COMMAND_SEND_NONE', 0);
define('SIMPLENEWS_COMMAND_SEND_NOW', 1);
define('SIMPLENEWS_COMMAND_SEND_TEST', 2);
define('SIMPLENEWS_STATUS_SEND_NOT', 0);
define('SIMPLENEWS_STATUS_SEND_PENDING', 1);
define('SIMPLENEWS_STATUS_SEND_READY', 2);
define('SIMPLENEWS_SPOOL_HOLD', 0);
define('SIMPLENEWS_SPOOL_PENDING', 1);
define('SIMPLENEWS_SPOOL_DONE', 2);
define('SIMPLENEWS_SEND_CHECK_INTERVAL', 100);
define('SIMPLENEWS_SEND_TIME_LIMIT', 0.8);
define('SIMPLENEWS_MAX_EXECUTION_TIME', ini_get('max_execution_time'));
function simplenews_perm() {
return array(
'administer newsletters',
'administer simplenews subscriptions',
'administer simplenews settings',
'send newsletter',
'subscribe to newsletters',
);
}
function simplenews_init() {
drupal_add_css(drupal_get_path('module', 'simplenews') . '/simplenews.css', 'module', 'all', TRUE);
if (variable_get('simplenews_vid', '') == '') {
drupal_set_message(t('Missing newsletter vocabulary. Please set a vocabulary at <a href="@settings">Simplenews settings</a>.', array(
'@settings' => url('admin/settings/simplenews/general'),
)), 'error');
}
}
function simplenews_menu() {
$items['admin/content/simplenews'] = array(
'title' => 'Newsletters',
'description' => 'Manage newsletters and subscriptions.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'system_admin_menu_block_page',
'access callback' => 'simplenews_newsletter_access',
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/content/simplenews/sent'] = array(
'title' => 'Sent issues',
'description' => 'List of newsletter issues sent and pending.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_news',
),
'access arguments' => array(
'administer newsletters',
),
'file' => 'simplenews.admin.inc',
'weight' => -10,
);
$items['admin/content/simplenews/notsent'] = array(
'title' => 'Draft issues',
'description' => 'List of newsletter issues not sent.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_news',
'notsent',
),
'access arguments' => array(
'administer newsletters',
),
'file' => 'simplenews.admin.inc',
'weight' => -9,
);
$items['admin/content/simplenews/types'] = array(
'title' => 'Newsletters',
'description' => 'List, add and edit newsletter series.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'simplenews_types_overview',
'access arguments' => array(
'administer newsletters',
),
'file' => 'simplenews.admin.inc',
'weight' => -8,
);
$items['admin/content/simplenews/types/edit/%'] = array(
'title' => 'Newsletters',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_types_form',
5,
),
'access arguments' => array(
'administer newsletters',
),
'file' => 'simplenews.admin.inc',
);
$items['admin/content/simplenews/types/delete/%'] = array(
'title' => 'Newsletters',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_types_delete',
5,
),
'access arguments' => array(
'administer newsletters',
),
'file' => 'simplenews.admin.inc',
);
$items['admin/content/simplenews/types/list'] = array(
'title' => 'List newsletters',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/content/simplenews/types/add'] = array(
'title' => 'Add newsletter',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_types_form',
),
'access arguments' => array(
'administer newsletters',
),
'file' => 'simplenews.admin.inc',
'weight' => -9,
);
$items['admin/content/simplenews/subscriptions/delete'] = array(
'title' => 'Delete',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_subscription_multiple_delete_confirm',
),
'access arguments' => array(
'administer simplenews subscriptions',
),
'file' => 'simplenews.admin.inc',
);
$items['admin/content/simplenews/users'] = array(
'title' => 'Subscriptions',
'description' => 'Newsletter subscription management.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_subscription_admin',
),
'access arguments' => array(
'administer simplenews subscriptions',
),
'file' => 'simplenews.admin.inc',
'weight' => -7,
);
$items['admin/content/simplenews/users/edit/%'] = array(
'title' => 'Subscriptions',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_users_form',
5,
),
'access arguments' => array(
'administer simplenews subscriptions',
),
'file' => 'simplenews.subscription.inc',
);
$items['admin/content/simplenews/users/list'] = array(
'title' => 'List',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/content/simplenews/users/import'] = array(
'title' => 'Mass subscribe',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_subscription_list_add',
),
'access arguments' => array(
'administer simplenews subscriptions',
),
'file' => 'simplenews.admin.inc',
'weight' => -9,
);
$items['admin/content/simplenews/users/export'] = array(
'title' => 'Export',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_subscription_list_export',
),
'access arguments' => array(
'administer simplenews subscriptions',
),
'file' => 'simplenews.admin.inc',
'weight' => -7,
);
$items['admin/content/simplenews/users/unsubscribe'] = array(
'title' => 'Mass unsubscribe',
'type' => MENU_LOCAL_TASK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_subscription_list_remove',
),
'access arguments' => array(
'administer simplenews subscriptions',
),
'file' => 'simplenews.admin.inc',
'weight' => -8,
);
$items['admin/settings/simplenews'] = array(
'title' => 'Simplenews',
'description' => 'Manage simplenews configuration.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'system_admin_menu_block_page',
'access arguments' => array(
'administer simplenews settings',
),
'file' => 'system.admin.inc',
'file path' => drupal_get_path('module', 'system'),
);
$items['admin/settings/simplenews/general'] = array(
'title' => 'General',
'description' => 'Simplenews content type and vocabulary settings.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_settings',
),
'access arguments' => array(
'administer simplenews settings',
),
'file' => 'simplenews.admin.inc',
'weight' => -10,
);
$items['admin/settings/simplenews/newsletter'] = array(
'title' => 'Newsletter',
'description' => 'Newsletter default settings and sender data.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_settings_newsletter',
),
'access arguments' => array(
'administer simplenews settings',
),
'file' => 'simplenews.admin.inc',
'weight' => -9,
);
$items['admin/settings/simplenews/subscription'] = array(
'title' => 'Subscription',
'description' => 'Subscription settings, opt-in/out confirmation email text.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_settings_subscription',
),
'access arguments' => array(
'administer simplenews settings',
),
'file' => 'simplenews.admin.inc',
'weight' => -8,
);
$items['admin/settings/simplenews/mail'] = array(
'title' => 'Send mail',
'description' => 'Send mail, cron and debug options.',
'type' => MENU_NORMAL_ITEM,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_admin_settings_mail',
),
'access arguments' => array(
'administer simplenews settings',
),
'file' => 'simplenews.admin.inc',
'weight' => -7,
);
$items['newsletter/confirm'] = array(
'title' => 'Confirm newsletter subscriptions',
'type' => MENU_CALLBACK,
'page callback' => 'simplenews_confirm_subscription',
'access arguments' => array(
'subscribe to newsletters',
),
'file' => 'simplenews.subscription.inc',
);
$items['newsletter/subscriptions'] = array(
'title' => 'Manage newsletter subscriptions',
'type' => MENU_CALLBACK,
'page callback' => 'drupal_get_form',
'page arguments' => array(
'simplenews_subscription_manager_form',
),
'access arguments' => array(
'subscribe to newsletters',
),
'file' => 'simplenews.subscription.inc',
);
return $items;
}
function simplenews_newsletter_access() {
return user_access('administer newsletters') || user_access('administer simplenews subscriptions');
}
function simplenews_node_type($op, $info) {
switch ($op) {
case 'delete':
$simplenews_types = variable_get('simplenews_content_types', array());
if (isset($simplenews_types[$info->type])) {
unset($simplenews_types[$info->type]);
variable_set('simplenews_content_types', $simplenews_types);
}
break;
case 'update':
$simplenews_types = variable_get('simplenews_content_types', array());
if (isset($info->old_type) && isset($simplenews_types[$info->old_type]) && $info->old_type != $info->type) {
unset($simplenews_types[$info->old_type]);
$simplenews_types[$info->type] = $info->type;
variable_set('simplenews_content_types', $simplenews_types);
}
break;
}
}
function simplenews_nodeapi(&$node, $op, $teaser, $page) {
global $user;
if (!in_array($node->type, variable_get('simplenews_content_types', array(
'simplenews',
)))) {
return;
}
switch ($op) {
case 'alter':
if (!isset($node->simplenews_mail)) {
global $language;
$context['node'] = $node;
$variables = simplenews_mail_tokens($user, $context, $language);
if (isset($node->body)) {
$node->body = strtr($node->body, $variables);
}
if (isset($node->teaser)) {
$node->teaser = strtr($node->teaser, $variables);
}
}
break;
case 'validate':
$vid = variable_get('simplenews_vid', '');
if (!isset($node->taxonomy[$vid]) || empty($node->taxonomy[$vid]) || simplenews_validate_taxonomy($node->taxonomy) == FALSE) {
form_set_error('taxonomy', t('No newsletter term is selected, the newsletter taxonomy term is probably not configured correctly.<br /> Check and <strong>save</strong> the <a href="@settings">Simplenews general settings</a>.', array(
'%name' => $vocabulary->name,
'@settings' => url('admin/settings/simplenews/general'),
)));
}
elseif (isset($node->simplenews['send']) && $node->simplenews['send'] == SIMPLENEWS_COMMAND_SEND_TEST) {
if (!empty($node->simplenews['test_address'])) {
$mails = explode(',', $node->simplenews['test_address']);
foreach ($mails as $mail) {
$mail = trim($mail);
if ($mail == '') {
form_set_error('simplenews][test_address', t('Test email address is empty.'));
}
elseif (!valid_email_address($mail)) {
form_set_error('simplenews][test_address', t('Invalid email address %mail.', array(
'%mail' => $mail,
)));
}
}
}
else {
form_set_error('simplenews][test_address', t('Missing test email address.'));
}
}
break;
case 'presave':
$term = simplenews_validate_taxonomy($node->taxonomy);
$tid = is_array($term) ? array_values($term) : FALSE;
$node->simplenews['tid'] = $tid ? $tid[0] : 0;
break;
case 'insert':
case 'update':
$node->simplenews = _simplenews_flatten_array($node->simplenews);
$send_with_permission = $node->simplenews['send'] == SIMPLENEWS_COMMAND_SEND_NOW && user_access('send newsletter');
if ($op == 'insert') {
$s_status = $send_with_permission ? SIMPLENEWS_STATUS_SEND_PENDING : SIMPLENEWS_STATUS_SEND_NOT;
db_query("INSERT INTO {simplenews_newsletters} (nid, vid, tid, s_status, s_format, priority, receipt)\n VALUES (%d, %d, %d, %d, '%s', %d, %d)", $node->nid, $node->vid, $node->simplenews['tid'], $s_status, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt']);
}
else {
if ($send_with_permission) {
db_query("UPDATE {simplenews_newsletters} SET vid = %d, tid = %d, s_status = %d, s_format = '%s', priority = %d, receipt = %d\n WHERE nid = %d", $node->vid, $node->simplenews['tid'], SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid);
}
else {
db_query("UPDATE {simplenews_newsletters} SET tid = %d, s_format = '%s', priority = %d, receipt = %d\n WHERE nid = %d", $node->simplenews['tid'], $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $node->nid);
}
}
if (module_exists('translation') && translation_supported_type($node->type) && $send_with_permission) {
if ($translations = translation_node_get_translations($node->tnid)) {
foreach ($translations as $translation) {
db_query("UPDATE {simplenews_newsletters} SET s_status = %d, s_format = '%s', priority = %d, receipt = %d\n WHERE nid = %d", SIMPLENEWS_STATUS_SEND_PENDING, $node->simplenews['s_format'], $node->simplenews['priority'], $node->simplenews['receipt'], $translation->nid);
}
}
}
if ($send_with_permission) {
simplenews_send_node($node);
}
elseif ($node->simplenews['send'] == SIMPLENEWS_COMMAND_SEND_TEST) {
simplenews_send_test($node);
}
break;
case 'delete':
$result = db_query('DELETE FROM {simplenews_newsletters} WHERE nid = %d', $node->nid);
if ($result) {
drupal_set_message(t('Newsletter %title was deleted.', array(
'%title' => $node->title,
)));
}
break;
case 'load':
$node->simplenews = db_fetch_array(db_query('SELECT * FROM {simplenews_newsletters} WHERE nid = %d', $node->nid));
break;
}
}
function simplenews_validate_taxonomy($taxonomy) {
$vid = variable_get('simplenews_vid', '');
$result = db_query('SELECT tid FROM {term_data} WHERE vid = %d', $vid);
while ($tid = db_fetch_object($result)) {
$newsletter_tids[] = $tid->tid;
}
if (isset($newsletter_tids) && !empty($taxonomy)) {
$selected_terms = array();
if (is_array($taxonomy)) {
foreach ($taxonomy as $term) {
if (is_array($term)) {
foreach ($term as $tid) {
if ($tid) {
$selected_terms[] = $tid;
}
}
}
else {
if (is_object($term)) {
$selected_terms[] = $term->tid;
}
else {
if ($term) {
$selected_terms[] = $term;
}
}
}
}
}
$valid_terms = array_intersect($newsletter_tids, $selected_terms);
return empty($valid_terms) ? FALSE : $valid_terms;
}
return FALSE;
}
function simplenews_form_alter(&$form, $form_state, $form_id) {
$vid = variable_get('simplenews_vid', '');
if ($form_id == 'taxonomy_form_vocabulary' && isset($form['vid']) && $form['vid']['#value'] == $vid) {
$form['help_simplenews_vocab'] = array(
'#value' => t('This is the designated simplenews vocabulary.'),
'#weight' => -1,
);
$form['content_types']['display_only'] = $form['content_types']['nodes'];
$form['content_types']['display_only']['#disabled'] = TRUE;
$form['content_types']['display_only']['#description'] = t('These content type(s) are used as newsletter. They can be set in !simplenews_settings.', array(
'!simplenews_settings' => l('Simplenews settings', 'admin/settings/simplenews'),
));
$form['content_types']['nodes'] = array(
'#type' => 'value',
'#value' => $form['content_types']['nodes']['#default_value'],
);
$form['settings']['tags'] = array(
'#type' => 'value',
'#value' => FALSE,
);
$form['settings']['multiple'] = array(
'#type' => 'value',
'#value' => FALSE,
);
$form['settings']['required'] = array(
'#type' => 'value',
'#value' => TRUE,
);
}
elseif (isset($form['type']) && isset($form['#node']) && strpos($form_id, '_node_form')) {
if (in_array($form['type']['#value'], variable_get('simplenews_content_types', array(
'simplenews',
)))) {
if (isset($form['body_field'])) {
$form['body_field']['body']['#description'] = t("This will be the body of your newsletter. Available variables are: !site (the name of your website), !uri (a link to your homepage), !uri_brief (homepage link without the http://), !date (today's date), !login_uri (link to login page), !confirm_subscribe_url (subscription confirmation link), !confirm_unsubscribe_url (unsubscription link), !newsletter_url (link to this newsletter issue), !newsletter_name (name of this newsletter series).");
}
if (isset($form['#node']->simplenews)) {
$simplenews_values = $form['#node']->simplenews;
}
$vocabulary = taxonomy_vocabulary_load(variable_get('simplenews_vid', ''));
if (!empty($vocabulary) && !isset($vocabulary->nodes[$form['type']['#value']])) {
drupal_set_message(t('Invalid vocabulary setting detected. Check and <strong>save</strong> the <a href="@settings">Simplenews general settings</a>.', array(
'%name' => $vocabulary->name,
'@settings' => url('admin/settings/simplenews'),
)), 'error');
}
$form['simplenews'] = array(
'#type' => 'fieldset',
'#title' => t('Send newsletter'),
'#collapsible' => TRUE,
'#collapsed' => FALSE,
'#tree' => TRUE,
);
if (module_exists('translation') && translation_supported_type($form['#node']->type) && (isset($form['#node']->translation_source) || $form['#node']->tnid && $form['#node']->tnid != $form['#node']->nid)) {
$form['simplenews']['#description'] = t('This newsletter issue is part of a translation set. Sending this set is controlled from the <a href="@link">translation source newsletter</a>.', array(
'@link' => url('node/' . $form['tnid']['#value']),
));
$form['simplenews']['send'] = array(
'#type' => 'hidden',
'#value' => SIMPLENEWS_COMMAND_SEND_NONE,
);
$form['simplenews']['advanced']['s_format'] = array(
'#type' => 'hidden',
'#value' => variable_get('simplenews_format', 'plain'),
);
$form['simplenews']['advanced']['priority'] = array(
'#type' => 'hidden',
'#value' => variable_get('simplenews_priority', SIMPLENEWS_PRIORITY_NONE),
);
$form['simplenews']['advanced']['receipt'] = array(
'#type' => 'hidden',
'#value' => variable_get('simplenews_receipt', 0),
);
}
else {
if (!isset($simplenews_values['s_status']) || isset($simplenews_values['s_status']) && $simplenews_values['s_status'] == SIMPLENEWS_STATUS_SEND_NOT) {
drupal_add_js(drupal_get_path('module', 'simplenews') . '/simplenews.js', 'module');
if (user_access('send newsletter')) {
$options[SIMPLENEWS_COMMAND_SEND_NONE] = t("Don't send now");
$options[SIMPLENEWS_COMMAND_SEND_TEST] = t('Send one test newsletter to the test address');
$options[SIMPLENEWS_COMMAND_SEND_NOW] = t('Send newsletter');
$form['simplenews']['send'] = array(
'#type' => 'radios',
'#title' => t('Send action'),
'#default_value' => isset($simplenews_values['send']) ? $simplenews_values['send'] : variable_get('simplenews_send', SIMPLENEWS_COMMAND_SEND_NONE),
'#options' => $options,
'#attributes' => array(
'class' => 'simplenews-command-send',
),
);
}
else {
$options[SIMPLENEWS_COMMAND_SEND_NONE] = t("Don't send now");
$options[SIMPLENEWS_COMMAND_SEND_TEST] = t('Send one test newsletter to the test address');
$form['simplenews']['send'] = array(
'#type' => 'radios',
'#title' => t('Sending'),
'#default_value' => isset($simplenews_values['send']) ? $simplenews_values['send'] : SIMPLENEWS_COMMAND_SEND_NONE,
'#options' => $options,
'#description' => t('You have no privileges to send this newsletter'),
'#attributes' => array(
'class' => 'simplenews-command-send',
),
);
}
$address_default = variable_get('site_mail', ini_get('sendmail_from'));
if (variable_get('simplenews_test_address_override', 0)) {
$form['simplenews']['test_address'] = array(
'#type' => 'textfield',
'#title' => t('Test email addresses'),
'#description' => t('Supply a comma-separated list of email addresses to be used as test addresses.'),
'#default_value' => isset($simplenews_values['test_address']) ? $simplenews_values['test_address'] : variable_get('simplenews_test_address', $address_default),
'#size' => 60,
'#maxlength' => 128,
);
}
else {
$form['simplenews']['test_address'] = array(
'#type' => 'hidden',
'#value' => variable_get('simplenews_test_address', $address_default),
);
}
$form['simplenews']['advanced'] = array(
'#type' => 'fieldset',
'#title' => t('Email options'),
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);
$format_options = _simplenews_format_options();
if (count($format_options) > 1) {
$form['simplenews']['advanced']['s_format'] = array(
'#type' => 'select',
'#title' => t('Email format'),
'#default_value' => isset($simplenews_values['s_format']) ? $simplenews_values['s_format'] : variable_get('simplenews_format', 'plain'),
'#options' => _simplenews_format_options(),
);
}
else {
$form['simplenews']['advanced']['s_format'] = array(
'#type' => 'hidden',
'#value' => key($format_options),
);
}
$form['simplenews']['advanced']['priority'] = array(
'#type' => 'select',
'#title' => t('Email priority'),
'#default_value' => isset($simplenews_values['priority']) ? $simplenews_values['priority'] : variable_get('simplenews_priority', SIMPLENEWS_PRIORITY_NONE),
'#options' => array(
SIMPLENEWS_PRIORITY_NONE => t('none'),
SIMPLENEWS_PRIORITY_HIGHEST => t('highest'),
SIMPLENEWS_PRIORITY_HIGH => t('high'),
SIMPLENEWS_PRIORITY_NORMAL => t('normal'),
SIMPLENEWS_PRIORITY_LOW => t('low'),
SIMPLENEWS_PRIORITY_LOWEST => t('lowest'),
),
);
$form['simplenews']['advanced']['receipt'] = array(
'#type' => 'checkbox',
'#title' => t('Request receipt'),
'#return_value' => 1,
'#default_value' => isset($simplenews_values['receipt']) ? $simplenews_values['receipt'] : variable_get('simplenews_receipt', 0),
);
}
else {
$form['simplenews']['none'] = array(
'#type' => 'checkbox',
'#title' => t('This newsletter has been sent'),
'#return_value' => 0,
'#attributes' => array(
'checked' => 'checked',
'disabled' => 'disabled',
),
);
$form['simplenews']['advanced']['s_format'] = array(
'#type' => 'hidden',
'#value' => $simplenews_values['s_format'],
);
$form['simplenews']['advanced']['priority'] = array(
'#type' => 'hidden',
'#value' => $simplenews_values['priority'],
);
$form['simplenews']['advanced']['receipt'] = array(
'#type' => 'hidden',
'#value' => $simplenews_values['receipt'],
);
}
}
$form['simplenews']['s_status'] = array(
'#type' => 'hidden',
'#value' => isset($simplenews_values['s_status']) ? $simplenews_values['s_status'] : SIMPLENEWS_STATUS_SEND_NOT,
);
}
}
}
function simplenews_cron() {
simplenews_mail_spool();
simplenews_clear_spool();
simplenews_send_status_update();
}
function simplenews_taxonomy($op, $type, $term = NULL) {
if ($op == 'delete' && $term['vid'] == variable_get('simplenews_vid', '')) {
switch ($type) {
case 'term':
db_query('DELETE FROM {simplenews_snid_tid} WHERE tid = %d', $term['tid']);
db_query("DELETE FROM {blocks} WHERE module = '%s' AND delta = '%s'", 'simplenews', $term['tid']);
drupal_set_message(t('All subscriptions to newsletter %newsletter have been deleted.', array(
'%newsletter' => $term['name'],
)));
break;
}
}
}
function simplenews_user($op, &$edit, &$account, $category = NULL) {
switch ($op) {
case 'insert':
if ($edit['mail']) {
$query = "SELECT snid FROM {simplenews_subscriptions} WHERE mail = '%s'";
if ($result = db_fetch_object(db_query($query, $edit['mail']))) {
db_query("UPDATE {simplenews_subscriptions} SET uid = %d, language = '%s' WHERE snid = %d", $edit['uid'], $edit['language'], $result->snid);
}
}
break;
case 'update':
if ($category == 'account' && $edit['mail']) {
$query = "SELECT snid FROM {simplenews_subscriptions} WHERE uid = %d";
if ($result = db_fetch_object(db_query($query, $account->uid))) {
db_query("DELETE FROM {simplenews_subscriptions} WHERE mail = '%s' AND uid = %d", $edit['mail'], 0);
db_query("UPDATE {simplenews_subscriptions} SET mail = '%s', language = '%s' WHERE snid = %d", $edit['mail'], $edit['language'], $result->snid);
}
else {
$query = "SELECT snid FROM {simplenews_subscriptions} WHERE mail = '%s'";
if ($result = db_fetch_object(db_query($query, $edit['mail']))) {
db_query("UPDATE {simplenews_subscriptions} SET uid = %d, language = '%s' WHERE snid = %d", $account->uid, $account->language, $result->snid);
}
}
}
if ($category == 'account' && isset($edit['status'])) {
if (variable_get('simplenews_sync_account', TRUE)) {
db_query("UPDATE {simplenews_subscriptions} SET activated = %d WHERE uid = %d", $edit['status'], $account->uid);
}
}
if ($category == 'newsletter' && (user_access('subscribe to newsletters', $account) || user_access('administer users'))) {
foreach ($edit['newsletters'] as $tid => $checked) {
if ($checked) {
simplenews_subscribe_user($account->mail, $tid, FALSE);
}
else {
simplenews_unsubscribe_user($account->mail, $tid, FALSE);
}
}
}
break;
case 'delete':
if (variable_get('simplenews_sync_account', TRUE)) {
$snid = db_result(db_query("SELECT s.snid FROM {simplenews_subscriptions} s WHERE s.mail = '%s'", $account->mail));
db_query('DELETE FROM {simplenews_snid_tid} WHERE snid = %d', $snid);
db_query('DELETE FROM {simplenews_subscriptions} WHERE snid = %d', $snid);
}
else {
db_query("UPDATE {simplenews_subscriptions} SET uid = 0 WHERE uid = %d", $account->uid);
}
break;
case 'form':
if ($category == 'newsletter') {
$subscription = simplenews_get_subscription($account);
$form = _simplenews_subscription_manager_form($subscription);
$form['subscriptions']['#title'] = t('Current newsletter subscriptions');
unset($form['update'], $form['subscriptions']['mail']);
return $form;
}
break;
case 'categories':
$output[] = array(
'name' => 'newsletter',
'title' => t('My newsletters'),
'weight' => 10,
'access callback' => 'simplenews_subscription_edit_access',
);
return $output;
break;
case 'view':
global $user;
if ($user->uid == $account->uid || user_access('administer users')) {
$account->content['simplenews'] = array(
'#type' => 'user_profile_category',
'#title' => t('Newsletters'),
);
$tree = taxonomy_get_tree(variable_get('simplenews_vid', ''));
foreach ($tree as $newsletter) {
if (db_result(db_query('SELECT COUNT(s.uid) FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.uid = %d AND t.tid = %d', $account->uid, $newsletter->tid))) {
$subscriptions[] = l($newsletter->name, 'taxonomy/term/' . $newsletter->tid);
}
}
if (isset($subscriptions)) {
$subscriptions = implode(', ', $subscriptions);
}
else {
$subscriptions = t('None');
}
if (user_access('subscribe to newsletters', $account) || $subscriptions != t('None')) {
$account->content['simplenews']['subscriptions'] = array(
'#type' => 'user_profile_item',
'#title' => t('Current subscriptions'),
'#value' => $subscriptions,
);
}
if (user_access('subscribe to newsletters', $account)) {
$account->content['simplenews']['my_newsletters'] = array(
'#type' => 'user_profile_item',
'#value' => t('Manage <a href="!url">my subscriptions</a>', array(
'!url' => url('user/' . $account->uid . '/edit/newsletter'),
)),
'#weight' => -1,
);
}
}
break;
}
}
function simplenews_subscription_edit_access($account) {
global $user;
if (!$account || $account->uid == 0) {
return FALSE;
}
if ($user->uid == $account->uid) {
if (user_access('subscribe to newsletters', $account)) {
return TRUE;
}
}
if (user_access('administer users')) {
return TRUE;
}
return FALSE;
}
function simplenews_block($op = 'list', $delta = 0, $edit = array()) {
switch ($op) {
case 'list':
$blocks = array();
foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) {
$blocks[$newsletter->tid] = array(
'info' => t('Newsletter: @title', array(
'@title' => $newsletter->name,
)),
'cache' => variable_get('simplenews_block_f_' . $newsletter->tid, 1) ? BLOCK_NO_CACHE : BLOCK_CACHE_PER_ROLE,
);
}
return $blocks;
case 'configure':
$form['simplenews_block_' . $delta]['simplenews_block_m_' . $delta] = array(
'#type' => 'textfield',
'#title' => t('Block message'),
'#size' => 60,
'#maxlength' => 128,
'#default_value' => variable_get('simplenews_block_m_' . $delta, t('Stay informed on our latest news!')),
);
$form['simplenews_block_' . $delta]['simplenews_block_f_' . $delta] = array(
'#type' => 'radios',
'#title' => t('Subscription interface'),
'#options' => array(
'1' => t('Subscription form'),
'0' => t('Link to form'),
),
'#description' => t("Note: this requires permission 'subscribe to newsletters'."),
'#default_value' => variable_get('simplenews_block_f_' . $delta, 1),
);
$form['simplenews_block_' . $delta]['simplenews_block_l_' . $delta] = array(
'#type' => 'checkbox',
'#title' => t('Display link to previous issues'),
'#return_value' => 1,
'#default_value' => variable_get('simplenews_block_l_' . $delta, 1),
);
$form['simplenews_block_' . $delta]['simplenews_block_i_status_' . $delta] = array(
'#type' => 'checkbox',
'#title' => t('Display previous issues'),
'#return_value' => 1,
'#default_value' => variable_get('simplenews_block_i_status_' . $delta, 0),
);
$form['simplenews_block_' . $delta]['simplenews_block_i_' . $delta] = array(
'#type' => 'select',
'#title' => t('Number of issues to display'),
'#options' => drupal_map_assoc(array(
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
)),
'#default_value' => variable_get('simplenews_block_i_' . $delta, 5),
);
$form['simplenews_block_' . $delta]['simplenews_block_r_' . $delta] = array(
'#type' => 'checkbox',
'#title' => t('Display RSS-feed icon'),
'#return_value' => 1,
'#default_value' => variable_get('simplenews_block_r_' . $delta, 1),
);
return $form;
case 'save':
variable_set('simplenews_block_m_' . $delta, $edit['simplenews_block_m_' . $delta]);
variable_set('simplenews_block_f_' . $delta, $edit['simplenews_block_f_' . $delta]);
variable_set('simplenews_block_l_' . $delta, $edit['simplenews_block_l_' . $delta]);
variable_set('simplenews_block_i_status_' . $delta, $edit['simplenews_block_i_status_' . $delta]);
variable_set('simplenews_block_i_' . $delta, $edit['simplenews_block_i_' . $delta]);
variable_set('simplenews_block_r_' . $delta, $edit['simplenews_block_r_' . $delta]);
break;
case 'view':
global $language;
if ($tree = taxonomy_get_tree(variable_get('simplenews_vid', ''))) {
foreach ($tree as $taxonomy) {
$tids[] = $taxonomy->tid;
}
if (in_array($delta, $tids)) {
$newsletter = (array) taxonomy_get_term($delta);
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
$newsletter['name'] = tt('taxonomy:term:' . $newsletter['tid'] . ':name', $newsletter['name'], $language->language);
}
$block = array(
'subject' => check_plain($newsletter['name']),
'content' => theme(array(
'simplenews_block__' . $newsletter['tid'],
'simplenews_block',
), $newsletter['tid']),
);
return $block;
}
}
break;
}
}
function simplenews_forms() {
if ($taxonomies = taxonomy_get_tree(variable_get('simplenews_vid', ''))) {
foreach ($taxonomies as $newsletter) {
$forms['simplenews_block_form_' . $newsletter->tid] = array(
'callback' => 'simplenews_block_form',
'callback arguments' => array(
$newsletter->tid,
),
);
}
}
return $forms;
}
function _simplenews_user_load($mail) {
$account = user_load(array(
'mail' => $mail,
));
if ($account === FALSE) {
$account = new stdClass();
$account->uid = 0;
$account->mail = drupal_strtolower($mail);
}
return $account;
}
function simplenews_subscribe_user($mail, $tid, $confirm = TRUE, $preferred_language = NULL) {
global $language;
$mail = strtolower($mail);
$account = (object) array(
'mail' => $mail,
);
$subscription = simplenews_get_subscription($account);
if ($subscription->snid == 0) {
$account = _simplenews_user_load($mail);
if (variable_get('language_count', 1) > 1) {
if ($account->uid) {
$preferred_language = $account->language;
}
else {
$preferred_language = isset($preferred_language) ? $preferred_language : $language->language;
}
}
db_query("INSERT INTO {simplenews_subscriptions} (mail, uid, language, activated) VALUES ('%s', %d, '%s', %d)", $mail, $account->uid, $preferred_language, 1);
$subscription = simplenews_get_subscription($account);
}
if ($confirm) {
$params['from'] = _simplenews_set_from();
$params['context']['newsletter'] = taxonomy_get_term($tid);
$params['context']['account'] = $subscription;
drupal_mail('simplenews', 'subscribe', $mail, $subscription->language, $params, $params['from']['address']);
}
elseif (!isset($subscription->tids[$tid])) {
db_query("INSERT INTO {simplenews_snid_tid} (snid, tid) VALUES (%d, %d)", $subscription->snid, $tid);
simplenews_call_actions('subscribe', $subscription);
}
return TRUE;
}
function simplenews_unsubscribe_user($mail, $tid, $confirm = TRUE) {
$mail = strtolower($mail);
$account = (object) array(
'mail' => $mail,
);
$subscription = simplenews_get_subscription($account);
if (!($newsletter = taxonomy_get_term($tid))) {
watchdog('simplenews', 'Attempt to unsubscribe from non existing newsletter term ID %id', array(
'%id' => $tid,
), WATCHDOG_ERROR);
return FALSE;
}
if ($confirm) {
$params['from'] = _simplenews_set_from();
$params['context']['newsletter'] = $newsletter;
$params['context']['account'] = $subscription;
drupal_mail('simplenews', 'unsubscribe', $mail, $subscription->language, $params, $params['from']['address']);
}
elseif (isset($subscription->tids[$tid])) {
db_query('DELETE FROM {simplenews_snid_tid} WHERE snid = %d AND tid = %d', $subscription->snid, $tid);
if (!db_result(db_query("SELECT COUNT(*) FROM {simplenews_snid_tid} t WHERE t.snid = %d", $subscription->snid))) {
db_query('DELETE FROM {simplenews_subscriptions} WHERE snid = %d', $subscription->snid);
}
simplenews_call_actions('unsubscribe', $subscription);
}
return TRUE;
}
function simplenews_user_is_subscribed($mail, $tid, $reset = FALSE) {
static $subscribed = array();
if ($reset) {
unset($subscribed);
}
if (!isset($subscribed[$mail][$tid])) {
$subscribed[$mail][$tid] = db_result(db_query("SELECT COUNT(*) FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.mail = '%s' AND t.tid = %d", $mail, $tid)) ? TRUE : FALSE;
}
return $subscribed[$mail][$tid];
}
function simplenews_get_subscription($account) {
if (isset($account->snid)) {
$subscription = db_fetch_object(db_query("SELECT s.* FROM {simplenews_subscriptions} s LEFT JOIN {users} u ON u.uid = s.uid WHERE s.snid = %d", $account->snid));
}
elseif (isset($account->mail)) {
$subscription = db_fetch_object(db_query("SELECT s.* FROM {simplenews_subscriptions} s LEFT JOIN {users} u ON u.uid = s.uid WHERE s.mail = '%s'", $account->mail));
}
elseif (isset($account->uid) && $account->uid > 0) {
$subscription = db_fetch_object(db_query("SELECT s.* FROM {simplenews_subscriptions} s LEFT JOIN {users} u ON u.uid = s.uid WHERE s.uid = %d", $account->uid));
}
if (!empty($subscription)) {
$result = db_query("SELECT tid FROM {simplenews_snid_tid} t WHERE t.snid = %d", $subscription->snid);
$subscription->tids = array();
while ($newsletter = db_fetch_object($result)) {
$subscription->tids[$newsletter->tid] = $newsletter->tid;
}
$subscription->name = '';
$subscription->language = user_preferred_language($subscription);
}
else {
$subscription = new stdClass();
$subscription->name = '';
$subscription->uid = isset($account->uid) ? $account->uid : 0;
$subscription->mail = isset($account->mail) ? $account->mail : '';
$subscription->language = language_default();
$subscription->snid = 0;
$subscription->tids = array();
}
return $subscription;
}
function simplenews_delete_subscription($snid) {
$account = db_fetch_object(db_query('SELECT mail FROM {simplenews_subscriptions} WHERE snid = %d', $snid));
db_query('DELETE FROM {simplenews_subscriptions} WHERE snid = %d', $snid);
db_query('DELETE FROM {simplenews_snid_tid} WHERE snid = %d', $snid);
watchdog('simplenews', 'User %email deleted from the mailing list.', array(
'%email' => $account->mail,
), WATCHDOG_NOTICE);
}
function _simplenews_subscription_manager_form($subscription) {
$form = array();
$options = array();
$default_value = array();
global $language;
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_TRANSLATE) {
$tterms = i18ntaxonomy_vocabulary_get_terms(variable_get('simplenews_vid', ''), $language->language);
foreach ($tterms as $tid => $name) {
$options[$tid] = check_plain($name);
$default_value[$tid] = FALSE;
}
}
else {
foreach (taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) {
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
$options[$newsletter->tid] = check_plain(tt('taxonomy:term:' . $newsletter->tid . ':name', $newsletter->name, $language->language));
}
else {
$options[$newsletter->tid] = check_plain($newsletter->name);
}
$default_value[$newsletter->tid] = FALSE;
}
}
$form['subscriptions'] = array(
'#type' => 'fieldset',
'#description' => t('Select the newsletter(s) to which you want to subscribe or unsubscribe.'),
);
$form['subscriptions']['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => array_merge($default_value, (array) $subscription->tids),
);
if ($subscription->mail) {
$form['subscriptions']['#title'] = t('Subscriptions for %mail', array(
'%mail' => $subscription->mail,
));
$form['subscriptions']['mail'] = array(
'#type' => 'value',
'#value' => $subscription->mail,
);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 20,
);
}
else {
$form['subscriptions']['#title'] = t('Manage your newsletter subscriptions');
$form['subscriptions']['mail'] = array(
'#type' => 'textfield',
'#title' => t('email'),
'#size' => 20,
'#maxlength' => 128,
'#weight' => 10,
'#required' => TRUE,
);
$form['subscribe'] = array(
'#type' => 'submit',
'#value' => t('Subscribe'),
'#weight' => 20,
);
$form['unsubscribe'] = array(
'#type' => 'submit',
'#value' => t('Unsubscribe'),
'#weight' => 30,
);
}
return $form;
}
function simplenews_recent_newsletters($tid, $count = 5) {
$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, sn.s_status, n.created FROM {node} n INNER JOIN {term_node} t ON n.vid = t.vid INNER JOIN {simplenews_newsletters} sn ON n.nid = sn.nid WHERE (t.tid = %d AND n.status = %d) ORDER BY n.created DESC'), $tid, 1, 0, $count);
$titles = array();
while ($item = db_fetch_object($result)) {
$titles[$item->nid]['data'] = l($item->title, 'node/' . $item->nid);
$titles[$item->nid]['class'] = $item->s_status == SIMPLENEWS_STATUS_SEND_NOT ? 'newsletter-created' : 'newsletter-send';
}
return $titles;
}
function simplenews_block_form(&$form_state, $tid) {
global $user;
$form = array();
if ($user->uid) {
if (simplenews_user_is_subscribed($user->mail, $tid)) {
$submit_text = t('Unsubscribe');
$form['action'] = array(
'#type' => 'value',
'#value' => 'unsubscribe',
);
}
else {
$submit_text = t('Subscribe');
$form['action'] = array(
'#type' => 'value',
'#value' => 'subscribe',
);
}
$form['display_mail'] = array(
'#type' => 'item',
'#title' => t('User'),
'#value' => check_plain($user->name),
);
$form['mail'] = array(
'#type' => 'value',
'#value' => $user->mail,
);
}
else {
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('Email'),
'#size' => 20,
'#maxlength' => 128,
'#required' => TRUE,
);
$form['action'] = array(
'#type' => 'radios',
'#default_value' => 'subscribe',
'#options' => array(
'subscribe' => t('Subscribe'),
'unsubscribe' => t('Unsubscribe'),
),
);
}
$form['#tid'] = $tid;
$form['#validate'][] = 'simplenews_block_form_validate';
$form['#submit'][] = 'simplenews_block_form_submit';
$form['submit'] = array(
'#type' => 'submit',
'#value' => isset($submit_text) ? $submit_text : t('Save'),
);
return $form;
}
function simplenews_block_form_validate($form, &$form_state) {
if (!valid_email_address($form_state['values']['mail'])) {
form_set_error('mail', t("The email address you supplied is not valid."));
}
}
function simplenews_block_form_submit($form, &$form_state) {
global $user;
$tid = $form['#tid'];
$account = _simplenews_user_load($form_state['values']['mail']);
$confirm = $account->uid && $account->uid == $user->uid ? FALSE : TRUE;
switch ($form_state['values']['action']) {
case 'subscribe':
simplenews_subscribe_user($form_state['values']['mail'], $tid, $confirm);
if ($confirm) {
drupal_set_message(t('You will receive a confirmation email shortly containing further instructions on how to complete your subscription.'));
}
else {
drupal_set_message(t('You have been subscribed.'));
}
break;
case 'unsubscribe':
simplenews_unsubscribe_user($form_state['values']['mail'], $tid, $confirm);
if ($confirm) {
drupal_set_message(t('You will receive a confirmation email shortly containing further instructions on how to complete the unsubscription process.'));
}
else {
drupal_set_message(t('You have been unsubscribed.'));
}
break;
}
}
function simplenews_send_node($node, $accounts = array()) {
$mails = array();
if (is_numeric($node)) {
$node = node_load($node);
}
if (is_object($node)) {
$from = _simplenews_set_from($node);
$params['context']['node'] = $node;
$params['from'] = $from;
$node_data['tid'] = $node->simplenews['tid'];
$node_data['nid'] = $node->nid;
$node_data['vid'] = $node->vid;
if (empty($accounts)) {
$result = db_query('SELECT s.mail FROM {simplenews_subscriptions} s INNER JOIN {simplenews_snid_tid} t ON s.snid = t.snid WHERE s.activated = %d AND t.tid = %d', 1, $node_data['tid']);
while ($account = db_fetch_object($result)) {
$mails[] = array(
'mail' => $account->mail,
);
}
}
else {
foreach ($accounts as $account) {
$account = simplenews_get_subscription($account);
$mails[] = array(
'mail' => $account->mail,
);
}
}
foreach ($mails as $mail) {
$data = array_merge($node_data, $mail);
simplenews_save_spool($data);
}
if (variable_get('simplenews_use_cron', TRUE) == FALSE) {
simplenews_mail_spool($node_data['nid'], $node_data['vid'], 999999);
drupal_set_message(t('Newsletter sent.'));
simplenews_clear_spool();
}
else {
drupal_set_message(t('Newsletter pending.'));
}
}
}
function simplenews_send_test($node) {
if (is_numeric($node)) {
$node = node_load($node);
}
if (is_object($node)) {
$mails = explode(',', $node->simplenews['test_address']);
foreach ($mails as $mail) {
$mail = trim($mail);
if (!empty($mail)) {
$result = simplenews_mail_mail($node->nid, $node->vid, $mail, 'test');
}
}
if ($result) {
drupal_set_message(t('Test newsletter sent to %recipient.', array(
'%recipient' => $node->simplenews['test_address'],
)));
}
}
}
function simplenews_mail($key, &$message, $params) {
$context = $params['context'];
switch ($key) {
case 'node':
case 'test':
static $messages = array();
$nid = $context['node']->nid;
$langcode = $message['language']->language;
if (module_exists('translation')) {
if ($tnid = $context['node']->tnid) {
if ($langcode != $context['node']->language) {
$translations = translation_node_get_translations($tnid);
if ($translation = $translations[$langcode]) {
$nid = $translation->nid;
$langcode = $translation->language;
}
else {
foreach ($translations as $translation) {
if ($translation->nid == $tnid) {
$nid = $tnid;
$langcode = $translation->language;
break;
}
}
}
}
}
if ($nid != $context['node']->nid && !isset($messages[$nid][$langcode])) {
$context['node'] = node_load($nid);
}
}
if (!isset($messages[$nid][$langcode])) {
global $custom_theme;
$org_cutom_theme = $custom_theme;
$custom_theme = '';
$node = drupal_clone($context['node']);
$headers = array_merge($message['headers'], _simplenews_headers($node, $params['from']['address']));
$headers['From'] = $params['from']['formatted'];
$message['headers'] = $messages[$nid][$langcode]['headers'] = $headers;
if ($tid = $node->simplenews['tid']) {
$term = taxonomy_get_term($tid);
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
$name = tt('taxonomy:term:' . $tid . ':name', $term->name, $langcode);
}
else {
$name = $term->name;
}
}
else {
$name = t('Unassigned newsletter');
}
$subject = theme('simplenews_newsletter_subject', $name, $node->title, $message['language']);
$subject = str_replace(array(
"\r",
"\n",
), '', $subject);
$message['subject'] = $messages[$nid][$langcode]['subject'] = $subject;
$node->build_mode = 'email_' . $node->simplenews['s_format'];
$node = node_build_content($node, FALSE, TRUE);
$content = drupal_render($node->content);
$node->body = $content;
unset($node->teaser);
$node->simplenews_mail = TRUE;
node_invoke_nodeapi($node, 'alter', FALSE, TRUE);
unset($node->simplenews_mail);
$body = theme(array(
'simplenews_newsletter_body__' . $context['node']->simplenews['tid'],
'simplenews_newsletter_body',
), $node, $message['language']);
$messages[$nid][$langcode]['body'] = $body;
$footer = theme(array(
'simplenews_newsletter_footer__' . $context['node']->simplenews['tid'],
'simplenews_newsletter_footer',
), $context['node'], $key, $message['language']);
$messages[$nid][$langcode]['footer'] = $footer;
$custom_theme = $org_cutom_theme;
}
else {
$message['headers'] = $messages[$nid][$langcode]['headers'];
$message['subject'] = $messages[$nid][$langcode]['subject'];
$body = $messages[$nid][$langcode]['body'];
$footer = $messages[$nid][$langcode]['footer'];
}
$variables = simplenews_mail_tokens($context['account'], $context, is_object($context['account']->language) ? $context['account']->language : language_default());
$body = strtr($body, $variables);
if ($context['node']->simplenews['s_format'] == 'plain') {
$body = simplenews_html_to_text($body, variable_get('simplenews_hyperlinks_' . $context['node']->simplenews['tid'], 1));
}
$message['body']['body'] = $body;
$message['body']['footer'] = strtr($footer, $variables);
$message['headers']['List-Unsubscribe'] = strtr('<!confirm_unsubscribe_url>', $variables);
break;
case 'subscribe':
$message['headers']['From'] = $params['from']['formatted'];
$variables = simplenews_mail_tokens($context['account'], $context, is_object($context['account']->language) ? $context['account']->language : language_default());
$message['subject'] = _simplenews_subscription_confirmation_text('subscribe_subject', $context['account']->language, $variables);
if (simplenews_user_is_subscribed($context['account']->mail, $context['newsletter']->tid)) {
$message['body'] = _simplenews_subscription_confirmation_text('subscribe_subscribed', $context['account']->language, $variables);
}
else {
$message['body'] = _simplenews_subscription_confirmation_text('subscribe_unsubscribed', $context['account']->language, $variables);
}
break;
case 'unsubscribe':
$message['headers']['From'] = $params['from']['formatted'];
$variables = simplenews_mail_tokens($context['account'], $context, is_object($context['account']->language) ? $context['account']->language : language_default());
$message['subject'] = _simplenews_subscription_confirmation_text('subscribe_subject', $context['account']->language, $variables);
if (simplenews_user_is_subscribed($context['account']->mail, $context['newsletter']->tid)) {
$message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_subscribed', $context['account']->language, $variables);
}
else {
$message['body'] = _simplenews_subscription_confirmation_text('unsubscribe_unsubscribed', $context['account']->language, $variables);
}
break;
}
if (variable_get('simplenews_debug', FALSE) && $key != 'node' && $key != 'test') {
watchdog('simplenews', 'Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to', array(
'%type' => $key,
'%to' => $message['to'],
'%subject' => $message['subject'],
), WATCHDOG_DEBUG);
}
}
function simplenews_mail_mail($nid, $vid, $mail, $key = 'node') {
$account = new stdClass();
$account->mail = $mail;
$subscription = simplenews_get_subscription($account);
$params['context']['account'] = $subscription;
$node = node_load($nid, $vid);
if (is_object($node)) {
$params['from'] = _simplenews_set_from($node);
$params['context']['newsletter'] = taxonomy_get_term($node->simplenews['tid']);
$params['context']['node'] = $node;
if (module_exists('mimemail')) {
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['formatted'], FALSE);
$to = isset($message['params']['context']['account']) ? $message['params']['context']['account'] : $message['to'];
$plain = $message['params']['context']['node']->simplenews['s_format'] == 'plain' ? TRUE : NULL;
$mimemail_result = mimemail($message['from'], $to, $message['subject'], $message['body'], $plain, $message['headers'], $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE), isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(), $message['id']);
if (is_array($mimemail_result)) {
$message = $mimemail_result;
}
else {
$message['result'] = $mimemail_result;
}
}
else {
$message = drupal_mail('simplenews', $key, $subscription->mail, $subscription->language, $params, $params['from']['formatted'], TRUE);
}
if (variable_get('simplenews_debug', FALSE)) {
$via_mimemail = '';
if (module_exists('mimemail')) {
$via_mimemail = t('Sent via Mime Mail');
}
if ($message['result']) {
watchdog('simplenews', 'Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array(
'%type' => $key,
'%to' => $message['to'],
'%subject' => $message['subject'],
'%mimemail' => $via_mimemail,
), WATCHDOG_DEBUG);
}
else {
watchdog('simplenews', 'Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to %mimemail', array(
'%type' => $key,
'%to' => $message['to'],
'%subject' => $message['subject'],
'%mimemail' => $via_mimemail,
), WATCHDOG_ERROR);
}
}
if ($message['result']) {
$message['result'] = array(
'status' => SIMPLENEWS_SPOOL_DONE,
'error' => FALSE,
);
}
else {
$message['result'] = array(
'status' => SIMPLENEWS_SPOOL_PENDING,
'error' => TRUE,
);
}
}
else {
$message['result'] = array(
'status' => SIMPLENEWS_SPOOL_DONE,
'error' => TRUE,
);
watchdog('simplenews', 'Newsletter not send: newsletter issue does not exist (nid = @nid; vid = @vid).', array(
'@nid' => $message['nid'],
'@vid' => $message['vid'],
), WATCHDOG_ERROR);
}
return isset($message['result']) ? $message['result'] : FALSE;
}
function simplenews_mail_spool($nid = NULL, $vid = NULL, $limit = NULL) {
$limit = isset($limit) ? $limit : variable_get('simplenews_throttle', 20);
if ($messages = simplenews_get_spool(SIMPLENEWS_SPOOL_PENDING, $nid, $vid, $limit)) {
$count_fail = $count_success = 0;
$max_execution_time = ini_get('max_execution_time') ? ini_get('max_execution_time') : SIMPLENEWS_MAX_EXECUTION_TIME;
_simplenews_measure_usec(TRUE);
foreach ($messages as $key => $message) {
$result = simplenews_mail_mail($message['nid'], $message['vid'], $message['mail']);
simplenews_update_spool(array(
$key,
), $result);
if ($result['status'] == SIMPLENEWS_SPOOL_DONE) {
$count_success++;
}
if ($result['error']) {
$count_fail++;
}
if (++$check_counter >= SIMPLENEWS_SEND_CHECK_INTERVAL) {
$check_counter = 0;
$elapsed = _simplenews_measure_usec();
if ($elapsed > SIMPLENEWS_SEND_TIME_LIMIT * $max_execution_time) {
watchdog('simplenews', 'Sending interrupted: PHP maximum execution time almost exceeded. Remaining newsletters will be sent during the next cron run. If this warning occurs regularly you should reduce the !cron_throttle_setting.', array(
'!cron_throttle_setting' => l(t('Cron throttle setting'), 'admin/settings/simplenews/mail'),
), WATCHDOG_WARNING);
break;
}
}
}
if (function_exists('getrusage')) {
watchdog('simplenews', '%success emails sent in %sec seconds, %fail failed sending.', array(
'%success' => $count_success,
'%sec' => round(_simplenews_measure_usec(), 1),
'%fail' => $count_fail,
));
}
else {
watchdog('simplenews', '%success emails sent, %fail failed.', array(
'%success' => $count_success,
'%fail' => $count_fail,
));
}
}
}
function simplenews_save_spool($message) {
$status = isset($message['status']) ? $message['status'] : SIMPLENEWS_SPOOL_PENDING;
$time = isset($message['time']) ? $message['time'] : time();
db_query("INSERT INTO {simplenews_mail_spool} (mail, nid, vid, tid, status, timestamp)\n VALUES ('%s', %d, %d, %d, %d, %d)", $message['mail'], $message['nid'], $message['vid'], $message['tid'], $status, $time);
}
function simplenews_get_spool($status, $nid = NULL, $vid = NULL, $limit = 999999) {
$messages = array();
$result = db_query_range("SELECT * FROM {simplenews_mail_spool} s WHERE s.status = %d ORDER BY s.timestamp ASC", $status, 0, $limit);
while ($data = db_fetch_array($result)) {
$message = array();
foreach ($data as $key => $value) {
$message[$key] = $value;
}
$messages[$data['msid']] = $message;
}
return $messages;
}
function simplenews_update_spool($msids, $result) {
$params[] = $result['status'];
$params[] = isset($result['error']) ? $result['error'] : FALSE;
$params[] = time();
$params = array_merge($params, $msids);
db_query("UPDATE {simplenews_mail_spool} SET status = %d, error = %d, timestamp = %d WHERE msid IN(" . db_placeholders($msids, 'int') . ")", $params);
}
function simplenews_count_spool($nid, $vid, $status = SIMPLENEWS_SPOOL_PENDING) {
return db_result(db_query("SELECT COUNT(*) FROM {simplenews_mail_spool} WHERE nid = %d AND vid = %d AND status = %d", $nid, $vid, $status));
}
function simplenews_clear_spool() {
$expiration_time = time() - variable_get('simplenews_spool_expire', 0) * 86400;
db_query("DELETE FROM {simplenews_mail_spool} WHERE status = %d AND timestamp <= %d", SIMPLENEWS_SPOOL_DONE, $expiration_time);
}
function simplenews_send_status_update() {
$counts = array();
$sum = array();
$send = array();
$result = db_query("SELECT s.nid, s.vid, s.tid, n.tnid FROM {simplenews_newsletters} s JOIN {node} n ON s.nid = n.nid AND s.vid = n.vid WHERE s.s_status = %d", SIMPLENEWS_STATUS_SEND_PENDING);
while ($newsletter = db_fetch_object($result)) {
$counts[$newsletter->tnid][$newsletter->nid . '-' . $newsletter->vid] = simplenews_count_spool($newsletter->nid, $newsletter->vid);
}
foreach ($counts as $tnid => $node_count) {
$sum[$tnid] = array_sum($node_count);
foreach ($node_count as $nidvid => $count) {
if ($tnid != '0' && $sum[$tnid] == '0') {
$send[] = $nidvid;
}
elseif ($tnid == '0' && $count == '0') {
$send[] = $nidvid;
}
}
}
if (!empty($send)) {
foreach ($send as $nidvid) {
$nid = strtok($nidvid, '-');
$vid = strtok('-');
db_query("UPDATE {simplenews_newsletters} SET s_status = '%s' WHERE nid = %d AND vid = %d", SIMPLENEWS_STATUS_SEND_READY, $nid, $vid);
}
}
}
function simplenews_views_api() {
return array(
'api' => 2,
);
}
function simplenews_call_actions($op, $subscription) {
if (!module_exists('simplenews_action')) {
return;
}
$aids = _trigger_get_hook_aids('simplenews', $op);
$context = array(
'hook' => 'simplenews',
'op' => $op,
'account' => $subscription,
);
foreach ($aids as $aid => $action_info) {
actions_do($aid, $subscription, $context);
}
}
function _simplenews_set_from($node = NULL) {
$address_default = variable_get('site_mail', ini_get('sendmail_from'));
$name_default = variable_get('site_name', 'Drupal');
if (isset($node->simplenews['tid'])) {
$address = variable_get('simplenews_from_address_' . $node->simplenews['tid'], variable_get('simplenews_from_address', $address_default));
$name = variable_get('simplenews_from_name_' . $node->simplenews['tid'], variable_get('simplenews_from_name', $name_default));
}
else {
$address = variable_get('simplenews_from_address', $address_default);
$name = variable_get('simplenews_from_name', $name_default);
}
$formatted_address = drupal_substr(PHP_OS, 0, 3) == 'WIN' ? $address : '"' . addslashes(mime_header_encode($name)) . '" <' . $address . '>';
return array(
'address' => $address,
'formatted' => $formatted_address,
);
}
function _simplenews_headers($node, $from) {
$headers = array();
if ($node->simplenews['receipt']) {
$headers['Disposition-Notification-To'] = $from;
$headers['X-Confirm-Reading-To'] = $from;
}
switch ($node->simplenews['priority']) {
case SIMPLENEWS_PRIORITY_HIGHEST:
$headers['Priority'] = 'High';
$headers['X-Priority'] = '1';
$headers['X-MSMail-Priority'] = 'Highest';
break;
case SIMPLENEWS_PRIORITY_HIGH:
$headers['Priority'] = 'urgent';
$headers['X-Priority'] = '2';
$headers['X-MSMail-Priority'] = 'High';
break;
case SIMPLENEWS_PRIORITY_NORMAL:
$headers['Priority'] = 'normal';
$headers['X-Priority'] = '3';
$headers['X-MSMail-Priority'] = 'Normal';
break;
case SIMPLENEWS_PRIORITY_LOW:
$headers['Priority'] = 'non-urgent';
$headers['X-Priority'] = '4';
$headers['X-MSMail-Priority'] = 'Low';
break;
case SIMPLENEWS_PRIORITY_LOWEST:
$headers['Priority'] = 'non-urgent';
$headers['X-Priority'] = '5';
$headers['X-MSMail-Priority'] = 'Lowest';
break;
}
$headers['Precedence'] = 'bulk';
return $headers;
}
function simplenews_html_to_text($text, $inline_hyperlinks = TRUE) {
if ($inline_hyperlinks) {
$pattern = '@<a[^>]+?href="([^"]*)"[^>]*?>(.+?)</a>@is';
$text = preg_replace_callback($pattern, '_simplenews_absolute_mail_urls', $text);
}
$preg = _simplenews_html_replace();
$text = preg_replace(array_keys($preg), array_values($preg), $text);
return drupal_html_to_text($text);
}
function _simplenews_absolute_mail_urls($match) {
global $base_url, $base_path;
static $regexp;
$url = $label = '';
if ($match) {
if (empty($regexp)) {
$regexp = '@^' . preg_quote($base_path, '@') . '@';
}
list(, $url, $label) = $match;
$url = strpos($url, '://') ? $url : preg_replace($regexp, $base_url . '/', $url);
if (strpos($label, '...') === strlen($label) - 3) {
$label = substr($label, 0, strlen($label) - 3);
}
if (strpos($url, $label) !== FALSE) {
return $url;
}
return $label . ' ' . $url;
}
}
function _simplenews_html_replace() {
return array(
'/"/i' => '"',
'/>/i' => '>',
'/</i' => '<',
'/&/i' => '&',
'/©/i' => '(c)',
'/™/i' => '(tm)',
'/“/' => '"',
'/”/' => '"',
'/–/' => '-',
'/’/' => "'",
'/&/' => '&',
'/©/' => '(c)',
'/™/' => '(tm)',
'/—/' => '--',
'/“/' => '"',
'/”/' => '"',
'/•/' => '*',
'/®/i' => '(R)',
'/•/i' => '*',
'/€/i' => 'Euro ',
);
}
function simplenews_mail_tokens($subscription, $context, $language) {
$hash = '';
if (isset($subscription->snid) && isset($context['newsletter']->tid)) {
$hash = _simplenews_generate_hash($subscription->mail, $subscription->snid, $context['newsletter']->tid);
}
$name = isset($context['newsletter']->name) ? $context['newsletter']->name : '';
if (!$name) {
if (isset($context['node']->simplenews['tid'])) {
if ($term = taxonomy_get_term($context['node']->simplenews['tid'])) {
$name = $term->name;
if (module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
$name = tt('taxonomy:term:' . $context['node']->simplenews['tid'] . ':name', $name, $language->language);
}
}
}
}
if ($subscription->uid) {
$vars = user_mail_tokens($subscription, $language);
}
else {
$vars = array();
$vars['!site'] = variable_get('site_name', 'Drupal');
$vars['!mailto'] = isset($subscription->mail) ? $subscription->mail : '';
$vars['!date'] = format_date(time(), 'medium', '', NULL, $language->language);
$vars['!login_uri'] = url('user', array(
'absolute' => TRUE,
'language' => $language,
));
}
$vars['!uri'] = url('', array(
'absolute' => TRUE,
'language' => $language,
));
$vars['!uri_brief'] = preg_replace('!^https?://!', '', $vars['!uri']);
$vars['!confirm_subscribe_url'] = url('newsletter/confirm/add/' . $hash, array(
'absolute' => TRUE,
'language' => $language,
));
$vars['!confirm_unsubscribe_url'] = url('newsletter/confirm/remove/' . $hash, array(
'absolute' => TRUE,
'language' => $language,
));
$vars['!newsletter_url'] = isset($context['node']->nid) ? url('node/' . $context['node']->nid, array(
'absolute' => TRUE,
'language' => $language,
)) : '';
$vars['!newsletter_name'] = $name;
return $vars;
}
function simplenews_private_key() {
$key = variable_get('simplenews_private_key', FALSE);
if (!$key) {
$key = md5(uniqid(rand()));
variable_set('simplenews_private_key', $key);
}
return $key;
}
function simplenews_help($path, $arg) {
switch ($path) {
case 'admin/help#simplenews':
$help = "<p>" . t('Simplenews publishes and sends newsletters to lists of subscribers. Both anonymous and authenticated users can opt-in to different mailing lists.') . "</p>\n";
$help .= "<p>" . t('Simplenews uses nodes for <strong>newsletter issues</strong>. Newsletter issues are grouped by a <strong>newsletter taxonomy term</strong>. Node type and vocabulary are selectable. A newsletter is send to all email addresses which are subscribed to the newsletter. Newsletter issues can be sent only once. Large mailings should be sent by cron to balance the mailserver load.') . "</p>\n";
$help .= "<p>" . t('Simplenews adds elements to the newsletter node add/edit form to manage newsletter format and sending of the newsletter issue. A newsletter issue can be sent for test before sending officially.') . "</p>\n";
$help .= "<p>" . t('Both anonymous and authenticated users can <strong>opt-in and opt-out</strong> to a newsletter. A confirmation message is sent to anonymous users at subscription and unsubscription. Users can (un)subscribe using a form and a block. A <strong>subscription block</strong> is available for each newsletter offering a subscription form, a link to recent newsletters and RSS feed. Email addresses can also be imported and exported via the subscription administration pages.') . "</p>\n";
$help .= "<h2>" . t('Configuration') . "</h2>\n";
$help .= "<ul>";
if (user_access('administer permissions')) {
$help .= "<li>" . l(t('Configure permissions'), 'admin/user/permissions', array(
'fragment' => 'module-simplenews',
)) . "</li>\n";
}
if (user_access('administer simplenews settings')) {
$help .= "<li>" . l(t('Configure Simplenews'), 'admin/settings/simplenews') . "</li>\n";
}
if (user_access('administer blocks')) {
$help .= "<li>" . t('Enable a newsletter <a href="@admin_blocks">subscription block</a>.', array(
'@admin_blocks' => url('admin/build/block'),
)) . "</li>\n";
}
if (user_access('administer simplenews settings')) {
$help .= "<li>" . t('Manage your <a href="@newsletters">newsletters</a>, <a href="@sent">sent newsletters</a> and <a href="@subscriptions">subscriptions</a>.', array(
'@newsletters' => url('admin/content/simplenews/types'),
'@sent' => url('admin/content/simplenews'),
'@subscriptions' => url('admin/content/simplenews/users'),
)) . "</li>\n";
}
$help .= "</ul>";
$help .= "<p>" . t('For more information, see the online handbook entry for <a href="@handbook">Simplenews</a>.', array(
'@handbook',
'http://drupal.org/node/197057',
)) . "</p>\n";
return $help;
case 'node/add/simplenews':
$help = '<ul>';
$help .= "<li>" . t('Add this newsletter issue to a newsletter by selecting a newsletter from the select list. Send a newsletter or a test newsletter by selecting the appropriate radio button and submitting the node.') . "</li>\n";
if (user_access('administer simplenews settings')) {
$help .= "<li>" . t('Set default send options at <a href="@configuration">Administer > Site configuration > Simplenews > Newsletter</a>.', array(
'@configuration' => url('admin/settings/simplenews/newsletter'),
)) . "</li>\n";
}
if (user_access('administer newsletters')) {
$help .= "<li>" . t('Set newsletter specific options at <a href="@configuration">Administer > Content management > Newsletters > Newsletters</a>.', array(
'@configuration' => url('admin/content/simplenews/types'),
)) . "</li>\n";
}
$help .= "</ul>";
return $help;
case 'admin/settings/simplenews/newsletter':
$help = '<ul>';
$help .= '<li>' . t('These settings are default to all newsletters. Newsletter specific settings can be found at the <a href="@page">newsletter\'s settings page</a>.', array(
'@page' => url('admin/content/simplenews/types'),
)) . "</li>\n";
if (!module_exists('mimemail')) {
$help .= "<li>" . t('Install <a href="@mime_mail_url">Mime Mail</a> to send HTML emails or emails with attachments (both plain text and HTML).', array(
'@mime_mail_url' => 'http://drupal.org/project/mimemail',
)) . "</li>\n";
}
$help .= "</ul>";
return $help;
case 'admin/content/simplenews/types/add':
$help = '<p>' . t('You can create different newsletters (or subjects) to categorize your news (e.g. Cats news, Dogs news, ...).') . "</p>\n";
return $help;
case 'admin/content/node-type/simplenews/display/simplenews':
$help = '<p>' . t("'Plain' display settings apply to the content of emails sent in plain text format. 'HTML' display settings apply to both HTML and plain text alternative content of emails sent in HTML format.") . "</p>\n";
return $help;
}
}
function _simplenews_flatten_array($array) {
$return = array();
foreach ($array as $key => $value) {
if (is_array($value)) {
$return += _simplenews_flatten_array($value);
}
else {
$return[$key] = $value;
}
}
return $return;
}
function _simplenews_generate_hash($mail, $snid, $tid) {
return drupal_substr(md5($mail . simplenews_private_key()), 0, 10) . $snid . 't' . $tid;
}
function _simplenews_format_options() {
$options = array(
'plain' => t('plain'),
);
if (module_exists('mimemail') || module_exists('htmlmail')) {
$options['html'] = t('html');
}
return $options;
}
function _simplenews_subscription_confirmation_text($key, $language = NULL, $variables = array()) {
$langcode = isset($language) ? $language->language : NULL;
if ($admin_setting = variable_get('simplenews_confirm_' . $key, FALSE)) {
return strtr($admin_setting, $variables);
}
else {
switch ($key) {
case 'subscribe_unsubscribed':
return t("We have received a request for subscription of !mailto to the !newsletter_name on !site website at !uri. To confirm this subscription please use the link below.\n\n!confirm_subscribe_url", $variables, $langcode);
case 'subscribe_subscribed':
return t("We have received a request for subscription of !mailto to the !newsletter_name on !site website at !uri. However, this email is already subscribed to this newsletter. If you intended to unsubscribe please visit our site: !uri", $variables, $langcode);
case 'unsubscribe_subscribed':
return t("We have received a request to unsubscribe !mailto from the !newsletter_name on !site website at !uri. To confirm this unsubscription please use the link below.\n\n!confirm_unsubscribe_url", $variables, $langcode);
case 'unsubscribe_unsubscribed':
return t("We have received a request to unsubscribe !mailto from the !newsletter_name on !site website at !uri. However, this email is not subscribed to this newsletter. If you intended to subscribe please visit our site: !uri", $variables, $langcode);
case 'subscribe_subject':
return t("Confirmation for !newsletter_name from !site", $variables, $langcode);
}
}
}
function _simplenews_measure_usec($start = FALSE) {
if (!function_exists('getrusage')) {
return 0;
}
static $start_time;
$usage = getrusage();
$now = (double) ($dat["ru_stime.tv_sec"] . '.' . $dat["ru_stime.tv_usec"]) + (double) ($usage["ru_utime.tv_sec"] . '.' . $usage["ru_utime.tv_usec"]);
if ($start) {
$start_time = $now;
return 0;
}
return $now - $start_time;
}
function simplenews_content_build_modes() {
return array(
'simplenews' => array(
'title' => t('Simplenews'),
'build modes' => array(
'email_plain' => array(
'title' => t('Email: Plain'),
'views style' => FALSE,
),
'email_html' => array(
'title' => t('Email: HTML'),
'views style' => FALSE,
),
),
),
);
}
function simplenews_theme() {
return array(
'simplenews_block' => array(
'template' => 'simplenews-block',
'arguments' => array(
'tid' => NULL,
),
'pattern' => 'simplenews_block__',
),
'simplenews_status' => array(
'template' => 'simplenews-status',
'file' => 'simplenews.admin.inc',
'arguments' => array(
'status' => NULL,
'source' => NULL,
),
),
'simplenews_newsletter_subject' => array(
'arguments' => array(
'name' => NULL,
'title' => NULL,
'language' => NULL,
),
),
'simplenews_newsletter_body' => array(
'template' => 'simplenews-newsletter-body',
'arguments' => array(
'node' => NULL,
'language' => NULL,
),
'pattern' => 'simplenews_newsletter_body__',
),
'simplenews_newsletter_footer' => array(
'template' => 'simplenews-newsletter-footer',
'arguments' => array(
'node' => NULL,
'key' => NULL,
'language' => NULL,
),
'pattern' => 'simplenews_newsletter_footer__',
),
'simplenews_subscription_list' => array(
'file' => 'simplenews.admin.inc',
'arguments' => array(
'form' => NULL,
),
),
);
}
function template_preprocess_simplenews_block(&$variables) {
global $user;
$tid = $variables['tid'];
$variables['form'] = '';
$variables['subscription_link'] = '';
$variables['newsletter_link'] = '';
$variables['issue_list'] = '';
$variables['rssfeed'] = '';
$variables['message'] = check_plain(variable_get('simplenews_block_m_' . $tid, t('Stay informed on our latest news!')));
if (user_access('subscribe to newsletters')) {
$variables['form'] = drupal_get_form('simplenews_block_form_' . $tid);
$variables['subscription_link'] = l(t('Manage my subscriptions'), 'newsletter/subscriptions');
}
$variables['newsletter_link'] = l(t('Previous issues'), 'taxonomy/term/' . $tid);
$recent = simplenews_recent_newsletters($tid, variable_get('simplenews_block_i_' . $tid, 5));
$variables['issue_list'] = theme('item_list', $recent, t('Previous issues'), 'ul');
$term = taxonomy_get_term($tid);
$variables['rssfeed'] = theme('feed_icon', url('taxonomy/term/' . $tid . '/0/feed'), t('@newsletter feed', array(
'@newsletter' => $term->name,
)));
$variables['use_form'] = variable_get('simplenews_block_f_' . $tid, 1);
$variables['use_issue_link'] = variable_get('simplenews_block_l_' . $tid, 1);
$variables['use_issue_list'] = variable_get('simplenews_block_i_status_' . $tid, 0);
$variables['use_rss'] = variable_get('simplenews_block_r_' . $tid, 1);
$variables['subscribed'] = empty($user->uid) ? FALSE : simplenews_user_is_subscribed($user->mail, $tid) == TRUE;
$variables['user'] = !empty($user->uid);
}
function theme_simplenews_newsletter_subject($name, $title, $language) {
return '[' . $name . '] ' . $title;
}
function template_preprocess_simplenews_newsletter_body(&$variables) {
$variables['title'] = check_plain($variables['node']->title);
$variables['body'] = $variables['node']->body;
}
function template_preprocess_simplenews_newsletter_footer(&$variables) {
$variables['format'] = $variables['node']->simplenews['s_format'];
$variables['unsubscribe_text'] = t('Unsubscribe from this newsletter', array(), $variables['language']->language);
$variables['test_message'] = t('This is a test version of the newsletter.', array(), $variables['language']->language);
}