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