Merge branch 'develop' into introduce-phpmd

This commit is contained in:
Art4 2025-01-23 08:56:07 +00:00
commit 4c95605711
188 changed files with 5977 additions and 5583 deletions

View file

@ -9,12 +9,10 @@ namespace Friendica\Model;
use Friendica\Content\Text\HTML;
use Friendica\Core\Cache\Enum\Duration;
use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\System;
use Friendica\Database\DBA;
use Friendica\DI;
use Friendica\Model\Item;
use Friendica\Network\HTTPException;
use Friendica\Network\Probe;
use Friendica\Protocol\ActivityNamespace;
@ -95,12 +93,12 @@ class APContact
public static function getByURL(string $url, bool $update = null): array
{
if (empty($url) || Network::isUrlBlocked($url)) {
Logger::info('Domain is blocked', ['url' => $url]);
DI::logger()->info('Domain is blocked', ['url' => $url]);
return [];
}
if (!Network::isValidHttpUrl($url) && !filter_var($url, FILTER_VALIDATE_EMAIL)) {
Logger::info('Invalid URL', ['url' => $url]);
DI::logger()->info('Invalid URL', ['url' => $url]);
return [];
}
@ -154,9 +152,9 @@ class APContact
// Detect multiple fast repeating request to the same address
// See https://github.com/friendica/friendica/issues/9303
$cachekey = 'apcontact:' . ItemURI::getIdByURI($url);
$result = DI::cache()->get($cachekey);
$result = DI::cache()->get($cachekey);
if (!is_null($result)) {
Logger::info('Multiple requests for the address', ['url' => $url, 'update' => $update, 'result' => $result]);
DI::logger()->info('Multiple requests for the address', ['url' => $url, 'update' => $update, 'result' => $result]);
if (!empty($fetched_contact)) {
return $fetched_contact;
}
@ -168,7 +166,7 @@ class APContact
if (DI::baseUrl()->isLocalUrl($url) && ($local_uid = User::getIdForURL($url))) {
try {
$data = Transmitter::getProfile($local_uid);
$data = Transmitter::getProfile($local_uid);
$local_owner = User::getOwnerDataById($local_uid);
} catch(HTTPException\NotFoundException $e) {
$data = null;
@ -180,11 +178,11 @@ class APContact
try {
$curlResult = HTTPSignature::fetchRaw($url);
$failed = empty($curlResult->getBodyString()) ||
$failed = empty($curlResult->getBodyString()) ||
(!$curlResult->isSuccess() && ($curlResult->getReturnCode() != 410));
if (!$failed) {
$data = json_decode($curlResult->getBodyString(), true);
if (!$failed) {
$data = json_decode($curlResult->getBodyString(), true);
$failed = empty($data) || !is_array($data);
}
@ -194,7 +192,7 @@ class APContact
$failed = true;
}
} catch (\Exception $exception) {
Logger::notice('Error fetching url', ['url' => $url, 'exception' => $exception]);
DI::logger()->notice('Error fetching url', ['url' => $url, 'exception' => $exception]);
$failed = true;
}
@ -218,13 +216,13 @@ class APContact
*/
private static function compactProfile(array $apcontact, array $compacted, string $url, $fetched_contact, bool $webfinger, $local_owner): array
{
$apcontact['url'] = $compacted['@id'];
$apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value');
$apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
$apcontact['url'] = $compacted['@id'];
$apcontact['uuid'] = JsonLD::fetchElement($compacted, 'diaspora:guid', '@value');
$apcontact['type'] = str_replace('as:', '', JsonLD::fetchElement($compacted, '@type'));
$apcontact['following'] = JsonLD::fetchElement($compacted, 'as:following', '@id');
$apcontact['followers'] = JsonLD::fetchElement($compacted, 'as:followers', '@id');
$apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
$apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
$apcontact['inbox'] = (JsonLD::fetchElement($compacted, 'ldp:inbox', '@id') ?? '');
$apcontact['outbox'] = JsonLD::fetchElement($compacted, 'as:outbox', '@id');
$apcontact['sharedinbox'] = '';
if (!empty($compacted['as:endpoints'])) {
@ -302,7 +300,7 @@ class APContact
try {
$apcontact['addr'] = $apcontact['nick'] . '@' . (new Uri($apcontact['url']))->getAuthority();
} catch (\Throwable $e) {
Logger::warning('Unable to coerce APContact URL into a UriInterface object', ['url' => $apcontact['url'], 'error' => $e->getMessage()]);
DI::logger()->warning('Unable to coerce APContact URL into a UriInterface object', ['url' => $apcontact['url'], 'error' => $e->getMessage()]);
$apcontact['addr'] = '';
}
}
@ -315,12 +313,12 @@ class APContact
}
}
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
$apcontact['manually-approve'] = (int)JsonLD::fetchElement($compacted, 'as:manuallyApprovesFollowers');
$apcontact['posting-restricted'] = (int)JsonLD::fetchElement($compacted, 'lemmy:postingRestrictedToMods');
$apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
$apcontact['suspended'] = (int)JsonLD::fetchElement($compacted, 'toot:suspended');
if (!empty($compacted['as:generator'])) {
$apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
$apcontact['baseurl'] = JsonLD::fetchElement($compacted['as:generator'], 'as:url', '@id');
$apcontact['generator'] = JsonLD::fetchElement($compacted['as:generator'], 'as:name', '@value');
}
@ -360,7 +358,7 @@ class APContact
if (!empty($local_owner)) {
$statuses_count = self::getStatusesCount($local_owner);
} else {
$outbox = HTTPSignature::fetch($apcontact['outbox']);
$outbox = HTTPSignature::fetch($apcontact['outbox']);
$statuses_count = $outbox['totalItems'] ?? 0;
}
if (!empty($statuses_count)) {
@ -382,7 +380,7 @@ class APContact
$apcontact['photo'] = Network::addBasePath($apcontact['photo'], $apcontact['url']);
if (!Network::isValidHttpUrl($apcontact['photo'])) {
Logger::warning('Invalid URL for photo', ['url' => $apcontact['url'], 'photo' => $apcontact['photo']]);
DI::logger()->warning('Invalid URL for photo', ['url' => $apcontact['url'], 'photo' => $apcontact['photo']]);
$apcontact['photo'] = '';
}
}
@ -468,9 +466,9 @@ class APContact
if (in_array($name, APContact\Endpoint::ENDPOINT_NAMES)) {
$key = array_search($name, APContact\Endpoint::ENDPOINT_NAMES);
APContact\Endpoint::update($apcontact['uri-id'], $key, $endpoint['@id']);
Logger::debug('Store endpoint', ['key' => $key, 'name' => $name, 'endpoint' => $endpoint['@id']]);
DI::logger()->debug('Store endpoint', ['key' => $key, 'name' => $name, 'endpoint' => $endpoint['@id']]);
} elseif (!in_array($name, ['as:sharedInbox', 'as:uploadMedia', 'as:oauthTokenEndpoint', 'as:oauthAuthorizationEndpoint', 'litepub:oauthRegistrationEndpoint'])) {
Logger::debug('Unknown endpoint', ['name' => $name, 'endpoint' => $endpoint['@id']]);
DI::logger()->debug('Unknown endpoint', ['name' => $name, 'endpoint' => $endpoint['@id']]);
}
}
}
@ -479,7 +477,7 @@ class APContact
// We delete the old entry when the URL is changed
if ($url != $apcontact['url']) {
Logger::info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]);
DI::logger()->info('Delete changed profile url', ['old' => $url, 'new' => $apcontact['url']]);
DBA::delete('apcontact', ['url' => $url]);
}
@ -492,7 +490,7 @@ class APContact
DBA::replace('apcontact', $apcontact);
}
Logger::info('Updated profile', ['url' => $url]);
DI::logger()->info('Updated profile', ['url' => $url]);
return DBA::selectFirst('apcontact', [], ['url' => $apcontact['url']]) ?: [];
}
@ -543,7 +541,7 @@ class APContact
public static function markForArchival(array $apcontact)
{
if (!empty($apcontact['inbox'])) {
Logger::info('Set inbox status to failure', ['inbox' => $apcontact['inbox']]);
DI::logger()->info('Set inbox status to failure', ['inbox' => $apcontact['inbox']]);
HTTPSignature::setInboxStatus($apcontact['inbox'], false, false, $apcontact['gsid']);
}
@ -553,7 +551,7 @@ class APContact
$apcontact['sharedinbox']]);
if (!$available) {
// If all known personal inboxes are failing then set their shared inbox to failure as well
Logger::info('Set shared inbox status to failure', ['sharedinbox' => $apcontact['sharedinbox']]);
DI::logger()->info('Set shared inbox status to failure', ['sharedinbox' => $apcontact['sharedinbox']]);
HTTPSignature::setInboxStatus($apcontact['sharedinbox'], false, true, $apcontact['gsid']);
}
}
@ -568,11 +566,11 @@ class APContact
public static function unmarkForArchival(array $apcontact)
{
if (!empty($apcontact['inbox'])) {
Logger::info('Set inbox status to success', ['inbox' => $apcontact['inbox']]);
DI::logger()->info('Set inbox status to success', ['inbox' => $apcontact['inbox']]);
HTTPSignature::setInboxStatus($apcontact['inbox'], true, false, $apcontact['gsid']);
}
if (!empty($apcontact['sharedinbox'])) {
Logger::info('Set shared inbox status to success', ['sharedinbox' => $apcontact['sharedinbox']]);
DI::logger()->info('Set shared inbox status to success', ['sharedinbox' => $apcontact['sharedinbox']]);
HTTPSignature::setInboxStatus($apcontact['sharedinbox'], true, true, $apcontact['gsid']);
}
}