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 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
49 $name = notags(trim($_POST['name']));
51 if($orig[0]['name'] != $name)
55 $pdesc = notags(trim($_POST['pdesc']));
56 $gender = notags(trim($_POST['gender']));
57 $address = notags(trim($_POST['address']));
58 $locality = notags(trim($_POST['locality']));
59 $region = notags(trim($_POST['region']));
60 $postal_code = notags(trim($_POST['postal_code']));
61 $country_name = notags(trim($_POST['country_name']));
62 $pub_keywords = notags(trim($_POST['pub_keywords']));
63 $prv_keywords = notags(trim($_POST['prv_keywords']));
64 $marital = notags(trim($_POST['marital']));
65 $howlong = notags(trim($_POST['howlong']));
67 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
69 if(! strlen($howlong))
70 $howlong = '0000-00-00 00:00:00';
72 $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong);
74 // linkify the relationship target if applicable
79 if($with != strip_tags($orig[0]['with'])) {
83 if(strpos($lookup,'@') === 0)
84 $lookup = substr($lookup,1);
85 $lookup = str_replace('_',' ', $lookup);
86 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
88 $links = @lrdd($lookup);
90 foreach($links as $link) {
91 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
92 $prf = $link['@attributes']['href'];
99 if(strstr($lookup,' ')) {
100 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
106 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
113 $newname = $r[0]['name'];
118 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
119 if(strpos($with,'@') === 0)
120 $with = substr($with,1);
124 $with = $orig[0]['with'];
127 $sexual = notags(trim($_POST['sexual']));
128 $homepage = notags(trim($_POST['homepage']));
129 $politic = notags(trim($_POST['politic']));
130 $religion = notags(trim($_POST['religion']));
132 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
133 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
134 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
135 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
136 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
137 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
138 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
139 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
140 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
141 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
143 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
150 if($marital != $orig[0]['marital']) {
151 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
155 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
156 $value = strip_tags($with);
158 if($work != $orig[0]['work']) {
159 $changes[] = t('Work/Employment');
161 if($religion != $orig[0]['religion']) {
162 $changes[] = t('Religion');
165 if($politic != $orig[0]['politic']) {
166 $changes[] = t('Political Views');
169 if($gender != $orig[0]['gender']) {
170 $changes[] = t('Gender');
173 if($sexual != $orig[0]['sexual']) {
174 $changes[] = t('Sexual Preference');
177 if($homepage != $orig[0]['homepage']) {
178 $changes[] = t('Homepage');
181 if($interest != $orig[0]['interest']) {
182 $changes[] = t('Interests');
185 if($address != $orig[0]['address']) {
186 $changes[] = t('Address');
187 // New address not sent in notifications, potential privacy issues
188 // in case this leaks to unintended recipients. Yes, it's in the public
189 // profile but that doesn't mean we have to broadcast it to everybody.
191 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
192 || $country_name != $orig[0]['country-name']) {
193 $changes[] = t('Location');
194 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
195 $comma2 = (($region && $country_name) ? ', ' : '');
196 $value = $locality . $comma1 . $region . $comma2 . $country_name;
199 profile_activity($changes,$value);
203 $r = q("UPDATE `profile`
204 SET `profile-name` = '%s',
212 `postal-code` = '%s',
213 `country-name` = '%s',
221 `pub_keywords` = '%s',
222 `prv_keywords` = '%s',
234 WHERE `id` = %d AND `uid` = %d LIMIT 1",
235 dbesc($profile_name),
244 dbesc($country_name),
252 dbesc($pub_keywords),
253 dbesc($prv_keywords),
264 intval($hide_friends),
270 info( t('Profile updated.') . EOL);
273 if($namechanged && $is_default) {
274 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
275 dbesc(datetime_convert()),
281 // Update global directory in background
282 $url = $_SESSION['my_url'];
283 if($url && strlen(get_config('system','directory_submit_url')))
284 proc_run('php',"include/directory.php","$url");
286 require_once('include/profile_update.php');
293 function profile_activity($changed, $value) {
296 if(! local_user() || ! is_array($changed) || ! count($changed))
299 if($a->user['hidewall'] || get_config('system','block_public'))
302 if(! get_pconfig(local_user(),'system','post_profilechange'))
305 require_once('include/items.php');
307 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
315 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
316 $arr['uid'] = local_user();
317 $arr['contact-id'] = $self[0]['id'];
319 $arr['type'] = 'wall';
322 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
323 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
324 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
325 $arr['verb'] = ACTIVITY_UPDATE;
326 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
328 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
332 $t = count($changed);
334 foreach($changed as $ch) {
335 if(strlen($changes)) {
337 $changes .= t(' and ');
345 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
347 if($t == 1 && strlen($value)) {
348 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
349 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
352 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
355 $arr['body'] = $message;
357 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
358 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
359 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
360 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
361 $arr['object'] .= '</link></object>' . "\n";
362 $arr['last-child'] = 1;
364 $arr['allow_cid'] = $a->user['allow_cid'];
365 $arr['allow_gid'] = $a->user['allow_gid'];
366 $arr['deny_cid'] = $a->user['deny_cid'];
367 $arr['deny_gid'] = $a->user['deny_gid'];
369 $i = item_store($arr);
371 proc_run('php',"include/notifier.php","activity","$i");
376 function profiles_content(&$a) {
379 nav_set_selected('profiles');
382 notice( t('Permission denied.') . EOL);
386 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
387 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
392 notice( t('Profile not found.') . EOL);
393 goaway($a->get_baseurl(true) . '/profiles');
394 return; // NOTREACHED
397 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
399 // move every contact using this profile as their default to the user default
401 $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 ",
402 intval(local_user()),
406 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
411 info( t('Profile deleted.') . EOL);
413 goaway($a->get_baseurl(true) . '/profiles');
414 return; // NOTREACHED
421 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
423 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
425 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
426 intval(local_user()));
427 $num_profiles = count($r0);
429 $name = t('Profile-') . ($num_profiles + 1);
431 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
432 intval(local_user()));
434 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
435 VALUES ( %d, '%s', '%s', '%s', '%s' )",
436 intval(local_user()),
438 dbesc($r1[0]['name']),
439 dbesc($r1[0]['photo']),
440 dbesc($r1[0]['thumb'])
443 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
444 intval(local_user()),
448 info( t('New profile created.') . EOL);
450 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
452 goaway($a->get_baseurl(true) . '/profiles');
455 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
457 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
459 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
460 intval(local_user()));
461 $num_profiles = count($r0);
463 $name = t('Profile-') . ($num_profiles + 1);
464 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
465 intval(local_user()),
469 notice( t('Profile unavailable to clone.') . EOL);
473 $r1[0]['is-default'] = 0;
474 $r1[0]['publish'] = 0;
475 $r1[0]['net-publish'] = 0;
476 $r1[0]['profile-name'] = dbesc($name);
480 $r2 = dbq("INSERT INTO `profile` (`"
481 . implode("`, `", array_keys($r1[0]))
483 . implode("', '", array_values($r1[0]))
486 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
487 intval(local_user()),
490 info( t('New profile created.') . EOL);
492 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
494 goaway($a->get_baseurl(true) . '/profiles');
496 return; // NOTREACHED
500 if(($a->argc > 1) && (intval($a->argv[1]))) {
501 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
506 notice( t('Profile not found.') . EOL);
510 profile_load($a,$a->user['nickname'],$r[0]['id']);
512 require_once('include/profile_selectors.php');
515 $editselect = 'textareas';
516 if(intval(get_pconfig(local_user(),'system','plaintext')))
517 $editselect = 'none';
519 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
520 '$baseurl' => $a->get_baseurl(true),
521 '$editselect' => $editselect,
525 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
526 $hide_friends = replace_macros($opt_tpl,array(
527 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
528 '$yes_str' => t('Yes'),
529 '$no_str' => t('No'),
530 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
531 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
534 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
540 $f = get_config('system','birthday_input_format');
544 $is_default = (($r[0]['is-default']) ? 1 : 0);
545 $tpl = get_markup_template("profile_edit.tpl");
546 $o .= replace_macros($tpl,array(
547 '$form_security_token' => get_form_security_token("profile_edit"),
548 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
549 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
550 '$banner' => t('Edit Profile Details'),
551 '$submit' => t('Submit'),
552 '$viewprof' => t('View this profile'),
553 '$cr_prof' => t('Create a new profile using these settings'),
554 '$cl_prof' => t('Clone this profile'),
555 '$del_prof' => t('Delete this profile'),
556 '$lbl_profname' => t('Profile Name:'),
557 '$lbl_fullname' => t('Your Full Name:'),
558 '$lbl_title' => t('Title/Description:'),
559 '$lbl_gender' => t('Your Gender:'),
560 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
561 '$lbl_address' => t('Street Address:'),
562 '$lbl_city' => t('Locality/City:'),
563 '$lbl_zip' => t('Postal/Zip Code:'),
564 '$lbl_country' => t('Country:'),
565 '$lbl_region' => t('Region/State:'),
566 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
567 '$lbl_with' => t("Who: \x28if applicable\x29"),
568 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
569 '$lbl_howlong' => t('Since [date]:'),
570 '$lbl_sexual' => t('Sexual Preference:'),
571 '$lbl_homepage' => t('Homepage URL:'),
572 '$lbl_politic' => t('Political Views:'),
573 '$lbl_religion' => t('Religious Views:'),
574 '$lbl_pubkey' => t('Public Keywords:'),
575 '$lbl_prvkey' => t('Private Keywords:'),
576 '$lbl_ex2' => t('Example: fishing photography software'),
577 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
578 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
579 '$lbl_about' => t('Tell us about yourself...'),
580 '$lbl_hobbies' => t('Hobbies/Interests'),
581 '$lbl_social' => t('Contact information and Social Networks'),
582 '$lbl_music' => t('Musical interests'),
583 '$lbl_book' => t('Books, literature'),
584 '$lbl_tv' => t('Television'),
585 '$lbl_film' => t('Film/dance/culture/entertainment'),
586 '$lbl_love' => t('Love/romance'),
587 '$lbl_work' => t('Work/employment'),
588 '$lbl_school' => t('School/education'),
589 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
590 '$baseurl' => $a->get_baseurl(true),
591 '$profile_id' => $r[0]['id'],
592 '$profile_name' => $r[0]['profile-name'],
593 '$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>' : ""),
594 '$name' => $r[0]['name'],
595 '$pdesc' => $r[0]['pdesc'],
596 '$dob' => dob($r[0]['dob']),
597 '$hide_friends' => $hide_friends,
598 '$address' => $r[0]['address'],
599 '$locality' => $r[0]['locality'],
600 '$region' => $r[0]['region'],
601 '$postal_code' => $r[0]['postal-code'],
602 '$country_name' => $r[0]['country-name'],
603 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
604 '$gender' => gender_selector($r[0]['gender']),
605 '$marital' => marital_selector($r[0]['marital']),
606 '$with' => strip_tags($r[0]['with']),
607 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
608 '$sexual' => sexpref_selector($r[0]['sexual']),
609 '$about' => $r[0]['about'],
610 '$homepage' => $r[0]['homepage'],
611 '$politic' => $r[0]['politic'],
612 '$religion' => $r[0]['religion'],
613 '$pub_keywords' => $r[0]['pub_keywords'],
614 '$prv_keywords' => $r[0]['prv_keywords'],
615 '$music' => $r[0]['music'],
616 '$book' => $r[0]['book'],
617 '$tv' => $r[0]['tv'],
618 '$film' => $r[0]['film'],
619 '$interest' => $r[0]['interest'],
620 '$romance' => $r[0]['romance'],
621 '$work' => $r[0]['work'],
622 '$education' => $r[0]['education'],
623 '$contact' => $r[0]['contact']
626 $arr = array('profile' => $r[0], 'entry' => $o);
627 call_hooks('profile_edit', $arr);
633 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
637 $tpl_header = get_markup_template('profile_listing_header.tpl');
638 $o .= replace_macros($tpl_header,array(
639 '$header' => t('Edit/Manage Profiles'),
640 '$chg_photo' => t('Change profile photo'),
641 '$cr_new' => t('Create New Profile'),
642 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
646 $tpl = get_markup_template('profile_entry.tpl');
649 $o .= replace_macros($tpl, array(
650 '$photo' => $rr['thumb'],
652 '$alt' => t('Profile Image'),
653 '$profile_name' => $rr['profile-name'],
654 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
655 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')