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