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 profile_clean_keywords($keywords) {
146 $keywords = str_replace(","," ",$keywords);
147 $keywords = explode(" ", $keywords);
150 foreach ($keywords as $keyword) {
151 $keyword = trim(strtolower($keyword));
153 $cleaned[] = $keyword;
156 $keywords = implode(", ", $cleaned);
161 function profiles_post(&$a) {
164 notice( t('Permission denied.') . EOL);
168 $namechanged = false;
170 call_hooks('profile_post', $_POST);
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",
178 notice( t('Profile not found.') . EOL);
182 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
184 $is_default = (($orig[0]['is-default']) ? 1 : 0);
186 $profile_name = notags(trim($_POST['profile_name']));
187 if(! strlen($profile_name)) {
188 notice( t('Profile Name is required.') . EOL);
192 $year = intval($_POST['year']);
193 if($year < 1900 || $year > 2100 || $year < 0)
195 $month = intval($_POST['month']);
196 if(($month > 12) || ($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))
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)
210 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
213 $name = notags(trim($_POST['name']));
215 if(! strlen($name)) {
219 if($orig[0]['name'] != $name)
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']));
236 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
238 if(! strlen($howlong))
239 $howlong = '0000-00-00 00:00:00';
241 $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
243 // linkify the relationship target if applicable
245 $withchanged = false;
248 if($with != strip_tags($orig[0]['with'])) {
252 if(strpos($lookup,'@') === 0)
253 $lookup = substr($lookup,1);
254 $lookup = str_replace('_',' ', $lookup);
255 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
257 $links = @lrdd($lookup);
259 foreach($links as $link) {
260 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
261 $prf = $link['@attributes']['href'];
268 /* if(strstr($lookup,' ')) {
269 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
275 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
281 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
286 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
293 $newname = $r[0]['name'];
298 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
299 if(strpos($with,'@') === 0)
300 $with = substr($with,1);
304 $with = $orig[0]['with'];
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;
313 $hometown = notags(trim($_POST['hometown']));
314 $politic = notags(trim($_POST['politic']));
315 $religion = notags(trim($_POST['religion']));
317 $likes = fix_mce_lf(escape_tags(trim($_POST['likes'])));
318 $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes'])));
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'])));
331 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
338 if($marital != $orig[0]['marital']) {
339 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
343 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
344 $value = strip_tags($with);
346 if($likes != $orig[0]['likes']) {
347 $changes[] = t('Likes');
350 if($dislikes != $orig[0]['dislikes']) {
351 $changes[] = t('Dislikes');
354 if($work != $orig[0]['work']) {
355 $changes[] = t('Work/Employment');
357 if($religion != $orig[0]['religion']) {
358 $changes[] = t('Religion');
361 if($politic != $orig[0]['politic']) {
362 $changes[] = t('Political Views');
365 if($gender != $orig[0]['gender']) {
366 $changes[] = t('Gender');
369 if($sexual != $orig[0]['sexual']) {
370 $changes[] = t('Sexual Preference');
373 if($homepage != $orig[0]['homepage']) {
374 $changes[] = t('Homepage');
377 if($interest != $orig[0]['interest']) {
378 $changes[] = t('Interests');
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.
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;
395 profile_activity($changes,$value);
399 $r = q("UPDATE `profile`
400 SET `profile-name` = '%s',
408 `postal-code` = '%s',
409 `country-name` = '%s',
418 `pub_keywords` = '%s',
419 `prv_keywords` = '%s',
433 WHERE `id` = %d AND `uid` = %d",
434 dbesc($profile_name),
443 dbesc($country_name),
452 dbesc($pub_keywords),
453 dbesc($prv_keywords),
466 intval($hide_friends),
472 info( t('Profile updated.') . EOL);
475 if($namechanged && $is_default) {
476 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d",
477 dbesc(datetime_convert()),
480 $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d",
488 $r = q("UPDATE `contact` SET `about` = '%s', `location` = '%s', `keywords` = '%s', `gender` = '%s' WHERE `self` = 1 AND `uid` = %d",
491 dbesc($pub_keywords),
496 // Update global directory in background
497 $url = $_SESSION['my_url'];
498 if($url && strlen(get_config('system','directory_submit_url')))
499 proc_run('php',"include/directory.php","$url");
501 require_once('include/profile_update.php');
508 function profile_activity($changed, $value) {
511 if(! local_user() || ! is_array($changed) || ! count($changed))
514 if($a->user['hidewall'] || get_config('system','block_public'))
517 if(! get_pconfig(local_user(),'system','post_profilechange'))
520 require_once('include/items.php');
522 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
530 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
531 $arr['uid'] = local_user();
532 $arr['contact-id'] = $self[0]['id'];
534 $arr['type'] = 'wall';
537 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
538 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
539 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
540 $arr['verb'] = ACTIVITY_UPDATE;
541 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
543 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
547 $t = count($changed);
549 foreach($changed as $ch) {
550 if(strlen($changes)) {
552 $changes .= t(' and ');
560 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
562 if($t == 1 && strlen($value)) {
563 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
564 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
567 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
570 $arr['body'] = $message;
572 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
573 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
574 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
575 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
576 $arr['object'] .= '</link></object>' . "\n";
577 $arr['last-child'] = 1;
579 $arr['allow_cid'] = $a->user['allow_cid'];
580 $arr['allow_gid'] = $a->user['allow_gid'];
581 $arr['deny_cid'] = $a->user['deny_cid'];
582 $arr['deny_gid'] = $a->user['deny_gid'];
584 $i = item_store($arr);
587 // give it a permanent link
588 //q("update item set plink = '%s' where id = %d",
589 // dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
593 proc_run('php',"include/notifier.php","activity","$i");
599 function profiles_content(&$a) {
602 notice( t('Permission denied.') . EOL);
608 if(($a->argc > 1) && (intval($a->argv[1]))) {
609 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
614 notice( t('Profile not found.') . EOL);
618 require_once('include/profile_selectors.php');
621 /* $editselect = 'textareas';
622 if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
623 $editselect = 'none';*/
624 $editselect = 'none';
625 if( feature_enabled(local_user(),'richtext') )
626 $editselect = 'textareas';
628 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
629 '$baseurl' => $a->get_baseurl(true),
630 '$editselect' => $editselect,
632 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
633 '$baseurl' => $a->get_baseurl(true),
634 '$editselect' => $editselect,
638 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
639 $hide_friends = replace_macros($opt_tpl,array(
641 'hide-friends', //Name
642 t('Hide contacts and friends:'), //Label
643 !!$r[0]['hide-friends'], //Value
645 array(t('No'),t('Yes')) //Off - On strings
647 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
648 '$yes_str' => t('Yes'),
649 '$no_str' => t('No'),
650 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
651 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
657 $f = get_config('system','birthday_input_format');
661 $is_default = (($r[0]['is-default']) ? 1 : 0);
662 $tpl = get_markup_template("profile_edit.tpl");
663 $o .= replace_macros($tpl,array(
664 '$multi_profiles' => feature_enabled(local_user(),'multi_profiles'),
665 '$form_security_token' => get_form_security_token("profile_edit"),
666 '$form_security_token_photo' => get_form_security_token("profile_photo"),
667 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
668 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
669 '$banner' => t('Edit Profile Details'),
670 '$submit' => t('Submit'),
671 '$profpic' => t('Change Profile Photo'),
672 '$viewprof' => t('View this profile'),
673 '$cr_prof' => t('Create a new profile using these settings'),
674 '$cl_prof' => t('Clone this profile'),
675 '$del_prof' => t('Delete this profile'),
676 '$lbl_basic_section' => t('Basic information'),
677 '$lbl_picture_section' => t('Profile picture'),
678 '$lbl_location_section' => t('Location'),
679 '$lbl_preferences_section' => t('Preferences'),
680 '$lbl_status_section' => t('Status information'),
681 '$lbl_about_section' => t('Additional information'),
682 '$lbl_interests_section' => t('Interests'),
683 '$lbl_profile_photo' => t('Upload Profile Photo'),
684 '$lbl_profname' => t('Profile Name:'),
685 '$lbl_fullname' => t('Your Full Name:'),
686 '$lbl_title' => t('Title/Description:'),
687 '$lbl_gender' => t('Your Gender:'),
688 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
689 '$lbl_address' => t('Street Address:'),
690 '$lbl_city' => t('Locality/City:'),
691 '$lbl_zip' => t('Postal/Zip Code:'),
692 '$lbl_country' => t('Country:'),
693 '$lbl_region' => t('Region/State:'),
694 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
695 '$lbl_with' => t("Who: \x28if applicable\x29"),
696 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
697 '$lbl_howlong' => t('Since [date]:'),
698 '$lbl_sexual' => t('Sexual Preference:'),
699 '$lbl_homepage' => t('Homepage URL:'),
700 '$lbl_hometown' => t('Hometown:'),
701 '$lbl_politic' => t('Political Views:'),
702 '$lbl_religion' => t('Religious Views:'),
703 '$lbl_pubkey' => t('Public Keywords:'),
704 '$lbl_prvkey' => t('Private Keywords:'),
705 '$lbl_likes' => t('Likes:'),
706 '$lbl_dislikes' => t('Dislikes:'),
707 '$lbl_ex2' => t('Example: fishing photography software'),
708 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
709 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
710 '$lbl_about' => t('Tell us about yourself...'),
711 '$lbl_hobbies' => t('Hobbies/Interests'),
712 '$lbl_social' => t('Contact information and Social Networks'),
713 '$lbl_music' => t('Musical interests'),
714 '$lbl_book' => t('Books, literature'),
715 '$lbl_tv' => t('Television'),
716 '$lbl_film' => t('Film/dance/culture/entertainment'),
717 '$lbl_love' => t('Love/romance'),
718 '$lbl_work' => t('Work/employment'),
719 '$lbl_school' => t('School/education'),
720 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
721 '$baseurl' => $a->get_baseurl(true),
722 '$profile_id' => $r[0]['id'],
723 '$profile_name' => $r[0]['profile-name'],
724 '$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>' : ""),
725 '$name' => $r[0]['name'],
726 '$pdesc' => $r[0]['pdesc'],
727 '$dob' => dob($r[0]['dob']),
728 '$hide_friends' => $hide_friends,
729 '$address' => $r[0]['address'],
730 '$locality' => $r[0]['locality'],
731 '$region' => $r[0]['region'],
732 '$postal_code' => $r[0]['postal-code'],
733 '$country_name' => $r[0]['country-name'],
734 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
735 '$gender' => gender_selector($r[0]['gender']),
736 '$marital' => marital_selector($r[0]['marital']),
737 '$with' => strip_tags($r[0]['with']),
738 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
739 '$sexual' => sexpref_selector($r[0]['sexual']),
740 '$about' => $r[0]['about'],
741 '$homepage' => $r[0]['homepage'],
742 '$hometown' => $r[0]['hometown'],
743 '$politic' => $r[0]['politic'],
744 '$religion' => $r[0]['religion'],
745 '$pub_keywords' => $r[0]['pub_keywords'],
746 '$prv_keywords' => $r[0]['prv_keywords'],
747 '$likes' => $r[0]['likes'],
748 '$dislikes' => $r[0]['dislikes'],
749 '$music' => $r[0]['music'],
750 '$book' => $r[0]['book'],
751 '$tv' => $r[0]['tv'],
752 '$film' => $r[0]['film'],
753 '$interest' => $r[0]['interest'],
754 '$romance' => $r[0]['romance'],
755 '$work' => $r[0]['work'],
756 '$education' => $r[0]['education'],
757 '$contact' => $r[0]['contact']
760 $arr = array('profile' => $r[0], 'entry' => $o);
761 call_hooks('profile_edit', $arr);
769 //If we don't support multi profiles, don't display this list.
770 if(!feature_enabled(local_user(),'multi_profiles')){
772 "SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
776 //Go to the default profile.
777 goaway($a->get_baseurl(true) . '/profiles/'.$r[0]['id']);
781 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
785 $tpl_header = get_markup_template('profile_listing_header.tpl');
786 $o .= replace_macros($tpl_header,array(
787 '$header' => t('Edit/Manage Profiles'),
788 '$chg_photo' => t('Change profile photo'),
789 '$cr_new' => t('Create New Profile'),
790 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
794 $tpl = get_markup_template('profile_entry.tpl');
797 $o .= replace_macros($tpl, array(
798 '$photo' => $a->get_cached_avatar_image($rr['thumb']),
800 '$alt' => t('Profile Image'),
801 '$profile_name' => $rr['profile-name'],
802 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
803 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')