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 gender($current = "", $suffix = "")
209 '' => DI::l10n()->t('No answer'),
210 'Male' => DI::l10n()->t('Male'),
211 'Female' => DI::l10n()->t('Female'),
212 'Currently Male' => DI::l10n()->t('Currently Male'),
213 'Currently Female' => DI::l10n()->t('Currently Female'),
214 'Mostly Male' => DI::l10n()->t('Mostly Male'),
215 'Mostly Female' => DI::l10n()->t('Mostly Female'),
216 'Transgender' => DI::l10n()->t('Transgender'),
217 'Intersex' => DI::l10n()->t('Intersex'),
218 'Transsexual' => DI::l10n()->t('Transsexual'),
219 'Hermaphrodite' => DI::l10n()->t('Hermaphrodite'),
220 'Neuter' => DI::l10n()->t('Neuter'),
221 'Non-specific' => DI::l10n()->t('Non-specific'),
222 'Other' => DI::l10n()->t('Other'),
223 'Undecided' => DI::l10n()->t('Undecided'),
226 Hook::callAll('gender_selector', $select);
228 $o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
229 foreach ($select as $neutral => $selection) {
230 if ($selection !== 'NOTRANSLATION') {
231 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
232 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
240 * @param string $current optional, default empty
241 * @param string $suffix optionsl, default empty
243 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
245 public static function sexualPreference($current = "", $suffix = "")
249 '' => DI::l10n()->t('No answer'),
250 'Males' => DI::l10n()->t('Males'),
251 'Females' => DI::l10n()->t('Females'),
252 'Gay' => DI::l10n()->t('Gay'),
253 'Lesbian' => DI::l10n()->t('Lesbian'),
254 'No Preference' => DI::l10n()->t('No Preference'),
255 'Bisexual' => DI::l10n()->t('Bisexual'),
256 'Autosexual' => DI::l10n()->t('Autosexual'),
257 'Abstinent' => DI::l10n()->t('Abstinent'),
258 'Virgin' => DI::l10n()->t('Virgin'),
259 'Deviant' => DI::l10n()->t('Deviant'),
260 'Fetish' => DI::l10n()->t('Fetish'),
261 'Oodles' => DI::l10n()->t('Oodles'),
262 'Nonsexual' => DI::l10n()->t('Nonsexual'),
265 Hook::callAll('sexpref_selector', $select);
267 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
268 foreach ($select as $neutral => $selection) {
269 if ($selection !== 'NOTRANSLATION') {
270 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
271 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
279 * @param string $current optional, default empty
281 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
283 public static function maritalStatus($current = "")
287 '' => DI::l10n()->t('No answer'),
288 'Single' => DI::l10n()->t('Single'),
289 'Lonely' => DI::l10n()->t('Lonely'),
290 'In a relation' => DI::l10n()->t('In a relation'),
291 'Has crush' => DI::l10n()->t('Has crush'),
292 'Infatuated' => DI::l10n()->t('Infatuated'),
293 'Dating' => DI::l10n()->t('Dating'),
294 'Unfaithful' => DI::l10n()->t('Unfaithful'),
295 'Sex Addict' => DI::l10n()->t('Sex Addict'),
296 'Friends' => DI::l10n()->t('Friends'),
297 'Friends/Benefits' => DI::l10n()->t('Friends/Benefits'),
298 'Casual' => DI::l10n()->t('Casual'),
299 'Engaged' => DI::l10n()->t('Engaged'),
300 'Married' => DI::l10n()->t('Married'),
301 'Imaginarily married' => DI::l10n()->t('Imaginarily married'),
302 'Partners' => DI::l10n()->t('Partners'),
303 'Cohabiting' => DI::l10n()->t('Cohabiting'),
304 'Common law' => DI::l10n()->t('Common law'),
305 'Happy' => DI::l10n()->t('Happy'),
306 'Not looking' => DI::l10n()->t('Not looking'),
307 'Swinger' => DI::l10n()->t('Swinger'),
308 'Betrayed' => DI::l10n()->t('Betrayed'),
309 'Separated' => DI::l10n()->t('Separated'),
310 'Unstable' => DI::l10n()->t('Unstable'),
311 'Divorced' => DI::l10n()->t('Divorced'),
312 'Imaginarily divorced' => DI::l10n()->t('Imaginarily divorced'),
313 'Widowed' => DI::l10n()->t('Widowed'),
314 'Uncertain' => DI::l10n()->t('Uncertain'),
315 'It\'s complicated' => DI::l10n()->t('It\'s complicated'),
316 'Don\'t care' => DI::l10n()->t('Don\'t care'),
317 'Ask me' => DI::l10n()->t('Ask me'),
320 Hook::callAll('marital_selector', $select);
322 $o .= '<select name="marital" id="marital-select" size="1" >';
323 foreach ($select as $neutral => $selection) {
324 if ($selection !== 'NOTRANSLATION') {
325 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
326 $o .= "<option value=\"$neutral\" $selected >$selection</option>";