Merge pull request #8811 from MrPetovan/task/8517-probe-mobile-twitter

Add support for mobile profile URL to core twitter probing
This commit is contained in:
Michael Vogel 2020-06-27 17:32:19 +02:00 committed by GitHub
commit c852e1479c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 21 additions and 26 deletions

View File

@ -297,8 +297,8 @@ function dfrn_request_post(App $a)
$data = Probe::uri($url); $data = Probe::uri($url);
$network = $data["network"]; $network = $data["network"];
// Canonicalise email-style profile locator // Canonicalize email-style profile locator
$url = Probe::webfingerDfrn($url, $hcard); $url = Probe::webfingerDfrn($data['url'], $hcard);
if (substr($url, 0, 5) === 'stat:') { if (substr($url, 0, 5) === 'stat:') {
// Every time we detect the remote subscription we define this as OStatus. // Every time we detect the remote subscription we define this as OStatus.

View File

@ -129,7 +129,7 @@ function follow_content(App $a)
if ($protocol == Protocol::PHANTOM) { if ($protocol == Protocol::PHANTOM) {
// Possibly it is a remote item and not an account // Possibly it is a remote item and not an account
follow_remote_item($url); follow_remote_item($ret['url']);
notice(DI::l10n()->t("The network type couldn't be detected. Contact can't be added.")); notice(DI::l10n()->t("The network type couldn't be detected. Contact can't be added."));
$submit = ''; $submit = '';

View File

@ -48,7 +48,6 @@ function ostatus_subscribe_content(App $a)
} }
$contact = Probe::uri($_REQUEST['url']); $contact = Probe::uri($_REQUEST['url']);
if (!$contact) { if (!$contact) {
DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact'); DI::pConfig()->delete($uid, 'ostatus', 'legacy_contact');
return $o . DI::l10n()->t('Couldn\'t fetch information for contact.'); return $o . DI::l10n()->t('Couldn\'t fetch information for contact.');
@ -91,7 +90,7 @@ function ostatus_subscribe_content(App $a)
$probed = Probe::uri($url); $probed = Probe::uri($url);
if ($probed['network'] == Protocol::OSTATUS) { if ($probed['network'] == Protocol::OSTATUS) {
$result = Contact::createFromProbe($a->user, $url, true, Protocol::OSTATUS); $result = Contact::createFromProbe($a->user, $probed['url'], true, Protocol::OSTATUS);
if ($result['success']) { if ($result['success']) {
$o .= ' - ' . DI::l10n()->t('success'); $o .= ' - ' . DI::l10n()->t('success');
} else { } else {

View File

@ -1572,7 +1572,7 @@ class Contact
$data['gsid'] = GServer::getID($data['baseurl']); $data['gsid'] = GServer::getID($data['baseurl']);
} }
if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $url) && !$in_loop) { if (!$contact_id && !empty($data['alias']) && ($data['alias'] != $data['url']) && !$in_loop) {
$contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true); $contact_id = self::getIdForURL($data["alias"], $uid, true, $default, true);
} }
@ -2353,11 +2353,11 @@ class Contact
$condition = ['uid' => $user['uid'], 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false]; $condition = ['uid' => $user['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' => $user['uid'], 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false]; $condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($ret['url']), 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition); $contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
} }
$protocol = self::getProtocol($url, $ret['network']); $protocol = self::getProtocol($ret['url'], $ret['network']);
if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) { if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
if ($interactive) { if ($interactive) {
@ -2394,7 +2394,7 @@ class Contact
if (empty($ret['url'])) { if (empty($ret['url'])) {
$result['message'] .= DI::l10n()->t('No browser URL could be matched to this address.') . EOL; $result['message'] .= DI::l10n()->t('No browser URL could be matched to this address.') . EOL;
} }
if (strpos($url, '@') !== false) { if (strpos($ret['url'], '@') !== false) {
$result['message'] .= DI::l10n()->t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL; $result['message'] .= DI::l10n()->t('Unable to match @-style Identity Address with a known protocol or email contact.') . EOL;
$result['message'] .= DI::l10n()->t('Use mailto: in front of address to force email check.') . EOL; $result['message'] .= DI::l10n()->t('Use mailto: in front of address to force email check.') . EOL;
} }
@ -2418,7 +2418,7 @@ class Contact
$pending = false; $pending = false;
if ($protocol == Protocol::ACTIVITYPUB) { if ($protocol == Protocol::ACTIVITYPUB) {
$apcontact = APContact::getByURL($url, false); $apcontact = APContact::getByURL($ret['url'], false);
if (isset($apcontact['manually-approve'])) { if (isset($apcontact['manually-approve'])) {
$pending = (bool)$apcontact['manually-approve']; $pending = (bool)$apcontact['manually-approve'];
} }

View File

@ -230,8 +230,6 @@ class GContact
throw new Exception('Probing for URL ' . $gcontact['url'] . ' failed'); throw new Exception('Probing for URL ' . $gcontact['url'] . ' failed');
} }
$orig_profile = $gcontact['url'];
$gcontact['server_url'] = $data['baseurl']; $gcontact['server_url'] = $data['baseurl'];
$gcontact = array_merge($gcontact, $data); $gcontact = array_merge($gcontact, $data);

View File

@ -268,7 +268,6 @@ class Mail
$uri = Item::newURI(local_user(), $guid); $uri = Item::newURI(local_user(), $guid);
$me = Probe::uri($replyto); $me = Probe::uri($replyto);
if (!$me['name']) { if (!$me['name']) {
return -2; return -2;
} }
@ -277,10 +276,7 @@ class Mail
$recip_handle = $recipient['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3); $recip_handle = $recipient['nickname'] . '@' . substr(DI::baseUrl(), strpos(DI::baseUrl(), '://') + 3);
$sender_nick = basename($replyto); $sender_handle = $me['addr'];
$sender_host = substr($replyto, strpos($replyto, '://') + 3);
$sender_host = substr($sender_host, 0, strpos($sender_host, '/'));
$sender_handle = $sender_nick . '@' . $sender_host;
$handles = $recip_handle . ';' . $sender_handle; $handles = $recip_handle . ';' . $sender_handle;
@ -313,7 +309,7 @@ class Mail
'reply' => 0, 'reply' => 0,
'replied' => 0, 'replied' => 0,
'uri' => $uri, 'uri' => $uri,
'parent-uri' => $replyto, 'parent-uri' => $me['url'],
'created' => DateTimeFormat::utcNow(), 'created' => DateTimeFormat::utcNow(),
'unknown' => 1 'unknown' => 1
] ]

View File

@ -36,7 +36,6 @@ class Acctlink extends BaseModule
if ($addr) { if ($addr) {
$url = Probe::uri($addr)['url'] ?? ''; $url = Probe::uri($addr)['url'] ?? '';
if ($url) { if ($url) {
System::externalRedirect($url); System::externalRedirect($url);
exit(); exit();

View File

@ -692,7 +692,7 @@ class Probe
$parts = parse_url($uri); $parts = parse_url($uri);
if (!empty($parts['scheme']) && !empty($parts['host'])) { if (!empty($parts['scheme']) && !empty($parts['host'])) {
if ($parts['host'] == 'twitter.com') { if (in_array($parts['host'], ['twitter.com', 'mobile.twitter.com'])) {
return self::twitter($uri); return self::twitter($uri);
} }
} elseif (strstr($uri, '@')) { } elseif (strstr($uri, '@')) {
@ -706,7 +706,9 @@ class Probe
return self::mail($uri, $uid); return self::mail($uri, $uid);
} }
if (strpos($uri, '@twitter.com')) { if (Strings::endsWith($uri, '@twitter.com')
|| Strings::endsWith($uri, '@mobile.twitter.com')
) {
return self::twitter($uri); return self::twitter($uri);
} }
} else { } else {
@ -1720,9 +1722,9 @@ class Probe
*/ */
private static function twitter($uri) private static function twitter($uri)
{ {
if (preg_match('=(.*)@twitter.com=i', $uri, $matches)) { if (preg_match('=([^@]+)@(?:mobile\.)?twitter\.com$=i', $uri, $matches)) {
$nick = $matches[1]; $nick = $matches[1];
} elseif (preg_match('=https?://twitter.com/(.*)=i', $uri, $matches)) { } elseif (preg_match('=^https?://(?:mobile\.)?twitter\.com/(.+)=i', $uri, $matches)) {
$nick = $matches[1]; $nick = $matches[1];
} else { } else {
return []; return [];

View File

@ -1829,11 +1829,12 @@ class OStatus
$item["private"] = Item::PRIVATE; $item["private"] = Item::PRIVATE;
$contact = Probe::uri($item['follow']); $contact = Probe::uri($item['follow']);
$item['follow'] = $contact['url'];
if ($contact['alias'] == '') { if ($contact['alias']) {
$contact['alias'] = $contact["url"];
} else {
$item['follow'] = $contact['alias']; $item['follow'] = $contact['alias'];
} else {
$contact['alias'] = $contact['url'];
} }
$condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($contact["url"])]; $condition = ['uid' => $owner['uid'], 'nurl' => Strings::normaliseLink($contact["url"])];