You are here

function simplenews_statistics_encoder_decode_hash in Simplenews Statistics 7

Same name and namespace in other branches
  1. 7.2 simplenews_statistics_encoder/encoder.inc \simplenews_statistics_encoder_decode_hash()

Decode a md5 hash and return an ID.

Parameters

$hash: A hash generated by simplenews_statistics_encoder_generate_hash().

Return value

Numeric ID or FALSE if the hash is invalid.

1 call to simplenews_statistics_encoder_decode_hash()
simplenews_statistics_encoder_simplenews_statistics_decode in simplenews_statistics_encoder/simplenews_statistics_encoder.module
Implements hook_simplenews_statistics_decode().

File

simplenews_statistics_encoder/encoder.inc, line 120
Encoder for IDs. Some logic borrowed from shorturl module.

Code

function simplenews_statistics_encoder_decode_hash($hash, $id_key) {

  // Attempt to detect invalid format.
  if (!preg_match('/.{10}[0-9]+/', $hash)) {
    return FALSE;
  }
  $id = drupal_substr($hash, 10);
  if ($hash == simplenews_statistics_encoder_generate_hash($id, $id_key)) {
    return $id;
  }
  return FALSE;
}