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