コード例 #1
0
ファイル: User.php プロジェクト: coldtrick/newsletter
 /**
  * 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);
     }
 }
コード例 #2
0
ファイル: functions.php プロジェクト: pleio/newsletter
/**
 * 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;
}
コード例 #3
0
ファイル: subscriptions.php プロジェクト: lorea/Hydra-dev
            $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 {
    register_error(elgg_echo("InvalidParameterException:MissingParameter"));
}
コード例 #4
0
ファイル: subscribe.php プロジェクト: coldtrick/newsletter
<?php

$guid = (int) get_input('guid');
$user_guid = (int) get_input('user_guid');
$email = get_input('email');
if (!empty($guid) && (!empty($user_guid) || !empty($email))) {
    $entity = get_entity($guid);
    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'));
            }
コード例 #5
0
ファイル: hooks.php プロジェクト: lorea/Hydra-dev
/**
 * 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);
            }
        }
    }
}