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