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