Parsed: 108360

  function PclZipUtilPathReduction($p_dir)
  {
    $v_result = "";

    // ----- Look for not empty path
    if ($p_dir != "") {
      // ----- Explode path by directory names
      $v_list = explode("/", $p_dir);

      // ----- Study directories from last to first
      $v_skip = 0;
      for ($i=sizeof($v_list)-1; $i>=0; $i--) {
        // ----- Look for current path
        if ($v_list[$i] == ".") {
          // ----- Ignore this directory
          // Should be the first $i=0, but no check is done
        }
        else if ($v_list[$i] == "..") {
      $v_skip++;
        }
        else if ($v_list[$i] == "") {
      // ----- First '/' i.e. root slash
      if ($i == 0) {
            $v_result = "/".$v_result;
        if ($v_skip > 0) {
            // ----- It is an invalid path, so the path is not modified
            // TBC
            $v_result = $p_dir;
                $v_skip = 0;
        }
      }
      // ----- Last '/' i.e. indicates a directory
      else if ($i == (sizeof($v_list)-1)) {
            $v_result = $v_list[$i];
      }
      // ----- Double '/' inside the path
      else {
            // ----- Ignore only the double '//' in path,
            // but not the first and last '/'
      }
        }
        else {
      // ----- Look for item to skip
      if ($v_skip > 0) {
        $v_skip--;
      }
      else {
            $v_result = $v_list[$i].($i!=(sizeof($v_list)-1)?"/".$v_result:"");
      }
        }
      }

      // ----- Look for skip
      if ($v_skip > 0) {
        while ($v_skip > 0) {
            $v_result = '../'.$v_result;
            $v_skip--;
        }
      }
    }

    // ----- Return
    return $v_result;
  }