X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fnetwork.php;h=11a0fffbe671a827c3e524e10ed0bc7b76def26c;hb=26d7cf1d6a03840bd6645ceb514ee92620a65485;hp=7d8cf36118a0363444edbebeca1eeb1647554ba6;hpb=2bbcbdc7041843bf1e0f116b0d59b371e670daf9;p=friendica.git
diff --git a/include/network.php b/include/network.php
index 7d8cf36118..11a0fffbe6 100644
--- a/include/network.php
+++ b/include/network.php
@@ -5,6 +5,7 @@
*/
use Friendica\App;
+use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Probe;
@@ -107,6 +108,11 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
@curl_setopt($ch, CURLOPT_RANGE, '0-' . $range);
}
+ // Without this setting it seems as if some webservers send compressed content
+ // This seems to confuse curl so that it shows this uncompressed.
+ /// @todo We could possibly set this value to "gzip" or something similar
+ curl_setopt($ch, CURLOPT_ENCODING, '');
+
if (x($opts, 'headers')) {
@curl_setopt($ch, CURLOPT_HTTPHEADER, $opts['headers']);
}
@@ -144,6 +150,10 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
}
}
+ if (Config::get('system', 'ipv4_resolve', false)) {
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+ }
+
if ($binary) {
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
@@ -187,7 +197,7 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
$newurl = $curl_info['redirect_url'];
- if (($new_location_info['path'] == '') AND ( $new_location_info['host'] != '')) {
+ if (($new_location_info['path'] == '') && ( $new_location_info['host'] != '')) {
$newurl = $new_location_info['scheme'] . '://' . $new_location_info['host'] . $old_location_info['path'];
}
@@ -220,8 +230,8 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
if (!$ret['success']) {
$ret['error'] = curl_error($ch);
$ret['debug'] = $curl_info;
- logger('z_fetch_url: error: ' . $url . ': ' . $ret['error'], LOGGER_DEBUG);
- logger('z_fetch_url: debug: ' . print_r($curl_info, true), LOGGER_DATA);
+ logger('z_fetch_url: error: '.$url.': '.$ret['return_code'].' - '.$ret['error'], LOGGER_DEBUG);
+ logger('z_fetch_url: debug: '.print_r($curl_info, true), LOGGER_DATA);
}
$ret['body'] = substr($s, strlen($header));
@@ -272,6 +282,10 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent());
+ if (Config::get('system', 'ipv4_resolve', false)) {
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+ }
+
if (intval($timeout)) {
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
} else {
@@ -372,14 +386,22 @@ function post_url($url, $params, $headers = null, &$redirects = 0, $timeout = 0)
function xml_status($st, $message = '') {
- $xml_message = ((strlen($message)) ? "\t" . xmlify($message) . "\r\n" : '');
+ $result = array('status' => $st);
+
+ if ($message != '') {
+ $result['message'] = $message;
+ }
- if ($st)
+ if ($st) {
logger('xml_status returning non_zero: ' . $st . " message=" . $message);
+ }
+
+ header("Content-type: text/xml");
+
+ $xmldata = array("result" => $result);
+
+ echo xml::from_array($xmldata, $xml);
- header( "Content-type: text/xml" );
- echo ''."\r\n";
- echo "\r\n\t$st\r\n$xml_message\r\n";
killme();
}
@@ -598,7 +620,7 @@ function avatar_img($email) {
call_hooks('avatar_lookup', $avatar);
if (! $avatar['success']) {
- $avatar['url'] = App::get_baseurl() . '/images/person-175.jpg';
+ $avatar['url'] = System::baseUrl() . '/images/person-175.jpg';
}
logger('Avatar: ' . $avatar['email'] . ' ' . $avatar['url'], LOGGER_DEBUG);
@@ -606,20 +628,15 @@ function avatar_img($email) {
}
-function parse_xml_string($s,$strict = true) {
+function parse_xml_string($s, $strict = true) {
+ // the "strict" parameter is deactivated
+
/// @todo Move this function to the xml class
- if ($strict) {
- if (! strstr($s,'code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
}
@@ -647,7 +664,7 @@ function scale_external_images($srctext, $include_link = true, $scale_replace =
foreach ($matches as $mtch) {
logger('scale_external_image: ' . $mtch[1]);
- $hostname = str_replace('www.','',substr(App::get_baseurl(),strpos(App::get_baseurl(),'://')+3));
+ $hostname = str_replace('www.','',substr(System::baseUrl(),strpos(System::baseUrl(),'://')+3));
if (stristr($mtch[1],$hostname)) {
continue;
}
@@ -723,7 +740,10 @@ function fix_contact_ssl_policy(&$contact,$new_policy) {
}
if ($ssl_changed) {
- dba::update('contact', $contact, array('id' => $contact['id']));
+ $fields = array('url' => $contact['url'], 'request' => $contact['request'],
+ 'notify' => $contact['notify'], 'poll' => $contact['poll'],
+ 'confirm' => $contact['confirm'], 'poco' => $contact['poco']);
+ dba::update('contact', $fields, array('id' => $contact['id']));
}
}
@@ -818,8 +838,8 @@ function original_url($url, $depth = 1, $fetchbody = false) {
if ($http_code == 0)
return($url);
- if ((($curl_info['http_code'] == "301") OR ($curl_info['http_code'] == "302"))
- AND (($curl_info['redirect_url'] != "") OR ($curl_info['location'] != ""))) {
+ if ((($curl_info['http_code'] == "301") || ($curl_info['http_code'] == "302"))
+ && (($curl_info['redirect_url'] != "") || ($curl_info['location'] != ""))) {
if ($curl_info['redirect_url'] != "")
return(original_url($curl_info['redirect_url'], ++$depth, $fetchbody));
else
@@ -835,7 +855,7 @@ function original_url($url, $depth = 1, $fetchbody = false) {
return($url);
// if it isn't a HTML file then exit
- if (($curl_info["content_type"] != "") AND !strstr(strtolower($curl_info["content_type"]),"html"))
+ if (($curl_info["content_type"] != "") && !strstr(strtolower($curl_info["content_type"]),"html"))
return($url);
$stamp1 = microtime(true);
@@ -929,7 +949,7 @@ function json_return_and_die($x) {
*/
function matching_url($url1, $url2) {
- if (($url1 == "") OR ($url2 == ""))
+ if (($url1 == "") || ($url2 == ""))
return "";
$url1 = normalise_link($url1);
@@ -938,7 +958,7 @@ function matching_url($url1, $url2) {
$parts1 = parse_url($url1);
$parts2 = parse_url($url2);
- if (!isset($parts1["host"]) OR !isset($parts2["host"]))
+ if (!isset($parts1["host"]) || !isset($parts2["host"]))
return "";
if ($parts1["scheme"] != $parts2["scheme"])
@@ -967,7 +987,7 @@ function matching_url($url1, $url2) {
if ($path1 == $path2)
$path .= $path1."/";
- } while (($path1 == $path2) AND ($i++ <= count($pathparts1)));
+ } while (($path1 == $path2) && ($i++ <= count($pathparts1)));
$match .= $path;