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