Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/format.php
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2018-07-10 09:00:24 +0200
committerErich Eckner <git@eckner.net>2018-07-10 09:00:24 +0200
commit272bae0fa77072f4e6676bb49ce9ba815d93940c (patch)
tree974a77287930aba442c9643289049f6818058c6e /lib/format.php
parent14aa04c65c693aa4b7fb32916a5dcf76d5ec1194 (diff)
lib/format.php new
Diffstat (limited to 'lib/format.php')
-rw-r--r--lib/format.php33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/format.php b/lib/format.php
new file mode 100644
index 0000000..c250c8a
--- /dev/null
+++ b/lib/format.php
@@ -0,0 +1,33 @@
+<?php
+
+# do not include twice
+if (function_exists("export_as_requested"))
+ return;
+
+require_once "../init.php";
+include_once BASE . "/lib/http.php";
+
+function export_as_requested($content) {
+ if (isset($_GET["json"])) {
+ header ("Content-type: application/json");
+ print json_encode(
+ $content,
+ JSON_UNESCAPED_SLASHES
+ );
+ } elseif (isset($_GET["tsv"])) {
+ header ("Content-type: text/tab-separated-values");
+ if (! isset($_GET["no-headers"]))
+ print implode("\t",array_keys($content[0])) . "\n";
+ print implode(
+ "\n",
+ array_map(
+ function($row){
+ return implode("\t",$row);
+ },
+ $content
+ )
+ );
+ } else {
+ throw_http_error(406,"Not Acceptable","Unknown output format.");
+ }
+}