Remove dependency to App in Contact::createFromProbe
- Address https://github.com/friendica/friendica/issues/8473#issuecomment-641259906
This commit is contained in:
parent
5f18d27b0b
commit
a5a7855d39
|
@ -40,7 +40,6 @@ function follow_post(App $a)
|
||||||
DI::baseUrl()->redirect('contact');
|
DI::baseUrl()->redirect('contact');
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = local_user();
|
|
||||||
$url = Probe::cleanURI($_REQUEST['url']);
|
$url = Probe::cleanURI($_REQUEST['url']);
|
||||||
$return_path = 'follow?url=' . urlencode($url);
|
$return_path = 'follow?url=' . urlencode($url);
|
||||||
|
|
||||||
|
@ -48,7 +47,7 @@ function follow_post(App $a)
|
||||||
// This is just a precaution if maybe this page is called somewhere directly via POST
|
// This is just a precaution if maybe this page is called somewhere directly via POST
|
||||||
$_SESSION['fastlane'] = $url;
|
$_SESSION['fastlane'] = $url;
|
||||||
|
|
||||||
$result = Contact::createFromProbe($uid, $url, true);
|
$result = Contact::createFromProbe($a->user, $url, true);
|
||||||
|
|
||||||
if ($result['success'] == false) {
|
if ($result['success'] == false) {
|
||||||
// Possibly it is a remote item and not an account
|
// Possibly it is a remote item and not an account
|
||||||
|
|
|
@ -91,7 +91,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($uid, $url, true, Protocol::OSTATUS);
|
$result = Contact::createFromProbe($a->user, $url, true, Protocol::OSTATUS);
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
$o .= ' - ' . DI::l10n()->t('success');
|
$o .= ' - ' . DI::l10n()->t('success');
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -70,7 +70,7 @@ function repair_ostatus_content(App $a) {
|
||||||
|
|
||||||
$o .= "<p>".DI::l10n()->t("Keep this window open until done.")."</p>";
|
$o .= "<p>".DI::l10n()->t("Keep this window open until done.")."</p>";
|
||||||
|
|
||||||
Contact::createFromProbe($uid, $r[0]["url"], true);
|
Contact::createFromProbe($a->user, $r[0]["url"], true);
|
||||||
|
|
||||||
DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter='.$counter.'">';
|
DI::page()['htmlhead'] = '<meta http-equiv="refresh" content="1; URL=' . DI::baseUrl() . '/repair_ostatus?counter='.$counter.'">';
|
||||||
|
|
||||||
|
|
|
@ -42,15 +42,11 @@ function salmon_post(App $a, $xml = '') {
|
||||||
|
|
||||||
$nick = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : '');
|
$nick = (($a->argc > 1) ? Strings::escapeTags(trim($a->argv[1])) : '');
|
||||||
|
|
||||||
$r = q("SELECT * FROM `user` WHERE `nickname` = '%s' AND `account_expired` = 0 AND `account_removed` = 0 LIMIT 1",
|
$importer = DBA::selectFirst('user', [], ['nickname' => $nick, 'account_expired' => false, 'account_removed' => false]);
|
||||||
DBA::escape($nick)
|
if (! DBA::isResult($importer)) {
|
||||||
);
|
|
||||||
if (! DBA::isResult($r)) {
|
|
||||||
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
throw new \Friendica\Network\HTTPException\InternalServerErrorException();
|
||||||
}
|
}
|
||||||
|
|
||||||
$importer = $r[0];
|
|
||||||
|
|
||||||
// parse the xml
|
// parse the xml
|
||||||
|
|
||||||
$dom = simplexml_load_string($xml,'SimpleXMLElement',0, ActivityNamespace::SALMON_ME);
|
$dom = simplexml_load_string($xml,'SimpleXMLElement',0, ActivityNamespace::SALMON_ME);
|
||||||
|
@ -175,7 +171,7 @@ function salmon_post(App $a, $xml = '') {
|
||||||
Logger::log('Author ' . $author_link . ' unknown to user ' . $importer['uid'] . '.');
|
Logger::log('Author ' . $author_link . ' unknown to user ' . $importer['uid'] . '.');
|
||||||
|
|
||||||
if (DI::pConfig()->get($importer['uid'], 'system', 'ostatus_autofriend')) {
|
if (DI::pConfig()->get($importer['uid'], 'system', 'ostatus_autofriend')) {
|
||||||
$result = Contact::createFromProbe($importer['uid'], $author_link);
|
$result = Contact::createFromProbe($importer, $author_link);
|
||||||
|
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
$r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s')
|
$r = q("SELECT * FROM `contact` WHERE `network` = '%s' AND ( `url` = '%s' OR `alias` = '%s')
|
||||||
|
|
|
@ -2272,20 +2272,20 @@ class Contact
|
||||||
* $return['message'] error text if success is false.
|
* $return['message'] error text if success is false.
|
||||||
*
|
*
|
||||||
* Takes a $uid and a url/handle and adds a new contact
|
* Takes a $uid and a url/handle and adds a new contact
|
||||||
* @param int $uid
|
*
|
||||||
* @param string $url
|
* @param array $user The user the contact should be created for
|
||||||
|
* @param string $url The profile URL of the contact
|
||||||
* @param bool $interactive
|
* @param bool $interactive
|
||||||
* @param string $network
|
* @param string $network
|
||||||
* @return array
|
* @return array
|
||||||
* @throws HTTPException\InternalServerErrorException
|
* @throws HTTPException\InternalServerErrorException
|
||||||
|
* @throws HTTPException\NotFoundException
|
||||||
* @throws \ImagickException
|
* @throws \ImagickException
|
||||||
*/
|
*/
|
||||||
public static function createFromProbe($uid, $url, $interactive = false, $network = '')
|
public static function createFromProbe(array $user, $url, $interactive = false, $network = '')
|
||||||
{
|
{
|
||||||
$result = ['cid' => -1, 'success' => false, 'message' => ''];
|
$result = ['cid' => -1, 'success' => false, 'message' => ''];
|
||||||
|
|
||||||
$a = DI::app();
|
|
||||||
|
|
||||||
// remove ajax junk, e.g. Twitter
|
// remove ajax junk, e.g. Twitter
|
||||||
$url = str_replace('/#!/', '/', $url);
|
$url = str_replace('/#!/', '/', $url);
|
||||||
|
|
||||||
|
@ -2316,7 +2316,7 @@ class Contact
|
||||||
if (!empty($arr['contact']['name'])) {
|
if (!empty($arr['contact']['name'])) {
|
||||||
$ret = $arr['contact'];
|
$ret = $arr['contact'];
|
||||||
} else {
|
} else {
|
||||||
$ret = Probe::uri($url, $network, $uid, false);
|
$ret = Probe::uri($url, $network, $user['uid'], false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (($network != '') && ($ret['network'] != $network)) {
|
if (($network != '') && ($ret['network'] != $network)) {
|
||||||
|
@ -2328,10 +2328,10 @@ class Contact
|
||||||
// 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'], 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' => $uid, 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false];
|
$condition = ['uid' => $user['uid'], 'nurl' => Strings::normaliseLink($url), 'network' => $ret['network'], 'pending' => false];
|
||||||
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
|
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2340,9 +2340,9 @@ class Contact
|
||||||
if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
|
if (($protocol === Protocol::DFRN) && !DBA::isResult($contact)) {
|
||||||
if ($interactive) {
|
if ($interactive) {
|
||||||
if (strlen(DI::baseUrl()->getUrlPath())) {
|
if (strlen(DI::baseUrl()->getUrlPath())) {
|
||||||
$myaddr = bin2hex(DI::baseUrl() . '/profile/' . $a->user['nickname']);
|
$myaddr = bin2hex(DI::baseUrl() . '/profile/' . $user['nickname']);
|
||||||
} else {
|
} else {
|
||||||
$myaddr = bin2hex($a->user['nickname'] . '@' . DI::baseUrl()->getHostname());
|
$myaddr = bin2hex($user['nickname'] . '@' . DI::baseUrl()->getHostname());
|
||||||
}
|
}
|
||||||
|
|
||||||
DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr");
|
DI::baseUrl()->redirect($ret['request'] . "&addr=$myaddr");
|
||||||
|
@ -2417,7 +2417,7 @@ class Contact
|
||||||
|
|
||||||
// create contact record
|
// create contact record
|
||||||
self::insert([
|
self::insert([
|
||||||
'uid' => $uid,
|
'uid' => $user['uid'],
|
||||||
'created' => DateTimeFormat::utcNow(),
|
'created' => DateTimeFormat::utcNow(),
|
||||||
'url' => $ret['url'],
|
'url' => $ret['url'],
|
||||||
'nurl' => Strings::normaliseLink($ret['url']),
|
'nurl' => Strings::normaliseLink($ret['url']),
|
||||||
|
@ -2445,7 +2445,7 @@ class Contact
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = DBA::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $uid]);
|
$contact = DBA::selectFirst('contact', [], ['url' => $ret['url'], 'network' => $ret['network'], 'uid' => $user['uid']]);
|
||||||
if (!DBA::isResult($contact)) {
|
if (!DBA::isResult($contact)) {
|
||||||
$result['message'] .= DI::l10n()->t('Unable to retrieve contact information.') . EOL;
|
$result['message'] .= DI::l10n()->t('Unable to retrieve contact information.') . EOL;
|
||||||
return $result;
|
return $result;
|
||||||
|
@ -2454,16 +2454,16 @@ class Contact
|
||||||
$contact_id = $contact['id'];
|
$contact_id = $contact['id'];
|
||||||
$result['cid'] = $contact_id;
|
$result['cid'] = $contact_id;
|
||||||
|
|
||||||
Group::addMember(User::getDefaultGroup($uid, $contact["network"]), $contact_id);
|
Group::addMember(User::getDefaultGroup($user['uid'], $contact["network"]), $contact_id);
|
||||||
|
|
||||||
// Update the avatar
|
// Update the avatar
|
||||||
self::updateAvatar($ret['photo'], $uid, $contact_id);
|
self::updateAvatar($ret['photo'], $user['uid'], $contact_id);
|
||||||
|
|
||||||
// pull feed and consume it, which should subscribe to the hub.
|
// pull feed and consume it, which should subscribe to the hub.
|
||||||
|
|
||||||
Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
|
Worker::add(PRIORITY_HIGH, "OnePoll", $contact_id, "force");
|
||||||
|
|
||||||
$owner = User::getOwnerDataById($uid);
|
$owner = User::getOwnerDataById($user['uid']);
|
||||||
|
|
||||||
if (DBA::isResult($owner)) {
|
if (DBA::isResult($owner)) {
|
||||||
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
|
if (in_array($protocol, [Protocol::OSTATUS, Protocol::DFRN])) {
|
||||||
|
@ -2483,7 +2483,7 @@ class Contact
|
||||||
Salmon::slapper($owner, $contact['notify'], $slap);
|
Salmon::slapper($owner, $contact['notify'], $slap);
|
||||||
}
|
}
|
||||||
} elseif ($protocol == Protocol::DIASPORA) {
|
} elseif ($protocol == Protocol::DIASPORA) {
|
||||||
$ret = Diaspora::sendShare($a->user, $contact);
|
$ret = Diaspora::sendShare($owner, $contact);
|
||||||
Logger::log('share returns: ' . $ret);
|
Logger::log('share returns: ' . $ret);
|
||||||
} elseif ($protocol == Protocol::ACTIVITYPUB) {
|
} elseif ($protocol == Protocol::ACTIVITYPUB) {
|
||||||
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
|
$activity_id = ActivityPub\Transmitter::activityIDFromContact($contact_id);
|
||||||
|
@ -2492,7 +2492,7 @@ class Contact
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $uid, $activity_id);
|
$ret = ActivityPub\Transmitter::sendActivity('Follow', $contact['url'], $user['uid'], $activity_id);
|
||||||
Logger::log('Follow returns: ' . $ret);
|
Logger::log('Follow returns: ' . $ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2677,7 +2677,7 @@ class Contact
|
||||||
}
|
}
|
||||||
} elseif (DBA::isResult($user) && in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
|
} elseif (DBA::isResult($user) && in_array($user['page-flags'], [User::PAGE_FLAGS_SOAPBOX, User::PAGE_FLAGS_FREELOVE, User::PAGE_FLAGS_COMMUNITY])) {
|
||||||
if (($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) && ($network != Protocol::DIASPORA)) {
|
if (($user['page-flags'] == User::PAGE_FLAGS_FREELOVE) && ($network != Protocol::DIASPORA)) {
|
||||||
self::createFromProbe($importer['uid'], $url, false, $network);
|
self::createFromProbe($importer, $url, false, $network);
|
||||||
}
|
}
|
||||||
|
|
||||||
$condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];
|
$condition = ['uid' => $importer['uid'], 'url' => $url, 'pending' => true];
|
||||||
|
|
|
@ -167,10 +167,9 @@ class Contact extends BaseModule
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uid = $contact['uid'];
|
|
||||||
|
|
||||||
if ($contact['network'] == Protocol::OSTATUS) {
|
if ($contact['network'] == Protocol::OSTATUS) {
|
||||||
$result = Model\Contact::createFromProbe($uid, $contact['url'], false, $contact['network']);
|
$user = Model\User::getById($contact['uid']);
|
||||||
|
$result = Model\Contact::createFromProbe($user, $contact['url'], false, $contact['network']);
|
||||||
|
|
||||||
if ($result['success']) {
|
if ($result['success']) {
|
||||||
DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
|
DBA::update('contact', ['subhub' => 1], ['id' => $contact_id]);
|
||||||
|
|
|
@ -23,6 +23,7 @@ namespace Friendica\Worker;
|
||||||
|
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Model\Contact;
|
use Friendica\Model\Contact;
|
||||||
|
use Friendica\Model\User;
|
||||||
|
|
||||||
class AddContact
|
class AddContact
|
||||||
{
|
{
|
||||||
|
@ -33,7 +34,11 @@ class AddContact
|
||||||
*/
|
*/
|
||||||
public static function execute(int $uid, string $url)
|
public static function execute(int $uid, string $url)
|
||||||
{
|
{
|
||||||
$result = Contact::createFromProbe($uid, $url, '', false);
|
$user = User::getById($uid);
|
||||||
|
if (empty($user)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$result = Contact::createFromProbe($user, $url, '', false);
|
||||||
Logger::info('Added contact', ['uid' => $uid, 'url' => $url, 'result' => $result]);
|
Logger::info('Added contact', ['uid' => $uid, 'url' => $url, 'result' => $result]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue