function simplenews_confirm_subscription in Simplenews 7
Same name and namespace in other branches
- 5 simplenews.module \simplenews_confirm_subscription()
- 6.2 includes/simplenews.subscription.inc \simplenews_confirm_subscription()
- 6 simplenews.subscription.inc \simplenews_confirm_subscription()
- 7.2 includes/simplenews.subscription.inc \simplenews_confirm_subscription()
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.
@todo Add parameter description here.
See also
simplenews_confirm_removal_form()
1 string reference to 'simplenews_confirm_subscription'
- simplenews_menu in ./
simplenews.module - Implements hook_menu().
File
- includes/
simplenews.subscription.inc, line 483 - (Un)subscription and (un)subscription confirmation
Code
function simplenews_confirm_subscription() {
$arguments = func_get_args();
$op = array_shift($arguments);
$code = array_shift($arguments);
// Prevent search engines from indexing this page.
$noindex = array(
'#tag' => 'meta',
'#attributes' => array(
'name' => 'robots',
'content' => 'noindex',
),
);
drupal_add_html_head($noindex, 'simplenews-noindex');
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') {
// Redirect and display message if no changes are available.
if (empty($subscriber->changes)) {
drupal_set_message(t('All changes to your subscriptions where already applied. No changes made.'));
drupal_goto(variable_get('site_frontpage', 'node'));
}
else {
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'));
}
elseif ($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'));
}
elseif ($op == 'combined') {
// Redirect and display message if no changes are available.
if (empty($subscriber->changes)) {
drupal_set_message(t('All changes to your subscriptions where already applied. No changes made.'));
drupal_goto(variable_get('site_frontpage', 'node'));
}
else {
foreach ($subscriber->changes as $tid => $action) {
if ($action == 'subscribe') {
simplenews_subscribe_user($subscriber->mail, $tid, FALSE, 'website');
}
elseif ($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,
)));
drupal_goto(variable_get('site_frontpage', 'node'));
}
}
}
}
// If md5 didn't match, do a not found.
drupal_not_found();
return;
}