You are here

function simplenews_subscription_list_add_submit in Simplenews 6

Same name and namespace in other branches
  1. 5 simplenews.module \simplenews_subscription_list_add_submit()
  2. 6.2 includes/simplenews.admin.inc \simplenews_subscription_list_add_submit()
  3. 7.2 includes/simplenews.admin.inc \simplenews_subscription_list_add_submit()
  4. 7 includes/simplenews.admin.inc \simplenews_subscription_list_add_submit()

File

./simplenews.admin.inc, line 429
Newsletter admin, subscription admin, simplenews settings

Code

function simplenews_subscription_list_add_submit($form, &$form_state) {
  $tree = taxonomy_get_tree(variable_get('simplenews_vid', ''));
  $added = array();
  $invalid = array();
  $checked_newsletters = array_filter($form_state['values']['newsletters']);
  $langcode = $form_state['values']['language'];
  $emails = preg_split("/[\\s,]+/", $form_state['values']['emails']);
  foreach ($emails as $email) {
    $email = trim($email);
    if ($email == '') {
      continue;
    }
    if (valid_email_address($email)) {
      foreach ($checked_newsletters as $tid) {
        $newsletter = taxonomy_get_term($tid);
        simplenews_subscribe_user($email, $newsletter->tid, FALSE, $langcode);
        $added[] = $email;
      }
    }
    else {
      $invalid[] = $email;
    }
  }
  if ($added) {
    $added = implode(", ", $added);
    drupal_set_message(t('The following addresses were added or updated: %added.', array(
      '%added' => $added,
    )));
    $newsletter_names = array();
    foreach ($checked_newsletters as $tid) {
      $newsletter = taxonomy_get_term($tid);
      $newsletter_names[] = $newsletter->name;
    }
    drupal_set_message(t('The addresses were subscribed to the following newsletters: %newsletters.', array(
      '%newsletters' => implode(', ', $newsletter_names),
    )));
  }
  else {
    drupal_set_message(t('No addresses were added.'));
  }
  if ($invalid) {
    $invalid = implode(", ", $invalid);
    drupal_set_message(t('The following addresses were invalid: %invalid.', array(
      '%invalid' => $invalid,
    )), 'error');
  }
}