4 function profiles_init(&$a) {
6 nav_set_selected('profiles');
9 notice( t('Permission denied.') . EOL);
14 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
15 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
20 notice( t('Profile not found.') . EOL);
21 goaway($a->get_baseurl(true) . '/profiles');
25 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
27 // move every contact using this profile as their default to the user default
29 $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 ",
34 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
39 info( t('Profile deleted.') . EOL);
41 goaway($a->get_baseurl(true) . '/profiles');
49 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
51 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
53 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
54 intval(local_user()));
55 $num_profiles = count($r0);
57 $name = t('Profile-') . ($num_profiles + 1);
59 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
60 intval(local_user()));
62 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
63 VALUES ( %d, '%s', '%s', '%s', '%s' )",
66 dbesc($r1[0]['name']),
67 dbesc($r1[0]['photo']),
68 dbesc($r1[0]['thumb'])
71 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
76 info( t('New profile created.') . EOL);
78 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
80 goaway($a->get_baseurl(true) . '/profiles');
83 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
85 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
87 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
88 intval(local_user()));
89 $num_profiles = count($r0);
91 $name = t('Profile-') . ($num_profiles + 1);
92 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
97 notice( t('Profile unavailable to clone.') . EOL);
102 $r1[0]['is-default'] = 0;
103 $r1[0]['publish'] = 0;
104 $r1[0]['net-publish'] = 0;
105 $r1[0]['profile-name'] = dbesc($name);
109 $r2 = dbq("INSERT INTO `profile` (`"
110 . implode("`, `", array_keys($r1[0]))
112 . implode("', '", array_values($r1[0]))
115 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
116 intval(local_user()),
119 info( t('New profile created.') . EOL);
121 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
123 goaway($a->get_baseurl(true) . '/profiles');
125 return; // NOTREACHED
129 if(($a->argc > 1) && (intval($a->argv[1]))) {
130 $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
135 notice( t('Profile not found.') . EOL);
140 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 notify( 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 $hometown = notags(trim($_POST['hometown']));
294 $politic = notags(trim($_POST['politic']));
295 $religion = notags(trim($_POST['religion']));
297 $likes = fix_mce_lf(escape_tags(trim($_POST['likes'])));
298 $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes'])));
300 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
301 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
302 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
303 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
304 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
305 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
306 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
307 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
308 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
309 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
311 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
318 if($marital != $orig[0]['marital']) {
319 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
323 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
324 $value = strip_tags($with);
326 if($likes != $orig[0]['likes']) {
327 $changes[] = t('Likes');
330 if($dislikes != $orig[0]['dislikes']) {
331 $changes[] = t('Dislikes');
334 if($work != $orig[0]['work']) {
335 $changes[] = t('Work/Employment');
337 if($religion != $orig[0]['religion']) {
338 $changes[] = t('Religion');
341 if($politic != $orig[0]['politic']) {
342 $changes[] = t('Political Views');
345 if($gender != $orig[0]['gender']) {
346 $changes[] = t('Gender');
349 if($sexual != $orig[0]['sexual']) {
350 $changes[] = t('Sexual Preference');
353 if($homepage != $orig[0]['homepage']) {
354 $changes[] = t('Homepage');
357 if($interest != $orig[0]['interest']) {
358 $changes[] = t('Interests');
361 if($address != $orig[0]['address']) {
362 $changes[] = t('Address');
363 // New address not sent in notifications, potential privacy issues
364 // in case this leaks to unintended recipients. Yes, it's in the public
365 // profile but that doesn't mean we have to broadcast it to everybody.
367 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
368 || $country_name != $orig[0]['country-name']) {
369 $changes[] = t('Location');
370 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
371 $comma2 = (($region && $country_name) ? ', ' : '');
372 $value = $locality . $comma1 . $region . $comma2 . $country_name;
375 profile_activity($changes,$value);
379 $r = q("UPDATE `profile`
380 SET `profile-name` = '%s',
388 `postal-code` = '%s',
389 `country-name` = '%s',
398 `pub_keywords` = '%s',
399 `prv_keywords` = '%s',
413 WHERE `id` = %d AND `uid` = %d LIMIT 1",
414 dbesc($profile_name),
423 dbesc($country_name),
432 dbesc($pub_keywords),
433 dbesc($prv_keywords),
446 intval($hide_friends),
452 info( t('Profile updated.') . EOL);
455 if($namechanged && $is_default) {
456 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
457 dbesc(datetime_convert()),
463 // Update global directory in background
464 $url = $_SESSION['my_url'];
465 if($url && strlen(get_config('system','directory_submit_url')))
466 proc_run('php',"include/directory.php","$url");
468 require_once('include/profile_update.php');
475 function profile_activity($changed, $value) {
478 if(! local_user() || ! is_array($changed) || ! count($changed))
481 if($a->user['hidewall'] || get_config('system','block_public'))
484 if(! get_pconfig(local_user(),'system','post_profilechange'))
487 require_once('include/items.php');
489 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
497 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
498 $arr['uid'] = local_user();
499 $arr['contact-id'] = $self[0]['id'];
501 $arr['type'] = 'wall';
504 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
505 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
506 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
507 $arr['verb'] = ACTIVITY_UPDATE;
508 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
510 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
514 $t = count($changed);
516 foreach($changed as $ch) {
517 if(strlen($changes)) {
519 $changes .= t(' and ');
527 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
529 if($t == 1 && strlen($value)) {
530 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
531 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
534 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
537 $arr['body'] = $message;
539 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
540 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
541 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
542 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
543 $arr['object'] .= '</link></object>' . "\n";
544 $arr['last-child'] = 1;
546 $arr['allow_cid'] = $a->user['allow_cid'];
547 $arr['allow_gid'] = $a->user['allow_gid'];
548 $arr['deny_cid'] = $a->user['deny_cid'];
549 $arr['deny_gid'] = $a->user['deny_gid'];
551 $i = item_store($arr);
554 // give it a permanent link
555 q("update item set plink = '%s' where id = %d limit 1",
556 dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i),
560 proc_run('php',"include/notifier.php","activity","$i");
566 function profiles_content(&$a) {
570 if(($a->argc > 1) && (intval($a->argv[1]))) {
571 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
576 notice( t('Profile not found.') . EOL);
580 require_once('include/profile_selectors.php');
583 /* $editselect = 'textareas';
584 if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') )
585 $editselect = 'none';*/
586 $editselect = 'none';
587 if( feature_enabled(local_user(),'richtext') )
588 $editselect = 'textareas';
590 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
591 '$baseurl' => $a->get_baseurl(true),
592 '$editselect' => $editselect,
594 $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array(
595 '$baseurl' => $a->get_baseurl(true),
596 '$editselect' => $editselect,
600 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
601 $hide_friends = replace_macros($opt_tpl,array(
602 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
603 '$yes_str' => t('Yes'),
604 '$no_str' => t('No'),
605 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
606 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
612 $f = get_config('system','birthday_input_format');
616 $is_default = (($r[0]['is-default']) ? 1 : 0);
617 $tpl = get_markup_template("profile_edit.tpl");
618 $o .= replace_macros($tpl,array(
619 '$form_security_token' => get_form_security_token("profile_edit"),
620 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
621 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
622 '$banner' => t('Edit Profile Details'),
623 '$submit' => t('Submit'),
624 '$profpic' => t('Change Profile Photo'),
625 '$viewprof' => t('View this profile'),
626 '$cr_prof' => t('Create a new profile using these settings'),
627 '$cl_prof' => t('Clone this profile'),
628 '$del_prof' => t('Delete this profile'),
629 '$lbl_profname' => t('Profile Name:'),
630 '$lbl_fullname' => t('Your Full Name:'),
631 '$lbl_title' => t('Title/Description:'),
632 '$lbl_gender' => t('Your Gender:'),
633 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
634 '$lbl_address' => t('Street Address:'),
635 '$lbl_city' => t('Locality/City:'),
636 '$lbl_zip' => t('Postal/Zip Code:'),
637 '$lbl_country' => t('Country:'),
638 '$lbl_region' => t('Region/State:'),
639 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
640 '$lbl_with' => t("Who: \x28if applicable\x29"),
641 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
642 '$lbl_howlong' => t('Since [date]:'),
643 '$lbl_sexual' => t('Sexual Preference:'),
644 '$lbl_homepage' => t('Homepage URL:'),
645 '$lbl_hometown' => t('Hometown:'),
646 '$lbl_politic' => t('Political Views:'),
647 '$lbl_religion' => t('Religious Views:'),
648 '$lbl_pubkey' => t('Public Keywords:'),
649 '$lbl_prvkey' => t('Private Keywords:'),
650 '$lbl_likes' => t('Likes:'),
651 '$lbl_dislikes' => t('Dislikes:'),
652 '$lbl_ex2' => t('Example: fishing photography software'),
653 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
654 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
655 '$lbl_about' => t('Tell us about yourself...'),
656 '$lbl_hobbies' => t('Hobbies/Interests'),
657 '$lbl_social' => t('Contact information and Social Networks'),
658 '$lbl_music' => t('Musical interests'),
659 '$lbl_book' => t('Books, literature'),
660 '$lbl_tv' => t('Television'),
661 '$lbl_film' => t('Film/dance/culture/entertainment'),
662 '$lbl_love' => t('Love/romance'),
663 '$lbl_work' => t('Work/employment'),
664 '$lbl_school' => t('School/education'),
665 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
666 '$baseurl' => $a->get_baseurl(true),
667 '$profile_id' => $r[0]['id'],
668 '$profile_name' => $r[0]['profile-name'],
669 '$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>' : ""),
670 '$name' => $r[0]['name'],
671 '$pdesc' => $r[0]['pdesc'],
672 '$dob' => dob($r[0]['dob']),
673 '$hide_friends' => $hide_friends,
674 '$address' => $r[0]['address'],
675 '$locality' => $r[0]['locality'],
676 '$region' => $r[0]['region'],
677 '$postal_code' => $r[0]['postal-code'],
678 '$country_name' => $r[0]['country-name'],
679 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
680 '$gender' => gender_selector($r[0]['gender']),
681 '$marital' => marital_selector($r[0]['marital']),
682 '$with' => strip_tags($r[0]['with']),
683 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
684 '$sexual' => sexpref_selector($r[0]['sexual']),
685 '$about' => $r[0]['about'],
686 '$homepage' => $r[0]['homepage'],
687 '$hometown' => $r[0]['hometown'],
688 '$politic' => $r[0]['politic'],
689 '$religion' => $r[0]['religion'],
690 '$pub_keywords' => $r[0]['pub_keywords'],
691 '$prv_keywords' => $r[0]['prv_keywords'],
692 '$likes' => $r[0]['likes'],
693 '$dislikes' => $r[0]['dislikes'],
694 '$music' => $r[0]['music'],
695 '$book' => $r[0]['book'],
696 '$tv' => $r[0]['tv'],
697 '$film' => $r[0]['film'],
698 '$interest' => $r[0]['interest'],
699 '$romance' => $r[0]['romance'],
700 '$work' => $r[0]['work'],
701 '$education' => $r[0]['education'],
702 '$contact' => $r[0]['contact']
705 $arr = array('profile' => $r[0], 'entry' => $o);
706 call_hooks('profile_edit', $arr);
712 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
716 $tpl_header = get_markup_template('profile_listing_header.tpl');
717 $o .= replace_macros($tpl_header,array(
718 '$header' => t('Edit/Manage Profiles'),
719 '$chg_photo' => t('Change profile photo'),
720 '$cr_new' => t('Create New Profile'),
721 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
725 $tpl = get_markup_template('profile_entry.tpl');
728 $o .= replace_macros($tpl, array(
729 '$photo' => $a->get_cached_avatar_image($rr['thumb']),
731 '$alt' => t('Profile Image'),
732 '$profile_name' => $rr['profile-name'],
733 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
734 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')