From 41a90f24786bf28d787fd0cf8c5af18407524391 Mon Sep 17 00:00:00 2001 From: Erich Eckner Date: Wed, 22 May 2019 14:07:32 +0200 Subject: lib/format.php: export_as_requested() understands /$format/ URIs now, too --- lib/format.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/format.php b/lib/format.php index 25748f0..f0f34b3 100644 --- a/lib/format.php +++ b/lib/format.php @@ -6,19 +6,19 @@ if (function_exists("export_as_requested")) include_once BASE . "/lib/http.php"; -function export_as_requested($content) { +function export_as_requested($content, $format = NULL) { if (isset($content["All"])) { $content["json"]=$content["All"]; $content["tsv"]=$content["All"]; unset($content["All"]); } - if (isset($content["json"]) && array_key_exists("json", $_GET)) { + if (isset($content["json"]) && ((empty($format) && array_key_exists("json", $_GET)) || ($format == 'json'))) { header ("Content-type: application/json"); print json_encode( $content["json"], JSON_UNESCAPED_SLASHES ); - } elseif (isset($content["tsv"]) && array_key_exists("tsv", $_GET)) { + } elseif (isset($content["tsv"]) && ((empty($format) && array_key_exists("tsv", $_GET)) || ($format == 'tsv'))) { header ("Content-type: text/tab-separated-values"); if (! array_key_exists("no-headers", $_GET)) print implode("\t",array_keys($content["tsv"][0])) . "\n"; @@ -32,6 +32,8 @@ function export_as_requested($content) { ) ); } else { + if (!empty($format)) + return false; throw_http_error( 406, "Not Acceptable", @@ -54,4 +56,5 @@ function export_as_requested($content) { ) ); } + return true; } -- cgit v1.2.3-70-g09d2