first import

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-08 11:40:19 +02:00
commit 1bc61b12ad
8435 changed files with 1582817 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,95 @@
<?php
/**
* @file
* Hooks provided by the Simplenews module.
*/
/**
* @todo
*/
function hook_simplenews_issue_operations() {
}
/**
* @todo
*/
function hook_simplenews_subscription_operations() {
}
/**
* @todo
*/
function hook_simplenews_category_insert($category) {
}
/**
* @todo
*/
function hook_simplenews_category_update($category) {
}
/**
* @todo
*/
function hook_simplenews_category_delete($category) {
}
/**
* @todo
*/
function hook_simplenews_mailing_list_insert($list) {
}
/**
* @todo
*/
function hook_simplenews_subscriber_update($subscriber) {
}
/**
* @todo
*/
function hook_simplenews_subscriber_insert($subscriber) {
}
/**
* @todo
*/
function hook_simplenews_subscriber_delete($subscriber) {
}
/**
* Invoked if a user is subscribed to a newsletter.
*
* @param $subscriber
* The subscriber object including all subscriptions of this user.
*
* @param $subscription
* The subscription object for this specific subscribe action.
*/
function hook_simplenews_subscribe_user($subscriber, $subscription) {
}
/**
* Invoked if a user is unsubscribed from a newsletter.
*
* @param $subscriber
* The subscriber object including all subscriptions of this user.
*
* @param $subscription
* The subscription object for this specific unsubscribe action.
*/
function hook_simplenews_unsubscribe_user($subscriber, $subscription) {
}

View File

@@ -0,0 +1,879 @@
<?php
/**
* @file
* Simplenews email send and spool handling
*
* @ingroup mail
*/
/**
* Add the newsletter node to the mail spool.
*
* @param $node
* The newsletter node to be sent.
*
* @ingroup issue
*/
function simplenews_add_node_to_spool($node) {
// To send the newsletter, the node id and target email addresses
// are stored in the spool.
// Only subscribed recipients are stored in the spool (status = 1).
$select = db_select('simplenews_subscriber', 's');
$select->innerJoin('simplenews_subscription', 't', 's.snid = t.snid');
$select->addField('s', 'mail');
$select->addField('s', 'snid');
$select->addField('t', 'tid');
$select->addExpression($node->nid, 'nid');
$select->addExpression(SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, 'status');
$select->addExpression(REQUEST_TIME, 'timestamp');
$select->condition('t.tid', $node->simplenews->tid);
$select->condition('t.status', SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED);
$select->condition('s.activated', SIMPLENEWS_SUBSCRIPTION_ACTIVE);
db_insert('simplenews_mail_spool')
->from($select)
->execute();
// Update simplenews newsletter status to send pending.
simplenews_newsletter_update_sent_status($node);
}
/**
* Send mail spool immediatly if cron should not be used.
*
* @param $conditions
* (Optional) Array of spool conditions which are applied to the query.
*/
function simplenews_mail_attempt_immediate_send(array $conditions = array(), $use_batch = TRUE) {
if (variable_get('simplenews_use_cron', TRUE)) {
return FALSE;
}
if ($use_batch) {
// Set up as many send operations as necessary to send all mails with the
// defined throttle amount.
$throttle = variable_get('simplenews_throttle', 20);
$spool_count = simplenews_count_spool($conditions);
$num_operations = ceil($spool_count / $throttle);
$operations = array();
for ($i = 0; $i < $num_operations; $i++) {
$operations[] = array('simplenews_mail_spool', array($throttle, $conditions));
}
// Add separate operations to clear the spool and updat the send status.
$operations[] = array('simplenews_clear_spool', array());
$operations[] = array('simplenews_send_status_update', array());
$batch = array(
'operations' => $operations,
'title' => t('Sending mails'),
'file' => drupal_get_path('module', 'simplenews') . '/includes/simplenews.mail.inc',
);
batch_set($batch);
}
else {
// Send everything that matches the conditions immediatly.
simplenews_mail_spool(SIMPLENEWS_UNLIMITED, $conditions);
simplenews_clear_spool();
simplenews_send_status_update();
}
return TRUE;
}
/**
* Send test version of newsletter.
*
* @param mixed $node
* The newsletter node to be sent.
*
* @ingroup issue
*/
function simplenews_send_test($node, $test_addresses) {
// Prevent session information from being saved while sending.
if ($original_session = drupal_save_session()) {
drupal_save_session(FALSE);
}
// Force the current user to anonymous to ensure consistent permissions.
$original_user = $GLOBALS['user'];
$GLOBALS['user'] = drupal_anonymous_user();
// Send the test newsletter to the test address(es) specified in the node.
// Build array of test email addresses
// Send newsletter to test addresses.
// Emails are send direct, not using the spool.
$recipients = array('anonymous' => array(), 'user' => array());
foreach ($test_addresses as $mail) {
$mail = trim($mail);
if (!empty($mail)) {
$subscriber = simplenews_subscriber_load_by_mail($mail);
if (!$subscriber) {
// The source expects a subscriber object with mail and language set.
// @todo: Find a cleaner way to do this.
$subscriber = new stdClass();
$subscriber->uid = 0;
$subscriber->mail = $mail;
$subscriber->language = $GLOBALS['language']->language;
}
if (!empty($account->uid)) {
$recipients['user'][] = $account->name . ' <' . $mail . '>';
}
else {
$recipients['anonymous'][] = $mail;
}
$source = new SimplenewsSourceNode($node, $subscriber);
$source->setKey('test');
$result = simplenews_send_source($source);
}
}
if (count($recipients['user'])) {
$recipients_txt = implode(', ', $recipients['user']);
drupal_set_message(t('Test newsletter sent to user %recipient.', array('%recipient' => $recipients_txt)));
}
if (count($recipients['anonymous'])) {
$recipients_txt = implode(', ', $recipients['anonymous']);
drupal_set_message(t('Test newsletter sent to anonymous %recipient.', array('%recipient' => $recipients_txt)));
}
$GLOBALS['user'] = $original_user;
if ($original_session) {
drupal_save_session(TRUE);
}
}
/**
* Send a node to an email address.
*
* @param $source
* The source object.s
*
* @return boolean
* TRUE if the email was successfully delivered; otherwise FALSE.
*
* @ingroup source
*/
function simplenews_send_source(SimplenewsSourceInterface $source) {
$params['simplenews_source'] = $source;
// Send mail.
$message = drupal_mail('simplenews', $source->getKey(), $source->getRecipient(), $source->getLanguage(), $params, $source->getFromFormatted());
// Log sent result in watchdog.
if (variable_get('simplenews_debug', FALSE)) {
if ($message['result']) {
watchdog('simplenews', 'Outgoing email. Message type: %type<br />Subject: %subject<br />Recipient: %to', array('%type' => $source->getKey(), '%to' => $message['to'], '%subject' => $message['subject']), WATCHDOG_DEBUG);
}
else {
watchdog('simplenews', 'Outgoing email failed. Message type: %type<br />Subject: %subject<br />Recipient: %to', array('%type' => $source->getKey(), '%to' => $message['to'], '%subject' => $message['subject']), WATCHDOG_ERROR);
}
}
// Build array of sent results for spool table and reporting.
if ($message['result']) {
$result = array(
'status' => SIMPLENEWS_SPOOL_DONE,
'error' => FALSE,
);
}
else {
// This error may be caused by faulty mailserver configuration or overload.
// Mark "pending" to keep trying.
$result = array(
'status' => SIMPLENEWS_SPOOL_PENDING,
'error' => TRUE,
);
}
return $result;
}
/**
* Send simplenews newsletters from the spool.
*
* Individual newsletter emails are stored in database spool.
* Sending is triggered by cron or immediately when the node is saved.
* Mail data is retrieved from the spool, rendered and send one by one
* If sending is successful the message is marked as send in the spool.
*
* @todo: Redesign API to allow language counter in multilingual sends.
*
* @param $limit
* (Optional) The maximum number of mails to send. Defaults to
* unlimited.
* @param $conditions
* (Optional) Array of spool conditions which are applied to the query.
*
* @return
* Returns the amount of sent mails.
*
* @ingroup spool
*/
function simplenews_mail_spool($limit = SIMPLENEWS_UNLIMITED, array $conditions = array()) {
$check_counter = 0;
// Send pending messages from database cache.
$spool_list = simplenews_get_spool($limit, $conditions);
if ($spool_list) {
// Switch to the anonymous user.
simplenews_impersonate_user(drupal_anonymous_user());
$count_fail = $count_success = 0;
_simplenews_measure_usec(TRUE);
$spool = new SimplenewsSpool($spool_list);
while ($source = $spool->nextSource()) {
$source->setKey('node');
$result = simplenews_send_source($source);
// Update spool status.
// This is not optimal for performance but prevents duplicate emails
// in case of PHP execution time overrun.
foreach ($spool->getProcessed() as $msid => $row) {
$row_result = isset($row->result) ? $row->result : $result;
simplenews_update_spool(array($msid), $row_result);
if ($row_result['status'] == SIMPLENEWS_SPOOL_DONE) {
$count_success++;
}
if ($row_result['error']) {
$count_fail++;
}
}
// Check every n emails if we exceed the limit.
// When PHP maximum execution time is almost elapsed we interrupt
// sending. The remainder will be sent during the next cron run.
if (++$check_counter >= SIMPLENEWS_SEND_CHECK_INTERVAL && ini_get('max_execution_time') > 0) {
$check_counter = 0;
// Break the sending if a percentage of max execution time was exceeded.
$elapsed = _simplenews_measure_usec();
if ($elapsed > SIMPLENEWS_SEND_TIME_LIMIT * ini_get('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/config/simplenews/mail')), WATCHDOG_WARNING);
break;
}
}
// It is possible that all or at the end some results failed to get
// prepared, report them separately.
foreach ($spool->getProcessed() as $msid => $row) {
$row_result = isset($row->result) ? $row->result : $result;
simplenews_update_spool(array($msid), $row_result);
if ($row_result['status'] == SIMPLENEWS_SPOOL_DONE) {
$count_success++;
}
if ($row_result['error']) {
$count_fail++;
}
}
}
// Report sent result and elapsed time. On Windows systems getrusage() is
// not implemented and hence no elapsed time is available.
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));
}
variable_set('simplenews_last_cron', REQUEST_TIME);
variable_set('simplenews_last_sent', $count_success);
simplenews_revert_user();
return $count_success;
}
}
/**
* Save mail message in mail cache table.
*
* @param array $spool
* The message to be stored in the spool table, as an array containing the
* following keys:
* - mail
* - nid
* - tid
* - status: (optional) Defaults to SIMPLENEWS_SPOOL_PENDING
* - time: (optional) Defaults to REQUEST_TIME.
*
* @ingroup spool
*/
function simplenews_save_spool($spool) {
$status = isset($spool['status']) ? $spool['status'] : SIMPLENEWS_SPOOL_PENDING;
$time = isset($spool['time']) ? $spool['time'] : REQUEST_TIME;
db_insert('simplenews_mail_spool')
->fields(array(
'mail' => $spool['mail'],
'nid' => $spool['nid'],
'tid' => $spool['tid'],
'snid' => $spool['snid'],
'status' => $status,
'timestamp' => $time,
'data' => serialize($spool['data']),
))
->execute();
}
/*
* Returns the expiration time for IN_PROGRESS status.
*
* @return int
* A unix timestamp. Any IN_PROGRESS messages with a timestamp older than
* this will be re-allocated and re-sent.
*/
function simplenews_get_expiration_time() {
$timeout = variable_get('simplenews_spool_progress_expiration', 3600);
$expiration_time = REQUEST_TIME - $timeout;
return $expiration_time;
}
/**
* This function allocates messages to be sent in current run.
*
* Drupal acquire_lock guarantees that no concurrency issue happened.
* If the message status is SIMPLENEWS_SPOOL_IN_PROGRESS but the maximum send
* time has expired, the message id will be returned as a message which is not
* allocated to another process.
*
* @param $limit
* (Optional) The maximum number of mails to load from the spool. Defaults to
* unlimited.
* @param $conditions
* (Optional) Array of conditions which are applied to the query. If not set,
* status defaults to SIMPLENEWS_SPOOL_PENDING, SIMPLENEWS_SPOOL_IN_PROGRESS.
*
* @return
* An array of message ids to be sent in the current run.
*
* @ingroup spool
*/
function simplenews_get_spool($limit = SIMPLENEWS_UNLIMITED, $conditions = array()) {
$messages = array();
// Add default status condition if not set.
if (!isset($conditions['status'])) {
$conditions['status'] = array(SIMPLENEWS_SPOOL_PENDING, SIMPLENEWS_SPOOL_IN_PROGRESS);
}
// Special case for the status condition, the in progress actually only
// includes spool items whose locking time has expired. So this need to build
// an OR condition for them.
$status_or = db_or();
$statuses = is_array($conditions['status']) ? $conditions['status'] : array($conditions['status']);
foreach ($statuses as $status) {
if ($status == SIMPLENEWS_SPOOL_IN_PROGRESS) {
$status_or->condition(db_and()
->condition('status', $status)
->condition('s.timestamp', simplenews_get_expiration_time(), '<')
);
}
else {
$status_or->condition('status', $status);
}
}
unset($conditions['status']);
$query = db_select('simplenews_mail_spool', 's')
->fields('s')
->condition($status_or)
->orderBy('s.timestamp', 'ASC');
// Add conditions.
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
/* BEGIN CRITICAL SECTION */
// The semaphore ensures that multiple processes get different message ID's,
// so that duplicate messages are not sent.
if (lock_acquire('simplenews_acquire_mail')) {
// Get message id's
// Allocate messages
if ($limit > 0) {
$query->range(0, $limit);
}
foreach ($query->execute() as $message) {
if (strlen($message->data)) {
$message->data = unserialize($message->data);
}
else {
$message->data = simplenews_subscriber_load_by_mail($message->mail);
}
$messages[$message->msid] = $message;
}
if (count($messages) > 0) {
// Set the state and the timestamp of the messages
simplenews_update_spool(
array_keys($messages),
array('status' => SIMPLENEWS_SPOOL_IN_PROGRESS)
);
}
lock_release('simplenews_acquire_mail');
}
/* END CRITICAL SECTION */
return $messages;
}
/**
* Update status of mail data in spool table.
*
* Time stamp is set to current time.
*
* @param array $msids
* Array of Mail spool ids to be updated
* @param array $data
* Array containing email sent results, with the following keys:
* - status: An integer indicating the updated status. Must be one of:
* - 0: hold
* - 1: pending
* - 2: send
* - 3: in progress
* - error: (optional) The error id. Defaults to 0 (no error).
*
* @ingroup spool
*/
function simplenews_update_spool($msids, $data) {
db_update('simplenews_mail_spool')
->condition('msid', $msids)
->fields(array(
'status' => $data['status'],
'error' => isset($result['error']) ? (int)$data['error'] : 0,
'timestamp' => REQUEST_TIME,
))
->execute();
}
/**
* Count data in mail spool table.
*
* @param $conditions
* (Optional) Array of conditions which are applied to the query. Defaults
*
* @return
* Count of mail spool elements of the passed in arguments.
*
* @ingroup spool
*/
function simplenews_count_spool(array $conditions = array()) {
// Add default status condition if not set.
if (!isset($conditions['status'])) {
$conditions['status'] = array(SIMPLENEWS_SPOOL_PENDING, SIMPLENEWS_SPOOL_IN_PROGRESS);
}
$query = db_select('simplenews_mail_spool');
// Add conditions.
foreach ($conditions as $field => $value) {
$query->condition($field, $value);
}
$query->addExpression('COUNT(*)', 'count');
return (int)$query
->execute()
->fetchField();
}
/**
* Remove old records from mail spool table.
*
* All records with status 'send' and time stamp before the expiration date
* are removed from the spool.
*
* @return
* Number of deleted spool rows.
*
* @ingroup spool
*/
function simplenews_clear_spool() {
$expiration_time = REQUEST_TIME - variable_get('simplenews_spool_expire', 0) * 86400;
return db_delete('simplenews_mail_spool')
->condition('status', SIMPLENEWS_SPOOL_DONE)
->condition('timestamp', $expiration_time, '<=')
->execute();
}
/**
* Remove records from mail spool table according to the conditions.
*
* @return Count deleted
*
* @ingroup spool
*/
function simplenews_delete_spool(array $conditions) {
$query = db_delete('simplenews_mail_spool');
foreach ($conditions as $condition => $value) {
$query->condition($condition, $value);
}
return $query->execute();
}
/**
* Update newsletter sent status.
*
* Set newsletter sent status based on email sent status in spool table.
* Translated and untranslated nodes get a different treatment.
*
* The spool table holds data for emails to be sent and (optionally)
* already send emails. The simplenews_newsletter table contains the overall
* sent status of each newsletter issue (node).
* Newsletter issues get the status pending when sending is initiated. As
* long as unsend emails exist in the spool, the status of the newsletter remains
* unsend. When no pending emails are found the newsletter status is set 'send'.
*
* Translated newsletters are a group of nodes that share the same tnid ({node}.tnid).
* Only one node of the group is found in the spool, but all nodes should share
* the same state. Therefore they are checked for the combined number of emails
* in the spool.
*
* @ingroup issue
*/
function simplenews_send_status_update() {
$counts = array(); // number pending of emails in the spool
$sum = array(); // sum of emails in the spool per tnid (translation id)
$send = array(); // nodes with the status 'send'
// For each pending newsletter count the number of pending emails in the spool.
$query = db_select('simplenews_newsletter', 's');
$query->innerJoin('node', 'n', 's.nid = n.nid');
$query->fields('s', array('nid', 'tid'))
->fields('n', array('tnid'))
->condition('s.status', SIMPLENEWS_STATUS_SEND_PENDING);
foreach ($query->execute() as $newsletter) {
$counts[$newsletter->tnid][$newsletter->nid] = simplenews_count_spool(array('nid' => $newsletter->nid));
}
// Determine which nodes are send per translation group and per individual node.
foreach ($counts as $tnid => $node_count) {
// The sum of emails per tnid is the combined status result for the group of translated nodes.
// Untranslated nodes have tnid == 0 which will be ignored later.
$sum[$tnid] = array_sum($node_count);
foreach ($node_count as $nid => $count) {
// Translated nodes (tnid != 0)
if ($tnid != '0' && $sum[$tnid] == '0') {
$send[] = $nid;
}
// Untranslated nodes (tnid == 0)
elseif ($tnid == '0' && $count == '0') {
$send[] = $nid;
}
}
}
// Update overall newsletter status
if (!empty($send)) {
foreach ($send as $nid) {
db_update('simplenews_newsletter')
->condition('nid', $nid)
->fields(array('status' => SIMPLENEWS_STATUS_SEND_READY))
->execute();
}
}
}
/**
* Build formatted from-name and email for a mail object.
*
* @return Associative array with (un)formatted from address
* 'address' => From address
* 'formatted' => Formatted, mime encoded, from name and address
*/
function _simplenews_set_from() {
$address_default = variable_get('site_mail', ini_get('sendmail_from'));
$name_default = variable_get('site_name', 'Drupal');
$address = variable_get('simplenews_from_address', $address_default);
$name = variable_get('simplenews_from_name', $name_default);
// Windows based PHP systems don't accept formatted emails.
$formatted_address = substr(PHP_OS, 0, 3) == 'WIN' ? $address : '"' . $name . '" <' . $address . '>';
return array(
'address' => $address,
'formatted' => $formatted_address,
);
}
/**
* HTML to text conversion for HTML and special characters.
*
* Converts some special HTML characters in addition to drupal_html_to_text()
*
* @param string $text
* The source text with HTML and special characters.
* @param boolean $inline_hyperlinks
* TRUE: URLs will be placed inline.
* FALSE: URLs will be converted to numbered reference list.
* @return string
* The target text with HTML and special characters replaced.
*/
function simplenews_html_to_text($text, $inline_hyperlinks = TRUE) {
// By replacing <a> tag by only its URL the URLs will be placed inline
// in the email body and are not converted to a numbered reference list
// by drupal_html_to_text().
// URL are converted to absolute URL as drupal_html_to_text() would have.
if ($inline_hyperlinks) {
$pattern = '@<a[^>]+?href="([^"]*)"[^>]*?>(.+?)</a>@is';
$text = preg_replace_callback($pattern, '_simplenews_absolute_mail_urls', $text);
}
// Replace some special characters before performing the drupal standard conversion.
$preg = _simplenews_html_replace();
$text = preg_replace(array_keys($preg), array_values($preg), $text);
// Perform standard drupal html to text conversion.
return drupal_html_to_text($text);
}
/**
* Helper function for simplenews_html_to_text().
*
* Replaces URLs with absolute URLs.
*/
function _simplenews_absolute_mail_urls($match) {
global $base_url, $base_path;
$regexp = &drupal_static(__FUNCTION__);
$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 the link is formed by Drupal's URL filter, we only return the URL.
// The URL filter generates a label out of the original URL.
if (strpos($label, '...') === strlen($label) - 3) {
// Remove ellipsis from end of label.
$label = substr($label, 0, strlen($label) - 3);
}
if (strpos($url, $label) !== FALSE) {
return $url;
}
return $label . ' ' . $url;
}
}
/**
* Helper function for simplenews_html_to_text().
*
* List of preg* regular expression patterns to search for and replace with
*/
function _simplenews_html_replace() {
return array(
'/&quot;/i' => '"',
'/&gt;/i' => '>',
'/&lt;/i' => '<',
'/&amp;/i' => '&',
'/&copy;/i' => '(c)',
'/&trade;/i' => '(tm)',
'/&#8220;/' => '"',
'/&#8221;/' => '"',
'/&#8211;/' => '-',
'/&#8217;/' => "'",
'/&#38;/' => '&',
'/&#169;/' => '(c)',
'/&#8482;/' => '(tm)',
'/&#151;/' => '--',
'/&#147;/' => '"',
'/&#148;/' => '"',
'/&#149;/' => '*',
'/&reg;/i' => '(R)',
'/&bull;/i' => '*',
'/&euro;/i' => 'Euro ',
);
}
/**
* Helper function to measure PHP execution time in microseconds.
*
* @param bool $start
* If TRUE, reset the time and start counting.
*
* @return float
* The elapsed PHP execution time since the last start.
*/
function _simplenews_measure_usec($start = FALSE) {
// Windows systems don't implement getrusage(). There is no alternative.
if (!function_exists('getrusage')) {
return;
}
$start_time = &drupal_static(__FUNCTION__);
$usage = getrusage();
$now = (float)($usage['ru_stime.tv_sec'] . '.' . $usage['ru_stime.tv_usec']) + (float)($usage['ru_utime.tv_sec'] . '.' . $usage['ru_utime.tv_usec']);
if ($start) {
$start_time = $now;
return;
}
return $now - $start_time;
}
/**
* Build subject and body of the test and normal newsletter email.
*
* @param array $message
* Message array as used by hook_mail().
* @param array $source
* The SimplenewsSource instance.
*
* @ingroup source
*/
function simplenews_build_newsletter_mail(&$message, SimplenewsSourceInterface $source) {
// Get message data from source.
$message['headers'] = $source->getHeaders($message['headers']);
$message['subject'] = $source->getSubject();
$message['body']['body'] = $source->getBody();
$message['body']['footer'] = $source->getFooter();
// Optional params for HTML mails.
if ($source->getFormat() == 'html') {
$message['params']['plain'] = NULL;
$message['params']['plaintext'] = $source->getPlainBody() . "\n" . $source->getPlainFooter();
$message['params']['attachments'] = $source->getAttachments();
}
else {
$message['params']['plain'] = TRUE;
}
}
/**
* Build subject and body of the subscribe confirmation email.
*
* @param array $message
* Message array as used by hook_mail().
* @param array $params
* Parameter array as used by hook_mail().
*/
function simplenews_build_subscribe_mail(&$message, $params) {
$context = $params['context'];
$langcode = $message['language'];
// Use formatted from address "name" <mail_address>
$message['headers']['From'] = $params['from']['formatted'];
$message['subject'] = simplenews_subscription_confirmation_text('subscribe_subject', $langcode);
$message['subject'] = token_replace($message['subject'], $context, array('sanitize' => FALSE));
if (simplenews_user_is_subscribed($context['simplenews_subscriber']->mail, $context['category']->tid)) {
$body = simplenews_subscription_confirmation_text('subscribe_subscribed', $langcode);
}
else {
$body = simplenews_subscription_confirmation_text('subscribe_unsubscribed', $langcode);
}
$message['body'][] = token_replace($body, $context, array('sanitize' => FALSE));
}
/**
* Build subject and body of the subscribe confirmation email.
*
* @param array $message
* Message array as used by hook_mail().
* @param array $params
* Parameter array as used by hook_mail().
*/
function simplenews_build_combined_mail(&$message, $params) {
$context = $params['context'];
$changes = $context['changes'];
$langcode = $message['language'];
// Use formatted from address "name" <mail_address>
$message['headers']['From'] = $params['from']['formatted'];
$message['subject'] = simplenews_subscription_confirmation_text('combined_subject', $langcode);
$message['subject'] = token_replace($message['subject'], $context, array('sanitize' => FALSE));
$changes_list = '';
$actual_changes = 0;
foreach (simplenews_confirmation_get_changes_list($context['simplenews_subscriber'], $changes, $langcode) as $tid => $change) {
$changes_list .= ' - ' . $change . "\n";
// Count the actual changes.
$subscribed = simplenews_user_is_subscribed($context['simplenews_subscriber']->mail, $tid);
if ($changes[$tid] == 'subscribe' && !$subscribed || $changes[$tid] == 'unsubscribe' && $subscribed) {
$actual_changes++;
}
}
// If there are actual changes, use the combined_body key otherwise use the
// one without a confirmation link.
$body_key = $actual_changes ? 'combined_body' : 'combined_body_unchanged';
$body = simplenews_subscription_confirmation_text($body_key, $langcode);
// The changes list is not an actual token.
$body = str_replace('[changes-list]', $changes_list, $body);
$message['body'][] = token_replace($body, $context, array('sanitize' => FALSE));
}
/**
* Build subject and body of the unsubscribe confirmation email.
*
* @param array $message
* Message array as used by hook_mail().
* @param array $params
* Parameter array as used by hook_mail().
*/
function simplenews_build_unsubscribe_mail(&$message, $params) {
$context = $params['context'];
$langcode = $message['language'];
// Use formatted from address "name" <mail_address>
$message['headers']['From'] = $params['from']['formatted'];
$message['subject'] = simplenews_subscription_confirmation_text('subscribe_subject', $langcode);
$message['subject'] = token_replace($message['subject'], $context, array('sanitize' => FALSE));
if (simplenews_user_is_subscribed($context['simplenews_subscriber']->mail, $context['category']->tid)) {
$body = simplenews_subscription_confirmation_text('unsubscribe_subscribed', $langcode);
$message['body'][] = token_replace($body, $context, array('sanitize' => FALSE));
}
else {
$body = simplenews_subscription_confirmation_text('unsubscribe_unsubscribed', $langcode);
$message['body'][] = token_replace($body, $context, array('sanitize' => FALSE));
}
}
/**
* A mail sending implementation that captures sent messages to a variable.
*
* This class is for running tests or for development and does not convert HTML
* to plaintext.
*/
class SimplenewsHTMLTestingMailSystem implements MailSystemInterface {
/**
* Implements MailSystemInterface::format().
*/
public function format(array $message) {
// Join the body array into one string.
$message['body'] = implode("\n\n", $message['body']);
// Wrap the mail body for sending.
$message['body'] = drupal_wrap_mail($message['body']);
return $message;
}
/**
* Implements MailSystemInterface::mail().
*/
public function mail(array $message) {
$captured_emails = variable_get('drupal_test_email_collector', array());
$captured_emails[] = $message;
// @todo: This is rather slow when sending 100 and more mails during tests.
// Investigate in other methods like APC shared memory.
variable_set('drupal_test_email_collector', $captured_emails);
return TRUE;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,818 @@
<?php
/**
* @file
* (Un)subscription and (un)subscription confirmation
*
* FAPI subscription form cases:
* - ACCOUNT
* self/admin action: authenticated user
* via hook_user form: category=newsletter
*
* - BLOCK
* self action: anonymous / authenticated user
* via hook_block: block
*
* - PAGE
* self action: anonymous / authenticated user
* callback: newsletter/subscriptions
*
* - MULTI BLOCK
* self action: anonymous / authenticated user
* authenticated user
* via hook_block: multi_block
* using PAGE handlers
*
* - ADMIN
* admin action: authenticated user
* via hook_menu: admin
*
* FAPI additional form cases:
* - CONFIRM ADD
* - CONFIRM REMOVAL
*
* @ingroup simplenews
*/
/**
* FAPI ACCOUNT subscription form.
*
* Finally _account_ cases inject into hook_user and won't work on its own.
* Note that our basis is:
* drupal_get_form('user_profile_form', ...);
* and NOT:
* drupal_get_form('simplenews_subscriptions_account', ...);
*
* see also user/user.module and user/user.pages.inc
*
* @see simplenews_subscriptions_account_form_validate()
* @see simplenews_subscriptions_account_form_submit()
*/
function simplenews_subscriptions_account_form(&$form, &$form_state, $subscriber) {
$options = array();
$default_value = array();
// Get newsletters for subscription form checkboxes.
// Newsletters with opt-in/out method 'hidden' will not be listed.
foreach (simplenews_category_get_visible() as $newsletter) {
$options[$newsletter->tid] = check_plain(_simplenews_newsletter_name($newsletter));
$default_value[$newsletter->tid] = FALSE;
}
if ($subscriber) {
$default_value = array_merge($default_value, $subscriber->tids);
}
$form['subscriptions'] = array(
'#type' => 'fieldset',
'#description' => t('Select your newsletter subscriptions.'),
);
$form['subscriptions']['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value,
);
$form['subscriptions']['#title'] = t('Current newsletter subscriptions');
// if we don't override #validate, see user_profile_form_validate
// adding an own #submit leads to the situation where drupal omits execution of user_profile_form_submit completely
$form['#submit'][] = 'simplenews_subscriptions_account_form_submit';
}
/**
* FAPI ACCOUNT subscription form_submit.
*/
function simplenews_subscriptions_account_form_submit($form, &$form_state) {
global $user;
$account = $form['#user'];
// We first subscribe, then unsubscribe. This prevents deletion of subscriptions
// when unsubscribed from the
arsort($form_state['values']['newsletters'], SORT_NUMERIC);
foreach ($form_state['values']['newsletters'] as $tid => $checked) {
if ($checked) {
simplenews_subscribe_user($account->mail, $tid, FALSE, 'website');
}
else {
simplenews_unsubscribe_user($account->mail, $tid, FALSE, 'website');
}
}
if ($user->uid == $account->uid) {
drupal_set_message(t('Your newsletter subscriptions have been updated.'));
}
else {
drupal_set_message(t('The newsletter subscriptions for user %account have been updated.', array('%account' => $account->name)));
}
}
/**
* FAPI BLOCK subscription form.
*
* @param $tid term id of selected newsletter.
*
* @see simplenews_block_form_validate()
* @see simplenews_block_form_submit()
*/
function simplenews_block_form($form, &$form_state, $tid) {
global $user;
$form = array();
$submit_text = t('Subscribe');
if ($user->uid) {
if (simplenews_user_is_subscribed($user->mail, $tid)) {
$submit_text = t('Unsubscribe');
$form['action'] = array('#type' => 'value', '#value' => 'unsubscribe');
$form['#attributes'] = array('class' => array('simplenews-unsubscribe'));
}
else {
$form['action'] = array('#type' => 'value', '#value' => 'subscribe');
$form['#attributes'] = array('class' => array('simplenews-subscribe'));
}
$form['mail'] = array('#type' => 'value', '#value' => $user->mail);
}
else {
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#size' => 20,
'#maxlength' => 128,
'#required' => TRUE,
);
$form['action'] = array('#type' => 'value', '#value' => 'subscribe');
$form['#attributes'] = array('class' => array('simplenews-subscribe'));
}
// All block forms use the same validate and submit function.
// #tid carries the tid for processing of the right newsletter issue term.
$form['#tid'] = $tid;
$form['#validate'][] = 'simplenews_block_form_validate';
$form['#submit'][] = 'simplenews_block_form_submit';
$form['submit'] = array(
'#type' => 'submit',
'#value' => $submit_text,
);
return $form;
}
/*
* FAPI BLOCK subscription form_validate.
*/
function simplenews_block_form_validate($form, &$form_state) {
if (!valid_email_address($form_state['values']['mail'])) {
form_set_error('mail', t("The e-mail address you supplied is not valid."));
}
}
/*
* FAPI BLOCK subscription form_submit.
*/
function simplenews_block_form_submit($form, &$form_state) {
$tid = $form['#tid'];
$account = simplenews_load_user_by_mail($form_state['values']['mail']);
$confirm = simplenews_require_double_opt_in($tid, $account);
switch ($form_state['values']['action']) {
case 'subscribe':
simplenews_subscribe_user($form_state['values']['mail'], $tid, $confirm, 'website');
if ($confirm) {
drupal_set_message(t('You will receive a confirmation e-mail 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, 'website');
if ($confirm) {
drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to cancel your subscription.'));
}
else {
drupal_set_message(t('You have been unsubscribed.'));
}
break;
}
}
/**
* FAPI PAGE subscription form.
*
* @see simplenews_subscriptions_page_form_validate()
* @see simplenews_subscriptions_page_form_submit()
*/
function simplenews_subscriptions_page_form($form, &$form_state, $code = NULL) {
global $user;
$subscriber = $mail = FALSE;
if (!empty($user->mail)) {
$subscriber = simplenews_subscriber_load_by_mail($user->mail);
$mail = $user->mail;
}
// If a hash is provided, try to load the corresponding subscriber.
else if ($code) {
if (!$subscriber = simplenews_subscriber_load_by_hash($code)) {
drupal_not_found();
return;
}
$mail = $subscriber->mail;
}
$form = array();
$options = array();
$default_value = array();
// Get newsletters for subscription form checkboxes.
// Newsletters with opt-in/out method 'hidden' will not be listed.
foreach (simplenews_category_get_visible() as $newsletter) {
$options[$newsletter->tid] = check_plain($newsletter->name);
$default_value[$newsletter->tid] = FALSE;
}
if ($subscriber) {
// If there is an existing subscriber object, use the existing settings.
$default_value = array_merge($default_value, $subscriber->tids);
}
$form['subscriptions'] = array(
'#type' => 'fieldset',
);
$form['subscriptions']['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value
);
// If we have a mail address, which is either from a logged in user or a
// subscriber identified through the hash code, display the mail address
// instead of a textfield. Anonymous uses will still have to confirm any
// changes.
if ($mail) {
$form['subscriptions']['#title'] = t('Subscriptions for %mail', array('%mail' => $mail));
$form['subscriptions']['#description'] = t('Check the newsletters you want to subscribe to. Uncheck the ones you want to unsubscribe from.');
$form['subscriptions']['mail'] = array('#type' => 'value', '#value' => $mail);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 20,
// @todo: add clean submit handler
);
}
else {
$form['subscriptions']['#title'] = t('Manage your newsletter subscriptions');
$form['subscriptions']['#description'] = t('Select the newsletter(s) to which you want to subscribe or unsubscribe.');
$form['subscriptions']['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#size' => 20,
'#maxlength' => 128,
'#weight' => 10,
'#required' => TRUE,
);
$form['subscribe'] = array(
'#type' => 'submit',
'#value' => t('Subscribe'),
'#weight' => 20,
// @todo: add clean submit handler
);
$form['unsubscribe'] = array(
'#type' => 'submit',
'#value' => t('Unsubscribe'),
'#weight' => 30,
// @todo: add clean submit handler
);
}
$form['#validate'][] = 'simplenews_subscriptions_page_form_validate';
$form['#submit'][] = 'simplenews_subscriptions_page_form_submit';
return $form;
}
/**
* FAPI PAGE subscription form_validate.
*/
function simplenews_subscriptions_page_form_validate($form, &$form_state) {
$valid_email = valid_email_address($form_state['values']['mail']);
if (!$valid_email) {
form_set_error('mail', t('The e-mail address you supplied is not valid.'));
}
$checked_newsletters = array_filter($form_state['values']['newsletters']);
// Unless we're in update mode, at least one checkbox must be checked.
if (!count($checked_newsletters) && $form_state['values']['op'] != t('Update')) {
form_set_error('newsletters', t('You must select at least one newsletter.'));
}
}
/**
* FAPI PAGE subscription form_submit.
*/
function simplenews_subscriptions_page_form_submit($form, &$form_state) {
$mail = $form_state['values']['mail'];
$account = simplenews_load_user_by_mail($mail);
// Group confirmation mails as necessary and configured.
simplenews_confirmation_combine(TRUE);
switch ($form_state['values']['op']) {
case t('Update'):
// We first subscribe, then unsubscribe. This prevents deletion of subscriptions
// when unsubscribed from the
arsort($form_state['values']['newsletters'], SORT_NUMERIC);
foreach ($form_state['values']['newsletters'] as $tid => $checked) {
$confirm = simplenews_require_double_opt_in($tid, $account);
if ($checked) {
simplenews_subscribe_user($mail, $tid, $confirm, 'website');
}
else {
simplenews_unsubscribe_user($mail, $tid, $confirm, 'website');
}
}
if (simplenews_confirmation_send_combined()) {
drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.'));
}
else {
drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_state['values']['mail'])));
}
break;
case t('Subscribe'):
foreach ($form_state['values']['newsletters'] as $tid => $checked) {
if ($checked) {
$confirm = simplenews_require_double_opt_in($tid, $account);
simplenews_subscribe_user($mail, $tid, $confirm, 'website');
}
}
if (simplenews_confirmation_send_combined()) {
drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to complete your subscription.'));
}
else {
drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_state['values']['mail'])));
}
break;
case t('Unsubscribe'):
foreach ($form_state['values']['newsletters'] as $tid => $checked) {
if ($checked) {
$confirm = simplenews_require_double_opt_in($tid, $account);
simplenews_unsubscribe_user($mail, $tid, $confirm, 'website');
}
}
if (simplenews_confirmation_send_combined()) {
drupal_set_message(t('You will receive a confirmation e-mail shortly containing further instructions on how to cancel your subscription.'));
}
else {
drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_state['values']['mail'])));
}
break;
}
}
/**
* FAPI MULTI BLOCK subscription form.
*
* Menu callback: Generates the subscription form for users for the multisignup block.
*
* @see simplenews_subscriptions_multi_block_form_validate()
* @see simplenews_subscriptions_multi_block_form_submit()
*/
function simplenews_subscriptions_multi_block_form($form, &$form_state) {
global $user;
$subscriber = !empty($user->mail) ? simplenews_subscriber_load_by_mail($user->mail) : FALSE;
// If someone not authorized to edit their subscription, return empty form.
if (!user_access('subscribe to newsletters')) {
return;
}
$form = array();
$options = array();
$default_value = array();
// Get newsletters for subscription form checkboxes.
// Newsletters with opt-in/out method 'hidden' will not be listed.
foreach (simplenews_category_get_visible() as $newsletter) {
$options[$newsletter->tid] = check_plain($newsletter->name);
$default_value[$newsletter->tid] = FALSE;
}
if ($subscriber) {
// If there is an existing subscriber object, use the existing settings.
$default_value = array_merge($default_value, $subscriber->tids);
}
$form['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => $default_value,
);
// If current user is logged in, just display email.
// Anonymous users see an email box and will receive confirmations
if (user_is_logged_in()) {
// @todo why not simply Manage your subscriptions?
$form['mail'] = array('#type' => 'value', '#value' => $user->mail);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 20,
// @todo: add clean submit handler
);
}
else {
$form['mail'] = array(
'#type' => 'textfield',
'#title' => t('E-mail'),
'#size' => 20,
'#maxlength' => 128,
'#weight' => 10,
'#required' => TRUE,
);
$form['subscribe'] = array(
'#type' => 'submit',
'#value' => t('Subscribe'),
'#weight' => 20,
// @todo: add clean submit handler
);
$form['unsubscribe'] = array(
'#type' => 'submit',
'#value' => t('Unsubscribe'),
'#weight' => 30,
// @todo: add clean submit handler
);
}
$form['#validate'][] = 'simplenews_subscriptions_page_form_validate';
$form['#submit'][] = 'simplenews_subscriptions_page_form_submit';
return $form;
}
/**
* Menu callback: confirm the user's (un)subscription request
*
* This function is called by clicking the confirm link in the confirmation
* email or the unsubscribe link in the footer of the newsletter. It handles
* both subscription addition and subscription removal.
*
* Calling URLs are:
* newsletter/confirm/add
* newsletter/confirm/add/$HASH
* newsletter/confirm/remove
* newsletter/confirm/remove/$HASH
*
* @see simplenews_confirm_add_form()
* @see simplenews_confirm_removal_form()
*/
/**
* Menu callback: confirm the user's (un)subscription request
*
* This function is called by clicking the confirm link in the confirmation
* email or the unsubscribe link in the footer of the newsletter. It handles
* both subscription addition and subscription removal.
*
* @see simplenews_confirm_add_form()
* @see simplenews_confirm_removal_form()
*
* @todo Add parameter description here.
*/
function simplenews_confirm_subscription() {
$arguments = func_get_args();
$op = array_shift($arguments);
$code = array_shift($arguments);
if ($subscriber = simplenews_subscriber_load_by_hash($code)) {
// Extract the category id.
list($snid, $tid) = explode('t', drupal_substr($code, 10));
if ($tid > 0) {
$category = simplenews_category_load($tid);
}
// The confirmation page called with two arguments will display a confirmation question.
// When called with three of more arguments the user will be directed to the
// (un)subscribe confirmation page. The additional arguments will be passed on
// to the confirmation page.
if (empty($arguments)) {
if ($op == 'remove') {
return drupal_get_form('simplenews_confirm_removal_form', $subscriber->mail, $category);
}
elseif ($op == 'add') {
return drupal_get_form('simplenews_confirm_add_form', $subscriber->mail, $category);
}
elseif ($op == 'combined' && !empty($subscriber->changes)) {
return drupal_get_form('simplenews_confirm_multi_form', $subscriber);
}
}
else {
if ($op == 'remove') {
simplenews_unsubscribe_user($subscriber->mail, $tid, FALSE, 'website');
if ($path = variable_get('simplenews_confirm_unsubscribe_page', '')) {
$path = $path . '/' . implode('/', $arguments);
drupal_goto($path);
}
drupal_set_message(t('%user was unsubscribed from the %newsletter mailing list.', array('%user' => $subscriber->mail, '%newsletter' => _simplenews_newsletter_name($category))));
drupal_goto(variable_get('site_frontpage', 'node'));
}
else if ($op == 'add') {
simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website');
if ($path = variable_get('simplenews_confirm_subscribe_page', '')) {
$path = $path . '/' . implode('/', $arguments);
drupal_goto($path);
}
drupal_set_message(t('%user was added to the %newsletter mailing list.', array('%user' => $subscriber->mail, '%newsletter' => _simplenews_newsletter_name($category))));
drupal_goto(variable_get('site_frontpage', 'node'));
}
else if ($op == 'combined' && !empty($subscriber->changes)) {
foreach ($subscriber->changes as $tid => $action) {
if ($action == 'subscribe') {
simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website');
}
else if ($action == 'subscribe') {
simplenews_unsubscribe_user($subscriber->mail, $tid, FALSE, 'website');
}
}
// Clear changes.
$subscriber->changes = array();
simplenews_subscriber_save($subscriber);
drupal_set_message(t('Subscription changes confirmed for %user.', array('%user' => $subscriberil)));
drupal_goto(variable_get('site_frontpage', 'node'));
}
}
}
// If md5 didn't match, do a not found.
drupal_not_found();
return;
}
/**
* Generate the confirm subscription form.
*
* @see simplenews_confirm_add_form_submit()
*/
function simplenews_confirm_add_form($form, &$form_state, $mail, $newsletter) {
$form = array();
$form['question'] = array(
'#markup' => '<p>' . t('Are you sure you want to add %user to the %newsletter mailing list?', array('%user' => $mail, '%newsletter' => _simplenews_newsletter_name($newsletter))) . "<p>\n",
);
$form['mail'] = array(
'#type' => 'value',
'#value' => $mail,
);
$form['newsletter'] = array(
'#type' => 'value',
'#value' => $newsletter,
);
return confirm_form($form,
t('Confirm subscription'),
'',
t('You can always unsubscribe later.'),
t('Subscribe'),
t('Cancel')
);
}
function simplenews_confirm_add_form_submit($form, &$form_state) {
simplenews_subscribe_user($form_state['values']['mail'], $form_state['values']['newsletter']->tid, FALSE, 'website');
if (!$path = variable_get('simplenews_confirm_subscribe_page', '')){
$path = variable_get('site_frontpage', 'node');
drupal_set_message(t('%user was added to the %newsletter mailing list.', array('%user' => $form_state['values']['mail'], '%newsletter' => _simplenews_newsletter_name($form_state['values']['newsletter']))));
}
$form_state['redirect'] = $path;
}
/**
* Generate the confirm subscription form.
*
* @see simplenews_confirm_add_form_submit()
*/
function simplenews_confirm_multi_form($form, &$form_state, $subscriber) {
$form = array();
$form['question'] = array(
'#markup' => '<p>' . t('Are you sure you want to confirm the following subscription changes for %user?', array('%user' => $subscriber->mail)) . "<p>\n",
);
$form['changes'] = array(
'#theme' => 'item_list',
'#items' => simplenews_confirmation_get_changes_list($subscriber),
);
$form['subscriber'] = array(
'#type' => 'value',
'#value' => $subscriber,
);
return confirm_form($form,
t('Confirm subscription'),
'',
t('You can always change your subscriptions later.'),
t('Confirm'),
t('Cancel')
);
}
function simplenews_confirm_multi_form_submit($form, &$form_state) {
$subscriber = $form_state['values']['subscriber'];
foreach ($subscriber->changes as $tid => $action) {
if ($action == 'subscribe') {
simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website');
}
else if ($action == 'unsubscribe') {
simplenews_unsubscribe_user($subscriber->mail, $tid, FALSE, 'website');
}
}
// Clear changes.
$subscriber->changes = array();
simplenews_subscriber_save($subscriber);
drupal_set_message(t('Subscription changes confirmed for %user.', array('%user' => $subscriber->mail)));
$form_state['redirect'] = variable_get('site_frontpage', 'node');
}
/**
* Generate the confirm unsubscription form.
*
* @see simplenews_confirm_removal_form_submit()
*/
function simplenews_confirm_removal_form($form, &$form_state, $mail, $newsletter) {
$form = array();
$form['question'] = array(
'#markup' => '<p>' . t('Are you sure you want to remove %user from the %newsletter mailing list?', array('%user' => $mail, '%newsletter' => _simplenews_newsletter_name($newsletter))) . "<p>\n",
);
$form['mail'] = array(
'#type' => 'value',
'#value' => $mail,
);
$form['newsletter'] = array(
'#type' => 'value',
'#value' => $newsletter,
);
return confirm_form($form,
t('Confirm remove subscription'),
'',
t('This action will unsubscribe you from the newsletter mailing list.'),
t('Unsubscribe'),
t('Cancel')
);
}
function simplenews_confirm_removal_form_submit($form, &$form_state) {
simplenews_unsubscribe_user($form_state['values']['mail'], $form_state['values']['newsletter']->tid, FALSE, 'website');
if (!$path = variable_get('simplenews_confirm_unsubscribe_page', '')){
$path = variable_get('site_frontpage', 'node');
drupal_set_message(t('%user was unsubscribed from the %newsletter mailing list.', array('%user' => $form_state['values']['mail'], '%newsletter' => _simplenews_newsletter_name($form_state['values']['newsletter']))));
}
$form_state['redirect'] = $path;
}
/**
* FAPI ADMIN subscription form.
*
* Menu callback: handle the edit subscription page and a subscription
* page for anonymous users.
*
* @see simplenews_subscriptions_admin_form_validate()
* @see simplenews_subscriptions_admin_form_submit()
*/
function simplenews_subscriptions_admin_form($form, &$form_state, $snid) {
$subscriber = simplenews_subscriber_load($snid);
$form = array();
$options = array();
$default_value = array();
// Get newsletters for subscription form checkboxes.
// Newsletters with opt-in/out method 'hidden' will not be listed.
foreach (simplenews_category_get_visible() as $newsletter) {
$options[$newsletter->tid] = check_plain($newsletter->name);
$default_value[$newsletter->tid] = FALSE;
}
$form['subscriptions'] = array(
'#title' => t('Subscriptions for %mail', array('%mail' => $subscriber->mail)),
'#type' => 'fieldset',
'#description' => t('Select the newsletter(s) to add/remove from subscription.'),
);
$form['subscriptions']['newsletters'] = array(
'#type' => 'checkboxes',
'#options' => $options,
'#default_value' => array_merge($default_value, $subscriber->tids),
);
$form['activated'] = array(
'#title' => t('Activation'),
'#type' => 'fieldset',
'#description' => t('Activate or inactivate account.'),
);
$form['activated']['activated'] = array(
'#type' => 'checkbox',
'#title' => t('Activated'),
'#default_value' => $subscriber->activated,
);
if ((variable_get('language_count', 1) > 1)) {
// @todo we could allow to switch back to "default", but user_load
//$language_options[''] = t('Site default language');
$languages = language_list('enabled');
foreach ($languages[1] as $langcode => $item) {
$name = t($item->name);
$language_options[$langcode] = $name . ($item->native != $name ? ' ('. $item->native .')' : '');
}
// std users have language in profile. disable
$disabled = $subscriber->uid ? TRUE : FALSE;
$form['language'] = array(
'#type' => 'fieldset',
'#title' => 'Preferred language',
'#description' => t('The e-mails will be localized in language chosen. Real users have their preference in account settings.'),
'#disabled' => FALSE,
);
if ($subscriber->uid) {
// fapi error: disabled not supported for select type. workaround: output markup
$form['language']['language'] = array(
'#type' => 'markup',
'#value' => $language_options[$subscriber->language],
);
}
else {
$form['language']['language'] = array(
'#type' => 'select',
'#default_value' => $subscriber->language,
'#options' => $language_options,
);
}
}
$form['subscriptions']['mail'] = array('#type' => 'value', '#value' => $subscriber->mail);
$form['update'] = array(
'#type' => 'submit',
'#value' => t('Update'),
'#weight' => 20,
);
$form['#validate'][] = 'simplenews_subscriptions_admin_form_validate';
$form['#submit'][] = 'simplenews_subscriptions_admin_form_submit';
$form['#redirect'] = 'admin/content/simplenews/users';
return $form;
}
/**
* FAPI ADMIN subscription form_validate.
*/
function simplenews_subscriptions_admin_form_validate($form, &$form_state) {
$subscriber = simplenews_subscriber_load_by_mail($form_state['values']['mail']);
$valid_email = valid_email_address($form_state['values']['mail']);
if (!$valid_email) {
form_set_error('mail', t('The e-mail address you supplied is not valid.'));
}
$checked_newsletters = array_filter($form_state['values']['newsletters']);
if (!count($checked_newsletters) && !$subscriber) {
form_set_error('newsletters', t('You must select at least one newsletter.'));
}
$languages = language_list('enabled');
if (!empty($form_state['values']['language'])
&& !isset($languages[1][$form_state['values']['language']])) {
form_set_error('language', t('Please choose a language from the list.'));
}
}
/**
* FAPI ADMIN subscription form_submit.
*/
function simplenews_subscriptions_admin_form_submit($form, &$form_state) {
$subscriber = simplenews_subscriber_load_by_mail($form_state['values']['mail']);
// update subscriptions
arsort($form_state['values']['newsletters'], SORT_NUMERIC);
foreach ($form_state['values']['newsletters'] as $tid => $checked) {
if ($checked) {
simplenews_subscribe_user($form_state['values']['mail'], $tid, FALSE, 'website');
}
else {
simplenews_unsubscribe_user($form_state['values']['mail'], $tid, FALSE, 'website');
}
}
// update subscriber
$data = array();
$subscriber->activated = $form_state['values']['activated'];
if (!$subscriber->uid) {
if (isset($form_state['values']['language'])) {
$subscriber->language = $form_state['values']['language'];
}
}
simplenews_subscriber_save($subscriber);
drupal_set_message(t('The newsletter subscriptions for %mail have been updated.', array('%mail' => $form_state['values']['mail'])));
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* Views handler for simplenews field simplewnews_category.hyperlinks.
*/
/**
* Provide HTML Mail Hyperlinks position settings.
*/
class simplenews_handler_field_category_hyperlinks extends views_handler_field {
function render($values) {
switch ($values->{$this->field_alias}) {
case 0:
return t('Bottom');
case 1:
return t('Inline');
}
}
}

View File

@@ -0,0 +1,21 @@
<?php
/**
* @file
* Views field handler for simplenews_category.opt_inout.
*/
/**
* Provide translatable simplenews_category.opt_inout Options.
*/
class simplenews_handler_field_category_new_account extends views_handler_field {
function render($values) {
$opt = array(
'none' => t('None'),
'on' => t('Default on'),
'off' => t('Default off'),
'silent' => t('invisible Subscrition'),
);
return check_plain($opt[$values->{$this->field_alias}]);
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* Views field handler for simplenews_category.opt_inout.
*/
/**
* Provide translatable simplenews_category.opt_inout Options.
*/
class simplenews_handler_field_category_opt_inout extends views_handler_field {
function render($values) {
$opt = array(
'hidden' => t('Hidden'),
'single' => t('Single opt-in'),
'double' => t('Double opt-in'),
);
return check_plain($opt[$values->{$this->field_alias}]);
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Views field handler for simplenews newsletter priority.
*/
/**
* Display simplenews newsletter priorities. See simplenews.admin.inc
* @ row 1427 for definition of the simplenews_get_priority() function
*/
class simplenews_handler_field_newsletter_priority extends views_handler_field {
function render($values) {
module_load_include('inc', 'simplenews', 'includes/simplenews.admin');
$p = simplenews_get_priority();
return check_plain($p[$values->{$this->field_alias}]);
}
}

View File

@@ -0,0 +1,26 @@
<?php
/**
* Field handler to present a link to close or open commenting on a node.
*/
class simplenews_handler_field_newsletter_send extends views_handler_field_node_link {
/**
* Renders the link.
*/
function render_link($node, $values) {
// Ensure user has access to delete this node.
if (!user_access('send newsletter')) {
return;
}
$this->options['alter']['make_link'] = TRUE;
$this->options['alter']['query'] = drupal_get_destination();
if ($node->simplenews->status == SIMPLENEWS_STATUS_SEND_NOT) {
$this->options['alter']['path'] = "node/$node->nid/simplenews";
$text = !empty($this->options['text']) ? $this->options['text'] : t('Send newsletter');
return $text;
}
else {
return;
}
}
}

View File

@@ -0,0 +1,23 @@
<?php
/**
* @file
* Views handler for simplenews sent status.
*/
/**
* Display newsletter sent status.
*/
class simplenews_handler_field_newsletter_status extends views_handler_field {
function render($values) {
switch ($values->{$this->field_alias}) {
case SIMPLENEWS_STATUS_SEND_NOT:
default:
return t('Not sent');
case SIMPLENEWS_STATUS_SEND_PENDING:
return t('Pending');
case SIMPLENEWS_STATUS_SEND_READY:
return t('Sent');
}
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Views handler for simplenews field simplewnews_category.hyperlinks.
*/
/**
* Display HTML Mail Hyperlinks position settings.
*/
class simplenews_handler_filter_category_hyperlinks extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
0 => t('Bottom'),
1 => t('Inline'),
);
}
}

View File

@@ -0,0 +1,20 @@
<?php
/**
* @file
* Views fiter handler for simplenews_category.new_account.
*/
/**
* Provide translatable simplenews_category.new_account Options.
*/
class simplenews_handler_filter_category_new_account extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
'none' => t('None'),
'on' => t('Default on'),
'off' => t('Default off'),
'silent' => t('invisible Subscrition'),
);
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @file
* Views fiter handler for simplenews_category.opt_inout.
*/
/**
* Provide translatable simplenews_category.opt_inout Options.
*/
class simplenews_handler_filter_category_opt_inout extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
'hidden' => t('Hidden'),
'single' => t('Single opt-in'),
'double' => t('Double opt-in'),
);
}
}

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Views filter handler for simplenews newsletter priorities
*/
/*
* Display simplenews newsletter priorities. See simplenews.admin.inc
* @row 1427 for definition of the simplenews_get_priority() function
*/
class simplenews_handler_filter_newsletter_priority extends views_handler_filter_in_operator {
function get_value_options() {
module_load_include('inc', 'simplenews', 'includes/simplenews.admin');
$this->value_options = simplenews_get_priority();
}
}

View File

@@ -0,0 +1,19 @@
<?php
/**
* @file
* Views filter for simplenews sent status.
*/
/**
* Filter based on newsletter sent status.
*/
class simplenews_handler_filter_newsletter_status extends views_handler_filter_in_operator {
function get_value_options() {
$this->value_options = array(
SIMPLENEWS_STATUS_SEND_NOT => t('Not sent'),
SIMPLENEWS_STATUS_SEND_PENDING => t('Pending'),
SIMPLENEWS_STATUS_SEND_READY => t('Sent'),
);
}
}

View File

@@ -0,0 +1,805 @@
<?php
/**
* @file
* Views interface for simplenews.
*/
/**
* Implements hook_views_data().
*/
function simplenews_views_data() {
/* ------------ Definitions for Simplenews mailspool ----------------------*/
$data['simplenews_mail_spool']['table'] = array(
'base' => array(
'field' => 'msid',
'title' => t('Simplenews mailspool'),
'help' => t('Spool for temporary storage of newsletter emails.'),
'weight' => 10,
'database' => 'default',
),
'group' => t('Simplenews spool'),
);
$data['simplenews_mail_spool']['msid'] = array(
'title' => t('Ms ID'),
'help' => t('The primary identifier for a mail spool record.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_mail_spool']['mail'] = array(
'title' => t('Subscriber'),
'help' => t('The formatted email address of mail message receipient.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_mail_spool']['nid'] = array(
'title' => t('Node ID'),
'help' => t('The {node}.nid of this newsletter.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'node',
'base field' => 'nid',
'label' => t('Node'),
),
);
$data['simplenews_mail_spool']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The {term_data}.tid this newsletter issue belongs to.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'taxonomy_term_data',
'base field' => 'tid',
'label' => t('Issue'),
),
);
$data['simplenews_mail_spool']['snid'] = array(
'title' => t('Subscriber ID'),
'help' => t('The {simplenews_subscriber}.snid foreign key for this spool'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'simplenews_subscriber',
'base field' => 'snid',
'label' => t('Subscriber'),
),
);
$data['simplenews_mail_spool']['status'] = array(
'title' => t('Sent status'),
'help' => t('The sent status of the email (0 = hold, 1 = pending, 2 = done).'),
'field' => array(
'handler' => 'simplenews_handler_field_newsletter_status',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'simplenews_handler_filter_newsletter_status',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_mail_spool']['error'] = array(
'title' => t('Error'),
'help' => t('A boolean indicating whether an error occured while sending the email.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_mail_spool']['timestamp'] = array(
'title' => t('Timestamp'),
'help' => t('The time status was set or changed.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
);
$data['simplenews_mail_spool']['data'] = array(
'title' => t('Data'),
'help' => t('A serialized array of name value pairs that are related to the email address.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
/* ------------ Definitions for Simplenews issue ----------------------*/
$data['simplenews_newsletter']['table'] = array(
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
'group' => t('Simplenews issue'),
);
// Joins
$data['simplenews_newsletter']['table']['join'] = array(
'node' => array(
'left_field' => 'nid',
'field' => 'nid',
),
'taxonomy_term_data' => array(
'left_field' => 'tid',
'field' => 'tid',
),
);
$data['simplenews_newsletter']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The {term_data}.tid (= newsletter series) this issue belongs to.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'taxonomy_term_data',
'base field' => 'tid',
'label' => t('Newsletter'),
),
);
$data['simplenews_newsletter']['status'] = array(
'title' => t('Sent status'), // The item it appears as on the UI,
'help' => t('Newsletter sent status: 0: Not sent, 1: Pending (being sent or waiting for cron to run), 2: Sent.'), // The help that appears on the UI,
'field' => array(
'handler' => 'simplenews_handler_field_newsletter_status',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'simplenews_handler_filter_newsletter_status',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_newsletter']['sent_subscriber_count'] = array(
'title' => t('Subscriber count'),
'help' => t('The count of subscribers of the newsletter at the time it was sent.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_newsletter']['send'] = array(
'field' => array(
'title' => t('Send newsletter'),
'help' => t('Provides a link to send the simplenews newsletter if not sent yet.'),
'handler' => 'simplenews_handler_field_newsletter_send',
),
);
/* ------------ Definitions for Simplenews subscriber ----------------------*/
$data['simplenews_subscriber']['table'] = array(
'base' => array(
'field' => 'snid',
'title' => t('Simplenews subscriber'),
'help' => t('Contains subscribers of Simplenews Newsletters.'),
'weight' => 10,
'database' => 'default',
),
'group' => t('Simplenews subscriber'),
);
// Joins
$data['simplenews_subscriber']['table']['join'] = array(
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
$data['simplenews_subscriber']['snid'] = array(
'title' => t('Subscriber ID'),
'help' => t('Primary key: Unique subsciber ID.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_subscriber']['activated'] = array(
'title' => t('Activated'),
'help' => t('Boolean indicating the status of the subscription.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_subscriber']['mail'] = array(
'title' => t('Subscriber'),
'help' => t('The subscription email address.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_subscriber']['uid'] = array(
'title' => t('User'),
'help' => t('The {users}.uid that has the same email address.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'users',
'base field' => 'uid',
'label' => t('user'),
),
);
$data['simplenews_subscriber']['language'] = array(
'title' => t('Language'),
'help' => t('Anonymous subscriber preferred language. Empty for authenticated users.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_subscriber']['timestamp'] = array(
'title' => t('Timestamp'),
'help' => t('UNIX timestamp of when the user first subscribed to a newsletter.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
);
/* ------------ Definitions for Simplenews subscription ----------------------*/
$data['simplenews_subscription']['table'] = array(
'base' => array(
'field' => 'snid',
'title' => t('Simplenews subscription'),
'help' => t('Contains all Subscriptions of every Simplenews Newsletters.'),
'weight' => 10,
'database' => 'default',
),
'group' => t('Simplenews subscription'),
);
$data['simplenews_subscription']['table']['join'] = array(
'taxonomy_term_data' => array(
'left_field' => 'tid',
'field' => 'tid',
),
'simplenews_subscriber' => array(
'left_field' => 'snid',
'field' => 'snid',
),
);
$data['simplenews_subscription']['snid'] = array(
'title' => t('Subscriber ID'),
'help' => t('The {simplenews_subscriptions}.snid who is subscribed.'),
'field' => array(
'label' => 'TEST',
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'simplenews_subscriber',
'base field' => 'snid',
'label' => t('Subscriber'),
),
);
$data['simplenews_subscription']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The newsletter series ({term_data}.tid) the subscriber is subscribed to.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'taxonomy_term_data',
'base field' => 'tid',
'label' => t('Term (Newsletter series)'),
),
);
$data['simplenews_subscription']['status'] = array(
'title' => t('Status'),
'help' => t('A flag indicating whether the user is subscribed (1) or unsubscribed (0).'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_subscription']['timestamp'] = array(
'title' => t('Timestamp'),
'help' => t('UNIX timestamp of when the user is (un)subscribed.'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_date',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_date',
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
);
$data['simplenews_subscription']['source'] = array(
'title' => t('Source'),
'help' => t('The source via which the user is (un)subscribed.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
/* ------------ Definitions for Simplenews category ----------------------*/
// Define the base group of this table. Fields that don't
// have a group defined will go into this field by default.
$data['simplenews_category']['table'] = array(
'group' => t('Simplenews category'),
);
// Joins
$data['simplenews_category']['table']['join'] = array(
// Category links directly to taxonomy via tid.
'taxonomy_term_data' => array(
'left_field' => 'tid',
'field' => 'tid',
),
);
// Fields
$data['simplenews_category']['tid'] = array(
'title' => t('Term ID'),
'help' => t('The newsletter series ({term_data}.tid) the subscriber is subscribed to.'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
'relationship' => array(
'handler' => 'views_handler_relationship',
'base' => 'taxonomy_term_data',
'base field' => 'tid',
'label' => t('Term (Newsletter series)'),
),
);
$data['simplenews_category']['format'] = array(
'title' => t('Format'),
'help' => t('Format of the newsletter (plain or html).'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['priority'] = array(
'title' => t('Priority'),
'help' => t('Email priority according to RFC 2156 and RFC 5231 (0 = none; 1 = highest; 2 = high; 3 = normal; 4 = low; 5 = lowest).'),
'field' => array(
'handler' => 'simplenews_handler_field_newsletter_priority',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'simplenews_handler_filter_newsletter_priority',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_newsletter']['receipt'] = array(
'title' => t('Receipt'),
'help' => t('Boolean indicating request for email receipt confirmation according to RFC 2822.'),
'field' => array(
'handler' => 'views_handler_field_boolean',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_boolean_operator',
'allow empty' => TRUE,
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['from_name'] = array(
'title' => t('From name'),
'help' => t('Sender name for newsletter emails.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['email_subject'] = array(
'title' => t('Email Subject'),
'help' => t('Subject of newsletter email. May contain tokens.'),
'field' => array(
'handler' => 'views_handler_field',
'click sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string',
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['from_address'] = array(
'title' => t('From address'),
'help' => t('Sender address for newsletter emails'),
'field' => array(
'handler' => 'views_handler_field',
'click_sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_string'
),
'argument' => array(
'handler' => 'views_handler_argument_srting',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['hyperlinks'] = array(
'title' => t('Hyperlinks displaymode'),
'help' => t('Flag indicating type of hyperlink conversion (1 = hyperlinks are in-line; 0 = hyperlinks are placed at email bottom).'),
'field' => array(
'handler' => 'simplenews_handler_field_category_hyperlinks',
'click_sortable' => TRUE,
),
'filter' => array(
'handler' => 'simplenews_handler_filter_category_hyperlinks'
),
'argument' => array(
'handler' => 'views_handler_argument_numeric'
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['new_account'] = array(
'title' => t('New account'),
'help' => t('How to treat subscription at account creation (none = None; on = Default on; off = Default off; silent = Invisible subscription).'),
'field' => array(
'handler' => 'simplenews_handler_field_category_new_account',
'click_sortable' => TRUE,
),
'filter' => array(
'handler' => 'simplenews_handler_filter_category_new_account'
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['opt_inout'] = array(
'title' => t('Confirmation displaymode'),
'help' => t('How to treat subscription confirmation (hidden = Newsletter is hidden from the user; single = Single opt-in; double = Double opt-in).'),
'field' => array(
'handler' => 'simplenews_handler_field_category_opt_inout',
'click_sortable' => TRUE,
),
'filter' => array(
'handler' => 'simplenews_handler_filter_category_opt_inout'
),
'argument' => array(
'handler' => 'views_handler_argument_string',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
$data['simplenews_category']['block'] = array(
'title' => t('Block'),
'help' => t('Indicates wether a subscription block is available for this category'),
'field' => array(
'handler' => 'views_handler_field_numeric',
'click_sortable' => TRUE,
),
'filter' => array(
'handler' => 'views_handler_filter_numeric',
),
'argument' => array(
'handler' => 'views_handler_argument_numeric',
),
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}