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