]> git.mxchange.org Git - friendica.git/commitdiff
We now can show "Friendica (AP)" as network name
authorMichael <heluecht@pirati.ca>
Fri, 5 Oct 2018 19:26:20 +0000 (19:26 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 5 Oct 2018 19:26:20 +0000 (19:26 +0000)
include/conversation.php
src/Content/ContactSelector.php
src/Object/Post.php

index 1185e9dc3b372193db2529451ec1e76f28e93b4d..43854bb40f7b7e8d1486edb47d41e3a092fa7063 100644 (file)
@@ -657,7 +657,7 @@ function conversation(App $a, array $items, $mode, $update, $preview = false, $o
                                        'id' => ($preview ? 'P0' : $item['id']),
                                        'guid' => ($preview ? 'Q0' : $item['guid']),
                                        'network' => $item['network'],
-                                       'network_name' => ContactSelector::networkToName($item['network'], $profile_link),
+                                       'network_name' => ContactSelector::networkToName($item['network'], $item['author-link']),
                                        'linktitle' => L10n::t('View %s\'s profile @ %s', $profile_name, $item['author-link']),
                                        'profile_url' => $profile_link,
                                        'item_photo_menu' => item_photo_menu($item),
index 6a701f25f355d11b87db1afe07f5222cb3584236..298f2512edf349f5089556f9dfcc1dadc7e9c7ff 100644 (file)
@@ -7,7 +7,9 @@ namespace Friendica\Content;
 use Friendica\Core\Addon;
 use Friendica\Core\L10n;
 use Friendica\Core\Protocol;
+use Friendica\Core\System;
 use Friendica\Database\DBA;
+use Friendica\Util\Network;
 
 /**
  * @brief ContactSelector class
@@ -68,11 +70,11 @@ class ContactSelector
        }
 
        /**
-        * @param string $s       network
+        * @param string $network network
         * @param string $profile optional, default empty
         * @return string
         */
-       public static function networkToName($s, $profile = "")
+       public static function networkToName($network, $profile = "")
        {
                $nets = [
                        Protocol::DFRN      =>   L10n::t('Friendica'),
@@ -98,18 +100,36 @@ class ContactSelector
                $search  = array_keys($nets);
                $replace = array_values($nets);
 
-               $networkname = str_replace($search, $replace, $s);
+               $networkname = str_replace($search, $replace, $network);
 
-               if ((in_array($s, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) {
-                       $r = DBA::fetchFirst("SELECT `gserver`.`platform` FROM `gcontact`
-                                       INNER JOIN `gserver` ON `gserver`.`nurl` = `gcontact`.`server_url`
-                                       WHERE `gcontact`.`nurl` = ? AND `platform` != ''", normalise_link($profile));
+               if ((in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($profile != "")) {
+                       // Create the server url out of the profile url
+                       $parts = parse_url($profile);
+                       unset($parts['path']);
+                       $server_url = [normalise_link(Network::unparseURL($parts))];
 
-                       if (DBA::isResult($r)) {
-                               $networkname = $r['platform'];
+                       // Fetch the server url
+                       $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => normalise_link($profile)]);
+                       if (!empty($gcontact) && !empty($gcontact['server_url'])) {
+                               $server_url[] = normalise_link($gcontact['server_url']);
+                       }
+
+                       // Now query the GServer for the platform name
+                       $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
+
+                       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($platform)) {
+                                       $networkname = $platform;
 
-                               if ($s == Protocol::ACTIVITYPUB) {
-                                       $networkname .= ' (AP)';
+                                       if ($network == Protocol::ACTIVITYPUB) {
+                                               $networkname .= ' (AP)';
+                                       }
                                }
                        }
                }
index efd7d4dc8de3d1101da3f381b1f9895214ca0c8e..35805e1fddb5112c55cd3c1b7a314f957c3c5a2a 100644 (file)
@@ -402,7 +402,7 @@ class Post extends BaseObject
                        'thread_level'    => $thread_level,
                        'edited'          => $edited,
                        'network'         => $item["network"],
-                       'network_name'    => ContactSelector::networkToName($item['network'], $profile_link),
+                       'network_name'    => ContactSelector::networkToName($item['network'], $item['author-link']),
                        'received'        => $item['received'],
                        'commented'       => $item['commented'],
                        'created_date'    => $item['created'],