get rid of deprecated post_url() function
This commit is contained in:
parent
194c1e7abc
commit
92f60ef51f
@ -6,108 +6,6 @@ function get_capath() {
|
|||||||
return appdirpath() . '/library/cacert.pem';
|
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
|
* @function z_fetch_url
|
||||||
* @param string $url
|
* @param string $url
|
||||||
@ -251,6 +149,8 @@ function z_post_url($url,$params, $redirects = 0, $opts = array()) {
|
|||||||
"Accept: " . $opts['accept_content']
|
"Accept: " . $opts['accept_content']
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
if(x($opts,'headers'))
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
|
||||||
|
|
||||||
if(x($opts,'timeout') && intval($opts['timeout'])) {
|
if(x($opts,'timeout') && intval($opts['timeout'])) {
|
||||||
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
|
@curl_setopt($ch, CURLOPT_TIMEOUT, $opts['timeout']);
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
// FIXME - this has never been properly ported from Friendica
|
||||||
|
// It takes keywords from your profile and queries the directory server for
|
||||||
|
// matching keywords from other profiles.
|
||||||
|
|
||||||
|
|
||||||
function match_content(&$a) {
|
function match_content(&$a) {
|
||||||
|
|
||||||
@ -30,10 +34,10 @@ function match_content(&$a) {
|
|||||||
if($a->pager['page'] != 1)
|
if($a->pager['page'] != 1)
|
||||||
$params['p'] = $a->pager['page'];
|
$params['p'] = $a->pager['page'];
|
||||||
|
|
||||||
if(strlen(get_config('system','directory_submit_url')))
|
// if(strlen(get_config('system','directory_submit_url')))
|
||||||
$x = post_url('http://dir.friendica.com/msearch', $params);
|
// $x = post_url('http://dir.friendica.com/msearch', $params);
|
||||||
else
|
// else
|
||||||
$x = post_url($a->get_baseurl() . '/msearch', $params);
|
// $x = post_url($a->get_baseurl() . '/msearch', $params);
|
||||||
|
|
||||||
$j = json_decode($x);
|
$j = json_decode($x);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user