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