Пример #1
0
 /**
  * Fetches ushahidi from download.ushahidi.com
  * 
  * @param String url-- download URL
  */
 public function download_ushahidi($url)
 {
     $http_client = new HttpClient($url, 30);
     $results = $http_client->execute();
     $this->log[] = "Starting to download the latest ushahidi build...";
     if ($results) {
         $this->log[] = "Download of latest ushahidi went successful.";
         $this->success = true;
         return $results;
     } else {
         $this->errors[] = sprintf(Kohana::lang('libraries.upgrade_failed') . ": %d", $http_client->get_error_msg());
         $this->success = false;
         return $results;
     }
 }
Пример #2
0
 /**
  * Helper function to send a cURL request
  * @param url - URL for cURL to hit
  */
 public function _curl_req($url)
 {
     $request = new HttpClient($url);
     $buffer = $request->execute();
     if ($buffer === FALSE) {
         throw new Kohana_Exception($request->get_error_msg());
     }
     return $buffer;
 }
Пример #3
0
 /**
  * Read in new layer KML via HttpClient
  * @param int $layer_id - ID of the new KML Layer
  */
 public function layer($layer_id = 0)
 {
     $this->template = "";
     $this->auto_render = FALSE;
     $layer = ORM::factory('layer')->where('layer_visible', 1)->find($layer_id);
     if ($layer->loaded) {
         $layer_url = $layer->layer_url;
         $layer_file = $layer->layer_file;
         if ($layer_url != '') {
             // Pull from a URL
             $layer_link = $layer_url;
         } else {
             // Pull from an uploaded file
             $layer_link = Kohana::config('upload.directory') . '/' . $layer_file;
         }
         $layer_request = new HttpClient($layer_link);
         $content = $layer_request->execute();
         if ($content === FALSE) {
             throw new Kohana_Exception($layer_request->get_error_msg());
         } else {
             echo $content;
         }
     } else {
         throw new Kohana_404_Exception();
     }
 }
Пример #4
0
 /**
  * Reverse Geocode a point using Google Geocode
  *
  * @author
  * @param   double  $latitude
  * @param   double  $longitude
  * @return  string  closest approximation of the point as a display name
  */
 static function reverseGoogle($lat, $lng)
 {
     if ($lat && $lng) {
         $url = Kohana::config('config.external_site_protocol') . '://maps.googleapis.com/maps/api/geocode/json?sensor=false&latlng=' . $lat . "," . $lng;
         $request = new HttpClient($url);
         if (!($json = $request->execute())) {
             Kohana::log('error', "Geocode - reverseGoogle\n" . $url . "\n" . $request->get_error_msg());
             return FALSE;
         }
         $location = json_decode($json);
         if ($location->status != 'OK') {
             // logs anything different from OK
             Kohana::log('error', "Geocode - reverseGoogle: " . $location->status . " - " . $location->error_message);
             return FALSE;
         }
         if (count($location->results) == 0) {
             return FALSE;
         }
         return $location->results[0]->formatted_address;
     } else {
         return FALSE;
     }
 }