Get a source image's binary contents from Rokka.

@param string $hash         Hash of the image
@param string $organization Optional organization name

@throws GuzzleException
@throws \RuntimeException

@return string
490027
public function getSourceImageContents($hash, $organization = '')
    {
        $path = implode('/', [
            self::SOURCEIMAGE_RESOURCE,
            $this->getOrganizationName($organization),
            $hash,
            'download', ]
        );

        return $this
            ->call('GET', $path)
            ->getBody()
            ->getContents();
    }
145242
protected function getItemByHash($hash)
    {
        foreach ($this->items as $item) {
            if ($item->getHash() === $hash) {
                return $item;
            }
        }
        
        return false;
    }
1280290
public function byName($hash) {
		if($this->loaded == false) {
			$this->items = $this->getReferences();
			$this->loaded = true;
		}
		// The item might not be in the list because of the limit, try to find
		// in an older version and add it to the list.
		if(!isset($this->items[$hash])) {
			$repository = new Gitonomy\Git\Repository($this->project->LocalCVSPath);
			$commit = new Gitonomy\Git\Commit($repository, $hash);
			$this->items[$hash] = DNCommit::create($commit, $this->project, $this->data);
		};

		return $this->items[$hash];
	}
369966
public function get(string $hash): ?EntityInterface
    {
        $result = null;
        $content = $this->loadContent($hash);
        if ($content !== null) {
            $result = $this->createEntityFromContent($content);
        }
        return $result;
    }
507225
function setHash($hash)
    {
        $hash = strtolower($hash);
        switch ($hash) {
            case 'md5-96':
            case 'sha1-96':
                $this->l = 12; // 96 / 8 = 12
                break;
            case 'md2':
            case 'md5':
                $this->l = 16;
                break;
            case 'sha1':
                $this->l = 20;
                break;
            case 'sha256':
                $this->l = 32;
                break;
            case 'sha384':
                $this->l = 48;
                break;
            case 'sha512':
                $this->l = 64;
        }

        switch ($hash) {
            case 'md2':
                $mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_HASH && in_array('md2', hash_algos()) ?
                    CRYPT_HASH_MODE_HASH : CRYPT_HASH_MODE_INTERNAL;
                break;
            case 'sha384':
            case 'sha512':
                $mode = CRYPT_HASH_MODE == CRYPT_HASH_MODE_MHASH ? CRYPT_HASH_MODE_INTERNAL : CRYPT_HASH_MODE;
                break;
            default:
                $mode = CRYPT_HASH_MODE;
        }

        switch ( $mode ) {
            case CRYPT_HASH_MODE_MHASH:
                switch ($hash) {
                    case 'md5':
                    case 'md5-96':
                        $this->hash = MHASH_MD5;
                        break;
                    case 'sha256':
                        $this->hash = MHASH_SHA256;
                        break;
                    case 'sha1':
                    case 'sha1-96':
                    default:
                        $this->hash = MHASH_SHA1;
                }
                return;
            case CRYPT_HASH_MODE_HASH:
                switch ($hash) {
                    case 'md5':
                    case 'md5-96':
                        $this->hash = 'md5';
                        return;
                    case 'md2':
                    case 'sha256':
                    case 'sha384':
                    case 'sha512':
                        $this->hash = $hash;
                        return;
                    case 'sha1':
                    case 'sha1-96':
                    default:
                        $this->hash = 'sha1';
                }
                return;
        }

        switch ($hash) {
            case 'md2':
                 $this->b = 16;
                 $this->hash = array($this, '_md2');
                 break;
            case 'md5':
            case 'md5-96':
                 $this->b = 64;
                 $this->hash = array($this, '_md5');
                 break;
            case 'sha256':
                 $this->b = 64;
                 $this->hash = array($this, '_sha256');
                 break;
            case 'sha384':
            case 'sha512':
                 $this->b = 128;
                 $this->hash = array($this, '_sha512');
                 break;
            case 'sha1':
            case 'sha1-96':
            default:
                 $this->b = 64;
                 $this->hash = array($this, '_sha1');
        }

        $this->ipad = str_repeat(chr(0x36), $this->b);
        $this->opad = str_repeat(chr(0x5C), $this->b);
    }
1356199
public function urlHash($hash = null, $withHash = true)
    {
        if ($hash) {
            $this->set('urlHash', ltrim($hash, '#'));
        }

        $hash = $this->get('urlHash', '');

        return $withHash && !empty($hash) ? '#' . $hash : $hash;
    }
1009011
public function path($hash) {
		return $this->convEncOut($this->_path($this->convEncIn($this->decode($hash))));
	}
1119679
public function getOrganizationProjects(string $organization): ResponseInterface
    {
        // This API endpoint uses the newer `api.transifex.com` subdomain, only change if the default www was given
        $currentBaseUri = $this->getOption('base_uri');

        if (!$currentBaseUri || $currentBaseUri === 'https://www.transifex.com') {
            $this->setOption('base_uri', 'https://api.transifex.com');
        }

        try {
            return $this->client->sendRequest($this->createRequest('GET', $this->createUri("/organizations/$organization/projects/")));
        } finally {
            $this->setOption('base_uri', $currentBaseUri);
        }
    }
374592
protected function getFromHash($hash, $version)
    {
        return sprintf('%08s-%04s-%04x-%04x-%12s',
    		// 32 bits for "time_low"
    		substr($hash, 0, 8),
    		// 16 bits for "time_mid"
    		substr($hash, 8, 4),
    		// 16 bits for "time_hi_and_version",
    		// four most significant bits holds version number 4
    		(hexdec(substr($hash, 12, 4)) & 0x0fff) | $version << 12,
    		// 16 bits, 8 bits for "clk_seq_hi_res",
    		// 8 bits for "clk_seq_low",
    		// two most significant bits holds zero and one for variant DCE1.1
    		(hexdec(substr($hash, 16, 4)) & 0x3fff) | 0x8000,
    		// 48 bits for "node"
    		substr($hash, 20, 12)
		);
    }
1340520
public function listMemberships($organization = '')
    {
        $contents = $this
            ->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']))
            ->getBody()
            ->getContents()
        ;

        $membership = Membership::createFromJsonResponse($contents);
        if (!\is_array($membership)) {
            throw new \RuntimeException('Something went wrong, return was not array, but should be');
        }

        return $membership;
    }
927041
public function provideNameByHash(FileInfo $srcFileInfo, $hash)
    {
        $pathSuffixParts = array();
        for ($i = 0; $i < $this->partCount; $i++) {
            $pathSuffixParts[] = substr($hash, $i * $this->partLength, $this->partLength);
        }
        if ($this->shouldFullFilenameBeKept) {
            $name = $hash;
        } else {
            $name = substr($hash, $i * $this->partLength);
        }
        $pathSuffix = implode(FileInfo::SEPARATOR_DIRECTORY, $pathSuffixParts);
        $dstFileInfo = $srcFileInfo
            ->changeBasename($name)
            ->changePath($srcFileInfo->getPath().FileInfo::SEPARATOR_DIRECTORY.$pathSuffix)
        ;

        return $dstFileInfo;
    }
187482
public function findByHash($hash)
    {
        return $this->hashWorkingRecord->get()->filter($this->hashDbField, $hash)->first();
    }
124909
protected function extractHashFromLocationHeader(array $headers)
    {
        $location = reset($headers);

        // Check if we got a Location header, otherwise something went wrong here.
        if (empty($location)) {
            return false;
        }

        $uri = new Uri($location);
        $parts = explode('/', $uri->getPath());

        // Returning just the HASH part for "api.rokka.io/organization/sourceimages/{HASH}"
        $return = array_pop($parts);
        if (null === $return) {
            return false;
        }

        return $return;
    }
176742
public function scandir($hash) {
		if (($dir = $this->dir($hash)) == false) {
			return false;
		}
		
		return $dir['read']
			? $this->getScandir($this->decode($hash))
			: $this->setError(elFinder::ERROR_PERM_DENIED);
	}
1168472
public function getOrganization($organization = '')
    {
        $contents = $this
            ->call('GET', self::ORGANIZATION_RESOURCE.'/'.$this->getOrganizationName($organization))
            ->getBody()
            ->getContents()
        ;

        return Organization::createFromJsonResponse($contents);
    }
727886
private function getHash($mixed)
    {
        if ($mixed instanceof File) {
            $mixed = pathinfo($mixed->getHashName(), PATHINFO_EXTENSION);
        }

        return $this->container->get('claroline.utilities.misc')->generateGuid().'.'.$mixed;
    }
421879
public function open($hash) {
		if (($file = $this->file($hash)) == false
		|| $file['mime'] == 'directory') {
			return false;
		}
		
		return $this->fopenCE($this->decode($hash), 'rb');
	}