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