function simplenews_subscriber_load_by_hash in Simplenews 7.2
Same name and namespace in other branches
- 7 simplenews.module \simplenews_subscriber_load_by_hash()
Load a simplenews subscriber using the hash.
Parameters
$hash: A hash generated by simplenews_generate_hash().
Return value
SimplenewsSubscriber Simplenews subscriber entity, FALSE if the hash is invalid or the corresponding subscriber does not exist.
1 call to simplenews_subscriber_load_by_hash()
- simplenews_old_confirm_subscription in includes/
simplenews.subscription.inc - Backwards compatibility for old conformation links.
File
- ./
simplenews.module, line 1781 - Simplenews node handling, sent email, newsletter block and general hooks
Code
function simplenews_subscriber_load_by_hash($hash) {
// Attempt to detect invalid format.
if (!preg_match('/.{10}[0-9]+t[0-9]+/', $hash)) {
return FALSE;
}
$md5 = drupal_substr($hash, 0, 10);
list($snid, $newsletter_id) = explode('t', drupal_substr($hash, 10));
$subscriber = simplenews_subscriber_load($snid);
if (!$subscriber) {
return FALSE;
}
// Check the hash if the comparison fails, return a not found error.
if ($md5 != drupal_substr(md5($subscriber->mail . simplenews_private_key()), 0, 10)) {
return FALSE;
}
return $subscriber;
}