3 * @file src/Content/ContactSelector.php
5 namespace Friendica\Content;
7 use Friendica\Core\Hook;
8 use Friendica\Core\L10n;
9 use Friendica\Core\Protocol;
10 use Friendica\Database\DBA;
11 use Friendica\Util\Network;
12 use Friendica\Util\Strings;
15 * @brief 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 => L10n::t('Frequently'),
59 1 => L10n::t('Hourly'),
60 2 => L10n::t('Twice daily'),
61 3 => L10n::t('Daily'),
62 4 => L10n::t('Weekly'),
63 5 => 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 => L10n::t('DFRN'),
118 Protocol::OSTATUS => L10n::t('OStatus'),
119 Protocol::FEED => L10n::t('RSS/Atom'),
120 Protocol::MAIL => L10n::t('Email'),
121 Protocol::DIASPORA => L10n::t('Diaspora'),
122 Protocol::ZOT => L10n::t('Zot!'),
123 Protocol::LINKEDIN => L10n::t('LinkedIn'),
124 Protocol::XMPP => L10n::t('XMPP/IM'),
125 Protocol::MYSPACE => L10n::t('MySpace'),
126 Protocol::GPLUS => L10n::t('Google+'),
127 Protocol::PUMPIO => L10n::t('pump.io'),
128 Protocol::TWITTER => L10n::t('Twitter'),
129 Protocol::DISCOURSE => L10n::t('Discourse'),
130 Protocol::DIASPORA2 => L10n::t('Diaspora Connector'),
131 Protocol::STATUSNET => L10n::t('GNU Social Connector'),
132 Protocol::ACTIVITYPUB => L10n::t('ActivityPub'),
133 Protocol::PNUT => 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 = 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 => 'file-text-o', /// @todo
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 '' => L10n::t('No answer'),
237 'Male' => L10n::t('Male'),
238 'Female' => L10n::t('Female'),
239 'Currently Male' => L10n::t('Currently Male'),
240 'Currently Female' => L10n::t('Currently Female'),
241 'Mostly Male' => L10n::t('Mostly Male'),
242 'Mostly Female' => L10n::t('Mostly Female'),
243 'Transgender' => L10n::t('Transgender'),
244 'Intersex' => L10n::t('Intersex'),
245 'Transsexual' => L10n::t('Transsexual'),
246 'Hermaphrodite' => L10n::t('Hermaphrodite'),
247 'Neuter' => L10n::t('Neuter'),
248 'Non-specific' => L10n::t('Non-specific'),
249 'Other' => L10n::t('Other'),
250 'Undecided' => 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 '' => L10n::t('No answer'),
277 'Males' => L10n::t('Males'),
278 'Females' => L10n::t('Females'),
279 'Gay' => L10n::t('Gay'),
280 'Lesbian' => L10n::t('Lesbian'),
281 'No Preference' => L10n::t('No Preference'),
282 'Bisexual' => L10n::t('Bisexual'),
283 'Autosexual' => L10n::t('Autosexual'),
284 'Abstinent' => L10n::t('Abstinent'),
285 'Virgin' => L10n::t('Virgin'),
286 'Deviant' => L10n::t('Deviant'),
287 'Fetish' => L10n::t('Fetish'),
288 'Oodles' => L10n::t('Oodles'),
289 'Nonsexual' => 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 '' => L10n::t('No answer'),
315 'Single' => L10n::t('Single'),
316 'Lonely' => L10n::t('Lonely'),
317 'In a relation' => L10n::t('In a relation'),
318 'Has crush' => L10n::t('Has crush'),
319 'Infatuated' => L10n::t('Infatuated'),
320 'Dating' => L10n::t('Dating'),
321 'Unfaithful' => L10n::t('Unfaithful'),
322 'Sex Addict' => L10n::t('Sex Addict'),
323 'Friends' => L10n::t('Friends'),
324 'Friends/Benefits' => L10n::t('Friends/Benefits'),
325 'Casual' => L10n::t('Casual'),
326 'Engaged' => L10n::t('Engaged'),
327 'Married' => L10n::t('Married'),
328 'Imaginarily married' => L10n::t('Imaginarily married'),
329 'Partners' => L10n::t('Partners'),
330 'Cohabiting' => L10n::t('Cohabiting'),
331 'Common law' => L10n::t('Common law'),
332 'Happy' => L10n::t('Happy'),
333 'Not looking' => L10n::t('Not looking'),
334 'Swinger' => L10n::t('Swinger'),
335 'Betrayed' => L10n::t('Betrayed'),
336 'Separated' => L10n::t('Separated'),
337 'Unstable' => L10n::t('Unstable'),
338 'Divorced' => L10n::t('Divorced'),
339 'Imaginarily divorced' => L10n::t('Imaginarily divorced'),
340 'Widowed' => L10n::t('Widowed'),
341 'Uncertain' => L10n::t('Uncertain'),
342 'It\'s complicated' => L10n::t('It\'s complicated'),
343 'Don\'t care' => L10n::t('Don\'t care'),
344 'Ask me' => 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>";