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