X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModule%2FNotifications%2FIntroductions.php;h=246bed54029d54f616e633de48d1ecc721a18aca;hb=f0743e4e128dfcb5d6305f4ed09e969573ba6b15;hp=45b7c266c647778b0c6ec96527774bfd0e3a684b;hpb=2c56d2f3360c08e312e5c167261af8e5d4b87af4;p=friendica.git diff --git a/src/Module/Notifications/Introductions.php b/src/Module/Notifications/Introductions.php index 45b7c266c6..246bed5402 100644 --- a/src/Module/Notifications/Introductions.php +++ b/src/Module/Notifications/Introductions.php @@ -1,6 +1,6 @@ notificationIntro = $notificationIntro; + $this->mode = $mode; + } + /** * @inheritDoc */ - public static function getNotifications() + public function getNotifications() { - $id = (int)DI::args()->get(2, 0); - $all = DI::args()->get(2) == 'all'; + $id = (int)$this->args->get(2, 0); + $all = $this->args->get(2) == 'all'; $notifications = [ 'ident' => 'introductions', - 'notifications' => DI::notificationIntro()->getList($all, self::$firstItemNum, self::ITEMS_PER_PAGE, $id), + 'notifications' => $this->notificationIntro->getList($all, $this->firstItemNum, self::ITEMS_PER_PAGE, $id), ]; return [ - 'header' => DI::l10n()->t('Notifications'), + 'header' => $this->t('Notifications'), 'notifications' => $notifications, ]; } - public static function content(array $parameters = []) + protected function content(array $request = []): string { Nav::setSelected('introductions'); - $all = DI::args()->get(2) == 'all'; + $all = $this->args->get(2) == 'all'; $notificationContent = []; $notificationNoContent = ''; - $notificationResult = self::getNotifications(); + $notificationResult = $this->getNotifications(); $notifications = $notificationResult['notifications'] ?? []; $notificationHeader = $notificationResult['header'] ?? ''; @@ -73,130 +96,127 @@ class Introductions extends BaseNotifications // The link to switch between ignored and normal connection requests $notificationShowLink = [ 'href' => (!$all ? 'notifications/intros/all' : 'notifications/intros'), - 'text' => (!$all ? DI::l10n()->t('Show Ignored Requests') : DI::l10n()->t('Hide Ignored Requests')), + 'text' => (!$all ? $this->t('Show Ignored Requests') : $this->t('Hide Ignored Requests')), ]; + $owner = User::getOwnerDataById(DI::userSession()->getLocalUserId()); + // Loop through all introduction notifications.This creates an array with the output html for each // introduction - /** @var Introduction $notification */ - foreach ($notifications['notifications'] as $notification) { + /** @var Introduction $Introduction */ + foreach ($notifications['notifications'] as $Introduction) { // There are two kind of introduction. Contacts suggested by other contacts and normal connection requests. // We have to distinguish between these two because they use different data. - switch ($notification->getLabel()) { + switch ($Introduction->getLabel()) { case 'friend_suggestion': $notificationContent[] = Renderer::replaceMacros($notificationSuggestions, [ - '$type' => $notification->getLabel(), - '$str_notification_type' => DI::l10n()->t('Notification type:'), - '$str_type' => $notification->getType(), - '$intro_id' => $notification->getIntroId(), - '$lbl_madeby' => DI::l10n()->t('Suggested by:'), - '$madeby' => $notification->getMadeBy(), - '$madeby_url' => $notification->getMadeByUrl(), - '$madeby_zrl' => $notification->getMadeByZrl(), - '$madeby_addr' => $notification->getMadeByAddr(), - '$contact_id' => $notification->getContactId(), - '$photo' => $notification->getPhoto(), - '$fullname' => $notification->getName(), - '$url' => $notification->getUrl(), - '$zrl' => $notification->getZrl(), - '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notification->getAddr(), - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''], - '$knowyou' => $notification->getKnowYou(), - '$approve' => DI::l10n()->t('Approve'), - '$note' => $notification->getNote(), - '$request' => $notification->getRequest(), - '$ignore' => DI::l10n()->t('Ignore'), - '$discard' => DI::l10n()->t('Discard'), + '$type' => $Introduction->getLabel(), + '$str_notification_type' => $this->t('Notification type:'), + '$str_type' => $Introduction->getType(), + '$intro_id' => $Introduction->getIntroId(), + '$lbl_madeby' => $this->t('Suggested by:'), + '$madeby' => $Introduction->getMadeBy(), + '$madeby_url' => $Introduction->getMadeByUrl(), + '$madeby_zrl' => $Introduction->getMadeByZrl(), + '$madeby_addr' => $Introduction->getMadeByAddr(), + '$contact_id' => $Introduction->getContactId(), + '$photo' => $Introduction->getPhoto(), + '$fullname' => $Introduction->getName(), + '$dfrn_url' => $owner['url'], + '$url' => $Introduction->getUrl(), + '$zrl' => $Introduction->getZrl(), + '$lbl_url' => $this->t('Profile URL'), + '$addr' => $Introduction->getAddr(), + '$action' => 'contact/follow', + '$approve' => $this->t('Approve'), + '$note' => $Introduction->getNote(), + '$ignore' => $this->t('Ignore'), + '$discard' => $this->t('Discard'), + '$is_mobile' => $this->mode->isMobile(), ]); break; // Normal connection requests default: - if ($notification->getNetwork() === Protocol::DFRN) { - $lbl_knowyou = DI::l10n()->t('Claims to be known to you: '); - $knowyou = ($notification->getKnowYou() ? DI::l10n()->t('Yes') : DI::l10n()->t('No')); + if ($Introduction->getNetwork() === Protocol::DFRN) { + $lbl_knowyou = $this->t('Claims to be known to you: '); + $knowyou = ($Introduction->getKnowYou() ? $this->t('Yes') : $this->t('No')); } else { $lbl_knowyou = ''; $knowyou = ''; } - $helptext = DI::l10n()->t('Shall your connection be bidirectional or not?'); - $helptext2 = DI::l10n()->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $notification->getName(), $notification->getName()); - $helptext3 = DI::l10n()->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $notification->getName()); + $convertedName = BBCode::convert($Introduction->getName()); - $friend = ['duplex', DI::l10n()->t('Friend'), '1', $helptext2, true]; - $follower = ['duplex', DI::l10n()->t('Subscriber'), '0', $helptext3, false]; + $helptext = $this->t('Shall your connection be bidirectional or not?'); + $helptext2 = $this->t('Accepting %s as a friend allows %s to subscribe to your posts, and you will also receive updates from them in your news feed.', $convertedName, $convertedName); + $helptext3 = $this->t('Accepting %s as a subscriber allows them to subscribe to your posts, but you will not receive updates from them in your news feed.', $convertedName); - $contact = DBA::selectFirst('contact', ['network', 'protocol'], ['id' => $notification->getContactId()]); + $friend = ['duplex', $this->t('Friend'), '1', $helptext2, true]; + $follower = ['duplex', $this->t('Subscriber'), '0', $helptext3, false]; - if (($contact['network'] != Protocol::DFRN) || ($contact['protocol'] == Protocol::ACTIVITYPUB)) { - $action = 'follow_confirm'; - } else { - $action = 'dfrn_confirm'; - } + $action = 'follow_confirm'; - $header = $notification->getName(); + $header = $Introduction->getName(); - if ($notification->getAddr() != '') { - $header .= ' <' . $notification->getAddr() . '>'; + if ($Introduction->getAddr() != '') { + $header .= ' <' . $Introduction->getAddr() . '>'; } - $header .= ' (' . ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()) . ')'; + $header .= ' (' . ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()) . ')'; - if ($notification->getNetwork() != Protocol::DIASPORA) { - $discard = DI::l10n()->t('Discard'); + if ($Introduction->getNetwork() != Protocol::DIASPORA) { + $discard = $this->t('Discard'); } else { $discard = ''; } $notificationContent[] = Renderer::replaceMacros($notificationTemplate, [ - '$type' => $notification->getLabel(), + '$type' => $Introduction->getLabel(), '$header' => $header, - '$str_notification_type' => DI::l10n()->t('Notification type:'), - '$str_type' => $notification->getType(), - '$dfrn_id' => $notification->getDfrnId(), - '$uid' => $notification->getUid(), - '$intro_id' => $notification->getIntroId(), - '$contact_id' => $notification->getContactId(), - '$photo' => $notification->getPhoto(), - '$fullname' => $notification->getName(), - '$location' => $notification->getLocation(), - '$lbl_location' => DI::l10n()->t('Location:'), - '$about' => $notification->getAbout(), - '$lbl_about' => DI::l10n()->t('About:'), - '$keywords' => $notification->getKeywords(), - '$lbl_keywords' => DI::l10n()->t('Tags:'), - '$gender' => $notification->getGender(), - '$lbl_gender' => DI::l10n()->t('Gender:'), - '$hidden' => ['hidden', DI::l10n()->t('Hide this contact from others'), $notification->isHidden(), ''], + '$str_notification_type' => $this->t('Notification type:'), + '$str_type' => $Introduction->getType(), + '$dfrn_id' => $Introduction->getDfrnId(), + '$uid' => $Introduction->getUid(), + '$intro_id' => $Introduction->getIntroId(), + '$contact_id' => $Introduction->getContactId(), + '$photo' => $Introduction->getPhoto(), + '$fullname' => $Introduction->getName(), + '$location' => $Introduction->getLocation(), + '$lbl_location' => $this->t('Location:'), + '$about' => $Introduction->getAbout(), + '$lbl_about' => $this->t('About:'), + '$keywords' => $Introduction->getKeywords(), + '$lbl_keywords' => $this->t('Tags:'), + '$hidden' => ['hidden', $this->t('Hide this contact from others'), $Introduction->isHidden(), ''], '$lbl_connection_type' => $helptext, '$friend' => $friend, '$follower' => $follower, - '$url' => $notification->getUrl(), - '$zrl' => $notification->getZrl(), - '$lbl_url' => DI::l10n()->t('Profile URL'), - '$addr' => $notification->getAddr(), + '$url' => $Introduction->getUrl(), + '$zrl' => $Introduction->getZrl(), + '$lbl_url' => $this->t('Profile URL'), + '$addr' => $Introduction->getAddr(), '$lbl_knowyou' => $lbl_knowyou, - '$lbl_network' => DI::l10n()->t('Network:'), - '$network' => ContactSelector::networkToName($notification->getNetwork(), $notification->getUrl()), + '$lbl_network' => $this->t('Network:'), + '$network' => ContactSelector::networkToName($Introduction->getNetwork(), $Introduction->getUrl()), '$knowyou' => $knowyou, - '$approve' => DI::l10n()->t('Approve'), - '$note' => $notification->getNote(), - '$ignore' => DI::l10n()->t('Ignore'), + '$approve' => $this->t('Approve'), + '$note' => $Introduction->getNote(), + '$ignore' => $this->t('Ignore'), '$discard' => $discard, '$action' => $action, + '$is_mobile' => $this->mode->isMobile(), ]); break; } } if (count($notifications['notifications']) == 0) { - info(DI::l10n()->t('No introductions.') . EOL); - $notificationNoContent = DI::l10n()->t('No more %s notifications.', $notifications['ident']); + DI::sysmsg()->addNotice($this->t('No introductions.')); + $notificationNoContent = $this->t('No more %s notifications.', $notifications['ident']); } - return self::printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); + return $this->printContent($notificationHeader, $notificationContent, $notificationNoContent, $notificationShowLink); } }