Browse Source

normalise_link calls

implement normaliseLink function
tags/2019.01
Adam Magness 1 year ago
parent
commit
ffc406d819
54 changed files with 248 additions and 222 deletions
  1. +13
    -13
      include/api.php
  2. +1
    -1
      include/conversation.php
  3. +3
    -3
      include/enotify.php
  4. +2
    -2
      mod/admin.php
  5. +3
    -2
      mod/bookmarklet.php
  6. +3
    -3
      mod/common.php
  7. +2
    -1
      mod/crepair.php
  8. +3
    -2
      mod/delegate.php
  9. +4
    -4
      mod/dfrn_request.php
  10. +1
    -1
      mod/dirfind.php
  11. +3
    -2
      mod/display.php
  12. +2
    -1
      mod/fetch.php
  13. +3
    -3
      mod/follow.php
  14. +3
    -3
      mod/hovercard.php
  15. +2
    -1
      mod/maintenance.php
  16. +2
    -1
      mod/match.php
  17. +1
    -1
      mod/message.php
  18. +1
    -1
      mod/network.php
  19. +2
    -2
      mod/salmon.php
  20. +4
    -4
      mod/unfollow.php
  21. +3
    -3
      src/App.php
  22. +4
    -3
      src/Content/ContactSelector.php
  23. +2
    -2
      src/Content/OEmbed.php
  24. +3
    -2
      src/Content/Text/BBCode.php
  25. +3
    -2
      src/Content/Widget.php
  26. +2
    -1
      src/Core/Console/ArchiveContact.php
  27. +2
    -1
      src/Core/Console/GlobalCommunitySilence.php
  28. +1
    -1
      src/Core/Installer.php
  29. +3
    -2
      src/Core/UserImport.php
  30. +5
    -4
      src/Model/APContact.php
  31. +28
    -28
      src/Model/Contact.php
  32. +14
    -13
      src/Model/GContact.php
  33. +3
    -3
      src/Model/Item.php
  34. +3
    -3
      src/Model/Profile.php
  35. +1
    -1
      src/Model/User.php
  36. +1
    -1
      src/Module/Contact.php
  37. +1
    -1
      src/Module/Magic.php
  38. +8
    -8
      src/Network/Probe.php
  39. +5
    -4
      src/Protocol/ActivityPub/Processor.php
  40. +12
    -11
      src/Protocol/ActivityPub/Receiver.php
  41. +10
    -10
      src/Protocol/DFRN.php
  42. +6
    -6
      src/Protocol/Diaspora.php
  43. +11
    -10
      src/Protocol/OStatus.php
  44. +27
    -26
      src/Protocol/PortableContact.php
  45. +1
    -1
      src/Protocol/Salmon.php
  46. +4
    -3
      src/Util/Network.php
  47. +3
    -2
      src/Util/ParseUrl.php
  48. +5
    -4
      src/Util/Proxy.php
  49. +1
    -1
      src/Util/Strings.php
  50. +1
    -1
      src/Worker/Delivery.php
  51. +7
    -6
      src/Worker/DiscoverPoCo.php
  52. +5
    -4
      src/Worker/GProbe.php
  53. +3
    -2
      src/Worker/UpdateGContact.php
  54. +2
    -1
      view/theme/vier/theme.php

+ 13
- 13
include/api.php View File

@@ -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;
}



+ 1
- 1
include/conversation.php View File

@@ -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'];


+ 3
- 3
include/enotify.php View File

@@ -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;


+ 2
- 2
mod/admin.php View File

@@ -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)
{


+ 3
- 2
mod/bookmarklet.php View File

@@ -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"])) {


+ 3
- 3
mod/common.php View File

@@ -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'];
}


+ 2
- 1
mod/crepair.php View File

@@ -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",


+ 3
- 2
mod/delegate.php View File

@@ -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)
);


+ 4
- 4
mod/dfrn_request.php View File

@@ -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;


+ 1
- 1
mod/dirfind.php View File

@@ -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]));
}


+ 3
- 2
mod/display.php View File

@@ -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`


+ 2
- 1
mod/fetch.php View File

@@ -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");


+ 3
- 3
mod/follow.php View File

@@ -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' => '']];


+ 3
- 3
mod/hovercard.php View File

@@ -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);
}



+ 2
- 1
mod/maintenance.php View File

@@ -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;


+ 2
- 1
mod/match.php View File

@@ -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()),


+ 1
- 1
mod/message.php View File

@@ -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])))
);
}



+ 1
- 1
mod/network.php View File

@@ -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;
}


+ 2
- 2
mod/salmon.php View File

@@ -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'])
);



+ 4
- 4
mod/unfollow.php View File

@@ -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);



+ 3
- 3
src/App.php View File

@@ -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;


+ 4
- 3
src/Content/ContactSelector.php View File

@@ -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


+ 2
- 2
src/Content/OEmbed.php View File

@@ -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()


+ 3
- 2
src/Content/Text/BBCode.php View File

@@ -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 = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . $mention . ':</b></p>' . "\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? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
} else {
$text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\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? '<br />' : '') . OEmbed::getHTML($attributes['link']);
} catch (Exception $e) {


+ 3
- 2
src/Content/Widget.php View File

@@ -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'];
}


+ 2
- 1
src/Core/Console/ArchiveContact.php View File

@@ -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));
}


+ 2
- 1
src/Core/Console/GlobalCommunitySilence.php View File

@@ -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"]]);


+ 1
- 1
src/Core/Installer.php View File

@@ -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);
}


+ 3
- 2
src/Core/UserImport.php View File

@@ -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'];


+ 5
- 4
src/Model/APContact.php View File

@@ -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);



+ 28
- 28
src/Model/Contact.php View File

@@ -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),


+ 14
- 13
src/Model/GContact.php View File

@@ -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);



+ 3
- 3
src/Model/Item.php View File

@@ -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) {


+ 3
- 3
src/Model/Profile.php View File

@@ -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)
);
}


+ 1
- 1
src/Model/User.php View File

@@ -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 {


+ 1
- 1
src/Module/Contact.php View File

@@ -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']);


+ 1
- 1
src/Module/Magic.php View File

@@ -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;


+ 8
- 8
src/Network/Probe.php View File

@@ -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;


+ 5
- 4
src/Protocol/ActivityPub/Processor.php View File

@@ -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']);
}


+ 12
- 11
src/Protocol/ActivityPub/Receiver.php View File

@@ -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\Util\JsonLD;
use Friendica\Util\LDSignature;
use Friendica\Protocol\ActivityPub;
use Friendica\Model\Conversation;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD;
use Friendica\Util\LDSignature;
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);
}


+ 10
- 10
src/Protocol/DFRN.php View File

@@ -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) {


+ 6
- 6
src/Protocol/Diaspora.php View File

@@ -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"]),


+ 11
- 10
src/Protocol/OStatus.php View File

@@ -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))) {


+ 27
- 26
src/Protocol/PortableContact.php View File

@@ -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)]);
}