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 string $foreign_net network
25 public static function profileAssign($current, $foreign_net)
29 $disabled = (($foreign_net) ? ' disabled="true" ' : '');
31 $o .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
33 $s = DBA::select('profile', ['id', 'profile-name', 'is-default'], ['uid' => $_SESSION['uid']]);
34 $r = DBA::toArray($s);
36 if (DBA::isResult($r)) {
38 $selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : "");
39 $o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
42 $o .= "</select>\r\n";
47 * @param string $current current
48 * @param boolean $disabled optional, default false
51 public static function pollInterval($current, $disabled = false)
53 $dis = (($disabled) ? ' disabled="disabled" ' : '');
55 $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
58 0 => DI::l10n()->t('Frequently'),
59 1 => DI::l10n()->t('Hourly'),
60 2 => DI::l10n()->t('Twice daily'),
61 3 => DI::l10n()->t('Daily'),
62 4 => DI::l10n()->t('Weekly'),
63 5 => DI::l10n()->t('Monthly')
66 foreach ($rep as $k => $v) {
67 $selected = (($k == $current) ? " selected=\"selected\" " : "");
68 $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
70 $o .= "</select>\r\n";
75 * @param string $profile Profile URL
76 * @return string Server URL
77 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
79 private static function getServerURLForProfile($profile)
83 // Fetch the server url from the contact table
84 $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($profile)]);
85 if (DBA::isResult($contact) && !empty($contact['baseurl'])) {
86 $server_url = Strings::normaliseLink($contact['baseurl']);
89 if (empty($server_url)) {
90 // Fetch the server url from the gcontact table
91 $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]);
92 if (!empty($gcontact) && !empty($gcontact['server_url'])) {
93 $server_url = Strings::normaliseLink($gcontact['server_url']);
97 if (empty($server_url)) {
98 // Create the server url out of the profile url
99 $parts = parse_url($profile);
100 unset($parts['path']);
101 $server_url = Strings::normaliseLink(Network::unparseURL($parts));
108 * @param string $network network of the contact
109 * @param string $profile optional, default empty
110 * @param string $protocol (Optional) Protocol that is used for the transmission
112 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
114 public static function networkToName($network, $profile = '', $protocol = '')
117 Protocol::DFRN => DI::l10n()->t('DFRN'),
118 Protocol::OSTATUS => DI::l10n()->t('OStatus'),
119 Protocol::FEED => DI::l10n()->t('RSS/Atom'),
120 Protocol::MAIL => DI::l10n()->t('Email'),
121 Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
122 Protocol::ZOT => DI::l10n()->t('Zot!'),
123 Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
124 Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
125 Protocol::MYSPACE => DI::l10n()->t('MySpace'),
126 Protocol::GPLUS => DI::l10n()->t('Google+'),
127 Protocol::PUMPIO => DI::l10n()->t('pump.io'),
128 Protocol::TWITTER => DI::l10n()->t('Twitter'),
129 Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
130 Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
131 Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
132 Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
133 Protocol::PNUT => DI::l10n()->t('pnut'),
136 Hook::callAll('network_to_name', $nets);
138 $search = array_keys($nets);
139 $replace = array_values($nets);
141 $networkname = str_replace($search, $replace, $network);
143 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
144 $server_url = self::getServerURLForProfile($profile);
146 // Now query the GServer for the platform name
147 $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
149 if (DBA::isResult($gserver)) {
150 if (!empty($gserver['platform'])) {
151 $platform = $gserver['platform'];
152 } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
153 $platform = self::networkToName($gserver['network']);
156 if (!empty($platform)) {
157 $networkname = $platform;
159 if ($network == Protocol::ACTIVITYPUB) {
160 $networkname .= ' (AP)';
166 if (!empty($protocol) && ($protocol != $network)) {
167 $networkname = DI::l10n()->t('%s (via %s)', $networkname, self::networkToName($protocol));
174 * @param string $network network
175 * @param string $profile optional, default empty
177 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
179 public static function networkToIcon($network, $profile = "")
182 Protocol::DFRN => 'friendica',
183 Protocol::OSTATUS => 'gnu-social', // There is no generic OStatus icon
184 Protocol::FEED => 'rss',
185 Protocol::MAIL => 'inbox',
186 Protocol::DIASPORA => 'diaspora',
187 Protocol::ZOT => 'hubzilla',
188 Protocol::LINKEDIN => 'linkedin',
189 Protocol::XMPP => 'xmpp',
190 Protocol::MYSPACE => 'file-text-o', /// @todo
191 Protocol::GPLUS => 'google-plus',
192 Protocol::PUMPIO => 'file-text-o', /// @todo
193 Protocol::TWITTER => 'twitter',
194 Protocol::DISCOURSE => 'dot-circle-o', /// @todo
195 Protocol::DIASPORA2 => 'diaspora',
196 Protocol::STATUSNET => 'gnu-social',
197 Protocol::ACTIVITYPUB => 'activitypub',
198 Protocol::PNUT => 'file-text-o', /// @todo
201 $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
202 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
203 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
204 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
205 'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
207 $search = array_keys($nets);
208 $replace = array_values($nets);
210 $network_icon = str_replace($search, $replace, $network);
212 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
213 $server_url = self::getServerURLForProfile($profile);
215 // Now query the GServer for the platform name
216 $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
218 if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
219 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
223 return $network_icon;
227 * @param string $current optional, default empty
228 * @param string $suffix optionsl, default empty
230 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
232 public static function gender($current = "", $suffix = "")
236 '' => DI::l10n()->t('No answer'),
237 'Male' => DI::l10n()->t('Male'),
238 'Female' => DI::l10n()->t('Female'),
239 'Currently Male' => DI::l10n()->t('Currently Male'),
240 'Currently Female' => DI::l10n()->t('Currently Female'),
241 'Mostly Male' => DI::l10n()->t('Mostly Male'),
242 'Mostly Female' => DI::l10n()->t('Mostly Female'),
243 'Transgender' => DI::l10n()->t('Transgender'),
244 'Intersex' => DI::l10n()->t('Intersex'),
245 'Transsexual' => DI::l10n()->t('Transsexual'),
246 'Hermaphrodite' => DI::l10n()->t('Hermaphrodite'),
247 'Neuter' => DI::l10n()->t('Neuter'),
248 'Non-specific' => DI::l10n()->t('Non-specific'),
249 'Other' => DI::l10n()->t('Other'),
250 'Undecided' => DI::l10n()->t('Undecided'),
253 Hook::callAll('gender_selector', $select);
255 $o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
256 foreach ($select as $neutral => $selection) {
257 if ($selection !== 'NOTRANSLATION') {
258 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
259 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
267 * @param string $current optional, default empty
268 * @param string $suffix optionsl, default empty
270 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
272 public static function sexualPreference($current = "", $suffix = "")
276 '' => DI::l10n()->t('No answer'),
277 'Males' => DI::l10n()->t('Males'),
278 'Females' => DI::l10n()->t('Females'),
279 'Gay' => DI::l10n()->t('Gay'),
280 'Lesbian' => DI::l10n()->t('Lesbian'),
281 'No Preference' => DI::l10n()->t('No Preference'),
282 'Bisexual' => DI::l10n()->t('Bisexual'),
283 'Autosexual' => DI::l10n()->t('Autosexual'),
284 'Abstinent' => DI::l10n()->t('Abstinent'),
285 'Virgin' => DI::l10n()->t('Virgin'),
286 'Deviant' => DI::l10n()->t('Deviant'),
287 'Fetish' => DI::l10n()->t('Fetish'),
288 'Oodles' => DI::l10n()->t('Oodles'),
289 'Nonsexual' => DI::l10n()->t('Nonsexual'),
292 Hook::callAll('sexpref_selector', $select);
294 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
295 foreach ($select as $neutral => $selection) {
296 if ($selection !== 'NOTRANSLATION') {
297 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
298 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
306 * @param string $current optional, default empty
308 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
310 public static function maritalStatus($current = "")
314 '' => DI::l10n()->t('No answer'),
315 'Single' => DI::l10n()->t('Single'),
316 'Lonely' => DI::l10n()->t('Lonely'),
317 'In a relation' => DI::l10n()->t('In a relation'),
318 'Has crush' => DI::l10n()->t('Has crush'),
319 'Infatuated' => DI::l10n()->t('Infatuated'),
320 'Dating' => DI::l10n()->t('Dating'),
321 'Unfaithful' => DI::l10n()->t('Unfaithful'),
322 'Sex Addict' => DI::l10n()->t('Sex Addict'),
323 'Friends' => DI::l10n()->t('Friends'),
324 'Friends/Benefits' => DI::l10n()->t('Friends/Benefits'),
325 'Casual' => DI::l10n()->t('Casual'),
326 'Engaged' => DI::l10n()->t('Engaged'),
327 'Married' => DI::l10n()->t('Married'),
328 'Imaginarily married' => DI::l10n()->t('Imaginarily married'),
329 'Partners' => DI::l10n()->t('Partners'),
330 'Cohabiting' => DI::l10n()->t('Cohabiting'),
331 'Common law' => DI::l10n()->t('Common law'),
332 'Happy' => DI::l10n()->t('Happy'),
333 'Not looking' => DI::l10n()->t('Not looking'),
334 'Swinger' => DI::l10n()->t('Swinger'),
335 'Betrayed' => DI::l10n()->t('Betrayed'),
336 'Separated' => DI::l10n()->t('Separated'),
337 'Unstable' => DI::l10n()->t('Unstable'),
338 'Divorced' => DI::l10n()->t('Divorced'),
339 'Imaginarily divorced' => DI::l10n()->t('Imaginarily divorced'),
340 'Widowed' => DI::l10n()->t('Widowed'),
341 'Uncertain' => DI::l10n()->t('Uncertain'),
342 'It\'s complicated' => DI::l10n()->t('It\'s complicated'),
343 'Don\'t care' => DI::l10n()->t('Don\'t care'),
344 'Ask me' => DI::l10n()->t('Ask me'),
347 Hook::callAll('marital_selector', $select);
349 $o .= '<select name="marital" id="marital-select" size="1" >';
350 foreach ($select as $neutral => $selection) {
351 if ($selection !== 'NOTRANSLATION') {
352 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
353 $o .= "<option value=\"$neutral\" $selected >$selection</option>";