示例#1
0
文件: index.php 项目: rsinger/Jangle
 $uri = $config["services"][$path[0]]["connector_url"] . join($reqpath, "/");
 if (preg_match("/\\/\$/", $url["path"])) {
     $uri .= "/";
 }
 if (count($_GET) > 0) {
     $uri .= "?" . http_build_query($_GET);
 }
 $http = new HttpGet($uri, $config["server"]["base_url"] . $path[0]);
 if ($_SERVER['PHP_AUTH_USER'] && $_SERVER['PHP_AUTH_PW']) {
     $http->setBasicAuth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']);
 }
 $http->doGet();
 $statusMap = array(400 => array("message" => "Bad Request", "body" => "An illegal request was sent, most likely an invalid query parameter"), 401 => array("message" => "Unauthorized", "body" => "Authorization required to view this resource"), 403 => array("message" => "Forbidden", "body" => "You have not been authorized to view this resource"), 404 => array("message" => "Not Found", "body" => "The requested resource does not exist"), 405 => array("message" => "Method Not Allowed", "body" => "This resource does not permit GET requests"), 410 => array("message" => "Gone", "body" => "This resource no longer exists"));
 if ($http->getStatus() != 200 && $http->getStatus() != 304) {
     header("HTTP/1.1 " . $http->getStatus() . " " . $statusMap[$http->getStatus()]["message"]);
     if ($auth = $http->getAuthHeaders()) {
         header("WWW-Authenticate:  " . $auth);
     }
     echo $statusMap[$http->getStatus()]["body"];
     exit;
 }
 $json = json_decode($http->getBody());
 switch ($json->type) {
     case "feed":
         $response = new JangleFeed();
         header("Content-type: application/atom+xml");
         break;
     case "search":
         $response = new JangleSearch();
         header("Content-type: application/atom+xml");
         $response->query = $_GET['query'];