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 $hometown = notags(trim($_POST['hometown']));
130 $politic = notags(trim($_POST['politic']));
131 $religion = notags(trim($_POST['religion']));
133 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
134 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
135 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
136 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
137 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
138 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
139 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
140 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
141 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
142 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
144 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
151 if($marital != $orig[0]['marital']) {
152 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
156 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
157 $value = strip_tags($with);
159 if($work != $orig[0]['work']) {
160 $changes[] = t('Work/Employment');
162 if($religion != $orig[0]['religion']) {
163 $changes[] = t('Religion');
166 if($politic != $orig[0]['politic']) {
167 $changes[] = t('Political Views');
170 if($gender != $orig[0]['gender']) {
171 $changes[] = t('Gender');
174 if($sexual != $orig[0]['sexual']) {
175 $changes[] = t('Sexual Preference');
178 if($homepage != $orig[0]['homepage']) {
179 $changes[] = t('Homepage');
182 if($interest != $orig[0]['interest']) {
183 $changes[] = t('Interests');
186 if($address != $orig[0]['address']) {
187 $changes[] = t('Address');
188 // New address not sent in notifications, potential privacy issues
189 // in case this leaks to unintended recipients. Yes, it's in the public
190 // profile but that doesn't mean we have to broadcast it to everybody.
192 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
193 || $country_name != $orig[0]['country-name']) {
194 $changes[] = t('Location');
195 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
196 $comma2 = (($region && $country_name) ? ', ' : '');
197 $value = $locality . $comma1 . $region . $comma2 . $country_name;
200 profile_activity($changes,$value);
204 $r = q("UPDATE `profile`
205 SET `profile-name` = '%s',
213 `postal-code` = '%s',
214 `country-name` = '%s',
223 `pub_keywords` = '%s',
224 `prv_keywords` = '%s',
236 WHERE `id` = %d AND `uid` = %d LIMIT 1",
237 dbesc($profile_name),
246 dbesc($country_name),
255 dbesc($pub_keywords),
256 dbesc($prv_keywords),
267 intval($hide_friends),
273 info( t('Profile updated.') . EOL);
276 if($namechanged && $is_default) {
277 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
278 dbesc(datetime_convert()),
284 // Update global directory in background
285 $url = $_SESSION['my_url'];
286 if($url && strlen(get_config('system','directory_submit_url')))
287 proc_run('php',"include/directory.php","$url");
289 require_once('include/profile_update.php');
296 function profile_activity($changed, $value) {
299 if(! local_user() || ! is_array($changed) || ! count($changed))
302 if($a->user['hidewall'] || get_config('system','block_public'))
305 if(! get_pconfig(local_user(),'system','post_profilechange'))
308 require_once('include/items.php');
310 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
318 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
319 $arr['uid'] = local_user();
320 $arr['contact-id'] = $self[0]['id'];
322 $arr['type'] = 'wall';
325 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
326 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
327 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
328 $arr['verb'] = ACTIVITY_UPDATE;
329 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
331 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
335 $t = count($changed);
337 foreach($changed as $ch) {
338 if(strlen($changes)) {
340 $changes .= t(' and ');
348 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
350 if($t == 1 && strlen($value)) {
351 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
352 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
355 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
358 $arr['body'] = $message;
360 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
361 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
362 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
363 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
364 $arr['object'] .= '</link></object>' . "\n";
365 $arr['last-child'] = 1;
367 $arr['allow_cid'] = $a->user['allow_cid'];
368 $arr['allow_gid'] = $a->user['allow_gid'];
369 $arr['deny_cid'] = $a->user['deny_cid'];
370 $arr['deny_gid'] = $a->user['deny_gid'];
372 $i = item_store($arr);
374 proc_run('php',"include/notifier.php","activity","$i");
379 function profiles_content(&$a) {
382 nav_set_selected('profiles');
385 notice( t('Permission denied.') . EOL);
389 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
390 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
395 notice( t('Profile not found.') . EOL);
396 goaway($a->get_baseurl(true) . '/profiles');
397 return; // NOTREACHED
400 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
402 // move every contact using this profile as their default to the user default
404 $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 ",
405 intval(local_user()),
409 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
414 info( t('Profile deleted.') . EOL);
416 goaway($a->get_baseurl(true) . '/profiles');
417 return; // NOTREACHED
424 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
426 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
428 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
429 intval(local_user()));
430 $num_profiles = count($r0);
432 $name = t('Profile-') . ($num_profiles + 1);
434 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
435 intval(local_user()));
437 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
438 VALUES ( %d, '%s', '%s', '%s', '%s' )",
439 intval(local_user()),
441 dbesc($r1[0]['name']),
442 dbesc($r1[0]['photo']),
443 dbesc($r1[0]['thumb'])
446 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
447 intval(local_user()),
451 info( t('New profile created.') . EOL);
453 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
455 goaway($a->get_baseurl(true) . '/profiles');
458 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
460 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
462 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
463 intval(local_user()));
464 $num_profiles = count($r0);
466 $name = t('Profile-') . ($num_profiles + 1);
467 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
468 intval(local_user()),
472 notice( t('Profile unavailable to clone.') . EOL);
476 $r1[0]['is-default'] = 0;
477 $r1[0]['publish'] = 0;
478 $r1[0]['net-publish'] = 0;
479 $r1[0]['profile-name'] = dbesc($name);
483 $r2 = dbq("INSERT INTO `profile` (`"
484 . implode("`, `", array_keys($r1[0]))
486 . implode("', '", array_values($r1[0]))
489 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
490 intval(local_user()),
493 info( t('New profile created.') . EOL);
495 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
497 goaway($a->get_baseurl(true) . '/profiles');
499 return; // NOTREACHED
503 if(($a->argc > 1) && (intval($a->argv[1]))) {
504 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
509 notice( t('Profile not found.') . EOL);
513 profile_load($a,$a->user['nickname'],$r[0]['id']);
515 require_once('include/profile_selectors.php');
518 $editselect = 'textareas';
519 if(intval(get_pconfig(local_user(),'system','plaintext')))
520 $editselect = 'none';
522 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
523 '$baseurl' => $a->get_baseurl(true),
524 '$editselect' => $editselect,
528 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
529 $hide_friends = replace_macros($opt_tpl,array(
530 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
531 '$yes_str' => t('Yes'),
532 '$no_str' => t('No'),
533 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
534 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
537 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
543 $f = get_config('system','birthday_input_format');
547 $is_default = (($r[0]['is-default']) ? 1 : 0);
548 $tpl = get_markup_template("profile_edit.tpl");
549 $o .= replace_macros($tpl,array(
550 '$form_security_token' => get_form_security_token("profile_edit"),
551 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
552 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
553 '$banner' => t('Edit Profile Details'),
554 '$submit' => t('Submit'),
555 '$viewprof' => t('View this profile'),
556 '$cr_prof' => t('Create a new profile using these settings'),
557 '$cl_prof' => t('Clone this profile'),
558 '$del_prof' => t('Delete this profile'),
559 '$lbl_profname' => t('Profile Name:'),
560 '$lbl_fullname' => t('Your Full Name:'),
561 '$lbl_title' => t('Title/Description:'),
562 '$lbl_gender' => t('Your Gender:'),
563 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
564 '$lbl_address' => t('Street Address:'),
565 '$lbl_city' => t('Locality/City:'),
566 '$lbl_zip' => t('Postal/Zip Code:'),
567 '$lbl_country' => t('Country:'),
568 '$lbl_region' => t('Region/State:'),
569 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
570 '$lbl_with' => t("Who: \x28if applicable\x29"),
571 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
572 '$lbl_howlong' => t('Since [date]:'),
573 '$lbl_sexual' => t('Sexual Preference:'),
574 '$lbl_homepage' => t('Homepage URL:'),
575 '$lbl_hometown' => t('Hometown:'),
576 '$lbl_politic' => t('Political Views:'),
577 '$lbl_religion' => t('Religious Views:'),
578 '$lbl_pubkey' => t('Public Keywords:'),
579 '$lbl_prvkey' => t('Private Keywords:'),
580 '$lbl_ex2' => t('Example: fishing photography software'),
581 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
582 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
583 '$lbl_about' => t('Tell us about yourself...'),
584 '$lbl_hobbies' => t('Hobbies/Interests'),
585 '$lbl_social' => t('Contact information and Social Networks'),
586 '$lbl_music' => t('Musical interests'),
587 '$lbl_book' => t('Books, literature'),
588 '$lbl_tv' => t('Television'),
589 '$lbl_film' => t('Film/dance/culture/entertainment'),
590 '$lbl_love' => t('Love/romance'),
591 '$lbl_work' => t('Work/employment'),
592 '$lbl_school' => t('School/education'),
593 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
594 '$baseurl' => $a->get_baseurl(true),
595 '$profile_id' => $r[0]['id'],
596 '$profile_name' => $r[0]['profile-name'],
597 '$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>' : ""),
598 '$name' => $r[0]['name'],
599 '$pdesc' => $r[0]['pdesc'],
600 '$dob' => dob($r[0]['dob']),
601 '$hide_friends' => $hide_friends,
602 '$address' => $r[0]['address'],
603 '$locality' => $r[0]['locality'],
604 '$region' => $r[0]['region'],
605 '$postal_code' => $r[0]['postal-code'],
606 '$country_name' => $r[0]['country-name'],
607 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
608 '$gender' => gender_selector($r[0]['gender']),
609 '$marital' => marital_selector($r[0]['marital']),
610 '$with' => strip_tags($r[0]['with']),
611 '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])),
612 '$sexual' => sexpref_selector($r[0]['sexual']),
613 '$about' => $r[0]['about'],
614 '$homepage' => $r[0]['homepage'],
615 '$hometown' => $r[0]['hometown'],
616 '$politic' => $r[0]['politic'],
617 '$religion' => $r[0]['religion'],
618 '$pub_keywords' => $r[0]['pub_keywords'],
619 '$prv_keywords' => $r[0]['prv_keywords'],
620 '$music' => $r[0]['music'],
621 '$book' => $r[0]['book'],
622 '$tv' => $r[0]['tv'],
623 '$film' => $r[0]['film'],
624 '$interest' => $r[0]['interest'],
625 '$romance' => $r[0]['romance'],
626 '$work' => $r[0]['work'],
627 '$education' => $r[0]['education'],
628 '$contact' => $r[0]['contact']
631 $arr = array('profile' => $r[0], 'entry' => $o);
632 call_hooks('profile_edit', $arr);
638 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
642 $tpl_header = get_markup_template('profile_listing_header.tpl');
643 $o .= replace_macros($tpl_header,array(
644 '$header' => t('Edit/Manage Profiles'),
645 '$chg_photo' => t('Change profile photo'),
646 '$cr_new' => t('Create New Profile'),
647 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
651 $tpl = get_markup_template('profile_entry.tpl');
654 $o .= replace_macros($tpl, array(
655 '$photo' => $rr['thumb'],
657 '$alt' => t('Profile Image'),
658 '$profile_name' => $rr['profile-name'],
659 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
660 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')