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