Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/format.php
blob: c250c8a32f068d95a2efa4edf684a2038b3554ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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.");
  }
}