]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
a9da5454cf787ae4674b77d4ecc96defaa20e91d
[friendica.git] / mod / profiles.php
1 <?php
2
3
4 function profiles_post(&$a) {
5
6         if(! local_user()) {
7                 notice( t('Permission denied.') . EOL);
8                 return;
9         }
10
11         $namechanged = false;
12
13         call_hooks('profile_post', $_POST);
14
15         if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
16                 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
17                         intval($a->argv[1]),
18                         intval(local_user())
19                 );
20                 if(! count($orig)) {
21                         notice( t('Profile not found.') . EOL);
22                         return;
23                 }
24                 
25                 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
26                 
27                 $is_default = (($orig[0]['is-default']) ? 1 : 0);
28
29                 $profile_name = notags(trim($_POST['profile_name']));
30                 if(! strlen($profile_name)) {
31                         notify( t('Profile Name is required.') . EOL);
32                         return;
33                 }
34         
35                 $year = intval($_POST['year']);
36                 if($year < 1900 || $year > 2100 || $year < 0)
37                         $year = 0;
38                 $month = intval($_POST['month']);
39                         if(($month > 12) || ($month < 0))
40                                 $month = 0;
41                 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
42                 $day = intval($_POST['day']);
43                         if(($day > $mtab[$month]) || ($day < 0))
44                                 $day = 0;
45                 $dob = '0000-00-00';
46                 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
47
48                         
49                 $name = notags(trim($_POST['name']));
50
51                 if($orig[0]['name'] != $name)
52                         $namechanged = true;
53
54
55                 $pdesc = notags(trim($_POST['pdesc']));
56                 $gender = notags(trim($_POST['gender']));
57                 $address = notags(trim($_POST['address']));
58                 $locality = notags(trim($_POST['locality']));
59                 $region = notags(trim($_POST['region']));
60                 $postal_code = notags(trim($_POST['postal_code']));
61                 $country_name = notags(trim($_POST['country_name']));
62                 $pub_keywords = notags(trim($_POST['pub_keywords']));
63                 $prv_keywords = notags(trim($_POST['prv_keywords']));
64                 $marital = notags(trim($_POST['marital']));
65                 $howlong = notags(trim($_POST['howlong']));
66
67                 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
68
69                 if(! strlen($howlong))
70                         $howlong = '0000-00-00 00:00:00';
71                 else
72                         $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
73  
74                 // linkify the relationship target if applicable
75
76                 $withchanged = false;
77
78                 if(strlen($with)) {
79                         if($with != strip_tags($orig[0]['with'])) {
80                                 $withchanged = true;
81                                 $prf = '';
82                                 $lookup = $with;
83                                 if(strpos($lookup,'@') === 0)
84                                         $lookup = substr($lookup,1);
85                                 $lookup = str_replace('_',' ', $lookup);
86                                 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
87                                         $newname = $lookup;
88                                         $links = @lrdd($lookup);
89                                         if(count($links)) {
90                                                 foreach($links as $link) {
91                                                         if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
92                                         $prf = $link['@attributes']['href'];
93                                                         }
94                                                 }
95                                         }
96                                 }
97                                 else {
98                                         $newname = $lookup;
99                                         if(strstr($lookup,' ')) {
100                                                 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
101                                                         dbesc($newname),
102                                                         intval(local_user())
103                                                 );
104                                         }
105                                         else {
106                                                 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
107                                                         dbesc($lookup),
108                                                         intval(local_user())
109                                                 );
110                                         }
111                                         if(count($r)) {
112                                                 $prf = $r[0]['url'];
113                                                 $newname = $r[0]['name'];
114                                         }
115                                 }
116         
117                                 if($prf) {
118                                         $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname        . '</a>', $with);
119                                         if(strpos($with,'@') === 0)
120                                                 $with = substr($with,1);
121                                 }
122                         }
123                         else
124                                 $with = $orig[0]['with'];
125                 }
126
127                 $sexual = notags(trim($_POST['sexual']));
128                 $homepage = notags(trim($_POST['homepage']));
129                 $hometown = notags(trim($_POST['hometown']));
130                 $politic = notags(trim($_POST['politic']));
131                 $religion = notags(trim($_POST['religion']));
132
133                 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
134                 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
135                 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
136                 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
137                 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
138                 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
139                 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
140                 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
141                 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
142                 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
143
144                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
145
146
147
148                 $changes = array();
149                 $value = '';
150                 if($is_default) {
151                         if($marital != $orig[0]['marital']) {
152                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . t('Marital Status');
153                                 $value = $marital;
154                         }
155                         if($withchanged) {
156                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . t('Romantic Partner');
157                                 $value = strip_tags($with);
158                         }                                                       
159                         if($work != $orig[0]['work']) {
160                                 $changes[] = t('Work/Employment');
161                         }
162                         if($religion != $orig[0]['religion']) {
163                                 $changes[] = t('Religion');
164                                 $value = $religion;
165                         }
166                         if($politic != $orig[0]['politic']) {
167                                 $changes[] = t('Political Views');
168                                 $value = $politic;
169                         }
170                         if($gender != $orig[0]['gender']) {
171                                 $changes[] = t('Gender');
172                                 $value = $gender;
173                         }
174                         if($sexual != $orig[0]['sexual']) {
175                                 $changes[] = t('Sexual Preference');
176                                 $value = $sexual;
177                         }
178                         if($homepage != $orig[0]['homepage']) {
179                                 $changes[] = t('Homepage');
180                                 $value = $homepage;
181                         }
182                         if($interest != $orig[0]['interest']) {
183                                 $changes[] = t('Interests');
184                                 $value = $interest;
185                         }
186                         if($address != $orig[0]['address']) {
187                                 $changes[] = t('Address');
188                                 // New address not sent in notifications, potential privacy issues
189                                 // in case this leaks to unintended recipients. Yes, it's in the public
190                                 // profile but that doesn't mean we have to broadcast it to everybody.
191                         }
192                         if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
193                                 || $country_name != $orig[0]['country-name']) {
194                                 $changes[] = t('Location');
195                                 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
196                                 $comma2 = (($region && $country_name) ? ', ' : '');
197                                 $value = $locality . $comma1 . $region . $comma2 . $country_name;
198                         }
199
200                         profile_activity($changes,$value);
201
202                 }                       
203                         
204                 $r = q("UPDATE `profile` 
205                         SET `profile-name` = '%s',
206                         `name` = '%s',
207                         `pdesc` = '%s',
208                         `gender` = '%s',
209                         `dob` = '%s',
210                         `address` = '%s',
211                         `locality` = '%s',
212                         `region` = '%s',
213                         `postal-code` = '%s',
214                         `country-name` = '%s',
215                         `marital` = '%s',
216                         `with` = '%s',
217                         `howlong` = '%s',
218                         `sexual` = '%s',
219                         `homepage` = '%s',
220                         `hometown` = '%s',
221                         `politic` = '%s',
222                         `religion` = '%s',
223                         `pub_keywords` = '%s',
224                         `prv_keywords` = '%s',
225                         `about` = '%s',
226                         `interest` = '%s',
227                         `contact` = '%s',
228                         `music` = '%s',
229                         `book` = '%s',
230                         `tv` = '%s',
231                         `film` = '%s',
232                         `romance` = '%s',
233                         `work` = '%s',
234                         `education` = '%s',
235                         `hide-friends` = %d
236                         WHERE `id` = %d AND `uid` = %d LIMIT 1",
237                         dbesc($profile_name),
238                         dbesc($name),
239                         dbesc($pdesc),
240                         dbesc($gender),
241                         dbesc($dob),
242                         dbesc($address),
243                         dbesc($locality),
244                         dbesc($region),
245                         dbesc($postal_code),
246                         dbesc($country_name),
247                         dbesc($marital),
248                         dbesc($with),
249                         dbesc($howlong),
250                         dbesc($sexual),
251                         dbesc($homepage),
252                         dbesc($hometown),
253                         dbesc($politic),
254                         dbesc($religion),
255                         dbesc($pub_keywords),
256                         dbesc($prv_keywords),
257                         dbesc($about),
258                         dbesc($interest),
259                         dbesc($contact),
260                         dbesc($music),
261                         dbesc($book),
262                         dbesc($tv),
263                         dbesc($film),
264                         dbesc($romance),
265                         dbesc($work),
266                         dbesc($education),
267                         intval($hide_friends),
268                         intval($a->argv[1]),
269                         intval(local_user())
270                 );
271
272                 if($r)
273                         info( t('Profile updated.') . EOL);
274
275
276                 if($namechanged && $is_default) {
277                         $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
278                                 dbesc(datetime_convert()),
279                                 intval(local_user())
280                         );
281                 }
282
283                 if($is_default) {
284                         // Update global directory in background
285                         $url = $_SESSION['my_url'];
286                         if($url && strlen(get_config('system','directory_submit_url')))
287                                 proc_run('php',"include/directory.php","$url");
288
289                         require_once('include/profile_update.php');
290                         profile_change();
291                 }
292         }
293 }
294
295
296 function profile_activity($changed, $value) {
297         $a = get_app();
298
299         if(! local_user() || ! is_array($changed) || ! count($changed))
300                 return;
301
302         if($a->user['hidewall'] || get_config('system','block_public'))
303                 return;
304
305         if(! get_pconfig(local_user(),'system','post_profilechange'))
306                 return;
307
308         require_once('include/items.php');
309
310         $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
311                 intval(local_user())
312         );
313
314         if(! count($self))
315                 return;
316
317         $arr = array();
318         $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user()); 
319         $arr['uid'] = local_user();
320         $arr['contact-id'] = $self[0]['id'];
321         $arr['wall'] = 1;
322         $arr['type'] = 'wall';
323         $arr['gravity'] = 0;
324         $arr['origin'] = 1;
325         $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
326         $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
327         $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
328         $arr['verb'] = ACTIVITY_UPDATE;
329         $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
330                                 
331         $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
332
333
334         $changes = '';
335         $t = count($changed);
336         $z = 0;
337         foreach($changed as $ch) {
338                 if(strlen($changes)) {
339                         if ($z == ($t - 1))
340                                 $changes .= t(' and ');
341                         else
342                                 $changes .= ', ';
343                 }
344                 $z ++;
345                 $changes .= $ch;
346         }
347
348         $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';      
349
350         if($t == 1 && strlen($value)) {
351                 $message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value);
352                 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
353         }
354         else
355                 $message =      sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
356  
357
358         $arr['body'] = $message;  
359
360         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
361         . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
362         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
363         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
364         $arr['object'] .= '</link></object>' . "\n";
365         $arr['last-child'] = 1;
366
367         $arr['allow_cid'] = $a->user['allow_cid'];
368         $arr['allow_gid'] = $a->user['allow_gid'];
369         $arr['deny_cid']  = $a->user['deny_cid'];
370         $arr['deny_gid']  = $a->user['deny_gid'];
371
372         $i = item_store($arr);
373         if($i)
374                 proc_run('php',"include/notifier.php","activity","$i");
375
376 }
377
378
379 function profiles_content(&$a) {
380
381         $o = '';
382         nav_set_selected('profiles');
383
384         if(! local_user()) {
385                 notice( t('Permission denied.') . EOL);
386                 return;
387         }
388
389         if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
390                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
391                         intval($a->argv[2]),
392                         intval(local_user())
393                 );
394                 if(! count($r)) {
395                         notice( t('Profile not found.') . EOL);
396                         goaway($a->get_baseurl(true) . '/profiles');
397                         return; // NOTREACHED
398                 }
399                 
400                 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
401
402                 // move every contact using this profile as their default to the user default
403
404                 $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 ",
405                         intval(local_user()),
406                         intval($a->argv[2]),
407                         intval(local_user())
408                 );
409                 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
410                         intval($a->argv[2]),
411                         intval(local_user())
412                 );
413                 if($r)
414                         info( t('Profile deleted.') . EOL);
415
416                 goaway($a->get_baseurl(true) . '/profiles');
417                 return; // NOTREACHED
418         }
419
420
421
422
423
424         if(($a->argc > 1) && ($a->argv[1] === 'new')) {
425                 
426                 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
427
428                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
429                         intval(local_user()));
430                 $num_profiles = count($r0);
431
432                 $name = t('Profile-') . ($num_profiles + 1);
433
434                 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
435                         intval(local_user()));
436                 
437                 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
438                         VALUES ( %d, '%s', '%s', '%s', '%s' )",
439                         intval(local_user()),
440                         dbesc($name),
441                         dbesc($r1[0]['name']),
442                         dbesc($r1[0]['photo']),
443                         dbesc($r1[0]['thumb'])
444                 );
445
446                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
447                         intval(local_user()),
448                         dbesc($name)
449                 );
450
451                 info( t('New profile created.') . EOL);
452                 if(count($r3) == 1)
453                         goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
454                 
455                 goaway($a->get_baseurl(true) . '/profiles');
456         } 
457
458         if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
459                 
460                 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
461
462                 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
463                         intval(local_user()));
464                 $num_profiles = count($r0);
465
466                 $name = t('Profile-') . ($num_profiles + 1);
467                 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
468                         intval(local_user()),
469                         intval($a->argv[2])
470                 );
471                 if(! count($r1)) {
472                         notice( t('Profile unavailable to clone.') . EOL);
473                         return;
474                 }
475                 unset($r1[0]['id']);
476                 $r1[0]['is-default'] = 0;
477                 $r1[0]['publish'] = 0;  
478                 $r1[0]['net-publish'] = 0;      
479                 $r1[0]['profile-name'] = dbesc($name);
480
481                 dbesc_array($r1[0]);
482
483                 $r2 = dbq("INSERT INTO `profile` (`" 
484                         . implode("`, `", array_keys($r1[0])) 
485                         . "`) VALUES ('" 
486                         . implode("', '", array_values($r1[0])) 
487                         . "')" );
488
489                 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
490                         intval(local_user()),
491                         dbesc($name)
492                 );
493                 info( t('New profile created.') . EOL);
494                 if(count($r3) == 1)
495                         goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
496                 
497                 goaway($a->get_baseurl(true) . '/profiles');
498                 
499                 return; // NOTREACHED
500         }
501
502
503         if(($a->argc > 1) && (intval($a->argv[1]))) {
504                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
505                         intval($a->argv[1]),
506                         intval(local_user())
507                 );
508                 if(! count($r)) {
509                         notice( t('Profile not found.') . EOL);
510                         return;
511                 }
512
513                 profile_load($a,$a->user['nickname'],$r[0]['id']);
514
515                 require_once('include/profile_selectors.php');
516
517
518                 $editselect = 'textareas';
519                 if(intval(get_pconfig(local_user(),'system','plaintext')))
520                         $editselect = 'none';
521
522                 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
523                         '$baseurl' => $a->get_baseurl(true),
524                         '$editselect' => $editselect,
525                 ));
526
527
528                 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
529                 $hide_friends = replace_macros($opt_tpl,array(
530                         '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
531                         '$yes_str' => t('Yes'),
532                         '$no_str' => t('No'),
533                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
534                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
535                 ));
536
537                 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
538
539
540
541
542
543                 $f = get_config('system','birthday_input_format');
544                 if(! $f)
545                         $f = 'ymd';
546
547                 $is_default = (($r[0]['is-default']) ? 1 : 0);
548                 $tpl = get_markup_template("profile_edit.tpl");
549                 $o .= replace_macros($tpl,array(
550                         '$form_security_token' => get_form_security_token("profile_edit"),
551                         '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
552                         '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
553                         '$banner' => t('Edit Profile Details'),
554                         '$submit' => t('Submit'),
555                         '$viewprof' => t('View this profile'),
556                         '$cr_prof' => t('Create a new profile using these settings'),
557                         '$cl_prof' => t('Clone this profile'),
558                         '$del_prof' => t('Delete this profile'),
559                         '$lbl_profname' => t('Profile Name:'),
560                         '$lbl_fullname' => t('Your Full Name:'),
561                         '$lbl_title' => t('Title/Description:'),
562                         '$lbl_gender' => t('Your Gender:'),
563                         '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
564                         '$lbl_address' => t('Street Address:'),
565                         '$lbl_city' => t('Locality/City:'),
566                         '$lbl_zip' => t('Postal/Zip Code:'),
567                         '$lbl_country' => t('Country:'),
568                         '$lbl_region' => t('Region/State:'),
569                         '$lbl_marital' => t('<span class="heart">&hearts;</span> Marital Status:'),
570                         '$lbl_with' => t("Who: \x28if applicable\x29"),
571                         '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
572                         '$lbl_howlong' => t('Since [date]:'),
573                         '$lbl_sexual' => t('Sexual Preference:'),
574                         '$lbl_homepage' => t('Homepage URL:'),
575                         '$lbl_hometown' => t('Hometown:'),
576                         '$lbl_politic' => t('Political Views:'),
577                         '$lbl_religion' => t('Religious Views:'),
578                         '$lbl_pubkey' => t('Public Keywords:'),
579                         '$lbl_prvkey' => t('Private Keywords:'),
580                         '$lbl_ex2' => t('Example: fishing photography software'),
581                         '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
582                         '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
583                         '$lbl_about' => t('Tell us about yourself...'),
584                         '$lbl_hobbies' => t('Hobbies/Interests'),
585                         '$lbl_social' => t('Contact information and Social Networks'),
586                         '$lbl_music' => t('Musical interests'),
587                         '$lbl_book' => t('Books, literature'),
588                         '$lbl_tv' => t('Television'),
589                         '$lbl_film' => t('Film/dance/culture/entertainment'),
590                         '$lbl_love' => t('Love/romance'),
591                         '$lbl_work' => t('Work/employment'),
592                         '$lbl_school' => t('School/education'),
593                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
594                         '$baseurl' => $a->get_baseurl(true),
595                         '$profile_id' => $r[0]['id'],
596                         '$profile_name' => $r[0]['profile-name'],
597                         '$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>' : ""),
598                         '$name' => $r[0]['name'],
599                         '$pdesc' => $r[0]['pdesc'],
600                         '$dob' => dob($r[0]['dob']),
601                         '$hide_friends' => $hide_friends,
602                         '$address' => $r[0]['address'],
603                         '$locality' => $r[0]['locality'],
604                         '$region' => $r[0]['region'],
605                         '$postal_code' => $r[0]['postal-code'],
606                         '$country_name' => $r[0]['country-name'],
607                         '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
608                         '$gender' => gender_selector($r[0]['gender']),
609                         '$marital' => marital_selector($r[0]['marital']),
610                         '$with' => strip_tags($r[0]['with']),
611                         '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
612                         '$sexual' => sexpref_selector($r[0]['sexual']),
613                         '$about' => $r[0]['about'],
614                         '$homepage' => $r[0]['homepage'],
615                         '$hometown' => $r[0]['hometown'],
616                         '$politic' => $r[0]['politic'],
617                         '$religion' => $r[0]['religion'],
618                         '$pub_keywords' => $r[0]['pub_keywords'],
619                         '$prv_keywords' => $r[0]['prv_keywords'],
620                         '$music' => $r[0]['music'],
621                         '$book' => $r[0]['book'],
622                         '$tv' => $r[0]['tv'],
623                         '$film' => $r[0]['film'],
624                         '$interest' => $r[0]['interest'],
625                         '$romance' => $r[0]['romance'],
626                         '$work' => $r[0]['work'],
627                         '$education' => $r[0]['education'],
628                         '$contact' => $r[0]['contact']
629                 ));
630
631                 $arr = array('profile' => $r[0], 'entry' => $o);
632                 call_hooks('profile_edit', $arr);
633
634                 return $o;
635         }
636         else {
637
638                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
639                         local_user());
640                 if(count($r)) {
641
642                         $tpl_header = get_markup_template('profile_listing_header.tpl');
643                         $o .= replace_macros($tpl_header,array(
644                                 '$header' => t('Edit/Manage Profiles'),
645                                 '$chg_photo' => t('Change profile photo'),
646                                 '$cr_new' => t('Create New Profile'),
647                                 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
648                         ));
649
650
651                         $tpl = get_markup_template('profile_entry.tpl');
652
653                         foreach($r as $rr) {
654                                 $o .= replace_macros($tpl, array(
655                                         '$photo' => $a->get_cached_avatar_image($rr['thumb']),
656                                         '$id' => $rr['id'],
657                                         '$alt' => t('Profile Image'),
658                                         '$profile_name' => $rr['profile-name'],
659                                         '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>' 
660                                                 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')
661                                 ));
662                         }
663                 }
664                 return $o;
665         }
666
667 }