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