protected function retrieveResponse() { if (!class_exists('ZipArchive')) { throw new KurogoException("class ZipArchive (php-zip) not available"); } $tmpFile = Kurogo::tempFile(); // this is the same as parent if (!($this->requestURL = $this->url())) { throw new KurogoDataException("URL could not be determined"); } $this->requestParameters = $this->parameters(); // the following are private functions in URLDataRetriever //$this->requestMethod = $this->setContextMethod(); //$this->requestHeaders = $this->setContextHeaders(); //$this->requestData = $this->setContextData(); Kurogo::log(LOG_INFO, "Retrieving {$this->requestURL}", 'url_retriever'); // the creation of $data is different from parent copy($this->requestURL, $tmpFile); $zip = new ZipArchive(); $zip->open($tmpFile); $data = $zip->getFromIndex(0); unlink($tmpFile); // this is the same as parent $http_response_header = isset($http_response_header) ? $http_response_header : array(); $response = $this->initResponse(); $response->setRequest($this->requestMethod, $this->requestURL, $this->requestParameters, $this->requestHeaders, null); $response->setResponse($data); $response->setResponseHeaders($http_response_header); Kurogo::log(LOG_DEBUG, sprintf("Returned status %d and %d bytes", $response->getCode(), strlen($data)), 'url_retriever'); return $response; }
protected function retrieveResponse() { $response = $this->initResponse(); if (strpos($this->fileStem, '.zip') !== false) { if (!class_exists('ZipArchive')) { throw new KurogoException("class ZipArchive (php-zip) not available"); } $response->setContext('zipped', true); $zip = new ZipArchive(); if (strpos($this->fileStem, 'http') === 0 || strpos($this->fileStem, 'ftp') === 0) { $tmpFile = Kurogo::tempFile(); copy($this->fileStem, $tmpFile); $zip->open($tmpFile); } else { $zip->open($this->fileStem); } // locate valid shapefile components $shapeNames = array(); for ($i = 0; $i < $zip->numFiles; $i++) { if (preg_match('/(.+)\\.(shp|dbf|prj)$/', $zip->getNameIndex($i), $matches)) { $shapeName = $matches[1]; $extension = $matches[2]; if (!isset($shapeNames[$shapeName])) { $shapeNames[$shapeName] = array(); } $shapeNames[$shapeName][] = $extension; } } $responseData = array(); foreach ($shapeNames as $shapeName => $extensions) { if (in_array('dbf', $extensions) && in_array('shp', $extensions)) { $fileData = array('dbf' => $zip->getFromName("{$shapeName}.dbf"), 'shp' => $zip->getFromName("{$shapeName}.shp")); if (in_array('prj', $extensions)) { $prjData = $zip->getFromName("{$shapeName}.prj"); $fileData['projection'] = new MapProjection($prjData); } $responseData[$shapeName] = $fileData; } } $response->setResponse($responseData); } elseif (realpath_exists("{$this->fileStem}.shp") && realpath_exists("{$this->fileStem}.dbf")) { $response->setContext('zipped', false); $response->setContext('shp', "{$this->fileStem}.shp"); $response->setContext('dbf', "{$this->fileStem}.dbf"); if (realpath_exists("{$this->fileStem}.prj")) { $prjData = file_get_contents("{$this->fileStem}.prj"); $response->setContext('projection', new MapProjection($prjData)); } } else { throw new KurogoDataException("Cannot find {$this->fileStem}"); } return $response; }
protected function retrieveResponse() { if (!class_exists('ZipArchive')) { throw new KurogoException("class ZipArchive (php-zip) not available"); } $tmpFile = Kurogo::tempFile(); // this is the same as parent if (!($this->requestURL = $this->url())) { throw new KurogoDataException("URL could not be determined"); } Kurogo::log(LOG_INFO, "Retrieving {$this->requestURL}", 'url_retriever'); // get data from parent request and save to temp file which we will // unzip and return $response = parent::retrieveResponse(); file_put_contents($tmpFile, $response->getResponse()); $zip = new ZipArchive(); if (!$zip->open($tmpFile)) { throw new KurogoDataException("Could not open zip file"); } $targetFile = $this->targetFile(); if ($targetFile) { $index = $zip->locateName($targetFile); } else { $index = 0; } if ($index === false) { // $zip->locateName failed throw new KurogoDataException("Could not locate {$this->targetFile} in zip archive"); } $data = $zip->getFromIndex($index); unlink($tmpFile); $zip->close(); $response->setResponse($data); Kurogo::log(LOG_DEBUG, sprintf("Returned status %d and %d bytes", $response->getCode(), strlen($data)), 'url_retriever'); return $response; }
protected function retrieveData($url) { if (strpos($url, '.kmz') !== false) { if (!class_exists('ZipArchive')) { throw new KurogoException("class ZipArchive (php-zip) not available"); } $tmpFile = Kurogo::tempFile(); copy($url, $tmpFile); $zip = new ZipArchive(); $zip->open($tmpFile); $contents = $zip->getFromIndex(0); unlink($tmpFile); return $contents; // this is false on failure, same as file_get_contents } return parent::retrieveData($url); }