]> git.mxchange.org Git - friendica.git/blob - src/Content/ContactSelector.php
Remove usage of profile.gender
[friendica.git] / src / Content / ContactSelector.php
1 <?php
2 /**
3  * @file src/Content/ContactSelector.php
4  */
5 namespace Friendica\Content;
6
7 use Friendica\Core\Hook;
8 use Friendica\Core\Protocol;
9 use Friendica\Database\DBA;
10 use Friendica\DI;
11 use Friendica\Util\Network;
12 use Friendica\Util\Strings;
13
14 /**
15  * ContactSelector class
16  */
17 class ContactSelector
18 {
19         /**
20          * @param string  $current  current
21          * @param boolean $disabled optional, default false
22          * @return object
23          */
24         public static function pollInterval($current, $disabled = false)
25         {
26                 $dis = (($disabled) ? ' disabled="disabled" ' : '');
27                 $o = '';
28                 $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
29
30                 $rep = [
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')
37                 ];
38
39                 foreach ($rep as $k => $v) {
40                         $selected = (($k == $current) ? " selected=\"selected\" " : "");
41                         $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
42                 }
43                 $o .= "</select>\r\n";
44                 return $o;
45         }
46
47         /**
48          * @param string $profile Profile URL
49          * @return string Server URL
50          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
51          */
52         private static function getServerURLForProfile($profile)
53         {
54                 $server_url = '';
55
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']);
60                 }
61
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']);
67                         }
68                 }
69
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));
75                 }
76
77                 return $server_url;
78         }
79
80         /**
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
84          * @return string
85          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
86          */
87         public static function networkToName($network, $profile = '', $protocol = '')
88         {
89                 $nets = [
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'),
107                 ];
108
109                 Hook::callAll('network_to_name', $nets);
110
111                 $search  = array_keys($nets);
112                 $replace = array_values($nets);
113
114                 $networkname = str_replace($search, $replace, $network);
115
116                 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
117                         $server_url = self::getServerURLForProfile($profile);
118
119                         // Now query the GServer for the platform name
120                         $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
121
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']);
127                                 }
128
129                                 if (!empty($platform)) {
130                                         $networkname = $platform;
131
132                                         if ($network == Protocol::ACTIVITYPUB) {
133                                                 $networkname .= ' (AP)';
134                                         }
135                                 }
136                         }
137                 }
138
139                 if (!empty($protocol) && ($protocol != $network)) {
140                         $networkname = DI::l10n()->t('%s (via %s)', $networkname, self::networkToName($protocol));
141                 }
142
143                 return $networkname;
144         }
145
146         /**
147          * @param string $network network
148          * @param string $profile optional, default empty
149          * @return string
150          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
151          */
152         public static function networkToIcon($network, $profile = "")
153         {
154                 $nets = [
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
172                 ];
173
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'];
179
180                 $search  = array_keys($nets);
181                 $replace = array_values($nets);
182
183                 $network_icon = str_replace($search, $replace, $network);
184
185                 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
186                         $server_url = self::getServerURLForProfile($profile);
187
188                         // Now query the GServer for the platform name
189                         $gserver = DBA::selectFirst('gserver', ['platform'], ['nurl' => $server_url]);
190
191                         if (DBA::isResult($gserver) && !empty($gserver['platform'])) {
192                                 $network_icon = $platform_icons[strtolower($gserver['platform'])] ?? $network_icon;
193                         }
194                 }
195
196                 return $network_icon;
197         }
198
199         /**
200          * @param string $current optional, default empty
201          * @param string $suffix  optionsl, default empty
202          * @return string
203          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
204          */
205         public static function sexualPreference($current = "", $suffix = "")
206         {
207                 $o = '';
208                 $select = [
209                         ''              => DI::l10n()->t('No answer'),
210                         'Males'         => DI::l10n()->t('Males'),
211                         'Females'       => DI::l10n()->t('Females'),
212                         'Gay'           => DI::l10n()->t('Gay'),
213                         'Lesbian'       => DI::l10n()->t('Lesbian'),
214                         'No Preference' => DI::l10n()->t('No Preference'),
215                         'Bisexual'      => DI::l10n()->t('Bisexual'),
216                         'Autosexual'    => DI::l10n()->t('Autosexual'),
217                         'Abstinent'     => DI::l10n()->t('Abstinent'),
218                         'Virgin'        => DI::l10n()->t('Virgin'),
219                         'Deviant'       => DI::l10n()->t('Deviant'),
220                         'Fetish'        => DI::l10n()->t('Fetish'),
221                         'Oodles'        => DI::l10n()->t('Oodles'),
222                         'Nonsexual'     => DI::l10n()->t('Nonsexual'),
223                 ];
224
225                 Hook::callAll('sexpref_selector', $select);
226
227                 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
228                 foreach ($select as $neutral => $selection) {
229                         if ($selection !== 'NOTRANSLATION') {
230                                 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
231                                 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
232                         }
233                 }
234                 $o .= '</select>';
235                 return $o;
236         }
237
238         /**
239          * @param string $current optional, default empty
240          * @return string
241          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
242          */
243         public static function maritalStatus($current = "")
244         {
245                 $o = '';
246                 $select = [
247                         ''                     => DI::l10n()->t('No answer'),
248                         'Single'               => DI::l10n()->t('Single'),
249                         'Lonely'               => DI::l10n()->t('Lonely'),
250                         'In a relation'        => DI::l10n()->t('In a relation'),
251                         'Has crush'            => DI::l10n()->t('Has crush'),
252                         'Infatuated'           => DI::l10n()->t('Infatuated'),
253                         'Dating'               => DI::l10n()->t('Dating'),
254                         'Unfaithful'           => DI::l10n()->t('Unfaithful'),
255                         'Sex Addict'           => DI::l10n()->t('Sex Addict'),
256                         'Friends'              => DI::l10n()->t('Friends'),
257                         'Friends/Benefits'     => DI::l10n()->t('Friends/Benefits'),
258                         'Casual'               => DI::l10n()->t('Casual'),
259                         'Engaged'              => DI::l10n()->t('Engaged'),
260                         'Married'              => DI::l10n()->t('Married'),
261                         'Imaginarily married'  => DI::l10n()->t('Imaginarily married'),
262                         'Partners'             => DI::l10n()->t('Partners'),
263                         'Cohabiting'           => DI::l10n()->t('Cohabiting'),
264                         'Common law'           => DI::l10n()->t('Common law'),
265                         'Happy'                => DI::l10n()->t('Happy'),
266                         'Not looking'          => DI::l10n()->t('Not looking'),
267                         'Swinger'              => DI::l10n()->t('Swinger'),
268                         'Betrayed'             => DI::l10n()->t('Betrayed'),
269                         'Separated'            => DI::l10n()->t('Separated'),
270                         'Unstable'             => DI::l10n()->t('Unstable'),
271                         'Divorced'             => DI::l10n()->t('Divorced'),
272                         'Imaginarily divorced' => DI::l10n()->t('Imaginarily divorced'),
273                         'Widowed'              => DI::l10n()->t('Widowed'),
274                         'Uncertain'            => DI::l10n()->t('Uncertain'),
275                         'It\'s complicated'    => DI::l10n()->t('It\'s complicated'),
276                         'Don\'t care'          => DI::l10n()->t('Don\'t care'),
277                         'Ask me'               => DI::l10n()->t('Ask me'),
278                 ];
279
280                 Hook::callAll('marital_selector', $select);
281
282                 $o .= '<select name="marital" id="marital-select" size="1" >';
283                 foreach ($select as $neutral => $selection) {
284                         if ($selection !== 'NOTRANSLATION') {
285                                 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
286                                 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
287                         }
288                 }
289                 $o .= '</select>';
290                 return $o;
291         }
292 }