示例#1
0
/**
 * Validate a provided unsubscribe code
 *
 * @param ElggEntity $container Which newsletter container (ElggSite or ElggGroup)
 * @param string|int $recipient The user_guid or email address of the recipient
 * @param string     $code      The unsubscribe code the recipient provided
 *
 * @return bool	true is valid or false on failure
 */
function newsletter_validate_unsubscribe_code(ElggEntity $container, $recipient, $code)
{
    $result = false;
    if (!empty($container) && (elgg_instanceof($container, "site") || elgg_instanceof($container, "group")) && !empty($recipient)) {
        // make sure we have a user_guid or email address
        if (is_numeric($recipient) || newsletter_is_email_address($recipient)) {
            // generate the code as it should be
            $correct_code = newsletter_generate_unsubscribe_code($container, $recipient);
            // check for a match
            if ($code === $correct_code) {
                $result = true;
            }
        }
    }
    return $result;
}
示例#2
0
/**
 * Validate a provided unsubscribe code
 *
 * @param ElggEntity $container Which newsletter container (ElggSite or ElggGroup)
 * @param string|int $recipient The user_guid or email address of the recipient
 * @param string     $code      The unsubscribe code the recipient provided
 *
 * @return bool	true is valid or false on failure
 */
function newsletter_validate_unsubscribe_code(ElggEntity $container, $recipient, $code)
{
    if (!elgg_instanceof($container, 'site') && !elgg_instanceof($container, 'group')) {
        return false;
    }
    if (empty($recipient)) {
        return false;
    }
    // make sure we have a user_guid or email address
    if (!is_numeric($recipient) && !newsletter_is_email_address($recipient)) {
        return false;
    }
    // generate the code as it should be
    $correct_code = newsletter_generate_unsubscribe_code($container, $recipient);
    // check for a match
    if ($code === $correct_code) {
        return true;
    }
    return false;
}