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