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