Esempio n. 1
0
 /**
  * A hook fired during the registration proccess of the user
  * Check if the user wants to receive site newsletters
  *
  * @param string $hook        Which hook was triggered
  * @param string $type        What was the type of hook
  * @param bool   $returnvalue you can stop the registration proccess
  * @param array  $params      different variables, including the new user
  *
  * @return void
  */
 public static function subscribeToSiteNewsletter($hook, $type, $returnvalue, $params)
 {
     $user = elgg_extract('user', $params);
     if (!elgg_instanceof($user, 'user')) {
         return;
     }
     $site = elgg_get_site_entity();
     $subscribe = (int) get_input('newsletter_subscription');
     if (!empty($subscribe)) {
         // user wants to receive newsletter
         newsletter_subscribe_user($user, $site);
     } else {
         // user doesn't want to recieve newsletter
         newsletter_unsubscribe_user($user, $site);
     }
 }
Esempio n. 2
0
/**
 * Convert an email subscription on the newsletters to a user setting
 *
 * @param NewsletterSubscription $subscription The found email subscription
 * @param ElggUser               $user         The user to save the new settings to
 *
 * @return bool	true on success or false on failure
 */
function newsletter_convert_subscription_to_user_setting(NewsletterSubscription $subscription, ElggUser $user)
{
    $result = false;
    if (!empty($subscription) && elgg_instanceof($subscription, "object", NewsletterSubscription::SUBTYPE) && !empty($user) && elgg_instanceof($user, "user")) {
        // check global block list
        $site = elgg_get_site_entity();
        if (check_entity_relationship($subscription->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID())) {
            // copy the block all
            add_entity_relationship($user->getGUID(), NewsletterSubscription::GENERAL_BLACKLIST, $site->getGUID());
        } else {
            // check for subscriptions
            $subscriptions = $subscription->getEntitiesFromRelationship(NewsletterSubscription::SUBSCRIPTION, false, false);
            if (!empty($subscriptions)) {
                foreach ($subscriptions as $entity) {
                    newsletter_subscribe_user($user, $entity);
                }
            }
            // check for blocks
            $blocked = $subscription->getEntitiesFromRelationship(NewsletterSubscription::BLACKLIST, false, false);
            if (!empty($blocked)) {
                foreach ($blocked as $entity) {
                    newsletter_unsubscribe_user($user, $entity);
                }
            }
        }
        // remove email subscription
        $result = (bool) $subscription->delete();
    }
    return $result;
}
Esempio n. 3
0
        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);
                    }
                }
            }
        }
        if ($result) {
            system_message(elgg_echo("newsletter:action:subscriptions:success"));
        } else {
            register_error(elgg_echo("newsletter:action:subscriptions:error"));
        }
    } else {
        register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
    }
} else {
Esempio n. 4
0
 if (elgg_instanceof($entity, 'site') || elgg_instanceof($entity, 'group')) {
     if (!empty($user_guid)) {
         // check the user
         $user = get_user($user_guid);
         if (!empty($user) && $user->canEdit()) {
             // is the user subscribed
             if (newsletter_check_user_subscription($user, $entity)) {
                 // unsubscribe
                 if (newsletter_unsubscribe_user($user, $entity)) {
                     system_message(elgg_echo('newsletter:action:subscribe:success:unsubscribe'));
                 } else {
                     register_error(elgg_echo('newsletter:action:subscribe:error:unsubscribe'));
                 }
             } else {
                 // subscribe
                 if (newsletter_subscribe_user($user, $entity)) {
                     system_message(elgg_echo('newsletter:action:subscribe:success'));
                 } else {
                     register_error(elgg_echo('newsletter:action:subscribe:error:subscribe'));
                 }
             }
         } else {
             register_error(elgg_echo('error:missing_data'));
         }
     } else {
         if (newsletter_is_email_address($email)) {
             // add the email address to the subscriber list
             if (newsletter_subscribe_email($email, $entity)) {
                 system_message(elgg_echo('newsletter:action:subscribe:success'));
             } else {
                 register_error(elgg_echo('newsletter:action:subscribe:error:subscribe'));
Esempio n. 5
0
/**
 * A hook fired during the registration proccess of the user
 * Check if the user wants to receive site newsletters
 *
 * @param string $hook        Which hook was triggered
 * @param string $type        What was the type of hook
 * @param bool   $returnvalue you can stop the registration proccess
 * @param array  $params      different variables, including the new user
 *
 * @return void
 */
function newsletter_register_user_handler($hook, $type, $returnvalue, $params)
{
    if (!empty($params) && is_array($params)) {
        $user = elgg_extract("user", $params);
        if (!empty($user) && elgg_instanceof($user, "user")) {
            $site = elgg_get_site_entity();
            $subscribe = (int) get_input("newsletter_subscription");
            if (!empty($subscribe)) {
                // user wants to receive newsletter
                newsletter_subscribe_user($user, $site);
            } else {
                // user doesn't want to recieve newsletter
                newsletter_unsubscribe_user($user, $site);
            }
        }
    }
}