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