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