3 * @file src/Content/ContactSelector.php
5 namespace Friendica\Content;
7 use Friendica\Core\Hook;
8 use Friendica\Core\Protocol;
9 use Friendica\Database\DBA;
11 use Friendica\Util\Network;
12 use Friendica\Util\Strings;
15 * ContactSelector class
20 * @param string $current current
21 * @param boolean $disabled optional, default false
24 public static function pollInterval($current, $disabled = false)
26 $dis = (($disabled) ? ' disabled="disabled" ' : '');
28 $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
31 0 => DI::l10n()->t('Frequently'),
32 1 => DI::l10n()->t('Hourly'),
33 2 => DI::l10n()->t('Twice daily'),
34 3 => DI::l10n()->t('Daily'),
35 4 => DI::l10n()->t('Weekly'),
36 5 => DI::l10n()->t('Monthly')
39 foreach ($rep as $k => $v) {
40 $selected = (($k == $current) ? " selected=\"selected\" " : "");
41 $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
43 $o .= "</select>\r\n";
48 * @param string $profile Profile URL
49 * @return string Server URL
52 private static function getServerURLForProfile($profile)
56 // Fetch the server url from the contact table
57 $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($profile)]);
58 if (DBA::isResult($contact) && !empty($contact['baseurl'])) {
59 $server_url = Strings::normaliseLink($contact['baseurl']);
62 if (empty($server_url)) {
63 // Fetch the server url from the gcontact table
64 $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]);
65 if (!empty($gcontact) && !empty($gcontact['server_url'])) {
66 $server_url = Strings::normaliseLink($gcontact['server_url']);
70 if (empty($server_url)) {
71 // Create the server url out of the profile url
72 $parts = parse_url($profile);
73 unset($parts['path']);
74 $server_url = Strings::normaliseLink(Network::unparseURL($parts));
81 * @param string $network network of the contact
82 * @param string $profile optional, default empty
83 * @param string $protocol (Optional) Protocol that is used for the transmission
85 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
87 public static function networkToName($network, $profile = '', $protocol = '')
90 Protocol::DFRN => DI::l10n()->t('DFRN'),
91 Protocol::OSTATUS => DI::l10n()->t('OStatus'),
92 Protocol::FEED => DI::l10n()->t('RSS/Atom'),
93 Protocol::MAIL => DI::l10n()->t('Email'),
94 Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
95 Protocol::ZOT => DI::l10n()->t('Zot!'),
96 Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
97 Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
98 Protocol::MYSPACE => DI::l10n()->t('MySpace'),
99 Protocol::GPLUS => DI::l10n()->t('Google+'),
100 Protocol::PUMPIO => DI::l10n()->t('pump.io'),
101 Protocol::TWITTER => DI::l10n()->t('Twitter'),
102 Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
103 Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
104 Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
105 Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
106 Protocol::PNUT => DI::l10n()->t('pnut'),
109 Hook::callAll('network_to_name', $nets);
111 $search = array_keys($nets);
112 $replace = array_values($nets);
114 $networkname = str_replace($search, $replace, $network);
116 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
117 $server_url = self::getServerURLForProfile($profile);
119 // Now query the GServer for the platform name
120 $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
122 if (DBA::isResult($gserver)) {
123 if (!empty($gserver['platform'])) {
124 $platform = $gserver['platform'];
125 } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
126 $platform = self::networkToName($gserver['network']);
129 if (!empty($platform)) {
130 $networkname = $platform;
132 if ($network == Protocol::ACTIVITYPUB) {
133 $networkname .= ' (AP)';
139 if (!empty($protocol) && ($protocol != $network)) {
140 $networkname = DI::l10n()->t('%s (via %s)', $networkname, self::networkToName($protocol));
147 * @param string $network network
148 * @param string $profile optional, default empty
152 public static function networkToIcon($network, $profile = "")
155 Protocol::DFRN => 'friendica',
156 Protocol::OSTATUS => 'gnu-social', // There is no generic OStatus icon
157 Protocol::FEED => 'rss',
158 Protocol::MAIL => 'inbox',
159 Protocol::DIASPORA => 'diaspora',
160 Protocol::ZOT => 'hubzilla',
161 Protocol::LINKEDIN => 'linkedin',
162 Protocol::XMPP => 'xmpp',
163 Protocol::MYSPACE => 'file-text-o', /// @todo
164 Protocol::GPLUS => 'google-plus',
165 Protocol::PUMPIO => 'file-text-o', /// @todo
166 Protocol::TWITTER => 'twitter',
167 Protocol::DISCOURSE => 'dot-circle-o', /// @todo
168 Protocol::DIASPORA2 => 'diaspora',
169 Protocol::STATUSNET => 'gnu-social',
170 Protocol::ACTIVITYPUB => 'activitypub',
171 Protocol::PNUT => 'file-text-o', /// @todo
174 $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
175 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
176 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
177 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
178 'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
180 $search = array_keys($nets);
181 $replace = array_values($nets);
183 $network_icon = str_replace($search, $replace, $network);
185 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
186 $server_url = self::getServerURLForProfile($profile);
188 // Now query the GServer for the platform name
189 $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
191 if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
192 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
196 return $network_icon;