]> git.mxchange.org Git - friendica.git/blob - src/Content/ContactSelector.php
2b86a6e75df663291b5f6bbd1fdaa7fac437928f
[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\L10n;
9 use Friendica\Core\Protocol;
10 use Friendica\Database\DBA;
11 use Friendica\Util\Network;
12 use Friendica\Util\Strings;
13
14 /**
15  * @brief ContactSelector class
16  */
17 class ContactSelector
18 {
19         /**
20          * @param string $current     current
21          * @param string $foreign_net network
22          * @return string
23          * @throws \Exception
24          */
25         public static function profileAssign($current, $foreign_net)
26         {
27                 $o = '';
28
29                 $disabled = (($foreign_net) ? ' disabled="true" ' : '');
30
31                 $o .= "<select id=\"contact-profile-selector\" class=\"form-control\" $disabled name=\"profile-assign\" >\r\n";
32
33                 $s = DBA::select('profile', ['id', 'profile-name', 'is-default'], ['uid' => $_SESSION['uid']]);
34                 $r = DBA::toArray($s);
35
36                 if (DBA::isResult($r)) {
37                         foreach ($r as $rr) {
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";
40                         }
41                 }
42                 $o .= "</select>\r\n";
43                 return $o;
44         }
45
46         /**
47          * @param string  $current  current
48          * @param boolean $disabled optional, default false
49          * @return object
50          */
51         public static function pollInterval($current, $disabled = false)
52         {
53                 $dis = (($disabled) ? ' disabled="disabled" ' : '');
54                 $o = '';
55                 $o .= "<select id=\"contact-poll-interval\" name=\"poll\" $dis />" . "\r\n";
56
57                 $rep = [
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')
64                 ];
65
66                 foreach ($rep as $k => $v) {
67                         $selected = (($k == $current) ? " selected=\"selected\" " : "");
68                         $o .= "<option value=\"$k\" $selected >$v</option>\r\n";
69                 }
70                 $o .= "</select>\r\n";
71                 return $o;
72         }
73
74         /**
75          * @param string $network network
76          * @param string $profile optional, default empty
77          * @return string
78          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
79          */
80         public static function networkToName($network, $profile = "")
81         {
82                 $nets = [
83                         Protocol::DFRN      =>   L10n::t('DFRN'),
84                         Protocol::OSTATUS   =>   L10n::t('OStatus'),
85                         Protocol::FEED      =>   L10n::t('RSS/Atom'),
86                         Protocol::MAIL      =>   L10n::t('Email'),
87                         Protocol::DIASPORA  =>   L10n::t('Diaspora'),
88                         Protocol::ZOT       =>   L10n::t('Zot!'),
89                         Protocol::LINKEDIN  =>   L10n::t('LinkedIn'),
90                         Protocol::XMPP      =>   L10n::t('XMPP/IM'),
91                         Protocol::MYSPACE   =>   L10n::t('MySpace'),
92                         Protocol::GPLUS     =>   L10n::t('Google+'),
93                         Protocol::PUMPIO    =>   L10n::t('pump.io'),
94                         Protocol::TWITTER   =>   L10n::t('Twitter'),
95                         Protocol::DIASPORA2 =>   L10n::t('Diaspora Connector'),
96                         Protocol::STATUSNET =>   L10n::t('GNU Social Connector'),
97                         Protocol::ACTIVITYPUB => L10n::t('ActivityPub'),
98                         Protocol::PNUT      =>   L10n::t('pnut'),
99                 ];
100
101                 Hook::callAll('network_to_name', $nets);
102
103                 $search  = array_keys($nets);
104                 $replace = array_values($nets);
105
106                 $networkname = str_replace($search, $replace, $network);
107
108                 if ((in_array($network, Protocol::FEDERATED)) && ($profile != "")) {
109                         // Create the server url out of the profile url
110                         $parts = parse_url($profile);
111                         unset($parts['path']);
112                         $server_url = [Strings::normaliseLink(Network::unparseURL($parts))];
113
114                         // Fetch the server url
115                         $gcontact = DBA::selectFirst('gcontact', ['server_url'], ['nurl' => Strings::normaliseLink($profile)]);
116                         if (!empty($gcontact) && !empty($gcontact['server_url'])) {
117                                 $server_url[] = Strings::normaliseLink($gcontact['server_url']);
118                         }
119
120                         // Now query the GServer for the platform name
121                         $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
122
123                         if (DBA::isResult($gserver)) {
124                                 if (!empty($gserver['platform'])) {
125                                         $platform = $gserver['platform'];
126                                 } elseif (!empty($gserver['network']) && ($gserver['network'] != Protocol::ACTIVITYPUB)) {
127                                         $platform = self::networkToName($gserver['network']);
128                                 }
129
130                                 if (!empty($platform)) {
131                                         $networkname = $platform;
132
133                                         if ($network == Protocol::ACTIVITYPUB) {
134                                                 $networkname .= ' (AP)';
135                                         }
136                                 }
137                         }
138                 }
139
140                 return $networkname;
141         }
142
143         /**
144          * @param string $current optional, default empty
145          * @param string $suffix  optionsl, default empty
146          * @return string
147          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
148          */
149         public static function gender($current = "", $suffix = "")
150         {
151                 $o = '';
152                 $select = [
153                         ''                 => L10n::t('No answer'),
154                         'Male'             => L10n::t('Male'),
155                         'Female'           => L10n::t('Female'),
156                         'Currently Male'   => L10n::t('Currently Male'),
157                         'Currently Female' => L10n::t('Currently Female'),
158                         'Mostly Male'      => L10n::t('Mostly Male'),
159                         'Mostly Female'    => L10n::t('Mostly Female'),
160                         'Transgender'      => L10n::t('Transgender'),
161                         'Intersex'         => L10n::t('Intersex'),
162                         'Transsexual'      => L10n::t('Transsexual'),
163                         'Hermaphrodite'    => L10n::t('Hermaphrodite'),
164                         'Neuter'           => L10n::t('Neuter'),
165                         'Non-specific'     => L10n::t('Non-specific'),
166                         'Other'            => L10n::t('Other'),
167                         'Undecided'        => L10n::t('Undecided'),
168                 ];
169
170                 Hook::callAll('gender_selector', $select);
171
172                 $o .= "<select name=\"gender$suffix\" id=\"gender-select$suffix\" size=\"1\" >";
173                 foreach ($select as $neutral => $selection) {
174                         if ($selection !== 'NOTRANSLATION') {
175                                 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
176                                 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
177                         }
178                 }
179                 $o .= '</select>';
180                 return $o;
181         }
182
183         /**
184          * @param string $current optional, default empty
185          * @param string $suffix  optionsl, default empty
186          * @return string
187          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
188          */
189         public static function sexualPreference($current = "", $suffix = "")
190         {
191                 $o = '';
192                 $select = [
193                         ''              => L10n::t('No answer'),
194                         'Males'         => L10n::t('Males'),
195                         'Females'       => L10n::t('Females'),
196                         'Gay'           => L10n::t('Gay'),
197                         'Lesbian'       => L10n::t('Lesbian'),
198                         'No Preference' => L10n::t('No Preference'),
199                         'Bisexual'      => L10n::t('Bisexual'),
200                         'Autosexual'    => L10n::t('Autosexual'),
201                         'Abstinent'     => L10n::t('Abstinent'),
202                         'Virgin'        => L10n::t('Virgin'),
203                         'Deviant'       => L10n::t('Deviant'),
204                         'Fetish'        => L10n::t('Fetish'),
205                         'Oodles'        => L10n::t('Oodles'),
206                         'Nonsexual'     => L10n::t('Nonsexual'),
207                 ];
208
209                 Hook::callAll('sexpref_selector', $select);
210
211                 $o .= "<select name=\"sexual$suffix\" id=\"sexual-select$suffix\" size=\"1\" >";
212                 foreach ($select as $neutral => $selection) {
213                         if ($selection !== 'NOTRANSLATION') {
214                                 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
215                                 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
216                         }
217                 }
218                 $o .= '</select>';
219                 return $o;
220         }
221
222         /**
223          * @param string $current optional, default empty
224          * @return string
225          * @throws \Friendica\Network\HTTPException\InternalServerErrorException
226          */
227         public static function maritalStatus($current = "")
228         {
229                 $o = '';
230                 $select = [
231                         ''                     => L10n::t('No answer'),
232                         'Single'               => L10n::t('Single'),
233                         'Lonely'               => L10n::t('Lonely'),
234                         'In a relation'        => L10n::t('In a relation'),
235                         'Has crush'            => L10n::t('Has crush'),
236                         'Infatuated'           => L10n::t('Infatuated'),
237                         'Dating'               => L10n::t('Dating'),
238                         'Unfaithful'           => L10n::t('Unfaithful'),
239                         'Sex Addict'           => L10n::t('Sex Addict'),
240                         'Friends'              => L10n::t('Friends'),
241                         'Friends/Benefits'     => L10n::t('Friends/Benefits'),
242                         'Casual'               => L10n::t('Casual'),
243                         'Engaged'              => L10n::t('Engaged'),
244                         'Married'              => L10n::t('Married'),
245                         'Imaginarily married'  => L10n::t('Imaginarily married'),
246                         'Partners'             => L10n::t('Partners'),
247                         'Cohabiting'           => L10n::t('Cohabiting'),
248                         'Common law'           => L10n::t('Common law'),
249                         'Happy'                => L10n::t('Happy'),
250                         'Not looking'          => L10n::t('Not looking'),
251                         'Swinger'              => L10n::t('Swinger'),
252                         'Betrayed'             => L10n::t('Betrayed'),
253                         'Separated'            => L10n::t('Separated'),
254                         'Unstable'             => L10n::t('Unstable'),
255                         'Divorced'             => L10n::t('Divorced'),
256                         'Imaginarily divorced' => L10n::t('Imaginarily divorced'),
257                         'Widowed'              => L10n::t('Widowed'),
258                         'Uncertain'            => L10n::t('Uncertain'),
259                         'It\'s complicated'    => L10n::t('It\'s complicated'),
260                         'Don\'t care'          => L10n::t('Don\'t care'),
261                         'Ask me'               => L10n::t('Ask me'),
262                 ];
263
264                 Hook::callAll('marital_selector', $select);
265
266                 $o .= '<select name="marital" id="marital-select" size="1" >';
267                 foreach ($select as $neutral => $selection) {
268                         if ($selection !== 'NOTRANSLATION') {
269                                 $selected = (($neutral == $current) ? ' selected="selected" ' : '');
270                                 $o .= "<option value=\"$neutral\" $selected >$selection</option>";
271                         }
272                 }
273                 $o .= '</select>';
274                 return $o;
275         }
276 }