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