*/
namespace Friendica\Util;
+use DOMDocument;
+use DomXPath;
+use Friendica\Core\Config;
use Friendica\Core\Hook;
use Friendica\Core\Logger;
use Friendica\Core\System;
-use Friendica\Core\Config;
use Friendica\Network\CurlResult;
-use DOMDocument;
-use DomXPath;
class Network
{
*/
public static function curl($url, $binary = false, &$redirects = 0, $opts = [])
{
- $ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => ''];
-
$stamp1 = microtime(true);
$a = \get_app();
return CurlResult::createErrorCurl(substr($url, 0, 200));
}
+ $parts2 = [];
$parts = parse_url($url);
$path_parts = explode('/', defaults($parts, 'path', ''));
foreach ($path_parts as $part) {
@curl_close($ch);
- $a->saveTimestamp($stamp1, 'network');
+ $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack());
return $curlResponse;
}
$s = @curl_exec($ch);
- $base = $s;
$curl_info = curl_getinfo($ch);
$curlResponse = new CurlResult($url, $s, $curl_info, curl_errno($ch), curl_error($ch));
curl_close($ch);
- $a->saveTimestamp($stamp1, 'network');
+ $a->getProfiler()->saveTimestamp($stamp1, 'network', System::callstack());
Logger::log('post_url: end ' . $url, Logger::DATA);
* @param string $url The url to check the domain from
*
* @return boolean
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
*/
public static function isUrlBlocked($url)
{
$http_code = $curl_info['http_code'];
curl_close($ch);
- $a->saveTimestamp($stamp1, "network");
+ $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
if ($http_code == 0) {
return $url;
$body = curl_exec($ch);
curl_close($ch);
- $a->saveTimestamp($stamp1, "network");
+ $a->getProfiler()->saveTimestamp($stamp1, "network", System::callstack());
if (trim($body) == "") {
return $url;
(strlen($query) ? "?".$query : '') .
(strlen($fragment) ? "#".$fragment : '');
}
+
+
+ /**
+ * Switch the scheme of an url between http and https
+ *
+ * @param string $url URL
+ *
+ * @return string switched URL
+ */
+ public static function switchScheme($url)
+ {
+ $scheme = parse_url($url, PHP_URL_SCHEME);
+ if (empty($scheme)) {
+ return $url;
+ }
+
+ if ($scheme === 'http') {
+ $url = str_replace('http://', 'https://', $url);
+ } elseif ($scheme === 'https') {
+ $url = str_replace('https://', 'http://', $url);
+ }
+
+ return $url;
+ }
}