]> git.mxchange.org Git - friendica.git/blobdiff - src/Content/ContactSelector.php
Implement functions
[friendica.git] / src / Content / ContactSelector.php
index 797ec78610a01010a039473e886a41ca9cb4f1b0..298f2512edf349f5089556f9dfcc1dadc7e9c7ff 100644 (file)
@@ -6,8 +6,10 @@ 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\Database\DBM;
+use Friendica\Util\Network;
 
 /**
  * @brief ContactSelector class
@@ -27,9 +29,9 @@ class ContactSelector
                $o .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
 
                $s = DBA::select('profile', ['id', 'profile-name', 'is-default'], ['uid' => $_SESSION['uid']]);
-               $r = DBA::inArray($s);
+               $r = DBA::toArray($s);
 
-               if (DBM::is_result($r)) {
+               if (DBA::isResult($r)) {
                        foreach ($r as $rr) {
                                $selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : "");
                                $o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
@@ -68,30 +70,29 @@ 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 = [
-                       NETWORK_DFRN     => L10n::t('Friendica'),
-                       NETWORK_OSTATUS  => L10n::t('OStatus'),
-                       NETWORK_FEED     => L10n::t('RSS/Atom'),
-                       NETWORK_MAIL     => L10n::t('Email'),
-                       NETWORK_DIASPORA => L10n::t('Diaspora'),
-                       NETWORK_FACEBOOK => L10n::t('Facebook'),
-                       NETWORK_ZOT      => L10n::t('Zot!'),
-                       NETWORK_LINKEDIN => L10n::t('LinkedIn'),
-                       NETWORK_XMPP     => L10n::t('XMPP/IM'),
-                       NETWORK_MYSPACE  => L10n::t('MySpace'),
-                       NETWORK_GPLUS    => L10n::t('Google+'),
-                       NETWORK_PUMPIO   => L10n::t('pump.io'),
-                       NETWORK_TWITTER  => L10n::t('Twitter'),
-                       NETWORK_DIASPORA2 => L10n::t('Diaspora Connector'),
-                       NETWORK_STATUSNET => L10n::t('GNU Social Connector'),
-                       NETWORK_PNUT      => L10n::t('pnut'),
-                       NETWORK_APPNET => L10n::t('App.net')
+                       Protocol::DFRN      =>   L10n::t('Friendica'),
+                       Protocol::OSTATUS   =>   L10n::t('OStatus'),
+                       Protocol::FEED      =>   L10n::t('RSS/Atom'),
+                       Protocol::MAIL      =>   L10n::t('Email'),
+                       Protocol::DIASPORA  =>   L10n::t('Diaspora'),
+                       Protocol::ZOT       =>   L10n::t('Zot!'),
+                       Protocol::LINKEDIN  =>   L10n::t('LinkedIn'),
+                       Protocol::XMPP      =>   L10n::t('XMPP/IM'),
+                       Protocol::MYSPACE   =>   L10n::t('MySpace'),
+                       Protocol::GPLUS     =>   L10n::t('Google+'),
+                       Protocol::PUMPIO    =>   L10n::t('pump.io'),
+                       Protocol::TWITTER   =>   L10n::t('Twitter'),
+                       Protocol::DIASPORA2 =>   L10n::t('Diaspora Connector'),
+                       Protocol::STATUSNET =>   L10n::t('GNU Social Connector'),
+                       Protocol::ACTIVITYPUB => L10n::t('ActivityPub'),
+                       Protocol::PNUT      =>   L10n::t('pnut'),
                ];
 
                Addon::callHooks('network_to_name', $nets);
@@ -99,15 +100,37 @@ 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, [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) && ($profile != "")) {
-                       $r = DBA::fetch_first("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 (DBM::is_result($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 ($network == Protocol::ACTIVITYPUB) {
+                                               $networkname .= ' (AP)';
+                                       }
+                               }
                        }
                }