/** * Listen to the join site event and check for email subscriptions * * @param string $event What event was fired * @param string $type What was the type of event * @param ElggRelationship $object The relationship object, containing the user and site * * @return void */ function newsletter_join_site_event_handler($event, $type, $object) { if (!empty($object) && $object instanceof ElggRelationship) { $user = get_user($object->guid_one); if (!empty($user)) { $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } } } }
/** * Check if there is a email subscription for the user's email address * If so, convert the settings to the user and remove the email subscription * * @param string $hook Which hook was triggered * @param string $type What was the type of hook * @param array $returnvalue null * @param array $params null * * @return void */ public static function convertEmailSubscriptionToUserSetting($hook, $type, $returnvalue, $params) { $user_guid = (int) get_input('guid'); $user = get_user($user_guid); if (empty($user)) { return; } $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } }
/** * Listen to the join site event and check for email subscriptions * * @param string $event What event was fired * @param string $type What was the type of event * @param ElggRelationship $object The relationship object, containing the user and site * * @return void */ public static function join($event, $type, $object) { if (!$object instanceof \ElggRelationship) { return; } if ($object->relationship !== 'member_of_site') { return; } $user = get_user($object->guid_one); if (empty($user)) { return; } $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } }
/** * Block an email address from all newsletters * * @param string $email The email address to block * * @return boolean True on success, false on failure */ function newsletter_unsubscribe_all_email($email) { $result = false; if (!empty($email) && newsletter_is_email_address($email)) { // get subscription $subscription = newsletter_get_subscription($email); if (empty($subscription)) { $subscription = new NewsletterSubscription(); $subscription->title = $email; if (!$subscription->save()) { return false; } // remove all existing subscriptions remove_entity_relationships($subscription->getGUID(), NewsletterSubscription::SUBSCRIPTION); // add to general blacklist $site = elgg_get_site_entity(); $result = (bool) add_entity_relationship($subscription->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID()); } } return $result; }
/** * Check if there is a email subscription for the user's email address * If so, convert the settings to the user and remove the email subscription * * @param string $hook Which hook was triggered * @param string $type What was the type of hook * @param array $returnvalue null * @param array $params null * * @return void */ function newsletter_usersettings_save_handler($hook, $type, $returnvalue, $params) { $user_guid = (int) get_input("guid"); $user = get_user($user_guid); if (!empty($user)) { $subscription = newsletter_get_subscription($user->email); if (!empty($subscription)) { newsletter_convert_subscription_to_user_setting($subscription, $user); } } }