3 * @copyright Copyright (C) 2020, Friendica
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Content;
24 use Friendica\Core\Hook;
25 use Friendica\Core\Protocol;
26 use Friendica\Database\DBA;
28 use Friendica\Util\Network;
29 use Friendica\Util\Strings;
32 * ContactSelector class
37 * @param string $current current
38 * @param boolean $disabled optional, default false
41 public static function pollInterval($current, $disabled = false)
43 $dis = (($disabled) ? ' disabled="disabled" ' : '');
45 $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
48 0 => DI::l10n()->t('Frequently'),
49 1 => DI::l10n()->t('Hourly'),
50 2 => DI::l10n()->t('Twice daily'),
51 3 => DI::l10n()->t('Daily'),
52 4 => DI::l10n()->t('Weekly'),
53 5 => DI::l10n()->t('Monthly')
56 foreach ($rep as $k => $v) {
57 $selected = (($k == $current) ? " selected=\"selected\" " : "");
58 $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
60 $o .= "</select>\r\n";
65 * @param string $profile Profile URL
66 * @return string Server URL
69 private static function getServerURLForProfile($profile)
73 // Fetch the server url from the contact table
74 $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($profile)]);
75 if (DBA::isResult($contact) && !empty($contact['baseurl'])) {
76 $server_url = Strings::normaliseLink($contact['baseurl']);
79 if (empty($server_url)) {
80 // Create the server url out of the profile url
81 $parts = parse_url($profile);
82 unset($parts['path']);
83 $server_url = Strings::normaliseLink(Network::unparseURL($parts));
90 * @param string $network network of the contact
91 * @param string $profile optional, default empty
92 * @param string $protocol (Optional) Protocol that is used for the transmission
94 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
96 public static function networkToName($network, $profile = '', $protocol = '')
99 Protocol::DFRN => DI::l10n()->t('DFRN'),
100 Protocol::OSTATUS => DI::l10n()->t('OStatus'),
101 Protocol::FEED => DI::l10n()->t('RSS/Atom'),
102 Protocol::MAIL => DI::l10n()->t('Email'),
103 Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
104 Protocol::ZOT => DI::l10n()->t('Zot!'),
105 Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
106 Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
107 Protocol::MYSPACE => DI::l10n()->t('MySpace'),
108 Protocol::GPLUS => DI::l10n()->t('Google+'),
109 Protocol::PUMPIO => DI::l10n()->t('pump.io'),
110 Protocol::TWITTER => DI::l10n()->t('Twitter'),
111 Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
112 Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
113 Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
114 Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
115 Protocol::PNUT => DI::l10n()->t('pnut'),
118 Hook::callAll('network_to_name', $nets);
120 $search = array_keys($nets);
121 $replace = array_values($nets);
123 $networkname = str_replace($search, $replace, $network);
125 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
126 $server_url = self::getServerURLForProfile($profile);
128 // Now query the GServer for the platform name
129 $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
131 if (DBA::isResult($gserver)) {
132 if (!empty($gserver['platform'])) {
133 $platform = $gserver['platform'];
134 } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
135 $platform = self::networkToName($gserver['network']);
138 if (!empty($platform)) {
139 $networkname = $platform;
141 if ($network == Protocol::ACTIVITYPUB) {
142 $networkname .= ' (AP)';
148 if (!empty($protocol) && ($protocol != $network)) {
149 $networkname = DI::l10n()->t('%s (via %s)', $networkname, self::networkToName($protocol));
156 * @param string $network network
157 * @param string $profile optional, default empty
161 public static function networkToIcon($network, $profile = "")
164 Protocol::DFRN => 'friendica',
165 Protocol::OSTATUS => 'gnu-social', // There is no generic OStatus icon
166 Protocol::FEED => 'rss',
167 Protocol::MAIL => 'inbox',
168 Protocol::DIASPORA => 'diaspora',
169 Protocol::ZOT => 'hubzilla',
170 Protocol::LINKEDIN => 'linkedin',
171 Protocol::XMPP => 'xmpp',
172 Protocol::MYSPACE => 'file-text-o', /// @todo
173 Protocol::GPLUS => 'google-plus',
174 Protocol::PUMPIO => 'file-text-o', /// @todo
175 Protocol::TWITTER => 'twitter',
176 Protocol::DISCOURSE => 'dot-circle-o', /// @todo
177 Protocol::DIASPORA2 => 'diaspora',
178 Protocol::STATUSNET => 'gnu-social',
179 Protocol::ACTIVITYPUB => 'activitypub',
180 Protocol::PNUT => 'file-text-o', /// @todo
183 $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
184 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
185 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
186 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
187 'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
189 $search = array_keys($nets);
190 $replace = array_values($nets);
192 $network_icon = str_replace($search, $replace, $network);
194 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
195 $server_url = self::getServerURLForProfile($profile);
197 // Now query the GServer for the platform name
198 $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
200 if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
201 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
205 return $network_icon;