function simplenews_subscription_list_add_submit in Simplenews 7.2
Same name and namespace in other branches
- 5 simplenews.module \simplenews_subscription_list_add_submit()
- 6.2 includes/simplenews.admin.inc \simplenews_subscription_list_add_submit()
- 6 simplenews.admin.inc \simplenews_subscription_list_add_submit()
- 7 includes/simplenews.admin.inc \simplenews_subscription_list_add_submit()
@todo
File
- includes/
simplenews.admin.inc, line 746 - Newsletter admin, subscription admin, simplenews settings
Code
function simplenews_subscription_list_add_submit($form, &$form_state) {
$added = array();
$invalid = array();
$unsubscribed = array();
$checked_newsletters = array_keys(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)) {
$subscriber = simplenews_subscriber_load_by_mail($email);
foreach (simplenews_newsletter_load_multiple($checked_newsletters) as $newsletter) {
// If there is a valid subscriber, check if there is a subscription for
// the current newsletter and if this subscription has the status
// unsubscribed.
$is_unsubscribed = $subscriber && array_key_exists($newsletter->newsletter_id, $subscriber->newsletter_subscription) && $subscriber->newsletter_subscription[$newsletter->newsletter_id]->status == SIMPLENEWS_SUBSCRIPTION_STATUS_UNSUBSCRIBED;
if (!$is_unsubscribed || $form_state['values']['resubscribe'] == TRUE) {
simplenews_subscribe($email, $newsletter->newsletter_id, FALSE, 'mass subscribe', $langcode);
$added[] = $email;
}
else {
$unsubscribed[check_plain($newsletter->name)][] = $email;
}
}
}
else {
$invalid[] = $email;
}
}
if ($added) {
$added = implode(", ", $added);
drupal_set_message(t('The following addresses were added or updated: %added.', array(
'%added' => $added,
)));
$list_names = array();
foreach (simplenews_newsletter_load_multiple($checked_newsletters) as $newsletter) {
$list_names[] = $newsletter->name;
}
drupal_set_message(t('The addresses were subscribed to the following newsletters: %newsletters.', array(
'%newsletters' => implode(', ', $list_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');
}
foreach ($unsubscribed as $name => $subscribers) {
$subscribers = implode(", ", $subscribers);
drupal_set_message(t('The following addresses were skipped because they have previously unsubscribed from %name: %unsubscribed.', array(
'%name' => $name,
'%unsubscribed' => $subscribers,
)), 'warning');
}
if (!empty($unsubscribed)) {
drupal_set_message(t("If you would like to resubscribe them, use the 'Force resubscription' option."), 'warning');
}
// Return to the parent page.
$form_state['redirect'] = 'admin/people/simplenews';
}