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