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']));
66 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
68 // linkify the relationship target if applicable
73 if($with != strip_tags($orig[0]['with'])) {
77 if(strpos($lookup,'@') === 0)
78 $lookup = substr($lookup,1);
79 $lookup = str_replace('_',' ', $lookup);
80 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
82 $links = @lrdd($lookup);
84 foreach($links as $link) {
85 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
86 $prf = $link['@attributes']['href'];
93 if(strstr($lookup,' ')) {
94 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
100 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
107 $newname = $r[0]['name'];
112 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
113 if(strpos($with,'@') === 0)
114 $with = substr($with,1);
118 $with = $orig[0]['with'];
121 $sexual = notags(trim($_POST['sexual']));
122 $homepage = notags(trim($_POST['homepage']));
123 $politic = notags(trim($_POST['politic']));
124 $religion = notags(trim($_POST['religion']));
126 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
127 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
128 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
129 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
130 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
131 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
132 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
133 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
134 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
135 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
137 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
144 if($marital != $orig[0]['marital']) {
145 $changes[] = '[color=#ff0000]♥[/color] ' . t('Marital Status');
149 $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner');
150 $value = strip_tags($with);
152 if($work != $orig[0]['work']) {
153 $changes[] = t('Work/Employment');
155 if($religion != $orig[0]['religion']) {
156 $changes[] = t('Religion');
159 if($politic != $orig[0]['politic']) {
160 $changes[] = t('Political Views');
163 if($gender != $orig[0]['gender']) {
164 $changes[] = t('Gender');
167 if($sexual != $orig[0]['sexual']) {
168 $changes[] = t('Sexual Preference');
171 if($homepage != $orig[0]['homepage']) {
172 $changes[] = t('Homepage');
175 if($interest != $orig[0]['interest']) {
176 $changes[] = t('Interests');
179 if($address != $orig[0]['address']) {
180 $changes[] = t('Address');
181 // New address not sent in notifications, potential privacy issues
182 // in case this leaks to unintended recipients. Yes, it's in the public
183 // profile but that doesn't mean we have to broadcast it to everybody.
185 if($locality != $orig[0]['locality'] || $region != $orig[0]['region']
186 || $country_name != $orig[0]['country-name']) {
187 $changes[] = t('Location');
188 $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' ');
189 $comma2 = (($region && $country_name) ? ', ' : '');
190 $value = $locality . $comma1 . $region . $comma2 . $country_name;
193 profile_activity($changes,$value);
197 $r = q("UPDATE `profile`
198 SET `profile-name` = '%s',
206 `postal-code` = '%s',
207 `country-name` = '%s',
214 `pub_keywords` = '%s',
215 `prv_keywords` = '%s',
227 WHERE `id` = %d AND `uid` = %d LIMIT 1",
228 dbesc($profile_name),
237 dbesc($country_name),
244 dbesc($pub_keywords),
245 dbesc($prv_keywords),
256 intval($hide_friends),
262 info( t('Profile updated.') . EOL);
265 if($namechanged && $is_default) {
266 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
267 dbesc(datetime_convert()),
273 // Update global directory in background
274 $url = $_SESSION['my_url'];
275 if($url && strlen(get_config('system','directory_submit_url')))
276 proc_run('php',"include/directory.php","$url");
278 require_once('include/profile_update.php');
285 function profile_activity($changed, $value) {
288 if(! local_user() || ! is_array($changed) || ! count($changed))
291 if($a->user['hidewall'] || get_config('system','block_public'))
294 if(! get_pconfig(local_user(),'system','post_profilechange'))
297 require_once('include/items.php');
299 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
307 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
308 $arr['uid'] = local_user();
309 $arr['contact-id'] = $self[0]['id'];
311 $arr['type'] = 'wall';
314 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
315 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
316 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
317 $arr['verb'] = ACTIVITY_UPDATE;
318 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
320 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
324 $t = count($changed);
326 foreach($changed as $ch) {
327 if(strlen($changes)) {
329 $changes .= t(' and ');
337 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
339 if($t == 1 && strlen($value)) {
340 $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value);
341 $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
344 $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
347 $arr['body'] = $message;
349 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
350 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
351 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
352 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
353 $arr['object'] .= '</link></object>' . "\n";
354 $arr['last-child'] = 1;
356 $arr['allow_cid'] = $a->user['allow_cid'];
357 $arr['allow_gid'] = $a->user['allow_gid'];
358 $arr['deny_cid'] = $a->user['deny_cid'];
359 $arr['deny_gid'] = $a->user['deny_gid'];
361 $i = item_store($arr);
363 proc_run('php',"include/notifier.php","activity","$i");
368 function profiles_content(&$a) {
371 nav_set_selected('profiles');
374 notice( t('Permission denied.') . EOL);
378 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
379 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
384 notice( t('Profile not found.') . EOL);
385 goaway($a->get_baseurl(true) . '/profiles');
386 return; // NOTREACHED
389 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
391 // move every contact using this profile as their default to the user default
393 $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 ",
394 intval(local_user()),
398 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
403 info( t('Profile deleted.') . EOL);
405 goaway($a->get_baseurl(true) . '/profiles');
406 return; // NOTREACHED
413 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
415 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
417 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
418 intval(local_user()));
419 $num_profiles = count($r0);
421 $name = t('Profile-') . ($num_profiles + 1);
423 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
424 intval(local_user()));
426 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
427 VALUES ( %d, '%s', '%s', '%s', '%s' )",
428 intval(local_user()),
430 dbesc($r1[0]['name']),
431 dbesc($r1[0]['photo']),
432 dbesc($r1[0]['thumb'])
435 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
436 intval(local_user()),
440 info( t('New profile created.') . EOL);
442 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
444 goaway($a->get_baseurl(true) . '/profiles');
447 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
449 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
451 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
452 intval(local_user()));
453 $num_profiles = count($r0);
455 $name = t('Profile-') . ($num_profiles + 1);
456 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
457 intval(local_user()),
461 notice( t('Profile unavailable to clone.') . EOL);
465 $r1[0]['is-default'] = 0;
466 $r1[0]['publish'] = 0;
467 $r1[0]['net-publish'] = 0;
468 $r1[0]['profile-name'] = dbesc($name);
472 $r2 = dbq("INSERT INTO `profile` (`"
473 . implode("`, `", array_keys($r1[0]))
475 . implode("', '", array_values($r1[0]))
478 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
479 intval(local_user()),
482 info( t('New profile created.') . EOL);
484 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
486 goaway($a->get_baseurl(true) . '/profiles');
488 return; // NOTREACHED
492 if(($a->argc > 1) && (intval($a->argv[1]))) {
493 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
498 notice( t('Profile not found.') . EOL);
502 profile_load($a,$a->user['nickname'],$r[0]['id']);
504 require_once('include/profile_selectors.php');
507 $editselect = 'textareas';
508 if(intval(get_pconfig(local_user(),'system','plaintext')))
509 $editselect = 'none';
511 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
512 '$baseurl' => $a->get_baseurl(true),
513 '$editselect' => $editselect,
517 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
518 $hide_friends = replace_macros($opt_tpl,array(
519 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
520 '$yes_str' => t('Yes'),
521 '$no_str' => t('No'),
522 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
523 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
526 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
532 $f = get_config('system','birthday_input_format');
536 $is_default = (($r[0]['is-default']) ? 1 : 0);
537 $tpl = get_markup_template("profile_edit.tpl");
538 $o .= replace_macros($tpl,array(
539 '$form_security_token' => get_form_security_token("profile_edit"),
540 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
541 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
542 '$banner' => t('Edit Profile Details'),
543 '$submit' => t('Submit'),
544 '$viewprof' => t('View this profile'),
545 '$cr_prof' => t('Create a new profile using these settings'),
546 '$cl_prof' => t('Clone this profile'),
547 '$del_prof' => t('Delete this profile'),
548 '$lbl_profname' => t('Profile Name:'),
549 '$lbl_fullname' => t('Your Full Name:'),
550 '$lbl_title' => t('Title/Description:'),
551 '$lbl_gender' => t('Your Gender:'),
552 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
553 '$lbl_address' => t('Street Address:'),
554 '$lbl_city' => t('Locality/City:'),
555 '$lbl_zip' => t('Postal/Zip Code:'),
556 '$lbl_country' => t('Country:'),
557 '$lbl_region' => t('Region/State:'),
558 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
559 '$lbl_with' => t("Who: \x28if applicable\x29"),
560 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
561 '$lbl_sexual' => t('Sexual Preference:'),
562 '$lbl_homepage' => t('Homepage URL:'),
563 '$lbl_politic' => t('Political Views:'),
564 '$lbl_religion' => t('Religious Views:'),
565 '$lbl_pubkey' => t('Public Keywords:'),
566 '$lbl_prvkey' => t('Private Keywords:'),
567 '$lbl_ex2' => t('Example: fishing photography software'),
568 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
569 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
570 '$lbl_about' => t('Tell us about yourself...'),
571 '$lbl_hobbies' => t('Hobbies/Interests'),
572 '$lbl_social' => t('Contact information and Social Networks'),
573 '$lbl_music' => t('Musical interests'),
574 '$lbl_book' => t('Books, literature'),
575 '$lbl_tv' => t('Television'),
576 '$lbl_film' => t('Film/dance/culture/entertainment'),
577 '$lbl_love' => t('Love/romance'),
578 '$lbl_work' => t('Work/employment'),
579 '$lbl_school' => t('School/education'),
580 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
581 '$baseurl' => $a->get_baseurl(true),
582 '$profile_id' => $r[0]['id'],
583 '$profile_name' => $r[0]['profile-name'],
584 '$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>' : ""),
585 '$name' => $r[0]['name'],
586 '$pdesc' => $r[0]['pdesc'],
587 '$dob' => dob($r[0]['dob']),
588 '$hide_friends' => $hide_friends,
589 '$address' => $r[0]['address'],
590 '$locality' => $r[0]['locality'],
591 '$region' => $r[0]['region'],
592 '$postal_code' => $r[0]['postal-code'],
593 '$country_name' => $r[0]['country-name'],
594 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
595 '$gender' => gender_selector($r[0]['gender']),
596 '$marital' => marital_selector($r[0]['marital']),
597 '$with' => strip_tags($r[0]['with']),
598 '$sexual' => sexpref_selector($r[0]['sexual']),
599 '$about' => $r[0]['about'],
600 '$homepage' => $r[0]['homepage'],
601 '$politic' => $r[0]['politic'],
602 '$religion' => $r[0]['religion'],
603 '$pub_keywords' => $r[0]['pub_keywords'],
604 '$prv_keywords' => $r[0]['prv_keywords'],
605 '$music' => $r[0]['music'],
606 '$book' => $r[0]['book'],
607 '$tv' => $r[0]['tv'],
608 '$film' => $r[0]['film'],
609 '$interest' => $r[0]['interest'],
610 '$romance' => $r[0]['romance'],
611 '$work' => $r[0]['work'],
612 '$education' => $r[0]['education'],
613 '$contact' => $r[0]['contact']
616 $arr = array('profile' => $r[0], 'entry' => $o);
617 call_hooks('profile_edit', $arr);
623 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
627 $tpl_header = get_markup_template('profile_listing_header.tpl');
628 $o .= replace_macros($tpl_header,array(
629 '$header' => t('Edit/Manage Profiles'),
630 '$chg_photo' => t('Change profile photo'),
631 '$cr_new' => t('Create New Profile'),
632 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
636 $tpl = get_markup_template('profile_entry.tpl');
639 $o .= replace_macros($tpl, array(
640 '$photo' => $rr['thumb'],
642 '$alt' => t('Profile Image'),
643 '$profile_name' => $rr['profile-name'],
644 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
645 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')