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