From ffc406d8195871a6580c78f1cc42ff0b7deeba02 Mon Sep 17 00:00:00 2001 From: Adam Magness Date: Thu, 8 Nov 2018 11:28:29 -0500 Subject: [PATCH] normalise_link calls implement normaliseLink function --- include/api.php | 26 +++++----- include/conversation.php | 2 +- include/enotify.php | 6 +-- mod/admin.php | 4 +- mod/bookmarklet.php | 5 +- mod/common.php | 6 +-- mod/crepair.php | 3 +- mod/delegate.php | 5 +- mod/dfrn_request.php | 8 +-- mod/dirfind.php | 2 +- mod/display.php | 5 +- mod/fetch.php | 3 +- mod/follow.php | 6 +-- mod/hovercard.php | 6 +-- mod/maintenance.php | 3 +- mod/match.php | 3 +- mod/message.php | 2 +- mod/network.php | 2 +- mod/salmon.php | 4 +- mod/unfollow.php | 8 +-- src/App.php | 6 +-- src/Content/ContactSelector.php | 7 +-- src/Content/OEmbed.php | 4 +- src/Content/Text/BBCode.php | 5 +- src/Content/Widget.php | 5 +- src/Core/Console/ArchiveContact.php | 3 +- src/Core/Console/GlobalCommunitySilence.php | 3 +- src/Core/Installer.php | 2 +- src/Core/UserImport.php | 5 +- src/Model/APContact.php | 9 ++-- src/Model/Contact.php | 56 ++++++++++----------- src/Model/GContact.php | 27 +++++----- src/Model/Item.php | 6 +-- src/Model/Profile.php | 6 +-- src/Model/User.php | 2 +- src/Module/Contact.php | 2 +- src/Module/Magic.php | 2 +- src/Network/Probe.php | 16 +++--- src/Protocol/ActivityPub/Processor.php | 9 ++-- src/Protocol/ActivityPub/Receiver.php | 23 +++++---- src/Protocol/DFRN.php | 20 ++++---- src/Protocol/Diaspora.php | 12 ++--- src/Protocol/OStatus.php | 21 ++++---- src/Protocol/PortableContact.php | 53 +++++++++---------- src/Protocol/Salmon.php | 2 +- src/Util/Network.php | 7 +-- src/Util/ParseUrl.php | 5 +- src/Util/Proxy.php | 9 ++-- src/Util/Strings.php | 2 +- src/Worker/Delivery.php | 2 +- src/Worker/DiscoverPoCo.php | 13 ++--- src/Worker/GProbe.php | 9 ++-- src/Worker/UpdateGContact.php | 5 +- view/theme/vier/theme.php | 3 +- 54 files changed, 248 insertions(+), 222 deletions(-) diff --git a/include/api.php b/include/api.php index 8ae3c03d44..5bfb2d65a2 100644 --- a/include/api.php +++ b/include/api.php @@ -527,7 +527,7 @@ function api_get_user(App $a, $contact_id = null) // Searching for contact URL if (!is_null($contact_id) && (intval($contact_id) == 0)) { - $user = DBA::escape(normalise_link($contact_id)); + $user = DBA::escape(Strings::normaliseLink($contact_id)); $url = $user; $extra_query = "AND `contact`.`nurl` = '%s' "; if (api_user() !== false) { @@ -572,7 +572,7 @@ function api_get_user(App $a, $contact_id = null) } if (is_null($user) && x($_GET, 'profileurl')) { - $user = DBA::escape(normalise_link($_GET['profileurl'])); + $user = DBA::escape(Strings::normaliseLink($_GET['profileurl'])); $extra_query = "AND `contact`.`nurl` = '%s' "; if (api_user() !== false) { $extra_query .= "AND `contact`.`uid`=".intval(api_user()); @@ -640,7 +640,7 @@ function api_get_user(App $a, $contact_id = null) throw new BadRequestException("User not found."); } - $contact = DBA::selectFirst('contact', [], ['uid' => 0, 'nurl' => normalise_link($url)]); + $contact = DBA::selectFirst('contact', [], ['uid' => 0, 'nurl' => Strings::normaliseLink($url)]); if (DBA::isResult($contact)) { $network_name = ContactSelector::networkToName($contact['network'], $contact['url']); @@ -2663,7 +2663,7 @@ function api_get_entitities(&$text, $bbcode) "id" => $start+1, "id_str" => (string)$start+1, "indices" => [$start, $start+strlen($url)], - "media_url" => normalise_link($media_url), + "media_url" => Strings::normaliseLink($media_url), "media_url_https" => $media_url, "url" => $url, "display_url" => $display_url, @@ -3666,8 +3666,8 @@ function api_friendships_destroy($type) $url = $contact["url"]; $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", - $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), - normalise_link($url), $url]; + $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url), + Strings::normaliseLink($url), $url]; $contact = DBA::selectFirst('contact', [], $condition); if (!DBA::isResult($contact)) { @@ -3791,9 +3791,9 @@ function api_direct_messages_box($type, $box, $verbose) foreach ($r as $item) { if ($box == "inbox" || $item['from-url'] != $profile_url) { $recipient = $user_info; - $sender = api_get_user($a, normalise_link($item['contact-url'])); + $sender = api_get_user($a, Strings::normaliseLink($item['contact-url'])); } elseif ($box == "sentbox" || $item['from-url'] == $profile_url) { - $recipient = api_get_user($a, normalise_link($item['contact-url'])); + $recipient = api_get_user($a, Strings::normaliseLink($item['contact-url'])); $sender = $user_info; } @@ -4780,7 +4780,7 @@ function api_friendica_remoteauth() throw new BadRequestException("Wrong parameters."); } - $c_url = normalise_link($c_url); + $c_url = Strings::normaliseLink($c_url); // traditional DFRN @@ -4944,7 +4944,7 @@ function api_get_nick($profile) $r = q( "SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'", - DBA::escape(normalise_link($profile)) + DBA::escape(Strings::normaliseLink($profile)) ); if (DBA::isResult($r)) { @@ -4954,7 +4954,7 @@ function api_get_nick($profile) if (!$nick == "") { $r = q( "SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'", - DBA::escape(normalise_link($profile)) + DBA::escape(Strings::normaliseLink($profile)) ); if (DBA::isResult($r)) { @@ -5837,9 +5837,9 @@ function api_friendica_direct_messages_search($type, $box = "") foreach ($r as $item) { if ($box == "inbox" || $item['from-url'] != $profile_url) { $recipient = $user_info; - $sender = api_get_user($a, normalise_link($item['contact-url'])); + $sender = api_get_user($a, Strings::normaliseLink($item['contact-url'])); } elseif ($box == "sentbox" || $item['from-url'] == $profile_url) { - $recipient = api_get_user($a, normalise_link($item['contact-url'])); + $recipient = api_get_user($a, Strings::normaliseLink($item['contact-url'])); $sender = $user_info; } diff --git a/include/conversation.php b/include/conversation.php index 04f0adaef6..e570336054 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -843,7 +843,7 @@ function item_photo_menu($item) { $cid = 0; $network = ''; $rel = 0; - $condition = ['uid' => local_user(), 'nurl' => normalise_link($item['author-link'])]; + $condition = ['uid' => local_user(), 'nurl' => Strings::normaliseLink($item['author-link'])]; $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition); if (DBA::isResult($contact)) { $cid = $contact['id']; diff --git a/include/enotify.php b/include/enotify.php index 2033027e3d..a4b0fd14b4 100644 --- a/include/enotify.php +++ b/include/enotify.php @@ -704,11 +704,11 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { // Check for invalid profile urls. 13 should be the shortest possible profile length: // http://a.bc/d // Additionally check for invalid urls that would return the normalised value "http:" - if ((strlen($profile) >= 13) && (normalise_link($profile) != "http:")) { + if ((strlen($profile) >= 13) && (Strings::normaliseLink($profile) != "http:")) { if (!in_array($profile, $profiles2)) $profiles2[] = $profile; - $profile = normalise_link($profile); + $profile = Strings::normaliseLink($profile); if (!in_array($profile, $profiles2)) $profiles2[] = $profile; @@ -762,7 +762,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") { if (DBA::isResult($tags)) { foreach ($tags AS $tag) { - $condition = ['nurl' => normalise_link($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true]; + $condition = ['nurl' => Strings::normaliseLink($tag["url"]), 'uid' => $uid, 'notify_new_posts' => true]; $r = DBA::exists('contact', $condition); if ($r) { $send_notification = true; diff --git a/mod/admin.php b/mod/admin.php index 76f994502b..873966b999 100644 --- a/mod/admin.php +++ b/mod/admin.php @@ -997,8 +997,8 @@ function admin_page_site_post(App $a) $old_url = $a->getBaseURL(true); // Generate host names for relocation the addresses in the format user@address.tld - $new_host = str_replace("http://", "@", normalise_link($new_url)); - $old_host = str_replace("http://", "@", normalise_link($old_url)); + $new_host = str_replace("http://", "@", Strings::normaliseLink($new_url)); + $old_host = str_replace("http://", "@", Strings::normaliseLink($old_url)); function update_table(App $a, $table_name, $fields, $old_url, $new_url) { diff --git a/mod/bookmarklet.php b/mod/bookmarklet.php index e1ae9aa64c..d9c2f52f82 100644 --- a/mod/bookmarklet.php +++ b/mod/bookmarklet.php @@ -9,6 +9,7 @@ use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\System; use Friendica\Module\Login; +use Friendica\Util\Strings; require_once 'include/conversation.php'; require_once 'include/items.php'; @@ -26,8 +27,8 @@ function bookmarklet_content(App $a) return $o; } - $referer = normalise_link(defaults($_SERVER, 'HTTP_REFERER', '')); - $page = normalise_link(System::baseUrl() . "/bookmarklet"); + $referer = Strings::normaliseLink(defaults($_SERVER, 'HTTP_REFERER', '')); + $page = Strings::normaliseLink(System::baseUrl() . "/bookmarklet"); if (!strstr($referer, $page)) { if (empty($_REQUEST["url"])) { diff --git a/mod/common.php b/mod/common.php index 0f9bc096a2..b335e296db 100644 --- a/mod/common.php +++ b/mod/common.php @@ -12,7 +12,7 @@ use Friendica\Database\DBA; use Friendica\Model; use Friendica\Module; use Friendica\Util\Proxy as ProxyUtils; - +use Friendica\Util\Strings; require_once 'include/dba.php'; @@ -67,11 +67,11 @@ function common_content(App $a) } if (!$cid && Model\Profile::getMyURL()) { - $contact = DBA::selectFirst('contact', ['id'], ['nurl' => normalise_link(Model\Profile::getMyURL()), 'uid' => $uid]); + $contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL()), 'uid' => $uid]); if (DBA::isResult($contact)) { $cid = $contact['id']; } else { - $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Model\Profile::getMyURL())]); + $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Model\Profile::getMyURL())]); if (DBA::isResult($gcontact)) { $zcid = $gcontact['id']; } diff --git a/mod/crepair.php b/mod/crepair.php index 3308315593..f9ba281d13 100644 --- a/mod/crepair.php +++ b/mod/crepair.php @@ -12,6 +12,7 @@ use Friendica\Core\Renderer; use Friendica\Database\DBA; use Friendica\Model; use Friendica\Module; +use Friendica\Util\Strings; function crepair_init(App $a) { @@ -61,7 +62,7 @@ function crepair_post(App $a) $attag = defaults($_POST, 'attag' , ''); $photo = defaults($_POST, 'photo' , ''); $remote_self = defaults($_POST, 'remote_self', false); - $nurl = normalise_link($url); + $nurl = Strings::normaliseLink($url); $r = q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `url` = '%s', `nurl` = '%s', `request` = '%s', `confirm` = '%s', `notify` = '%s', `poll` = '%s', `attag` = '%s' , `remote_self` = %d WHERE `id` = %d AND `uid` = %d", diff --git a/mod/delegate.php b/mod/delegate.php index 1162458125..c8987ab570 100644 --- a/mod/delegate.php +++ b/mod/delegate.php @@ -12,6 +12,7 @@ use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Model\User; use Friendica\Util\Security; +use Friendica\Util\Strings; require_once 'mod/settings.php'; @@ -72,7 +73,7 @@ function delegate_content(App $a) if (DBA::isResult($user)) { $condition = [ 'uid' => local_user(), - 'nurl' => normalise_link(System::baseUrl() . '/profile/' . $user['nickname']) + 'nurl' => Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']) ]; if (DBA::exists('contact', $condition)) { DBA::insert('manage', ['uid' => $user_id, 'mid' => local_user()]); @@ -114,7 +115,7 @@ function delegate_content(App $a) AND SUBSTRING_INDEX(`nurl`, '/', 3) = '%s' AND `uid` = %d AND `network` = '%s' ", - DBA::escape(normalise_link(System::baseUrl())), + DBA::escape(Strings::normaliseLink(System::baseUrl())), intval(local_user()), DBA::escape(Protocol::DFRN) ); diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 7b2b3fbf1c..8548c67f19 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -88,7 +88,7 @@ function dfrn_request_post(App $a) // Lookup the contact based on their URL (which is the only unique thing we have at the moment) $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1", intval(local_user()), - DBA::escape(normalise_link($dfrn_url)) + DBA::escape(Strings::normaliseLink($dfrn_url)) ); if (DBA::isResult($r)) { @@ -142,7 +142,7 @@ function dfrn_request_post(App $a) intval(local_user()), DateTimeFormat::utcNow(), DBA::escape($dfrn_url), - DBA::escape(normalise_link($dfrn_url)), + DBA::escape(Strings::normaliseLink($dfrn_url)), $parms['addr'], $parms['fn'], $parms['nick'], @@ -381,7 +381,7 @@ function dfrn_request_post(App $a) intval($uid), DBA::escape(DateTimeFormat::utcNow()), $parms['url'], - DBA::escape(normalise_link($url)), + DBA::escape(Strings::normaliseLink($url)), $parms['addr'], $parms['fn'], $parms['nick'], @@ -503,7 +503,7 @@ function dfrn_request_content(App $a) $confirm_key = x($_GET, 'confirm_key') ? $_GET['confirm_key'] : ""; // Checking fastlane for validity - if (x($_SESSION, "fastlane") && (normalise_link($_SESSION["fastlane"]) == normalise_link($dfrn_url))) { + if (x($_SESSION, "fastlane") && (Strings::normaliseLink($_SESSION["fastlane"]) == Strings::normaliseLink($dfrn_url))) { $_POST["dfrn_url"] = $dfrn_url; $_POST["confirm_key"] = $confirm_key; $_POST["localconfirm"] = 1; diff --git a/mod/dirfind.php b/mod/dirfind.php index 738ac124f8..b814d3b4f7 100644 --- a/mod/dirfind.php +++ b/mod/dirfind.php @@ -54,7 +54,7 @@ function dirfind_content(App $a, $prefix = "") { $search = substr($search,1); $header = L10n::t('People Search - %s', $search); if ((Strings::isValidEmail($search) && Network::isEmailDomainValid($search)) || - (substr(normalise_link($search), 0, 7) == "http://")) { + (substr(Strings::normaliseLink($search), 0, 7) == "http://")) { $user_data = Probe::uri($search); $discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])); } diff --git a/mod/display.php b/mod/display.php index ac345d5412..39661cb76f 100644 --- a/mod/display.php +++ b/mod/display.php @@ -21,6 +21,7 @@ use Friendica\Model\Item; use Friendica\Model\Profile; use Friendica\Protocol\ActivityPub; use Friendica\Protocol\DFRN; +use Friendica\Util\Strings; function display_init(App $a) { @@ -90,8 +91,8 @@ function display_init(App $a) $profiledata = display_fetchauthor($a, $item); - if (strstr(normalise_link($profiledata["url"]), normalise_link(System::baseUrl()))) { - $nickname = str_replace(normalise_link(System::baseUrl())."/profile/", "", normalise_link($profiledata["url"])); + if (strstr(Strings::normaliseLink($profiledata["url"]), Strings::normaliseLink(System::baseUrl()))) { + $nickname = str_replace(Strings::normaliseLink(System::baseUrl())."/profile/", "", Strings::normaliseLink($profiledata["url"])); if (($nickname != $a->user["nickname"])) { $profile = DBA::fetchFirst("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` diff --git a/mod/fetch.php b/mod/fetch.php index 4e7d8c751a..9336c14047 100644 --- a/mod/fetch.php +++ b/mod/fetch.php @@ -10,6 +10,7 @@ use Friendica\Core\System; use Friendica\Protocol\Diaspora; use Friendica\Model\Item; use Friendica\Model\User; +use Friendica\Util\Strings; use Friendica\Util\XML; use Friendica\Database\DBA; @@ -35,7 +36,7 @@ function fetch_init(App $a) $parts = parse_url($item["author-link"]); $host = $parts["scheme"]."://".$parts["host"]; - if (normalise_link($host) != normalise_link(System::baseUrl())) { + if (Strings::normaliseLink($host) != Strings::normaliseLink(System::baseUrl())) { $location = $host."/fetch/".$a->argv[1]."/".urlencode($guid); header("HTTP/1.1 301 Moved Permanently"); diff --git a/mod/follow.php b/mod/follow.php index f69cb4abed..47b66430a4 100644 --- a/mod/follow.php +++ b/mod/follow.php @@ -69,8 +69,8 @@ function follow_content(App $a) $r = q("SELECT `pending` FROM `contact` WHERE `uid` = %d AND ((`rel` != %d) OR (`network` = '%s')) AND (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND `network` != '%s' LIMIT 1", - intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(normalise_link($url)), - DBA::escape(normalise_link($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET)); + intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)), + DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET)); if ($r) { if ($r[0]['pending']) { @@ -131,7 +131,7 @@ function follow_content(App $a) $_SESSION['fastlane'] = $ret['url']; $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", - normalise_link($ret['url'])); + Strings::normaliseLink($ret['url'])); if (!$r) { $r = [['location' => '', 'about' => '', 'keywords' => '']]; diff --git a/mod/hovercard.php b/mod/hovercard.php index d35de1a7fa..f5ad3ef021 100644 --- a/mod/hovercard.php +++ b/mod/hovercard.php @@ -56,7 +56,7 @@ function hovercard_content() $contact = []; // if it's the url containing https it should be converted to http - $nurl = normalise_link(GContact::cleanContactUrl($profileurl)); + $nurl = Strings::normaliseLink(GContact::cleanContactUrl($profileurl)); if (!$nurl) { return; } @@ -74,12 +74,12 @@ function hovercard_content() // Feeds url could have been destroyed through "cleanContactUrl", so we now use the original url if (!count($contact) && local_user()) { - $nurl = normalise_link($profileurl); + $nurl = Strings::normaliseLink($profileurl); $contact = Contact::getDetailsByURL($nurl, local_user()); } if (!count($contact)) { - $nurl = normalise_link($profileurl); + $nurl = Strings::normaliseLink($profileurl); $contact = Contact::getDetailsByURL($nurl); } diff --git a/mod/maintenance.php b/mod/maintenance.php index a1b032a617..8e0197b868 100644 --- a/mod/maintenance.php +++ b/mod/maintenance.php @@ -6,12 +6,13 @@ use Friendica\App; use Friendica\Core\Config; use Friendica\Core\L10n; use Friendica\Core\Renderer; +use Friendica\Util\Strings; function maintenance_content(App $a) { $reason = Config::get('system', 'maintenance_reason'); - if (substr(normalise_link($reason), 0, 7) == 'http://') { + if (substr(Strings::normaliseLink($reason), 0, 7) == 'http://') { header("HTTP/1.1 307 Temporary Redirect"); header("Location:".$reason); return; diff --git a/mod/match.php b/mod/match.php index e924722aa3..0ec7534662 100644 --- a/mod/match.php +++ b/mod/match.php @@ -14,6 +14,7 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Util\Network; use Friendica\Util\Proxy as ProxyUtils; +use Friendica\Util\Strings; require_once 'include/text.php'; @@ -76,7 +77,7 @@ function match_content(App $a) $id = 0; foreach ($j->results as $jj) { - $match_nurl = normalise_link($jj->url); + $match_nurl = Strings::normaliseLink($jj->url); $match = q( "SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1", intval(local_user()), diff --git a/mod/message.php b/mod/message.php index 6ac5d183a2..e689c45021 100644 --- a/mod/message.php +++ b/mod/message.php @@ -219,7 +219,7 @@ function message_content(App $a) if (!DBA::isResult($r)) { $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", intval(local_user()), - DBA::escape(normalise_link(base64_decode($a->argv[2]))) + DBA::escape(Strings::normaliseLink(base64_decode($a->argv[2]))) ); } diff --git a/mod/network.php b/mod/network.php index ec87e4c87e..77e815fe1a 100644 --- a/mod/network.php +++ b/mod/network.php @@ -883,7 +883,7 @@ function networkThreadedView(App $a, $update, $parent) foreach ($data as $item) { // Don't show hash tag posts from blocked or ignored contacts $condition = ["`nurl` = ? AND `uid` = ? AND (`blocked` OR `readonly`)", - normalise_link($item['author-link']), local_user()]; + Strings::normaliseLink($item['author-link']), local_user()]; if (!DBA::exists('contact', $condition)) { $s[$item['uri']] = $item; } diff --git a/mod/salmon.php b/mod/salmon.php index 1538a1c68c..5c8fc9fda7 100644 --- a/mod/salmon.php +++ b/mod/salmon.php @@ -150,9 +150,9 @@ function salmon_post(App $a, $xml = '') { AND `uid` = %d LIMIT 1", DBA::escape(Protocol::OSTATUS), DBA::escape(Protocol::DFRN), - DBA::escape(normalise_link($author_link)), + DBA::escape(Strings::normaliseLink($author_link)), DBA::escape($author_link), - DBA::escape(normalise_link($author_link)), + DBA::escape(Strings::normaliseLink($author_link)), intval($importer['uid']) ); diff --git a/mod/unfollow.php b/mod/unfollow.php index e2ee312f24..9ca965bfd0 100644 --- a/mod/unfollow.php +++ b/mod/unfollow.php @@ -28,8 +28,8 @@ function unfollow_post(App $a) $url = Strings::removeTags(trim(defaults($_REQUEST, 'url', ''))); $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", - $uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), - normalise_link($url), $url]; + $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url), + Strings::normaliseLink($url), $url]; $contact = DBA::selectFirst('contact', [], $condition); if (!DBA::isResult($contact)) { @@ -83,8 +83,8 @@ function unfollow_content(App $a) $url = Strings::removeTags(trim($_REQUEST['url'])); $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", - local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url), - normalise_link($url), $url]; + local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url), + Strings::normaliseLink($url), $url]; $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition); diff --git a/src/App.php b/src/App.php index a9fc7173c0..12f302f06e 100644 --- a/src/App.php +++ b/src/App.php @@ -816,12 +816,12 @@ class App public function removeBaseURL($origURL) { // Remove the hostname from the url if it is an internal link - $nurl = normalise_link($origURL); - $base = normalise_link($this->getBaseURL()); + $nurl = Util\Strings::normaliseLink($origURL); + $base = Util\Strings::normaliseLink($this->getBaseURL()); $url = str_replace($base . '/', '', $nurl); // if it is an external link return the orignal value - if ($url == normalise_link($origURL)) { + if ($url == Util\Strings::normaliseLink($origURL)) { return $origURL; } else { return $url; diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index 298f2512ed..a23acecc55 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -10,6 +10,7 @@ use Friendica\Core\Protocol; use Friendica\Core\System; use Friendica\Database\DBA; use Friendica\Util\Network; +use Friendica\Util\Strings; /** * @brief ContactSelector class @@ -106,12 +107,12 @@ class ContactSelector // Create the server url out of the profile url $parts = parse_url($profile); unset($parts['path']); - $server_url = [normalise_link(Network::unparseURL($parts))]; + $server_url = [Strings::normaliseLink(Network::unparseURL($parts))]; // Fetch the server url - $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => normalise_link($profile)]); + $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]); if (!empty($gcontact) && !empty($gcontact['server_url'])) { - $server_url[] = normalise_link($gcontact['server_url']); + $server_url[] = Strings::normaliseLink($gcontact['server_url']); } // Now query the GServer for the platform name diff --git a/src/Content/OEmbed.php b/src/Content/OEmbed.php index 741f1f42d8..c77db3827f 100644 --- a/src/Content/OEmbed.php +++ b/src/Content/OEmbed.php @@ -62,7 +62,7 @@ class OEmbed $cache_key = 'oembed:' . $a->videowidth . ':' . $embedurl; - $condition = ['url' => normalise_link($embedurl), 'maxwidth' => $a->videowidth]; + $condition = ['url' => Strings::normaliseLink($embedurl), 'maxwidth' => $a->videowidth]; $oembed_record = DBA::selectFirst('oembed', ['content'], $condition); if (DBA::isResult($oembed_record)) { $json_string = $oembed_record['content']; @@ -117,7 +117,7 @@ class OEmbed if (!empty($oembed->type) && $oembed->type != 'error') { DBA::insert('oembed', [ - 'url' => normalise_link($embedurl), + 'url' => Strings::normaliseLink($embedurl), 'maxwidth' => $a->videowidth, 'content' => $json_string, 'created' => DateTimeFormat::utcNow() diff --git a/src/Content/Text/BBCode.php b/src/Content/Text/BBCode.php index f37400f836..778d95cedb 100644 --- a/src/Content/Text/BBCode.php +++ b/src/Content/Text/BBCode.php @@ -27,6 +27,7 @@ use Friendica\Util\Map; use Friendica\Util\Network; use Friendica\Util\ParseUrl; use Friendica\Util\Proxy as ProxyUtils; +use Friendica\Util\Strings; class BBCode extends BaseObject { @@ -943,7 +944,7 @@ class BBCode extends BaseObject case 3: // Diaspora $headline = '

' . html_entity_decode('♲ ', ENT_QUOTES, 'UTF-8') . $mention . ':

' . "\n"; - if (stripos(normalise_link($attributes['link']), 'http://twitter.com/') === 0) { + if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0) { $text = ($is_quote_share? '
' : '') . '

' . $attributes['link'] . '

' . "\n"; } else { $text = ($is_quote_share? '
' : '') . $headline . '
' . trim($content) . '
' . "\n"; @@ -978,7 +979,7 @@ class BBCode extends BaseObject break; default: // Transforms quoted tweets in rich attachments to avoid nested tweets - if (stripos(normalise_link($attributes['link']), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($attributes['link'])) { + if (stripos(Strings::normaliseLink($attributes['link']), 'http://twitter.com/') === 0 && OEmbed::isAllowedURL($attributes['link'])) { try { $text = ($is_quote_share? '
' : '') . OEmbed::getHTML($attributes['link']); } catch (Exception $e) { diff --git a/src/Content/Widget.php b/src/Content/Widget.php index 397a1863d3..0ea539dec0 100644 --- a/src/Content/Widget.php +++ b/src/Content/Widget.php @@ -18,6 +18,7 @@ use Friendica\Model\Contact; use Friendica\Model\FileTag; use Friendica\Model\GContact; use Friendica\Model\Profile; +use Friendica\Util\Strings; use Friendica\Util\XML; require_once 'boot.php'; @@ -270,11 +271,11 @@ class Widget if (!$cid) { if (Profile::getMyURL()) { $contact = DBA::selectFirst('contact', ['id'], - ['nurl' => normalise_link(Profile::getMyURL()), 'uid' => $profile_uid]); + ['nurl' => Strings::normaliseLink(Profile::getMyURL()), 'uid' => $profile_uid]); if (DBA::isResult($contact)) { $cid = $contact['id']; } else { - $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => normalise_link(Profile::getMyURL())]); + $gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(Profile::getMyURL())]); if (DBA::isResult($gcontact)) { $zcid = $gcontact['id']; } diff --git a/src/Core/Console/ArchiveContact.php b/src/Core/Console/ArchiveContact.php index 481037a5f6..ffcd5a1658 100644 --- a/src/Core/Console/ArchiveContact.php +++ b/src/Core/Console/ArchiveContact.php @@ -5,6 +5,7 @@ namespace Friendica\Core\Console; use Friendica\App; use Friendica\Core\L10n; use Friendica\Database\DBA; +use Friendica\Util\Strings; use RuntimeException; /** @@ -60,7 +61,7 @@ HELP; throw new RuntimeException('Friendica isn\'t properly installed yet.'); } - $nurl = normalise_link($this->getArgument(0)); + $nurl = Strings::normaliseLink($this->getArgument(0)); if (!DBA::exists('contact', ['nurl' => $nurl, 'archive' => false])) { throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl)); } diff --git a/src/Core/Console/GlobalCommunitySilence.php b/src/Core/Console/GlobalCommunitySilence.php index 3ea6b41554..01413cab13 100644 --- a/src/Core/Console/GlobalCommunitySilence.php +++ b/src/Core/Console/GlobalCommunitySilence.php @@ -5,6 +5,7 @@ namespace Friendica\Core\Console; use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\Network\Probe; +use Friendica\Util\Strings; use RuntimeException; require_once 'include/text.php'; @@ -79,7 +80,7 @@ HELP; throw new RuntimeException('This account seems not to exist.'); } - $nurl = normalise_link($net['url']); + $nurl = Strings::normaliseLink($net['url']); $contact = DBA::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]); if (DBA::isResult($contact)) { DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]); diff --git a/src/Core/Installer.php b/src/Core/Installer.php index 9dd338e2c5..f7190b2f89 100644 --- a/src/Core/Installer.php +++ b/src/Core/Installer.php @@ -511,7 +511,7 @@ class Installer if (function_exists('curl_init')) { $fetchResult = Network::fetchUrlFull($baseurl . "/install/testrewrite"); - $url = normalise_link($baseurl . "/install/testrewrite"); + $url = Strings::normaliseLink($baseurl . "/install/testrewrite"); if ($fetchResult->getReturnCode() != 204) { $fetchResult = Network::fetchUrlFull($url); } diff --git a/src/Core/UserImport.php b/src/Core/UserImport.php index 7ccb6f80cb..5488fe43f0 100644 --- a/src/Core/UserImport.php +++ b/src/Core/UserImport.php @@ -10,6 +10,7 @@ use Friendica\Core\Protocol; use Friendica\Database\DBA; use Friendica\Model\Photo; use Friendica\Object\Image; +use Friendica\Util\Strings; require_once "include/dba.php"; @@ -119,8 +120,8 @@ class UserImport $oldbaseurl = $account['baseurl']; $newbaseurl = System::baseUrl(); - $oldaddr = str_replace('http://', '@', normalise_link($oldbaseurl)); - $newaddr = str_replace('http://', '@', normalise_link($newbaseurl)); + $oldaddr = str_replace('http://', '@', Strings::normaliseLink($oldbaseurl)); + $newaddr = str_replace('http://', '@', Strings::normaliseLink($newbaseurl)); if (!empty($account['profile']['addr'])) { $old_handle = $account['profile']['addr']; diff --git a/src/Model/APContact.php b/src/Model/APContact.php index 917e0895dc..c306b3e007 100644 --- a/src/Model/APContact.php +++ b/src/Model/APContact.php @@ -7,13 +7,14 @@ namespace Friendica\Model; use Friendica\BaseObject; +use Friendica\Content\Text\HTML; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\Protocol\ActivityPub; use Friendica\Util\Network; use Friendica\Util\JsonLD; use Friendica\Util\DateTimeFormat; -use Friendica\Content\Text\HTML; +use Friendica\Util\Strings; require_once 'boot.php'; @@ -186,16 +187,16 @@ class APContact extends BaseObject // Update some data in the contact table with various ways to catch them all $contact_fields = ['name' => $apcontact['name'], 'about' => $apcontact['about']]; - DBA::update('contact', $contact_fields, ['nurl' => normalise_link($url)]); + DBA::update('contact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]); - $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => normalise_link($url)]); + $contacts = DBA::select('contact', ['uid', 'id'], ['nurl' => Strings::normaliseLink($url)]); while ($contact = DBA::fetch($contacts)) { Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); } DBA::close($contacts); // Update the gcontact table - DBA::update('gcontact', $contact_fields, ['nurl' => normalise_link($url)]); + DBA::update('gcontact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]); Logger::log('Updated profile for ' . $url, Logger::DEBUG); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 1a6349d9ca..8e150b5065 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -393,7 +393,7 @@ class Contact extends BaseObject 'blocked' => 0, 'pending' => 0, 'url' => System::baseUrl() . '/profile/' . $user['nickname'], - 'nurl' => normalise_link(System::baseUrl() . '/profile/' . $user['nickname']), + 'nurl' => Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']), 'addr' => $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3), 'request' => System::baseUrl() . '/dfrn_request/' . $user['nickname'], 'notify' => System::baseUrl() . '/dfrn_notify/' . $user['nickname'], @@ -478,7 +478,7 @@ class Contact extends BaseObject // it seems as if ported accounts can have wrong values, so we make sure that now everything is fine. $fields['url'] = System::baseUrl() . '/profile/' . $user['nickname']; - $fields['nurl'] = normalise_link($fields['url']); + $fields['nurl'] = Strings::normaliseLink($fields['url']); $fields['addr'] = $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); $fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname']; $fields['notify'] = System::baseUrl() . '/dfrn_notify/' . $user['nickname']; @@ -598,7 +598,7 @@ class Contact extends BaseObject if ($contact['term-date'] <= DBA::NULL_DATETIME) { DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); - DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', normalise_link($contact['url']), DBA::NULL_DATETIME]); + DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['`nurl` = ? AND `term-date` <= ? AND NOT `self`', Strings::normaliseLink($contact['url']), DBA::NULL_DATETIME]); } else { /* @todo * We really should send a notification to the owner after 2-3 weeks @@ -616,7 +616,7 @@ class Contact extends BaseObject * the whole process over again. */ DBA::update('contact', ['archive' => 1], ['id' => $contact['id']]); - DBA::update('contact', ['archive' => 1], ['nurl' => normalise_link($contact['url']), 'self' => false]); + DBA::update('contact', ['archive' => 1], ['nurl' => Strings::normaliseLink($contact['url']), 'self' => false]); } } } @@ -650,7 +650,7 @@ class Contact extends BaseObject // It's a miracle. Our dead contact has inexplicably come back to life. $fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false]; DBA::update('contact', $fields, ['id' => $contact['id']]); - DBA::update('contact', $fields, ['nurl' => normalise_link($contact['url'])]); + DBA::update('contact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]); if (!empty($contact['batch'])) { $condition = ['batch' => $contact['batch'], 'contact-type' => self::ACCOUNT_TYPE_RELAY]; @@ -691,14 +691,14 @@ class Contact extends BaseObject // Fetch contact data from the contact table for the given user $s = DBA::p("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self` - FROM `contact` WHERE `nurl` = ? AND `uid` = ?", normalise_link($url), $uid); + FROM `contact` WHERE `nurl` = ? AND `uid` = ?", Strings::normaliseLink($url), $uid); $r = DBA::toArray($s); // Fetch contact data from the contact table for the given user, checking with the alias if (!DBA::isResult($r)) { $s = DBA::p("SELECT `id`, `id` AS `cid`, 0 AS `gid`, 0 AS `zid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, `self` - FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = ?", normalise_link($url), $url, $ssl_url, $uid); + FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = ?", Strings::normaliseLink($url), $url, $ssl_url, $uid); $r = DBA::toArray($s); } @@ -706,7 +706,7 @@ class Contact extends BaseObject if (!DBA::isResult($r)) { $s = DBA::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self` - FROM `contact` WHERE `nurl` = ? AND `uid` = 0", normalise_link($url)); + FROM `contact` WHERE `nurl` = ? AND `uid` = 0", Strings::normaliseLink($url)); $r = DBA::toArray($s); } @@ -714,7 +714,7 @@ class Contact extends BaseObject if (!DBA::isResult($r)) { $s = DBA::p("SELECT `id`, 0 AS `cid`, `id` AS `zid`, 0 AS `gid`, `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, `xmpp`, `keywords`, `gender`, `photo`, `thumb`, `micro`, `forum`, `prv`, (`forum` | `prv`) AS `community`, `contact-type`, `bd` AS `birthday`, 0 AS `self` - FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = 0", normalise_link($url), $url, $ssl_url); + FROM `contact` WHERE `alias` IN (?, ?, ?) AND `uid` = 0", Strings::normaliseLink($url), $url, $ssl_url); $r = DBA::toArray($s); } @@ -722,7 +722,7 @@ class Contact extends BaseObject if (!DBA::isResult($r)) { $s = DBA::p("SELECT 0 AS `id`, 0 AS `cid`, `id` AS `gid`, 0 AS `zid`, 0 AS `uid`, `url`, `nurl`, `alias`, `network`, `name`, `nick`, `addr`, `location`, `about`, '' AS `xmpp`, `keywords`, `gender`, `photo`, `photo` AS `thumb`, `photo` AS `micro`, 0 AS `forum`, 0 AS `prv`, `community`, `contact-type`, `birthday`, 0 AS `self` - FROM `gcontact` WHERE `nurl` = ?", normalise_link($url)); + FROM `gcontact` WHERE `nurl` = ?", Strings::normaliseLink($url)); $r = DBA::toArray($s); } @@ -1039,7 +1039,7 @@ class Contact extends BaseObject /// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following // We first try the nurl (http://server.tld/nick), most common case - $contact = DBA::selectFirst('contact', ['id', 'avatar', 'avatar-date'], ['nurl' => normalise_link($url), 'uid' => $uid, 'deleted' => false]); + $contact = DBA::selectFirst('contact', ['id', 'avatar', 'avatar-date'], ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false]); // Then the addr (nick@server.tld) if (!DBA::isResult($contact)) { @@ -1050,7 +1050,7 @@ class Contact extends BaseObject if (!DBA::isResult($contact)) { // The link could be provided as http although we stored it as https $ssl_url = str_replace('http://', 'https://', $url); - $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, normalise_link($url), $ssl_url, $uid]; + $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid]; $contact = DBA::selectFirst('contact', ['id', 'avatar', 'avatar-date'], $condition); } @@ -1077,7 +1077,7 @@ class Contact extends BaseObject $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick', 'photo', 'keywords', 'location', 'about', 'network', 'priority', 'batch', 'request', 'confirm', 'poco']; - $data = DBA::selectFirst('contact', $fields, ['nurl' => normalise_link($url)]); + $data = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url)]); if (DBA::isResult($data)) { // For security reasons we don't fetch key data from our users @@ -1104,9 +1104,9 @@ class Contact extends BaseObject // Get data from the gcontact table $fields = ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network']; - $contact = DBA::selectFirst('gcontact', $fields, ['nurl' => normalise_link($url)]); + $contact = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($url)]); if (!DBA::isResult($contact)) { - $contact = DBA::selectFirst('contact', $fields, ['nurl' => normalise_link($url)]); + $contact = DBA::selectFirst('contact', $fields, ['nurl' => Strings::normaliseLink($url)]); } if (!DBA::isResult($contact)) { @@ -1119,14 +1119,14 @@ class Contact extends BaseObject if (!DBA::isResult($contact)) { // The link could be provided as http although we stored it as https $ssl_url = str_replace('http://', 'https://', $url); - $condition = ['alias' => [$url, normalise_link($url), $ssl_url]]; + $condition = ['alias' => [$url, Strings::normaliseLink($url), $ssl_url]]; $contact = DBA::selectFirst('contact', $fields, $condition); } if (!DBA::isResult($contact)) { $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick', 'photo', 'network', 'priority', 'batch', 'request', 'confirm']; - $condition = ['url' => [$url, normalise_link($url), $ssl_url]]; + $condition = ['url' => [$url, Strings::normaliseLink($url), $ssl_url]]; $contact = DBA::selectFirst('fcontact', $fields, $condition); } @@ -1151,7 +1151,7 @@ class Contact extends BaseObject 'uid' => $uid, 'created' => DateTimeFormat::utcNow(), 'url' => $data["url"], - 'nurl' => normalise_link($data["url"]), + 'nurl' => Strings::normaliseLink($data["url"]), 'addr' => $data["addr"], 'alias' => $data["alias"], 'notify' => $data["notify"], @@ -1179,7 +1179,7 @@ class Contact extends BaseObject 'pending' => 0] ); - $s = DBA::select('contact', ['id'], ['nurl' => normalise_link($data["url"]), 'uid' => $uid], ['order' => ['id'], 'limit' => 2]); + $s = DBA::select('contact', ['id'], ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid], ['order' => ['id'], 'limit' => 2]); $contacts = DBA::toArray($s); if (!DBA::isResult($contacts)) { return 0; @@ -1188,7 +1188,7 @@ class Contact extends BaseObject $contact_id = $contacts[0]["id"]; // Update the newly created contact from data in the gcontact table - $gcontact = DBA::selectFirst('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => normalise_link($data["url"])]); + $gcontact = DBA::selectFirst('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => Strings::normaliseLink($data["url"])]); if (DBA::isResult($gcontact)) { // Only use the information when the probing hadn't fetched these values if ($data['keywords'] != '') { @@ -1205,7 +1205,7 @@ class Contact extends BaseObject if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") { DBA::delete('contact', ["`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`", - normalise_link($data["url"]), $contact_id]); + Strings::normaliseLink($data["url"]), $contact_id]); } } @@ -1222,7 +1222,7 @@ class Contact extends BaseObject $updated = ['addr' => $data['addr'], 'alias' => $data['alias'], 'url' => $data['url'], - 'nurl' => normalise_link($data['url']), + 'nurl' => Strings::normaliseLink($data['url']), 'name' => $data['name'], 'nick' => $data['nick']]; @@ -1544,7 +1544,7 @@ class Contact extends BaseObject DBA::update( 'contact', [ 'url' => $ret['url'], - 'nurl' => normalise_link($ret['url']), + 'nurl' => Strings::normaliseLink($ret['url']), 'network' => $ret['network'], 'addr' => $ret['addr'], 'alias' => $ret['alias'], @@ -1628,10 +1628,10 @@ class Contact extends BaseObject // the poll url is more reliable than the profile url, as we may have // indirect links or webfinger links - $condition = ['uid' => $uid, 'poll' => [$ret['poll'], normalise_link($ret['poll'])], 'network' => $ret['network'], 'pending' => false]; + $condition = ['uid' => $uid, 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false]; $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition); if (!DBA::isResult($contact)) { - $condition = ['uid' => $uid, 'nurl' => normalise_link($url), 'network' => $ret['network'], 'pending' => false]; + $condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false]; $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition); } @@ -1711,7 +1711,7 @@ class Contact extends BaseObject 'uid' => $uid, 'created' => DateTimeFormat::utcNow(), 'url' => $ret['url'], - 'nurl' => normalise_link($ret['url']), + 'nurl' => Strings::normaliseLink($ret['url']), 'addr' => $ret['addr'], 'alias' => $ret['alias'], 'batch' => $ret['batch'], @@ -1856,7 +1856,7 @@ class Contact extends BaseObject // send email notification to owner? } else { - if (DBA::exists('contact', ['nurl' => normalise_link($url), 'uid' => $importer['uid'], 'pending' => true])) { + if (DBA::exists('contact', ['nurl' => Strings::normaliseLink($url), 'uid' => $importer['uid'], 'pending' => true])) { Logger::log('ignoring duplicated connection request from pending contact ' . $url); return; } @@ -1867,7 +1867,7 @@ class Contact extends BaseObject intval($importer['uid']), DBA::escape(DateTimeFormat::utcNow()), DBA::escape($url), - DBA::escape(normalise_link($url)), + DBA::escape(Strings::normaliseLink($url)), DBA::escape($name), DBA::escape($nick), DBA::escape($photo), diff --git a/src/Model/GContact.php b/src/Model/GContact.php index 398fc77588..6e2e520c89 100644 --- a/src/Model/GContact.php +++ b/src/Model/GContact.php @@ -17,6 +17,7 @@ use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; +use Friendica\Util\Strings; require_once 'include/dba.php'; @@ -146,13 +147,13 @@ class GContact $alternate = PortableContact::alternateOStatusUrl($gcontact['url']); // The global contacts should contain the original picture, not the cached one - if (($gcontact['generation'] != 1) && stristr(normalise_link($gcontact['photo']), normalise_link(System::baseUrl()."/photo/"))) { + if (($gcontact['generation'] != 1) && stristr(Strings::normaliseLink($gcontact['photo']), Strings::normaliseLink(System::baseUrl()."/photo/"))) { $gcontact['photo'] = ""; } if (!isset($gcontact['network'])) { $condition = ["`uid` = 0 AND `nurl` = ? AND `network` != '' AND `network` != ?", - normalise_link($gcontact['url']), Protocol::STATUSNET]; + Strings::normaliseLink($gcontact['url']), Protocol::STATUSNET]; $contact = DBA::selectFirst('contact', ['network'], $condition); if (DBA::isResult($contact)) { $gcontact['network'] = $contact["network"]; @@ -160,7 +161,7 @@ class GContact if (($gcontact['network'] == "") || ($gcontact['network'] == Protocol::OSTATUS)) { $condition = ["`uid` = 0 AND `alias` IN (?, ?) AND `network` != '' AND `network` != ?", - $gcontact['url'], normalise_link($gcontact['url']), Protocol::STATUSNET]; + $gcontact['url'], Strings::normaliseLink($gcontact['url']), Protocol::STATUSNET]; $contact = DBA::selectFirst('contact', ['network'], $condition); if (DBA::isResult($contact)) { $gcontact['network'] = $contact["network"]; @@ -172,7 +173,7 @@ class GContact $gcontact['network'] = ''; $fields = ['network', 'updated', 'server_url', 'url', 'addr']; - $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => normalise_link($gcontact['url'])]); + $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($gcontact['url'])]); if (DBA::isResult($gcnt)) { if (!isset($gcontact['network']) && ($gcnt["network"] != Protocol::STATUSNET)) { $gcontact['network'] = $gcnt["network"]; @@ -180,7 +181,7 @@ class GContact if ($gcontact['updated'] <= DBA::NULL_DATETIME) { $gcontact['updated'] = $gcnt["updated"]; } - if (!isset($gcontact['server_url']) && (normalise_link($gcnt["server_url"]) != normalise_link($gcnt["url"]))) { + if (!isset($gcontact['server_url']) && (Strings::normaliseLink($gcnt["server_url"]) != Strings::normaliseLink($gcnt["url"]))) { $gcontact['server_url'] = $gcnt["server_url"]; } if (!isset($gcontact['addr'])) { @@ -205,8 +206,8 @@ class GContact if ($alternate && ($gcontact['network'] == Protocol::OSTATUS)) { // Delete the old entry - if it exists - if (DBA::exists('gcontact', ['nurl' => normalise_link($orig_profile)])) { - DBA::delete('gcontact', ['nurl' => normalise_link($orig_profile)]); + if (DBA::exists('gcontact', ['nurl' => Strings::normaliseLink($orig_profile)])) { + DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($orig_profile)]); } } } @@ -658,7 +659,7 @@ class GContact DBA::lock('gcontact'); $fields = ['id', 'last_contact', 'last_failure', 'network']; - $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => normalise_link($contact["url"])]); + $gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($contact["url"])]); if (DBA::isResult($gcnt)) { $gcontact_id = $gcnt["id"]; @@ -683,7 +684,7 @@ class GContact DBA::escape($contact["addr"]), DBA::escape($contact["network"]), DBA::escape($contact["url"]), - DBA::escape(normalise_link($contact["url"])), + DBA::escape(Strings::normaliseLink($contact["url"])), DBA::escape($contact["photo"]), DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()), @@ -693,7 +694,7 @@ class GContact intval($contact["generation"]) ); - $condition = ['nurl' => normalise_link($contact["url"])]; + $condition = ['nurl' => Strings::normaliseLink($contact["url"])]; $cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]); if (DBA::isResult($cnt)) { $gcontact_id = $cnt["id"]; @@ -793,7 +794,7 @@ class GContact $contact["server_url"] = $data['baseurl']; } } else { - $contact["server_url"] = normalise_link($contact["server_url"]); + $contact["server_url"] = Strings::normaliseLink($contact["server_url"]); } if (($contact["addr"] == "") && ($contact["server_url"] != "") && ($contact["nick"] != "")) { @@ -822,7 +823,7 @@ class GContact if ($update) { Logger::log("Update gcontact for ".$contact["url"], Logger::DEBUG); $condition = ['`nurl` = ? AND (`generation` = 0 OR `generation` >= ?)', - normalise_link($contact["url"]), $contact["generation"]]; + Strings::normaliseLink($contact["url"]), $contact["generation"]]; $contact["updated"] = DateTimeFormat::utc($contact["updated"]); $updated = ['photo' => $contact['photo'], 'name' => $contact['name'], @@ -842,7 +843,7 @@ class GContact // This is used for the shadow copies of public items. /// @todo Check if we really should do this. // The quality of the gcontact table is mostly lower than the public contact - $public_contact = DBA::selectFirst('contact', ['id'], ['nurl' => normalise_link($contact["url"]), 'uid' => 0]); + $public_contact = DBA::selectFirst('contact', ['id'], ['nurl' => Strings::normaliseLink($contact["url"]), 'uid' => 0]); if (DBA::isResult($public_contact)) { Logger::log("Update public contact ".$public_contact["id"], Logger::DEBUG); diff --git a/src/Model/Item.php b/src/Model/Item.php index 5a44796773..a96c77921d 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -1535,7 +1535,7 @@ class Item extends BaseObject Logger::log("Checking if parent ".$parent_id." has to be tagged as mention for user ".$item['uid'], Logger::DEBUG); $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]); if (DBA::isResult($user)) { - $self = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']); + $self = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']); $self_id = Contact::getIdForURL($self, 0, true); Logger::log("'myself' is ".$self_id." for parent ".$parent_id." checking against ".$item['author-id']." and ".$item['owner-id'], Logger::DEBUG); if (($item['author-id'] == $self_id) || ($item['owner-id'] == $self_id)) { @@ -2545,13 +2545,13 @@ class Item extends BaseObject return; } - $link = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']); + $link = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']); /* * Diaspora uses their own hardwired link URL in @-tags * instead of the one we supply with webfinger */ - $dlink = normalise_link(System::baseUrl() . '/u/' . $user['nickname']); + $dlink = Strings::normaliseLink(System::baseUrl() . '/u/' . $user['nickname']); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER); if ($cnt) { diff --git a/src/Model/Profile.php b/src/Model/Profile.php index be667ee60f..b6a7546022 100644 --- a/src/Model/Profile.php +++ b/src/Model/Profile.php @@ -327,9 +327,9 @@ class Profile // Is the local user already connected to that user? if ($connect && local_user()) { if (isset($profile['url'])) { - $profile_url = normalise_link($profile['url']); + $profile_url = Strings::normaliseLink($profile['url']); } else { - $profile_url = normalise_link(System::baseUrl() . '/profile/' . $profile['nickname']); + $profile_url = Strings::normaliseLink(System::baseUrl() . '/profile/' . $profile['nickname']); } if (DBA::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) { @@ -371,7 +371,7 @@ class Profile $r = q( "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d", intval($profile['uid']), - DBA::escape(normalise_link(self::getMyURL())), + DBA::escape(Strings::normaliseLink(self::getMyURL())), intval(Contact::FRIEND) ); } diff --git a/src/Model/User.php b/src/Model/User.php index 84083b868f..7447c02740 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -61,7 +61,7 @@ class User */ public static function getIdForURL($url) { - $self = DBA::selectFirst('contact', ['uid'], ['nurl' => normalise_link($url), 'self' => true]); + $self = DBA::selectFirst('contact', ['uid'], ['nurl' => Strings::normaliseLink($url), 'self' => true]); if (!DBA::isResult($self)) { return false; } else { diff --git a/src/Module/Contact.php b/src/Module/Contact.php index faf1ecad5f..30c05c889a 100644 --- a/src/Module/Contact.php +++ b/src/Module/Contact.php @@ -304,7 +304,7 @@ class Contact extends BaseModule } } - $fields['nurl'] = normalise_link($data['url']); + $fields['nurl'] = Strings::normaliseLink($data['url']); if (!empty($data['priority'])) { $fields['priority'] = intval($data['priority']); diff --git a/src/Module/Magic.php b/src/Module/Magic.php index a94339a6e9..ecfe18e596 100644 --- a/src/Module/Magic.php +++ b/src/Module/Magic.php @@ -50,7 +50,7 @@ class Magic extends BaseModule $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); // Redirect if the contact is already authenticated on this site. - if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], normalise_link(self::getApp()->getBaseURL())) !== false) { + if (!empty($a->contact) && array_key_exists('id', $a->contact) && strpos($contact['nurl'], Strings::normaliseLink(self::getApp()->getBaseURL())) !== false) { if ($test) { $ret['success'] = true; $ret['message'] .= 'Local site - you are already authenticated.' . EOL; diff --git a/src/Network/Probe.php b/src/Network/Probe.php index 030de41299..60250a5a00 100644 --- a/src/Network/Probe.php +++ b/src/Network/Probe.php @@ -348,7 +348,7 @@ class Probe } if (x($data, "photo")) { - $data["baseurl"] = Network::getUrlMatch(normalise_link(defaults($data, "baseurl", "")), normalise_link($data["photo"])); + $data["baseurl"] = Network::getUrlMatch(Strings::normaliseLink(defaults($data, "baseurl", "")), Strings::normaliseLink($data["photo"])); } else { $data["photo"] = System::baseUrl().'/images/person-300.jpg'; } @@ -427,7 +427,7 @@ class Probe $fields['updated'] = DateTimeFormat::utcNow(); - $condition = ['nurl' => normalise_link($data["url"])]; + $condition = ['nurl' => Strings::normaliseLink($data["url"])]; $old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition); @@ -474,7 +474,7 @@ class Probe } } - $condition = ['nurl' => normalise_link($data["url"]), 'self' => false, 'uid' => 0]; + $condition = ['nurl' => Strings::normaliseLink($data["url"]), 'self' => false, 'uid' => 0]; // "$old_fields" will return a "false" when the contact doesn't exist. // This won't trigger an insert. This is intended, since we only need @@ -1010,7 +1010,7 @@ class Probe foreach ($webfinger["aliases"] as $alias) { if (empty($data["url"]) && !strstr($alias, "@")) { $data["url"] = $alias; - } elseif (!strstr($alias, "@") && normalise_link($alias) != normalise_link($data["url"])) { + } elseif (!strstr($alias, "@") && Strings::normaliseLink($alias) != Strings::normaliseLink($data["url"])) { $data["alias"] = $alias; } elseif (substr($alias, 0, 5) == 'acct:') { $data["addr"] = substr($alias, 5); @@ -1213,7 +1213,7 @@ class Probe if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { foreach ($webfinger["aliases"] as $alias) { - if (normalise_link($alias) != normalise_link($data["url"]) && ! strstr($alias, "@")) { + if (Strings::normaliseLink($alias) != Strings::normaliseLink($data["url"]) && ! strstr($alias, "@")) { $data["alias"] = $alias; } elseif (substr($alias, 0, 5) == 'acct:') { $data["addr"] = substr($alias, 5); @@ -1269,14 +1269,14 @@ class Probe if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { foreach ($webfinger["aliases"] as $alias) { - if (strstr($alias, "@") && !strstr(normalise_link($alias), "http://")) { + if (strstr($alias, "@") && !strstr(Strings::normaliseLink($alias), "http://")) { $data["addr"] = str_replace('acct:', '', $alias); } } } if (!empty($webfinger["subject"]) && strstr($webfinger["subject"], "@") - && !strstr(normalise_link($webfinger["subject"]), "http://") + && !strstr(Strings::normaliseLink($webfinger["subject"]), "http://") ) { $data["addr"] = str_replace('acct:', '', $webfinger["subject"]); } @@ -1302,7 +1302,7 @@ class Probe } else { $pubkey = substr($pubkey, 5); } - } elseif (normalise_link($pubkey) == 'http://') { + } elseif (Strings::normaliseLink($pubkey) == 'http://') { $curlResult = Network::curl($pubkey); if ($curlResult->isTimeout()) { return false; diff --git a/src/Protocol/ActivityPub/Processor.php b/src/Protocol/ActivityPub/Processor.php index 5dadc029f9..bff8767f38 100644 --- a/src/Protocol/ActivityPub/Processor.php +++ b/src/Protocol/ActivityPub/Processor.php @@ -5,6 +5,8 @@ namespace Friendica\Protocol\ActivityPub; use Friendica\Database\DBA; +use Friendica\Content\Text\HTML; +use Friendica\Core\Config; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Model\Conversation; @@ -13,11 +15,10 @@ use Friendica\Model\APContact; use Friendica\Model\Item; use Friendica\Model\Event; use Friendica\Model\User; -use Friendica\Content\Text\HTML; -use Friendica\Util\JsonLD; -use Friendica\Core\Config; use Friendica\Protocol\ActivityPub; use Friendica\Util\DateTimeFormat; +use Friendica\Util\JsonLD; +use Friendica\Util\Strings; /** * ActivityPub Processor Protocol class @@ -417,7 +418,7 @@ class Processor return; } - $contacts = DBA::select('contact', ['id'], ['nurl' => normalise_link($activity['object_id'])]); + $contacts = DBA::select('contact', ['id'], ['nurl' => Strings::normaliseLink($activity['object_id'])]); while ($contact = DBA::fetch($contacts)) { Contact::remove($contact['id']); } diff --git a/src/Protocol/ActivityPub/Receiver.php b/src/Protocol/ActivityPub/Receiver.php index c958b9d6c3..686ac8be32 100644 --- a/src/Protocol/ActivityPub/Receiver.php +++ b/src/Protocol/ActivityPub/Receiver.php @@ -5,18 +5,19 @@ namespace Friendica\Protocol\ActivityPub; use Friendica\Database\DBA; -use Friendica\Util\HTTPSignature; use Friendica\Core\Logger; use Friendica\Core\Protocol; use Friendica\Model\Contact; use Friendica\Model\APContact; +use Friendica\Model\Conversation; use Friendica\Model\Item; use Friendica\Model\User; +use Friendica\Protocol\ActivityPub; +use Friendica\Util\DateTimeFormat; +use Friendica\Util\HTTPSignature; use Friendica\Util\JsonLD; use Friendica\Util\LDSignature; -use Friendica\Protocol\ActivityPub; -use Friendica\Model\Conversation; -use Friendica\Util\DateTimeFormat; +use Friendica\Util\Strings; /** * @brief ActivityPub Receiver Protocol class @@ -455,7 +456,7 @@ class Receiver if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) { // This will most likely catch all OStatus connections to Mastodon - $condition = ['alias' => [$actor, normalise_link($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND] + $condition = ['alias' => [$actor, Strings::normaliseLink($actor)], 'rel' => [Contact::SHARING, Contact::FRIEND] , 'archive' => false, 'pending' => false]; $contacts = DBA::select('contact', ['uid'], $condition); while ($contact = DBA::fetch($contacts)) { @@ -472,7 +473,7 @@ class Receiver } // Fetching all directly addressed receivers - $condition = ['self' => true, 'nurl' => normalise_link($receiver)]; + $condition = ['self' => true, 'nurl' => Strings::normaliseLink($receiver)]; $contact = DBA::selectFirst('contact', ['uid', 'contact-type'], $condition); if (!DBA::isResult($contact)) { continue; @@ -482,7 +483,7 @@ class Receiver // Exception: The receiver is targetted via "to" or this is a comment if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY)) { $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; - $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND], + $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND], 'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']]; // Forum posts are only accepted from forum contacts @@ -516,7 +517,7 @@ class Receiver { $receivers = []; $networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; - $condition = ['nurl' => normalise_link($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER], + $condition = ['nurl' => Strings::normaliseLink($actor), 'rel' => [Contact::SHARING, Contact::FRIEND, Contact::FOLLOWER], 'network' => $networks, 'archive' => false, 'pending' => false]; $contacts = DBA::select('contact', ['uid', 'rel'], $condition); while ($contact = DBA::fetch($contacts)) { @@ -589,7 +590,7 @@ class Receiver unset($profile['photo']); unset($profile['baseurl']); - $profile['nurl'] = normalise_link($profile['url']); + $profile['nurl'] = Strings::normaliseLink($profile['url']); DBA::update('contact', $profile, ['id' => $cid]); Contact::updateAvatar($photo, $uid, $cid); @@ -614,12 +615,12 @@ class Receiver } foreach ($receivers as $receiver) { - $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => normalise_link($actor)]); + $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'nurl' => Strings::normaliseLink($actor)]); if (DBA::isResult($contact)) { self::switchContact($contact['id'], $receiver, $actor); } - $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [normalise_link($actor), $actor]]); + $contact = DBA::selectFirst('contact', ['id'], ['uid' => $receiver, 'network' => Protocol::OSTATUS, 'alias' => [Strings::normaliseLink($actor), $actor]]); if (DBA::isResult($contact)) { self::switchContact($contact['id'], $receiver, $actor); } diff --git a/src/Protocol/DFRN.php b/src/Protocol/DFRN.php index 7f7e52f54f..a430b26468 100644 --- a/src/Protocol/DFRN.php +++ b/src/Protocol/DFRN.php @@ -1097,7 +1097,7 @@ class DFRN } foreach ($mentioned as $mention) { - $condition = ['uid' => $owner["uid"], 'nurl' => normalise_link($mention)]; + $condition = ['uid' => $owner["uid"], 'nurl' => Strings::normaliseLink($mention)]; $contact = DBA::selectFirst('contact', ['forum', 'prv'], $condition); if (DBA::isResult($contact) && ($contact["forum"] || $contact["prv"])) { @@ -1569,7 +1569,7 @@ class DFRN $fields = ['id', 'uid', 'url', 'network', 'avatar-date', 'avatar', 'name-date', 'uri-date', 'addr', 'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type']; $condition = ["`uid` = ? AND `nurl` = ? AND `network` != ?", - $importer["importer_uid"], normalise_link($author["link"]), Protocol::STATUSNET]; + $importer["importer_uid"], Strings::normaliseLink($author["link"]), Protocol::STATUSNET]; $contact_old = DBA::selectFirst('contact', $fields, $condition); if (DBA::isResult($contact_old)) { @@ -1960,7 +1960,7 @@ class DFRN * * @see https://github.com/friendica/friendica/pull/3254#discussion_r107315246 */ - $condition = ['name' => $suggest["name"], 'nurl' => normalise_link($suggest["url"]), + $condition = ['name' => $suggest["name"], 'nurl' => Strings::normaliseLink($suggest["url"]), 'uid' => $suggest["uid"]]; if (DBA::exists('contact', $condition)) { return false; @@ -2100,18 +2100,18 @@ class DFRN $relocate["server_url"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $relocate["url"]); $fields = ['name' => $relocate["name"], 'photo' => $relocate["avatar"], - 'url' => $relocate["url"], 'nurl' => normalise_link($relocate["url"]), + 'url' => $relocate["url"], 'nurl' => Strings::normaliseLink($relocate["url"]), 'addr' => $relocate["addr"], 'connect' => $relocate["addr"], 'notify' => $relocate["notify"], 'server_url' => $relocate["server_url"]]; - DBA::update('gcontact', $fields, ['nurl' => normalise_link($old["url"])]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($old["url"])]); // Update the contact table. We try to find every entry. $fields = ['name' => $relocate["name"], 'avatar' => $relocate["avatar"], - 'url' => $relocate["url"], 'nurl' => normalise_link($relocate["url"]), + 'url' => $relocate["url"], 'nurl' => Strings::normaliseLink($relocate["url"]), 'addr' => $relocate["addr"], 'request' => $relocate["request"], 'confirm' => $relocate["confirm"], 'notify' => $relocate["notify"], 'poll' => $relocate["poll"], 'site-pubkey' => $relocate["sitepubkey"]]; - $condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], normalise_link($old["url"])]; + $condition = ["(`id` = ?) OR (`nurl` = ?)", $importer["id"], Strings::normaliseLink($old["url"])]; DBA::update('contact', $fields, $condition); @@ -2986,7 +2986,7 @@ class DFRN return; } $baseurl = substr($baseurl, $domain_st + 3); - $nurl = normalise_link($baseurl); + $nurl = Strings::normaliseLink($baseurl); /// @todo Why is there a query for "url" *and* "nurl"? Especially this normalising is strange. $r = q("SELECT `id` FROM `contact` WHERE `uid` = (SELECT `uid` FROM `user` WHERE `nickname` = '%s' LIMIT 1) @@ -3079,13 +3079,13 @@ class DFRN $community_page = ($user['page-flags'] == Contact::PAGE_COMMUNITY); $prvgroup = ($user['page-flags'] == Contact::PAGE_PRVGROUP); - $link = normalise_link(System::baseUrl() . '/profile/' . $user['nickname']); + $link = Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname']); /* * Diaspora uses their own hardwired link URL in @-tags * instead of the one we supply with webfinger */ - $dlink = normalise_link(System::baseUrl() . '/u/' . $user['nickname']); + $dlink = Strings::normaliseLink(System::baseUrl() . '/u/' . $user['nickname']); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER); if ($cnt) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 657009e776..4af08a3ac1 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -147,7 +147,7 @@ class Diaspora $fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked']; // Fetch the relay contact - $condition = ['uid' => 0, 'nurl' => normalise_link($server_url), + $condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url), 'contact-type' => Contact::ACCOUNT_TYPE_RELAY]; $contact = DBA::selectFirst('contact', $fields, $condition); @@ -186,7 +186,7 @@ class Diaspora $fields = array_merge($fields, $network_fields); - $condition = ['uid' => 0, 'nurl' => normalise_link($server_url), + $condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url), 'contact-type' => Contact::ACCOUNT_TYPE_RELAY]; if (DBA::exists('contact', $condition)) { @@ -1434,7 +1434,7 @@ class Diaspora */ private static function authorContactByUrl($def_contact, $person, $uid) { - $condition = ['nurl' => normalise_link($person["url"]), 'uid' => $uid]; + $condition = ['nurl' => Strings::normaliseLink($person["url"]), 'uid' => $uid]; $contact = DBA::selectFirst('contact', ['id', 'network'], $condition); if (DBA::isResult($contact)) { $cid = $contact["id"]; @@ -1536,7 +1536,7 @@ class Diaspora return false; } - $fields = ['url' => $data['url'], 'nurl' => normalise_link($data['url']), + $fields = ['url' => $data['url'], 'nurl' => Strings::normaliseLink($data['url']), 'name' => $data['name'], 'nick' => $data['nick'], 'addr' => $data['addr'], 'batch' => $data['batch'], 'notify' => $data['notify'], 'poll' => $data['poll'], @@ -1544,7 +1544,7 @@ class Diaspora DBA::update('contact', $fields, ['addr' => $old_handle]); - $fields = ['url' => $data['url'], 'nurl' => normalise_link($data['url']), + $fields = ['url' => $data['url'], 'nurl' => Strings::normaliseLink($data['url']), 'name' => $data['name'], 'nick' => $data['nick'], 'addr' => $data['addr'], 'connect' => $data['addr'], 'notify' => $data['notify'], 'photo' => $data['photo'], @@ -2392,7 +2392,7 @@ class Diaspora DBA::escape($ret["addr"]), DateTimeFormat::utcNow(), DBA::escape($ret["url"]), - DBA::escape(normalise_link($ret["url"])), + DBA::escape(Strings::normaliseLink($ret["url"])), DBA::escape($batch), DBA::escape($ret["name"]), DBA::escape($ret["nick"]), diff --git a/src/Protocol/OStatus.php b/src/Protocol/OStatus.php index a1857c5db7..0c096c25a8 100644 --- a/src/Protocol/OStatus.php +++ b/src/Protocol/OStatus.php @@ -26,6 +26,7 @@ use Friendica\Object\Image; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; use Friendica\Util\Proxy as ProxyUtils; +use Friendica\Util\Strings; use Friendica\Util\XML; require_once 'include/dba.php'; @@ -98,7 +99,7 @@ class OStatus } $condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ? AND `rel` IN (?, ?)", - $importer["uid"], normalise_link($author["author-link"]), normalise_link($aliaslink), + $importer["uid"], Strings::normaliseLink($author["author-link"]), Strings::normaliseLink($aliaslink), Protocol::STATUSNET, Contact::SHARING, Contact::FRIEND]; $contact = DBA::selectFirst('contact', [], $condition); } @@ -164,7 +165,7 @@ class OStatus // $contact["poll"] = $value; $contact['url'] = $author["author-link"]; - $contact['nurl'] = normalise_link($contact['url']); + $contact['nurl'] = Strings::normaliseLink($contact['url']); $value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context); if ($value != "") { @@ -209,7 +210,7 @@ class OStatus // Update it with the current values $fields = ['url' => $author["author-link"], 'name' => $contact["name"], - 'nurl' => normalise_link($author["author-link"]), + 'nurl' => Strings::normaliseLink($author["author-link"]), 'nick' => $contact["nick"], 'alias' => $contact["alias"], 'about' => $contact["about"], 'location' => $contact["location"], 'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()]; @@ -1599,7 +1600,7 @@ class OStatus { $r = q( "SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1", - DBA::escape(normalise_link($url)), + DBA::escape(Strings::normaliseLink($url)), intval($owner["uid"]) ); if (DBA::isResult($r)) { @@ -1608,7 +1609,7 @@ class OStatus } if (!DBA::isResult($r)) { - $gcontact = DBA::selectFirst('gcontact', [], ['nurl' => normalise_link($url)]); + $gcontact = DBA::selectFirst('gcontact', [], ['nurl' => Strings::normaliseLink($url)]); if (DBA::isResult($r)) { $contact = $gcontact; $contact["uid"] = -1; @@ -1651,7 +1652,7 @@ class OStatus */ private static function reshareEntry(DOMDocument $doc, array $item, array $owner, $repeated_guid, $toplevel) { - if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) { + if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } @@ -1714,7 +1715,7 @@ class OStatus */ private static function likeEntry(DOMDocument $doc, array $item, array $owner, $toplevel) { - if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) { + if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } @@ -1811,7 +1812,7 @@ class OStatus $item['follow'] = $contact['alias']; } - $condition = ['uid' => $owner['uid'], 'nurl' => normalise_link($contact["url"])]; + $condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($contact["url"])]; $user_contact = DBA::selectFirst('contact', ['id'], $condition); if (DBA::isResult($user_contact)) { @@ -1861,7 +1862,7 @@ class OStatus */ private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel) { - if (($item["id"] != $item["parent"]) && (normalise_link($item["author-link"]) != normalise_link($owner["url"]))) { + if (($item["id"] != $item["parent"]) && (Strings::normaliseLink($item["author-link"]) != Strings::normaliseLink($owner["url"]))) { Logger::log("OStatus entry is from author ".$owner["url"]." - not from ".$item["author-link"].". Quitting.", Logger::DEBUG); } @@ -2048,7 +2049,7 @@ class OStatus $mentioned = $newmentions; foreach ($mentioned as $mention) { - $condition = ['uid' => $owner['uid'], 'nurl' => normalise_link($mention)]; + $condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($mention)]; $contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition); if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) || ($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) { diff --git a/src/Protocol/PortableContact.php b/src/Protocol/PortableContact.php index 9c22a21631..7243da523f 100644 --- a/src/Protocol/PortableContact.php +++ b/src/Protocol/PortableContact.php @@ -23,6 +23,7 @@ use Friendica\Model\Profile; use Friendica\Network\Probe; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; +use Friendica\Util\Strings; use Friendica\Util\XML; require_once 'include/dba.php'; @@ -284,7 +285,7 @@ class PortableContact $r = q( "SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`", - DBA::escape(normalise_link($server_url)) + DBA::escape(Strings::normaliseLink($server_url)) ); if (DBA::isResult($r)) { @@ -309,7 +310,7 @@ class PortableContact { $gcontacts = q( "SELECT * FROM `gcontact` WHERE `nurl` = '%s'", - DBA::escape(normalise_link($profile)) + DBA::escape(Strings::normaliseLink($profile)) ); if (!DBA::isResult($gcontacts)) { @@ -324,7 +325,7 @@ class PortableContact $server_url = ''; if ($force) { - $server_url = normalise_link(self::detectServer($profile)); + $server_url = Strings::normaliseLink(self::detectServer($profile)); } if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) { @@ -332,7 +333,7 @@ class PortableContact } if (!$force && (($server_url == '') || ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) { - $server_url = normalise_link(self::detectServer($profile)); + $server_url = Strings::normaliseLink(self::detectServer($profile)); } if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) { @@ -344,7 +345,7 @@ class PortableContact if (!self::checkServer($server_url, $gcontacts[0]["network"], $force)) { if ($force) { $fields = ['last_failure' => DateTimeFormat::utcNow()]; - DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]); } Logger::log("Profile ".$profile.": Server ".$server_url." wasn't reachable.", Logger::DEBUG); @@ -356,7 +357,7 @@ class PortableContact if (in_array($gcontacts[0]["network"], ["", Protocol::FEED])) { $server = q( "SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''", - DBA::escape(normalise_link($server_url)) + DBA::escape(Strings::normaliseLink($server_url)) ); if ($server) { @@ -369,7 +370,7 @@ class PortableContact // noscrape is really fast so we don't cache the call. if (($server_url != "") && ($gcontacts[0]["nick"] != "")) { // Use noscrape if possible - $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", DBA::escape(normalise_link($server_url))); + $server = q("SELECT `noscrape`, `network` FROM `gserver` WHERE `nurl` = '%s' AND `noscrape` != ''", DBA::escape(Strings::normaliseLink($server_url))); if ($server) { $curlResult = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); @@ -425,7 +426,7 @@ class PortableContact if (!empty($noscrape["updated"])) { $fields = ['last_contact' => DateTimeFormat::utcNow()]; - DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]); Logger::log("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", Logger::DEBUG); @@ -449,11 +450,11 @@ class PortableContact // Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711) // Then check the other link and delete this one if (($data["network"] == Protocol::OSTATUS) && self::alternateOStatusUrl($profile) - && (normalise_link($profile) == normalise_link($data["alias"])) - && (normalise_link($profile) != normalise_link($data["url"])) + && (Strings::normaliseLink($profile) == Strings::normaliseLink($data["alias"])) + && (Strings::normaliseLink($profile) != Strings::normaliseLink($data["url"])) ) { // Delete the old entry - DBA::delete('gcontact', ['nurl' => normalise_link($profile)]); + DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($profile)]); $gcontact = array_merge($gcontacts[0], $data); @@ -474,7 +475,7 @@ class PortableContact if (($data["poll"] == "") || (in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM]))) { $fields = ['last_failure' => DateTimeFormat::utcNow()]; - DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]); Logger::log("Profile ".$profile." wasn't reachable (profile)", Logger::DEBUG); return false; @@ -490,7 +491,7 @@ class PortableContact if (!$curlResult->isSuccess()) { $fields = ['last_failure' => DateTimeFormat::utcNow()]; - DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]); Logger::log("Profile ".$profile." wasn't reachable (no feed)", Logger::DEBUG); return false; @@ -533,11 +534,11 @@ class PortableContact $fields['updated'] = $last_updated; } - DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]); if (($gcontacts[0]["generation"] == 0)) { $fields = ['generation' => 9]; - DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]); + DBA::update('gcontact', $fields, ['nurl' => Strings::normaliseLink($profile)]); } Logger::log("Profile ".$profile." was last updated at ".$last_updated, Logger::DEBUG); @@ -930,11 +931,11 @@ class PortableContact return false; } - $gserver = DBA::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]); + $gserver = DBA::selectFirst('gserver', [], ['nurl' => Strings::normaliseLink($server_url)]); if (DBA::isResult($gserver)) { if ($gserver["created"] <= DBA::NULL_DATETIME) { $fields = ['created' => DateTimeFormat::utcNow()]; - $condition = ['nurl' => normalise_link($server_url)]; + $condition = ['nurl' => Strings::normaliseLink($server_url)]; DBA::update('gserver', $fields, $condition); } $poco = $gserver["poco"]; @@ -990,7 +991,7 @@ class PortableContact // Mastodon uses the "@" for user profiles. // But this can be misunderstood. if (parse_url($server_url, PHP_URL_USER) != '') { - DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]); + DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]); return false; } @@ -1006,7 +1007,7 @@ class PortableContact if (DBA::isResult($gserver) && ($orig_server_url == $server_url) && ($curlResult->isTimeout())) { Logger::log("Connection to server ".$server_url." timed out.", Logger::DEBUG); - DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]); + DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]); return false; } @@ -1021,7 +1022,7 @@ class PortableContact // Quit if there is a timeout if ($curlResult->isTimeout()) { Logger::log("Connection to server " . $server_url . " timed out.", Logger::DEBUG); - DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]); + DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => Strings::normaliseLink($server_url)]); return false; } @@ -1048,7 +1049,7 @@ class PortableContact if (!$failure) { // This will be too low, but better than no value at all. - $registered_users = DBA::count('gcontact', ['server_url' => normalise_link($server_url)]); + $registered_users = DBA::count('gcontact', ['server_url' => Strings::normaliseLink($server_url)]); } // Look for poco @@ -1410,7 +1411,7 @@ class PortableContact } // Check again if the server exists - $found = DBA::exists('gserver', ['nurl' => normalise_link($server_url)]); + $found = DBA::exists('gserver', ['nurl' => Strings::normaliseLink($server_url)]); $version = strip_tags($version); $site_name = strip_tags($site_name); @@ -1424,9 +1425,9 @@ class PortableContact 'last_contact' => $last_contact, 'last_failure' => $last_failure]; if ($found) { - DBA::update('gserver', $fields, ['nurl' => normalise_link($server_url)]); + DBA::update('gserver', $fields, ['nurl' => Strings::normaliseLink($server_url)]); } elseif (!$failure) { - $fields['nurl'] = normalise_link($server_url); + $fields['nurl'] = Strings::normaliseLink($server_url); $fields['created'] = DateTimeFormat::utcNow(); DBA::insert('gserver', $fields); } @@ -1461,7 +1462,7 @@ class PortableContact return; } - $gserver = DBA::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => normalise_link($server_url)]); + $gserver = DBA::selectFirst('gserver', ['id', 'relay-subscribe', 'relay-scope'], ['nurl' => Strings::normaliseLink($server_url)]); if (!DBA::isResult($gserver)) { return; @@ -1560,7 +1561,7 @@ class PortableContact foreach ($serverlist as $server) { $server_url = str_replace("/index.php", "", $server['url']); - $r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(normalise_link($server_url))); + $r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(Strings::normaliseLink($server_url))); if (!DBA::isResult($r)) { Logger::log("Call server check for server ".$server_url, Logger::DEBUG); diff --git a/src/Protocol/Salmon.php b/src/Protocol/Salmon.php index 1192781801..47376890d5 100644 --- a/src/Protocol/Salmon.php +++ b/src/Protocol/Salmon.php @@ -52,7 +52,7 @@ class Salmon } else { $ret[$x] = substr($ret[$x], 5); } - } elseif (normalise_link($ret[$x]) == 'http://') { + } elseif (Strings::normaliseLink($ret[$x]) == 'http://') { $ret[$x] = Network::fetchUrl($ret[$x]); } } diff --git a/src/Util/Network.php b/src/Util/Network.php index 0ff34f120a..0ac0f2aeb7 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -9,6 +9,7 @@ use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Core\Config; use Friendica\Network\CurlResult; +use Friendica\Util\Strings; use DOMDocument; use DomXPath; @@ -718,8 +719,8 @@ class Network return ""; } - $url1 = normalise_link($url1); - $url2 = normalise_link($url2); + $url1 = Strings::normaliseLink($url1); + $url2 = Strings::normaliseLink($url2); $parts1 = parse_url($url1); $parts2 = parse_url($url2); @@ -790,7 +791,7 @@ class Network $match .= $path; - return normalise_link($match); + return Strings::normaliseLink($match); } /** diff --git a/src/Util/ParseUrl.php b/src/Util/ParseUrl.php index 6530959f23..1188214200 100644 --- a/src/Util/ParseUrl.php +++ b/src/Util/ParseUrl.php @@ -12,6 +12,7 @@ use Friendica\Core\Addon; use Friendica\Core\Logger; use Friendica\Database\DBA; use Friendica\Object\Image; +use Friendica\Util\Strings; require_once 'include/dba.php'; @@ -49,7 +50,7 @@ class ParseUrl } $parsed_url = DBA::selectFirst('parsed_url', ['content'], - ['url' => normalise_link($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed] + ['url' => Strings::normaliseLink($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed] ); if (!empty($parsed_url['content'])) { $data = unserialize($parsed_url['content']); @@ -61,7 +62,7 @@ class ParseUrl DBA::insert( 'parsed_url', [ - 'url' => normalise_link($url), 'guessing' => !$no_guessing, + 'url' => Strings::normaliseLink($url), 'guessing' => !$no_guessing, 'oembed' => $do_oembed, 'content' => serialize($data), 'created' => DateTimeFormat::utcNow() ], diff --git a/src/Util/Proxy.php b/src/Util/Proxy.php index 8478ce868a..be70077f15 100644 --- a/src/Util/Proxy.php +++ b/src/Util/Proxy.php @@ -6,6 +6,7 @@ use Friendica\BaseModule; use Friendica\BaseObject; use Friendica\Core\Config; use Friendica\Core\System; +use Friendica\Util\Strings; /** * @brief Proxy utilities class @@ -76,7 +77,7 @@ class Proxy // Only continue if it isn't a local image and the isn't deactivated if (self::isLocalImage($url)) { - $url = str_replace(normalise_link(System::baseUrl()) . '/', System::baseUrl() . '/', $url); + $url = str_replace(Strings::normaliseLink(System::baseUrl()) . '/', System::baseUrl() . '/', $url); return $url; } @@ -140,7 +141,7 @@ class Proxy */ public static function proxifyHtml($html) { - $html = str_replace(normalise_link(System::baseUrl()) . '/', System::baseUrl() . '/', $html); + $html = str_replace(Strings::normaliseLink(System::baseUrl()) . '/', System::baseUrl() . '/', $html); return preg_replace_callback('/(]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'self::replaceUrl', $html); } @@ -162,8 +163,8 @@ class Proxy } // links normalised - bug #431 - $baseurl = normalise_link(System::baseUrl()); - $url = normalise_link($url); + $baseurl = Strings::normaliseLink(System::baseUrl()); + $url = Strings::normaliseLink($url); return (substr($url, 0, strlen($baseurl)) == $baseurl); } diff --git a/src/Util/Strings.php b/src/Util/Strings.php index 3febe60bd8..40109e67ee 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -369,7 +369,7 @@ class Strings * * @return string Normalized URL. */ - public static function normaliseLink($url) // normalise_link() + public static function normaliseLink($url) { $ret = str_replace(['https:', '//www.'], ['http:', '//'], $url); return rtrim($ret, '/'); diff --git a/src/Worker/Delivery.php b/src/Worker/Delivery.php index f67390f843..40230e3bdb 100644 --- a/src/Worker/Delivery.php +++ b/src/Worker/Delivery.php @@ -249,7 +249,7 @@ class Delivery extends BaseObject // perform local delivery if we are on the same site if (Strings::compareLink($basepath, System::baseUrl())) { - $condition = ['nurl' => normalise_link($contact['url']), 'self' => true]; + $condition = ['nurl' => Strings::normaliseLink($contact['url']), 'self' => true]; $target_self = DBA::selectFirst('contact', ['uid'], $condition); if (!DBA::isResult($target_self)) { return; diff --git a/src/Worker/DiscoverPoCo.php b/src/Worker/DiscoverPoCo.php index 72df3420e8..55eeec98f2 100644 --- a/src/Worker/DiscoverPoCo.php +++ b/src/Worker/DiscoverPoCo.php @@ -15,6 +15,7 @@ use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; use Friendica\Util\Network; +use Friendica\Util\Strings; class DiscoverPoCo { @@ -80,7 +81,7 @@ class DiscoverPoCo return; } $server_url = filter_var($server_url, FILTER_SANITIZE_URL); - if (substr(normalise_link($server_url), 0, 7) != "http://") { + if (substr(Strings::normaliseLink($server_url), 0, 7) != "http://") { return; } $result = "Checking server ".$server_url." - "; @@ -162,7 +163,7 @@ class DiscoverPoCo $urlparts = parse_url($user["url"]); if (!isset($urlparts["scheme"])) { DBA::update('gcontact', ['network' => Protocol::PHANTOM], - ['nurl' => normalise_link($user["url"])]); + ['nurl' => Strings::normaliseLink($user["url"])]); continue; } @@ -170,7 +171,7 @@ class DiscoverPoCo $networks = ["twitter.com" => Protocol::TWITTER, "identi.ca" => Protocol::PUMPIO]; DBA::update('gcontact', ['network' => $networks[$urlparts["host"]]], - ['nurl' => normalise_link($user["url"])]); + ['nurl' => Strings::normaliseLink($user["url"])]); continue; } @@ -179,7 +180,7 @@ class DiscoverPoCo if ($user["server_url"] != "") { - $force_update = (normalise_link($user["server_url"]) != normalise_link($server_url)); + $force_update = (Strings::normaliseLink($user["server_url"]) != Strings::normaliseLink($server_url)); $server_url = $user["server_url"]; } @@ -193,7 +194,7 @@ class DiscoverPoCo } } else { DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()], - ['nurl' => normalise_link($user["url"])]); + ['nurl' => Strings::normaliseLink($user["url"])]); } // Quit the loop after 3 minutes @@ -220,7 +221,7 @@ class DiscoverPoCo if (!empty($j->results)) { foreach ($j->results as $jj) { // Check if the contact already exists - $exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", normalise_link($jj->url)); + $exists = q("SELECT `id`, `last_contact`, `last_failure`, `updated` FROM `gcontact` WHERE `nurl` = '%s'", Strings::normaliseLink($jj->url)); if (DBA::isResult($exists)) { Logger::log("Profile ".$jj->url." already exists (".$search.")", Logger::DEBUG); diff --git a/src/Worker/GProbe.php b/src/Worker/GProbe.php index 55da28f914..4f51db2dfb 100644 --- a/src/Worker/GProbe.php +++ b/src/Worker/GProbe.php @@ -12,6 +12,7 @@ use Friendica\Database\DBA; use Friendica\Model\GContact; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; +use Friendica\Util\Strings; class GProbe { public static function execute($url = '') @@ -22,10 +23,10 @@ class GProbe { $r = q( "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", - DBA::escape(normalise_link($url)) + DBA::escape(Strings::normaliseLink($url)) ); - Logger::log("gprobe start for ".normalise_link($url), Logger::DEBUG); + Logger::log("gprobe start for ".Strings::normaliseLink($url), Logger::DEBUG); if (!DBA::isResult($r)) { // Is it a DDoS attempt? @@ -51,7 +52,7 @@ class GProbe { $r = q( "SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", - DBA::escape(normalise_link($url)) + DBA::escape(Strings::normaliseLink($url)) ); } if (DBA::isResult($r)) { @@ -61,7 +62,7 @@ class GProbe { } } - Logger::log("gprobe end for ".normalise_link($url), Logger::DEBUG); + Logger::log("gprobe end for ".Strings::normaliseLink($url), Logger::DEBUG); return; } } diff --git a/src/Worker/UpdateGContact.php b/src/Worker/UpdateGContact.php index b7a78b51f4..b927e61bbd 100644 --- a/src/Worker/UpdateGContact.php +++ b/src/Worker/UpdateGContact.php @@ -12,6 +12,7 @@ use Friendica\Database\DBA; use Friendica\Network\Probe; use Friendica\Protocol\PortableContact; use Friendica\Util\DateTimeFormat; +use Friendica\Util\Strings; class UpdateGContact { @@ -78,13 +79,13 @@ class UpdateGContact DBA::escape($data["nick"]), DBA::escape($data["addr"]), DBA::escape($data["photo"]), - DBA::escape(normalise_link($data["url"])) + DBA::escape(Strings::normaliseLink($data["url"])) ); q("UPDATE `contact` SET `addr` = '%s' WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'", DBA::escape($data["addr"]), - DBA::escape(normalise_link($data["url"])) + DBA::escape(Strings::normaliseLink($data["url"])) ); } } diff --git a/view/theme/vier/theme.php b/view/theme/vier/theme.php index fb4f66431b..9427f1f23b 100644 --- a/view/theme/vier/theme.php +++ b/view/theme/vier/theme.php @@ -21,6 +21,7 @@ use Friendica\Database\DBA; use Friendica\Model\Contact; use Friendica\Model\GContact; use Friendica\Util\Proxy as ProxyUtils; +use Friendica\Util\Strings; function vier_init(App $a) { @@ -277,7 +278,7 @@ function vier_community_info() $query .= ","; } - $query .= "'".DBA::escape(normalise_link(trim($helper)))."'"; + $query .= "'".DBA::escape(Strings::normaliseLink(trim($helper)))."'"; } $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);