From f04d40a37eb36e903433478d671a9dcd5bb6aacb Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Sat, 27 Jan 2018 11:13:41 -0500 Subject: [PATCH] Review update Rename function, move others --- include/acl_selectors.php | 2 +- include/api.php | 2 +- include/bb2diaspora.php | 4 +- include/bbcode.php | 6 +- include/conversation.php | 14 +-- include/html2bbcode.php | 2 +- include/items.php | 2 +- mod/dfrn_confirm.php | 23 ++-- mod/dfrn_notify.php | 16 +-- mod/dfrn_poll.php | 27 ++--- mod/dfrn_request.php | 8 +- mod/dirfind.php | 4 +- mod/hovercard.php | 2 +- mod/install.php | 4 +- mod/item.php | 3 +- mod/match.php | 4 +- mod/nodeinfo.php | 2 +- mod/notifications.php | 2 +- mod/oexchange.php | 2 +- mod/ostatus_subscribe.php | 2 +- mod/parse_url.php | 2 +- mod/proxy.php | 2 +- mod/pubsubhubbub.php | 2 +- mod/settings.php | 2 +- mod/smilies.php | 2 +- spec/dfrn2_contact_confirmation.svg | 2 +- spec/dfrn2_contact_request.svg | 4 +- src/Content/OEmbed.php | 8 +- src/Content/Text/BBCode.php | 73 ++++++++++++ src/Core/NotificationsManager.php | 4 +- src/Core/Worker.php | 2 +- src/Model/Contact.php | 37 +++++- src/Model/GContact.php | 4 +- src/Model/Photo.php | 2 +- src/Model/Profile.php | 2 +- src/Model/User.php | 12 +- src/Module/Login.php | 2 +- src/Network/Probe.php | 28 ++--- src/Object/Image.php | 2 +- src/Protocol/DFRN.php | 24 ++-- src/Protocol/Diaspora.php | 18 +-- src/Protocol/Feed.php | 2 +- src/Protocol/OStatus.php | 14 +-- src/Protocol/PortableContact.php | 48 ++++---- src/Protocol/Salmon.php | 8 +- src/Util/ExAuth.php | 2 +- src/Util/Network.php | 172 +++++----------------------- src/Util/ParseUrl.php | 2 +- src/Util/XML.php | 16 +++ src/Worker/CheckVersion.php | 2 +- src/Worker/Delivery.php | 3 +- src/Worker/Directory.php | 8 +- src/Worker/DiscoverPoCo.php | 4 +- src/Worker/OnePoll.php | 9 +- src/Worker/PubSubPublish.php | 2 +- 55 files changed, 331 insertions(+), 326 deletions(-) diff --git a/include/acl_selectors.php b/include/acl_selectors.php index 38a418dd1..72f49a40b 100644 --- a/include/acl_selectors.php +++ b/include/acl_selectors.php @@ -734,7 +734,7 @@ function navbar_complete(App $a) { if (! $localsearch) { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); - $x = Network::zFetchURL(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::curl(get_server() . '/lsearch?f=' . $p . '&search=' . urlencode($search)); if ($x['success']) { $j = json_decode($x['body'],true); if ($j && isset($j['results'])) { diff --git a/include/api.php b/include/api.php index 610cd26dd..7164f85ab 100644 --- a/include/api.php +++ b/include/api.php @@ -5074,7 +5074,7 @@ function api_get_nick($profile) if ($StatusnetHost != $profile) { $StatusnetUser = preg_replace("=https?://(.*)/user/(.*)=ism", "$2", $profile); if ($StatusnetUser != $profile) { - $UserData = Network::fetchURL("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); + $UserData = Network::fetchUrl("http://".$StatusnetHost."/api/users/show.json?user_id=".$StatusnetUser); $user = json_decode($UserData); if ($user) { $nick = $user->screen_name; diff --git a/include/bb2diaspora.php b/include/bb2diaspora.php index d5fa8642a..95047d61a 100644 --- a/include/bb2diaspora.php +++ b/include/bb2diaspora.php @@ -1,11 +1,11 @@ loadHTML($body); @@ -803,7 +803,7 @@ function bb_CleanPictureLinksSub($match) { $text = "[img]".$match[2]."[/img]"; // if its not a picture then look if its a page that contains a picture link - $body = Network::fetchURL($match[1]); + $body = Network::fetchUrl($match[1]); $doc = new DOMDocument(); @$doc->loadHTML($body); diff --git a/include/conversation.php b/include/conversation.php index 11d0a0d0d..af4bb0559 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -15,7 +15,7 @@ use Friendica\Model\Contact; use Friendica\Model\Profile; use Friendica\Object\Thread; use Friendica\Object\Post; -use Friendica\Util\Network; +use Friendica\Util\XML; require_once "include/bbcode.php"; require_once "include/acl_selectors.php"; @@ -185,8 +185,8 @@ function localize_item(&$item) { $xmlhead="<"."?xml version='1.0' encoding='UTF-8' ?".">"; - $obj = Network::parseXmlString($xmlhead.$item['object']); - $links = Network::parseXmlString($xmlhead."".unxmlify($obj->link).""); + $obj = XML::parseString($xmlhead.$item['object']); + $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; $Bphoto = ""; @@ -221,8 +221,8 @@ function localize_item(&$item) { $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = Network::parseXmlString($xmlhead.$item['object']); - $links = Network::parseXmlString($xmlhead."".unxmlify($obj->link).""); + $obj = XML::parseString($xmlhead.$item['object']); + $links = XML::parseString($xmlhead."".unxmlify($obj->link).""); $Bname = $obj->title; $Blink = ""; @@ -296,7 +296,7 @@ function localize_item(&$item) { } $plink = '[url=' . $obj['plink'] . ']' . $post_type . '[/url]'; - $parsedobj = Network::parseXmlString($xmlhead.$item['object']); + $parsedobj = XML::parseString($xmlhead.$item['object']); $tag = sprintf('#[url=%s]%s[/url]', $parsedobj->id, $parsedobj->content); $item['body'] = L10n::t('%1$s tagged %2$s\'s %3$s with %4$s', $author, $objauthor, $plink, $tag ); @@ -313,7 +313,7 @@ function localize_item(&$item) { $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = Network::parseXmlString($xmlhead.$item['object']); + $obj = XML::parseString($xmlhead.$item['object']); if (strlen($obj->id)) { $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($obj->id), diff --git a/include/html2bbcode.php b/include/html2bbcode.php index c8a05c145..a5967d2cb 100644 --- a/include/html2bbcode.php +++ b/include/html2bbcode.php @@ -363,7 +363,7 @@ function addHostnameSub($matches, $basepath) $url = $matches[1]; $parts = array_merge($base, parse_url($url)); - $url2 = Network::unParseURL($parts); + $url2 = Network::unparseURL($parts); return str_replace($url, $url2, $link); } diff --git a/include/items.php b/include/items.php index a1afbb306..1951b340c 100644 --- a/include/items.php +++ b/include/items.php @@ -1481,7 +1481,7 @@ function subscribe_to_hub($url, $importer, $contact, $hubmode = 'subscribe') { dba::update('contact', ['hub-verify' => $verify_token], ['id' => $contact['id']]); } - Network::postURL($url, $params); + Network::post($url, $params); logger('subscribe_to_hub: returns: ' . $a->get_curl_code(), LOGGER_DEBUG); diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php index 8c50a05a1..85e896dcf 100644 --- a/mod/dfrn_confirm.php +++ b/mod/dfrn_confirm.php @@ -31,6 +31,7 @@ use Friendica\Network\Probe; use Friendica\Protocol\Diaspora; use Friendica\Util\Crypto; use Friendica\Util\Network; +use Friendica\Util\XML; require_once 'include/enotify.php'; require_once 'include/items.php'; @@ -221,7 +222,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) * */ - $res = Network::postURL($dfrn_confirm, $params, null, $redirects, 120); + $res = Network::post($dfrn_confirm, $params, null, $redirects, 120); logger(' Confirm: received data: ' . $res, LOGGER_DATA); @@ -252,7 +253,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) return; } - $xml = Network::parseXmlString($res); + $xml = XML::parseString($res); $status = (int) $xml->status; $message = unxmlify($xml->message); // human readable text of what may have gone wrong. switch ($status) { @@ -493,7 +494,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) $user = dba::selectFirst('user', [], ['nickname' => $node]); if (!DBM::is_result($user)) { $message = L10n::t('No user record found for \'%s\' ', $node); - Network::xmlStatus(3, $message); // failure + Network::xmlExit(3, $message); // failure // NOTREACHED } @@ -503,7 +504,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strstr($my_prvkey, 'PRIVATE KEY')) { $message = L10n::t('Our site encryption key is apparently messed up.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } // verify everything @@ -514,7 +515,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!strlen($decrypted_source_url)) { $message = L10n::t('Empty site URL was provided or URL could not be decrypted by us.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); // NOTREACHED } @@ -530,7 +531,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!DBM::is_result($contact)) { // this is either a bogus confirmation (?) or we deleted the original introduction. $message = L10n::t('Contact record was not found for you on our site.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); return; // NOTREACHED } } @@ -544,7 +545,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (!$foreign_pubkey) { $message = L10n::t('Site public key not available in contact record for URL %s.', $decrypted_source_url); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } $decrypted_dfrn_id = ""; @@ -560,7 +561,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) if (dba::exists('contact', ['dfrn-id' => $decrypted_dfrn_id])) { $message = L10n::t('The ID provided by your system is a duplicate on our system. It should work if you try again.'); - Network::xmlStatus(1, $message); // Birthday paradox - duplicate dfrn-id + Network::xmlExit(1, $message); // Birthday paradox - duplicate dfrn-id // NOTREACHED } @@ -571,7 +572,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { $message = L10n::t('Unable to set your contact credentials on our system.'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } // It's possible that the other person also requested friendship. @@ -626,7 +627,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) ); if (!DBM::is_result($r)) { // indicates schema is messed up or total db failure $message = L10n::t('Unable to update your contact profile details on our system'); - Network::xmlStatus(3, $message); + Network::xmlExit(3, $message); } // Otherwise everything seems to have worked and we are almost done. Yay! @@ -707,7 +708,7 @@ function dfrn_confirm_post(App $a, $handsfree = null) } } } - Network::xmlStatus(0); // Success + Network::xmlExit(0); // Success return; // NOTREACHED ////////////////////// End of this scenario /////////////////////////////////////////////// } diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php index b1af5b3ef..8efb9328d 100644 --- a/mod/dfrn_notify.php +++ b/mod/dfrn_notify.php @@ -49,7 +49,7 @@ function dfrn_notify_post(App $a) { ); if (! DBM::is_result($r)) { logger('dfrn_notify: could not match challenge to dfrn_id ' . $dfrn_id . ' challenge=' . $challenge); - Network::xmlStatus(3, 'Could not match challenge'); + Network::xmlExit(3, 'Could not match challenge'); } $r = q("DELETE FROM `challenge` WHERE `dfrn-id` = '%s' AND `challenge` = '%s'", @@ -71,7 +71,7 @@ function dfrn_notify_post(App $a) { $sql_extra = sprintf(" AND `dfrn-id` = '%s' AND `duplex` = 1 ", dbesc($dfrn_id)); break; default: - Network::xmlStatus(3, 'Invalid direction'); + Network::xmlExit(3, 'Invalid direction'); break; // NOTREACHED } @@ -97,7 +97,7 @@ function dfrn_notify_post(App $a) { if (! DBM::is_result($r)) { logger('dfrn_notify: contact not found for dfrn_id ' . $dfrn_id); - Network::xmlStatus(3, 'Contact not found'); + Network::xmlExit(3, 'Contact not found'); //NOTREACHED } @@ -123,7 +123,7 @@ function dfrn_notify_post(App $a) { // if contact's ssl policy changed, update our links - Network::fixContactSslPolicy($importer, $ssl_policy); + $importer = Contact::updateSslPolicy($importer, $ssl_policy); logger('dfrn_notify: received notify from ' . $importer['name'] . ' for ' . $importer['username']); logger('dfrn_notify: data: ' . $data, LOGGER_DATA); @@ -132,7 +132,7 @@ function dfrn_notify_post(App $a) { // Relationship is dissolved permanently Contact::remove($importer['id']); logger('relationship dissolved : ' . $importer['name'] . ' dissolved ' . $importer['username']); - Network::xmlStatus(0, 'relationship dissolved'); + Network::xmlExit(0, 'relationship dissolved'); } $rino = Config::get('system', 'rino_encrypt'); @@ -146,7 +146,7 @@ function dfrn_notify_post(App $a) { // but only for $remote_rino > 1, because old code did't send rino version if ($rino_remote > 1 && $rino < $rino_remote) { logger("rino version '$rino_remote' is lower than supported '$rino'"); - Network::xmlStatus(0, "rino version '$rino_remote' is lower than supported '$rino'"); + Network::xmlExit(0, "rino version '$rino_remote' is lower than supported '$rino'"); } $rawkey = hex2bin(trim($key)); @@ -176,14 +176,14 @@ function dfrn_notify_post(App $a) { break; default: logger("rino: invalid sent version '$rino_remote'"); - Network::xmlStatus(0, "Invalid sent version '$rino_remote'"); + Network::xmlExit(0, "Invalid sent version '$rino_remote'"); } logger('rino: decrypted data: ' . $data, LOGGER_DATA); } $ret = DFRN::import($data, $importer); - Network::xmlStatus($ret, 'Processed'); + Network::xmlExit($ret, 'Processed'); // NOTREACHED } diff --git a/mod/dfrn_poll.php b/mod/dfrn_poll.php index 5042ed642..3e5aa5b1c 100644 --- a/mod/dfrn_poll.php +++ b/mod/dfrn_poll.php @@ -12,6 +12,7 @@ use Friendica\Module\Login; use Friendica\Protocol\DFRN; use Friendica\Protocol\OStatus; use Friendica\Util\Network; +use Friendica\Util\XML; require_once 'include/items.php'; @@ -99,12 +100,12 @@ function dfrn_poll_init(App $a) ); if (DBM::is_result($r)) { - $s = Network::fetchURL($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); + $s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $my_id . '&type=profile-check'); logger("dfrn_poll: old profile returns " . $s, LOGGER_DATA); if (strlen($s)) { - $xml = Network::parseXmlString($s); + $xml = XML::parseString($s); if ((int) $xml->status === 1) { $_SESSION['authenticated'] = 1; @@ -144,7 +145,7 @@ function dfrn_poll_init(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - Network::xmlStatus(3, 'No ticket'); + Network::xmlExit(3, 'No ticket'); // NOTREACHED } @@ -157,7 +158,7 @@ function dfrn_poll_init(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - Network::xmlStatus(3, 'No profile'); + Network::xmlExit(3, 'No profile'); } $contact = $c[0]; @@ -184,7 +185,7 @@ function dfrn_poll_init(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - Network::xmlStatus(3, 'Bad decryption'); + Network::xmlExit(3, 'Bad decryption'); } header("Content-type: text/xml"); @@ -208,10 +209,10 @@ function dfrn_poll_init(App $a) $r = q("SELECT * FROM `profile_check` WHERE `dfrn_id` = '%s' ORDER BY `expire` DESC", dbesc($dfrn_id)); if (DBM::is_result($r)) { - Network::xmlStatus(1); + Network::xmlExit(1); return; // NOTREACHED } - Network::xmlStatus(0); + Network::xmlExit(0); return; // NOTREACHED } } @@ -236,7 +237,7 @@ function dfrn_poll_post(App $a) dbesc($sec) ); if (!DBM::is_result($r)) { - Network::xmlStatus(3, 'No ticket'); + Network::xmlExit(3, 'No ticket'); // NOTREACHED } @@ -249,7 +250,7 @@ function dfrn_poll_post(App $a) intval($r[0]['cid']) ); if (!DBM::is_result($c)) { - Network::xmlStatus(3, 'No profile'); + Network::xmlExit(3, 'No profile'); } $contact = $c[0]; @@ -276,7 +277,7 @@ function dfrn_poll_post(App $a) if ($final_dfrn_id != $orig_id) { logger('profile_check: ' . $final_dfrn_id . ' != ' . $orig_id, LOGGER_DEBUG); // did not decode properly - cannot trust this site - Network::xmlStatus(3, 'Bad decryption'); + Network::xmlExit(3, 'Bad decryption'); } header("Content-type: text/xml"); @@ -482,7 +483,7 @@ function dfrn_poll_content(App $a) if (($type === 'profile') && (strlen($sec))) { // URL reply if ($dfrn_version < 2.2) { - $s = Network::fetchURL($r[0]['poll'] + $s = Network::fetchUrl($r[0]['poll'] . '?dfrn_id=' . $encrypted_id . '&type=profile-check' . '&dfrn_version=' . DFRN_PROTOCOL_VERSION @@ -490,7 +491,7 @@ function dfrn_poll_content(App $a) . '&sec=' . $sec ); } else { - $s = Network::postURL($r[0]['poll'], [ + $s = Network::post($r[0]['poll'], [ 'dfrn_id' => $encrypted_id, 'type' => 'profile-check', 'dfrn_version' => DFRN_PROTOCOL_VERSION, @@ -521,7 +522,7 @@ function dfrn_poll_content(App $a) logger("dfrn_poll: sec profile: " . $s, LOGGER_DATA); if (strlen($s) && strstr($s, 'cmd); return; // NOTREACHED } - if (!Network::allowedURL($url)) { + if (!Network::isUrlAllowed($url)) { notice(L10n::t('Disallowed profile URL.') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED } - if (Network::blockedURL($url)) { + if (Network::isUrlBlocked($url)) { notice(L10n::t('Blocked domain') . EOL); goaway(System::baseUrl() . '/' . $a->cmd); return; // NOTREACHED diff --git a/mod/dirfind.php b/mod/dirfind.php index f08e723ba..9db4eeb7b 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -46,7 +46,7 @@ function dirfind_content(App $a, $prefix = "") { if (strpos($search,'@') === 0) { $search = substr($search,1); $header = L10n::t('People Search - %s', $search); - if ((valid_email($search) && Network::validateEmail($search)) || + if ((valid_email($search) && Network::isEmailDomainValid($search)) || (substr(normalise_link($search), 0, 7) == "http://")) { $user_data = Probe::uri($search); $discover_user = (in_array($user_data["network"], [NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA])); @@ -178,7 +178,7 @@ function dirfind_content(App $a, $prefix = "") { $p = (($a->pager['page'] != 1) ? '&p=' . $a->pager['page'] : ''); if(strlen(Config::get('system','directory'))) - $x = Network::fetchURL(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); + $x = Network::fetchUrl(get_server().'/lsearch?f=' . $p . '&search=' . urlencode($search)); $j = json_decode($x); } diff --git a/mod/hovercard.php b/mod/hovercard.php index fbe783a51..0bd1d2617 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -91,7 +91,7 @@ function hovercard_content() return $o; } else { - Network::jsonReturnAndDie($profile); + Network::jsonExit($profile); } } diff --git a/mod/install.php b/mod/install.php index ef9f023f5..c5f2e985f 100644 --- a/mod/install.php +++ b/mod/install.php @@ -483,10 +483,10 @@ function check_htaccess(&$checks) { $status = true; $help = ""; if (function_exists('curl_init')) { - $test = Network::fetchURL(System::baseUrl()."/install/testrewrite"); + $test = Network::fetchUrl(System::baseUrl()."/install/testrewrite"); if ($test != "ok") { - $test = Network::fetchURL(normalise_link(System::baseUrl()."/install/testrewrite")); + $test = Network::fetchUrl(normalise_link(System::baseUrl()."/install/testrewrite")); } if ($test != "ok") { diff --git a/mod/item.php b/mod/item.php index ad089adc0..1a512acec 100644 --- a/mod/item.php +++ b/mod/item.php @@ -29,7 +29,6 @@ use Friendica\Network\Probe; use Friendica\Protocol\Diaspora; use Friendica\Protocol\Email; use Friendica\Util\Emailer; -use Friendica\Util\Network; require_once 'include/enotify.php'; require_once 'include/tags.php'; @@ -520,7 +519,7 @@ function item_post(App $a) { // Fold multi-line [code] sequences $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); - $body = Network::scaleExternalImages($body, false); + $body = BBCode::scaleExternalImages($body, false); // Setting the object type if not defined before if (!$objecttype) { diff --git a/mod/match.php b/mod/match.php index ad1e00101..c5e35031f 100644 --- a/mod/match.php +++ b/mod/match.php @@ -59,9 +59,9 @@ function match_content(App $a) } if (strlen(Config::get('system', 'directory'))) { - $x = Network::postURL(get_server().'/msearch', $params); + $x = Network::post(get_server().'/msearch', $params); } else { - $x = Network::postURL(System::baseUrl() . '/msearch', $params); + $x = Network::post(System::baseUrl() . '/msearch', $params); } $j = json_decode($x); diff --git a/mod/nodeinfo.php b/mod/nodeinfo.php index b3d42ab52..026d3f03d 100644 --- a/mod/nodeinfo.php +++ b/mod/nodeinfo.php @@ -247,7 +247,7 @@ function nodeinfo_cron() { // Now trying to register $url = 'http://the-federation.info/register/'.$a->get_hostname(); logger('registering url: '.$url, LOGGER_DEBUG); - $ret = Network::fetchURL($url); + $ret = Network::fetchUrl($url); logger('registering answer: '.$ret, LOGGER_DEBUG); logger('cron_end'); diff --git a/mod/notifications.php b/mod/notifications.php index 06624f3c0..067e95422 100644 --- a/mod/notifications.php +++ b/mod/notifications.php @@ -139,7 +139,7 @@ function notifications_content(App $a) { // Json output if (intval($json) === 1) { - Network::jsonReturnAndDie($notifs); + Network::jsonExit($notifs); } $notif_tpl = get_markup_template('notifications.tpl'); diff --git a/mod/oexchange.php b/mod/oexchange.php index 79414a7f6..feca39d35 100644 --- a/mod/oexchange.php +++ b/mod/oexchange.php @@ -40,7 +40,7 @@ function oexchange_content(App $a) { $tags = (((x($_REQUEST,'tags')) && strlen($_REQUEST['tags'])) ? '&tags=' . urlencode(notags(trim($_REQUEST['tags']))) : ''); - $s = Network::fetchURL(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); + $s = Network::fetchUrl(System::baseUrl() . '/parse_url?f=&url=' . $url . $title . $description . $tags); if (! strlen($s)) { return; diff --git a/mod/ostatus_subscribe.php b/mod/ostatus_subscribe.php index 81eced22e..07f4647e6 100644 --- a/mod/ostatus_subscribe.php +++ b/mod/ostatus_subscribe.php @@ -41,7 +41,7 @@ function ostatus_subscribe_content(App $a) { $api = $contact["baseurl"]."/api/"; // Fetching friends - $data = Network::zFetchURL($api."statuses/friends.json?screen_name=".$contact["nick"]); + $data = Network::curl($api."statuses/friends.json?screen_name=".$contact["nick"]); if (!$data["success"]) { return $o.L10n::t("Couldn't fetch friends for contact."); diff --git a/mod/parse_url.php b/mod/parse_url.php index f1214e160..ea860f6d3 100644 --- a/mod/parse_url.php +++ b/mod/parse_url.php @@ -61,7 +61,7 @@ function parse_url_content(App $a) { // the URL with the corresponding BBCode media tag $redirects = 0; // Fetch the header of the URL - $result = Network::zFetchURL($url, false, $redirects, ["novalidate" => true, "nobody" => true]); + $result = Network::curl($url, false, $redirects, ["novalidate" => true, "nobody" => true]); if($result["success"]) { // Convert the header fields into an array $hdrs = []; diff --git a/mod/proxy.php b/mod/proxy.php index 149718591..7efc0ffba 100644 --- a/mod/proxy.php +++ b/mod/proxy.php @@ -162,7 +162,7 @@ function proxy_init(App $a) { // It shouldn't happen but it does - spaces in URL $_REQUEST['url'] = str_replace(' ', '+', $_REQUEST['url']); $redirects = 0; - $img_str = Network::fetchURL($_REQUEST['url'], true, $redirects, 10); + $img_str = Network::fetchUrl($_REQUEST['url'], true, $redirects, 10); $tempfile = tempnam(get_temppath(), 'cache'); file_put_contents($tempfile, $img_str); diff --git a/mod/pubsubhubbub.php b/mod/pubsubhubbub.php index af7172cee..210bc6efb 100644 --- a/mod/pubsubhubbub.php +++ b/mod/pubsubhubbub.php @@ -110,7 +110,7 @@ function pubsubhubbub_init(App $a) { // we don't actually enforce the lease time because GNU // Social/StatusNet doesn't honour it (yet) - $body = Network::fetchURL($hub_callback . "?" . $params); + $body = Network::fetchUrl($hub_callback . "?" . $params); $ret = $a->get_curl_code(); // give up if the HTTP return code wasn't a success (2xx) diff --git a/mod/settings.php b/mod/settings.php index a6ffd99e9..2ea6d5334 100644 --- a/mod/settings.php +++ b/mod/settings.php @@ -536,7 +536,7 @@ function settings_post(App $a) // If openid has changed or if there's an openid but no openidserver, try and discover it. if ($openid != $a->user['openid'] || (strlen($openid) && (!strlen($openidserver)))) { - if (Network::validateURL($openid)) { + if (Network::isUrlValid($openid)) { logger('updating openidserver'); require_once 'library/openid.php'; $open_id_obj = new LightOpenID; diff --git a/mod/smilies.php b/mod/smilies.php index 232ef91d0..19f0152ef 100644 --- a/mod/smilies.php +++ b/mod/smilies.php @@ -18,7 +18,7 @@ function smilies_content(App $a) for ($i = 0; $i < count($tmp['texts']); $i++) { $results[] = ['text' => $tmp['texts'][$i], 'icon' => $tmp['icons'][$i]]; } - Network::jsonReturnAndDie($results); + Network::jsonExit($results); } else { return Smilies::replace('', true); } diff --git a/spec/dfrn2_contact_confirmation.svg b/spec/dfrn2_contact_confirmation.svg index 53c2b6c19..fc5b33162 100644 --- a/spec/dfrn2_contact_confirmation.svg +++ b/spec/dfrn2_contact_confirmation.svg @@ -69,7 +69,7 @@ text { font:12px Dialog; } getting transmitted (if $aes_allow -> encrypt the the public key) -> add duplex state and page-flags to the params -> send params to Bobs dfrn_confirm page ($res = -Network::postURL($dfrn_confirm,$params); +Network::post($dfrn_confirm,$params); dfrn_confirm_post() diff --git a/spec/dfrn2_contact_request.svg b/spec/dfrn2_contact_request.svg index 23b040985..cc78be55c 100644 --- a/spec/dfrn2_contact_request.svg +++ b/spec/dfrn2_contact_request.svg @@ -93,9 +93,9 @@ text { font:12px Dialog; } - create a contact for Karen in the contact table with the scraped data with blocked = 1 and pending = 1 (Karens pubkey becomes the contact site-pubkey) -- Network::fetchURL($dfrn_request . '?confirm_key=' . +- Network::fetchUrl($dfrn_request . '?confirm_key=' . $confirm_key); -- Network::fetchURL(http://karenhomepage.com/dfrn_request? +- Network::fetchUrl(http://karenhomepage.com/dfrn_request? confirm_key=”ABC123”) diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 1ddd3e65c..170ee7ba2 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -78,7 +78,7 @@ class OEmbed if (!in_array($ext, $noexts)) { // try oembed autodiscovery $redirects = 0; - $html_text = Network::fetchURL($embedurl, false, $redirects, 15, "text/*"); + $html_text = Network::fetchUrl($embedurl, false, $redirects, 15, "text/*"); if ($html_text) { $dom = @DOMDocument::loadHTML($html_text); if ($dom) { @@ -86,13 +86,13 @@ class OEmbed $entries = $xpath->query("//link[@type='application/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } $entries = $xpath->query("//link[@type='text/json+oembed']"); foreach ($entries as $e) { $href = $e->getAttributeNode("href")->nodeValue; - $txt = Network::fetchURL($href . '&maxwidth=' . $a->videowidth); + $txt = Network::fetchUrl($href . '&maxwidth=' . $a->videowidth); break; } } @@ -312,7 +312,7 @@ class OEmbed $allowed = explode(',', $str_allowed); - return Network::allowedDomain($domain, $allowed); + return Network::isDomainAllowed($domain, $allowed); } public static function getHTML($url, $title = null) diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index 664be933a..5760533d3 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -6,7 +6,10 @@ namespace Friendica\Content\Text; use Friendica\App; use Friendica\Content\Text\Plaintext; +use Friencica\Core\Config; +use Friendica\Core\L10n; use Friendica\Core\PConfig; +use Friendica\Core\System; use Friendica\Object\Image; use Friendica\Util\ParseUrl; @@ -475,4 +478,74 @@ class BBCode return($post); } + + public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) + { + // Suppress "view full size" + if (intval(Config::get('system', 'no_view_full_size'))) { + $include_link = false; + } + + // Picture addresses can contain special characters + $s = htmlspecialchars_decode($srctext); + + $matches = null; + $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); + if ($c) { + foreach ($matches as $mtch) { + logger('scale_external_image: ' . $mtch[1]); + + $hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3)); + if (stristr($mtch[1], $hostname)) { + continue; + } + + // $scale_replace, if passed, is an array of two elements. The + // first is the name of the full-size image. The second is the + // name of a remote, scaled-down version of the full size image. + // This allows Friendica to display the smaller remote image if + // one exists, while still linking to the full-size image + if ($scale_replace) { + $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]); + } else { + $scaled = $mtch[1]; + } + $i = self::fetchURL($scaled); + if (! $i) { + return $srctext; + } + + // guess mimetype from headers or filename + $type = Image::guessType($mtch[1], true); + + if ($i) { + $Image = new Image($i, $type); + if ($Image->isValid()) { + $orig_width = $Image->getWidth(); + $orig_height = $Image->getHeight(); + + if ($orig_width > 640 || $orig_height > 640) { + $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], + '[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' + . "\n" . (($include_link) + ? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n" + : ''), + $s + ); + logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); + } + } + } + } + } + + // replace the special char encoding + $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); + return $s; + } } diff --git a/src/Core/NotificationsManager.php b/src/Core/NotificationsManager.php index 654ed5cc4..7c2760a85 100644 --- a/src/Core/NotificationsManager.php +++ b/src/Core/NotificationsManager.php @@ -13,7 +13,7 @@ use Friendica\Core\System; use Friendica\Database\DBM; use Friendica\Model\Contact; use Friendica\Model\Profile; -use Friendica\Util\Network; +use Friendica\Util\XML; require_once 'include/dba.php'; require_once 'include/html2plain.php'; @@ -338,7 +338,7 @@ class NotificationsManager extends BaseObject case ACTIVITY_FRIEND: $xmlhead = "<" . "?xml version='1.0' encoding='UTF-8' ?" . ">"; - $obj = Network::parseXmlString($xmlhead . $it['object']); + $obj = XML::parseString($xmlhead . $it['object']); $it['fname'] = $obj->title; $notif = [ diff --git a/src/Core/Worker.php b/src/Core/Worker.php index 11146e4a2..ee313bef0 100644 --- a/src/Core/Worker.php +++ b/src/Core/Worker.php @@ -888,7 +888,7 @@ class Worker } $url = System::baseUrl()."/worker"; - Network::fetchURL($url, false, $redirects, 1); + Network::fetchUrl($url, false, $redirects, 1); } /** diff --git a/src/Model/Contact.php b/src/Model/Contact.php index bda5a925f..ba9536b39 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -1132,12 +1132,12 @@ class Contact extends BaseObject // remove ajax junk, e.g. Twitter $url = str_replace('/#!/', '/', $url); - if (!Network::allowedURL($url)) { + if (!Network::isUrlAllowed($url)) { $result['message'] = L10n::t('Disallowed profile URL.'); return $result; } - if (Network::blockedURL($url)) { + if (Network::isUrlBlocked($url)) { $result['message'] = L10n::t('Blocked domain'); return $result; } @@ -1321,4 +1321,37 @@ class Contact extends BaseObject $result['success'] = true; return $result; } + + public static function updateSslPolicy($contact, $new_policy) + { + $ssl_changed = false; + if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) { + $ssl_changed = true; + $contact['url'] = str_replace('https:', 'http:', $contact['url']); + $contact['request'] = str_replace('https:', 'http:', $contact['request']); + $contact['notify'] = str_replace('https:', 'http:', $contact['notify']); + $contact['poll'] = str_replace('https:', 'http:', $contact['poll']); + $contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']); + $contact['poco'] = str_replace('https:', 'http:', $contact['poco']); + } + + if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) { + $ssl_changed = true; + $contact['url'] = str_replace('http:', 'https:', $contact['url']); + $contact['request'] = str_replace('http:', 'https:', $contact['request']); + $contact['notify'] = str_replace('http:', 'https:', $contact['notify']); + $contact['poll'] = str_replace('http:', 'https:', $contact['poll']); + $contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']); + $contact['poco'] = str_replace('http:', 'https:', $contact['poco']); + } + + if ($ssl_changed) { + $fields = ['url' => $contact['url'], 'request' => $contact['request'], + 'notify' => $contact['notify'], 'poll' => $contact['poll'], + 'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; + dba::update('contact', $fields, ['id' => $contact['id']]); + } + + return $contact; + } } diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 099111031..0d0969ca0 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -568,7 +568,7 @@ class GContact $done[] = System::baseUrl() . '/poco'; if (strlen(Config::get('system', 'directory'))) { - $x = Network::fetchURL(get_server()."/pubsites"); + $x = Network::fetchUrl(get_server()."/pubsites"); if ($x) { $j = json_decode($x); if ($j->entries) { @@ -980,7 +980,7 @@ class GContact $url = $server."/main/statistics"; - $result = Network::zFetchURL($url); + $result = Network::curl($url); if (!$result["success"]) { return false; } diff --git a/src/Model/Photo.php b/src/Model/Photo.php index 23d893c92..fc6e60a9c 100644 --- a/src/Model/Photo.php +++ b/src/Model/Photo.php @@ -102,7 +102,7 @@ class Photo $photo_failure = false; $filename = basename($image_url); - $img_str = Network::fetchURL($image_url, true); + $img_str = Network::fetchUrl($image_url, true); if ($quit_on_error && ($img_str == "")) { return false; diff --git a/src/Model/Profile.php b/src/Model/Profile.php index c77b6bbe4..df53b5d80 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -964,7 +964,7 @@ class Profile public static function zrlInit(App $a) { $my_url = self::getMyURL(); - $my_url = Network::validateURL($my_url); + $my_url = Network::isUrlValid($my_url); if ($my_url) { // Is it a DDoS attempt? // The check fetches the cached value from gprobe to reduce the load for this system diff --git a/src/Model/User.php b/src/Model/User.php index c767ec1b6..4eba5112a 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -281,7 +281,7 @@ class User if (!x($username) || !x($email) || !x($nickname)) { if ($openid_url) { - if (!Network::validateURL($openid_url)) { + if (!Network::isUrlValid($openid_url)) { throw new Exception(L10n::t('Invalid OpenID url')); } $_SESSION['register'] = 1; @@ -304,7 +304,7 @@ class User throw new Exception(L10n::t('Please enter the required information.')); } - if (!Network::validateURL($openid_url)) { + if (!Network::isUrlValid($openid_url)) { $openid_url = ''; } @@ -329,11 +329,11 @@ class User } } - if (!Network::allowedEmail($email)) { + if (!Network::isEmailDomainAllowed($email)) { throw new Exception(L10n::t('Your email domain is not among those allowed on this site.')); } - if (!valid_email($email) || !Network::validateEmail($email)) { + if (!valid_email($email) || !Network::isEmailDomainValid($email)) { throw new Exception(L10n::t('Not a valid email address.')); } @@ -460,7 +460,7 @@ class User // if we have no OpenID photo try to look up an avatar if (!strlen($photo)) { - $photo = Network::avatarImg($email); + $photo = Network::lookupAvatarByEmail($email); } // unless there is no avatar-addon loaded @@ -468,7 +468,7 @@ class User $photo_failure = false; $filename = basename($photo); - $img_str = Network::fetchURL($photo, true); + $img_str = Network::fetchUrl($photo, true); // guess mimetype from headers or filename $type = Image::guessType($photo, true); diff --git a/src/Module/Login.php b/src/Module/Login.php index c6396a414..e080663d7 100644 --- a/src/Module/Login.php +++ b/src/Module/Login.php @@ -60,7 +60,7 @@ class Login extends BaseModule $openid_url = trim($_POST['openid_url'] ? : $_POST['username']); // if it's an email address or doesn't resolve to a URL, fail. - if ($noid || strpos($openid_url, '@') || !Network::validateURL($openid_url)) { + if ($noid || strpos($openid_url, '@') || !Network::isUrlValid($openid_url)) { notice(L10n::t('Login failed.') . EOL); goaway(self::getApp()->get_baseurl()); // NOTREACHED diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 79b384003..f7c3b84fd 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -107,21 +107,21 @@ class Probe logger("Probing for ".$host, LOGGER_DEBUG); - $ret = Network::zFetchURL($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::curl($ssl_url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['success']) { $xml = $ret['body']; - $xrd = Network::parseXmlString($xml, false); + $xrd = XML::parseString($xml, false); $host_url = 'https://'.$host; } if (!is_object($xrd)) { - $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); + $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => 'application/xrd+xml']); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { logger("Probing timeout for ".$url, LOGGER_DEBUG); return false; } $xml = $ret['body']; - $xrd = Network::parseXmlString($xml, false); + $xrd = XML::parseString($xml, false); $host_url = 'http://'.$host; } if (!is_object($xrd)) { @@ -331,7 +331,7 @@ class Probe } if (x($data, "photo")) { - $data["baseurl"] = Network::matchingURL(normalise_link($data["baseurl"]), normalise_link($data["photo"])); + $data["baseurl"] = Network::getUrlMatch(normalise_link($data["baseurl"]), normalise_link($data["photo"])); } else { $data["photo"] = System::baseUrl().'/images/person-175.jpg'; } @@ -692,7 +692,7 @@ class Probe $xrd_timeout = Config::get('system', 'xrd_timeout', 20); $redirects = 0; - $ret = Network::zFetchURL($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); + $ret = Network::curl($url, false, $redirects, ['timeout' => $xrd_timeout, 'accept_content' => $type]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -708,7 +708,7 @@ class Probe } // If it is not JSON, maybe it is XML - $xrd = Network::parseXmlString($data, false); + $xrd = XML::parseString($data, false); if (!is_object($xrd)) { logger("No webfinger data retrievable for ".$url, LOGGER_DEBUG); return false; @@ -759,7 +759,7 @@ class Probe */ private static function pollNoscrape($noscrape_url, $data) { - $ret = Network::zFetchURL($noscrape_url); + $ret = Network::curl($noscrape_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -993,7 +993,7 @@ class Probe */ private static function pollHcard($hcard_url, $data, $dfrn = false) { - $ret = Network::zFetchURL($hcard_url); + $ret = Network::curl($hcard_url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1232,7 +1232,7 @@ class Probe $pubkey = substr($pubkey, 5); } } elseif (normalise_link($pubkey) == 'http://') { - $ret = Network::zFetchURL($pubkey); + $ret = Network::curl($pubkey); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1264,7 +1264,7 @@ class Probe } // Fetch all additional data from the feed - $ret = Network::zFetchURL($data["poll"]); + $ret = Network::curl($data["poll"]); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1448,7 +1448,7 @@ class Probe */ private static function feed($url, $probe = true) { - $ret = Network::zFetchURL($url); + $ret = Network::curl($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return false; } @@ -1509,7 +1509,7 @@ class Probe */ private static function mail($uri, $uid) { - if (!Network::validateEmail($uri)) { + if (!Network::isEmailDomainValid($uri)) { return false; } @@ -1543,7 +1543,7 @@ class Probe $data["network"] = NETWORK_MAIL; $data["name"] = substr($uri, 0, strpos($uri, '@')); $data["nick"] = $data["name"]; - $data["photo"] = Network::avatarImg($uri); + $data["photo"] = Network::lookupAvatarByEmail($uri); $data["url"] = 'mailto:'.$uri; $data["notify"] = 'smtp '.random_string(); $data["poll"] = 'email '.random_string(); diff --git a/src/Object/Image.php b/src/Object/Image.php index 84c462205..d8d6dafc3 100644 --- a/src/Object/Image.php +++ b/src/Object/Image.php @@ -774,7 +774,7 @@ class Image $data = Cache::get($url); if (is_null($data) || !$data || !is_array($data)) { - $img_str = Network::fetchURL($url, true, $redirects, 4); + $img_str = Network::fetchUrl($url, true, $redirects, 4); $filesize = strlen($img_str); if (function_exists("getimagesizefromstring")) { diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 2901796db..59141576b 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -793,7 +793,7 @@ class DFRN if ($activity) { $entry = $doc->createElement($element); - $r = Network::parseXmlString($activity, false); + $r = XML::parseString($activity, false); if (!$r) { return false; } @@ -816,7 +816,7 @@ class DFRN $r->link = preg_replace('/\/', '', $r->link); // XML does need a single element as root element so we add a dummy element here - $data = Network::parseXmlString("" . $r->link . "", false); + $data = XML::parseString("" . $r->link . "", false); if (is_object($data)) { foreach ($data->link as $link) { $attributes = []; @@ -1187,7 +1187,7 @@ class DFRN logger('dfrn_deliver: ' . $url); - $ret = Network::zFetchURL($url); + $ret = Network::curl($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { return -2; // timed out @@ -1212,7 +1212,7 @@ class DFRN return 3; } - $res = Network::parseXmlString($xml); + $res = XML::parseString($xml); if ((intval($res->status) != 0) || (! strlen($res->challenge)) || (! strlen($res->dfrn_id))) { return (($res->status) ? $res->status : 3); @@ -1333,7 +1333,7 @@ class DFRN logger('dfrn_deliver: ' . "SENDING: " . print_r($postvars, true), LOGGER_DATA); - $xml = Network::postURL($contact['notify'], $postvars); + $xml = Network::post($contact['notify'], $postvars); logger('dfrn_deliver: ' . "RECEIVED: " . $xml, LOGGER_DATA); @@ -1357,7 +1357,7 @@ class DFRN Contact::unmarkForArchival($contact); } - $res = Network::parseXmlString($xml); + $res = XML::parseString($xml); if (!isset($res->status)) { return -11; @@ -2188,7 +2188,7 @@ class DFRN if (!$verb) { return; } - $xo = Network::parseXmlString($item["object"], false); + $xo = XML::parseString($item["object"], false); if (($xo->type == ACTIVITY_OBJ_PERSON) && ($xo->id)) { // somebody was poked/prodded. Was it me? @@ -2310,8 +2310,8 @@ class DFRN } if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = Network::parseXmlString($item["object"], false); - $xt = Network::parseXmlString($item["target"], false); + $xo = XML::parseString($item["object"], false); + $xt = XML::parseString($item["target"], false); if ($xt->type == ACTIVITY_OBJ_NOTE) { $r = q( @@ -2518,7 +2518,7 @@ class DFRN $item["object"] = self::transformActivity($xpath, $object, "object"); if (trim($item["object"]) != "") { - $r = Network::parseXmlString($item["object"], false); + $r = XML::parseString($item["object"], false); if (isset($r->type)) { $item["object-type"] = $r->type; } @@ -2787,8 +2787,8 @@ class DFRN } if (($item["verb"] == ACTIVITY_TAG) && ($item["object-type"] == ACTIVITY_OBJ_TAGTERM)) { - $xo = Network::parseXmlString($item["object"], false); - $xt = Network::parseXmlString($item["target"], false); + $xo = XML::parseString($item["object"], false); + $xt = XML::parseString($item["target"], false); if ($xt->type == ACTIVITY_OBJ_NOTE) { $i = q( diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index b87aabfb4..a6c74537d 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -186,7 +186,7 @@ class Diaspora */ private static function verifyMagicEnvelope($envelope) { - $basedom = Network::parseXmlString($envelope); + $basedom = XML::parseString($envelope); if (!is_object($basedom)) { logger("Envelope is no XML file"); @@ -296,7 +296,7 @@ class Diaspora $xml = $raw; } - $basedom = Network::parseXmlString($xml); + $basedom = XML::parseString($xml); if (!is_object($basedom)) { logger('Received data does not seem to be an XML. Discarding. '.$xml); @@ -347,7 +347,7 @@ class Diaspora public static function decode($importer, $xml) { $public = false; - $basedom = Network::parseXmlString($xml); + $basedom = XML::parseString($xml); if (!is_object($basedom)) { logger("XML is not parseable."); @@ -381,7 +381,7 @@ class Diaspora $decrypted = self::aesDecrypt($outer_key, $outer_iv, $ciphertext); logger('decrypted: '.$decrypted, LOGGER_DEBUG); - $idom = Network::parseXmlString($decrypted); + $idom = XML::parseString($decrypted); $inner_iv = base64_decode($idom->iv); $inner_aes_key = base64_decode($idom->aes_key); @@ -631,7 +631,7 @@ class Diaspora */ private static function validPosting($msg) { - $data = Network::parseXmlString($msg["message"]); + $data = XML::parseString($msg["message"]); if (!is_object($data)) { logger("No valid XML ".$msg["message"], LOGGER_DEBUG); @@ -1257,7 +1257,7 @@ class Diaspora logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $envelope = Network::fetchURL($source_url); + $envelope = Network::fetchUrl($source_url); if ($envelope) { logger("Envelope was fetched.", LOGGER_DEBUG); $x = self::verifyMagicEnvelope($envelope); @@ -1275,13 +1275,13 @@ class Diaspora $source_url = $server."/p/".urlencode($guid).".xml"; logger("Fetch post from ".$source_url, LOGGER_DEBUG); - $x = Network::fetchURL($source_url); + $x = Network::fetchUrl($source_url); if (!$x) { return false; } } - $source_xml = Network::parseXmlString($x); + $source_xml = XML::parseString($x); if (!is_object($source_xml)) { return false; @@ -3229,7 +3229,7 @@ class Diaspora if (!intval(Config::get("system", "diaspora_test"))) { $content_type = (($public_batch) ? "application/magic-envelope+xml" : "application/json"); - Network::postURL($dest_url."/", $envelope, ["Content-Type: ".$content_type]); + Network::post($dest_url."/", $envelope, ["Content-Type: ".$content_type]); $return_code = $a->get_curl_code(); } else { logger("test_mode"); diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index e728afa24..cc0915472 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -244,7 +244,7 @@ class Feed { $orig_plink = $item["plink"]; - $item["plink"] = Network::originalURL($item["plink"]); + $item["plink"] = Network::finalUrl($item["plink"]); $item["parent-uri"] = $item["uri"]; diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index 87b894a71..e41f3addc 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -726,7 +726,7 @@ class OStatus self::$conv_list[$conversation] = true; - $conversation_data = Network::zFetchURL($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $conversation_data = Network::curl($conversation, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$conversation_data['success']) { return; @@ -754,7 +754,7 @@ class OStatus } } if ($file != '') { - $conversation_atom = Network::zFetchURL($attribute['href']); + $conversation_atom = Network::curl($attribute['href']); if ($conversation_atom['success']) { $xml = $conversation_atom['body']; @@ -870,7 +870,7 @@ class OStatus return; } - $self_data = Network::zFetchURL($self); + $self_data = Network::curl($self); if (!$self_data['success']) { return; @@ -915,7 +915,7 @@ class OStatus } $stored = false; - $related_data = Network::zFetchURL($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); + $related_data = Network::curl($related, false, $redirects, ['accept_content' => 'application/atom+xml, text/html']); if (!$related_data['success']) { return; @@ -946,7 +946,7 @@ class OStatus } } if ($atom_file != '') { - $related_atom = Network::zFetchURL($atom_file); + $related_atom = Network::curl($atom_file); if ($related_atom['success']) { logger('Fetched XML for URI '.$related_uri, LOGGER_DEBUG); @@ -958,7 +958,7 @@ class OStatus // Workaround for older GNU Social servers if (($xml == '') && strstr($related, '/notice/')) { - $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); + $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround to fetch XML for URI '.$related_uri, LOGGER_DEBUG); @@ -969,7 +969,7 @@ class OStatus // Even more worse workaround for GNU Social ;-) if ($xml == '') { $related_guess = OStatus::convertHref($related_uri); - $related_atom = Network::zFetchURL(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); + $related_atom = Network::curl(str_replace('/notice/', '/api/statuses/show/', $related_guess).'.atom'); if ($related_atom['success']) { logger('GNU Social workaround 2 to fetch XML for URI '.$related_uri, LOGGER_DEBUG); diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 9ed48b1cf..f2def21ec 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -85,7 +85,7 @@ class PortableContact logger('load: ' . $url, LOGGER_DEBUG); - $s = Network::fetchURL($url); + $s = Network::fetchUrl($url); logger('load: returns ' . $s, LOGGER_DATA); @@ -287,7 +287,7 @@ class PortableContact } // Fetch the host-meta to check if this really is a server - $serverret = Network::zFetchURL($server_url."/.well-known/host-meta"); + $serverret = Network::curl($server_url."/.well-known/host-meta"); if (!$serverret["success"]) { return ""; } @@ -366,7 +366,7 @@ class PortableContact $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", dbesc(normalise_link($server_url))); if ($server) { - $noscraperet = Network::zFetchURL($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); + $noscraperet = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); if ($noscraperet["success"] && ($noscraperet["body"] != "")) { $noscrape = json_decode($noscraperet["body"], true); @@ -480,7 +480,7 @@ class PortableContact GContact::update($contact); - $feedret = Network::zFetchURL($data["poll"]); + $feedret = Network::curl($data["poll"]); if (!$feedret["success"]) { $fields = ['last_failure' => datetime_convert()]; @@ -631,7 +631,7 @@ class PortableContact */ private static function fetchNodeinfo($server_url) { - $serverret = Network::zFetchURL($server_url."/.well-known/nodeinfo"); + $serverret = Network::curl($server_url."/.well-known/nodeinfo"); if (!$serverret["success"]) { return false; } @@ -663,7 +663,7 @@ class PortableContact return false; } - $serverret = Network::zFetchURL($nodeinfo_url); + $serverret = Network::curl($nodeinfo_url); if (!$serverret["success"]) { return false; } @@ -872,7 +872,7 @@ class PortableContact $server_url = str_replace("http://", "https://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout. // But we want to make sure to only quit if we are mostly sure that this server url fits. @@ -889,7 +889,7 @@ class PortableContact $server_url = str_replace("https://", "http://", $server_url); // We set the timeout to 20 seconds since this operation should be done in no time if the server was vital - $serverret = Network::zFetchURL($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); + $serverret = Network::curl($server_url."/.well-known/host-meta", false, $redirects, ['timeout' => 20]); // Quit if there is a timeout if ($serverret['errno'] == CURLE_OPERATION_TIMEDOUT) { @@ -925,7 +925,7 @@ class PortableContact // Look for poco if (!$failure) { - $serverret = Network::zFetchURL($server_url."/poco"); + $serverret = Network::curl($server_url."/poco"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->totalResults)) { @@ -951,7 +951,7 @@ class PortableContact if (!$failure) { // Test for Diaspora, Hubzilla, Mastodon or older Friendica servers - $serverret = Network::zFetchURL($server_url); + $serverret = Network::curl($server_url); if (!$serverret["success"] || ($serverret["body"] == "")) { $failure = true; @@ -990,7 +990,7 @@ class PortableContact // Test for Statusnet // Will also return data for Friendica and GNU Social - but it will be overwritten later // The "not implemented" is a special treatment for really, really old Friendica versions - $serverret = Network::zFetchURL($server_url."/api/statusnet/version.json"); + $serverret = Network::curl($server_url."/api/statusnet/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "StatusNet"; @@ -1001,7 +1001,7 @@ class PortableContact } // Test for GNU Social - $serverret = Network::zFetchURL($server_url."/api/gnusocial/version.json"); + $serverret = Network::curl($server_url."/api/gnusocial/version.json"); if ($serverret["success"] && ($serverret["body"] != '{"error":"not implemented"}') && ($serverret["body"] != '') && (strlen($serverret["body"]) < 30)) { $platform = "GNU Social"; @@ -1013,7 +1013,7 @@ class PortableContact // Test for Mastodon $orig_version = $version; - $serverret = Network::zFetchURL($server_url."/api/v1/instance"); + $serverret = Network::curl($server_url."/api/v1/instance"); if ($serverret["success"] && ($serverret["body"] != '')) { $data = json_decode($serverret["body"]); @@ -1036,7 +1036,7 @@ class PortableContact if (!$failure) { // Test for Hubzilla and Red - $serverret = Network::zFetchURL($server_url."/siteinfo.json"); + $serverret = Network::curl($server_url."/siteinfo.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->url)) { @@ -1064,7 +1064,7 @@ class PortableContact } } else { // Test for Hubzilla, Redmatrix or Friendica - $serverret = Network::zFetchURL($server_url."/api/statusnet/config.json"); + $serverret = Network::curl($server_url."/api/statusnet/config.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); if (isset($data->site->server)) { @@ -1119,7 +1119,7 @@ class PortableContact // Query statistics.json. Optional package for Diaspora, Friendica and Redmatrix if (!$failure) { - $serverret = Network::zFetchURL($server_url."/statistics.json"); + $serverret = Network::curl($server_url."/statistics.json"); if ($serverret["success"]) { $data = json_decode($serverret["body"]); @@ -1181,10 +1181,10 @@ class PortableContact // Check for noscrape // Friendica servers could be detected as OStatus servers if (!$failure && in_array($network, [NETWORK_DFRN, NETWORK_OSTATUS])) { - $serverret = Network::zFetchURL($server_url."/friendica/json"); + $serverret = Network::curl($server_url."/friendica/json"); if (!$serverret["success"]) { - $serverret = Network::zFetchURL($server_url."/friendika/json"); + $serverret = Network::curl($server_url."/friendika/json"); } if ($serverret["success"]) { @@ -1294,7 +1294,7 @@ class PortableContact */ private static function fetchServerlist($poco) { - $serverret = Network::zFetchURL($poco."/@server"); + $serverret = Network::curl($poco."/@server"); if (!$serverret["success"]) { return; } @@ -1343,7 +1343,7 @@ class PortableContact if (!empty($accesstoken)) { $api = 'https://instances.social/api/1.0/instances/list?count=0'; $header = ['Authorization: Bearer '.$accesstoken]; - $serverdata = Network::zFetchURL($api, false, $redirects, ['headers' => $header]); + $serverdata = Network::curl($api, false, $redirects, ['headers' => $header]); if ($serverdata['success']) { $servers = json_decode($serverdata['body']); foreach ($servers->instances as $server) { @@ -1360,7 +1360,7 @@ class PortableContact //if (!Config::get('system','ostatus_disabled')) { // $serverdata = "http://gstools.org/api/get_open_instances/"; - // $result = Network::zFetchURL($serverdata); + // $result = Network::curl($serverdata); // if ($result["success"]) { // $servers = json_decode($result["body"]); @@ -1389,7 +1389,7 @@ class PortableContact logger("Fetch all users from the server ".$server["url"], LOGGER_DEBUG); - $retdata = Network::zFetchURL($url); + $retdata = Network::curl($url); if ($retdata["success"]) { $data = json_decode($retdata["body"]); @@ -1408,7 +1408,7 @@ class PortableContact $success = false; - $retdata = Network::zFetchURL($url); + $retdata = Network::curl($url); if ($retdata["success"]) { logger("Fetch all global contacts from the server ".$server["nurl"], LOGGER_DEBUG); $success = self::discoverServer(json_decode($retdata["body"])); @@ -1493,7 +1493,7 @@ class PortableContact // Fetch all contacts from a given user from the other server $url = $server["poco"]."/".$username."/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation"; - $retdata = Network::zFetchURL($url); + $retdata = Network::curl($url); if ($retdata["success"]) { self::discoverServer(json_decode($retdata["body"]), 3); } diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index f49225021..f30488ce1 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -51,7 +51,7 @@ class Salmon $ret[$x] = substr($ret[$x], 5); } } elseif (normalise_link($ret[$x]) == 'http://') { - $ret[$x] = Network::fetchURL($ret[$x]); + $ret[$x] = Network::fetchUrl($ret[$x]); } } } @@ -133,7 +133,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - Network::postURL($url, $salmon, [ + Network::post($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) ]); @@ -159,7 +159,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - Network::postURL($url, $salmon, [ + Network::post($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon) ]); @@ -182,7 +182,7 @@ class Salmon $salmon = XML::fromArray($xmldata, $xml, false, $namespaces); // slap them - Network::postURL($url, $salmon, [ + Network::post($url, $salmon, [ 'Content-type: application/magic-envelope+xml', 'Content-length: ' . strlen($salmon)]); $return_code = $a->get_curl_code(); diff --git a/src/Util/ExAuth.php b/src/Util/ExAuth.php index 35e812a5c..a6851c385 100644 --- a/src/Util/ExAuth.php +++ b/src/Util/ExAuth.php @@ -181,7 +181,7 @@ class ExAuth $url = ($ssl ? 'https' : 'http') . '://' . $host . '/noscrape/' . $user; - $data = Network::zFetchURL($url); + $data = Network::curl($url); if (!is_array($data)) { return false; diff --git a/src/Util/Network.php b/src/Util/Network.php index 9cd3cb719..b013f65a3 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -11,7 +11,6 @@ use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Network\Probe; use Friendica\Object\Image; -use Friendica\Util\Network; use Friendica\Util\XML; require_once 'library/slinky.php'; @@ -35,9 +34,9 @@ class Network * * @return string The fetched content */ - public static function fetchURL($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) + public static function fetchUrl($url, $binary = false, &$redirects = 0, $timeout = 0, $accept_content = null, $cookiejar = 0) { - $ret = self::zFetchURL( + $ret = self::curl( $url, $binary, $redirects, @@ -72,7 +71,7 @@ class Network * string 'header' => HTTP headers * string 'body' => fetched content */ - public static function zFetchURL($url, $binary = false, &$redirects = 0, $opts = []) + public static function curl($url, $binary = false, &$redirects = 0, $opts = []) { $ret = ['return_code' => 0, 'success' => false, 'header' => '', 'info' => '', 'body' => '']; @@ -80,7 +79,7 @@ class Network $a = get_app(); - if (self::blockedURL($url)) { + if (self::isUrlBlocked($url)) { logger('z_fetch_url: domain of ' . $url . ' is blocked', LOGGER_DATA); return $ret; } @@ -278,11 +277,11 @@ class Network * * @return string The content */ - public static function postURL($url, $params, $headers = null, &$redirects = 0, $timeout = 0) + public static function post($url, $params, $headers = null, &$redirects = 0, $timeout = 0) { $stamp1 = microtime(true); - if (self::blockedURL($url)) { + if (self::isUrlBlocked($url)) { logger('post_url: domain of ' . $url . ' is blocked', LOGGER_DATA); return false; } @@ -381,7 +380,7 @@ class Network if (filter_var($newurl, FILTER_VALIDATE_URL)) { $redirects++; logger('post_url: redirect ' . $url . ' to ' . $newurl); - return self::postURL($newurl, $params, $headers, $redirects, $timeout); + return self::post($newurl, $params, $headers, $redirects, $timeout); } } @@ -405,7 +404,7 @@ class Network * Outputs a basic dfrn XML status structure to STDOUT, with a variable * of $st and an optional text of $message and terminates the current process. */ - public static function xmlStatus($st, $message = '') + public static function xmlExit($st, $message = '') { $result = ['status' => $st]; @@ -465,7 +464,7 @@ class Network } /** - * @brief Check URL to se if ts's real + * @brief Check URL to see if it's real * * 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) @@ -473,7 +472,7 @@ class Network * @param string $url The URL to be validated * @return string|boolean The actual working URL, false else */ - public static function validateURL($url) + public static function isUrlValid($url) { if (Config::get('system', 'disable_url_validation')) { return $url; @@ -504,7 +503,7 @@ class Network * @param string $addr The email address * @return boolean True if it's a valid email address, false if it's not */ - public static function validateEmail($addr) + public static function isEmailDomainValid($addr) { if (Config::get('system', 'disable_email_validation')) { return true; @@ -531,7 +530,7 @@ class Network * @param string $url URL which get tested * @return boolean True if url is allowed otherwise return false */ - public static function allowedURL($url) + public static function isUrlAllowed($url) { $h = @parse_url($url); @@ -576,7 +575,7 @@ class Network * * @return boolean */ - public static function blockedURL($url) + public static function isUrlBlocked($url) { $h = @parse_url($url); @@ -609,7 +608,7 @@ class Network * @return boolean False if not allowed, true if allowed * or if allowed list is not configured */ - public static function allowedEmail($email) + public static function isEmailDomainAllowed($email) { $domain = strtolower(substr($email, strpos($email, '@') + 1)); if (!$domain) { @@ -623,7 +622,7 @@ class Network $allowed = explode(',', $str_allowed); - return self::allowedDomain($domain, $allowed); + return self::isDomainAllowed($domain, $allowed); } /** @@ -634,7 +633,7 @@ class Network * @param array $domain_list * @return boolean */ - public static function allowedDomain($domain, array $domain_list) + public static function isDomainAllowed($domain, array $domain_list) { $found = false; @@ -649,7 +648,7 @@ class Network return $found; } - public static function avatarImg($email) + public static function lookupAvatarByEmail($email) { $avatar['size'] = 175; $avatar['email'] = $email; @@ -666,125 +665,6 @@ class Network return $avatar['url']; } - public static function parseXmlString($s, $strict = true) - { - // the "strict" parameter is deactivated - - /// @todo Move this function to the xml class - libxml_use_internal_errors(true); - - $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); - } - libxml_clear_errors(); - } - return $x; - } - - public static function scaleExternalImages($srctext, $include_link = true, $scale_replace = false) - { - // Suppress "view full size" - if (intval(Config::get('system', 'no_view_full_size'))) { - $include_link = false; - } - - // Picture addresses can contain special characters - $s = htmlspecialchars_decode($srctext); - - $matches = null; - $c = preg_match_all('/\[img.*?\](.*?)\[\/img\]/ism', $s, $matches, PREG_SET_ORDER); - if ($c) { - foreach ($matches as $mtch) { - logger('scale_external_image: ' . $mtch[1]); - - $hostname = str_replace('www.', '', substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3)); - if (stristr($mtch[1], $hostname)) { - continue; - } - - // $scale_replace, if passed, is an array of two elements. The - // first is the name of the full-size image. The second is the - // name of a remote, scaled-down version of the full size image. - // This allows Friendica to display the smaller remote image if - // one exists, while still linking to the full-size image - if ($scale_replace) { - $scaled = str_replace($scale_replace[0], $scale_replace[1], $mtch[1]); - } else { - $scaled = $mtch[1]; - } - $i = self::fetchURL($scaled); - if (! $i) { - return $srctext; - } - - // guess mimetype from headers or filename - $type = Image::guessType($mtch[1], true); - - if ($i) { - $Image = new Image($i, $type); - if ($Image->isValid()) { - $orig_width = $Image->getWidth(); - $orig_height = $Image->getHeight(); - - if ($orig_width > 640 || $orig_height > 640) { - $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], - '[img=' . $new_width . 'x' . $new_height. ']' . $scaled . '[/img]' - . "\n" . (($include_link) - ? '[url=' . $mtch[1] . ']' . L10n::t('view full size') . '[/url]' . "\n" - : ''), - $s - ); - logger('scale_external_images: new string: ' . $s, LOGGER_DEBUG); - } - } - } - } - } - - // replace the special char encoding - $s = htmlspecialchars($s, ENT_NOQUOTES, 'UTF-8'); - return $s; - } - - public static function fixContactSslPolicy(&$contact, $new_policy) - { - $ssl_changed = false; - if ((intval($new_policy) == SSL_POLICY_SELFSIGN || $new_policy === 'self') && strstr($contact['url'], 'https:')) { - $ssl_changed = true; - $contact['url'] = str_replace('https:', 'http:', $contact['url']); - $contact['request'] = str_replace('https:', 'http:', $contact['request']); - $contact['notify'] = str_replace('https:', 'http:', $contact['notify']); - $contact['poll'] = str_replace('https:', 'http:', $contact['poll']); - $contact['confirm'] = str_replace('https:', 'http:', $contact['confirm']); - $contact['poco'] = str_replace('https:', 'http:', $contact['poco']); - } - - if ((intval($new_policy) == SSL_POLICY_FULL || $new_policy === 'full') && strstr($contact['url'], 'http:')) { - $ssl_changed = true; - $contact['url'] = str_replace('http:', 'https:', $contact['url']); - $contact['request'] = str_replace('http:', 'https:', $contact['request']); - $contact['notify'] = str_replace('http:', 'https:', $contact['notify']); - $contact['poll'] = str_replace('http:', 'https:', $contact['poll']); - $contact['confirm'] = str_replace('http:', 'https:', $contact['confirm']); - $contact['poco'] = str_replace('http:', 'https:', $contact['poco']); - } - - if ($ssl_changed) { - $fields = ['url' => $contact['url'], 'request' => $contact['request'], - 'notify' => $contact['notify'], 'poll' => $contact['poll'], - 'confirm' => $contact['confirm'], 'poco' => $contact['poco']]; - dba::update('contact', $fields, ['id' => $contact['id']]); - } - } - /** * @brief Remove Google Analytics and other tracking platforms params from URL * @@ -849,7 +729,7 @@ class Network * @param bool $fetchbody Wether to fetch the body or not after the HEAD requests * @return string A canonical URL */ - public static function originalURL($url, $depth = 1, $fetchbody = false) + public static function finalUrl($url, $depth = 1, $fetchbody = false) { $a = get_app(); @@ -886,15 +766,15 @@ class Network && (($curl_info['redirect_url'] != "") || ($curl_info['location'] != "")) ) { if ($curl_info['redirect_url'] != "") { - return(Network::originalURL($curl_info['redirect_url'], ++$depth, $fetchbody)); + return(self::finalUrl($curl_info['redirect_url'], ++$depth, $fetchbody)); } else { - return(Network::originalURL($curl_info['location'], ++$depth, $fetchbody)); + return(self::finalUrl($curl_info['location'], ++$depth, $fetchbody)); } } // Check for redirects in the meta elements of the body if there are no redirects in the header. if (!$fetchbody) { - return(Network::originalURL($url, ++$depth, true)); + return(self::finalUrl($url, ++$depth, true)); } // if the file is too large then exit @@ -946,7 +826,7 @@ class Network $pathinfo = explode(";", $path); foreach ($pathinfo as $value) { if (substr(strtolower($value), 0, 4) == "url=") { - return(Network::originalURL(substr($value, 4), ++$depth)); + return(self::finalUrl(substr($value, 4), ++$depth)); } } } @@ -955,7 +835,7 @@ class Network return $url; } - public static function shortLink($url) + public static function shortenUrl($url) { $slinky = new Slinky($url); $yourls_url = Config::get('yourls', 'url1'); @@ -987,7 +867,7 @@ class Network * * @param array $x The input content */ - public static function jsonReturnAndDie($x) + public static function jsonExit($x) { header("content-type: application/json"); echo json_encode($x); @@ -1001,7 +881,7 @@ class Network * @param string $url2 * @return string The matching part */ - public static function matchingURL($url1, $url2) + public static function getUrlMatch($url1, $url2) { if (($url1 == "") || ($url2 == "")) { return ""; @@ -1061,7 +941,7 @@ class Network * * @return string The glued URL */ - public static function unParseURL($parsed) + public static function unparseURL($parsed) { $get = function ($key) use ($parsed) { return isset($parsed[$key]) ? $parsed[$key] : null; diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 1c5676ace..868bd7ede 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -145,7 +145,7 @@ class ParseUrl $siteinfo["url"] = $url; $siteinfo["type"] = "link"; - $data = Network::zFetchURL($url); + $data = Network::curl($url); if (!$data['success']) { return($siteinfo); } diff --git a/src/Util/XML.php b/src/Util/XML.php index c866475c1..d8c5e0323 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -413,4 +413,20 @@ class XML $child->parentNode->removeChild($child); } } + + public static function parseString($s, $strict = true) + { + // the "strict" parameter is deactivated + libxml_use_internal_errors(true); + + $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); + } + libxml_clear_errors(); + } + return $x; + } } diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index 2e089502f..a6056ccbc 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -38,7 +38,7 @@ class CheckVersion { logger("Checking VERSION from: ".$checked_url, LOGGER_DEBUG); // fetch the VERSION file - $gitversion = dbesc(trim(Network::fetchURL($checked_url))); + $gitversion = dbesc(trim(Network::fetchUrl($checked_url))); logger("Upstream VERSION is: ".$gitversion, LOGGER_DEBUG); Config::set('system', 'git_friendica_version', $gitversion); diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index cc704474e..e17d68f88 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -15,7 +15,6 @@ use Friendica\Model\User; use Friendica\Protocol\Diaspora; use Friendica\Protocol\DFRN; use Friendica\Protocol\Email; -use Friendica\Util\Network; use dba; require_once 'include/html2plain.php'; @@ -300,7 +299,7 @@ class Delivery { } $ssl_policy = Config::get('system','ssl_policy'); - Network::fixContactSslPolicy($x[0], $ssl_policy); + $x[0] = Contact::updateSslPolicy($x[0], $ssl_policy); // If we are setup as a soapbox we aren't accepting top level posts from this person diff --git a/src/Worker/Directory.php b/src/Worker/Directory.php index 634c5a5ec..a59461037 100644 --- a/src/Worker/Directory.php +++ b/src/Worker/Directory.php @@ -12,8 +12,10 @@ use Friendica\Core\Worker; use Friendica\Database\DBM; use Friendica\Util\Network; -class Directory { - public static function execute($url = '') { +class Directory +{ + public static function execute($url = '') + { $dir = Config::get('system', 'directory'); if (!strlen($dir)) { @@ -33,7 +35,7 @@ class Directory { logger('Updating directory: ' . $arr['url'], LOGGER_DEBUG); if (strlen($arr['url'])) { - Network::fetchURL($dir . '?url=' . bin2hex($arr['url'])); + Network::fetchUrl($dir . '?url=' . bin2hex($arr['url'])); } return; diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index 0172bcd34..0657b0e1b 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -218,7 +218,7 @@ class DiscoverPoCo { } } - $x = Network::fetchURL(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); + $x = Network::fetchUrl(get_server()."/lsearch?p=1&n=500&search=".urlencode($search)); $j = json_decode($x); if (count($j->results)) { @@ -281,7 +281,7 @@ class DiscoverPoCo { $url = "http://gstools.org/api/users_search/".urlencode($search); - $result = Network::zFetchURL($url); + $result = Network::curl($url); if (!$result["success"]) { return false; } diff --git a/src/Worker/OnePoll.php b/src/Worker/OnePoll.php index c06b8f593..3a5fa5575 100644 --- a/src/Worker/OnePoll.php +++ b/src/Worker/OnePoll.php @@ -11,6 +11,7 @@ use Friendica\Model\Contact; use Friendica\Protocol\Email; use Friendica\Protocol\PortableContact; use Friendica\Util\Network; +use Friendica\Util\XML; use dba; require_once 'include/dba.php'; @@ -177,7 +178,7 @@ class OnePoll . '&type=data&last_update=' . $last_update . '&perm=' . $perm ; - $ret = Network::zFetchURL($url); + $ret = Network::curl($url); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { // set the last-update so we don't keep polling @@ -219,7 +220,7 @@ class OnePoll } - $res = Network::parseXmlString($handshake_xml); + $res = XML::parseString($handshake_xml); if (intval($res->status) == 1) { logger("$url replied status 1 - marking for death "); @@ -281,7 +282,7 @@ class OnePoll $postvars['dfrn_version'] = DFRN_PROTOCOL_VERSION; $postvars['perm'] = 'rw'; - $xml = Network::postURL($contact['poll'], $postvars); + $xml = Network::post($contact['poll'], $postvars); } elseif (($contact['network'] === NETWORK_OSTATUS) || ($contact['network'] === NETWORK_DIASPORA) @@ -312,7 +313,7 @@ class OnePoll } $cookiejar = tempnam(get_temppath(), 'cookiejar-onepoll-'); - $ret = Network::zFetchURL($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); + $ret = Network::curl($contact['poll'], false, $redirects, ['cookiejar' => $cookiejar]); unlink($cookiejar); if ($ret['errno'] == CURLE_OPERATION_TIMEDOUT) { diff --git a/src/Worker/PubSubPublish.php b/src/Worker/PubSubPublish.php index a287e89d3..03608bea6 100644 --- a/src/Worker/PubSubPublish.php +++ b/src/Worker/PubSubPublish.php @@ -69,7 +69,7 @@ class PubSubPublish { logger('POST '.print_r($headers, true)."\n".$params, LOGGER_DEBUG); - Network::postURL($rr['callback_url'], $params, $headers); + Network::post($rr['callback_url'], $params, $headers); $ret = $a->get_curl_code(); if ($ret >= 200 && $ret <= 299) {