function simplenews_subscriber_load_by_hash in Simplenews 7
Same name and namespace in other branches
- 7.2 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
Simplenews subscriber object, FALSE if the hash is invalid or the corresponding subscriber does not exist.
2 calls to simplenews_subscriber_load_by_hash()
- simplenews_confirm_subscription in includes/
simplenews.subscription.inc - Menu callback: confirm the user's (un)subscription request
- simplenews_subscriptions_page_form in includes/
simplenews.subscription.inc - FAPI PAGE subscription form.
File
- ./
simplenews.module, line 1577 - 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, $tid) = 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;
}