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 // Fetch the server url from the gcontact table
81 $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]);
82 if (!empty($gcontact) && !empty($gcontact['server_url'])) {
83 $server_url = Strings::normaliseLink($gcontact['server_url']);
87 if (empty($server_url)) {
88 // Create the server url out of the profile url
89 $parts = parse_url($profile);
90 unset($parts['path']);
91 $server_url = Strings::normaliseLink(Network::unparseURL($parts));
98 * @param string $network network of the contact
99 * @param string $profile optional, default empty
100 * @param string $protocol (Optional) Protocol that is used for the transmission
102 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
104 public static function networkToName($network, $profile = '', $protocol = '')
107 Protocol::DFRN => DI::l10n()->t('DFRN'),
108 Protocol::OSTATUS => DI::l10n()->t('OStatus'),
109 Protocol::FEED => DI::l10n()->t('RSS/Atom'),
110 Protocol::MAIL => DI::l10n()->t('Email'),
111 Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
112 Protocol::ZOT => DI::l10n()->t('Zot!'),
113 Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
114 Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
115 Protocol::MYSPACE => DI::l10n()->t('MySpace'),
116 Protocol::GPLUS => DI::l10n()->t('Google+'),
117 Protocol::PUMPIO => DI::l10n()->t('pump.io'),
118 Protocol::TWITTER => DI::l10n()->t('Twitter'),
119 Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
120 Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
121 Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
122 Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
123 Protocol::PNUT => DI::l10n()->t('pnut'),
126 Hook::callAll('network_to_name', $nets);
128 $search = array_keys($nets);
129 $replace = array_values($nets);
131 $networkname = str_replace($search, $replace, $network);
133 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
134 $server_url = self::getServerURLForProfile($profile);
136 // Now query the GServer for the platform name
137 $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
139 if (DBA::isResult($gserver)) {
140 if (!empty($gserver['platform'])) {
141 $platform = $gserver['platform'];
142 } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
143 $platform = self::networkToName($gserver['network']);
146 if (!empty($platform)) {
147 $networkname = $platform;
149 if ($network == Protocol::ACTIVITYPUB) {
150 $networkname .= ' (AP)';
156 if (!empty($protocol) && ($protocol != $network)) {
157 $networkname = DI::l10n()->t('%s (via %s)', $networkname, self::networkToName($protocol));
164 * @param string $network network
165 * @param string $profile optional, default empty
169 public static function networkToIcon($network, $profile = "")
172 Protocol::DFRN => 'friendica',
173 Protocol::OSTATUS => 'gnu-social', // There is no generic OStatus icon
174 Protocol::FEED => 'rss',
175 Protocol::MAIL => 'inbox',
176 Protocol::DIASPORA => 'diaspora',
177 Protocol::ZOT => 'hubzilla',
178 Protocol::LINKEDIN => 'linkedin',
179 Protocol::XMPP => 'xmpp',
180 Protocol::MYSPACE => 'file-text-o', /// @todo
181 Protocol::GPLUS => 'google-plus',
182 Protocol::PUMPIO => 'file-text-o', /// @todo
183 Protocol::TWITTER => 'twitter',
184 Protocol::DISCOURSE => 'dot-circle-o', /// @todo
185 Protocol::DIASPORA2 => 'diaspora',
186 Protocol::STATUSNET => 'gnu-social',
187 Protocol::ACTIVITYPUB => 'activitypub',
188 Protocol::PNUT => 'file-text-o', /// @todo
191 $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
192 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
193 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
194 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
195 'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
197 $search = array_keys($nets);
198 $replace = array_values($nets);
200 $network_icon = str_replace($search, $replace, $network);
202 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
203 $server_url = self::getServerURLForProfile($profile);
205 // Now query the GServer for the platform name
206 $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
208 if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
209 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
213 return $network_icon;