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
109 * @param string $profile optional, default empty
111 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
113 public static function networkToName($network, $profile = "")
116 Protocol::DFRN => L10n::t('DFRN'),
117 Protocol::OSTATUS => L10n::t('OStatus'),
118 Protocol::FEED => L10n::t('RSS/Atom'),
119 Protocol::MAIL => L10n::t('Email'),
120 Protocol::DIASPORA => L10n::t('Diaspora'),
121 Protocol::ZOT => L10n::t('Zot!'),
122 Protocol::LINKEDIN => L10n::t('LinkedIn'),
123 Protocol::XMPP => L10n::t('XMPP/IM'),
124 Protocol::MYSPACE => L10n::t('MySpace'),
125 Protocol::GPLUS => L10n::t('Google+'),
126 Protocol::PUMPIO => L10n::t('pump.io'),
127 Protocol::TWITTER => L10n::t('Twitter'),
128 Protocol::DISCOURSE => L10n::t('Discourse'),
129 Protocol::DIASPORA2 => L10n::t('Diaspora Connector'),
130 Protocol::STATUSNET => L10n::t('GNU Social Connector'),
131 Protocol::ACTIVITYPUB => L10n::t('ActivityPub'),
132 Protocol::PNUT => 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)';
169 * @param string $network network
170 * @param string $profile optional, default empty
172 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
174 public static function networkToIcon($network, $profile = "")
177 Protocol::DFRN => 'friendica',
178 Protocol::OSTATUS => 'gnu-social', // There is no generic OStatus icon
179 Protocol::FEED => 'rss',
180 Protocol::MAIL => 'file-text-o', /// @todo
181 Protocol::DIASPORA => 'diaspora',
182 Protocol::ZOT => 'hubzilla',
183 Protocol::LINKEDIN => 'linkedin',
184 Protocol::XMPP => 'xmpp',
185 Protocol::MYSPACE => 'file-text-o', /// @todo
186 Protocol::GPLUS => 'google-plus',
187 Protocol::PUMPIO => 'file-text-o', /// @todo
188 Protocol::TWITTER => 'twitter',
189 Protocol::DISCOURSE => 'dot-circle-o', /// @todo
190 Protocol::DIASPORA2 => 'diaspora',
191 Protocol::STATUSNET => 'gnu-social',
192 Protocol::ACTIVITYPUB => 'activitypub',
193 Protocol::PNUT => 'file-text-o', /// @todo
196 $platform_icons = ['diaspora' => 'diaspora', 'friendica' => 'friendica', 'friendika' => 'friendica',
197 'GNU Social' => 'gnu-social', 'gnusocial' => 'gnu-social', 'hubzilla' => 'hubzilla',
198 'mastodon' => 'mastodon', 'peertube' => 'peertube', 'pixelfed' => 'pixelfed',
199 'pleroma' => 'pleroma', 'red' => 'hubzilla', 'redmatrix' => 'hubzilla',
200 'socialhome' => 'social-home', 'wordpress' => 'wordpress'];
202 $search = array_keys($nets);
203 $replace = array_values($nets);
205 $network_icon = str_replace($search, $replace, $network);
207 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
208 $server_url = self::getServerURLForProfile($profile);
210 // Now query the GServer for the platform name
211 $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
213 if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
214 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
218 return $network_icon;
222 * @param string $current optional, default empty
223 * @param string $suffix optionsl, default empty
225 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
227 public static function gender($current = "", $suffix = "")
231 '' => L10n::t('No answer'),
232 'Male' => L10n::t('Male'),
233 'Female' => L10n::t('Female'),
234 'Currently Male' => L10n::t('Currently Male'),
235 'Currently Female' => L10n::t('Currently Female'),
236 'Mostly Male' => L10n::t('Mostly Male'),
237 'Mostly Female' => L10n::t('Mostly Female'),
238 'Transgender' => L10n::t('Transgender'),
239 'Intersex' => L10n::t('Intersex'),
240 'Transsexual' => L10n::t('Transsexual'),
241 'Hermaphrodite' => L10n::t('Hermaphrodite'),
242 'Neuter' => L10n::t('Neuter'),
243 'Non-specific' => L10n::t('Non-specific'),
244 'Other' => L10n::t('Other'),
245 'Undecided' => L10n::t('Undecided'),
248 Hook::callAll('gender_selector', $select);
250 $o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
251 foreach ($select as $neutral => $selection) {
252 if ($selection !== 'NOTRANSLATION') {
253 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
254 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
262 * @param string $current optional, default empty
263 * @param string $suffix optionsl, default empty
265 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
267 public static function sexualPreference($current = "", $suffix = "")
271 '' => L10n::t('No answer'),
272 'Males' => L10n::t('Males'),
273 'Females' => L10n::t('Females'),
274 'Gay' => L10n::t('Gay'),
275 'Lesbian' => L10n::t('Lesbian'),
276 'No Preference' => L10n::t('No Preference'),
277 'Bisexual' => L10n::t('Bisexual'),
278 'Autosexual' => L10n::t('Autosexual'),
279 'Abstinent' => L10n::t('Abstinent'),
280 'Virgin' => L10n::t('Virgin'),
281 'Deviant' => L10n::t('Deviant'),
282 'Fetish' => L10n::t('Fetish'),
283 'Oodles' => L10n::t('Oodles'),
284 'Nonsexual' => L10n::t('Nonsexual'),
287 Hook::callAll('sexpref_selector', $select);
289 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
290 foreach ($select as $neutral => $selection) {
291 if ($selection !== 'NOTRANSLATION') {
292 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
293 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
301 * @param string $current optional, default empty
303 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
305 public static function maritalStatus($current = "")
309 '' => L10n::t('No answer'),
310 'Single' => L10n::t('Single'),
311 'Lonely' => L10n::t('Lonely'),
312 'In a relation' => L10n::t('In a relation'),
313 'Has crush' => L10n::t('Has crush'),
314 'Infatuated' => L10n::t('Infatuated'),
315 'Dating' => L10n::t('Dating'),
316 'Unfaithful' => L10n::t('Unfaithful'),
317 'Sex Addict' => L10n::t('Sex Addict'),
318 'Friends' => L10n::t('Friends'),
319 'Friends/Benefits' => L10n::t('Friends/Benefits'),
320 'Casual' => L10n::t('Casual'),
321 'Engaged' => L10n::t('Engaged'),
322 'Married' => L10n::t('Married'),
323 'Imaginarily married' => L10n::t('Imaginarily married'),
324 'Partners' => L10n::t('Partners'),
325 'Cohabiting' => L10n::t('Cohabiting'),
326 'Common law' => L10n::t('Common law'),
327 'Happy' => L10n::t('Happy'),
328 'Not looking' => L10n::t('Not looking'),
329 'Swinger' => L10n::t('Swinger'),
330 'Betrayed' => L10n::t('Betrayed'),
331 'Separated' => L10n::t('Separated'),
332 'Unstable' => L10n::t('Unstable'),
333 'Divorced' => L10n::t('Divorced'),
334 'Imaginarily divorced' => L10n::t('Imaginarily divorced'),
335 'Widowed' => L10n::t('Widowed'),
336 'Uncertain' => L10n::t('Uncertain'),
337 'It\'s complicated' => L10n::t('It\'s complicated'),
338 'Don\'t care' => L10n::t('Don\'t care'),
339 'Ask me' => L10n::t('Ask me'),
342 Hook::callAll('marital_selector', $select);
344 $o .= '<select name="marital" id="marital-select" size="1" >';
345 foreach ($select as $neutral => $selection) {
346 if ($selection !== 'NOTRANSLATION') {
347 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
348 $o .= "<option value=\"$neutral\" $selected >$selection</option>";