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