Merge pull request #5719 from annando/notices-yeah
[friendica.git/.git] / mod / profiles.php
1 <?php
2 /**
3  * @file mod/profiles.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Content\Nav;
10 use Friendica\Core\Addon;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\System;
15 use Friendica\Core\Worker;
16 use Friendica\Database\DBA;
17 use Friendica\Model\Contact;
18 use Friendica\Model\GContact;
19 use Friendica\Model\Profile;
20 use Friendica\Network\Probe;
21 use Friendica\Util\DateTimeFormat;
22 use Friendica\Util\Temporal;
23
24 function profiles_init(App $a) {
25
26         Nav::setSelected('profiles');
27
28         if (! local_user()) {
29                 return;
30         }
31
32         if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
33                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
34                         intval($a->argv[2]),
35                         intval(local_user())
36                 );
37                 if (! DBA::isResult($r)) {
38                         notice(L10n::t('Profile not found.') . EOL);
39                         goaway('profiles');
40                         return; // NOTREACHED
41                 }
42
43                 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
44
45                 // move every contact using this profile as their default to the user default
46
47                 $r = q("UPDATE `contact` SET `profile-id` = (SELECT `profile`.`id` AS `profile-id` FROM `profile` WHERE `profile`.`is-default` = 1 AND `profile`.`uid` = %d LIMIT 1) WHERE `profile-id` = %d AND `uid` = %d ",
48                         intval(local_user()),
49                         intval($a->argv[2]),
50                         intval(local_user())
51                 );
52                 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d",
53                         intval($a->argv[2]),
54                         intval(local_user())
55                 );
56                 if (DBA::isResult($r)) {
57                         info(L10n::t('Profile deleted.').EOL);
58                 }
59
60                 goaway('profiles');
61                 return; // NOTREACHED
62         }
63
64         if (($a->argc > 1) && ($a->argv[1] === 'new')) {
65
66                 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
67
68                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
69                         intval(local_user()));
70
71                 $num_profiles = (DBA::isResult($r0) ? count($r0) : 0);
72
73                 $name = L10n::t('Profile-') . ($num_profiles + 1);
74
75                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
76                         intval(local_user()));
77
78                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
79                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
80                         intval(local_user()),
81                         DBA::escape($name),
82                         DBA::escape($r1[0]['name']),
83                         DBA::escape($r1[0]['photo']),
84                         DBA::escape($r1[0]['thumb'])
85                 );
86
87                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
88                         intval(local_user()),
89                         DBA::escape($name)
90                 );
91
92                 info(L10n::t('New profile created.') . EOL);
93                 if (DBA::isResult($r3) && count($r3) == 1) {
94                         goaway('profiles/' . $r3[0]['id']);
95                 }
96
97                 goaway('profiles');
98         }
99
100         if (($a->argc > 2) && ($a->argv[1] === 'clone')) {
101
102                 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
103
104                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
105                         intval(local_user()));
106
107                 $num_profiles = (DBA::isResult($r0) ? count($r0) : 0);
108
109                 $name = L10n::t('Profile-') . ($num_profiles + 1);
110                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
111                         intval(local_user()),
112                         intval($a->argv[2])
113                 );
114                 if(! DBA::isResult($r1)) {
115                         notice(L10n::t('Profile unavailable to clone.') . EOL);
116                         killme();
117                         return;
118                 }
119                 unset($r1[0]['id']);
120                 $r1[0]['is-default'] = 0;
121                 $r1[0]['publish'] = 0;
122                 $r1[0]['net-publish'] = 0;
123                 $r1[0]['profile-name'] = DBA::escape($name);
124
125                 DBA::insert('profile', $r1[0]);
126
127                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
128                         intval(local_user()),
129                         DBA::escape($name)
130                 );
131                 info(L10n::t('New profile created.') . EOL);
132                 if ((DBA::isResult($r3)) && (count($r3) == 1)) {
133                         goaway('profiles/'.$r3[0]['id']);
134                 }
135
136                 goaway('profiles');
137
138                 return; // NOTREACHED
139         }
140
141
142         if (($a->argc > 1) && (intval($a->argv[1]))) {
143                 $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
144                         intval($a->argv[1]),
145                         intval(local_user())
146                 );
147                 if (! DBA::isResult($r)) {
148                         notice(L10n::t('Profile not found.') . EOL);
149                         killme();
150                         return;
151                 }
152
153                 Profile::load($a, $a->user['nickname'], $r[0]['id']);
154         }
155 }
156
157 function profile_clean_keywords($keywords)
158 {
159         $keywords = str_replace(",", " ", $keywords);
160         $keywords = explode(" ", $keywords);
161
162         $cleaned = [];
163         foreach ($keywords as $keyword) {
164                 $keyword = trim(strtolower($keyword));
165                 $keyword = trim($keyword, "#");
166                 if ($keyword != "") {
167                         $cleaned[] = $keyword;
168                 }
169         }
170
171         $keywords = implode(", ", $cleaned);
172
173         return $keywords;
174 }
175
176 function profiles_post(App $a) {
177
178         if (! local_user()) {
179                 notice(L10n::t('Permission denied.') . EOL);
180                 return;
181         }
182
183         $namechanged = false;
184
185         Addon::callHooks('profile_post', $_POST);
186
187         if (($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
188                 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
189                         intval($a->argv[1]),
190                         intval(local_user())
191                 );
192                 if (! DBA::isResult($orig)) {
193                         notice(L10n::t('Profile not found.') . EOL);
194                         return;
195                 }
196
197                 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
198
199                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
200
201                 $profile_name = notags(trim($_POST['profile_name']));
202                 if (! strlen($profile_name)) {
203                         notice(L10n::t('Profile Name is required.') . EOL);
204                         return;
205                 }
206
207                 $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00';
208
209                 $y = substr($dob, 0, 4);
210                 if ((! ctype_digit($y)) || ($y < 1900)) {
211                         $ignore_year = true;
212                 } else {
213                         $ignore_year = false;
214                 }
215                 if (!in_array($dob, ['0000-00-00', '0001-01-01'])) {
216                         if (strpos($dob, '0000-') === 0 || strpos($dob, '0001-') === 0) {
217                                 $ignore_year = true;
218                                 $dob = substr($dob, 5);
219                         }
220
221                         if ($ignore_year) {
222                                 $dob = '0000-' . DateTimeFormat::utc('1900-' . $dob, 'm-d');
223                         } else {
224                                 $dob = DateTimeFormat::utc($dob, 'Y-m-d');
225                         }
226                 }
227
228                 $name = notags(trim($_POST['name']));
229
230                 if (! strlen($name)) {
231                         $name = '[No Name]';
232                 }
233
234                 if ($orig[0]['name'] != $name) {
235                         $namechanged = true;
236                 }
237
238                 $pdesc = notags(trim($_POST['pdesc']));
239                 $gender = notags(trim($_POST['gender']));
240                 $address = notags(trim($_POST['address']));
241                 $locality = notags(trim($_POST['locality']));
242                 $region = notags(trim($_POST['region']));
243                 $postal_code = notags(trim($_POST['postal_code']));
244                 $country_name = notags(trim($_POST['country_name']));
245                 $pub_keywords = profile_clean_keywords(notags(trim($_POST['pub_keywords'])));
246                 $prv_keywords = profile_clean_keywords(notags(trim($_POST['prv_keywords'])));
247                 $marital = notags(trim($_POST['marital']));
248                 $howlong = notags(trim($_POST['howlong']));
249
250                 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
251
252                 if (! strlen($howlong)) {
253                         $howlong = NULL_DATE;
254                 } else {
255                         $howlong = DateTimeFormat::convert($howlong, 'UTC', date_default_timezone_get());
256                 }
257                 // linkify the relationship target if applicable
258
259                 $withchanged = false;
260
261                 if (strlen($with)) {
262                         if ($with != strip_tags($orig[0]['with'])) {
263                                 $withchanged = true;
264                                 $prf = '';
265                                 $lookup = $with;
266                                 if (strpos($lookup, '@') === 0) {
267                                         $lookup = substr($lookup, 1);
268                                 }
269                                 $lookup = str_replace('_',' ', $lookup);
270                                 if (strpos($lookup, '@') || (strpos($lookup, 'http://'))) {
271                                         $newname = $lookup;
272                                         $links = @Probe::lrdd($lookup);
273                                         if (count($links)) {
274                                                 foreach ($links as $link) {
275                                                         if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
276                                                                 $prf = $link['@attributes']['href'];
277                                                         }
278                                                 }
279                                         }
280                                 } else {
281                                         $newname = $lookup;
282
283                                         $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
284                                                 DBA::escape($newname),
285                                                 intval(local_user())
286                                         );
287                                         if (! DBA::isResult($r)) {
288                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
289                                                         DBA::escape($lookup),
290                                                         intval(local_user())
291                                                 );
292                                         }
293                                         if (DBA::isResult($r)) {
294                                                 $prf = $r[0]['url'];
295                                                 $newname = $r[0]['name'];
296                                         }
297                                 }
298
299                                 if ($prf) {
300                                         $with = str_replace($lookup, '<a href="' . $prf . '">' . $newname . '</a>', $with);
301                                         if (strpos($with, '@') === 0) {
302                                                 $with = substr($with, 1);
303                                         }
304                                 }
305                         } else {
306                                 $with = $orig[0]['with'];
307                         }
308                 }
309
310                 /// @TODO Not flexible enough for later expansion, let's have more OOP here
311                 $sexual = notags(trim($_POST['sexual']));
312                 $xmpp = notags(trim($_POST['xmpp']));
313                 $homepage = notags(trim($_POST['homepage']));
314                 if ((strpos($homepage, 'http') !== 0) && (strlen($homepage))) {
315                         // neither http nor https in URL, add them
316                         $homepage = 'http://'.$homepage;
317                 }
318                 $hometown = notags(trim($_POST['hometown']));
319                 $politic = notags(trim($_POST['politic']));
320                 $religion = notags(trim($_POST['religion']));
321
322                 $likes = escape_tags(trim($_POST['likes']));
323                 $dislikes = escape_tags(trim($_POST['dislikes']));
324
325                 $about = escape_tags(trim($_POST['about']));
326                 $interest = escape_tags(trim($_POST['interest']));
327                 $contact = escape_tags(trim($_POST['contact']));
328                 $music = escape_tags(trim($_POST['music']));
329                 $book = escape_tags(trim($_POST['book']));
330                 $tv = escape_tags(trim($_POST['tv']));
331                 $film = escape_tags(trim($_POST['film']));
332                 $romance = escape_tags(trim($_POST['romance']));
333                 $work = escape_tags(trim($_POST['work']));
334                 $education = escape_tags(trim($_POST['education']));
335
336                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
337
338                 PConfig::set(local_user(), 'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0));
339
340                 $changes = [];
341                 $value = '';
342                 if ($is_default) {
343                         if ($marital != $orig[0]['marital']) {
344                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . L10n::t('Marital Status');
345                                 $value = $marital;
346                         }
347                         if ($withchanged) {
348                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . L10n::t('Romantic Partner');
349                                 $value = strip_tags($with);
350                         }
351                         if ($likes != $orig[0]['likes']) {
352                                 $changes[] = L10n::t('Likes');
353                                 $value = $likes;
354                         }
355                         if ($dislikes != $orig[0]['dislikes']) {
356                                 $changes[] = L10n::t('Dislikes');
357                                 $value = $dislikes;
358                         }
359                         if ($work != $orig[0]['work']) {
360                                 $changes[] = L10n::t('Work/Employment');
361                         }
362                         if ($religion != $orig[0]['religion']) {
363                                 $changes[] = L10n::t('Religion');
364                                 $value = $religion;
365                         }
366                         if ($politic != $orig[0]['politic']) {
367                                 $changes[] = L10n::t('Political Views');
368                                 $value = $politic;
369                         }
370                         if ($gender != $orig[0]['gender']) {
371                                 $changes[] = L10n::t('Gender');
372                                 $value = $gender;
373                         }
374                         if ($sexual != $orig[0]['sexual']) {
375                                 $changes[] = L10n::t('Sexual Preference');
376                                 $value = $sexual;
377                         }
378                         if ($xmpp != $orig[0]['xmpp']) {
379                                 $changes[] = L10n::t('XMPP');
380                                 $value = $xmpp;
381                         }
382                         if ($homepage != $orig[0]['homepage']) {
383                                 $changes[] = L10n::t('Homepage');
384                                 $value = $homepage;
385                         }
386                         if ($interest != $orig[0]['interest']) {
387                                 $changes[] = L10n::t('Interests');
388                                 $value = $interest;
389                         }
390                         if ($address != $orig[0]['address']) {
391                                 $changes[] = L10n::t('Address');
392                                 // New address not sent in notifications, potential privacy issues
393                                 // in case this leaks to unintended recipients. Yes, it's in the public
394                                 // profile but that doesn't mean we have to broadcast it to everybody.
395                         }
396                         if ($locality != $orig[0]['locality'] || $region != $orig[0]['region']
397                                 || $country_name != $orig[0]['country-name']) {
398                                 $changes[] = L10n::t('Location');
399                                 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
400                                 $comma2 = (($region && $country_name) ? ', ' : '');
401                                 $value = $locality . $comma1 . $region . $comma2 . $country_name;
402                         }
403                 }
404
405                 $r = q("UPDATE `profile`
406                         SET `profile-name` = '%s',
407                         `name` = '%s',
408                         `pdesc` = '%s',
409                         `gender` = '%s',
410                         `dob` = '%s',
411                         `address` = '%s',
412                         `locality` = '%s',
413                         `region` = '%s',
414                         `postal-code` = '%s',
415                         `country-name` = '%s',
416                         `marital` = '%s',
417                         `with` = '%s',
418                         `howlong` = '%s',
419                         `sexual` = '%s',
420                         `xmpp` = '%s',
421                         `homepage` = '%s',
422                         `hometown` = '%s',
423                         `politic` = '%s',
424                         `religion` = '%s',
425                         `pub_keywords` = '%s',
426                         `prv_keywords` = '%s',
427                         `likes` = '%s',
428                         `dislikes` = '%s',
429                         `about` = '%s',
430                         `interest` = '%s',
431                         `contact` = '%s',
432                         `music` = '%s',
433                         `book` = '%s',
434                         `tv` = '%s',
435                         `film` = '%s',
436                         `romance` = '%s',
437                         `work` = '%s',
438                         `education` = '%s',
439                         `hide-friends` = %d
440                         WHERE `id` = %d AND `uid` = %d",
441                         DBA::escape($profile_name),
442                         DBA::escape($name),
443                         DBA::escape($pdesc),
444                         DBA::escape($gender),
445                         DBA::escape($dob),
446                         DBA::escape($address),
447                         DBA::escape($locality),
448                         DBA::escape($region),
449                         DBA::escape($postal_code),
450                         DBA::escape($country_name),
451                         DBA::escape($marital),
452                         DBA::escape($with),
453                         DBA::escape($howlong),
454                         DBA::escape($sexual),
455                         DBA::escape($xmpp),
456                         DBA::escape($homepage),
457                         DBA::escape($hometown),
458                         DBA::escape($politic),
459                         DBA::escape($religion),
460                         DBA::escape($pub_keywords),
461                         DBA::escape($prv_keywords),
462                         DBA::escape($likes),
463                         DBA::escape($dislikes),
464                         DBA::escape($about),
465                         DBA::escape($interest),
466                         DBA::escape($contact),
467                         DBA::escape($music),
468                         DBA::escape($book),
469                         DBA::escape($tv),
470                         DBA::escape($film),
471                         DBA::escape($romance),
472                         DBA::escape($work),
473                         DBA::escape($education),
474                         intval($hide_friends),
475                         intval($a->argv[1]),
476                         intval(local_user())
477                 );
478
479                 /// @TODO decide to use DBA::isResult() here and check $r
480                 if ($r) {
481                         info(L10n::t('Profile updated.') . EOL);
482                 }
483
484                 if ($is_default) {
485                         if ($namechanged) {
486                                 $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
487                                         DBA::escape($name),
488                                         intval(local_user())
489                                 );
490                         }
491
492                         Contact::updateSelfFromUserID(local_user());
493
494                         // Update global directory in background
495                         $url = $_SESSION['my_url'];
496                         if ($url && strlen(Config::get('system', 'directory'))) {
497                                 Worker::add(PRIORITY_LOW, "Directory", $url);
498                         }
499
500                         Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
501
502                         // Update the global contact for the user
503                         GContact::updateForUser(local_user());
504                 }
505         }
506 }
507
508 function profiles_content(App $a) {
509
510         if (! local_user()) {
511                 notice(L10n::t('Permission denied.') . EOL);
512                 return;
513         }
514
515         $o = '';
516
517         if (($a->argc > 1) && (intval($a->argv[1]))) {
518                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
519                         intval($a->argv[1]),
520                         intval(local_user())
521                 );
522                 if (! DBA::isResult($r)) {
523                         notice(L10n::t('Profile not found.') . EOL);
524                         return;
525                 }
526
527                 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), [
528                         '$baseurl' => System::baseUrl(true),
529                 ]);
530                 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), [
531                         '$baseurl' => System::baseUrl(true),
532                 ]);
533
534                 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
535                 $hide_friends = replace_macros($opt_tpl,[
536                         '$yesno' => [
537                                 'hide-friends', //Name
538                                 L10n::t('Hide contacts and friends:'), //Label
539                                 !!$r[0]['hide-friends'], //Value
540                                 '', //Help string
541                                 [L10n::t('No'), L10n::t('Yes')] //Off - On strings
542                         ],
543                         '$desc' => L10n::t('Hide your contact/friend list from viewers of this profile?'),
544                         '$yes_str' => L10n::t('Yes'),
545                         '$no_str' => L10n::t('No'),
546                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
547                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
548                 ]);
549
550                 $personal_account = !(in_array($a->user["page-flags"],
551                                         [Contact::PAGE_COMMUNITY, Contact::PAGE_PRVGROUP]));
552
553                 $detailled_profile = (PConfig::get(local_user(), 'system', 'detailled_profile') AND $personal_account);
554
555                 $is_default = (($r[0]['is-default']) ? 1 : 0);
556                 $tpl = get_markup_template("profile_edit.tpl");
557                 $o .= replace_macros($tpl, [
558                         '$personal_account' => $personal_account,
559                         '$detailled_profile' => $detailled_profile,
560
561                         '$details' => [
562                                 'detailled_profile', //Name
563                                 L10n::t('Show more profile fields:'), //Label
564                                 $detailled_profile, //Value
565                                 '', //Help string
566                                 [L10n::t('No'), L10n::t('Yes')] //Off - On strings
567                         ],
568
569                         '$multi_profiles'               => Feature::isEnabled(local_user(), 'multi_profiles'),
570                         '$form_security_token'          => get_form_security_token("profile_edit"),
571                         '$form_security_token_photo'    => get_form_security_token("profile_photo"),
572                         '$profile_clone_link'           => ((Feature::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""),
573                         '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
574
575                         '$profile_action' => L10n::t('Profile Actions'),
576                         '$banner'       => L10n::t('Edit Profile Details'),
577                         '$submit'       => L10n::t('Submit'),
578                         '$profpic'      => L10n::t('Change Profile Photo'),
579                         '$profpiclink'  => '/photos/' . $a->user['nickname'],
580                         '$viewprof'     => L10n::t('View this profile'),
581                         '$viewallprof'  => L10n::t('View all profiles'),
582                         '$editvis'      => L10n::t('Edit visibility'),
583                         '$cr_prof'      => L10n::t('Create a new profile using these settings'),
584                         '$cl_prof'      => L10n::t('Clone this profile'),
585                         '$del_prof'     => L10n::t('Delete this profile'),
586
587                         '$lbl_basic_section' => L10n::t('Basic information'),
588                         '$lbl_picture_section' => L10n::t('Profile picture'),
589                         '$lbl_location_section' => L10n::t('Location'),
590                         '$lbl_preferences_section' => L10n::t('Preferences'),
591                         '$lbl_status_section' => L10n::t('Status information'),
592                         '$lbl_about_section' => L10n::t('Additional information'),
593                         '$lbl_interests_section' => L10n::t('Interests'),
594                         '$lbl_personal_section' => L10n::t('Personal'),
595                         '$lbl_relation_section' => L10n::t('Relation'),
596                         '$lbl_miscellaneous_section' => L10n::t('Miscellaneous'),
597
598                         '$lbl_profile_photo' => L10n::t('Upload Profile Photo'),
599                         '$lbl_gender' => L10n::t('Your Gender:'),
600                         '$lbl_marital' => L10n::t('<span class="heart">&hearts;</span> Marital Status:'),
601                         '$lbl_sexual' => L10n::t('Sexual Preference:'),
602                         '$lbl_ex2' => L10n::t('Example: fishing photography software'),
603
604                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
605                         '$baseurl' => System::baseUrl(true),
606                         '$profile_id' => $r[0]['id'],
607                         '$profile_name' => ['profile_name', L10n::t('Profile Name:'), $r[0]['profile-name'], L10n::t('Required'), '*'],
608                         '$is_default'   => $is_default,
609                         '$default' => (($is_default) ? '<p id="profile-edit-default-desc">' . L10n::t('This is your <strong>public</strong> profile.<br />It <strong>may</strong> be visible to anybody using the internet.') . '</p>' : ""),
610                         '$name' => ['name', L10n::t('Your Full Name:'), $r[0]['name']],
611                         '$pdesc' => ['pdesc', L10n::t('Title/Description:'), $r[0]['pdesc']],
612                         '$dob' => Temporal::getDateofBirthField($r[0]['dob']),
613                         '$hide_friends' => $hide_friends,
614                         '$address' => ['address', L10n::t('Street Address:'), $r[0]['address']],
615                         '$locality' => ['locality', L10n::t('Locality/City:'), $r[0]['locality']],
616                         '$region' => ['region', L10n::t('Region/State:'), $r[0]['region']],
617                         '$postal_code' => ['postal_code', L10n::t('Postal/Zip Code:'), $r[0]['postal-code']],
618                         '$country_name' => ['country_name', L10n::t('Country:'), $r[0]['country-name']],
619                         '$age' => ((intval($r[0]['dob'])) ? '(' . L10n::t('Age: ') . Temporal::getAgeByTimezone($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
620                         '$gender' => ContactSelector::gender($r[0]['gender']),
621                         '$marital' => ContactSelector::maritalStatus($r[0]['marital']),
622                         '$with' => ['with', L10n::t("Who: \x28if applicable\x29"), strip_tags($r[0]['with']), L10n::t('Examples: cathy123, Cathy Williams, cathy@example.com')],
623                         '$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= NULL_DATE ? '' : DateTimeFormat::local($r[0]['howlong']))],
624                         '$sexual' => ContactSelector::sexualPreference($r[0]['sexual']),
625                         '$about' => ['about', L10n::t('Tell us about yourself...'), $r[0]['about']],
626                         '$xmpp' => ['xmpp', L10n::t("XMPP \x28Jabber\x29 address:"), $r[0]['xmpp'], L10n::t("The XMPP address will be propagated to your contacts so that they can follow you.")],
627                         '$homepage' => ['homepage', L10n::t('Homepage URL:'), $r[0]['homepage']],
628                         '$hometown' => ['hometown', L10n::t('Hometown:'), $r[0]['hometown']],
629                         '$politic' => ['politic', L10n::t('Political Views:'), $r[0]['politic']],
630                         '$religion' => ['religion', L10n::t('Religious Views:'), $r[0]['religion']],
631                         '$pub_keywords' => ['pub_keywords', L10n::t('Public Keywords:'), $r[0]['pub_keywords'], L10n::t("\x28Used for suggesting potential friends, can be seen by others\x29")],
632                         '$prv_keywords' => ['prv_keywords', L10n::t('Private Keywords:'), $r[0]['prv_keywords'], L10n::t("\x28Used for searching profiles, never shown to others\x29")],
633                         '$likes' => ['likes', L10n::t('Likes:'), $r[0]['likes']],
634                         '$dislikes' => ['dislikes', L10n::t('Dislikes:'), $r[0]['dislikes']],
635                         '$music' => ['music', L10n::t('Musical interests'), $r[0]['music']],
636                         '$book' => ['book', L10n::t('Books, literature'), $r[0]['book']],
637                         '$tv' => ['tv', L10n::t('Television'), $r[0]['tv']],
638                         '$film' => ['film', L10n::t('Film/dance/culture/entertainment'), $r[0]['film']],
639                         '$interest' => ['interest', L10n::t('Hobbies/Interests'), $r[0]['interest']],
640                         '$romance' => ['romance', L10n::t('Love/romance'), $r[0]['romance']],
641                         '$work' => ['work', L10n::t('Work/employment'), $r[0]['work']],
642                         '$education' => ['education', L10n::t('School/education'), $r[0]['education']],
643                         '$contact' => ['contact', L10n::t('Contact information and Social Networks'), $r[0]['contact']],
644                 ]);
645
646                 $arr = ['profile' => $r[0], 'entry' => $o];
647                 Addon::callHooks('profile_edit', $arr);
648
649                 return $o;
650         } else {
651                 // If we don't support multi profiles, don't display this list.
652                 if (!Feature::isEnabled(local_user(), 'multi_profiles')) {
653                         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
654                                 local_user()
655                         );
656                         if (DBA::isResult($r)) {
657                                 //Go to the default profile.
658                                 goaway('profiles/' . $r[0]['id']);
659                         }
660                 }
661
662                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
663                         local_user());
664
665                 if (DBA::isResult($r)) {
666
667                         $tpl = get_markup_template('profile_entry.tpl');
668
669                         $profiles = '';
670                         foreach ($r as $rr) {
671                                 $profiles .= replace_macros($tpl, [
672                                         '$photo'        => $a->remove_baseurl($rr['thumb']),
673                                         '$id'           => $rr['id'],
674                                         '$alt'          => L10n::t('Profile Image'),
675                                         '$profile_name' => $rr['profile-name'],
676                                         '$visible'      => (($rr['is-default']) ? '<strong>' . L10n::t('visible to everybody') . '</strong>'
677                                                 : '<a href="'.'profperm/'.$rr['id'].'" />' . L10n::t('Edit visibility') . '</a>')
678                                 ]);
679                         }
680
681                         $tpl_header = get_markup_template('profile_listing_header.tpl');
682                         $o .= replace_macros($tpl_header,[
683                                 '$header'      => L10n::t('Edit/Manage Profiles'),
684                                 '$chg_photo'   => L10n::t('Change profile photo'),
685                                 '$cr_new'      => L10n::t('Create New Profile'),
686                                 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new"),
687                                 '$profiles'    => $profiles
688                         ]);
689                 }
690                 return $o;
691         }
692
693 }