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