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