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;
10 use Friendica\Util\Network;
11 use Friendica\Util\Strings;
14 * ContactSelector class
19 * @param string $current current
20 * @param string $foreign_net network
24 public static function profileAssign($current, $foreign_net)
28 $disabled = (($foreign_net) ? ' disabled="true" ' : '');
30 $o .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
32 $s = DBA::select('profile', ['id', 'profile-name', 'is-default'], ['uid' => $_SESSION['uid']]);
33 $r = DBA::toArray($s);
35 if (DBA::isResult($r)) {
37 $selected = (($rr['id'] == $current || ($current == 0 && $rr['is-default'] == 1)) ? " selected=\"selected\" " : "");
38 $o .= "<option value=\"{$rr['id']}\" $selected >{$rr['profile-name']}</option>\r\n";
41 $o .= "</select>\r\n";
46 * @param string $current current
47 * @param boolean $disabled optional, default false
50 public static function pollInterval($current, $disabled = false)
52 $dis = (($disabled) ? ' disabled="disabled" ' : '');
54 $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
57 0 => DI::l10n()->t('Frequently'),
58 1 => DI::l10n()->t('Hourly'),
59 2 => DI::l10n()->t('Twice daily'),
60 3 => DI::l10n()->t('Daily'),
61 4 => DI::l10n()->t('Weekly'),
62 5 => DI::l10n()->t('Monthly')
65 foreach ($rep as $k => $v) {
66 $selected = (($k == $current) ? " selected=\"selected\" " : "");
67 $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
69 $o .= "</select>\r\n";
74 * @param string $profile Profile URL
75 * @return string Server URL
76 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
78 private static function getServerURLForProfile($profile)
82 // Fetch the server url from the contact table
83 $contact = DBA::selectFirst('contact', ['baseurl'], ['uid' => 0, 'nurl' => Strings::normaliseLink($profile)]);
84 if (DBA::isResult($contact) && !empty($contact['baseurl'])) {
85 $server_url = Strings::normaliseLink($contact['baseurl']);
88 if (empty($server_url)) {
89 // Fetch the server url from the gcontact table
90 $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]);
91 if (!empty($gcontact) && !empty($gcontact['server_url'])) {
92 $server_url = Strings::normaliseLink($gcontact['server_url']);
96 if (empty($server_url)) {
97 // Create the server url out of the profile url
98 $parts = parse_url($profile);
99 unset($parts['path']);
100 $server_url = Strings::normaliseLink(Network::unparseURL($parts));
107 * @param string $network network of the contact
108 * @param string $profile optional, default empty
109 * @param string $protocol (Optional) Protocol that is used for the transmission
111 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
113 public static function networkToName($network, $profile = '', $protocol = '')
116 Protocol::DFRN => DI::l10n()->t('DFRN'),
117 Protocol::OSTATUS => DI::l10n()->t('OStatus'),
118 Protocol::FEED => DI::l10n()->t('RSS/Atom'),
119 Protocol::MAIL => DI::l10n()->t('Email'),
120 Protocol::DIASPORA => DI::l10n()->t('Diaspora'),
121 Protocol::ZOT => DI::l10n()->t('Zot!'),
122 Protocol::LINKEDIN => DI::l10n()->t('LinkedIn'),
123 Protocol::XMPP => DI::l10n()->t('XMPP/IM'),
124 Protocol::MYSPACE => DI::l10n()->t('MySpace'),
125 Protocol::GPLUS => DI::l10n()->t('Google+'),
126 Protocol::PUMPIO => DI::l10n()->t('pump.io'),
127 Protocol::TWITTER => DI::l10n()->t('Twitter'),
128 Protocol::DISCOURSE => DI::l10n()->t('Discourse'),
129 Protocol::DIASPORA2 => DI::l10n()->t('Diaspora Connector'),
130 Protocol::STATUSNET => DI::l10n()->t('GNU Social Connector'),
131 Protocol::ACTIVITYPUB => DI::l10n()->t('ActivityPub'),
132 Protocol::PNUT => DI::l10n()->t('pnut'),
135 Hook::callAll('network_to_name', $nets);
137 $search = array_keys($nets);
138 $replace = array_values($nets);
140 $networkname = str_replace($search, $replace, $network);
142 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
143 $server_url = self::getServerURLForProfile($profile);
145 // Now query the GServer for the platform name
146 $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
148 if (DBA::isResult($gserver)) {
149 if (!empty($gserver['platform'])) {
150 $platform = $gserver['platform'];
151 } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
152 $platform = self::networkToName($gserver['network']);
155 if (!empty($platform)) {
156 $networkname = $platform;
158 if ($network == Protocol::ACTIVITYPUB) {
159 $networkname .= ' (AP)';
165 if (!empty($protocol) && ($protocol != $network)) {
166 $networkname = DI::l10n()->t('%s (via %s)', $networkname, self::networkToName($protocol));
173 * @param string $network network
174 * @param string $profile optional, default empty
176 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
178 public static function networkToIcon($network, $profile = "")
181 Protocol::DFRN => 'friendica',
182 Protocol::OSTATUS => 'gnu-social', // There is no generic OStatus icon
183 Protocol::FEED => 'rss',
184 Protocol::MAIL => 'inbox',
185 Protocol::DIASPORA => 'diaspora',
186 Protocol::ZOT => 'hubzilla',
187 Protocol::LINKEDIN => 'linkedin',
188 Protocol::XMPP => 'xmpp',
189 Protocol::MYSPACE => 'file-text-o', /// @todo
190 Protocol::GPLUS => 'google-plus',
191 Protocol::PUMPIO => 'file-text-o', /// @todo
192 Protocol::TWITTER => 'twitter',
193 Protocol::DISCOURSE => 'dot-circle-o', /// @todo
194 Protocol::DIASPORA2 => 'diaspora',
195 Protocol::STATUSNET => 'gnu-social',
196 Protocol::ACTIVITYPUB => 'activitypub',
197 Protocol::PNUT => 'file-text-o', /// @todo
200 $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
201 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
202 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
203 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
204 'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
206 $search = array_keys($nets);
207 $replace = array_values($nets);
209 $network_icon = str_replace($search, $replace, $network);
211 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
212 $server_url = self::getServerURLForProfile($profile);
214 // Now query the GServer for the platform name
215 $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
217 if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
218 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
222 return $network_icon;
226 * @param string $current optional, default empty
227 * @param string $suffix optionsl, default empty
229 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
231 public static function gender($current = "", $suffix = "")
235 '' => DI::l10n()->t('No answer'),
236 'Male' => DI::l10n()->t('Male'),
237 'Female' => DI::l10n()->t('Female'),
238 'Currently Male' => DI::l10n()->t('Currently Male'),
239 'Currently Female' => DI::l10n()->t('Currently Female'),
240 'Mostly Male' => DI::l10n()->t('Mostly Male'),
241 'Mostly Female' => DI::l10n()->t('Mostly Female'),
242 'Transgender' => DI::l10n()->t('Transgender'),
243 'Intersex' => DI::l10n()->t('Intersex'),
244 'Transsexual' => DI::l10n()->t('Transsexual'),
245 'Hermaphrodite' => DI::l10n()->t('Hermaphrodite'),
246 'Neuter' => DI::l10n()->t('Neuter'),
247 'Non-specific' => DI::l10n()->t('Non-specific'),
248 'Other' => DI::l10n()->t('Other'),
249 'Undecided' => DI::l10n()->t('Undecided'),
252 Hook::callAll('gender_selector', $select);
254 $o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
255 foreach ($select as $neutral => $selection) {
256 if ($selection !== 'NOTRANSLATION') {
257 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
258 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
266 * @param string $current optional, default empty
267 * @param string $suffix optionsl, default empty
269 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
271 public static function sexualPreference($current = "", $suffix = "")
275 '' => DI::l10n()->t('No answer'),
276 'Males' => DI::l10n()->t('Males'),
277 'Females' => DI::l10n()->t('Females'),
278 'Gay' => DI::l10n()->t('Gay'),
279 'Lesbian' => DI::l10n()->t('Lesbian'),
280 'No Preference' => DI::l10n()->t('No Preference'),
281 'Bisexual' => DI::l10n()->t('Bisexual'),
282 'Autosexual' => DI::l10n()->t('Autosexual'),
283 'Abstinent' => DI::l10n()->t('Abstinent'),
284 'Virgin' => DI::l10n()->t('Virgin'),
285 'Deviant' => DI::l10n()->t('Deviant'),
286 'Fetish' => DI::l10n()->t('Fetish'),
287 'Oodles' => DI::l10n()->t('Oodles'),
288 'Nonsexual' => DI::l10n()->t('Nonsexual'),
291 Hook::callAll('sexpref_selector', $select);
293 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
294 foreach ($select as $neutral => $selection) {
295 if ($selection !== 'NOTRANSLATION') {
296 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
297 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
305 * @param string $current optional, default empty
307 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
309 public static function maritalStatus($current = "")
313 '' => DI::l10n()->t('No answer'),
314 'Single' => DI::l10n()->t('Single'),
315 'Lonely' => DI::l10n()->t('Lonely'),
316 'In a relation' => DI::l10n()->t('In a relation'),
317 'Has crush' => DI::l10n()->t('Has crush'),
318 'Infatuated' => DI::l10n()->t('Infatuated'),
319 'Dating' => DI::l10n()->t('Dating'),
320 'Unfaithful' => DI::l10n()->t('Unfaithful'),
321 'Sex Addict' => DI::l10n()->t('Sex Addict'),
322 'Friends' => DI::l10n()->t('Friends'),
323 'Friends/Benefits' => DI::l10n()->t('Friends/Benefits'),
324 'Casual' => DI::l10n()->t('Casual'),
325 'Engaged' => DI::l10n()->t('Engaged'),
326 'Married' => DI::l10n()->t('Married'),
327 'Imaginarily married' => DI::l10n()->t('Imaginarily married'),
328 'Partners' => DI::l10n()->t('Partners'),
329 'Cohabiting' => DI::l10n()->t('Cohabiting'),
330 'Common law' => DI::l10n()->t('Common law'),
331 'Happy' => DI::l10n()->t('Happy'),
332 'Not looking' => DI::l10n()->t('Not looking'),
333 'Swinger' => DI::l10n()->t('Swinger'),
334 'Betrayed' => DI::l10n()->t('Betrayed'),
335 'Separated' => DI::l10n()->t('Separated'),
336 'Unstable' => DI::l10n()->t('Unstable'),
337 'Divorced' => DI::l10n()->t('Divorced'),
338 'Imaginarily divorced' => DI::l10n()->t('Imaginarily divorced'),
339 'Widowed' => DI::l10n()->t('Widowed'),
340 'Uncertain' => DI::l10n()->t('Uncertain'),
341 'It\'s complicated' => DI::l10n()->t('It\'s complicated'),
342 'Don\'t care' => DI::l10n()->t('Don\'t care'),
343 'Ask me' => DI::l10n()->t('Ask me'),
346 Hook::callAll('marital_selector', $select);
348 $o .= '<select name="marital" id="marital-select" size="1" >';
349 foreach ($select as $neutral => $selection) {
350 if ($selection !== 'NOTRANSLATION') {
351 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
352 $o .= "<option value=\"$neutral\" $selected >$selection</option>";