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 $network network
76 * @param string $profile optional, default empty
78 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
80 public static function networkToName($network, $profile = "")
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'),
101 Hook::callAll('network_to_name', $nets);
103 $search = array_keys($nets);
104 $replace = array_values($nets);
106 $networkname = str_replace($search, $replace, $network);
108 if ((in_array($network, [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS])) && ($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))];
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']);
120 // Now query the GServer for the platform name
121 $gserver = DBA::selectFirst('gserver', ['platform', 'network'], ['nurl' => $server_url]);
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']);
130 if (!empty($platform)) {
131 $networkname = $platform;
133 if ($network == Protocol::ACTIVITYPUB) {
134 $networkname .= ' (AP)';
144 * @param string $current optional, default empty
145 * @param string $suffix optionsl, default empty
147 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
149 public static function gender($current = "", $suffix = "")
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'),
170 Hook::callAll('gender_selector', $select);
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>";
184 * @param string $current optional, default empty
185 * @param string $suffix optionsl, default empty
187 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
189 public static function sexualPreference($current = "", $suffix = "")
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'),
209 Hook::callAll('sexpref_selector', $select);
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>";
223 * @param string $current optional, default empty
225 * @throws \Friendica\Network\HTTPException\InternalServerErrorException
227 public static function maritalStatus($current = "")
232 'Single' => L10n::t('Single'),
233 'Lonely' => L10n::t('Lonely'),
234 'Available' => L10n::t('Available'),
235 'Unavailable' => L10n::t('Unavailable'),
236 'Has crush' => L10n::t('Has crush'),
237 'Infatuated' => L10n::t('Infatuated'),
238 'Dating' => L10n::t('Dating'),
239 'Unfaithful' => L10n::t('Unfaithful'),
240 'Sex Addict' => L10n::t('Sex Addict'),
241 'Friends' => L10n::t('Friends'),
242 'Friends/Benefits' => L10n::t('Friends/Benefits'),
243 'Casual' => L10n::t('Casual'),
244 'Engaged' => L10n::t('Engaged'),
245 'Married' => L10n::t('Married'),
246 'Imaginarily married' => L10n::t('Imaginarily married'),
247 'Partners' => L10n::t('Partners'),
248 'Cohabiting' => L10n::t('Cohabiting'),
249 'Common law' => L10n::t('Common law'),
250 'Happy' => L10n::t('Happy'),
251 'Not looking' => L10n::t('Not looking'),
252 'Swinger' => L10n::t('Swinger'),
253 'Betrayed' => L10n::t('Betrayed'),
254 'Separated' => L10n::t('Separated'),
255 'Unstable' => L10n::t('Unstable'),
256 'Divorced' => L10n::t('Divorced'),
257 'Imaginarily divorced' => L10n::t('Imaginarily divorced'),
258 'Widowed' => L10n::t('Widowed'),
259 'Uncertain' => L10n::t('Uncertain'),
260 'It\'s complicated' => L10n::t('It\'s complicated'),
261 'Don\'t care' => L10n::t('Don\'t care'),
262 'Ask me' => L10n::t('Ask me'),
265 Hook::callAll('marital_selector', $select);
267 $o .= '<select name="marital" id="marital-select" 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>";