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 LIMIT 1",
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']);
143 function profiles_post(&$a) {
146 notice( t('Permission denied.') . EOL);
150 $namechanged = false;
152 call_hooks('profile_post', $_POST);
154 if(($a->argc > 1) && ($a->argv[1] !== "new") && intval($a->argv[1])) {
155 $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
160 notice( t('Profile not found.') . EOL);
164 check_form_security_token_redirectOnErr('/profiles', 'profile_edit');
166 $is_default = (($orig[0]['is-default']) ? 1 : 0);
168 $profile_name = notags(trim($_POST['profile_name']));
169 if(! strlen($profile_name)) {
170 notify( t('Profile Name is required.') . EOL);
174 $year = intval($_POST['year']);
175 if($year < 1900 || $year > 2100 || $year < 0)
177 $month = intval($_POST['month']);
178 if(($month > 12) || ($month < 0))
180 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
181 $day = intval($_POST['day']);
182 if(($day > $mtab[$month]) || ($day < 0))
185 // 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
186 if($year && ! $month)
192 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
195 $name = notags(trim($_POST['name']));
197 if(! strlen($name)) {
201 if($orig[0]['name'] != $name)
206 $pdesc = notags(trim($_POST['pdesc']));
207 $gender = notags(trim($_POST['gender']));
208 $address = notags(trim($_POST['address']));
209 $locality = notags(trim($_POST['locality']));
210 $region = notags(trim($_POST['region']));
211 $postal_code = notags(trim($_POST['postal_code']));
212 $country_name = notags(trim($_POST['country_name']));
213 $pub_keywords = notags(trim($_POST['pub_keywords']));
214 $prv_keywords = notags(trim($_POST['prv_keywords']));
215 $marital = notags(trim($_POST['marital']));
216 $howlong = notags(trim($_POST['howlong']));
218 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
220 if(! strlen($howlong))
221 $howlong = '0000-00-00 00:00:00';
223 $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
225 // linkify the relationship target if applicable
227 $withchanged = false;
230 if($with != strip_tags($orig[0]['with'])) {
234 if(strpos($lookup,'@') === 0)
235 $lookup = substr($lookup,1);
236 $lookup = str_replace('_',' ', $lookup);
237 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
239 $links = @lrdd($lookup);
241 foreach($links as $link) {
242 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
243 $prf = $link['@attributes']['href'];
250 /* if(strstr($lookup,' ')) {
251 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
257 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
263 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
268 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
275 $newname = $r[0]['name'];
280 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
281 if(strpos($with,'@') === 0)
282 $with = substr($with,1);
286 $with = $orig[0]['with'];
289 $sexual = notags(trim($_POST['sexual']));
290 $homepage = notags(trim($_POST['homepage']));
291 $hometown = notags(trim($_POST['hometown']));
292 $politic = notags(trim($_POST['politic']));
293 $religion = notags(trim($_POST['religion']));
295 $likes = fix_mce_lf(escape_tags(trim($_POST['likes'])));
296 $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes'])));
298 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
299 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
300 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
301 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
302 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
303 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
304 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
305 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
306 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
307 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
309 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
316 if($marital != $orig[0]['marital']) {
317 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
321 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
322 $value = strip_tags($with);
324 if($likes != $orig[0]['likes']) {
325 $changes[] = t('Likes');
328 if($dislikes != $orig[0]['dislikes']) {
329 $changes[] = t('Dislikes');
332 if($work != $orig[0]['work']) {
333 $changes[] = t('Work/Employment');
335 if($religion != $orig[0]['religion']) {
336 $changes[] = t('Religion');
339 if($politic != $orig[0]['politic']) {
340 $changes[] = t('Political Views');
343 if($gender != $orig[0]['gender']) {
344 $changes[] = t('Gender');
347 if($sexual != $orig[0]['sexual']) {
348 $changes[] = t('Sexual Preference');
351 if($homepage != $orig[0]['homepage']) {
352 $changes[] = t('Homepage');
355 if($interest != $orig[0]['interest']) {
356 $changes[] = t('Interests');
359 if($address != $orig[0]['address']) {
360 $changes[] = t('Address');
361 // New address not sent in notifications, potential privacy issues
362 // in case this leaks to unintended recipients. Yes, it's in the public
363 // profile but that doesn't mean we have to broadcast it to everybody.
365 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
366 || $country_name != $orig[0]['country-name']) {
367 $changes[] = t('Location');
368 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
369 $comma2 = (($region && $country_name) ? ', ' : '');
370 $value = $locality . $comma1 . $region . $comma2 . $country_name;
373 profile_activity($changes,$value);
377 $r = q("UPDATE `profile`
378 SET `profile-name` = '%s',
386 `postal-code` = '%s',
387 `country-name` = '%s',
396 `pub_keywords` = '%s',
397 `prv_keywords` = '%s',
411 WHERE `id` = %d AND `uid` = %d LIMIT 1",
412 dbesc($profile_name),
421 dbesc($country_name),
430 dbesc($pub_keywords),
431 dbesc($prv_keywords),
444 intval($hide_friends),
450 info( t('Profile updated.') . EOL);
453 if($namechanged && $is_default) {
454 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
455 dbesc(datetime_convert()),
461 // Update global directory in background
462 $url = $_SESSION['my_url'];
463 if($url && strlen(get_config('system','directory_submit_url')))
464 proc_run('php',"include/directory.php","$url");
466 require_once('include/profile_update.php');
473 function profile_activity($changed, $value) {
476 if(! local_user() || ! is_array($changed) || ! count($changed))
479 if($a->user['hidewall'] || get_config('system','block_public'))
482 if(! get_pconfig(local_user(),'system','post_profilechange'))
485 require_once('include/items.php');
487 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
495 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
496 $arr['uid'] = local_user();
497 $arr['contact-id'] = $self[0]['id'];
499 $arr['type'] = 'wall';
502 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
503 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
504 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
505 $arr['verb'] = ACTIVITY_UPDATE;
506 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
508 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
512 $t = count($changed);
514 foreach($changed as $ch) {
515 if(strlen($changes)) {
517 $changes .= t(' and ');
525 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
527 if($t == 1 && strlen($value)) {
528 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
529 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
532 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
535 $arr['body'] = $message;
537 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
538 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
539 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
540 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
541 $arr['object'] .= '</link></object>' . "\n";
542 $arr['last-child'] = 1;
544 $arr['allow_cid'] = $a->user['allow_cid'];
545 $arr['allow_gid'] = $a->user['allow_gid'];
546 $arr['deny_cid'] = $a->user['deny_cid'];
547 $arr['deny_gid'] = $a->user['deny_gid'];
549 $i = item_store($arr);
552 // give it a permanent link
553 q("update item set plink = '%s' where id = %d limit 1",
554 dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
558 proc_run('php',"include/notifier.php","activity","$i");
564 function profiles_content(&$a) {
567 notice( t('Permission denied.') . EOL);
573 if(($a->argc > 1) && (intval($a->argv[1]))) {
574 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
579 notice( t('Profile not found.') . EOL);
583 require_once('include/profile_selectors.php');
586 /* $editselect = 'textareas';
587 if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
588 $editselect = 'none';*/
589 $editselect = 'none';
590 if( feature_enabled(local_user(),'richtext') )
591 $editselect = 'textareas';
593 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
594 '$baseurl' => $a->get_baseurl(true),
595 '$editselect' => $editselect,
597 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
598 '$baseurl' => $a->get_baseurl(true),
599 '$editselect' => $editselect,
603 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
604 $hide_friends = replace_macros($opt_tpl,array(
605 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
606 '$yes_str' => t('Yes'),
607 '$no_str' => t('No'),
608 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
609 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
615 $f = get_config('system','birthday_input_format');
619 $is_default = (($r[0]['is-default']) ? 1 : 0);
620 $tpl = get_markup_template("profile_edit.tpl");
621 $o .= replace_macros($tpl,array(
622 '$form_security_token' => get_form_security_token("profile_edit"),
623 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
624 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
625 '$banner' => t('Edit Profile Details'),
626 '$submit' => t('Submit'),
627 '$profpic' => t('Change Profile Photo'),
628 '$viewprof' => t('View this profile'),
629 '$cr_prof' => t('Create a new profile using these settings'),
630 '$cl_prof' => t('Clone this profile'),
631 '$del_prof' => t('Delete this profile'),
632 '$lbl_profname' => t('Profile Name:'),
633 '$lbl_fullname' => t('Your Full Name:'),
634 '$lbl_title' => t('Title/Description:'),
635 '$lbl_gender' => t('Your Gender:'),
636 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
637 '$lbl_address' => t('Street Address:'),
638 '$lbl_city' => t('Locality/City:'),
639 '$lbl_zip' => t('Postal/Zip Code:'),
640 '$lbl_country' => t('Country:'),
641 '$lbl_region' => t('Region/State:'),
642 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
643 '$lbl_with' => t("Who: \x28if applicable\x29"),
644 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
645 '$lbl_howlong' => t('Since [date]:'),
646 '$lbl_sexual' => t('Sexual Preference:'),
647 '$lbl_homepage' => t('Homepage URL:'),
648 '$lbl_hometown' => t('Hometown:'),
649 '$lbl_politic' => t('Political Views:'),
650 '$lbl_religion' => t('Religious Views:'),
651 '$lbl_pubkey' => t('Public Keywords:'),
652 '$lbl_prvkey' => t('Private Keywords:'),
653 '$lbl_likes' => t('Likes:'),
654 '$lbl_dislikes' => t('Dislikes:'),
655 '$lbl_ex2' => t('Example: fishing photography software'),
656 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
657 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
658 '$lbl_about' => t('Tell us about yourself...'),
659 '$lbl_hobbies' => t('Hobbies/Interests'),
660 '$lbl_social' => t('Contact information and Social Networks'),
661 '$lbl_music' => t('Musical interests'),
662 '$lbl_book' => t('Books, literature'),
663 '$lbl_tv' => t('Television'),
664 '$lbl_film' => t('Film/dance/culture/entertainment'),
665 '$lbl_love' => t('Love/romance'),
666 '$lbl_work' => t('Work/employment'),
667 '$lbl_school' => t('School/education'),
668 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
669 '$baseurl' => $a->get_baseurl(true),
670 '$profile_id' => $r[0]['id'],
671 '$profile_name' => $r[0]['profile-name'],
672 '$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>' : ""),
673 '$name' => $r[0]['name'],
674 '$pdesc' => $r[0]['pdesc'],
675 '$dob' => dob($r[0]['dob']),
676 '$hide_friends' => $hide_friends,
677 '$address' => $r[0]['address'],
678 '$locality' => $r[0]['locality'],
679 '$region' => $r[0]['region'],
680 '$postal_code' => $r[0]['postal-code'],
681 '$country_name' => $r[0]['country-name'],
682 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
683 '$gender' => gender_selector($r[0]['gender']),
684 '$marital' => marital_selector($r[0]['marital']),
685 '$with' => strip_tags($r[0]['with']),
686 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
687 '$sexual' => sexpref_selector($r[0]['sexual']),
688 '$about' => $r[0]['about'],
689 '$homepage' => $r[0]['homepage'],
690 '$hometown' => $r[0]['hometown'],
691 '$politic' => $r[0]['politic'],
692 '$religion' => $r[0]['religion'],
693 '$pub_keywords' => $r[0]['pub_keywords'],
694 '$prv_keywords' => $r[0]['prv_keywords'],
695 '$likes' => $r[0]['likes'],
696 '$dislikes' => $r[0]['dislikes'],
697 '$music' => $r[0]['music'],
698 '$book' => $r[0]['book'],
699 '$tv' => $r[0]['tv'],
700 '$film' => $r[0]['film'],
701 '$interest' => $r[0]['interest'],
702 '$romance' => $r[0]['romance'],
703 '$work' => $r[0]['work'],
704 '$education' => $r[0]['education'],
705 '$contact' => $r[0]['contact']
708 $arr = array('profile' => $r[0], 'entry' => $o);
709 call_hooks('profile_edit', $arr);
715 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
719 $tpl_header = get_markup_template('profile_listing_header.tpl');
720 $o .= replace_macros($tpl_header,array(
721 '$header' => t('Edit/Manage Profiles'),
722 '$chg_photo' => t('Change profile photo'),
723 '$cr_new' => t('Create New Profile'),
724 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
728 $tpl = get_markup_template('profile_entry.tpl');
731 $o .= replace_macros($tpl, array(
732 '$photo' => $a->get_cached_avatar_image($rr['thumb']),
734 '$alt' => t('Profile Image'),
735 '$profile_name' => $rr['profile-name'],
736 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
737 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')