aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/network.php158
-rwxr-xr-xinclude/oembed.php3
2 files changed, 7 insertions, 154 deletions
diff --git a/include/network.php b/include/network.php
index 367e0df56..a15b89c67 100644
--- a/include/network.php
+++ b/include/network.php
@@ -18,97 +18,6 @@ function get_capath() {
* remove this function and perhaps rename z_fetch_url back to fetch_url
*/
-
-
-function fetch_url($url,$binary = false, &$redirects = 0, $timeout = 0, $accept_content=Null) {
-
- $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());
-
- if (!is_null($accept_content)){
- curl_setopt($ch,CURLOPT_HTTPHEADER, array (
- "Accept: " . $accept_content
- ));
- }
-
- @curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
- @curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (compatible; 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));
- }
- // by default we will allow self-signed certs
- // but you can override this
-
- $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);
- }
- if($binary)
- @curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
-
-// $a->set_curl_code(0);
-
- // 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'];
-// logger('fetch_url:' . $http_code . ' data: ' . $s);
- $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 fetch_url($newurl,$binary,$redirects,$timeout);
- }
- }
-
-// $a->set_curl_code($http_code);
-
- $body = substr($s,strlen($header));
-// $a->set_curl_headers($header);
- @curl_close($ch);
- return($body);
-}
-
// post request to $url. $params is an array of post variables.
@@ -156,7 +65,6 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $prxusr);
}
-// $a->set_curl_code(0);
// don't let curl abort the entire application
// if it throws any errors.
@@ -188,22 +96,18 @@ function post_url($url,$params, $headers = null, &$redirects = 0, $timeout = 0)
if (isset($url_parsed)) {
$redirects++;
@curl_close($ch);
- if($http_code == 303) {
- return fetch_url($newurl,false,$redirects,$timeout);
- } else {
- return post_url($newurl,$params,$redirects,$timeout);
- }
+ return post_url($newurl,$params,$redirects,$timeout);
}
}
-// $a->set_curl_code($http_code);
- $body = substr($s,strlen($header));
-
-// $a->set_curl_headers($header);
+ $body = substr($s,strlen($header));
curl_close($ch);
return($body);
}
+
+
+
/**
* @function z_fetch_url
* @param string $url
@@ -616,58 +520,6 @@ function fetch_lrdd_template($host) {
return $tpl;
}
-// Given a URL, retrieve the page as an XRD document.
-// Return an array of links.
-// on error/failure return empty array.
-
-
-function fetch_xrd_links($url) {
-
- $xrd_timeout = intval(get_config('system','xrd_timeout'));
- $redirects = 0;
- $xml = fetch_url($url,false,$redirects,(($xrd_timeout) ? $xrd_timeout : 30));
-
- logger('fetch_xrd_links: ' . $xml, LOGGER_DATA);
-
- if ((! $xml) || (! stristr($xml,'<xrd')))
- return array();
-
- // fix diaspora's bad xml
- $xml = str_replace(array('href=&quot;','&quot;/>'),array('href="','"/>'),$xml);
-
- $arr = xml2array($xml);
-
- logger('fetch_xrd_links: ' . print_r($arr,true), LOGGER_DATA);
-
- $links = array();
-
- if(isset($arr['xrd']['link'])) {
- $link = $arr['xrd']['link'];
- if(! isset($link[0]))
- $links = array($link);
- else
- $links = $link;
- }
- if(isset($arr['xrd']['alias'])) {
- $alias = $arr['xrd']['alias'];
- if(! isset($alias[0]))
- $aliases = array($alias);
- else
- $aliases = $alias;
- if(is_array($aliases) && count($aliases)) {
- foreach($aliases as $alias) {
- $links[]['@attributes'] = array('rel' => 'alias' , 'href' => $alias);
- }
- }
- }
-
- logger('fetch_xrd_links: ' . print_r($links,true), LOGGER_DATA);
-
- return $links;
-
-}
-
-
// Take a URL from the wild, prepend http:// if necessary
// and check DNS to see if it's real (or check if is a valid IP address)
// return true if it's OK, false if something is wrong with it
diff --git a/include/oembed.php b/include/oembed.php
index 5da842170..520b69892 100755
--- a/include/oembed.php
+++ b/include/oembed.php
@@ -44,7 +44,8 @@ function oembed_fetch_url($embedurl){
$entries = $xpath->query("//link[@type='application/json+oembed']");
foreach($entries as $e){
$href = $e->getAttributeNode("href")->nodeValue;
- $txt = fetch_url($href . '&maxwidth=' . $a->videowidth);
+ $x = z_fetch_url($href . '&maxwidth=' . $a->videowidth);
+ $txt = $x['body'];
break;
}
}