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
50 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
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
150 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
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;
200 * @param string $current optional, default empty
201 * @param string $suffix optionsl, default empty
203 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
205 public static function sexualPreference($current = "", $suffix = "")
209 '' => DI::l10n()->t('No answer'),
210 'Males' => DI::l10n()->t('Males'),
211 'Females' => DI::l10n()->t('Females'),
212 'Gay' => DI::l10n()->t('Gay'),
213 'Lesbian' => DI::l10n()->t('Lesbian'),
214 'No Preference' => DI::l10n()->t('No Preference'),
215 'Bisexual' => DI::l10n()->t('Bisexual'),
216 'Autosexual' => DI::l10n()->t('Autosexual'),
217 'Abstinent' => DI::l10n()->t('Abstinent'),
218 'Virgin' => DI::l10n()->t('Virgin'),
219 'Deviant' => DI::l10n()->t('Deviant'),
220 'Fetish' => DI::l10n()->t('Fetish'),
221 'Oodles' => DI::l10n()->t('Oodles'),
222 'Nonsexual' => DI::l10n()->t('Nonsexual'),
225 Hook::callAll('sexpref_selector', $select);
227 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
228 foreach ($select as $neutral => $selection) {
229 if ($selection !== 'NOTRANSLATION') {
230 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
231 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
239 * @param string $current optional, default empty
241 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
243 public static function maritalStatus($current = "")
247 '' => DI::l10n()->t('No answer'),
248 'Single' => DI::l10n()->t('Single'),
249 'Lonely' => DI::l10n()->t('Lonely'),
250 'In a relation' => DI::l10n()->t('In a relation'),
251 'Has crush' => DI::l10n()->t('Has crush'),
252 'Infatuated' => DI::l10n()->t('Infatuated'),
253 'Dating' => DI::l10n()->t('Dating'),
254 'Unfaithful' => DI::l10n()->t('Unfaithful'),
255 'Sex Addict' => DI::l10n()->t('Sex Addict'),
256 'Friends' => DI::l10n()->t('Friends'),
257 'Friends/Benefits' => DI::l10n()->t('Friends/Benefits'),
258 'Casual' => DI::l10n()->t('Casual'),
259 'Engaged' => DI::l10n()->t('Engaged'),
260 'Married' => DI::l10n()->t('Married'),
261 'Imaginarily married' => DI::l10n()->t('Imaginarily married'),
262 'Partners' => DI::l10n()->t('Partners'),
263 'Cohabiting' => DI::l10n()->t('Cohabiting'),
264 'Common law' => DI::l10n()->t('Common law'),
265 'Happy' => DI::l10n()->t('Happy'),
266 'Not looking' => DI::l10n()->t('Not looking'),
267 'Swinger' => DI::l10n()->t('Swinger'),
268 'Betrayed' => DI::l10n()->t('Betrayed'),
269 'Separated' => DI::l10n()->t('Separated'),
270 'Unstable' => DI::l10n()->t('Unstable'),
271 'Divorced' => DI::l10n()->t('Divorced'),
272 'Imaginarily divorced' => DI::l10n()->t('Imaginarily divorced'),
273 'Widowed' => DI::l10n()->t('Widowed'),
274 'Uncertain' => DI::l10n()->t('Uncertain'),
275 'It\'s complicated' => DI::l10n()->t('It\'s complicated'),
276 'Don\'t care' => DI::l10n()->t('Don\'t care'),
277 'Ask me' => DI::l10n()->t('Ask me'),
280 Hook::callAll('marital_selector', $select);
282 $o .= '<select name="marital" id="marital-select" size="1" >';
283 foreach ($select as $neutral => $selection) {
284 if ($selection !== 'NOTRANSLATION') {
285 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
286 $o .= "<option value=\"$neutral\" $selected >$selection</option>";