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