4 function profiles_init(&$a) {
6 nav_set_selected('profiles');
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",
18 notice( t('Profile not found.') . EOL);
19 goaway($a->get_baseurl(true) . '/profiles');
23 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
25 // move every contact using this profile as their default to the user default
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 ",
32 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d",
37 info( t('Profile deleted.') . EOL);
39 goaway($a->get_baseurl(true) . '/profiles');
47 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
49 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
51 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
52 intval(local_user()));
53 $num_profiles = count($r0);
55 $name = t('Profile-') . ($num_profiles + 1);
57 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
58 intval(local_user()));
60 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
61 VALUES ( %d, '%s', '%s', '%s', '%s' )",
64 dbesc($r1[0]['name']),
65 dbesc($r1[0]['photo']),
66 dbesc($r1[0]['thumb'])
69 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
74 info( t('New profile created.') . EOL);
76 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
78 goaway($a->get_baseurl(true) . '/profiles');
81 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
83 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
85 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
86 intval(local_user()));
87 $num_profiles = count($r0);
89 $name = t('Profile-') . ($num_profiles + 1);
90 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
95 notice( t('Profile unavailable to clone.') . EOL);
100 $r1[0]['is-default'] = 0;
101 $r1[0]['publish'] = 0;
102 $r1[0]['net-publish'] = 0;
103 $r1[0]['profile-name'] = dbesc($name);
107 $r2 = dbq("INSERT INTO `profile` (`"
108 . implode("`, `", array_keys($r1[0]))
110 . implode("', '", array_values($r1[0]))
113 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
114 intval(local_user()),
117 info( t('New profile created.') . EOL);
119 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
121 goaway($a->get_baseurl(true) . '/profiles');
123 return; // NOTREACHED
127 if(($a->argc > 1) && (intval($a->argv[1]))) {
128 $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
133 notice( t('Profile not found.') . EOL);
138 profile_load($a,$a->user['nickname'],$r[0]['id']);
145 function profiles_post(&$a) {
148 notice( t('Permission denied.') . EOL);
152 $namechanged = false;
154 call_hooks('profile_post', $_POST);
156 if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
157 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
162 notice( t('Profile not found.') . EOL);
166 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
168 $is_default = (($orig[0]['is-default']) ? 1 : 0);
170 $profile_name = notags(trim($_POST['profile_name']));
171 if(! strlen($profile_name)) {
172 notice( t('Profile Name is required.') . EOL);
176 $year = intval($_POST['year']);
177 if($year < 1900 || $year > 2100 || $year < 0)
179 $month = intval($_POST['month']);
180 if(($month > 12) || ($month < 0))
182 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
183 $day = intval($_POST['day']);
184 if(($day > $mtab[$month]) || ($day < 0))
187 // 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
188 if($year && ! $month)
194 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
197 $name = notags(trim($_POST['name']));
199 if(! strlen($name)) {
203 if($orig[0]['name'] != $name)
208 $pdesc = notags(trim($_POST['pdesc']));
209 $gender = notags(trim($_POST['gender']));
210 $address = notags(trim($_POST['address']));
211 $locality = notags(trim($_POST['locality']));
212 $region = notags(trim($_POST['region']));
213 $postal_code = notags(trim($_POST['postal_code']));
214 $country_name = notags(trim($_POST['country_name']));
215 $pub_keywords = notags(trim($_POST['pub_keywords']));
216 $prv_keywords = notags(trim($_POST['prv_keywords']));
217 $marital = notags(trim($_POST['marital']));
218 $howlong = notags(trim($_POST['howlong']));
220 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
222 if(! strlen($howlong))
223 $howlong = '0000-00-00 00:00:00';
225 $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
227 // linkify the relationship target if applicable
229 $withchanged = false;
232 if($with != strip_tags($orig[0]['with'])) {
236 if(strpos($lookup,'@') === 0)
237 $lookup = substr($lookup,1);
238 $lookup = str_replace('_',' ', $lookup);
239 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
241 $links = @lrdd($lookup);
243 foreach($links as $link) {
244 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
245 $prf = $link['@attributes']['href'];
252 /* if(strstr($lookup,' ')) {
253 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
259 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
265 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
270 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
277 $newname = $r[0]['name'];
282 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
283 if(strpos($with,'@') === 0)
284 $with = substr($with,1);
288 $with = $orig[0]['with'];
291 $sexual = notags(trim($_POST['sexual']));
292 $homepage = notags(trim($_POST['homepage']));
293 if ((strpos($homepage, 'http') !== 0) && (strlen($homepage))) {
294 // neither http nor https in URL, add them
295 $homepage = 'http://'.$homepage;
297 $hometown = notags(trim($_POST['hometown']));
298 $politic = notags(trim($_POST['politic']));
299 $religion = notags(trim($_POST['religion']));
301 $likes = fix_mce_lf(escape_tags(trim($_POST['likes'])));
302 $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes'])));
304 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
305 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
306 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
307 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
308 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
309 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
310 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
311 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
312 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
313 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
315 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
322 if($marital != $orig[0]['marital']) {
323 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
327 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
328 $value = strip_tags($with);
330 if($likes != $orig[0]['likes']) {
331 $changes[] = t('Likes');
334 if($dislikes != $orig[0]['dislikes']) {
335 $changes[] = t('Dislikes');
338 if($work != $orig[0]['work']) {
339 $changes[] = t('Work/Employment');
341 if($religion != $orig[0]['religion']) {
342 $changes[] = t('Religion');
345 if($politic != $orig[0]['politic']) {
346 $changes[] = t('Political Views');
349 if($gender != $orig[0]['gender']) {
350 $changes[] = t('Gender');
353 if($sexual != $orig[0]['sexual']) {
354 $changes[] = t('Sexual Preference');
357 if($homepage != $orig[0]['homepage']) {
358 $changes[] = t('Homepage');
361 if($interest != $orig[0]['interest']) {
362 $changes[] = t('Interests');
365 if($address != $orig[0]['address']) {
366 $changes[] = t('Address');
367 // New address not sent in notifications, potential privacy issues
368 // in case this leaks to unintended recipients. Yes, it's in the public
369 // profile but that doesn't mean we have to broadcast it to everybody.
371 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
372 || $country_name != $orig[0]['country-name']) {
373 $changes[] = t('Location');
374 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
375 $comma2 = (($region && $country_name) ? ', ' : '');
376 $value = $locality . $comma1 . $region . $comma2 . $country_name;
379 profile_activity($changes,$value);
383 $r = q("UPDATE `profile`
384 SET `profile-name` = '%s',
392 `postal-code` = '%s',
393 `country-name` = '%s',
402 `pub_keywords` = '%s',
403 `prv_keywords` = '%s',
417 WHERE `id` = %d AND `uid` = %d",
418 dbesc($profile_name),
427 dbesc($country_name),
436 dbesc($pub_keywords),
437 dbesc($prv_keywords),
450 intval($hide_friends),
456 info( t('Profile updated.') . EOL);
459 if($namechanged && $is_default) {
460 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d",
461 dbesc(datetime_convert()),
464 $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
471 // Update global directory in background
472 $url = $_SESSION['my_url'];
473 if($url && strlen(get_config('system','directory_submit_url')))
474 proc_run('php',"include/directory.php","$url");
476 require_once('include/profile_update.php');
483 function profile_activity($changed, $value) {
486 if(! local_user() || ! is_array($changed) || ! count($changed))
489 if($a->user['hidewall'] || get_config('system','block_public'))
492 if(! get_pconfig(local_user(),'system','post_profilechange'))
495 require_once('include/items.php');
497 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
505 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
506 $arr['uid'] = local_user();
507 $arr['contact-id'] = $self[0]['id'];
509 $arr['type'] = 'wall';
512 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
513 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
514 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
515 $arr['verb'] = ACTIVITY_UPDATE;
516 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
518 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
522 $t = count($changed);
524 foreach($changed as $ch) {
525 if(strlen($changes)) {
527 $changes .= t(' and ');
535 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
537 if($t == 1 && strlen($value)) {
538 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
539 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
542 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
545 $arr['body'] = $message;
547 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
548 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
549 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
550 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
551 $arr['object'] .= '</link></object>' . "\n";
552 $arr['last-child'] = 1;
554 $arr['allow_cid'] = $a->user['allow_cid'];
555 $arr['allow_gid'] = $a->user['allow_gid'];
556 $arr['deny_cid'] = $a->user['deny_cid'];
557 $arr['deny_gid'] = $a->user['deny_gid'];
559 $i = item_store($arr);
562 // give it a permanent link
563 //q("update item set plink = '%s' where id = %d",
564 // dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
568 proc_run('php',"include/notifier.php","activity","$i");
574 function profiles_content(&$a) {
577 notice( t('Permission denied.') . EOL);
583 if(($a->argc > 1) && (intval($a->argv[1]))) {
584 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
589 notice( t('Profile not found.') . EOL);
593 require_once('include/profile_selectors.php');
596 /* $editselect = 'textareas';
597 if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
598 $editselect = 'none';*/
599 $editselect = 'none';
600 if( feature_enabled(local_user(),'richtext') )
601 $editselect = 'textareas';
603 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
604 '$baseurl' => $a->get_baseurl(true),
605 '$editselect' => $editselect,
607 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
608 '$baseurl' => $a->get_baseurl(true),
609 '$editselect' => $editselect,
613 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
614 $hide_friends = replace_macros($opt_tpl,array(
616 'hide-friends', //Name
617 t('Hide contacts and friends:'), //Label
618 !!$r[0]['hide-friends'], //Value
620 array(t('No'),t('Yes')) //Off - On strings
622 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
623 '$yes_str' => t('Yes'),
624 '$no_str' => t('No'),
625 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
626 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
632 $f = get_config('system','birthday_input_format');
636 $is_default = (($r[0]['is-default']) ? 1 : 0);
637 $tpl = get_markup_template("profile_edit.tpl");
638 $o .= replace_macros($tpl,array(
639 '$multi_profiles' => feature_enabled(local_user(),'multi_profiles'),
640 '$form_security_token' => get_form_security_token("profile_edit"),
641 '$form_security_token_photo' => get_form_security_token("profile_photo"),
642 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
643 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
644 '$banner' => t('Edit Profile Details'),
645 '$submit' => t('Submit'),
646 '$profpic' => t('Change Profile Photo'),
647 '$viewprof' => t('View this profile'),
648 '$cr_prof' => t('Create a new profile using these settings'),
649 '$cl_prof' => t('Clone this profile'),
650 '$del_prof' => t('Delete this profile'),
651 '$lbl_basic_section' => t('Basic information'),
652 '$lbl_picture_section' => t('Profile picture'),
653 '$lbl_location_section' => t('Location'),
654 '$lbl_preferences_section' => t('Preferences'),
655 '$lbl_status_section' => t('Status information'),
656 '$lbl_about_section' => t('Additional information'),
657 '$lbl_interests_section' => t('Interests'),
658 '$lbl_profile_photo' => t('Upload Profile Photo'),
659 '$lbl_profname' => t('Profile Name:'),
660 '$lbl_fullname' => t('Your Full Name:'),
661 '$lbl_title' => t('Title/Description:'),
662 '$lbl_gender' => t('Your Gender:'),
663 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
664 '$lbl_address' => t('Street Address:'),
665 '$lbl_city' => t('Locality/City:'),
666 '$lbl_zip' => t('Postal/Zip Code:'),
667 '$lbl_country' => t('Country:'),
668 '$lbl_region' => t('Region/State:'),
669 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
670 '$lbl_with' => t("Who: \x28if applicable\x29"),
671 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
672 '$lbl_howlong' => t('Since [date]:'),
673 '$lbl_sexual' => t('Sexual Preference:'),
674 '$lbl_homepage' => t('Homepage URL:'),
675 '$lbl_hometown' => t('Hometown:'),
676 '$lbl_politic' => t('Political Views:'),
677 '$lbl_religion' => t('Religious Views:'),
678 '$lbl_pubkey' => t('Public Keywords:'),
679 '$lbl_prvkey' => t('Private Keywords:'),
680 '$lbl_likes' => t('Likes:'),
681 '$lbl_dislikes' => t('Dislikes:'),
682 '$lbl_ex2' => t('Example: fishing photography software'),
683 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
684 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
685 '$lbl_about' => t('Tell us about yourself...'),
686 '$lbl_hobbies' => t('Hobbies/Interests'),
687 '$lbl_social' => t('Contact information and Social Networks'),
688 '$lbl_music' => t('Musical interests'),
689 '$lbl_book' => t('Books, literature'),
690 '$lbl_tv' => t('Television'),
691 '$lbl_film' => t('Film/dance/culture/entertainment'),
692 '$lbl_love' => t('Love/romance'),
693 '$lbl_work' => t('Work/employment'),
694 '$lbl_school' => t('School/education'),
695 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
696 '$baseurl' => $a->get_baseurl(true),
697 '$profile_id' => $r[0]['id'],
698 '$profile_name' => $r[0]['profile-name'],
699 '$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>' : ""),
700 '$name' => $r[0]['name'],
701 '$pdesc' => $r[0]['pdesc'],
702 '$dob' => dob($r[0]['dob']),
703 '$hide_friends' => $hide_friends,
704 '$address' => $r[0]['address'],
705 '$locality' => $r[0]['locality'],
706 '$region' => $r[0]['region'],
707 '$postal_code' => $r[0]['postal-code'],
708 '$country_name' => $r[0]['country-name'],
709 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
710 '$gender' => gender_selector($r[0]['gender']),
711 '$marital' => marital_selector($r[0]['marital']),
712 '$with' => strip_tags($r[0]['with']),
713 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
714 '$sexual' => sexpref_selector($r[0]['sexual']),
715 '$about' => $r[0]['about'],
716 '$homepage' => $r[0]['homepage'],
717 '$hometown' => $r[0]['hometown'],
718 '$politic' => $r[0]['politic'],
719 '$religion' => $r[0]['religion'],
720 '$pub_keywords' => $r[0]['pub_keywords'],
721 '$prv_keywords' => $r[0]['prv_keywords'],
722 '$likes' => $r[0]['likes'],
723 '$dislikes' => $r[0]['dislikes'],
724 '$music' => $r[0]['music'],
725 '$book' => $r[0]['book'],
726 '$tv' => $r[0]['tv'],
727 '$film' => $r[0]['film'],
728 '$interest' => $r[0]['interest'],
729 '$romance' => $r[0]['romance'],
730 '$work' => $r[0]['work'],
731 '$education' => $r[0]['education'],
732 '$contact' => $r[0]['contact']
735 $arr = array('profile' => $r[0], 'entry' => $o);
736 call_hooks('profile_edit', $arr);
744 //If we don't support multi profiles, don't display this list.
745 if(!feature_enabled(local_user(),'multi_profiles')){
747 "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
751 //Go to the default profile.
752 goaway($a->get_baseurl(true) . '/profiles/'.$r[0]['id']);
756 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
760 $tpl_header = get_markup_template('profile_listing_header.tpl');
761 $o .= replace_macros($tpl_header,array(
762 '$header' => t('Edit/Manage Profiles'),
763 '$chg_photo' => t('Change profile photo'),
764 '$cr_new' => t('Create New Profile'),
765 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
769 $tpl = get_markup_template('profile_entry.tpl');
772 $o .= replace_macros($tpl, array(
773 '$photo' => $a->get_cached_avatar_image($rr['thumb']),
775 '$alt' => t('Profile Image'),
776 '$profile_name' => $rr['profile-name'],
777 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
778 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')