You are here

function simplenews_confirmation_get_changes_list in Simplenews 7.2

Same name and namespace in other branches
  1. 7 simplenews.module \simplenews_confirmation_get_changes_list()

Converts an array of subscription changes into descriptions.

Parameters

$subscriber: Simplenews subscriber object.

$changes: (Optional) Array of changes, each is an array with the keys action and newsletter_id. Defaults to $subscriber->changes, which contains the currently saved changes for the subscriber. No-op changes are removed from this array.

$langcode: (Optional) Specify the language of the description strings, defaults to the current language.

Return value

Array of description strings describing the changes.

2 calls to simplenews_confirmation_get_changes_list()
simplenews_build_combined_mail in includes/simplenews.mail.inc
Build subject and body of the subscribe confirmation email.
simplenews_confirm_multi_form in includes/simplenews.subscription.inc
Generate the confirm subscription form.

File

./simplenews.module, line 3111
Simplenews node handling, sent email, newsletter block and general hooks

Code

function simplenews_confirmation_get_changes_list($subscriber, &$changes = NULL, $langcode = NULL) {
  if (empty($langcode)) {
    global $language;
    $langcode = $language->language;
  }
  if (empty($changes)) {
    $changes = $subscriber->changes;
  }
  $changes_list = array();
  foreach ($changes as $newsletter_id => $action) {
    $subscribed = simplenews_user_is_subscribed($subscriber->mail, $newsletter_id);

    // Get text for each possible combination.
    if ($action == 'subscribe' && !$subscribed) {
      $line = simplenews_subscription_confirmation_text('combined_line_subscribe_unsubscribed', $langcode);
    }
    elseif ($action == 'subscribe' && $subscribed) {
      $line = simplenews_subscription_confirmation_text('combined_line_subscribe_subscribed', $langcode);
    }
    elseif ($action == 'unsubscribe' && !$subscribed) {
      $line = simplenews_subscription_confirmation_text('combined_line_unsubscribe_unsubscribed', $langcode);
    }
    elseif ($action == 'unsubscribe' && $subscribed) {
      $line = simplenews_subscription_confirmation_text('combined_line_unsubscribe_subscribed', $langcode);
    }
    $newsletter_context = array(
      'simplenews_subscriber' => $subscriber,
      'newsletter' => simplenews_newsletter_load($newsletter_id),
    );
    $changes_list[$newsletter_id] = token_replace($line, $newsletter_context, array(
      'sanitize' => FALSE,
    ));
  }
  return $changes_list;
}