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