diff options
author | zotlabs <mike@macgirvin.com> | 2017-07-17 19:53:03 -0700 |
---|---|---|
committer | zotlabs <mike@macgirvin.com> | 2017-07-17 19:53:03 -0700 |
commit | 15e836b7dd2fed3f97f134928d88e13db1d8a7f4 (patch) | |
tree | 0ea175e0dd495b6fcafd00ffb1df6f044aed7bb5 | |
parent | 0d062251b6c38a71932e9875cdd777afdfff140b (diff) | |
download | volse-hubzilla-15e836b7dd2fed3f97f134928d88e13db1d8a7f4.tar.gz volse-hubzilla-15e836b7dd2fed3f97f134928d88e13db1d8a7f4.tar.bz2 volse-hubzilla-15e836b7dd2fed3f97f134928d88e13db1d8a7f4.zip |
provide content-type matching ability for activitypub
-rw-r--r-- | include/network.php | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/include/network.php b/include/network.php index b85a16d21..fe9a9aa2b 100644 --- a/include/network.php +++ b/include/network.php @@ -1896,3 +1896,41 @@ function service_plink($contact, $guid) { return $x['plink']; } +function getBestSupportedMimeType($mimeTypes = null, $acceptedTypes = false) { + // Values will be stored in this array + + if($acceptedTypes === false) + $acceptedTypes = $_SERVER['HTTP_ACCEPT']; + + $AcceptTypes = Array (); + + // Accept header is case insensitive, and whitespace isn’t important + $accept = strtolower(str_replace(' ', '', $acceptedTypes)); + // divide it into parts in the place of a "," + $accept = explode(',', $accept); + foreach ($accept as $a) { + // the default quality is 1. + $q = 1; + // check if there is a different quality + if (strpos($a, ';q=')) { + // divide "mime/type;q=X" into two parts: "mime/type" i "X" + list($a, $q) = explode(';q=', $a); + } + // mime-type $a is accepted with the quality $q + // WARNING: $q == 0 means, that mime-type isn’t supported! + $AcceptTypes[$a] = $q; + } + arsort($AcceptTypes); + + // if no parameter was passed, just return parsed data + if (!$mimeTypes) return $AcceptTypes; + + $mimeTypes = array_map('strtolower', (array)$mimeTypes); + + // let’s check our supported types: + foreach ($AcceptTypes as $mime => $q) { + if ($q && in_array($mime, $mimeTypes)) return $mime; + } + // no mime-type found + return null; +}
\ No newline at end of file |