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