1
0
Fork 0

Merge remote-tracking branch 'upstream/develop' into diaspora-reshare

This commit is contained in:
Michael 2022-12-20 06:58:36 +00:00
commit 4db4d1843d
52 changed files with 5745 additions and 5298 deletions

View file

@ -1130,39 +1130,25 @@ class Contact
* Returns the data array for the photo menu of a given contact
*
* @param array $contact contact
* @param int $uid optional, default 0
* @param int $uid Visitor user id
* @return array
* @throws HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function photoMenu(array $contact, int $uid = 0): array
public static function photoMenu(array $contact, int $uid): array
{
$pm_url = '';
// Anonymous visitor
if (!$uid) {
return ['profile' => [DI::l10n()->t('View Profile'), self::magicLinkByContact($contact), true]];
}
$pm_url = '';
$status_link = '';
$photos_link = '';
if ($uid == 0) {
$uid = DI::userSession()->getLocalUserId();
}
if (empty($contact['uid']) || ($contact['uid'] != $uid)) {
if ($uid == 0) {
$profile_link = self::magicLinkByContact($contact);
$menu = ['profile' => [DI::l10n()->t('View Profile'), $profile_link, true]];
return $menu;
}
// Look for our own contact if the uid doesn't match and isn't public
$contact_own = DBA::selectFirst('contact', [], ['nurl' => $contact['nurl'], 'network' => $contact['network'], 'uid' => $uid]);
if (DBA::isResult($contact_own)) {
return self::photoMenu($contact_own, $uid);
}
}
$sparkle = false;
if (($contact['network'] === Protocol::DFRN) && !$contact['self'] && empty($contact['pending'])) {
$sparkle = true;
$sparkle = true;
$profile_link = 'contact/redir/' . $contact['id'];
} else {
$profile_link = $contact['url'];
@ -1173,8 +1159,8 @@ class Contact
}
if ($sparkle) {
$status_link = $profile_link . '/status';
$photos_link = $profile_link . '/photos';
$status_link = $profile_link . '/status';
$photos_link = $profile_link . '/photos';
$profile_link = $profile_link . '/profile';
}
@ -1183,15 +1169,14 @@ class Contact
}
$contact_url = 'contact/' . $contact['id'];
$posts_link = 'contact/' . $contact['id'] . '/conversations';
$follow_link = '';
$follow_link = '';
$unfollow_link = '';
if (!$contact['self'] && Protocol::supportsFollow($contact['network'])) {
if ($contact['uid'] && in_array($contact['rel'], [self::SHARING, self::FRIEND])) {
$unfollow_link = 'contact/unfollow?url=' . urlencode($contact['url']) . '&auto=1';
} elseif(!$contact['pending']) {
} elseif (!$contact['pending']) {
$follow_link = 'contact/follow?url=' . urlencode($contact['url']) . '&auto=1';
}
}
@ -1202,27 +1187,27 @@ class Contact
*/
if (empty($contact['uid'])) {
$menu = [
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link, true],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
];
} else {
$menu = [
'status' => [DI::l10n()->t('View Status') , $status_link , true],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true],
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true],
'unfollow'=> [DI::l10n()->t('Unfollow') , $unfollow_link , true],
'status' => [DI::l10n()->t('View Status') , $status_link , true ],
'profile' => [DI::l10n()->t('View Profile') , $profile_link , true ],
'photos' => [DI::l10n()->t('View Photos') , $photos_link , true ],
'network' => [DI::l10n()->t('Network Posts') , $posts_link , false],
'edit' => [DI::l10n()->t('View Contact') , $contact_url , false],
'pm' => [DI::l10n()->t('Send PM') , $pm_url , false],
'follow' => [DI::l10n()->t('Connect/Follow'), $follow_link , true ],
'unfollow' => [DI::l10n()->t('Unfollow') , $unfollow_link, true ],
];
if (!empty($contact['pending'])) {
try {
$intro = DI::intro()->selectForContact($contact['id']);
$intro = DI::intro()->selectForContact($contact['id']);
$menu['follow'] = [DI::l10n()->t('Approve'), 'notifications/intros/' . $intro->id, true];
} catch (IntroductionNotFoundException $exception) {
DI::logger()->error('Pending contact doesn\'t have an introduction.', ['exception' => $exception]);
@ -1401,14 +1386,18 @@ class Contact
if ($data['network'] == Protocol::DIASPORA) {
try {
DI::dsprContact()->updateFromProbeArray($data);
} catch (HTTPException\NotFoundException $e) {
Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data]);
} catch (\InvalidArgumentException $e) {
Logger::error($e->getMessage(), ['url' => $url, 'data' => $data]);
Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data]);
}
} elseif (!empty($data['networks'][Protocol::DIASPORA])) {
try {
DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]);
} catch (HTTPException\NotFoundException $e) {
Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data['networks'][Protocol::DIASPORA]]);
} catch (\InvalidArgumentException $e) {
Logger::error($e->getMessage(), ['url' => $url, 'data' => $data['networks'][Protocol::DIASPORA]]);
Logger::notice($e->getMessage(), ['url' => $url, 'data' => $data['networks'][Protocol::DIASPORA]]);
}
}
@ -2513,14 +2502,18 @@ class Contact
if ($data['network'] == Protocol::DIASPORA) {
try {
DI::dsprContact()->updateFromProbeArray($data);
} catch (HTTPException\NotFoundException $e) {
Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
} catch (\InvalidArgumentException $e) {
Logger::error($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
}
} elseif (!empty($data['networks'][Protocol::DIASPORA])) {
try {
DI::dsprContact()->updateFromProbeArray($data['networks'][Protocol::DIASPORA]);
} catch (HTTPException\NotFoundException $e) {
Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
} catch (\InvalidArgumentException $e) {
Logger::error($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
Logger::notice($e->getMessage(), ['id' => $id, 'network' => $network, 'contact' => $contact, 'data' => $data]);
}
}
@ -2923,15 +2916,8 @@ class Contact
}
// check if we already have a contact
// the poll url is more reliable than the profile url, as we may have
// indirect links or webfinger links
$condition = ['uid' => $uid, 'poll' => [$ret['poll'], Strings::normaliseLink($ret['poll'])], 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
if (!DBA::isResult($contact)) {
$condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url']), 'network' => $ret['network'], 'pending' => false];
$contact = DBA::selectFirst('contact', ['id', 'rel'], $condition);
}
$condition = ['uid' => $uid, 'nurl' => Strings::normaliseLink($ret['url'])];
$contact = DBA::selectFirst('contact', ['id', 'rel', 'url', 'pending', 'hub-verify'], $condition);
$protocol = self::getProtocol($ret['url'], $ret['network']);
@ -2987,7 +2973,13 @@ class Contact
// update contact
$new_relation = (in_array($contact['rel'], [self::FOLLOWER, self::FRIEND]) ? self::FRIEND : self::SHARING);
$fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false];
$fields = ['rel' => $new_relation, 'subhub' => $subhub, 'readonly' => false, 'network' => $ret['network']];
if ($contact['pending'] && !empty($contact['hub-verify'])) {
ActivityPub\Transmitter::sendContactAccept($contact['url'], $contact['hub-verify'], $uid);
$fields['pending'] = false;
}
self::update($fields, ['id' => $contact['id']]);
} else {
$new_relation = (in_array($protocol, [Protocol::MAIL]) ? self::FRIEND : self::SHARING);

View file

@ -412,66 +412,66 @@ class Event
public static function getStrings(): array
{
// First day of the week (0 = Sunday).
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'system', 'first_day_of_week', 0);
$firstDay = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'first_day_of_week') ?? 0;
$defaultView = DI::pConfig()->get(DI::userSession()->getLocalUserId(), 'calendar', 'defaultView') ?? 'month';
$i18n = [
"firstDay" => $firstDay,
"allday" => DI::l10n()->t("all-day"),
return [
'firstDay' => $firstDay,
'defaultView' => $defaultView,
'allday' => DI::l10n()->t('all-day'),
"Sun" => DI::l10n()->t("Sun"),
"Mon" => DI::l10n()->t("Mon"),
"Tue" => DI::l10n()->t("Tue"),
"Wed" => DI::l10n()->t("Wed"),
"Thu" => DI::l10n()->t("Thu"),
"Fri" => DI::l10n()->t("Fri"),
"Sat" => DI::l10n()->t("Sat"),
'Sun' => DI::l10n()->t('Sun'),
'Mon' => DI::l10n()->t('Mon'),
'Tue' => DI::l10n()->t('Tue'),
'Wed' => DI::l10n()->t('Wed'),
'Thu' => DI::l10n()->t('Thu'),
'Fri' => DI::l10n()->t('Fri'),
'Sat' => DI::l10n()->t('Sat'),
"Sunday" => DI::l10n()->t("Sunday"),
"Monday" => DI::l10n()->t("Monday"),
"Tuesday" => DI::l10n()->t("Tuesday"),
"Wednesday" => DI::l10n()->t("Wednesday"),
"Thursday" => DI::l10n()->t("Thursday"),
"Friday" => DI::l10n()->t("Friday"),
"Saturday" => DI::l10n()->t("Saturday"),
'Sunday' => DI::l10n()->t('Sunday'),
'Monday' => DI::l10n()->t('Monday'),
'Tuesday' => DI::l10n()->t('Tuesday'),
'Wednesday' => DI::l10n()->t('Wednesday'),
'Thursday' => DI::l10n()->t('Thursday'),
'Friday' => DI::l10n()->t('Friday'),
'Saturday' => DI::l10n()->t('Saturday'),
"Jan" => DI::l10n()->t("Jan"),
"Feb" => DI::l10n()->t("Feb"),
"Mar" => DI::l10n()->t("Mar"),
"Apr" => DI::l10n()->t("Apr"),
"May" => DI::l10n()->t("May"),
"Jun" => DI::l10n()->t("Jun"),
"Jul" => DI::l10n()->t("Jul"),
"Aug" => DI::l10n()->t("Aug"),
"Sep" => DI::l10n()->t("Sept"),
"Oct" => DI::l10n()->t("Oct"),
"Nov" => DI::l10n()->t("Nov"),
"Dec" => DI::l10n()->t("Dec"),
'Jan' => DI::l10n()->t('Jan'),
'Feb' => DI::l10n()->t('Feb'),
'Mar' => DI::l10n()->t('Mar'),
'Apr' => DI::l10n()->t('Apr'),
'May' => DI::l10n()->t('May'),
'Jun' => DI::l10n()->t('Jun'),
'Jul' => DI::l10n()->t('Jul'),
'Aug' => DI::l10n()->t('Aug'),
'Sep' => DI::l10n()->t('Sept'),
'Oct' => DI::l10n()->t('Oct'),
'Nov' => DI::l10n()->t('Nov'),
'Dec' => DI::l10n()->t('Dec'),
"January" => DI::l10n()->t("January"),
"February" => DI::l10n()->t("February"),
"March" => DI::l10n()->t("March"),
"April" => DI::l10n()->t("April"),
"June" => DI::l10n()->t("June"),
"July" => DI::l10n()->t("July"),
"August" => DI::l10n()->t("August"),
"September" => DI::l10n()->t("September"),
"October" => DI::l10n()->t("October"),
"November" => DI::l10n()->t("November"),
"December" => DI::l10n()->t("December"),
'January' => DI::l10n()->t('January'),
'February' => DI::l10n()->t('February'),
'March' => DI::l10n()->t('March'),
'April' => DI::l10n()->t('April'),
'June' => DI::l10n()->t('June'),
'July' => DI::l10n()->t('July'),
'August' => DI::l10n()->t('August'),
'September' => DI::l10n()->t('September'),
'October' => DI::l10n()->t('October'),
'November' => DI::l10n()->t('November'),
'December' => DI::l10n()->t('December'),
"today" => DI::l10n()->t("today"),
"month" => DI::l10n()->t("month"),
"week" => DI::l10n()->t("week"),
"day" => DI::l10n()->t("day"),
'today' => DI::l10n()->t('today'),
'month' => DI::l10n()->t('month'),
'week' => DI::l10n()->t('week'),
'day' => DI::l10n()->t('day'),
"noevent" => DI::l10n()->t("No events to display"),
'noevent' => DI::l10n()->t('No events to display'),
"dtstart_label" => DI::l10n()->t("Starts:"),
"dtend_label" => DI::l10n()->t("Finishes:"),
"location_label" => DI::l10n()->t("Location:")
'dtstart_label' => DI::l10n()->t('Starts:'),
'dtend_label' => DI::l10n()->t('Finishes:'),
'location_label' => DI::l10n()->t('Location:')
];
return $i18n;
}
/**

View file

@ -167,27 +167,43 @@ class GServer
/**
* Checks if the given server is reachable
*
* @param string $profile URL of the given profile
* @param string $server URL of the given server (If empty, taken from profile)
* @param string $network Network value that is used, when detection failed
* @param boolean $force Force an update.
* @param array $contact Contact that should be checked
*
* @return boolean 'true' if server seems vital
*/
public static function reachable(string $profile, string $server = '', string $network = '', bool $force = false): bool
public static function reachable(array $contact): bool
{
if ($server == '') {
$contact = Contact::getByURL($profile, null, ['baseurl']);
if (!empty($contact['baseurl'])) {
$server = $contact['baseurl'];
}
}
if ($server == '') {
if (!empty($contact['gsid'])) {
$gsid = $contact['gsid'];
} elseif (!empty($contact['baseurl'])) {
$server = $contact['baseurl'];
} elseif ($contact['network'] == Protocol::DIASPORA) {
$parts = parse_url($contact['url']);
unset($parts['path']);
$server = (string)Uri::fromParts($parts);
} else {
return true;
}
return self::check($server, $network, $force);
if (!empty($gsid)) {
$condition = ['id' => $gsid];
} else {
$condition = ['nurl' => Strings::normaliseLink($server)];
}
$gserver = DBA::selectFirst('gserver', ['url', 'next_contact', 'failed'], $condition);
if (empty($gserver)) {
$reachable = true;
} else {
$reachable = !$gserver['failed'];
$server = $gserver['url'];
}
if (!empty($server) && (empty($gserver) || strtotime($gserver['next_contact']) < time())) {
Worker::add(Worker::PRIORITY_LOW, 'UpdateGServer', $server, false);
}
return $reachable;
}
/**

View file

@ -3030,6 +3030,7 @@ class Item
$shared = DI::contentItem()->getSharedPost($item, $fields);
if (!empty($shared['post'])) {
$shared_item = $shared['post'];
$shared_item['body'] = Post\Media::removeFromEndOfBody($shared_item['body']);
$quote_uri_id = $shared['post']['uri-id'];
$shared_links[] = strtolower($shared['post']['uri']);
$item['body'] = BBCode::removeSharedData($item['body']);