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