<?php /** * Action file to save the subscriptions of a user * */ $user_guid = (int) get_input("user_guid"); $subscriptions = get_input("subscriptions"); $block_all = (int) get_input("block_all"); if (!empty($user_guid) && !empty($subscriptions) && is_array($subscriptions)) { $user = get_user($user_guid); if (!empty($user) && $user->canEdit()) { $result = true; if (!empty($block_all)) { // block all newsletters $result = newsletter_unsubscribe_all_user($user); } else { // remove block all remove_entity_relationship($user->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, elgg_get_site_entity()->getGUID()); // go through all the subscriptions foreach ($subscriptions as $guid => $value) { // value is stored // 1 => subscribe // 0 => unsubscribe $value = (bool) $value; $entity = get_entity($guid); if (!empty($entity)) { if ($value) { $result = $result && newsletter_subscribe_user($user, $entity); } else { $result = $result && newsletter_unsubscribe_user($user, $entity);
} elseif (newsletter_is_email_address($recipient)) { if (newsletter_unsubscribe_email($recipient, $entity)) { $forward_url = ""; system_message(elgg_echo("newsletter:action:unsubscribe:success:entity", array($entity->name))); } else { register_error(elgg_echo("newsletter:action:unsubscribe:error:entity", array($entity->name))); } } else { $recipient_error = true; register_error(elgg_echo("newsletter:action:unsubscribe:error:recipient", array($recipient))); } } // unsubscribe from all if (!empty($all)) { if (is_numeric($recipient) && ($user = get_user($recipient))) { if (newsletter_unsubscribe_all_user($user)) { $forward_url = ""; system_message(elgg_echo("newsletter:action:unsubscribe:success:all")); } else { register_error(elgg_echo("newsletter:action:unsubscribe:error:all")); } } elseif (newsletter_is_email_address($recipient)) { if (newsletter_unsubscribe_all_email($recipient)) { $forward_url = ""; system_message(elgg_echo("newsletter:action:unsubscribe:success:all")); } else { register_error(elgg_echo("newsletter:action:unsubscribe:error:all")); } } elseif (!$recipient_error) { register_error(elgg_echo("newsletter:action:unsubscribe:error:recipient", array($recipient))); }