diff --git a/Code/Lib/Activity.php b/Code/Lib/Activity.php index 7cb2965a3..614600019 100644 --- a/Code/Lib/Activity.php +++ b/Code/Lib/Activity.php @@ -122,8 +122,16 @@ class Activity logger('fetch_actual: ' . $url, LOGGER_DEBUG); + $default_accept_header = 'application/activity+json, application/x-zot-activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; + + if ($channel) { + $accept_header = PConfig::Get($channel['channel_id'],'system','accept_header'); + } + if (!$accept_header) { + $accept_header = Config::Get('system', 'accept_header', $default_accept_header); + } $headers = [ - 'Accept' => 'application/activity+json, application/x-zot-activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"', + 'Accept' => $accept_header, 'Host' => $parsed['host'], 'Date' => datetime_convert('UTC', 'UTC', 'now', 'D, d M Y H:i:s \\G\\M\\T'), '(request-target)' => 'get ' . get_request_string($url) diff --git a/Code/Lib/ActivityStreams.php b/Code/Lib/ActivityStreams.php index 0e8f3a119..b3713593f 100644 --- a/Code/Lib/ActivityStreams.php +++ b/Code/Lib/ActivityStreams.php @@ -508,13 +508,26 @@ class ActivityStreams public static function is_as_request() : bool { - $x = getBestSupportedMimeType([ - 'application/ld+json;profile="https://www.w3.org/ns/activitystreams"', - 'application/activity+json', - 'application/ld+json;profile="http://www.w3.org/ns/activitystreams"', - 'application/ld+json', - 'application/x-zot-activity+json' - ]); + $default_accept_header = 'application/activity+json, application/x-zot-activity+json, application/ld+json; profile="https://www.w3.org/ns/activitystreams"'; + + if ($channel) { + $accept_header = PConfig::Get($channel['channel_id'],'system','accept_header'); + } + if (!$accept_header) { + $accept_header = Config::Get('system', 'accept_header', $default_accept_header); + } + + $x = getBestSupportedMimeType(explode(',', $accept_header)); + + if (! $x) { + $x = getBestSupportedMimeType([ + 'application/ld+json;profile="https://www.w3.org/ns/activitystreams"', + 'application/activity+json', + 'application/ld+json;profile="http://www.w3.org/ns/activitystreams"', + 'application/ld+json', + 'application/x-zot-activity+json' + ]); + } return (bool)$x; } diff --git a/Code/Lib/Libzot.php b/Code/Lib/Libzot.php index 4aef43360..c90d118c4 100644 --- a/Code/Lib/Libzot.php +++ b/Code/Lib/Libzot.php @@ -3238,10 +3238,22 @@ class Libzot public static function is_nomad_request() { - $x = getBestSupportedMimeType([ 'application/x-zot+json', 'application/x-nomad+json' ]); + $supportedTypes = explode(',', self::getAccepts()); + $x = getBestSupportedMimeType($supportedTypes); return (($x) ? true : false); } + public static function getAccepts() { + $default_accept_header = 'application/x-zot+json,application/x-nomad+json'; + + if ($channel) { + $accept_header = PConfig::Get($channel['channel_id'],'system','nomad_accept_header'); + } + if (!$accept_header) { + $accept_header = Config::Get('system', 'nomad_accept_header', $default_accept_header); + } + return $accept_header; + } public static function zot_record_preferred($arr, $check = 'hubloc_network') { diff --git a/Code/Lib/Zotfinger.php b/Code/Lib/Zotfinger.php index 5c76828b1..1b379079d 100644 --- a/Code/Lib/Zotfinger.php +++ b/Code/Lib/Zotfinger.php @@ -25,9 +25,10 @@ class Zotfinger $data = json_encode(['zot_token' => random_string()]); + $accepts = Libzot::getAccepts(); if ($channel && $m) { $headers = [ - 'Accept' => 'application/x-nomad+json, application/x-zot+json', + 'Accept' => $accepts, 'Content-Type' => 'application/x-nomad+json', 'X-Zot-Token' => random_string(), 'Digest' => HTTPSig::generate_digest_header($data), @@ -37,7 +38,7 @@ class Zotfinger $h = HTTPSig::create_sig($headers, $channel['channel_prvkey'], Channel::url($channel), false); } else { - $h = ['Accept: application/x-nomad+json, application/x-zot+json']; + $h = ['Accept: ' . $accepts]; } $result = []; diff --git a/Code/Module/Dev/Zot_probe.php b/Code/Module/Dev/Zot_probe.php index 5efb85152..2adf59063 100644 --- a/Code/Module/Dev/Zot_probe.php +++ b/Code/Module/Dev/Zot_probe.php @@ -3,6 +3,7 @@ namespace Code\Module\Dev; use App; +use Code\Lib\Libzot; use Code\Lib\Url; use Code\Lib\Zotfinger; use Code\Web\Controller; @@ -31,7 +32,8 @@ class Zot_probe extends Controller $o .= '
' . htmlspecialchars(print_array($x)) . '
'; - $headers = 'Accept: application/x-nomad+json, application/x-zot+json, application/jrd+json, application/json'; + $accepts = Libzot::getAccepts() . ', application/jrd+json, application/json'; + $headers = 'Accept: ' . $accepts; $x = Url::get($resource, ['headers' => [$headers]]); diff --git a/Code/Module/Magic.php b/Code/Module/Magic.php index d37648b6c..572182794 100644 --- a/Code/Module/Magic.php +++ b/Code/Module/Magic.php @@ -3,6 +3,7 @@ namespace Code\Module; use App; +use Code\Lib\Libzot; use Code\Web\Controller; use Code\Web\HTTPSig; use Code\Lib\SConfig; @@ -95,7 +96,7 @@ class Magic extends Controller $dest = strip_query_param($dest, 'f'); $headers = []; - $headers['Accept'] = 'application/x-nomad+json, application/x-zot+json'; + $headers['Accept'] = Libzot::getAccepts(); $headers['Content-Type'] = 'application/x-nomad+json'; $headers['X-Open-Web-Auth'] = random_string(); $headers['Host'] = $parsed['host']; diff --git a/Code/Module/Rpost.php b/Code/Module/Rpost.php index a91c6c4d3..798893ce1 100644 --- a/Code/Module/Rpost.php +++ b/Code/Module/Rpost.php @@ -99,7 +99,7 @@ class Rpost extends Controller $url = z_root() . '/cloud/' . $channel['channel_address'] . '/' . $r['data']['display_path']; - if (strpos($r['data']['filetype'], 'video') === 0) { + if (str_starts_with($r['data']['filetype'], 'video')) { for ($n = 0; $n < 15; $n++) { $thumb = Linkinfo::get_video_poster($url); if ($thumb) { @@ -114,7 +114,7 @@ class Rpost extends Controller $s .= "\n\n" . '[zvideo]' . $url . '[/zvideo]' . "\n\n"; } } - if (strpos($r['data']['filetype'], 'audio') === 0) { + if (str_starts_with($r['data']['filetype'], 'audio')) { $s .= "\n\n" . '[zaudio]' . $url . '[/zaudio]' . "\n\n"; } if ($r['data']['filetype'] === 'image/svg+xml') {