From 92f60ef51fc8c85f632a245847c75ab27980d0de Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 1 Dec 2013 19:52:18 -0800 Subject: get rid of deprecated post_url() function --- include/network.php | 104 +--------------------------------------------------- 1 file changed, 2 insertions(+), 102 deletions(-) (limited to 'include/network.php') diff --git a/include/network.php b/include/network.php index a15b89c67..77ba7b176 100644 --- a/include/network.php +++ b/include/network.php @@ -6,108 +6,6 @@ function get_capath() { return appdirpath() . '/library/cacert.pem'; } - - -// curl wrapper. If binary flag is true, return binary -// results. - -/** - * fetch_url is deprecated and being replaced by the more capable z_fetch_url - * please use that function instead. - * Once all occurrences of fetch_url are removed from the codebase we will - * remove this function and perhaps rename z_fetch_url back to fetch_url - */ - -// post request to $url. $params is an array of post variables. - - -function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0) { - $a = get_app(); - $ch = curl_init($url); - if(($redirects > 8) || (! $ch)) - return false; - - curl_setopt($ch, CURLOPT_HEADER, true); - @curl_setopt($ch, CURLOPT_CAINFO, get_capath()); - curl_setopt($ch, CURLOPT_RETURNTRANSFER,true); - curl_setopt($ch, CURLOPT_POST,1); - curl_setopt($ch, CURLOPT_POSTFIELDS,$params); - curl_setopt($ch, CURLOPT_USERAGENT, "Red"); - - if(intval($timeout)) { - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); - } - else { - $curl_time = intval(get_config('system','curl_timeout')); - curl_setopt($ch, CURLOPT_TIMEOUT, (($curl_time !== false) ? $curl_time : 60)); - } - - if(defined('LIGHTTPD')) { - if(!is_array($headers)) { - $headers = array('Expect:'); - } else { - if(!in_array('Expect:', $headers)) { - array_push($headers, 'Expect:'); - } - } - } - if($headers) - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); - - $check_cert = get_config('system','verifyssl'); - curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, (($check_cert) ? true : false)); - $prx = get_config('system','proxy'); - if(strlen($prx)) { - curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1); - curl_setopt($ch, CURLOPT_PROXY, $prx); - $prxusr = get_config('system','proxyuser'); - if(strlen($prxusr)) - curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr); - } - - - // don't let curl abort the entire application - // if it throws any errors. - - $s = @curl_exec($ch); - - $base = $s; - $curl_info = curl_getinfo($ch); - $http_code = $curl_info['http_code']; - - $header = ''; - - // Pull out multiple headers, e.g. proxy and continuation headers - // allow for HTTP/2.x without fixing code - - while(preg_match('/^HTTP\/[1-2].+? [1-5][0-9][0-9]/',$base)) { - $chunk = substr($base,0,strpos($base,"\r\n\r\n")+4); - $header .= $chunk; - $base = substr($base,strlen($chunk)); - } - - if($http_code == 301 || $http_code == 302 || $http_code == 303 || $http_code == 307 || $http_code == 308) { - $matches = array(); - preg_match('/(Location:|URI:)(.*?)\n/', $header, $matches); - $newurl = trim(array_pop($matches)); - if(strpos($newurl,'/') === 0) - $newurl = $url . $newurl; - $url_parsed = @parse_url($newurl); - if (isset($url_parsed)) { - $redirects++; - @curl_close($ch); - return post_url($newurl,$params,$redirects,$timeout); - } - } - - $body = substr($s,strlen($header)); - curl_close($ch); - return($body); -} - - - - /** * @function z_fetch_url * @param string $url @@ -251,6 +149,8 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) { "Accept: " . $opts['accept_content'] )); } + if(x($opts,'headers')) + curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']); if(x($opts,'timeout') && intval($opts['timeout'])) { @curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']); -- cgit v1.2.3