X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fnetwork.php;h=413048d5b8057992d731b5e489b7ba8bfb8be02a;hb=b3e6a1d2832be024819328e51e9e1df4c25b560f;hp=45f5d4e79a9c4572e63d35bc88c92879a44f7661;hpb=6d3ced63894ebac84851b594e8bf80cc4677f9c5;p=friendica.git diff --git a/include/network.php b/include/network.php index 45f5d4e79a..413048d5b8 100644 --- a/include/network.php +++ b/include/network.php @@ -6,7 +6,7 @@ use Friendica\App; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Network\Probe; -use Friendica\Object\Photo; +use Friendica\Object\Image; use Friendica\Util\XML; /** @@ -232,8 +232,6 @@ function z_fetch_url($url, $binary = false, &$redirects = 0, $opts = array()) $a->set_curl_code($http_code); $a->set_curl_content_type($curl_info['content_type']); - $body = substr($s, strlen($header)); - $rc = intval($http_code); $ret['return_code'] = $rc; $ret['success'] = (($rc >= 200 && $rc <= 299) ? true : false); @@ -470,26 +468,28 @@ function http_status_exit($val, $description = array()) * and check DNS to see if it's real (or check if is a valid IP address) * * @param string $url The URL to be validated - * @return boolean True if it's a valid URL, fals if something wrong with it + * @return string|boolean The actual working URL, false else */ -function validate_url(&$url) +function validate_url($url) { if (Config::get('system', 'disable_url_validation')) { - return true; + return $url; } // no naked subdomains (allow localhost for tests) - if (strpos($url, '.') === false && strpos($url, '/localhost/') === false) + if (strpos($url, '.') === false && strpos($url, '/localhost/') === false) { return false; + } - if (substr($url, 0, 4) != 'http') + if (substr($url, 0, 4) != 'http') { $url = 'http://' . $url; + } - /// @TODO Really supress function outcomes? Why not find them + debug them? + /// @TODO Really suppress function outcomes? Why not find them + debug them? $h = @parse_url($url); if ((is_array($h)) && (dns_get_record($h['host'], DNS_A + DNS_CNAME + DNS_PTR) || filter_var($h['host'], FILTER_VALIDATE_IP) )) { - return true; + return $url; } return false; @@ -609,29 +609,40 @@ function blocked_url($url) function allowed_email($email) { $domain = strtolower(substr($email, strpos($email, '@') + 1)); - if (! $domain) { + if (!$domain) { return false; } - $str_allowed = Config::get('system', 'allowed_email'); - if (! $str_allowed) { + $str_allowed = Config::get('system', 'allowed_email', ''); + if (!x($str_allowed)) { return true; } - $found = false; - - $fnmatch = function_exists('fnmatch'); $allowed = explode(',', $str_allowed); - if (count($allowed)) { - foreach ($allowed as $a) { - $pat = strtolower(trim($a)); - if (($fnmatch && fnmatch($pat, $domain)) || ($pat == $domain)) { - $found = true; - break; - } + return allowed_domain($domain, $allowed); +} + +/** + * Checks for the existence of a domain in a domain list + * + * @brief Checks for the existence of a domain in a domain list + * @param string $domain + * @param array $domain_list + * @return boolean + */ +function allowed_domain($domain, array $domain_list) +{ + $found = false; + + foreach ($domain_list as $item) { + $pat = strtolower(trim($item)); + if (fnmatch($pat, $domain) || ($pat == $domain)) { + $found = true; + break; } } + return $found; } @@ -678,8 +689,6 @@ function scale_external_images($srctext, $include_link = true, $scale_replace = $include_link = false; } - $a = get_app(); - // Picture addresses can contain special characters $s = htmlspecialchars_decode($srctext); @@ -710,18 +719,18 @@ function scale_external_images($srctext, $include_link = true, $scale_replace = } // guess mimetype from headers or filename - $type = Photo::guessImageType($mtch[1], true); + $type = Image::guessType($mtch[1], true); if ($i) { - $ph = new Photo($i, $type); - if ($ph->isValid()) { - $orig_width = $ph->getWidth(); - $orig_height = $ph->getHeight(); + $Image = new Image($i, $type); + if ($Image->isValid()) { + $orig_width = $Image->getWidth(); + $orig_height = $Image->getHeight(); if ($orig_width > 640 || $orig_height > 640) { - $ph->scaleImage(640); - $new_width = $ph->getWidth(); - $new_height = $ph->getHeight(); + $Image->scaleDown(640); + $new_width = $Image->getWidth(); + $new_height = $Image->getHeight(); logger('scale_external_images: ' . $orig_width . '->' . $new_width . 'w ' . $orig_height . '->' . $new_height . 'h' . ' match: ' . $mtch[0], LOGGER_DEBUG); $s = str_replace( $mtch[0], @@ -853,7 +862,6 @@ function original_url($url, $depth = 1, $fetchbody = false) $stamp1 = microtime(true); - $siteinfo = array(); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 1); @@ -862,7 +870,7 @@ function original_url($url, $depth = 1, $fetchbody = false) curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_USERAGENT, $a->get_useragent()); - $header = curl_exec($ch); + curl_exec($ch); $curl_info = @curl_getinfo($ch); $http_code = $curl_info['http_code']; curl_close($ch); @@ -934,7 +942,6 @@ function original_url($url, $depth = 1, $fetchbody = false) if (@$attr["http-equiv"] == 'refresh') { $path = $attr["content"]; $pathinfo = explode(";", $path); - $content = ""; foreach ($pathinfo as $value) { if (substr(strtolower($value), 0, 4) == "url=") { return(original_url(substr($value, 4), ++$depth)); @@ -943,7 +950,7 @@ function original_url($url, $depth = 1, $fetchbody = false) } } - return($url); + return $url; } function short_link($url)