normalise_link calls

implement normaliseLink function
This commit is contained in:
Adam Magness 2018-11-08 11:28:29 -05:00
parent 5276c28a78
commit ffc406d819
54 changed files with 248 additions and 222 deletions

View file

@ -527,7 +527,7 @@ function api_get_user(App $a, $contact_id = null)
// Searching for contact URL // Searching for contact URL
if (!is_null($contact_id) && (intval($contact_id) == 0)) { 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; $url = $user;
$extra_query = "AND `contact`.`nurl` = '%s' "; $extra_query = "AND `contact`.`nurl` = '%s' ";
if (api_user() !== false) { if (api_user() !== false) {
@ -572,7 +572,7 @@ function api_get_user(App $a, $contact_id = null)
} }
if (is_null($user) && x($_GET, 'profileurl')) { 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' "; $extra_query = "AND `contact`.`nurl` = '%s' ";
if (api_user() !== false) { if (api_user() !== false) {
$extra_query .= "AND `contact`.`uid`=".intval(api_user()); $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."); 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)) { if (DBA::isResult($contact)) {
$network_name = ContactSelector::networkToName($contact['network'], $contact['url']); $network_name = ContactSelector::networkToName($contact['network'], $contact['url']);
@ -2663,7 +2663,7 @@ function api_get_entitities(&$text, $bbcode)
"id" => $start+1, "id" => $start+1,
"id_str" => (string)$start+1, "id_str" => (string)$start+1,
"indices" => [$start, $start+strlen($url)], "indices" => [$start, $start+strlen($url)],
"media_url" => normalise_link($media_url), "media_url" => Strings::normaliseLink($media_url),
"media_url_https" => $media_url, "media_url_https" => $media_url,
"url" => $url, "url" => $url,
"display_url" => $display_url, "display_url" => $display_url,
@ -3666,8 +3666,8 @@ function api_friendships_destroy($type)
$url = $contact["url"]; $url = $contact["url"];
$condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
$uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
normalise_link($url), $url]; Strings::normaliseLink($url), $url];
$contact = DBA::selectFirst('contact', [], $condition); $contact = DBA::selectFirst('contact', [], $condition);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
@ -3791,9 +3791,9 @@ function api_direct_messages_box($type, $box, $verbose)
foreach ($r as $item) { foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url) { if ($box == "inbox" || $item['from-url'] != $profile_url) {
$recipient = $user_info; $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) { } 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; $sender = $user_info;
} }
@ -4780,7 +4780,7 @@ function api_friendica_remoteauth()
throw new BadRequestException("Wrong parameters."); throw new BadRequestException("Wrong parameters.");
} }
$c_url = normalise_link($c_url); $c_url = Strings::normaliseLink($c_url);
// traditional DFRN // traditional DFRN
@ -4944,7 +4944,7 @@ function api_get_nick($profile)
$r = q( $r = q(
"SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'", "SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
DBA::escape(normalise_link($profile)) DBA::escape(Strings::normaliseLink($profile))
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -4954,7 +4954,7 @@ function api_get_nick($profile)
if (!$nick == "") { if (!$nick == "") {
$r = q( $r = q(
"SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'", "SELECT `nick` FROM `contact` WHERE `uid` = 0 AND `nurl` = '%s'",
DBA::escape(normalise_link($profile)) DBA::escape(Strings::normaliseLink($profile))
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -5837,9 +5837,9 @@ function api_friendica_direct_messages_search($type, $box = "")
foreach ($r as $item) { foreach ($r as $item) {
if ($box == "inbox" || $item['from-url'] != $profile_url) { if ($box == "inbox" || $item['from-url'] != $profile_url) {
$recipient = $user_info; $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) { } 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; $sender = $user_info;
} }

View file

@ -843,7 +843,7 @@ function item_photo_menu($item) {
$cid = 0; $cid = 0;
$network = ''; $network = '';
$rel = 0; $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); $contact = DBA::selectFirst('contact', ['id', 'network', 'rel'], $condition);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$cid = $contact['id']; $cid = $contact['id'];

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: // Check for invalid profile urls. 13 should be the shortest possible profile length:
// http://a.bc/d // http://a.bc/d
// Additionally check for invalid urls that would return the normalised value "http:" // 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)) if (!in_array($profile, $profiles2))
$profiles2[] = $profile; $profiles2[] = $profile;
$profile = normalise_link($profile); $profile = Strings::normaliseLink($profile);
if (!in_array($profile, $profiles2)) if (!in_array($profile, $profiles2))
$profiles2[] = $profile; $profiles2[] = $profile;
@ -762,7 +762,7 @@ function check_item_notification($itemid, $uid, $defaulttype = "") {
if (DBA::isResult($tags)) { if (DBA::isResult($tags)) {
foreach ($tags AS $tag) { 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); $r = DBA::exists('contact', $condition);
if ($r) { if ($r) {
$send_notification = true; $send_notification = true;

View file

@ -997,8 +997,8 @@ function admin_page_site_post(App $a)
$old_url = $a->getBaseURL(true); $old_url = $a->getBaseURL(true);
// Generate host names for relocation the addresses in the format user@address.tld // Generate host names for relocation the addresses in the format user@address.tld
$new_host = str_replace("http://", "@", normalise_link($new_url)); $new_host = str_replace("http://", "@", Strings::normaliseLink($new_url));
$old_host = str_replace("http://", "@", normalise_link($old_url)); $old_host = str_replace("http://", "@", Strings::normaliseLink($old_url));
function update_table(App $a, $table_name, $fields, $old_url, $new_url) function update_table(App $a, $table_name, $fields, $old_url, $new_url)
{ {

View file

@ -9,6 +9,7 @@ use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Module\Login; use Friendica\Module\Login;
use Friendica\Util\Strings;
require_once 'include/conversation.php'; require_once 'include/conversation.php';
require_once 'include/items.php'; require_once 'include/items.php';
@ -26,8 +27,8 @@ function bookmarklet_content(App $a)
return $o; return $o;
} }
$referer = normalise_link(defaults($_SERVER, 'HTTP_REFERER', '')); $referer = Strings::normaliseLink(defaults($_SERVER, 'HTTP_REFERER', ''));
$page = normalise_link(System::baseUrl() . "/bookmarklet"); $page = Strings::normaliseLink(System::baseUrl() . "/bookmarklet");
if (!strstr($referer, $page)) { if (!strstr($referer, $page)) {
if (empty($_REQUEST["url"])) { if (empty($_REQUEST["url"])) {

View file

@ -12,7 +12,7 @@ use Friendica\Database\DBA;
use Friendica\Model; use Friendica\Model;
use Friendica\Module; use Friendica\Module;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -67,11 +67,11 @@ function common_content(App $a)
} }
if (!$cid && Model\Profile::getMyURL()) { 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)) { if (DBA::isResult($contact)) {
$cid = $contact['id']; $cid = $contact['id'];
} else { } 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)) { if (DBA::isResult($gcontact)) {
$zcid = $gcontact['id']; $zcid = $gcontact['id'];
} }

View file

@ -12,6 +12,7 @@ use Friendica\Core\Renderer;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model; use Friendica\Model;
use Friendica\Module; use Friendica\Module;
use Friendica\Util\Strings;
function crepair_init(App $a) function crepair_init(App $a)
{ {
@ -61,7 +62,7 @@ function crepair_post(App $a)
$attag = defaults($_POST, 'attag' , ''); $attag = defaults($_POST, 'attag' , '');
$photo = defaults($_POST, 'photo' , ''); $photo = defaults($_POST, 'photo' , '');
$remote_self = defaults($_POST, 'remote_self', false); $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 $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", WHERE `id` = %d AND `uid` = %d",

View file

@ -12,6 +12,7 @@ use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Security; use Friendica\Util\Security;
use Friendica\Util\Strings;
require_once 'mod/settings.php'; require_once 'mod/settings.php';
@ -72,7 +73,7 @@ function delegate_content(App $a)
if (DBA::isResult($user)) { if (DBA::isResult($user)) {
$condition = [ $condition = [
'uid' => local_user(), 'uid' => local_user(),
'nurl' => normalise_link(System::baseUrl() . '/profile/' . $user['nickname']) 'nurl' => Strings::normaliseLink(System::baseUrl() . '/profile/' . $user['nickname'])
]; ];
if (DBA::exists('contact', $condition)) { if (DBA::exists('contact', $condition)) {
DBA::insert('manage', ['uid' => $user_id, 'mid' => local_user()]); 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 SUBSTRING_INDEX(`nurl`, '/', 3) = '%s'
AND `uid` = %d AND `uid` = %d
AND `network` = '%s' ", AND `network` = '%s' ",
DBA::escape(normalise_link(System::baseUrl())), DBA::escape(Strings::normaliseLink(System::baseUrl())),
intval(local_user()), intval(local_user()),
DBA::escape(Protocol::DFRN) DBA::escape(Protocol::DFRN)
); );

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) // 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", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND NOT `self` LIMIT 1",
intval(local_user()), intval(local_user()),
DBA::escape(normalise_link($dfrn_url)) DBA::escape(Strings::normaliseLink($dfrn_url))
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -142,7 +142,7 @@ function dfrn_request_post(App $a)
intval(local_user()), intval(local_user()),
DateTimeFormat::utcNow(), DateTimeFormat::utcNow(),
DBA::escape($dfrn_url), DBA::escape($dfrn_url),
DBA::escape(normalise_link($dfrn_url)), DBA::escape(Strings::normaliseLink($dfrn_url)),
$parms['addr'], $parms['addr'],
$parms['fn'], $parms['fn'],
$parms['nick'], $parms['nick'],
@ -381,7 +381,7 @@ function dfrn_request_post(App $a)
intval($uid), intval($uid),
DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()),
$parms['url'], $parms['url'],
DBA::escape(normalise_link($url)), DBA::escape(Strings::normaliseLink($url)),
$parms['addr'], $parms['addr'],
$parms['fn'], $parms['fn'],
$parms['nick'], $parms['nick'],
@ -503,7 +503,7 @@ function dfrn_request_content(App $a)
$confirm_key = x($_GET, 'confirm_key') ? $_GET['confirm_key'] : ""; $confirm_key = x($_GET, 'confirm_key') ? $_GET['confirm_key'] : "";
// Checking fastlane for validity // 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["dfrn_url"] = $dfrn_url;
$_POST["confirm_key"] = $confirm_key; $_POST["confirm_key"] = $confirm_key;
$_POST["localconfirm"] = 1; $_POST["localconfirm"] = 1;

View file

@ -54,7 +54,7 @@ function dirfind_content(App $a, $prefix = "") {
$search = substr($search,1); $search = substr($search,1);
$header = L10n::t('People Search - %s', $search); $header = L10n::t('People Search - %s', $search);
if ((Strings::isValidEmail($search) && Network::isEmailDomainValid($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); $user_data = Probe::uri($search);
$discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA])); $discover_user = (in_array($user_data["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::OSTATUS, Protocol::DIASPORA]));
} }

View file

@ -21,6 +21,7 @@ use Friendica\Model\Item;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Protocol\DFRN; use Friendica\Protocol\DFRN;
use Friendica\Util\Strings;
function display_init(App $a) function display_init(App $a)
{ {
@ -90,8 +91,8 @@ function display_init(App $a)
$profiledata = display_fetchauthor($a, $item); $profiledata = display_fetchauthor($a, $item);
if (strstr(normalise_link($profiledata["url"]), normalise_link(System::baseUrl()))) { if (strstr(Strings::normaliseLink($profiledata["url"]), Strings::normaliseLink(System::baseUrl()))) {
$nickname = str_replace(normalise_link(System::baseUrl())."/profile/", "", normalise_link($profiledata["url"])); $nickname = str_replace(Strings::normaliseLink(System::baseUrl())."/profile/", "", Strings::normaliseLink($profiledata["url"]));
if (($nickname != $a->user["nickname"])) { if (($nickname != $a->user["nickname"])) {
$profile = DBA::fetchFirst("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile` $profile = DBA::fetchFirst("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `contact`.`avatar-date` AS picdate, `user`.* FROM `profile`

View file

@ -10,6 +10,7 @@ use Friendica\Core\System;
use Friendica\Protocol\Diaspora; use Friendica\Protocol\Diaspora;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
use Friendica\Database\DBA; use Friendica\Database\DBA;
@ -35,7 +36,7 @@ function fetch_init(App $a)
$parts = parse_url($item["author-link"]); $parts = parse_url($item["author-link"]);
$host = $parts["scheme"]."://".$parts["host"]; $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); $location = $host."/fetch/".$a->argv[1]."/".urlencode($guid);
header("HTTP/1.1 301 Moved Permanently"); header("HTTP/1.1 301 Moved Permanently");

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 $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 (`nurl` = '%s' OR `alias` = '%s' OR `alias` = '%s') AND
`network` != '%s' LIMIT 1", `network` != '%s' LIMIT 1",
intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(normalise_link($url)), intval(local_user()), DBA::escape(Contact::FOLLOWER), DBA::escape(Protocol::DFRN), DBA::escape(Strings::normaliseLink($url)),
DBA::escape(normalise_link($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET)); DBA::escape(Strings::normaliseLink($url)), DBA::escape($url), DBA::escape(Protocol::STATUSNET));
if ($r) { if ($r) {
if ($r[0]['pending']) { if ($r[0]['pending']) {
@ -131,7 +131,7 @@ function follow_content(App $a)
$_SESSION['fastlane'] = $ret['url']; $_SESSION['fastlane'] = $ret['url'];
$r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'", $r = q("SELECT `id`, `location`, `about`, `keywords` FROM `gcontact` WHERE `nurl` = '%s'",
normalise_link($ret['url'])); Strings::normaliseLink($ret['url']));
if (!$r) { if (!$r) {
$r = [['location' => '', 'about' => '', 'keywords' => '']]; $r = [['location' => '', 'about' => '', 'keywords' => '']];

View file

@ -56,7 +56,7 @@ function hovercard_content()
$contact = []; $contact = [];
// if it's the url containing https it should be converted to http // 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) { if (!$nurl) {
return; return;
} }
@ -74,12 +74,12 @@ function hovercard_content()
// Feeds url could have been destroyed through "cleanContactUrl", so we now use the original url // Feeds url could have been destroyed through "cleanContactUrl", so we now use the original url
if (!count($contact) && local_user()) { if (!count($contact) && local_user()) {
$nurl = normalise_link($profileurl); $nurl = Strings::normaliseLink($profileurl);
$contact = Contact::getDetailsByURL($nurl, local_user()); $contact = Contact::getDetailsByURL($nurl, local_user());
} }
if (!count($contact)) { if (!count($contact)) {
$nurl = normalise_link($profileurl); $nurl = Strings::normaliseLink($profileurl);
$contact = Contact::getDetailsByURL($nurl); $contact = Contact::getDetailsByURL($nurl);
} }

View file

@ -6,12 +6,13 @@ use Friendica\App;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Core\Renderer; use Friendica\Core\Renderer;
use Friendica\Util\Strings;
function maintenance_content(App $a) function maintenance_content(App $a)
{ {
$reason = Config::get('system', 'maintenance_reason'); $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("HTTP/1.1 307 Temporary Redirect");
header("Location:".$reason); header("Location:".$reason);
return; return;

View file

@ -14,6 +14,7 @@ use Friendica\Database\DBA;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
require_once 'include/text.php'; require_once 'include/text.php';
@ -76,7 +77,7 @@ function match_content(App $a)
$id = 0; $id = 0;
foreach ($j->results as $jj) { foreach ($j->results as $jj) {
$match_nurl = normalise_link($jj->url); $match_nurl = Strings::normaliseLink($jj->url);
$match = q( $match = q(
"SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1", "SELECT `nurl` FROM `contact` WHERE `uid` = '%d' AND nurl='%s' LIMIT 1",
intval(local_user()), intval(local_user()),

View file

@ -219,7 +219,7 @@ function message_content(App $a)
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
$r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1", $r = q("SELECT `name`, `url`, `id` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' LIMIT 1",
intval(local_user()), intval(local_user()),
DBA::escape(normalise_link(base64_decode($a->argv[2]))) DBA::escape(Strings::normaliseLink(base64_decode($a->argv[2])))
); );
} }

View file

@ -883,7 +883,7 @@ function networkThreadedView(App $a, $update, $parent)
foreach ($data as $item) { foreach ($data as $item) {
// Don't show hash tag posts from blocked or ignored contacts // Don't show hash tag posts from blocked or ignored contacts
$condition = ["`nurl` = ? AND `uid` = ? AND (`blocked` OR `readonly`)", $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)) { if (!DBA::exists('contact', $condition)) {
$s[$item['uri']] = $item; $s[$item['uri']] = $item;
} }

View file

@ -150,9 +150,9 @@ function salmon_post(App $a, $xml = '') {
AND `uid` = %d LIMIT 1", AND `uid` = %d LIMIT 1",
DBA::escape(Protocol::OSTATUS), DBA::escape(Protocol::OSTATUS),
DBA::escape(Protocol::DFRN), DBA::escape(Protocol::DFRN),
DBA::escape(normalise_link($author_link)), DBA::escape(Strings::normaliseLink($author_link)),
DBA::escape($author_link), DBA::escape($author_link),
DBA::escape(normalise_link($author_link)), DBA::escape(Strings::normaliseLink($author_link)),
intval($importer['uid']) intval($importer['uid'])
); );

View file

@ -28,8 +28,8 @@ function unfollow_post(App $a)
$url = Strings::removeTags(trim(defaults($_REQUEST, 'url', ''))); $url = Strings::removeTags(trim(defaults($_REQUEST, 'url', '')));
$condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
$uid, Contact::SHARING, Contact::FRIEND, normalise_link($url), $uid, Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
normalise_link($url), $url]; Strings::normaliseLink($url), $url];
$contact = DBA::selectFirst('contact', [], $condition); $contact = DBA::selectFirst('contact', [], $condition);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
@ -83,8 +83,8 @@ function unfollow_content(App $a)
$url = Strings::removeTags(trim($_REQUEST['url'])); $url = Strings::removeTags(trim($_REQUEST['url']));
$condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)", $condition = ["`uid` = ? AND (`rel` = ? OR `rel` = ?) AND (`nurl` = ? OR `alias` = ? OR `alias` = ?)",
local_user(), Contact::SHARING, Contact::FRIEND, normalise_link($url), local_user(), Contact::SHARING, Contact::FRIEND, Strings::normaliseLink($url),
normalise_link($url), $url]; Strings::normaliseLink($url), $url];
$contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition); $contact = DBA::selectFirst('contact', ['url', 'network', 'addr', 'name'], $condition);

View file

@ -816,12 +816,12 @@ class App
public function removeBaseURL($origURL) public function removeBaseURL($origURL)
{ {
// Remove the hostname from the url if it is an internal link // Remove the hostname from the url if it is an internal link
$nurl = normalise_link($origURL); $nurl = Util\Strings::normaliseLink($origURL);
$base = normalise_link($this->getBaseURL()); $base = Util\Strings::normaliseLink($this->getBaseURL());
$url = str_replace($base . '/', '', $nurl); $url = str_replace($base . '/', '', $nurl);
// if it is an external link return the orignal value // if it is an external link return the orignal value
if ($url == normalise_link($origURL)) { if ($url == Util\Strings::normaliseLink($origURL)) {
return $origURL; return $origURL;
} else { } else {
return $url; return $url;

View file

@ -10,6 +10,7 @@ use Friendica\Core\Protocol;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings;
/** /**
* @brief ContactSelector class * @brief ContactSelector class
@ -106,12 +107,12 @@ class ContactSelector
// Create the server url out of the profile url // Create the server url out of the profile url
$parts = parse_url($profile); $parts = parse_url($profile);
unset($parts['path']); unset($parts['path']);
$server_url = [normalise_link(Network::unparseURL($parts))]; $server_url = [Strings::normaliseLink(Network::unparseURL($parts))];
// Fetch the server url // 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'])) { 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 // Now query the GServer for the platform name

View file

@ -62,7 +62,7 @@ class OEmbed
$cache_key = 'oembed:' . $a->videowidth . ':' . $embedurl; $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); $oembed_record = DBA::selectFirst('oembed', ['content'], $condition);
if (DBA::isResult($oembed_record)) { if (DBA::isResult($oembed_record)) {
$json_string = $oembed_record['content']; $json_string = $oembed_record['content'];
@ -117,7 +117,7 @@ class OEmbed
if (!empty($oembed->type) && $oembed->type != 'error') { if (!empty($oembed->type) && $oembed->type != 'error') {
DBA::insert('oembed', [ DBA::insert('oembed', [
'url' => normalise_link($embedurl), 'url' => Strings::normaliseLink($embedurl),
'maxwidth' => $a->videowidth, 'maxwidth' => $a->videowidth,
'content' => $json_string, 'content' => $json_string,
'created' => DateTimeFormat::utcNow() 'created' => DateTimeFormat::utcNow()

View file

@ -27,6 +27,7 @@ use Friendica\Util\Map;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\ParseUrl; use Friendica\Util\ParseUrl;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
class BBCode extends BaseObject class BBCode extends BaseObject
{ {
@ -943,7 +944,7 @@ class BBCode extends BaseObject
case 3: // Diaspora case 3: // Diaspora
$headline = '<p><b>' . html_entity_decode('&#x2672; ', ENT_QUOTES, 'UTF-8') . $mention . ':</b></p>' . "\n"; $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"; $text = ($is_quote_share? '<hr />' : '') . '<p><a href="' . $attributes['link'] . '">' . $attributes['link'] . '</a></p>' . "\n";
} else { } else {
$text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n"; $text = ($is_quote_share? '<hr />' : '') . $headline . '<blockquote>' . trim($content) . '</blockquote>' . "\n";
@ -978,7 +979,7 @@ class BBCode extends BaseObject
break; break;
default: default:
// Transforms quoted tweets in rich attachments to avoid nested tweets // 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 { try {
$text = ($is_quote_share? '<br />' : '') . OEmbed::getHTML($attributes['link']); $text = ($is_quote_share? '<br />' : '') . OEmbed::getHTML($attributes['link']);
} catch (Exception $e) { } catch (Exception $e) {

View file

@ -18,6 +18,7 @@ use Friendica\Model\Contact;
use Friendica\Model\FileTag; use Friendica\Model\FileTag;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Model\Profile; use Friendica\Model\Profile;
use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
require_once 'boot.php'; require_once 'boot.php';
@ -270,11 +271,11 @@ class Widget
if (!$cid) { if (!$cid) {
if (Profile::getMyURL()) { if (Profile::getMyURL()) {
$contact = DBA::selectFirst('contact', ['id'], $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)) { if (DBA::isResult($contact)) {
$cid = $contact['id']; $cid = $contact['id'];
} else { } 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)) { if (DBA::isResult($gcontact)) {
$zcid = $gcontact['id']; $zcid = $gcontact['id'];
} }

View file

@ -5,6 +5,7 @@ namespace Friendica\Core\Console;
use Friendica\App; use Friendica\App;
use Friendica\Core\L10n; use Friendica\Core\L10n;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Util\Strings;
use RuntimeException; use RuntimeException;
/** /**
@ -60,7 +61,7 @@ HELP;
throw new RuntimeException('Friendica isn\'t properly installed yet.'); 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])) { 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)); throw new RuntimeException(L10n::t('Could not find any unarchived contact entry for this URL (%s)', $nurl));
} }

View file

@ -5,6 +5,7 @@ namespace Friendica\Core\Console;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\Strings;
use RuntimeException; use RuntimeException;
require_once 'include/text.php'; require_once 'include/text.php';
@ -79,7 +80,7 @@ HELP;
throw new RuntimeException('This account seems not to exist.'); 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]); $contact = DBA::selectFirst("contact", ["id"], ["nurl" => $nurl, "uid" => 0]);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]); DBA::update("contact", ["hidden" => true], ["id" => $contact["id"]]);

View file

@ -511,7 +511,7 @@ class Installer
if (function_exists('curl_init')) { if (function_exists('curl_init')) {
$fetchResult = Network::fetchUrlFull($baseurl . "/install/testrewrite"); $fetchResult = Network::fetchUrlFull($baseurl . "/install/testrewrite");
$url = normalise_link($baseurl . "/install/testrewrite"); $url = Strings::normaliseLink($baseurl . "/install/testrewrite");
if ($fetchResult->getReturnCode() != 204) { if ($fetchResult->getReturnCode() != 204) {
$fetchResult = Network::fetchUrlFull($url); $fetchResult = Network::fetchUrlFull($url);
} }

View file

@ -10,6 +10,7 @@ use Friendica\Core\Protocol;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Model\Photo; use Friendica\Model\Photo;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Strings;
require_once "include/dba.php"; require_once "include/dba.php";
@ -119,8 +120,8 @@ class UserImport
$oldbaseurl = $account['baseurl']; $oldbaseurl = $account['baseurl'];
$newbaseurl = System::baseUrl(); $newbaseurl = System::baseUrl();
$oldaddr = str_replace('http://', '@', normalise_link($oldbaseurl)); $oldaddr = str_replace('http://', '@', Strings::normaliseLink($oldbaseurl));
$newaddr = str_replace('http://', '@', normalise_link($newbaseurl)); $newaddr = str_replace('http://', '@', Strings::normaliseLink($newbaseurl));
if (!empty($account['profile']['addr'])) { if (!empty($account['profile']['addr'])) {
$old_handle = $account['profile']['addr']; $old_handle = $account['profile']['addr'];

View file

@ -7,13 +7,14 @@
namespace Friendica\Model; namespace Friendica\Model;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Content\Text\HTML;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\JsonLD; use Friendica\Util\JsonLD;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Content\Text\HTML; use Friendica\Util\Strings;
require_once 'boot.php'; 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 // Update some data in the contact table with various ways to catch them all
$contact_fields = ['name' => $apcontact['name'], 'about' => $apcontact['about']]; $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)) { while ($contact = DBA::fetch($contacts)) {
Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']); Contact::updateAvatar($apcontact['photo'], $contact['uid'], $contact['id']);
} }
DBA::close($contacts); DBA::close($contacts);
// Update the gcontact table // 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); Logger::log('Updated profile for ' . $url, Logger::DEBUG);

View file

@ -393,7 +393,7 @@ class Contact extends BaseObject
'blocked' => 0, 'blocked' => 0,
'pending' => 0, 'pending' => 0,
'url' => System::baseUrl() . '/profile/' . $user['nickname'], '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), 'addr' => $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3),
'request' => System::baseUrl() . '/dfrn_request/' . $user['nickname'], 'request' => System::baseUrl() . '/dfrn_request/' . $user['nickname'],
'notify' => System::baseUrl() . '/dfrn_notify/' . $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. // 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['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['addr'] = $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
$fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname']; $fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname'];
$fields['notify'] = System::baseUrl() . '/dfrn_notify/' . $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) { if ($contact['term-date'] <= DBA::NULL_DATETIME) {
DBA::update('contact', ['term-date' => DateTimeFormat::utcNow()], ['id' => $contact['id']]); 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 { } else {
/* @todo /* @todo
* We really should send a notification to the owner after 2-3 weeks * 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. * the whole process over again.
*/ */
DBA::update('contact', ['archive' => 1], ['id' => $contact['id']]); 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. // It's a miracle. Our dead contact has inexplicably come back to life.
$fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false]; $fields = ['term-date' => DBA::NULL_DATETIME, 'archive' => false];
DBA::update('contact', $fields, ['id' => $contact['id']]); 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'])) { if (!empty($contact['batch'])) {
$condition = ['batch' => $contact['batch'], 'contact-type' => self::ACCOUNT_TYPE_RELAY]; $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 // 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`, $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` `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); $r = DBA::toArray($s);
// Fetch contact data from the contact table for the given user, checking with the alias // Fetch contact data from the contact table for the given user, checking with the alias
if (!DBA::isResult($r)) { 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`, $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` `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); $r = DBA::toArray($s);
} }
@ -706,7 +706,7 @@ class Contact extends BaseObject
if (!DBA::isResult($r)) { 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`, $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` `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); $r = DBA::toArray($s);
} }
@ -714,7 +714,7 @@ class Contact extends BaseObject
if (!DBA::isResult($r)) { 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`, $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` `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); $r = DBA::toArray($s);
} }
@ -722,7 +722,7 @@ class Contact extends BaseObject
if (!DBA::isResult($r)) { 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`, $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` `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); $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 /// @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 // 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) // Then the addr (nick@server.tld)
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
@ -1050,7 +1050,7 @@ class Contact extends BaseObject
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
// The link could be provided as http although we stored it as https // The link could be provided as http although we stored it as https
$ssl_url = str_replace('http://', 'https://', $url); $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); $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', $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
'photo', 'keywords', 'location', 'about', 'network', 'photo', 'keywords', 'location', 'about', 'network',
'priority', 'batch', 'request', 'confirm', 'poco']; '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)) { if (DBA::isResult($data)) {
// For security reasons we don't fetch key data from our users // 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 // Get data from the gcontact table
$fields = ['name', 'nick', 'url', 'photo', 'addr', 'alias', 'network']; $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)) { 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)) { if (!DBA::isResult($contact)) {
@ -1119,14 +1119,14 @@ class Contact extends BaseObject
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
// The link could be provided as http although we stored it as https // The link could be provided as http although we stored it as https
$ssl_url = str_replace('http://', 'https://', $url); $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); $contact = DBA::selectFirst('contact', $fields, $condition);
} }
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
$fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick', $fields = ['url', 'addr', 'alias', 'notify', 'poll', 'name', 'nick',
'photo', 'network', 'priority', 'batch', 'request', 'confirm']; '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); $contact = DBA::selectFirst('fcontact', $fields, $condition);
} }
@ -1151,7 +1151,7 @@ class Contact extends BaseObject
'uid' => $uid, 'uid' => $uid,
'created' => DateTimeFormat::utcNow(), 'created' => DateTimeFormat::utcNow(),
'url' => $data["url"], 'url' => $data["url"],
'nurl' => normalise_link($data["url"]), 'nurl' => Strings::normaliseLink($data["url"]),
'addr' => $data["addr"], 'addr' => $data["addr"],
'alias' => $data["alias"], 'alias' => $data["alias"],
'notify' => $data["notify"], 'notify' => $data["notify"],
@ -1179,7 +1179,7 @@ class Contact extends BaseObject
'pending' => 0] '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); $contacts = DBA::toArray($s);
if (!DBA::isResult($contacts)) { if (!DBA::isResult($contacts)) {
return 0; return 0;
@ -1188,7 +1188,7 @@ class Contact extends BaseObject
$contact_id = $contacts[0]["id"]; $contact_id = $contacts[0]["id"];
// Update the newly created contact from data in the gcontact table // 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)) { if (DBA::isResult($gcontact)) {
// Only use the information when the probing hadn't fetched these values // Only use the information when the probing hadn't fetched these values
if ($data['keywords'] != '') { if ($data['keywords'] != '') {
@ -1205,7 +1205,7 @@ class Contact extends BaseObject
if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") { if (count($contacts) > 1 && $uid == 0 && $contact_id != 0 && $data["url"] != "") {
DBA::delete('contact', ["`nurl` = ? AND `uid` = 0 AND `id` != ? AND NOT `self`", 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'], $updated = ['addr' => $data['addr'],
'alias' => $data['alias'], 'alias' => $data['alias'],
'url' => $data['url'], 'url' => $data['url'],
'nurl' => normalise_link($data['url']), 'nurl' => Strings::normaliseLink($data['url']),
'name' => $data['name'], 'name' => $data['name'],
'nick' => $data['nick']]; 'nick' => $data['nick']];
@ -1544,7 +1544,7 @@ class Contact extends BaseObject
DBA::update( DBA::update(
'contact', [ 'contact', [
'url' => $ret['url'], 'url' => $ret['url'],
'nurl' => normalise_link($ret['url']), 'nurl' => Strings::normaliseLink($ret['url']),
'network' => $ret['network'], 'network' => $ret['network'],
'addr' => $ret['addr'], 'addr' => $ret['addr'],
'alias' => $ret['alias'], '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 // the poll url is more reliable than the profile url, as we may have
// indirect links or webfinger links // 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); $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
if (!DBA::isResult($contact)) { 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); $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
} }
@ -1711,7 +1711,7 @@ class Contact extends BaseObject
'uid' => $uid, 'uid' => $uid,
'created' => DateTimeFormat::utcNow(), 'created' => DateTimeFormat::utcNow(),
'url' => $ret['url'], 'url' => $ret['url'],
'nurl' => normalise_link($ret['url']), 'nurl' => Strings::normaliseLink($ret['url']),
'addr' => $ret['addr'], 'addr' => $ret['addr'],
'alias' => $ret['alias'], 'alias' => $ret['alias'],
'batch' => $ret['batch'], 'batch' => $ret['batch'],
@ -1856,7 +1856,7 @@ class Contact extends BaseObject
// send email notification to owner? // send email notification to owner?
} else { } 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); Logger::log('ignoring duplicated connection request from pending contact ' . $url);
return; return;
} }
@ -1867,7 +1867,7 @@ class Contact extends BaseObject
intval($importer['uid']), intval($importer['uid']),
DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()),
DBA::escape($url), DBA::escape($url),
DBA::escape(normalise_link($url)), DBA::escape(Strings::normaliseLink($url)),
DBA::escape($name), DBA::escape($name),
DBA::escape($nick), DBA::escape($nick),
DBA::escape($photo), DBA::escape($photo),

View file

@ -17,6 +17,7 @@ use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -146,13 +147,13 @@ class GContact
$alternate = PortableContact::alternateOStatusUrl($gcontact['url']); $alternate = PortableContact::alternateOStatusUrl($gcontact['url']);
// The global contacts should contain the original picture, not the cached one // 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'] = ""; $gcontact['photo'] = "";
} }
if (!isset($gcontact['network'])) { if (!isset($gcontact['network'])) {
$condition = ["`uid` = 0 AND `nurl` = ? AND `network` != '' AND `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); $contact = DBA::selectFirst('contact', ['network'], $condition);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$gcontact['network'] = $contact["network"]; $gcontact['network'] = $contact["network"];
@ -160,7 +161,7 @@ class GContact
if (($gcontact['network'] == "") || ($gcontact['network'] == Protocol::OSTATUS)) { if (($gcontact['network'] == "") || ($gcontact['network'] == Protocol::OSTATUS)) {
$condition = ["`uid` = 0 AND `alias` IN (?, ?) AND `network` != '' AND `network` != ?", $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); $contact = DBA::selectFirst('contact', ['network'], $condition);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$gcontact['network'] = $contact["network"]; $gcontact['network'] = $contact["network"];
@ -172,7 +173,7 @@ class GContact
$gcontact['network'] = ''; $gcontact['network'] = '';
$fields = ['network', 'updated', 'server_url', 'url', 'addr']; $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 (DBA::isResult($gcnt)) {
if (!isset($gcontact['network']) && ($gcnt["network"] != Protocol::STATUSNET)) { if (!isset($gcontact['network']) && ($gcnt["network"] != Protocol::STATUSNET)) {
$gcontact['network'] = $gcnt["network"]; $gcontact['network'] = $gcnt["network"];
@ -180,7 +181,7 @@ class GContact
if ($gcontact['updated'] <= DBA::NULL_DATETIME) { if ($gcontact['updated'] <= DBA::NULL_DATETIME) {
$gcontact['updated'] = $gcnt["updated"]; $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"]; $gcontact['server_url'] = $gcnt["server_url"];
} }
if (!isset($gcontact['addr'])) { if (!isset($gcontact['addr'])) {
@ -205,8 +206,8 @@ class GContact
if ($alternate && ($gcontact['network'] == Protocol::OSTATUS)) { if ($alternate && ($gcontact['network'] == Protocol::OSTATUS)) {
// Delete the old entry - if it exists // Delete the old entry - if it exists
if (DBA::exists('gcontact', ['nurl' => normalise_link($orig_profile)])) { if (DBA::exists('gcontact', ['nurl' => Strings::normaliseLink($orig_profile)])) {
DBA::delete('gcontact', ['nurl' => normalise_link($orig_profile)]); DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($orig_profile)]);
} }
} }
} }
@ -658,7 +659,7 @@ class GContact
DBA::lock('gcontact'); DBA::lock('gcontact');
$fields = ['id', 'last_contact', 'last_failure', 'network']; $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)) { if (DBA::isResult($gcnt)) {
$gcontact_id = $gcnt["id"]; $gcontact_id = $gcnt["id"];
@ -683,7 +684,7 @@ class GContact
DBA::escape($contact["addr"]), DBA::escape($contact["addr"]),
DBA::escape($contact["network"]), DBA::escape($contact["network"]),
DBA::escape($contact["url"]), DBA::escape($contact["url"]),
DBA::escape(normalise_link($contact["url"])), DBA::escape(Strings::normaliseLink($contact["url"])),
DBA::escape($contact["photo"]), DBA::escape($contact["photo"]),
DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()),
DBA::escape(DateTimeFormat::utcNow()), DBA::escape(DateTimeFormat::utcNow()),
@ -693,7 +694,7 @@ class GContact
intval($contact["generation"]) intval($contact["generation"])
); );
$condition = ['nurl' => normalise_link($contact["url"])]; $condition = ['nurl' => Strings::normaliseLink($contact["url"])];
$cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]); $cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]);
if (DBA::isResult($cnt)) { if (DBA::isResult($cnt)) {
$gcontact_id = $cnt["id"]; $gcontact_id = $cnt["id"];
@ -793,7 +794,7 @@ class GContact
$contact["server_url"] = $data['baseurl']; $contact["server_url"] = $data['baseurl'];
} }
} else { } 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"] != "")) { if (($contact["addr"] == "") && ($contact["server_url"] != "") && ($contact["nick"] != "")) {
@ -822,7 +823,7 @@ class GContact
if ($update) { if ($update) {
Logger::log("Update gcontact for ".$contact["url"], Logger::DEBUG); Logger::log("Update gcontact for ".$contact["url"], Logger::DEBUG);
$condition = ['`nurl` = ? AND (`generation` = 0 OR `generation` >= ?)', $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"]); $contact["updated"] = DateTimeFormat::utc($contact["updated"]);
$updated = ['photo' => $contact['photo'], 'name' => $contact['name'], $updated = ['photo' => $contact['photo'], 'name' => $contact['name'],
@ -842,7 +843,7 @@ class GContact
// This is used for the shadow copies of public items. // This is used for the shadow copies of public items.
/// @todo Check if we really should do this. /// @todo Check if we really should do this.
// The quality of the gcontact table is mostly lower than the public contact // 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)) { if (DBA::isResult($public_contact)) {
Logger::log("Update public contact ".$public_contact["id"], Logger::DEBUG); Logger::log("Update public contact ".$public_contact["id"], Logger::DEBUG);

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); 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']]); $user = DBA::selectFirst('user', ['nickname'], ['uid' => $item['uid']]);
if (DBA::isResult($user)) { 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); $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); 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)) { if (($item['author-id'] == $self_id) || ($item['owner-id'] == $self_id)) {
@ -2545,13 +2545,13 @@ class Item extends BaseObject
return; 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 * Diaspora uses their own hardwired link URL in @-tags
* instead of the one we supply with webfinger * 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); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER);
if ($cnt) { if ($cnt) {

View file

@ -327,9 +327,9 @@ class Profile
// Is the local user already connected to that user? // Is the local user already connected to that user?
if ($connect && local_user()) { if ($connect && local_user()) {
if (isset($profile['url'])) { if (isset($profile['url'])) {
$profile_url = normalise_link($profile['url']); $profile_url = Strings::normaliseLink($profile['url']);
} else { } 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])) { if (DBA::exists('contact', ['pending' => false, 'uid' => local_user(), 'nurl' => $profile_url])) {
@ -371,7 +371,7 @@ class Profile
$r = q( $r = q(
"SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d", "SELECT `url` FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `rel` = %d",
intval($profile['uid']), intval($profile['uid']),
DBA::escape(normalise_link(self::getMyURL())), DBA::escape(Strings::normaliseLink(self::getMyURL())),
intval(Contact::FRIEND) intval(Contact::FRIEND)
); );
} }

View file

@ -61,7 +61,7 @@ class User
*/ */
public static function getIdForURL($url) 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)) { if (!DBA::isResult($self)) {
return false; return false;
} else { } else {

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'])) { if (!empty($data['priority'])) {
$fields['priority'] = intval($data['priority']); $fields['priority'] = intval($data['priority']);

View file

@ -50,7 +50,7 @@ class Magic extends BaseModule
$contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]); $contact = DBA::selectFirst('contact', ['id', 'nurl', 'url'], ['id' => $cid]);
// Redirect if the contact is already authenticated on this site. // 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) { if ($test) {
$ret['success'] = true; $ret['success'] = true;
$ret['message'] .= 'Local site - you are already authenticated.' . EOL; $ret['message'] .= 'Local site - you are already authenticated.' . EOL;

View file

@ -348,7 +348,7 @@ class Probe
} }
if (x($data, "photo")) { 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 { } else {
$data["photo"] = System::baseUrl().'/images/person-300.jpg'; $data["photo"] = System::baseUrl().'/images/person-300.jpg';
} }
@ -427,7 +427,7 @@ class Probe
$fields['updated'] = DateTimeFormat::utcNow(); $fields['updated'] = DateTimeFormat::utcNow();
$condition = ['nurl' => normalise_link($data["url"])]; $condition = ['nurl' => Strings::normaliseLink($data["url"])];
$old_fields = DBA::selectFirst('gcontact', $fieldnames, $condition); $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. // "$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 // This won't trigger an insert. This is intended, since we only need
@ -1010,7 +1010,7 @@ class Probe
foreach ($webfinger["aliases"] as $alias) { foreach ($webfinger["aliases"] as $alias) {
if (empty($data["url"]) && !strstr($alias, "@")) { if (empty($data["url"]) && !strstr($alias, "@")) {
$data["url"] = $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; $data["alias"] = $alias;
} elseif (substr($alias, 0, 5) == 'acct:') { } elseif (substr($alias, 0, 5) == 'acct:') {
$data["addr"] = substr($alias, 5); $data["addr"] = substr($alias, 5);
@ -1213,7 +1213,7 @@ class Probe
if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
foreach ($webfinger["aliases"] as $alias) { 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; $data["alias"] = $alias;
} elseif (substr($alias, 0, 5) == 'acct:') { } elseif (substr($alias, 0, 5) == 'acct:') {
$data["addr"] = substr($alias, 5); $data["addr"] = substr($alias, 5);
@ -1269,14 +1269,14 @@ class Probe
if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) { if (!empty($webfinger["aliases"]) && is_array($webfinger["aliases"])) {
foreach ($webfinger["aliases"] as $alias) { 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); $data["addr"] = str_replace('acct:', '', $alias);
} }
} }
} }
if (!empty($webfinger["subject"]) && strstr($webfinger["subject"], "@") 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"]); $data["addr"] = str_replace('acct:', '', $webfinger["subject"]);
} }
@ -1302,7 +1302,7 @@ class Probe
} else { } else {
$pubkey = substr($pubkey, 5); $pubkey = substr($pubkey, 5);
} }
} elseif (normalise_link($pubkey) == 'http://') { } elseif (Strings::normaliseLink($pubkey) == 'http://') {
$curlResult = Network::curl($pubkey); $curlResult = Network::curl($pubkey);
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
return false; return false;

View file

@ -5,6 +5,8 @@
namespace Friendica\Protocol\ActivityPub; namespace Friendica\Protocol\ActivityPub;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Content\Text\HTML;
use Friendica\Core\Config;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Model\Conversation; use Friendica\Model\Conversation;
@ -13,11 +15,10 @@ use Friendica\Model\APContact;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\Event; use Friendica\Model\Event;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Content\Text\HTML;
use Friendica\Util\JsonLD;
use Friendica\Core\Config;
use Friendica\Protocol\ActivityPub; use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\JsonLD;
use Friendica\Util\Strings;
/** /**
* ActivityPub Processor Protocol class * ActivityPub Processor Protocol class
@ -417,7 +418,7 @@ class Processor
return; 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)) { while ($contact = DBA::fetch($contacts)) {
Contact::remove($contact['id']); Contact::remove($contact['id']);
} }

View file

@ -5,18 +5,19 @@
namespace Friendica\Protocol\ActivityPub; namespace Friendica\Protocol\ActivityPub;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Util\HTTPSignature;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Core\Protocol; use Friendica\Core\Protocol;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\APContact; use Friendica\Model\APContact;
use Friendica\Model\Conversation;
use Friendica\Model\Item; use Friendica\Model\Item;
use Friendica\Model\User; use Friendica\Model\User;
use Friendica\Protocol\ActivityPub;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\HTTPSignature;
use Friendica\Util\JsonLD; use Friendica\Util\JsonLD;
use Friendica\Util\LDSignature; use Friendica\Util\LDSignature;
use Friendica\Protocol\ActivityPub; use Friendica\Util\Strings;
use Friendica\Model\Conversation;
use Friendica\Util\DateTimeFormat;
/** /**
* @brief ActivityPub Receiver Protocol class * @brief ActivityPub Receiver Protocol class
@ -455,7 +456,7 @@ class Receiver
if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) { if (($receiver == self::PUBLIC_COLLECTION) && !empty($actor)) {
// This will most likely catch all OStatus connections to Mastodon // 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]; , 'archive' => false, 'pending' => false];
$contacts = DBA::select('contact', ['uid'], $condition); $contacts = DBA::select('contact', ['uid'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
@ -472,7 +473,7 @@ class Receiver
} }
// Fetching all directly addressed receivers // 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); $contact = DBA::selectFirst('contact', ['uid', 'contact-type'], $condition);
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
continue; continue;
@ -482,7 +483,7 @@ class Receiver
// Exception: The receiver is targetted via "to" or this is a comment // 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)) { if ((($element != 'as:to') && empty($replyto)) || ($contact['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY)) {
$networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $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']]; 'network' => $networks, 'archive' => false, 'pending' => false, 'uid' => $contact['uid']];
// Forum posts are only accepted from forum contacts // Forum posts are only accepted from forum contacts
@ -516,7 +517,7 @@ class Receiver
{ {
$receivers = []; $receivers = [];
$networks = [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS]; $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]; 'network' => $networks, 'archive' => false, 'pending' => false];
$contacts = DBA::select('contact', ['uid', 'rel'], $condition); $contacts = DBA::select('contact', ['uid', 'rel'], $condition);
while ($contact = DBA::fetch($contacts)) { while ($contact = DBA::fetch($contacts)) {
@ -589,7 +590,7 @@ class Receiver
unset($profile['photo']); unset($profile['photo']);
unset($profile['baseurl']); unset($profile['baseurl']);
$profile['nurl'] = normalise_link($profile['url']); $profile['nurl'] = Strings::normaliseLink($profile['url']);
DBA::update('contact', $profile, ['id' => $cid]); DBA::update('contact', $profile, ['id' => $cid]);
Contact::updateAvatar($photo, $uid, $cid); Contact::updateAvatar($photo, $uid, $cid);
@ -614,12 +615,12 @@ class Receiver
} }
foreach ($receivers as $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)) { if (DBA::isResult($contact)) {
self::switchContact($contact['id'], $receiver, $actor); 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)) { if (DBA::isResult($contact)) {
self::switchContact($contact['id'], $receiver, $actor); self::switchContact($contact['id'], $receiver, $actor);
} }

View file

@ -1097,7 +1097,7 @@ class DFRN
} }
foreach ($mentioned as $mention) { 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); $contact = DBA::selectFirst('contact', ['forum', 'prv'], $condition);
if (DBA::isResult($contact) && ($contact["forum"] || $contact["prv"])) { 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', $fields = ['id', 'uid', 'url', 'network', 'avatar-date', 'avatar', 'name-date', 'uri-date', 'addr',
'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type']; 'name', 'nick', 'about', 'location', 'keywords', 'xmpp', 'bdyear', 'bd', 'hidden', 'contact-type'];
$condition = ["`uid` = ? AND `nurl` = ? AND `network` != ?", $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); $contact_old = DBA::selectFirst('contact', $fields, $condition);
if (DBA::isResult($contact_old)) { if (DBA::isResult($contact_old)) {
@ -1960,7 +1960,7 @@ class DFRN
* *
* @see https://github.com/friendica/friendica/pull/3254#discussion_r107315246 * @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"]]; 'uid' => $suggest["uid"]];
if (DBA::exists('contact', $condition)) { if (DBA::exists('contact', $condition)) {
return false; return false;
@ -2100,18 +2100,18 @@ class DFRN
$relocate["server_url"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $relocate["url"]); $relocate["server_url"] = preg_replace("=(https?://)(.*)/profile/(.*)=ism", "$1$2", $relocate["url"]);
$fields = ['name' => $relocate["name"], 'photo' => $relocate["avatar"], $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"], 'addr' => $relocate["addr"], 'connect' => $relocate["addr"],
'notify' => $relocate["notify"], 'server_url' => $relocate["server_url"]]; '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. // Update the contact table. We try to find every entry.
$fields = ['name' => $relocate["name"], 'avatar' => $relocate["avatar"], $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"], 'addr' => $relocate["addr"], 'request' => $relocate["request"],
'confirm' => $relocate["confirm"], 'notify' => $relocate["notify"], 'confirm' => $relocate["confirm"], 'notify' => $relocate["notify"],
'poll' => $relocate["poll"], 'site-pubkey' => $relocate["sitepubkey"]]; '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); DBA::update('contact', $fields, $condition);
@ -2986,7 +2986,7 @@ class DFRN
return; return;
} }
$baseurl = substr($baseurl, $domain_st + 3); $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. /// @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) $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); $community_page = ($user['page-flags'] == Contact::PAGE_COMMUNITY);
$prvgroup = ($user['page-flags'] == Contact::PAGE_PRVGROUP); $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 * Diaspora uses their own hardwired link URL in @-tags
* instead of the one we supply with webfinger * 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); $cnt = preg_match_all('/[\@\!]\[url\=(.*?)\](.*?)\[\/url\]/ism', $item['body'], $matches, PREG_SET_ORDER);
if ($cnt) { if ($cnt) {

View file

@ -147,7 +147,7 @@ class Diaspora
$fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked']; $fields = ['batch', 'id', 'name', 'network', 'archive', 'blocked'];
// Fetch the relay contact // 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-type' => Contact::ACCOUNT_TYPE_RELAY];
$contact = DBA::selectFirst('contact', $fields, $condition); $contact = DBA::selectFirst('contact', $fields, $condition);
@ -186,7 +186,7 @@ class Diaspora
$fields = array_merge($fields, $network_fields); $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]; 'contact-type' => Contact::ACCOUNT_TYPE_RELAY];
if (DBA::exists('contact', $condition)) { if (DBA::exists('contact', $condition)) {
@ -1434,7 +1434,7 @@ class Diaspora
*/ */
private static function authorContactByUrl($def_contact, $person, $uid) 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); $contact = DBA::selectFirst('contact', ['id', 'network'], $condition);
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
$cid = $contact["id"]; $cid = $contact["id"];
@ -1536,7 +1536,7 @@ class Diaspora
return false; 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'], 'name' => $data['name'], 'nick' => $data['nick'],
'addr' => $data['addr'], 'batch' => $data['batch'], 'addr' => $data['addr'], 'batch' => $data['batch'],
'notify' => $data['notify'], 'poll' => $data['poll'], 'notify' => $data['notify'], 'poll' => $data['poll'],
@ -1544,7 +1544,7 @@ class Diaspora
DBA::update('contact', $fields, ['addr' => $old_handle]); 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'], 'name' => $data['name'], 'nick' => $data['nick'],
'addr' => $data['addr'], 'connect' => $data['addr'], 'addr' => $data['addr'], 'connect' => $data['addr'],
'notify' => $data['notify'], 'photo' => $data['photo'], 'notify' => $data['notify'], 'photo' => $data['photo'],
@ -2392,7 +2392,7 @@ class Diaspora
DBA::escape($ret["addr"]), DBA::escape($ret["addr"]),
DateTimeFormat::utcNow(), DateTimeFormat::utcNow(),
DBA::escape($ret["url"]), DBA::escape($ret["url"]),
DBA::escape(normalise_link($ret["url"])), DBA::escape(Strings::normaliseLink($ret["url"])),
DBA::escape($batch), DBA::escape($batch),
DBA::escape($ret["name"]), DBA::escape($ret["name"]),
DBA::escape($ret["nick"]), DBA::escape($ret["nick"]),

View file

@ -26,6 +26,7 @@ use Friendica\Object\Image;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -98,7 +99,7 @@ class OStatus
} }
$condition = ["`uid` = ? AND `nurl` IN (?, ?) AND `network` != ? AND `rel` IN (?, ?)", $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]; Protocol::STATUSNET, Contact::SHARING, Contact::FRIEND];
$contact = DBA::selectFirst('contact', [], $condition); $contact = DBA::selectFirst('contact', [], $condition);
} }
@ -164,7 +165,7 @@ class OStatus
// $contact["poll"] = $value; // $contact["poll"] = $value;
$contact['url'] = $author["author-link"]; $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); $value = XML::getFirstNodeValue($xpath, 'atom:author/atom:uri/text()', $context);
if ($value != "") { if ($value != "") {
@ -209,7 +210,7 @@ class OStatus
// Update it with the current values // Update it with the current values
$fields = ['url' => $author["author-link"], 'name' => $contact["name"], $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"], 'nick' => $contact["nick"], 'alias' => $contact["alias"],
'about' => $contact["about"], 'location' => $contact["location"], 'about' => $contact["about"], 'location' => $contact["location"],
'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()]; 'success_update' => DateTimeFormat::utcNow(), 'last-update' => DateTimeFormat::utcNow()];
@ -1599,7 +1600,7 @@ class OStatus
{ {
$r = q( $r = q(
"SELECT * FROM `contact` WHERE `nurl` = '%s' AND `uid` IN (0, %d) ORDER BY `uid` DESC LIMIT 1", "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"]) intval($owner["uid"])
); );
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
@ -1608,7 +1609,7 @@ class OStatus
} }
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
$gcontact = DBA::selectFirst('gcontact', [], ['nurl' => normalise_link($url)]); $gcontact = DBA::selectFirst('gcontact', [], ['nurl' => Strings::normaliseLink($url)]);
if (DBA::isResult($r)) { if (DBA::isResult($r)) {
$contact = $gcontact; $contact = $gcontact;
$contact["uid"] = -1; $contact["uid"] = -1;
@ -1651,7 +1652,7 @@ class OStatus
*/ */
private static function reshareEntry(DOMDocument $doc, array $item, array $owner, $repeated_guid, $toplevel) 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); 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) 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); 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']; $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); $user_contact = DBA::selectFirst('contact', ['id'], $condition);
if (DBA::isResult($user_contact)) { if (DBA::isResult($user_contact)) {
@ -1861,7 +1862,7 @@ class OStatus
*/ */
private static function noteEntry(DOMDocument $doc, array $item, array $owner, $toplevel) 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); 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; $mentioned = $newmentions;
foreach ($mentioned as $mention) { 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); $contact = DBA::selectFirst('contact', ['forum', 'prv', 'self', 'contact-type'], $condition);
if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) || if ($contact["forum"] || $contact["prv"] || ($owner['contact-type'] == Contact::ACCOUNT_TYPE_COMMUNITY) ||
($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) { ($contact['self'] && ($owner['account-type'] == Contact::ACCOUNT_TYPE_COMMUNITY))) {

View file

@ -23,6 +23,7 @@ use Friendica\Model\Profile;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings;
use Friendica\Util\XML; use Friendica\Util\XML;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -284,7 +285,7 @@ class PortableContact
$r = q( $r = q(
"SELECT `id` FROM `gserver` WHERE `nurl` = '%s' AND `last_contact` > `last_failure`", "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)) { if (DBA::isResult($r)) {
@ -309,7 +310,7 @@ class PortableContact
{ {
$gcontacts = q( $gcontacts = q(
"SELECT * FROM `gcontact` WHERE `nurl` = '%s'", "SELECT * FROM `gcontact` WHERE `nurl` = '%s'",
DBA::escape(normalise_link($profile)) DBA::escape(Strings::normaliseLink($profile))
); );
if (!DBA::isResult($gcontacts)) { if (!DBA::isResult($gcontacts)) {
@ -324,7 +325,7 @@ class PortableContact
$server_url = ''; $server_url = '';
if ($force) { if ($force) {
$server_url = normalise_link(self::detectServer($profile)); $server_url = Strings::normaliseLink(self::detectServer($profile));
} }
if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) { if (($server_url == '') && ($gcontacts[0]["server_url"] != "")) {
@ -332,7 +333,7 @@ class PortableContact
} }
if (!$force && (($server_url == '') || ($gcontacts[0]["server_url"] == $gcontacts[0]["nurl"]))) { 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, ""])) { 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 (!self::checkServer($server_url, $gcontacts[0]["network"], $force)) {
if ($force) { if ($force) {
$fields = ['last_failure' => DateTimeFormat::utcNow()]; $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); 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])) { if (in_array($gcontacts[0]["network"], ["", Protocol::FEED])) {
$server = q( $server = q(
"SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''", "SELECT `network` FROM `gserver` WHERE `nurl` = '%s' AND `network` != ''",
DBA::escape(normalise_link($server_url)) DBA::escape(Strings::normaliseLink($server_url))
); );
if ($server) { if ($server) {
@ -369,7 +370,7 @@ class PortableContact
// noscrape is really fast so we don't cache the call. // noscrape is really fast so we don't cache the call.
if (($server_url != "") && ($gcontacts[0]["nick"] != "")) { if (($server_url != "") && ($gcontacts[0]["nick"] != "")) {
// Use noscrape if possible // 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) { if ($server) {
$curlResult = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]); $curlResult = Network::curl($server[0]["noscrape"]."/".$gcontacts[0]["nick"]);
@ -425,7 +426,7 @@ class PortableContact
if (!empty($noscrape["updated"])) { if (!empty($noscrape["updated"])) {
$fields = ['last_contact' => DateTimeFormat::utcNow()]; $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); 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) // Is the profile link the alternate OStatus link notation? (http://domain.tld/user/4711)
// Then check the other link and delete this one // Then check the other link and delete this one
if (($data["network"] == Protocol::OSTATUS) && self::alternateOStatusUrl($profile) if (($data["network"] == Protocol::OSTATUS) && self::alternateOStatusUrl($profile)
&& (normalise_link($profile) == normalise_link($data["alias"])) && (Strings::normaliseLink($profile) == Strings::normaliseLink($data["alias"]))
&& (normalise_link($profile) != normalise_link($data["url"])) && (Strings::normaliseLink($profile) != Strings::normaliseLink($data["url"]))
) { ) {
// Delete the old entry // Delete the old entry
DBA::delete('gcontact', ['nurl' => normalise_link($profile)]); DBA::delete('gcontact', ['nurl' => Strings::normaliseLink($profile)]);
$gcontact = array_merge($gcontacts[0], $data); $gcontact = array_merge($gcontacts[0], $data);
@ -474,7 +475,7 @@ class PortableContact
if (($data["poll"] == "") || (in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM]))) { if (($data["poll"] == "") || (in_array($data["network"], [Protocol::FEED, Protocol::PHANTOM]))) {
$fields = ['last_failure' => DateTimeFormat::utcNow()]; $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); Logger::log("Profile ".$profile." wasn't reachable (profile)", Logger::DEBUG);
return false; return false;
@ -490,7 +491,7 @@ class PortableContact
if (!$curlResult->isSuccess()) { if (!$curlResult->isSuccess()) {
$fields = ['last_failure' => DateTimeFormat::utcNow()]; $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); Logger::log("Profile ".$profile." wasn't reachable (no feed)", Logger::DEBUG);
return false; return false;
@ -533,11 +534,11 @@ class PortableContact
$fields['updated'] = $last_updated; $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)) { if (($gcontacts[0]["generation"] == 0)) {
$fields = ['generation' => 9]; $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); Logger::log("Profile ".$profile." was last updated at ".$last_updated, Logger::DEBUG);
@ -930,11 +931,11 @@ class PortableContact
return false; 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 (DBA::isResult($gserver)) {
if ($gserver["created"] <= DBA::NULL_DATETIME) { if ($gserver["created"] <= DBA::NULL_DATETIME) {
$fields = ['created' => DateTimeFormat::utcNow()]; $fields = ['created' => DateTimeFormat::utcNow()];
$condition = ['nurl' => normalise_link($server_url)]; $condition = ['nurl' => Strings::normaliseLink($server_url)];
DBA::update('gserver', $fields, $condition); DBA::update('gserver', $fields, $condition);
} }
$poco = $gserver["poco"]; $poco = $gserver["poco"];
@ -990,7 +991,7 @@ class PortableContact
// Mastodon uses the "@" for user profiles. // Mastodon uses the "@" for user profiles.
// But this can be misunderstood. // But this can be misunderstood.
if (parse_url($server_url, PHP_URL_USER) != '') { 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; return false;
} }
@ -1006,7 +1007,7 @@ class PortableContact
if (DBA::isResult($gserver) && ($orig_server_url == $server_url) && if (DBA::isResult($gserver) && ($orig_server_url == $server_url) &&
($curlResult->isTimeout())) { ($curlResult->isTimeout())) {
Logger::log("Connection to server ".$server_url." timed out.", Logger::DEBUG); 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; return false;
} }
@ -1021,7 +1022,7 @@ class PortableContact
// Quit if there is a timeout // Quit if there is a timeout
if ($curlResult->isTimeout()) { if ($curlResult->isTimeout()) {
Logger::log("Connection to server " . $server_url . " timed out.", Logger::DEBUG); 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; return false;
} }
@ -1048,7 +1049,7 @@ class PortableContact
if (!$failure) { if (!$failure) {
// This will be too low, but better than no value at all. // 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 // Look for poco
@ -1410,7 +1411,7 @@ class PortableContact
} }
// Check again if the server exists // 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); $version = strip_tags($version);
$site_name = strip_tags($site_name); $site_name = strip_tags($site_name);
@ -1424,9 +1425,9 @@ class PortableContact
'last_contact' => $last_contact, 'last_failure' => $last_failure]; 'last_contact' => $last_contact, 'last_failure' => $last_failure];
if ($found) { if ($found) {
DBA::update('gserver', $fields, ['nurl' => normalise_link($server_url)]); DBA::update('gserver', $fields, ['nurl' => Strings::normaliseLink($server_url)]);
} elseif (!$failure) { } elseif (!$failure) {
$fields['nurl'] = normalise_link($server_url); $fields['nurl'] = Strings::normaliseLink($server_url);
$fields['created'] = DateTimeFormat::utcNow(); $fields['created'] = DateTimeFormat::utcNow();
DBA::insert('gserver', $fields); DBA::insert('gserver', $fields);
} }
@ -1461,7 +1462,7 @@ class PortableContact
return; 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)) { if (!DBA::isResult($gserver)) {
return; return;
@ -1560,7 +1561,7 @@ class PortableContact
foreach ($serverlist as $server) { foreach ($serverlist as $server) {
$server_url = str_replace("/index.php", "", $server['url']); $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)) { if (!DBA::isResult($r)) {
Logger::log("Call server check for server ".$server_url, Logger::DEBUG); Logger::log("Call server check for server ".$server_url, Logger::DEBUG);

View file

@ -52,7 +52,7 @@ class Salmon
} else { } else {
$ret[$x] = substr($ret[$x], 5); $ret[$x] = substr($ret[$x], 5);
} }
} elseif (normalise_link($ret[$x]) == 'http://') { } elseif (Strings::normaliseLink($ret[$x]) == 'http://') {
$ret[$x] = Network::fetchUrl($ret[$x]); $ret[$x] = Network::fetchUrl($ret[$x]);
} }
} }

View file

@ -9,6 +9,7 @@ use Friendica\Core\Logger;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Network\CurlResult; use Friendica\Network\CurlResult;
use Friendica\Util\Strings;
use DOMDocument; use DOMDocument;
use DomXPath; use DomXPath;
@ -718,8 +719,8 @@ class Network
return ""; return "";
} }
$url1 = normalise_link($url1); $url1 = Strings::normaliseLink($url1);
$url2 = normalise_link($url2); $url2 = Strings::normaliseLink($url2);
$parts1 = parse_url($url1); $parts1 = parse_url($url1);
$parts2 = parse_url($url2); $parts2 = parse_url($url2);
@ -790,7 +791,7 @@ class Network
$match .= $path; $match .= $path;
return normalise_link($match); return Strings::normaliseLink($match);
} }
/** /**

View file

@ -12,6 +12,7 @@ use Friendica\Core\Addon;
use Friendica\Core\Logger; use Friendica\Core\Logger;
use Friendica\Database\DBA; use Friendica\Database\DBA;
use Friendica\Object\Image; use Friendica\Object\Image;
use Friendica\Util\Strings;
require_once 'include/dba.php'; require_once 'include/dba.php';
@ -49,7 +50,7 @@ class ParseUrl
} }
$parsed_url = DBA::selectFirst('parsed_url', ['content'], $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'])) { if (!empty($parsed_url['content'])) {
$data = unserialize($parsed_url['content']); $data = unserialize($parsed_url['content']);
@ -61,7 +62,7 @@ class ParseUrl
DBA::insert( DBA::insert(
'parsed_url', 'parsed_url',
[ [
'url' => normalise_link($url), 'guessing' => !$no_guessing, 'url' => Strings::normaliseLink($url), 'guessing' => !$no_guessing,
'oembed' => $do_oembed, 'content' => serialize($data), 'oembed' => $do_oembed, 'content' => serialize($data),
'created' => DateTimeFormat::utcNow() 'created' => DateTimeFormat::utcNow()
], ],

View file

@ -6,6 +6,7 @@ use Friendica\BaseModule;
use Friendica\BaseObject; use Friendica\BaseObject;
use Friendica\Core\Config; use Friendica\Core\Config;
use Friendica\Core\System; use Friendica\Core\System;
use Friendica\Util\Strings;
/** /**
* @brief Proxy utilities class * @brief Proxy utilities class
@ -76,7 +77,7 @@ class Proxy
// Only continue if it isn't a local image and the isn't deactivated // Only continue if it isn't a local image and the isn't deactivated
if (self::isLocalImage($url)) { 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; return $url;
} }
@ -140,7 +141,7 @@ class Proxy
*/ */
public static function proxifyHtml($html) 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('/(<img [^>]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'self::replaceUrl', $html); return preg_replace_callback('/(<img [^>]*src *= *["\'])([^"\']+)(["\'][^>]*>)/siU', 'self::replaceUrl', $html);
} }
@ -162,8 +163,8 @@ class Proxy
} }
// links normalised - bug #431 // links normalised - bug #431
$baseurl = normalise_link(System::baseUrl()); $baseurl = Strings::normaliseLink(System::baseUrl());
$url = normalise_link($url); $url = Strings::normaliseLink($url);
return (substr($url, 0, strlen($baseurl)) == $baseurl); return (substr($url, 0, strlen($baseurl)) == $baseurl);
} }

View file

@ -369,7 +369,7 @@ class Strings
* *
* @return string Normalized URL. * @return string Normalized URL.
*/ */
public static function normaliseLink($url) // normalise_link() public static function normaliseLink($url)
{ {
$ret = str_replace(['https:', '//www.'], ['http:', '//'], $url); $ret = str_replace(['https:', '//www.'], ['http:', '//'], $url);
return rtrim($ret, '/'); return rtrim($ret, '/');

View file

@ -249,7 +249,7 @@ class Delivery extends BaseObject
// perform local delivery if we are on the same site // perform local delivery if we are on the same site
if (Strings::compareLink($basepath, System::baseUrl())) { 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); $target_self = DBA::selectFirst('contact', ['uid'], $condition);
if (!DBA::isResult($target_self)) { if (!DBA::isResult($target_self)) {
return; return;

View file

@ -15,6 +15,7 @@ use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Network; use Friendica\Util\Network;
use Friendica\Util\Strings;
class DiscoverPoCo class DiscoverPoCo
{ {
@ -80,7 +81,7 @@ class DiscoverPoCo
return; return;
} }
$server_url = filter_var($server_url, FILTER_SANITIZE_URL); $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; return;
} }
$result = "Checking server ".$server_url." - "; $result = "Checking server ".$server_url." - ";
@ -162,7 +163,7 @@ class DiscoverPoCo
$urlparts = parse_url($user["url"]); $urlparts = parse_url($user["url"]);
if (!isset($urlparts["scheme"])) { if (!isset($urlparts["scheme"])) {
DBA::update('gcontact', ['network' => Protocol::PHANTOM], DBA::update('gcontact', ['network' => Protocol::PHANTOM],
['nurl' => normalise_link($user["url"])]); ['nurl' => Strings::normaliseLink($user["url"])]);
continue; continue;
} }
@ -170,7 +171,7 @@ class DiscoverPoCo
$networks = ["twitter.com" => Protocol::TWITTER, "identi.ca" => Protocol::PUMPIO]; $networks = ["twitter.com" => Protocol::TWITTER, "identi.ca" => Protocol::PUMPIO];
DBA::update('gcontact', ['network' => $networks[$urlparts["host"]]], DBA::update('gcontact', ['network' => $networks[$urlparts["host"]]],
['nurl' => normalise_link($user["url"])]); ['nurl' => Strings::normaliseLink($user["url"])]);
continue; continue;
} }
@ -179,7 +180,7 @@ class DiscoverPoCo
if ($user["server_url"] != "") { 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"]; $server_url = $user["server_url"];
} }
@ -193,7 +194,7 @@ class DiscoverPoCo
} }
} else { } else {
DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()], DBA::update('gcontact', ['last_failure' => DateTimeFormat::utcNow()],
['nurl' => normalise_link($user["url"])]); ['nurl' => Strings::normaliseLink($user["url"])]);
} }
// Quit the loop after 3 minutes // Quit the loop after 3 minutes
@ -220,7 +221,7 @@ class DiscoverPoCo
if (!empty($j->results)) { if (!empty($j->results)) {
foreach ($j->results as $jj) { foreach ($j->results as $jj) {
// Check if the contact already exists // 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)) { if (DBA::isResult($exists)) {
Logger::log("Profile ".$jj->url." already exists (".$search.")", Logger::DEBUG); Logger::log("Profile ".$jj->url." already exists (".$search.")", Logger::DEBUG);

View file

@ -12,6 +12,7 @@ use Friendica\Database\DBA;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\Strings;
class GProbe { class GProbe {
public static function execute($url = '') public static function execute($url = '')
@ -22,10 +23,10 @@ class GProbe {
$r = q( $r = q(
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", "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)) { if (!DBA::isResult($r)) {
// Is it a DDoS attempt? // Is it a DDoS attempt?
@ -51,7 +52,7 @@ class GProbe {
$r = q( $r = q(
"SELECT `id`, `url`, `network` FROM `gcontact` WHERE `nurl` = '%s' ORDER BY `id` LIMIT 1", "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)) { 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; return;
} }
} }

View file

@ -12,6 +12,7 @@ use Friendica\Database\DBA;
use Friendica\Network\Probe; use Friendica\Network\Probe;
use Friendica\Protocol\PortableContact; use Friendica\Protocol\PortableContact;
use Friendica\Util\DateTimeFormat; use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
class UpdateGContact class UpdateGContact
{ {
@ -78,13 +79,13 @@ class UpdateGContact
DBA::escape($data["nick"]), DBA::escape($data["nick"]),
DBA::escape($data["addr"]), DBA::escape($data["addr"]),
DBA::escape($data["photo"]), DBA::escape($data["photo"]),
DBA::escape(normalise_link($data["url"])) DBA::escape(Strings::normaliseLink($data["url"]))
); );
q("UPDATE `contact` SET `addr` = '%s' q("UPDATE `contact` SET `addr` = '%s'
WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'", WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
DBA::escape($data["addr"]), DBA::escape($data["addr"]),
DBA::escape(normalise_link($data["url"])) DBA::escape(Strings::normaliseLink($data["url"]))
); );
} }
} }

View file

@ -21,6 +21,7 @@ use Friendica\Database\DBA;
use Friendica\Model\Contact; use Friendica\Model\Contact;
use Friendica\Model\GContact; use Friendica\Model\GContact;
use Friendica\Util\Proxy as ProxyUtils; use Friendica\Util\Proxy as ProxyUtils;
use Friendica\Util\Strings;
function vier_init(App $a) function vier_init(App $a)
{ {
@ -277,7 +278,7 @@ function vier_community_info()
$query .= ","; $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); $r = q("SELECT `url`, `name` FROM `gcontact` WHERE `nurl` IN (%s)", $query);