Permalink
Browse files

Merge pull request #1243 from ditorelo/923-fixes

Updating file_get_contents() and curl calls to HttpClient
  • Loading branch information...
2 parents b0eafd8 + 631ec0a commit 7b96cdf7a5a0378165f4e00599dd11bdb4e3532d @rjmackay rjmackay committed Sep 22, 2013
@@ -1090,19 +1090,12 @@ public function update_cities($country_id = 0)
private function _check_for_clean_url() {
- $url = url::base().'reports/';
+ $url = url::base() .'reports/';
- $curl_handle = curl_init();
+ $request = new HttpClient($url);
+ $return_code = $request->get_http_response_code();
- curl_setopt($curl_handle, CURLOPT_URL, $url);
- curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true );
- curl_setopt($curl_handle, CURLOPT_SSL_VERIFYPEER, false);
- curl_exec($curl_handle);
-
- $return_code = curl_getinfo($curl_handle,CURLINFO_HTTP_CODE);
- curl_close($curl_handle);
-
- return ($return_code == 404)? FALSE : TRUE;
+ return ($return_code == 404)? FALSE : TRUE;
}
/**
@@ -543,28 +543,4 @@ function punchcard()
$this->template->content->chart_url = Kohana::config('core.site_protocol').'://chart.googleapis.com/chart?chs=905x300&chds=-1,24,-1,7,0,'.$highest_value.'&chf=bg,s,efefef&chd=t:0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23|0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7|'.implode(',',$data['sun']).','.implode(',',$data['mon']).','.implode(',',$data['tue']).','.implode(',',$data['wed']).','.implode(',',$data['thu']).','.implode(',',$data['fri']).','.implode(',',$data['sat']).',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0&chxt=x,y&chm=o,333333,1,1.0,30.0&chxl=0:||12'.Kohana::lang('datetime.am').'|1|2|3|4|5|6|7|8|9|10|11|12'.Kohana::lang('datetime.pm').'|1|2|3|4|5|6|7|8|9|10|11||1:||'.Kohana::lang('datetime.sunday.abbv').'|'.Kohana::lang('datetime.monday.abbv').'|'.Kohana::lang('datetime.tuesday.abbv').'|'.Kohana::lang('datetime.wednesday.abbv').'|'.Kohana::lang('datetime.thursday.abbv').'|'.Kohana::lang('datetime.friday.abbv').'|'.Kohana::lang('datetime.saturday.abbv').'|&cht=s';
}
-
- /**
- * Helper function to send a cURL request
- * @param url - URL for cURL to hit
- */
- public function _curl_req( $url )
- {
- // Make sure cURL is installed
- if ( ! function_exists('curl_exec'))
- {
- throw new Kohana_Exception('stats.cURL_not_installed');
- return false;
- }
-
- $curl_handle = curl_init();
- curl_setopt($curl_handle,CURLOPT_URL,$url);
- curl_setopt($curl_handle,CURLOPT_CONNECTTIMEOUT,15); // Timeout set to 15 seconds. This is somewhat arbitrary and can be changed.
- curl_setopt($curl_handle,CURLOPT_RETURNTRANSFER,1); //Set curl to store data in variable instead of print
- curl_setopt($curl_handle,CURLOPT_SSL_VERIFYPEER, false);
- $buffer = curl_exec($curl_handle);
- curl_close($curl_handle);
-
- return $buffer;
- }
}
@@ -621,7 +621,7 @@ public function timeline($category_id = 0)
/**
- * Read in new layer KML via file_get_contents
+ * Read in new layer KML via HttpClient
* @param int $layer_id - ID of the new KML Layer
*/
public function layer($layer_id = 0)
@@ -649,9 +649,14 @@ public function layer($layer_id = 0)
$layer_link = Kohana::config('upload.directory').'/'.$layer_file;
}
- $content = file_get_contents($layer_link);
+ $layer_request = new HttpClient($layer_link);
+ $content = $layer_request->execute();
- if ($content !== false)
+ if ($content === FALSE)
+ {
+ throw new Kohana_Exception($layer_request->get_error_msg());
+ }
+ else
{
echo $content;
}
@@ -473,7 +473,11 @@ public static function geocode($address = NULL)
$url = Kohana::config('config.external_site_protocol').'://maps.google.com/maps/api/geocode/json?sensor=false&address='.rawurlencode($address);
$result = FALSE;
- if ($result = @file_get_contents($url)) {
+
+ $url_request = new HttpClient($url);
+
+ if ($result = $url_request->execute())
+ {
$payload = json_decode($result);
}
@@ -535,13 +539,10 @@ public static function reverse_geocode($latitude,$longitude)
{
if ($latitude AND $longitude)
{
- $url = 'http://nominatim.openstreetmap.org/reverse?format=json&lat='.$latitude.'&lon='.$longitude;
- $ch = curl_init();
- curl_setopt($ch,CURLOPT_URL,$url);
- curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
- curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
- $json = curl_exec($ch);
- curl_close($ch);
+ $url = 'http://nominatim.openstreetmap.org/reverse?format=json&lat=' . $latitude . '&lon=' . $longitude;
+
+ $request = new HttpClient($url);
+ $json = $request->execute();
$location = json_decode($json, false);
@@ -48,6 +48,7 @@ function geocode_feed ($feed_url = NULL)
{
$base_url = "http://" . GEOCODER_GEONAMES . "/rssToGeoRSS?";
+
if ($feed_url)
{
// First check to make sure geonames webservice is running
@@ -62,13 +63,17 @@ function geocode_feed ($feed_url = NULL)
$request_url = $feed_url;
}
- if ( ! ($georss = @file_get_contents($request_url)))
+
+ $request = new HttpClient($request_url);
+
+ if ( ! ($georss = $request->execute($request_url)))
{
// If the request failed, something may be wrong with the GEOCODER_GEONAMES service
return false;
}
//$georss = utf8_encode($georss);
+
return trim($georss);
}
Oops, something went wrong.

0 comments on commit 7b96cdf

Please sign in to comment.