]> git.mxchange.org Git - friendica.git/blob - mod/profiles.php
Merge pull request #1107 from annando/1409-issue-964
[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",
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 }
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                         notice( 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                 if ((strpos($homepage, 'http') !== 0) && (strlen($homepage))) {
294                     // neither http nor https in URL, add them
295                     $homepage = 'http://'.$homepage;
296                 }
297                 $hometown = notags(trim($_POST['hometown']));
298                 $politic = notags(trim($_POST['politic']));
299                 $religion = notags(trim($_POST['religion']));
300
301                 $likes = fix_mce_lf(escape_tags(trim($_POST['likes'])));
302                 $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes'])));
303
304                 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
305                 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
306                 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
307                 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
308                 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
309                 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
310                 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
311                 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
312                 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
313                 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
314
315                 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
316
317
318
319                 $changes = array();
320                 $value = '';
321                 if($is_default) {
322                         if($marital != $orig[0]['marital']) {
323                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . t('Marital Status');
324                                 $value = $marital;
325                         }
326                         if($withchanged) {
327                                 $changes[] = '[color=#ff0000]&hearts;[/color] ' . t('Romantic Partner');
328                                 $value = strip_tags($with);
329                         }
330                         if($likes != $orig[0]['likes']) {
331                                 $changes[] = t('Likes');
332                                 $value = $likes;
333                         }
334                         if($dislikes != $orig[0]['dislikes']) {
335                                 $changes[] = t('Dislikes');
336                                 $value = $dislikes;
337                         }
338                         if($work != $orig[0]['work']) {
339                                 $changes[] = t('Work/Employment');
340                         }
341                         if($religion != $orig[0]['religion']) {
342                                 $changes[] = t('Religion');
343                                 $value = $religion;
344                         }
345                         if($politic != $orig[0]['politic']) {
346                                 $changes[] = t('Political Views');
347                                 $value = $politic;
348                         }
349                         if($gender != $orig[0]['gender']) {
350                                 $changes[] = t('Gender');
351                                 $value = $gender;
352                         }
353                         if($sexual != $orig[0]['sexual']) {
354                                 $changes[] = t('Sexual Preference');
355                                 $value = $sexual;
356                         }
357                         if($homepage != $orig[0]['homepage']) {
358                                 $changes[] = t('Homepage');
359                                 $value = $homepage;
360                         }
361                         if($interest != $orig[0]['interest']) {
362                                 $changes[] = t('Interests');
363                                 $value = $interest;
364                         }
365                         if($address != $orig[0]['address']) {
366                                 $changes[] = t('Address');
367                                 // New address not sent in notifications, potential privacy issues
368                                 // in case this leaks to unintended recipients. Yes, it's in the public
369                                 // profile but that doesn't mean we have to broadcast it to everybody.
370                         }
371                         if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
372                                 || $country_name != $orig[0]['country-name']) {
373                                 $changes[] = t('Location');
374                                 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
375                                 $comma2 = (($region && $country_name) ? ', ' : '');
376                                 $value = $locality . $comma1 . $region . $comma2 . $country_name;
377                         }
378
379                         profile_activity($changes,$value);
380
381                 }
382
383                 $r = q("UPDATE `profile`
384                         SET `profile-name` = '%s',
385                         `name` = '%s',
386                         `pdesc` = '%s',
387                         `gender` = '%s',
388                         `dob` = '%s',
389                         `address` = '%s',
390                         `locality` = '%s',
391                         `region` = '%s',
392                         `postal-code` = '%s',
393                         `country-name` = '%s',
394                         `marital` = '%s',
395                         `with` = '%s',
396                         `howlong` = '%s',
397                         `sexual` = '%s',
398                         `homepage` = '%s',
399                         `hometown` = '%s',
400                         `politic` = '%s',
401                         `religion` = '%s',
402                         `pub_keywords` = '%s',
403                         `prv_keywords` = '%s',
404                         `likes` = '%s',
405                         `dislikes` = '%s',
406                         `about` = '%s',
407                         `interest` = '%s',
408                         `contact` = '%s',
409                         `music` = '%s',
410                         `book` = '%s',
411                         `tv` = '%s',
412                         `film` = '%s',
413                         `romance` = '%s',
414                         `work` = '%s',
415                         `education` = '%s',
416                         `hide-friends` = %d
417                         WHERE `id` = %d AND `uid` = %d",
418                         dbesc($profile_name),
419                         dbesc($name),
420                         dbesc($pdesc),
421                         dbesc($gender),
422                         dbesc($dob),
423                         dbesc($address),
424                         dbesc($locality),
425                         dbesc($region),
426                         dbesc($postal_code),
427                         dbesc($country_name),
428                         dbesc($marital),
429                         dbesc($with),
430                         dbesc($howlong),
431                         dbesc($sexual),
432                         dbesc($homepage),
433                         dbesc($hometown),
434                         dbesc($politic),
435                         dbesc($religion),
436                         dbesc($pub_keywords),
437                         dbesc($prv_keywords),
438                         dbesc($likes),
439                         dbesc($dislikes),
440                         dbesc($about),
441                         dbesc($interest),
442                         dbesc($contact),
443                         dbesc($music),
444                         dbesc($book),
445                         dbesc($tv),
446                         dbesc($film),
447                         dbesc($romance),
448                         dbesc($work),
449                         dbesc($education),
450                         intval($hide_friends),
451                         intval($a->argv[1]),
452                         intval(local_user())
453                 );
454
455                 if($r)
456                         info( t('Profile updated.') . EOL);
457
458
459                 if($namechanged && $is_default) {
460                         $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d",
461                                 dbesc(datetime_convert()),
462                                 intval(local_user())
463                         );
464                         $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
465                                 dbesc($name),
466                                 intval(local_user())
467                         );
468                 }
469
470                 if($is_default) {
471                         // Update global directory in background
472                         $url = $_SESSION['my_url'];
473                         if($url && strlen(get_config('system','directory_submit_url')))
474                                 proc_run('php',"include/directory.php","$url");
475
476                         require_once('include/profile_update.php');
477                         profile_change();
478                 }
479         }
480 }
481
482
483 function profile_activity($changed, $value) {
484         $a = get_app();
485
486         if(! local_user() || ! is_array($changed) || ! count($changed))
487                 return;
488
489         if($a->user['hidewall'] || get_config('system','block_public'))
490                 return;
491
492         if(! get_pconfig(local_user(),'system','post_profilechange'))
493                 return;
494
495         require_once('include/items.php');
496
497         $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
498                 intval(local_user())
499         );
500
501         if(! count($self))
502                 return;
503
504         $arr = array();
505         $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user()); 
506         $arr['uid'] = local_user();
507         $arr['contact-id'] = $self[0]['id'];
508         $arr['wall'] = 1;
509         $arr['type'] = 'wall';
510         $arr['gravity'] = 0;
511         $arr['origin'] = 1;
512         $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
513         $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
514         $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
515         $arr['verb'] = ACTIVITY_UPDATE;
516         $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
517                                 
518         $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
519
520
521         $changes = '';
522         $t = count($changed);
523         $z = 0;
524         foreach($changed as $ch) {
525                 if(strlen($changes)) {
526                         if ($z == ($t - 1))
527                                 $changes .= t(' and ');
528                         else
529                                 $changes .= ', ';
530                 }
531                 $z ++;
532                 $changes .= $ch;
533         }
534
535         $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';      
536
537         if($t == 1 && strlen($value)) {
538                 $message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value);
539                 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
540         }
541         else
542                 $message =      sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
543  
544
545         $arr['body'] = $message;  
546
547         $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
548         . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
549         $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
550         $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
551         $arr['object'] .= '</link></object>' . "\n";
552         $arr['last-child'] = 1;
553
554         $arr['allow_cid'] = $a->user['allow_cid'];
555         $arr['allow_gid'] = $a->user['allow_gid'];
556         $arr['deny_cid']  = $a->user['deny_cid'];
557         $arr['deny_gid']  = $a->user['deny_gid'];
558
559         $i = item_store($arr);
560         if($i) {
561
562                 // give it a permanent link
563                 //q("update item set plink = '%s' where id = %d",
564                 //      dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
565                 //      intval($i)
566                 //);
567
568                 proc_run('php',"include/notifier.php","activity","$i");
569
570         }
571 }
572
573
574 function profiles_content(&$a) {
575
576         if(! local_user()) {
577                 notice( t('Permission denied.') . EOL);
578                 return;
579         }
580
581         $o = '';
582
583         if(($a->argc > 1) && (intval($a->argv[1]))) {
584                 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
585                         intval($a->argv[1]),
586                         intval(local_user())
587                 );
588                 if(! count($r)) {
589                         notice( t('Profile not found.') . EOL);
590                         return;
591                 }
592
593                 require_once('include/profile_selectors.php');
594
595
596 /*              $editselect = 'textareas';
597                 if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
598                         $editselect = 'none';*/
599                 $editselect = 'none';
600                 if( feature_enabled(local_user(),'richtext') )
601                         $editselect = 'textareas';
602
603                 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
604                         '$baseurl' => $a->get_baseurl(true),
605                         '$editselect' => $editselect,
606                 ));
607                 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
608                         '$baseurl' => $a->get_baseurl(true),
609                         '$editselect' => $editselect,
610                 ));
611
612
613                 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
614                 $hide_friends = replace_macros($opt_tpl,array(
615                         '$yesno' => array(
616                                 'hide-friends', //Name
617                                 t('Hide contacts and friends:'), //Label
618                                 !!$r[0]['hide-friends'], //Value
619                                 '', //Help string
620                                 array(t('No'),t('Yes')) //Off - On strings
621                         ),
622                         '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
623                         '$yes_str' => t('Yes'),
624                         '$no_str' => t('No'),
625                         '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
626                         '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
627                 ));
628
629
630
631
632                 $f = get_config('system','birthday_input_format');
633                 if(! $f)
634                         $f = 'ymd';
635
636                 $is_default = (($r[0]['is-default']) ? 1 : 0);
637                 $tpl = get_markup_template("profile_edit.tpl");
638                 $o .= replace_macros($tpl,array(
639                         '$multi_profiles' => feature_enabled(local_user(),'multi_profiles'),
640                         '$form_security_token' => get_form_security_token("profile_edit"),
641                         '$form_security_token_photo' => get_form_security_token("profile_photo"),
642                         '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
643                         '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
644                         '$banner' => t('Edit Profile Details'),
645                         '$submit' => t('Submit'),
646                         '$profpic' => t('Change Profile Photo'),
647                         '$viewprof' => t('View this profile'),
648                         '$cr_prof' => t('Create a new profile using these settings'),
649                         '$cl_prof' => t('Clone this profile'),
650                         '$del_prof' => t('Delete this profile'),
651                         '$lbl_basic_section' => t('Basic information'),
652                         '$lbl_picture_section' => t('Profile picture'),
653                         '$lbl_location_section' => t('Location'),
654                         '$lbl_preferences_section' => t('Preferences'),
655                         '$lbl_status_section' => t('Status information'),
656                         '$lbl_about_section' => t('Additional information'),
657                         '$lbl_interests_section' => t('Interests'),
658                         '$lbl_profile_photo' => t('Upload Profile Photo'),
659                         '$lbl_profname' => t('Profile Name:'),
660                         '$lbl_fullname' => t('Your Full Name:'),
661                         '$lbl_title' => t('Title/Description:'),
662                         '$lbl_gender' => t('Your Gender:'),
663                         '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
664                         '$lbl_address' => t('Street Address:'),
665                         '$lbl_city' => t('Locality/City:'),
666                         '$lbl_zip' => t('Postal/Zip Code:'),
667                         '$lbl_country' => t('Country:'),
668                         '$lbl_region' => t('Region/State:'),
669                         '$lbl_marital' => t('<span class="heart">&hearts;</span> Marital Status:'),
670                         '$lbl_with' => t("Who: \x28if applicable\x29"),
671                         '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
672                         '$lbl_howlong' => t('Since [date]:'),
673                         '$lbl_sexual' => t('Sexual Preference:'),
674                         '$lbl_homepage' => t('Homepage URL:'),
675                         '$lbl_hometown' => t('Hometown:'),
676                         '$lbl_politic' => t('Political Views:'),
677                         '$lbl_religion' => t('Religious Views:'),
678                         '$lbl_pubkey' => t('Public Keywords:'),
679                         '$lbl_prvkey' => t('Private Keywords:'),
680                         '$lbl_likes' => t('Likes:'),
681                         '$lbl_dislikes' => t('Dislikes:'),
682                         '$lbl_ex2' => t('Example: fishing photography software'),
683                         '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
684                         '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
685                         '$lbl_about' => t('Tell us about yourself...'),
686                         '$lbl_hobbies' => t('Hobbies/Interests'),
687                         '$lbl_social' => t('Contact information and Social Networks'),
688                         '$lbl_music' => t('Musical interests'),
689                         '$lbl_book' => t('Books, literature'),
690                         '$lbl_tv' => t('Television'),
691                         '$lbl_film' => t('Film/dance/culture/entertainment'),
692                         '$lbl_love' => t('Love/romance'),
693                         '$lbl_work' => t('Work/employment'),
694                         '$lbl_school' => t('School/education'),
695                         '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
696                         '$baseurl' => $a->get_baseurl(true),
697                         '$profile_id' => $r[0]['id'],
698                         '$profile_name' => $r[0]['profile-name'],
699                         '$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>' : ""),
700                         '$name' => $r[0]['name'],
701                         '$pdesc' => $r[0]['pdesc'],
702                         '$dob' => dob($r[0]['dob']),
703                         '$hide_friends' => $hide_friends,
704                         '$address' => $r[0]['address'],
705                         '$locality' => $r[0]['locality'],
706                         '$region' => $r[0]['region'],
707                         '$postal_code' => $r[0]['postal-code'],
708                         '$country_name' => $r[0]['country-name'],
709                         '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
710                         '$gender' => gender_selector($r[0]['gender']),
711                         '$marital' => marital_selector($r[0]['marital']),
712                         '$with' => strip_tags($r[0]['with']),
713                         '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
714                         '$sexual' => sexpref_selector($r[0]['sexual']),
715                         '$about' => $r[0]['about'],
716                         '$homepage' => $r[0]['homepage'],
717                         '$hometown' => $r[0]['hometown'],
718                         '$politic' => $r[0]['politic'],
719                         '$religion' => $r[0]['religion'],
720                         '$pub_keywords' => $r[0]['pub_keywords'],
721                         '$prv_keywords' => $r[0]['prv_keywords'],
722                         '$likes' => $r[0]['likes'],
723                         '$dislikes' => $r[0]['dislikes'],
724                         '$music' => $r[0]['music'],
725                         '$book' => $r[0]['book'],
726                         '$tv' => $r[0]['tv'],
727                         '$film' => $r[0]['film'],
728                         '$interest' => $r[0]['interest'],
729                         '$romance' => $r[0]['romance'],
730                         '$work' => $r[0]['work'],
731                         '$education' => $r[0]['education'],
732                         '$contact' => $r[0]['contact']
733                 ));
734
735                 $arr = array('profile' => $r[0], 'entry' => $o);
736                 call_hooks('profile_edit', $arr);
737
738                 return $o;
739         }
740         
741         //Profiles list.
742         else {
743                 
744                 //If we don't support multi profiles, don't display this list.
745                 if(!feature_enabled(local_user(),'multi_profiles')){
746                         $r = q(
747                                 "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
748                                 local_user()
749                         );
750                         if(count($r)){
751                                 //Go to the default profile.
752                                 goaway($a->get_baseurl(true) . '/profiles/'.$r[0]['id']);
753                         }
754                 }
755                 
756                 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
757                         local_user());
758                 if(count($r)) {
759                         
760                         $tpl_header = get_markup_template('profile_listing_header.tpl');
761                         $o .= replace_macros($tpl_header,array(
762                                 '$header' => t('Edit/Manage Profiles'),
763                                 '$chg_photo' => t('Change profile photo'),
764                                 '$cr_new' => t('Create New Profile'),
765                                 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
766                         ));
767                         
768                         
769                         $tpl = get_markup_template('profile_entry.tpl');
770                         
771                         foreach($r as $rr) {
772                                 $o .= replace_macros($tpl, array(
773                                         '$photo' => $a->get_cached_avatar_image($rr['thumb']),
774                                         '$id' => $rr['id'],
775                                         '$alt' => t('Profile Image'),
776                                         '$profile_name' => $rr['profile-name'],
777                                         '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>' 
778                                                 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')
779                                 ));
780                         }
781                 }
782                 return $o;
783         }
784
785 }