X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FContent%2FContactSelector.php;h=56d6961be54fe9c921ab86474c15042f1442966b;hb=5cf71baf551bf209e62cf13b16173bddcd76a0fc;hp=c834f8c514c4ccfcec0e63161a3596ca2178ca68;hpb=0e05ff68686270d87447c570e28543a5bcc7e755;p=friendica.git diff --git a/src/Content/ContactSelector.php b/src/Content/ContactSelector.php index c834f8c514..56d6961be5 100644 --- a/src/Content/ContactSelector.php +++ b/src/Content/ContactSelector.php @@ -1,6 +1,6 @@ $server_url]); + + self::$serverdata[$server_url] = $gserver; + return $gserver; + } + /** * @param string $profile Profile URL * @return string Server URL * @throws \Exception */ - private static function getServerURLForProfile($profile) + private static function getServerURLForProfile(string $profile): string { + if (!empty(self::$server_url[$profile])) { + return self::$server_url[$profile]; + } + $server_url = ''; // Fetch the server url from the contact table @@ -76,14 +98,6 @@ class ContactSelector $server_url = Strings::normaliseLink($contact['baseurl']); } - if (empty($server_url)) { - // Fetch the server url from the gcontact table - $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]); - if (!empty($gcontact) && !empty($gcontact['server_url'])) { - $server_url = Strings::normaliseLink($gcontact['server_url']); - } - } - if (empty($server_url)) { // Create the server url out of the profile url $parts = parse_url($profile); @@ -91,17 +105,22 @@ class ContactSelector $server_url = Strings::normaliseLink(Network::unparseURL($parts)); } + self::$server_url[$profile] = $server_url; + return $server_url; } /** + * Determines network name + * * @param string $network network of the contact * @param string $profile optional, default empty * @param string $protocol (Optional) Protocol that is used for the transmission + * @param int $gsid Server id * @return string * @throws \Friendica\Network\HTTPException\InternalServerErrorException */ - public static function networkToName($network, $profile = '', $protocol = '') + public static function networkToName(string $network, string $profile = '', string $protocol = '', int $gsid = null): string { $nets = [ Protocol::DFRN => DI::l10n()->t('DFRN'), @@ -121,6 +140,8 @@ class ContactSelector Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'), Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'), Protocol::PNUT => DI::l10n()->t('pnut'), + Protocol::TUMBLR => DI::l10n()->t('Tumblr'), + Protocol::BLUESKY => DI::l10n()->t('Bluesky'), ]; Hook::callAll('network_to_name', $nets); @@ -131,24 +152,26 @@ class ContactSelector $networkname = str_replace($search, $replace, $network); if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) { - $server_url = self::getServerURLForProfile($profile); - - // Now query the GServer for the platform name - $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]); + if (!empty($gsid) && !empty(self::$serverdata[$gsid])) { + $gserver = self::$serverdata[$gsid]; + } elseif (!empty($gsid)) { + $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['id' => $gsid]); + self::$serverdata[$gsid] = $gserver; + } else { + $gserver = self::getServerForProfile($profile); + } - if (DBA::isResult($gserver)) { - if (!empty($gserver['platform'])) { - $platform = $gserver['platform']; - } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) { - $platform = self::networkToName($gserver['network']); - } + if (!empty($gserver['platform'])) { + $platform = $gserver['platform']; + } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) { + $platform = self::networkToName($gserver['network']); + } - if (!empty($platform)) { - $networkname = $platform; + if (!empty($platform)) { + $networkname = $platform; - if ($network == Protocol::ACTIVITYPUB) { - $networkname .= ' (AP)'; - } + if ($network == Protocol::ACTIVITYPUB) { + $networkname .= ' (AP)'; } } } @@ -161,12 +184,15 @@ class ContactSelector } /** + * Determines network's icon name + * * @param string $network network * @param string $profile optional, default empty - * @return string + * @param int $gsid Server id + * @return string Name for network icon * @throws \Exception */ - public static function networkToIcon($network, $profile = "") + public static function networkToIcon(string $network, string $profile = "", int $gsid = null): string { $nets = [ Protocol::DFRN => 'friendica', @@ -186,13 +212,17 @@ class ContactSelector Protocol::STATUSNET => 'gnu-social', Protocol::ACTIVITYPUB => 'activitypub', Protocol::PNUT => 'file-text-o', /// @todo + Protocol::TUMBLR => 'tumblr', + Protocol::BLUESKY => 'circle', /// @todo ]; $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica', 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla', 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed', 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla', - 'socialhome' => 'social-home', 'wordpress' => 'wordpress']; + 'socialhome' => 'social-home', 'wordpress' => 'wordpress', 'lemmy' => 'users', + 'plume' => 'plume', 'funkwhale' => 'funkwhale', 'nextcloud' => 'nextcloud', 'drupal' => 'drupal', + 'firefish' => 'fire', 'calckey' => 'calculator', 'kbin' => 'check']; $search = array_keys($nets); $replace = array_values($nets); @@ -200,12 +230,15 @@ class ContactSelector $network_icon = str_replace($search, $replace, $network); if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) { - $server_url = self::getServerURLForProfile($profile); - - // Now query the GServer for the platform name - $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]); - - if (DBA::isResult($gserver) && !empty($gserver['platform'])) { + if (!empty($gsid) && !empty(self::$serverdata[$gsid])) { + $gserver = self::$serverdata[$gsid]; + } elseif (!empty($gsid)) { + $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['id' => $gsid]); + self::$serverdata[$gsid] = $gserver; + } else { + $gserver = self::getServerForProfile($profile); + } + if (!empty($gserver['platform'])) { $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon; } }