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