*/
use Friendica\App;
+use Friendica\Core\System;
use Friendica\Core\Config;
use Friendica\Network\Probe;
* string 'body' => fetched content
*/
function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) {
- $ret = array('return_code' => 0, 'success' => false, 'header' => '', 'body' => '');
+ $ret = array('return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '');
$stamp1 = microtime(true);
}
}
+ if (Config::get('system', 'ipv4_resolve', false)) {
+ curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
+ }
+
if ($binary) {
@curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
}
// if it throws any errors.
$s = @curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
+
+ // Special treatment for HTTP Code 416
+ // See https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/416
+ if (($curl_info['http_code'] == 416) && ($range > 0)) {
+ @curl_setopt($ch, CURLOPT_RANGE, '');
+ $s = @curl_exec($ch);
+ $curl_info = @curl_getinfo($ch);
+ }
if (curl_errno($ch) !== CURLE_OK) {
logger('fetch_url error fetching ' . $url . ': ' . curl_error($ch), LOGGER_NORMAL);
$ret['errno'] = curl_errno($ch);
$base = $s;
- $curl_info = @curl_getinfo($ch);
+ $ret['info'] = $curl_info;
$http_code = $curl_info['http_code'];
+
logger('fetch_url ' . $url . ': ' . $http_code . " " . $s, LOGGER_DATA);
$header = '';
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 {
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);
}
-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,'<?xml'))
- return false;
- $s2 = substr($s,strpos($s,'<?xml'));
- }
- else
- $s2 = $s;
libxml_use_internal_errors(true);
- $x = @simplexml_load_string($s2);
- if (! $x) {
- logger('libxml: parse: error: ' . $s2, LOGGER_DATA);
+ $x = @simplexml_load_string($s);
+ if (!$x) {
+ logger('libxml: parse: error: ' . $s, LOGGER_DATA);
foreach (libxml_get_errors() as $err) {
logger('libxml: parse: ' . $err->code." at ".$err->line.":".$err->column." : ".$err->message, LOGGER_DATA);
}
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;
}
}
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']));
}
}
return normalise_link($match);
}
+
+/**
+ * @brief Glue url parts together
+ *
+ * @param array $parsed URL parts
+ *
+ * @return string The glued URL
+ */
+function unParseUrl($parsed) {
+ $get = function ($key) use ($parsed) {
+ return isset($parsed[$key]) ? $parsed[$key] : null;
+ };
+
+ $pass = $get('pass');
+ $user = $get('user');
+ $userinfo = $pass !== null ? "$user:$pass" : $user;
+ $port = $get('port');
+ $scheme = $get('scheme');
+ $query = $get('query');
+ $fragment = $get('fragment');
+ $authority =
+ ($userinfo !== null ? $userinfo."@" : '') .
+ $get('host') .
+ ($port ? ":$port" : '');
+
+ return (strlen($scheme) ? $scheme.":" : '') .
+ (strlen($authority) ? "//".$authority : '') .
+ $get('path') .
+ (strlen($query) ? "?".$query : '') .
+ (strlen($fragment) ? "#".$fragment : '');
+}