You are here

function ARC_api_helper::get_hash_sha1_id in Taxonomy import/export via XML 6

Same name and namespace in other branches
  1. 5.2 arc/ARC_api_helper.php \ARC_api_helper::get_hash_sha1_id()
  2. 5 arc/ARC_api_helper.php \ARC_api_helper::get_hash_sha1_id()
  3. 6.2 arc/ARC_api_helper.php \ARC_api_helper::get_hash_sha1_id()

File

arc/ARC_api_helper.php, line 170

Class

ARC_api_helper

Code

function get_hash_sha1_id($val = "", $sql = false) {
  $result = "";
  if ($val == "") {
    return $sql ? "'ZSK!7vEP6q[fX +VKiH+s6(a,e'" : "ZSK!7vEP6q[fX +VKiH+s6(a,e";
  }
  $val = sha1($val);
  $parts = array(
    substr($val, 0, 11),
    substr($val, 11, 11),
    substr($val, 22, 11),
    substr($val, 33),
  );
  $alpha = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ !?()+,-.@;=[]_{}';
  $base = strlen($alpha);
  for ($i = 0; $i < 4; $i++) {
    $cur_part = $parts[$i];
    $cur_int = hexdec($cur_part);
    $cur_result = "";
    for ($j = floor(log10($cur_int) / log10($base)); $j >= 0; $j--) {
      $pos = floor($cur_int / pow($base, $j));
      $cur_result .= $alpha[$pos];
      $cur_int -= $pos * pow($base, $j);
    }
    $result .= $i == 3 ? sprintf("%05s", $cur_result) : sprintf("%07s", $cur_result);
  }
  return $sql ? "'" . $result . "'" : $result;
}