]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
added more curly braces + spaces for #3254
[friendica.git] / mod / profiles.php
1 <?php
2 /**
3  * @file mod/profiles.php
4  */
5
6 use Friendica\App;
7 use Friendica\Content\ContactSelector;
8 use Friendica\Content\Feature;
9 use Friendica\Content\Nav;
10 use Friendica\Core\Addon;
11 use Friendica\Core\Config;
12 use Friendica\Core\L10n;
13 use Friendica\Core\PConfig;
14 use Friendica\Core\System;
15 use Friendica\Core\Worker;
16 use Friendica\Database\DBM;
17 use Friendica\Model\Contact;
18 use Friendica\Model\GContact;
19 use Friendica\Model\Item;
20 use Friendica\Model\Profile;
21 use Friendica\Network\Probe;
22 use Friendica\Util\DateTimeFormat;
23 use Friendica\Util\Temporal;
24
25 function profiles_init(App $a) {
26
27         Nav::setSelected('profiles');
28
29         if (! local_user()) {
30                 return;
31         }
32
33         if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
34                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
35                         intval($a->argv[2]),
36                         intval(local_user())
37                 );
38                 if (! DBM::is_result($r)) {
39                         notice(L10n::t('Profile not found.') . EOL);
40                         goaway('profiles');
41                         return; // NOTREACHED
42                 }
43
44                 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
45
46                 // move every contact using this profile as their default to the user default
47
48                 $r = 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 ",
49                         intval(local_user()),
50                         intval($a->argv[2]),
51                         intval(local_user())
52                 );
53                 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d",
54                         intval($a->argv[2]),
55                         intval(local_user())
56                 );
57                 if (DBM::is_result($r)) {
58                         info(L10n::t('Profile deleted.').EOL);
59                 }
60
61                 goaway('profiles');
62                 return; // NOTREACHED
63         }
64
65         if (($a->argc > 1) && ($a->argv[1] === 'new')) {
66
67                 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
68
69                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
70                         intval(local_user()));
71
72                 $num_profiles = (DBM::is_result($r0) ? count($r0) : 0);
73
74                 $name = L10n::t('Profile-') . ($num_profiles + 1);
75
76                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
77                         intval(local_user()));
78
79                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
80                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
81                         intval(local_user()),
82                         dbesc($name),
83                         dbesc($r1[0]['name']),
84                         dbesc($r1[0]['photo']),
85                         dbesc($r1[0]['thumb'])
86                 );
87
88                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
89                         intval(local_user()),
90                         dbesc($name)
91                 );
92
93                 info(L10n::t('New profile created.') . EOL);
94                 if (DBM::is_result($r3) && count($r3) == 1) {
95                         goaway('profiles/' . $r3[0]['id']);
96                 }
97
98                 goaway('profiles');
99         }
100
101         if (($a->argc > 2) && ($a->argv[1] === 'clone')) {
102
103                 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
104
105                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
106                         intval(local_user()));
107
108                 $num_profiles = (DBM::is_result($r0) ? count($r0) : 0);
109
110                 $name = L10n::t('Profile-') . ($num_profiles + 1);
111                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
112                         intval(local_user()),
113                         intval($a->argv[2])
114                 );
115                 if(! DBM::is_result($r1)) {
116                         notice(L10n::t('Profile unavailable to clone.') . EOL);
117                         killme();
118                         return;
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'] = dbesc($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                         dbesc($name)
131                 );
132                 info(L10n::t('New profile created.') . EOL);
133                 if ((DBM::is_result($r3)) && (count($r3) == 1)) {
134                         goaway('profiles/'.$r3[0]['id']);
135                 }
136
137                 goaway('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 (! DBM::is_result($r)) {
149                         notice(L10n::t('Profile not found.') . EOL);
150                         killme();
151                         return;
152                 }
153
154                 Profile::load($a, $a->user['nickname'], $r[0]['id']);
155         }
156
157
158
159 }
160
161 function profile_clean_keywords($keywords) {
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         Addon::callHooks('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 (! DBM::is_result($orig)) {
196                         notice(L10n::t('Profile not found.') . EOL);
197                         return;
198                 }
199
200                 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
201
202                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
203
204                 $profile_name = notags(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'] ? escape_tags(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', '0001-01-01'])) {
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 = notags(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 = notags(trim($_POST['pdesc']));
242                 $gender = notags(trim($_POST['gender']));
243                 $address = notags(trim($_POST['address']));
244                 $locality = notags(trim($_POST['locality']));
245                 $region = notags(trim($_POST['region']));
246                 $postal_code = notags(trim($_POST['postal_code']));
247                 $country_name = notags(trim($_POST['country_name']));
248                 $pub_keywords = profile_clean_keywords(notags(trim($_POST['pub_keywords'])));
249                 $prv_keywords = profile_clean_keywords(notags(trim($_POST['prv_keywords'])));
250                 $marital = notags(trim($_POST['marital']));
251                 $howlong = notags(trim($_POST['howlong']));
252
253                 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
254
255                 if (! strlen($howlong)) {
256                         $howlong = NULL_DATE;
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                                                 dbesc($newname),
288                                                 intval(local_user())
289                                         );
290                                         if (! DBM::is_result($r)) {
291                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
292                                                         dbesc($lookup),
293                                                         intval(local_user())
294                                                 );
295                                         }
296                                         if (DBM::is_result($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 = notags(trim($_POST['sexual']));
315                 $xmpp = notags(trim($_POST['xmpp']));
316                 $homepage = notags(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 = notags(trim($_POST['hometown']));
322                 $politic = notags(trim($_POST['politic']));
323                 $religion = notags(trim($_POST['religion']));
324
325                 $likes = escape_tags(trim($_POST['likes']));
326                 $dislikes = escape_tags(trim($_POST['dislikes']));
327
328                 $about = escape_tags(trim($_POST['about']));
329                 $interest = escape_tags(trim($_POST['interest']));
330                 $contact = escape_tags(trim($_POST['contact']));
331                 $music = escape_tags(trim($_POST['music']));
332                 $book = escape_tags(trim($_POST['book']));
333                 $tv = escape_tags(trim($_POST['tv']));
334                 $film = escape_tags(trim($_POST['film']));
335                 $romance = escape_tags(trim($_POST['romance']));
336                 $work = escape_tags(trim($_POST['work']));
337                 $education = escape_tags(trim($_POST['education']));
338
339                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
340
341                 PConfig::set(local_user(), 'system', 'detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0));
342
343                 $changes = [];
344                 $value = '';
345                 if ($is_default) {
346                         if ($marital != $orig[0]['marital']) {
347                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . L10n::t('Marital Status');
348                                 $value = $marital;
349                         }
350                         if ($withchanged) {
351                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . L10n::t('Romantic Partner');
352                                 $value = strip_tags($with);
353                         }
354                         if ($likes != $orig[0]['likes']) {
355                                 $changes[] = L10n::t('Likes');
356                                 $value = $likes;
357                         }
358                         if ($dislikes != $orig[0]['dislikes']) {
359                                 $changes[] = L10n::t('Dislikes');
360                                 $value = $dislikes;
361                         }
362                         if ($work != $orig[0]['work']) {
363                                 $changes[] = L10n::t('Work/Employment');
364                         }
365                         if ($religion != $orig[0]['religion']) {
366                                 $changes[] = L10n::t('Religion');
367                                 $value = $religion;
368                         }
369                         if ($politic != $orig[0]['politic']) {
370                                 $changes[] = L10n::t('Political Views');
371                                 $value = $politic;
372                         }
373                         if ($gender != $orig[0]['gender']) {
374                                 $changes[] = L10n::t('Gender');
375                                 $value = $gender;
376                         }
377                         if ($sexual != $orig[0]['sexual']) {
378                                 $changes[] = L10n::t('Sexual Preference');
379                                 $value = $sexual;
380                         }
381                         if ($xmpp != $orig[0]['xmpp']) {
382                                 $changes[] = L10n::t('XMPP');
383                                 $value = $xmpp;
384                         }
385                         if ($homepage != $orig[0]['homepage']) {
386                                 $changes[] = L10n::t('Homepage');
387                                 $value = $homepage;
388                         }
389                         if ($interest != $orig[0]['interest']) {
390                                 $changes[] = L10n::t('Interests');
391                                 $value = $interest;
392                         }
393                         if ($address != $orig[0]['address']) {
394                                 $changes[] = L10n::t('Address');
395                                 // New address not sent in notifications, potential privacy issues
396                                 // in case this leaks to unintended recipients. Yes, it's in the public
397                                 // profile but that doesn't mean we have to broadcast it to everybody.
398                         }
399                         if ($locality != $orig[0]['locality'] || $region != $orig[0]['region']
400                                 || $country_name != $orig[0]['country-name']) {
401                                 $changes[] = L10n::t('Location');
402                                 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
403                                 $comma2 = (($region && $country_name) ? ', ' : '');
404                                 $value = $locality . $comma1 . $region . $comma2 . $country_name;
405                         }
406
407                         profile_activity($changes,$value);
408
409                 }
410
411                 $r = q("UPDATE `profile`
412                         SET `profile-name` = '%s',
413                         `name` = '%s',
414                         `pdesc` = '%s',
415                         `gender` = '%s',
416                         `dob` = '%s',
417                         `address` = '%s',
418                         `locality` = '%s',
419                         `region` = '%s',
420                         `postal-code` = '%s',
421                         `country-name` = '%s',
422                         `marital` = '%s',
423                         `with` = '%s',
424                         `howlong` = '%s',
425                         `sexual` = '%s',
426                         `xmpp` = '%s',
427                         `homepage` = '%s',
428                         `hometown` = '%s',
429                         `politic` = '%s',
430                         `religion` = '%s',
431                         `pub_keywords` = '%s',
432                         `prv_keywords` = '%s',
433                         `likes` = '%s',
434                         `dislikes` = '%s',
435                         `about` = '%s',
436                         `interest` = '%s',
437                         `contact` = '%s',
438                         `music` = '%s',
439                         `book` = '%s',
440                         `tv` = '%s',
441                         `film` = '%s',
442                         `romance` = '%s',
443                         `work` = '%s',
444                         `education` = '%s',
445                         `hide-friends` = %d
446                         WHERE `id` = %d AND `uid` = %d",
447                         dbesc($profile_name),
448                         dbesc($name),
449                         dbesc($pdesc),
450                         dbesc($gender),
451                         dbesc($dob),
452                         dbesc($address),
453                         dbesc($locality),
454                         dbesc($region),
455                         dbesc($postal_code),
456                         dbesc($country_name),
457                         dbesc($marital),
458                         dbesc($with),
459                         dbesc($howlong),
460                         dbesc($sexual),
461                         dbesc($xmpp),
462                         dbesc($homepage),
463                         dbesc($hometown),
464                         dbesc($politic),
465                         dbesc($religion),
466                         dbesc($pub_keywords),
467                         dbesc($prv_keywords),
468                         dbesc($likes),
469                         dbesc($dislikes),
470                         dbesc($about),
471                         dbesc($interest),
472                         dbesc($contact),
473                         dbesc($music),
474                         dbesc($book),
475                         dbesc($tv),
476                         dbesc($film),
477                         dbesc($romance),
478                         dbesc($work),
479                         dbesc($education),
480                         intval($hide_friends),
481                         intval($a->argv[1]),
482                         intval(local_user())
483                 );
484
485                 /// @TODO decide to use dbm::is_result() here and check $r
486                 if ($r) {
487                         info(L10n::t('Profile updated.') . EOL);
488                 }
489
490                 if ($is_default) {
491                         if ($namechanged) {
492                                 $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
493                                         dbesc($name),
494                                         intval(local_user())
495                                 );
496                         }
497
498                         Contact::updateSelfFromUserID(local_user());
499
500                         // Update global directory in background
501                         $url = $_SESSION['my_url'];
502                         if ($url && strlen(Config::get('system', 'directory'))) {
503                                 Worker::add(PRIORITY_LOW, "Directory", $url);
504                         }
505
506                         Worker::add(PRIORITY_LOW, 'ProfileUpdate', local_user());
507
508                         // Update the global contact for the user
509                         GContact::updateForUser(local_user());
510                 }
511         }
512 }
513
514
515 function profile_activity($changed, $value) {
516         $a = get_app();
517
518         if (! local_user() || ! is_array($changed) || ! count($changed)) {
519                 return;
520         }
521
522         if ($a->user['hidewall'] || Config::get('system', 'block_public')) {
523                 return;
524         }
525
526         if (! PConfig::get(local_user(), 'system', 'post_profilechange')) {
527                 return;
528         }
529
530         require_once 'include/items.php';
531
532         $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
533                 intval(local_user())
534         );
535
536         if (! DBM::is_result($self)) {
537                 return;
538         }
539
540         $arr = [];
541
542         $arr['guid'] = get_guid(32);
543         $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
544         $arr['uid'] = local_user();
545         $arr['contact-id'] = $self[0]['id'];
546         $arr['wall'] = 1;
547         $arr['type'] = 'wall';
548         $arr['gravity'] = 0;
549         $arr['origin'] = 1;
550         $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
551         $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
552         $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
553         $arr['verb'] = ACTIVITY_UPDATE;
554         $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
555
556         $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
557
558
559         $changes = '';
560         $t = count($changed);
561         $z = 0;
562         foreach ($changed as $ch) {
563                 if (strlen($changes)) {
564                         if ($z == ($t - 1)) {
565                                 $changes .= L10n::t(' and ');
566                         } else {
567                                 $changes .= ', ';
568                         }
569                 }
570                 $z ++;
571                 $changes .= $ch;
572         }
573
574         $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . L10n::t('public profile') . '[/url]';
575
576         if ($t == 1 && strlen($value)) {
577                 $message = L10n::t('%1$s changed %2$s to &ldquo;%3$s&rdquo;', $A, $changes, $value);
578                 $message .= "\n\n" . L10n::t(' - Visit %1$s\'s %2$s', $A, $prof);
579         } else {
580                 $message =      L10n::t('%1$s has an updated %2$s, changing %3$s.', $A, $prof, $changes);
581         }
582
583
584         $arr['body'] = $message;
585
586         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
587         . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
588         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
589         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
590         $arr['object'] .= '</link></object>' . "\n";
591
592         $arr['allow_cid'] = $a->user['allow_cid'];
593         $arr['allow_gid'] = $a->user['allow_gid'];
594         $arr['deny_cid']  = $a->user['deny_cid'];
595         $arr['deny_gid']  = $a->user['deny_gid'];
596
597         $i = Item::insert($arr);
598         if ($i) {
599                 Worker::add(PRIORITY_HIGH, "Notifier", "activity", $i);
600         }
601 }
602
603
604 function profiles_content(App $a) {
605
606         if (! local_user()) {
607                 notice(L10n::t('Permission denied.') . EOL);
608                 return;
609         }
610
611         $o = '';
612
613         if (($a->argc > 1) && (intval($a->argv[1]))) {
614                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
615                         intval($a->argv[1]),
616                         intval(local_user())
617                 );
618                 if (! DBM::is_result($r)) {
619                         notice(L10n::t('Profile not found.') . EOL);
620                         return;
621                 }
622
623                 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), [
624                         '$baseurl' => System::baseUrl(true),
625                 ]);
626                 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), [
627                         '$baseurl' => System::baseUrl(true),
628                 ]);
629
630                 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
631                 $hide_friends = replace_macros($opt_tpl,[
632                         '$yesno' => [
633                                 'hide-friends', //Name
634                                 L10n::t('Hide contacts and friends:'), //Label
635                                 !!$r[0]['hide-friends'], //Value
636                                 '', //Help string
637                                 [L10n::t('No'), L10n::t('Yes')] //Off - On strings
638                         ],
639                         '$desc' => L10n::t('Hide your contact/friend list from viewers of this profile?'),
640                         '$yes_str' => L10n::t('Yes'),
641                         '$no_str' => L10n::t('No'),
642                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
643                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
644                 ]);
645
646                 $personal_account = !(in_array($a->user["page-flags"],
647                                         [PAGE_COMMUNITY, PAGE_PRVGROUP]));
648
649                 $detailled_profile = (PConfig::get(local_user(), 'system', 'detailled_profile') AND $personal_account);
650
651                 $is_default = (($r[0]['is-default']) ? 1 : 0);
652                 $tpl = get_markup_template("profile_edit.tpl");
653                 $o .= replace_macros($tpl, [
654                         '$personal_account' => $personal_account,
655                         '$detailled_profile' => $detailled_profile,
656
657                         '$details' => [
658                                 'detailled_profile', //Name
659                                 L10n::t('Show more profile fields:'), //Label
660                                 $detailled_profile, //Value
661                                 '', //Help string
662                                 [L10n::t('No'), L10n::t('Yes')] //Off - On strings
663                         ],
664
665                         '$multi_profiles'               => Feature::isEnabled(local_user(), 'multi_profiles'),
666                         '$form_security_token'          => get_form_security_token("profile_edit"),
667                         '$form_security_token_photo'    => get_form_security_token("profile_photo"),
668                         '$profile_clone_link'           => ((Feature::isEnabled(local_user(), 'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""),
669                         '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
670
671                         '$profile_action' => L10n::t('Profile Actions'),
672                         '$banner'       => L10n::t('Edit Profile Details'),
673                         '$submit'       => L10n::t('Submit'),
674                         '$profpic'      => L10n::t('Change Profile Photo'),
675                         '$viewprof'     => L10n::t('View this profile'),
676                         '$editvis'      => L10n::t('Edit visibility'),
677                         '$cr_prof'      => L10n::t('Create a new profile using these settings'),
678                         '$cl_prof'      => L10n::t('Clone this profile'),
679                         '$del_prof'     => L10n::t('Delete this profile'),
680
681                         '$lbl_basic_section' => L10n::t('Basic information'),
682                         '$lbl_picture_section' => L10n::t('Profile picture'),
683                         '$lbl_location_section' => L10n::t('Location'),
684                         '$lbl_preferences_section' => L10n::t('Preferences'),
685                         '$lbl_status_section' => L10n::t('Status information'),
686                         '$lbl_about_section' => L10n::t('Additional information'),
687                         '$lbl_interests_section' => L10n::t('Interests'),
688                         '$lbl_personal_section' => L10n::t('Personal'),
689                         '$lbl_relation_section' => L10n::t('Relation'),
690                         '$lbl_miscellaneous_section' => L10n::t('Miscellaneous'),
691
692                         '$lbl_profile_photo' => L10n::t('Upload Profile Photo'),
693                         '$lbl_gender' => L10n::t('Your Gender:'),
694                         '$lbl_marital' => L10n::t('<span class="heart">&hearts;</span> Marital Status:'),
695                         '$lbl_sexual' => L10n::t('Sexual Preference:'),
696                         '$lbl_ex2' => L10n::t('Example: fishing photography software'),
697
698                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
699                         '$baseurl' => System::baseUrl(true),
700                         '$profile_id' => $r[0]['id'],
701                         '$profile_name' => ['profile_name', L10n::t('Profile Name:'), $r[0]['profile-name'], L10n::t('Required'), '*'],
702                         '$is_default'   => $is_default,
703                         '$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>' : ""),
704                         '$name' => ['name', L10n::t('Your Full Name:'), $r[0]['name']],
705                         '$pdesc' => ['pdesc', L10n::t('Title/Description:'), $r[0]['pdesc']],
706                         '$dob' => Temporal::getDateofBirthField($r[0]['dob']),
707                         '$hide_friends' => $hide_friends,
708                         '$address' => ['address', L10n::t('Street Address:'), $r[0]['address']],
709                         '$locality' => ['locality', L10n::t('Locality/City:'), $r[0]['locality']],
710                         '$region' => ['region', L10n::t('Region/State:'), $r[0]['region']],
711                         '$postal_code' => ['postal_code', L10n::t('Postal/Zip Code:'), $r[0]['postal-code']],
712                         '$country_name' => ['country_name', L10n::t('Country:'), $r[0]['country-name']],
713                         '$age' => ((intval($r[0]['dob'])) ? '(' . L10n::t('Age: ') . Temporal::getAgeByTimezone($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
714                         '$gender' => ContactSelector::gender($r[0]['gender']),
715                         '$marital' => ContactSelector::maritalStatus($r[0]['marital']),
716                         '$with' => ['with', L10n::t("Who: \x28if applicable\x29"), strip_tags($r[0]['with']), L10n::t('Examples: cathy123, Cathy Williams, cathy@example.com')],
717                         '$howlong' => ['howlong', L10n::t('Since [date]:'), ($r[0]['howlong'] <= NULL_DATE ? '' : DateTimeFormat::local($r[0]['howlong']))],
718                         '$sexual' => ContactSelector::sexualPreference($r[0]['sexual']),
719                         '$about' => ['about', L10n::t('Tell us about yourself...'), $r[0]['about']],
720                         '$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.")],
721                         '$homepage' => ['homepage', L10n::t('Homepage URL:'), $r[0]['homepage']],
722                         '$hometown' => ['hometown', L10n::t('Hometown:'), $r[0]['hometown']],
723                         '$politic' => ['politic', L10n::t('Political Views:'), $r[0]['politic']],
724                         '$religion' => ['religion', L10n::t('Religious Views:'), $r[0]['religion']],
725                         '$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")],
726                         '$prv_keywords' => ['prv_keywords', L10n::t('Private Keywords:'), $r[0]['prv_keywords'], L10n::t("\x28Used for searching profiles, never shown to others\x29")],
727                         '$likes' => ['likes', L10n::t('Likes:'), $r[0]['likes']],
728                         '$dislikes' => ['dislikes', L10n::t('Dislikes:'), $r[0]['dislikes']],
729                         '$music' => ['music', L10n::t('Musical interests'), $r[0]['music']],
730                         '$book' => ['book', L10n::t('Books, literature'), $r[0]['book']],
731                         '$tv' => ['tv', L10n::t('Television'), $r[0]['tv']],
732                         '$film' => ['film', L10n::t('Film/dance/culture/entertainment'), $r[0]['film']],
733                         '$interest' => ['interest', L10n::t('Hobbies/Interests'), $r[0]['interest']],
734                         '$romance' => ['romance', L10n::t('Love/romance'), $r[0]['romance']],
735                         '$work' => ['work', L10n::t('Work/employment'), $r[0]['work']],
736                         '$education' => ['education', L10n::t('School/education'), $r[0]['education']],
737                         '$contact' => ['contact', L10n::t('Contact information and Social Networks'), $r[0]['contact']],
738                 ]);
739
740                 $arr = ['profile' => $r[0], 'entry' => $o];
741                 Addon::callHooks('profile_edit', $arr);
742
743                 return $o;
744         } else {
745                 // If we don't support multi profiles, don't display this list.
746                 if (!Feature::isEnabled(local_user(), 'multi_profiles')) {
747                         $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
748                                 local_user()
749                         );
750                         if (DBM::is_result($r)) {
751                                 //Go to the default profile.
752                                 goaway('profiles/' . $r[0]['id']);
753                         }
754                 }
755
756                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
757                         local_user());
758
759                 if (DBM::is_result($r)) {
760
761                         $tpl = get_markup_template('profile_entry.tpl');
762
763                         $profiles = '';
764                         foreach ($r as $rr) {
765                                 $profiles .= replace_macros($tpl, [
766                                         '$photo'        => $a->remove_baseurl($rr['thumb']),
767                                         '$id'           => $rr['id'],
768                                         '$alt'          => L10n::t('Profile Image'),
769                                         '$profile_name' => $rr['profile-name'],
770                                         '$visible'      => (($rr['is-default']) ? '<strong>' . L10n::t('visible to everybody') . '</strong>'
771                                                 : '<a href="'.'profperm/'.$rr['id'].'" />' . L10n::t('Edit visibility') . '</a>')
772                                 ]);
773                         }
774
775                         $tpl_header = get_markup_template('profile_listing_header.tpl');
776                         $o .= replace_macros($tpl_header,[
777                                 '$header'      => L10n::t('Edit/Manage Profiles'),
778                                 '$chg_photo'   => L10n::t('Change profile photo'),
779                                 '$cr_new'      => L10n::t('Create New Profile'),
780                                 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new"),
781                                 '$profiles'    => $profiles
782                         ]);
783                 }
784                 return $o;
785         }
786
787 }