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