]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
Merge remote-tracking branch 'upstream/develop' into rewrites/coding-convention
[friendica.git] / mod / profiles.php
1 <?php
2 require_once("include/Contact.php");
3 require_once('include/Probe.php');
4
5 function profiles_init(App $a) {
6
7         nav_set_selected('profiles');
8
9         if (! local_user()) {
10                 return;
11         }
12
13         if (($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
14                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
15                         intval($a->argv[2]),
16                         intval(local_user())
17                 );
18                 if (! dbm::is_result($r)) {
19                         notice( t('Profile not found.') . EOL);
20                         goaway('profiles');
21                         return; // NOTREACHED
22                 }
23
24                 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
25
26                 // move every contact using this profile as their default to the user default
27
28                 $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 ",
29                         intval(local_user()),
30                         intval($a->argv[2]),
31                         intval(local_user())
32                 );
33                 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d",
34                         intval($a->argv[2]),
35                         intval(local_user())
36                 );
37                 if ($r) {
38                         info(t('Profile deleted.').EOL);
39                 }
40
41                 goaway('profiles');
42                 return; // NOTREACHED
43         }
44
45
46
47
48
49         if (($a->argc > 1) && ($a->argv[1] === 'new')) {
50
51                 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
52
53                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
54                         intval(local_user()));
55                 $num_profiles = count($r0);
56
57                 $name = t('Profile-') . ($num_profiles + 1);
58
59                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
60                         intval(local_user()));
61
62                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
63                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
64                         intval(local_user()),
65                         dbesc($name),
66                         dbesc($r1[0]['name']),
67                         dbesc($r1[0]['photo']),
68                         dbesc($r1[0]['thumb'])
69                 );
70
71                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
72                         intval(local_user()),
73                         dbesc($name)
74                 );
75
76                 info( t('New profile created.') . EOL);
77                 if (count($r3) == 1)
78                         goaway('profiles/'.$r3[0]['id']);
79
80                 goaway('profiles');
81         }
82
83         if (($a->argc > 2) && ($a->argv[1] === 'clone')) {
84
85                 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
86
87                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
88                         intval(local_user()));
89                 $num_profiles = count($r0);
90
91                 $name = t('Profile-') . ($num_profiles + 1);
92                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
93                         intval(local_user()),
94                         intval($a->argv[2])
95                 );
96                 if (! dbm::is_result($r1)) {
97                         notice( t('Profile unavailable to clone.') . EOL);
98                         killme();
99                         return;
100                 }
101                 unset($r1[0]['id']);
102                 $r1[0]['is-default'] = 0;
103                 $r1[0]['publish'] = 0;
104                 $r1[0]['net-publish'] = 0;
105                 $r1[0]['profile-name'] = dbesc($name);
106
107                 dbm::esc_array($r1[0], true);
108
109                 $r2 = dbq("INSERT INTO `profile` (`"
110                         . implode("`, `", array_keys($r1[0]))
111                         . "`) VALUES ("
112                         . implode(", ", array_values($r1[0]))
113                         . ")" );
114
115                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
116                         intval(local_user()),
117                         dbesc($name)
118                 );
119                 info( t('New profile created.') . EOL);
120                 if ((dbm::is_result($r3)) && (count($r3) == 1))
121                         goaway('profiles/'.$r3[0]['id']);
122
123                 goaway('profiles');
124
125                 return; // NOTREACHED
126         }
127
128
129         if (($a->argc > 1) && (intval($a->argv[1]))) {
130                 $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
131                         intval($a->argv[1]),
132                         intval(local_user())
133                 );
134                 if (! dbm::is_result($r)) {
135                         notice( t('Profile not found.') . EOL);
136                         killme();
137                         return;
138                 }
139
140                 profile_load($a,$a->user['nickname'],$r[0]['id']);
141         }
142
143
144
145 }
146
147 function profile_clean_keywords($keywords) {
148         $keywords = str_replace(","," ",$keywords);
149         $keywords = explode(" ", $keywords);
150
151         $cleaned = array();
152         foreach ($keywords as $keyword) {
153                 $keyword = trim(strtolower($keyword));
154                 $keyword = trim($keyword, "#");
155                 if ($keyword != "")
156                         $cleaned[] = $keyword;
157         }
158
159         $keywords = implode(", ", $cleaned);
160
161         return $keywords;
162 }
163
164 function profiles_post(App $a) {
165
166         if (! local_user()) {
167                 notice( t('Permission denied.') . EOL);
168                 return;
169         }
170
171         $namechanged = false;
172
173         call_hooks('profile_post', $_POST);
174
175         if (($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
176                 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
177                         intval($a->argv[1]),
178                         intval(local_user())
179                 );
180                 if (! count($orig)) {
181                         notice( t('Profile not found.') . EOL);
182                         return;
183                 }
184
185                 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
186
187                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
188
189                 $profile_name = notags(trim($_POST['profile_name']));
190                 if (! strlen($profile_name)) {
191                         notice( t('Profile Name is required.') . EOL);
192                         return;
193                 }
194
195                 $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated?
196
197                 $y = substr($dob,0,4);
198                 if ((! ctype_digit($y)) || ($y < 1900))
199                         $ignore_year = true;
200                 else
201                         $ignore_year = false;
202                 if ($dob != '0000-00-00') {
203                         if (strpos($dob,'0000-') === 0) {
204                                 $ignore_year = true;
205                                 $dob = substr($dob,5);
206                         }
207                         $dob = datetime_convert('UTC','UTC',(($ignore_year) ? '1900-' . $dob : $dob),(($ignore_year) ? 'm-d' : 'Y-m-d'));
208                         if ($ignore_year)
209                                 $dob = '0000-' . $dob;
210                 }
211
212                 $name = notags(trim($_POST['name']));
213
214                 if (! strlen($name)) {
215                         $name = '[No Name]';
216                 }
217
218                 if ($orig[0]['name'] != $name)
219                         $namechanged = true;
220
221
222
223                 $pdesc = notags(trim($_POST['pdesc']));
224                 $gender = notags(trim($_POST['gender']));
225                 $address = notags(trim($_POST['address']));
226                 $locality = notags(trim($_POST['locality']));
227                 $region = notags(trim($_POST['region']));
228                 $postal_code = notags(trim($_POST['postal_code']));
229                 $country_name = notags(trim($_POST['country_name']));
230                 $pub_keywords = profile_clean_keywords(notags(trim($_POST['pub_keywords'])));
231                 $prv_keywords = profile_clean_keywords(notags(trim($_POST['prv_keywords'])));
232                 $marital = notags(trim($_POST['marital']));
233                 $howlong = notags(trim($_POST['howlong']));
234
235                 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
236
237                 if (! strlen($howlong)) {
238                         $howlong = NULL_DATE;
239                 } else {
240                         $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
241                 }
242                 // linkify the relationship target if applicable
243
244                 $withchanged = false;
245
246                 if (strlen($with)) {
247                         if ($with != strip_tags($orig[0]['with'])) {
248                                 $withchanged = true;
249                                 $prf = '';
250                                 $lookup = $with;
251                                 if (strpos($lookup,'@') === 0) {
252                                         $lookup = substr($lookup,1);
253                                 }
254                                 $lookup = str_replace('_',' ', $lookup);
255                                 if (strpos($lookup,'@') || (strpos($lookup,'http://'))) {
256                                         $newname = $lookup;
257                                         /// @TODO Maybe kill those error/debugging-surpressing @ characters
258                                         $links = @Probe::lrdd($lookup);
259                                         if (count($links)) {
260                                                 foreach ($links as $link) {
261                                                         if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
262                                                                 $prf = $link['@attributes']['href'];
263                                                         }
264                                                 }
265                                         }
266                                 } else {
267                                         $newname = $lookup;
268 /*                                      if (strstr($lookup,' ')) {
269                                                 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
270                                                         dbesc($newname),
271                                                         intval(local_user())
272                                                 );
273                                         } else {
274                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
275                                                         dbesc($lookup),
276                                                         intval(local_user())
277                                                 );
278                                         }*/
279
280                                         $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
281                                                 dbesc($newname),
282                                                 intval(local_user())
283                                         );
284                                         if (! $r) {
285                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
286                                                         dbesc($lookup),
287                                                         intval(local_user())
288                                                 );
289                                         }
290                                         if (dbm::is_result($r)) {
291                                                 $prf = $r[0]['url'];
292                                                 $newname = $r[0]['name'];
293                                         }
294                                 }
295
296                                 if ($prf) {
297                                         $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname        . '</a>', $with);
298                                         if (strpos($with,'@') === 0)
299                                                 $with = substr($with,1);
300                                 }
301                         }
302                         else
303                                 $with = $orig[0]['with'];
304                 }
305
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                 set_pconfig(local_user(),'system','detailled_profile', (($_POST['detailled_profile'] == 1) ? 1: 0));
334
335                 $changes = array();
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 = formatted_location(array("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(get_config('system','directory'))) {
508                                 proc_run(PRIORITY_LOW, "include/directory.php", $url);
509                         }
510
511                         require_once('include/profile_update.php');
512                         profile_change();
513
514                         // Update the global contact for the user
515                         update_gcontact_for_user(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         if ($a->user['hidewall'] || get_config('system','block_public'))
528                 return;
529
530         if (! get_pconfig(local_user(),'system','post_profilechange'))
531                 return;
532
533         require_once('include/items.php');
534
535         $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
536                 intval(local_user())
537         );
538
539         if (! count($self))
540                 return;
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                 $z ++;
572                 $changes .= $ch;
573         }
574
575         $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
576
577         if ($t == 1 && strlen($value)) {
578                 $message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value);
579                 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
580         }
581         else
582                 $message =      sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
583
584
585         $arr['body'] = $message;
586
587         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
588         . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
589         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
590         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
591         $arr['object'] .= '</link></object>' . "\n";
592         $arr['last-child'] = 1;
593
594         $arr['allow_cid'] = $a->user['allow_cid'];
595         $arr['allow_gid'] = $a->user['allow_gid'];
596         $arr['deny_cid']  = $a->user['deny_cid'];
597         $arr['deny_gid']  = $a->user['deny_gid'];
598
599         $i = item_store($arr);
600         if ($i) {
601                 proc_run(PRIORITY_HIGH, "include/notifier.php", "activity", $i);
602         }
603 }
604
605
606 function profiles_content(App $a) {
607
608         if (! local_user()) {
609                 notice( t('Permission denied.') . EOL);
610                 return;
611         }
612
613         $o = '';
614
615         if (($a->argc > 1) && (intval($a->argv[1]))) {
616                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
617                         intval($a->argv[1]),
618                         intval(local_user())
619                 );
620                 if (! dbm::is_result($r)) {
621                         notice( t('Profile not found.') . EOL);
622                         return;
623                 }
624
625                 require_once('include/profile_selectors.php');
626
627
628                 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
629                         '$baseurl' => App::get_baseurl(true),
630                 ));
631                 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
632                         '$baseurl' => App::get_baseurl(true),
633                 ));
634
635                 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
636                 $hide_friends = replace_macros($opt_tpl,array(
637                         '$yesno' => array(
638                                 'hide-friends', //Name
639                                 t('Hide contacts and friends:'), //Label
640                                 !!$r[0]['hide-friends'], //Value
641                                 '', //Help string
642                                 array(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                                         array(PAGE_COMMUNITY, PAGE_PRVGROUP)));
653
654                 $detailled_profile = (get_pconfig(local_user(),'system','detailled_profile') AND $personal_account);
655
656                 $f = get_config('system','birthday_input_format');
657                 if (! $f)
658                         $f = 'ymd';
659
660                 $is_default = (($r[0]['is-default']) ? 1 : 0);
661                 $tpl = get_markup_template("profile_edit.tpl");
662                 $o .= replace_macros($tpl,array(
663                         '$personal_account' => $personal_account,
664                         '$detailled_profile' => $detailled_profile,
665
666                         '$details' => array(
667                                 'detailled_profile', //Name
668                                 t('Show more profile fields:'), //Label
669                                 $detailled_profile, //Value
670                                 '', //Help string
671                                 array(t('No'),t('Yes')) //Off - On strings
672                         ),
673
674                         '$multi_profiles'               => feature_enabled(local_user(),'multi_profiles'),
675                         '$form_security_token'          => get_form_security_token("profile_edit"),
676                         '$form_security_token_photo'    => get_form_security_token("profile_photo"),
677                         '$profile_clone_link'           => ((feature_enabled(local_user(),'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone") : ""),
678                         '$profile_drop_link'            => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
679
680                         '$profile_action' => t('Profile Actions'),
681                         '$banner'       => t('Edit Profile Details'),
682                         '$submit'       => t('Submit'),
683                         '$profpic'      => t('Change Profile Photo'),
684                         '$viewprof'     => t('View this profile'),
685                         '$editvis'      => t('Edit visibility'),
686                         '$cr_prof'      => t('Create a new profile using these settings'),
687                         '$cl_prof'      => t('Clone this profile'),
688                         '$del_prof'     => t('Delete this profile'),
689
690                         '$lbl_basic_section' => t('Basic information'),
691                         '$lbl_picture_section' => t('Profile picture'),
692                         '$lbl_location_section' => t('Location'),
693                         '$lbl_preferences_section' => t('Preferences'),
694                         '$lbl_status_section' => t('Status information'),
695                         '$lbl_about_section' => t('Additional information'),
696                         '$lbl_interests_section' => t('Interests'),
697                         '$lbl_personal_section' => t('Personal'),
698                         '$lbl_relation_section' => t('Relation'),
699                         '$lbl_miscellaneous_section' => t('Miscellaneous'),
700
701                         '$lbl_profile_photo' => t('Upload Profile Photo'),
702                         '$lbl_gender' => t('Your Gender:'),
703                         '$lbl_marital' => t('<span class="heart">&hearts;</span> Marital Status:'),
704                         '$lbl_sexual' => t('Sexual Preference:'),
705                         '$lbl_ex2' => t('Example: fishing photography software'),
706
707                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
708                         '$baseurl' => App::get_baseurl(true),
709                         '$profile_id' => $r[0]['id'],
710                         '$profile_name' => array('profile_name', t('Profile Name:'), $r[0]['profile-name'], t('Required'), '*'),
711                         '$is_default'   => $is_default,
712                         '$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>' : ""),
713                         '$name' => array('name', t('Your Full Name:'), $r[0]['name']),
714                         '$pdesc' => array('pdesc', t('Title/Description:'), $r[0]['pdesc']),
715                         '$dob' => dob($r[0]['dob']),
716                         '$hide_friends' => $hide_friends,
717                         '$address' => array('address', t('Street Address:'), $r[0]['address']),
718                         '$locality' => array('locality', t('Locality/City:'), $r[0]['locality']),
719                         '$region' => array('region', t('Region/State:'), $r[0]['region']),
720                         '$postal_code' => array('postal_code', t('Postal/Zip Code:'), $r[0]['postal-code']),
721                         '$country_name' => array('country_name', t('Country:'), $r[0]['country-name']),
722                         '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
723                         '$gender' => gender_selector($r[0]['gender']),
724                         '$marital' => marital_selector($r[0]['marital']),
725                         '$with' => array('with', t("Who: \x28if applicable\x29"), strip_tags($r[0]['with']), t('Examples: cathy123, Cathy Williams, cathy@example.com')),
726                         '$howlong' => array('howlong', t('Since [date]:'), ($r[0]['howlong'] <= NULL_DATE ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong']))),
727                         '$sexual' => sexpref_selector($r[0]['sexual']),
728                         '$about' => array('about', t('Tell us about yourself...'), $r[0]['about']),
729                         '$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.")),
730                         '$homepage' => array('homepage', t('Homepage URL:'), $r[0]['homepage']),
731                         '$hometown' => array('hometown', t('Hometown:'), $r[0]['hometown']),
732                         '$politic' => array('politic', t('Political Views:'), $r[0]['politic']),
733                         '$religion' => array('religion', t('Religious Views:'), $r[0]['religion']),
734                         '$pub_keywords' => array('pub_keywords', t('Public Keywords:'), $r[0]['pub_keywords'], t("\x28Used for suggesting potential friends, can be seen by others\x29")),
735                         '$prv_keywords' => array('prv_keywords', t('Private Keywords:'), $r[0]['prv_keywords'], t("\x28Used for searching profiles, never shown to others\x29")),
736                         '$likes' => array('likes', t('Likes:'), $r[0]['likes']),
737                         '$dislikes' => array('dislikes', t('Dislikes:'), $r[0]['dislikes']),
738                         '$music' => array('music', t('Musical interests'), $r[0]['music']),
739                         '$book' => array('book', t('Books, literature'), $r[0]['book']),
740                         '$tv' => array('tv', t('Television'), $r[0]['tv']),
741                         '$film' => array('film', t('Film/dance/culture/entertainment'), $r[0]['film']),
742                         '$interest' => array('interest', t('Hobbies/Interests'), $r[0]['interest']),
743                         '$romance' => array('romance',t('Love/romance'), $r[0]['romance']),
744                         '$work' => array('work', t('Work/employment'), $r[0]['work']),
745                         '$education' => array('education', t('School/education'), $r[0]['education']),
746                         '$contact' => array('contact', t('Contact information and Social Networks'), $r[0]['contact']),
747                 ));
748
749                 $arr = array('profile' => $r[0], 'entry' => $o);
750                 call_hooks('profile_edit', $arr);
751
752                 return $o;
753         }
754
755         //Profiles list.
756         else {
757
758                 //If we don't support multi profiles, don't display this list.
759                 if (!feature_enabled(local_user(),'multi_profiles')){
760                         $r = q(
761                                 "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
762                                 local_user()
763                         );
764                         if (dbm::is_result($r)){
765                                 //Go to the default profile.
766                                 goaway('profiles/'.$r[0]['id']);
767                         }
768                 }
769
770                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
771                         local_user());
772                 if (dbm::is_result($r)) {
773
774                         $tpl = get_markup_template('profile_entry.tpl');
775
776                         $profiles = '';
777                         foreach ($r as $rr) {
778                                 $profiles .= replace_macros($tpl, array(
779                                         '$photo'        => $a->remove_baseurl($rr['thumb']),
780                                         '$id'           => $rr['id'],
781                                         '$alt'          => t('Profile Image'),
782                                         '$profile_name' => $rr['profile-name'],
783                                         '$visible'      => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
784                                                 : '<a href="'.'profperm/'.$rr['id'].'" />' . t('Edit visibility') . '</a>')
785                                 ));
786                         }
787
788                         $tpl_header = get_markup_template('profile_listing_header.tpl');
789                         $o .= replace_macros($tpl_header,array(
790                                 '$header'      => t('Edit/Manage Profiles'),
791                                 '$chg_photo'   => t('Change profile photo'),
792                                 '$cr_new'      => t('Create New Profile'),
793                                 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new"),
794                                 '$profiles'    => $profiles
795                         ));
796                 }
797                 return $o;
798         }
799
800 }