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