4 function profiles_post(&$a) {
7 notice( t('Permission denied.') . EOL);
13 call_hooks('profile_post', $_POST);
15 if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
16 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
21 notice( t('Profile not found.') . EOL);
25 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
27 $is_default = (($orig[0]['is-default']) ? 1 : 0);
29 $profile_name = notags(trim($_POST['profile_name']));
30 if(! strlen($profile_name)) {
31 notify( t('Profile Name is required.') . EOL);
35 $year = intval($_POST['year']);
36 if($year < 1900 || $year > 2100 || $year < 0)
38 $month = intval($_POST['month']);
39 if(($month > 12) || ($month < 0))
41 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
42 $day = intval($_POST['day']);
43 if(($day > $mtab[$month]) || ($day < 0))
46 // 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
53 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
56 $name = notags(trim($_POST['name']));
62 if($orig[0]['name'] != $name)
67 $pdesc = notags(trim($_POST['pdesc']));
68 $gender = notags(trim($_POST['gender']));
69 $address = notags(trim($_POST['address']));
70 $locality = notags(trim($_POST['locality']));
71 $region = notags(trim($_POST['region']));
72 $postal_code = notags(trim($_POST['postal_code']));
73 $country_name = notags(trim($_POST['country_name']));
74 $pub_keywords = notags(trim($_POST['pub_keywords']));
75 $prv_keywords = notags(trim($_POST['prv_keywords']));
76 $marital = notags(trim($_POST['marital']));
77 $howlong = notags(trim($_POST['howlong']));
79 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
81 if(! strlen($howlong))
82 $howlong = '0000-00-00 00:00:00';
84 $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
86 // linkify the relationship target if applicable
91 if($with != strip_tags($orig[0]['with'])) {
95 if(strpos($lookup,'@') === 0)
96 $lookup = substr($lookup,1);
97 $lookup = str_replace('_',' ', $lookup);
98 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
100 $links = @lrdd($lookup);
102 foreach($links as $link) {
103 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
104 $prf = $link['@attributes']['href'];
111 /* if(strstr($lookup,' ')) {
112 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
118 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
124 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
129 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
136 $newname = $r[0]['name'];
141 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
142 if(strpos($with,'@') === 0)
143 $with = substr($with,1);
147 $with = $orig[0]['with'];
150 $sexual = notags(trim($_POST['sexual']));
151 $homepage = notags(trim($_POST['homepage']));
152 $hometown = notags(trim($_POST['hometown']));
153 $politic = notags(trim($_POST['politic']));
154 $religion = notags(trim($_POST['religion']));
156 $likes = fix_mce_lf(escape_tags(trim($_POST['likes'])));
157 $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes'])));
159 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
160 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
161 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
162 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
163 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
164 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
165 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
166 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
167 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
168 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
170 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
177 if($marital != $orig[0]['marital']) {
178 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
182 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
183 $value = strip_tags($with);
185 if($likes != $orig[0]['likes']) {
186 $changes[] = t('Likes');
189 if($dislikes != $orig[0]['dislikes']) {
190 $changes[] = t('Dislikes');
193 if($work != $orig[0]['work']) {
194 $changes[] = t('Work/Employment');
196 if($religion != $orig[0]['religion']) {
197 $changes[] = t('Religion');
200 if($politic != $orig[0]['politic']) {
201 $changes[] = t('Political Views');
204 if($gender != $orig[0]['gender']) {
205 $changes[] = t('Gender');
208 if($sexual != $orig[0]['sexual']) {
209 $changes[] = t('Sexual Preference');
212 if($homepage != $orig[0]['homepage']) {
213 $changes[] = t('Homepage');
216 if($interest != $orig[0]['interest']) {
217 $changes[] = t('Interests');
220 if($address != $orig[0]['address']) {
221 $changes[] = t('Address');
222 // New address not sent in notifications, potential privacy issues
223 // in case this leaks to unintended recipients. Yes, it's in the public
224 // profile but that doesn't mean we have to broadcast it to everybody.
226 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
227 || $country_name != $orig[0]['country-name']) {
228 $changes[] = t('Location');
229 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
230 $comma2 = (($region && $country_name) ? ', ' : '');
231 $value = $locality . $comma1 . $region . $comma2 . $country_name;
234 profile_activity($changes,$value);
238 $r = q("UPDATE `profile`
239 SET `profile-name` = '%s',
247 `postal-code` = '%s',
248 `country-name` = '%s',
257 `pub_keywords` = '%s',
258 `prv_keywords` = '%s',
272 WHERE `id` = %d AND `uid` = %d LIMIT 1",
273 dbesc($profile_name),
282 dbesc($country_name),
291 dbesc($pub_keywords),
292 dbesc($prv_keywords),
305 intval($hide_friends),
311 info( t('Profile updated.') . EOL);
314 if($namechanged && $is_default) {
315 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
316 dbesc(datetime_convert()),
322 // Update global directory in background
323 $url = $_SESSION['my_url'];
324 if($url && strlen(get_config('system','directory_submit_url')))
325 proc_run('php',"include/directory.php","$url");
327 require_once('include/profile_update.php');
334 function profile_activity($changed, $value) {
337 if(! local_user() || ! is_array($changed) || ! count($changed))
340 if($a->user['hidewall'] || get_config('system','block_public'))
343 if(! get_pconfig(local_user(),'system','post_profilechange'))
346 require_once('include/items.php');
348 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
356 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
357 $arr['uid'] = local_user();
358 $arr['contact-id'] = $self[0]['id'];
360 $arr['type'] = 'wall';
363 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
364 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
365 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
366 $arr['verb'] = ACTIVITY_UPDATE;
367 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
369 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
373 $t = count($changed);
375 foreach($changed as $ch) {
376 if(strlen($changes)) {
378 $changes .= t(' and ');
386 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
388 if($t == 1 && strlen($value)) {
389 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
390 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
393 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
396 $arr['body'] = $message;
398 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
399 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
400 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
401 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
402 $arr['object'] .= '</link></object>' . "\n";
403 $arr['last-child'] = 1;
405 $arr['allow_cid'] = $a->user['allow_cid'];
406 $arr['allow_gid'] = $a->user['allow_gid'];
407 $arr['deny_cid'] = $a->user['deny_cid'];
408 $arr['deny_gid'] = $a->user['deny_gid'];
410 $i = item_store($arr);
413 // give it a permanent link
414 q("update item set plink = '%s' where id = %d limit 1",
415 dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
419 proc_run('php',"include/notifier.php","activity","$i");
425 function profiles_content(&$a) {
428 nav_set_selected('profiles');
431 notice( t('Permission denied.') . EOL);
435 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
436 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
441 notice( t('Profile not found.') . EOL);
442 goaway($a->get_baseurl(true) . '/profiles');
443 return; // NOTREACHED
446 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
448 // move every contact using this profile as their default to the user default
450 $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 ",
451 intval(local_user()),
455 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
460 info( t('Profile deleted.') . EOL);
462 goaway($a->get_baseurl(true) . '/profiles');
463 return; // NOTREACHED
470 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
472 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
474 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
475 intval(local_user()));
476 $num_profiles = count($r0);
478 $name = t('Profile-') . ($num_profiles + 1);
480 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
481 intval(local_user()));
483 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
484 VALUES ( %d, '%s', '%s', '%s', '%s' )",
485 intval(local_user()),
487 dbesc($r1[0]['name']),
488 dbesc($r1[0]['photo']),
489 dbesc($r1[0]['thumb'])
492 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
493 intval(local_user()),
497 info( t('New profile created.') . EOL);
499 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
501 goaway($a->get_baseurl(true) . '/profiles');
504 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
506 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
508 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
509 intval(local_user()));
510 $num_profiles = count($r0);
512 $name = t('Profile-') . ($num_profiles + 1);
513 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
514 intval(local_user()),
518 notice( t('Profile unavailable to clone.') . EOL);
522 $r1[0]['is-default'] = 0;
523 $r1[0]['publish'] = 0;
524 $r1[0]['net-publish'] = 0;
525 $r1[0]['profile-name'] = dbesc($name);
529 $r2 = dbq("INSERT INTO `profile` (`"
530 . implode("`, `", array_keys($r1[0]))
532 . implode("', '", array_values($r1[0]))
535 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
536 intval(local_user()),
539 info( t('New profile created.') . EOL);
541 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
543 goaway($a->get_baseurl(true) . '/profiles');
545 return; // NOTREACHED
549 if(($a->argc > 1) && (intval($a->argv[1]))) {
550 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
555 notice( t('Profile not found.') . EOL);
559 profile_load($a,$a->user['nickname'],$r[0]['id']);
561 require_once('include/profile_selectors.php');
564 /* $editselect = 'textareas';
565 if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
566 $editselect = 'none';*/
567 $editselect = 'none';
568 if( feature_enabled(local_user(),'richtext') )
569 $editselect = 'textareas';
571 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
572 '$baseurl' => $a->get_baseurl(true),
573 '$editselect' => $editselect,
575 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
576 '$baseurl' => $a->get_baseurl(true),
577 '$editselect' => $editselect,
581 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
582 $hide_friends = replace_macros($opt_tpl,array(
583 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
584 '$yes_str' => t('Yes'),
585 '$no_str' => t('No'),
586 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
587 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
593 $f = get_config('system','birthday_input_format');
597 $is_default = (($r[0]['is-default']) ? 1 : 0);
598 $tpl = get_markup_template("profile_edit.tpl");
599 $o .= replace_macros($tpl,array(
600 '$form_security_token' => get_form_security_token("profile_edit"),
601 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
602 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
603 '$banner' => t('Edit Profile Details'),
604 '$submit' => t('Submit'),
605 '$profpic' => t('Change Profile Photo'),
606 '$viewprof' => t('View this profile'),
607 '$cr_prof' => t('Create a new profile using these settings'),
608 '$cl_prof' => t('Clone this profile'),
609 '$del_prof' => t('Delete this profile'),
610 '$lbl_profname' => t('Profile Name:'),
611 '$lbl_fullname' => t('Your Full Name:'),
612 '$lbl_title' => t('Title/Description:'),
613 '$lbl_gender' => t('Your Gender:'),
614 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
615 '$lbl_address' => t('Street Address:'),
616 '$lbl_city' => t('Locality/City:'),
617 '$lbl_zip' => t('Postal/Zip Code:'),
618 '$lbl_country' => t('Country:'),
619 '$lbl_region' => t('Region/State:'),
620 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
621 '$lbl_with' => t("Who: \x28if applicable\x29"),
622 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
623 '$lbl_howlong' => t('Since [date]:'),
624 '$lbl_sexual' => t('Sexual Preference:'),
625 '$lbl_homepage' => t('Homepage URL:'),
626 '$lbl_hometown' => t('Hometown:'),
627 '$lbl_politic' => t('Political Views:'),
628 '$lbl_religion' => t('Religious Views:'),
629 '$lbl_pubkey' => t('Public Keywords:'),
630 '$lbl_prvkey' => t('Private Keywords:'),
631 '$lbl_likes' => t('Likes:'),
632 '$lbl_dislikes' => t('Dislikes:'),
633 '$lbl_ex2' => t('Example: fishing photography software'),
634 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
635 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
636 '$lbl_about' => t('Tell us about yourself...'),
637 '$lbl_hobbies' => t('Hobbies/Interests'),
638 '$lbl_social' => t('Contact information and Social Networks'),
639 '$lbl_music' => t('Musical interests'),
640 '$lbl_book' => t('Books, literature'),
641 '$lbl_tv' => t('Television'),
642 '$lbl_film' => t('Film/dance/culture/entertainment'),
643 '$lbl_love' => t('Love/romance'),
644 '$lbl_work' => t('Work/employment'),
645 '$lbl_school' => t('School/education'),
646 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
647 '$baseurl' => $a->get_baseurl(true),
648 '$profile_id' => $r[0]['id'],
649 '$profile_name' => $r[0]['profile-name'],
650 '$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>' : ""),
651 '$name' => $r[0]['name'],
652 '$pdesc' => $r[0]['pdesc'],
653 '$dob' => dob($r[0]['dob']),
654 '$hide_friends' => $hide_friends,
655 '$address' => $r[0]['address'],
656 '$locality' => $r[0]['locality'],
657 '$region' => $r[0]['region'],
658 '$postal_code' => $r[0]['postal-code'],
659 '$country_name' => $r[0]['country-name'],
660 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
661 '$gender' => gender_selector($r[0]['gender']),
662 '$marital' => marital_selector($r[0]['marital']),
663 '$with' => strip_tags($r[0]['with']),
664 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
665 '$sexual' => sexpref_selector($r[0]['sexual']),
666 '$about' => $r[0]['about'],
667 '$homepage' => $r[0]['homepage'],
668 '$hometown' => $r[0]['hometown'],
669 '$politic' => $r[0]['politic'],
670 '$religion' => $r[0]['religion'],
671 '$pub_keywords' => $r[0]['pub_keywords'],
672 '$prv_keywords' => $r[0]['prv_keywords'],
673 '$likes' => $r[0]['likes'],
674 '$dislikes' => $r[0]['dislikes'],
675 '$music' => $r[0]['music'],
676 '$book' => $r[0]['book'],
677 '$tv' => $r[0]['tv'],
678 '$film' => $r[0]['film'],
679 '$interest' => $r[0]['interest'],
680 '$romance' => $r[0]['romance'],
681 '$work' => $r[0]['work'],
682 '$education' => $r[0]['education'],
683 '$contact' => $r[0]['contact']
686 $arr = array('profile' => $r[0], 'entry' => $o);
687 call_hooks('profile_edit', $arr);
693 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
697 $tpl_header = get_markup_template('profile_listing_header.tpl');
698 $o .= replace_macros($tpl_header,array(
699 '$header' => t('Edit/Manage Profiles'),
700 '$chg_photo' => t('Change profile photo'),
701 '$cr_new' => t('Create New Profile'),
702 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
706 $tpl = get_markup_template('profile_entry.tpl');
709 $o .= replace_macros($tpl, array(
710 '$photo' => $a->get_cached_avatar_image($rr['thumb']),
712 '$alt' => t('Profile Image'),
713 '$profile_name' => $rr['profile-name'],
714 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
715 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')