You are here

function ARC_api_helper::get_hash_md5_id in Taxonomy import/export via XML 6.2

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

File

arc/ARC_api_helper.php, line 147

Class

ARC_api_helper

Code

function get_hash_md5_id($val = "", $sql = false) {
  $result = "";
  if ($val == "") {
    return $sql ? "'X_by1-I3bB@@hJ2Tz--=9'" : "X_by1-I3bB@@hJ2Tz--=9";
  }
  $val = md5($val);
  $parts = array(
    substr($val, 0, 11),
    substr($val, 11, 11),
    substr($val, 22),
  );
  $alpha = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ !?()+,-.@;=[]_{}';
  $base = strlen($alpha);
  for ($i = 0; $i < 3; $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 .= sprintf("%07s", $cur_result);
  }
  return $sql ? "'" . $result . "'" : $result;
}