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