From 9689e536a9c72251fc20512f81a24b3a92a53c22 Mon Sep 17 00:00:00 2001 From: Remi Collet Date: Sun, 19 Sep 2010 10:30:28 +0200 Subject: add header + fix version when epoch --- zoom.php | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'zoom.php') diff --git a/zoom.php b/zoom.php index 39381a7..c36c2c5 100644 --- a/zoom.php +++ b/zoom.php @@ -193,22 +193,23 @@ if ( !isset($name) || !$name ) { ); } } + if ($type == "json") { - // Displays the output as json + // Displays the output as json (TODO : why not use json_encode) + header('Content-Type: application/json'); + $json = "{"; - $json .= '"package": "' . $name ."\", "; - $json .= '"branch": ['; + $json .= '"package":"' . $name ."\","; + $json .= '"branch":['; $cnt = 0; foreach ($packages as $package) { $cnt += 1; $json .= "{"; - $json .= '"'. $package->repo_main .'": '; + $json .= '"'. $package->repo_main .'":"'; if ($package->epoch) { - $json .= '"'.$package->epoch.'" '; - } else { - $json .= '"'.$package->ver."-".$package->rel.'" '; + $json .= $package->epoch.':'; } - $json .= "}"; + $json .= $package->ver."-".$package->rel.'"}'; if ($cnt != count($packages)) { $json .= ","; } @@ -217,17 +218,17 @@ if ($type == "json") { echo $json; } else if ($type == "text") { // Displays the output as text + header('Content-Type: text/plain'); + $text = 'package: ' . $name ." \n"; $cnt = 0; foreach ($packages as $package) { $cnt += 1; $text .= $package->repo_main .': '; if ($package->epoch) { - $text .= $package->epoch; - } else { - $text .= $package->ver."-".$package->rel; + $text .= $package->epoch.':'; } - $text .= "\n"; + $text .= $package->ver."-".$package->rel."\n"; } echo $text; } else { -- cgit