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
71 if($with != strip_tags($orig[0]['with'])) {
74 if(strpos($lookup,'@') === 0)
75 $lookup = substr($lookup,1);
76 $lookup = str_replace('_',' ', $lookup);
77 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
79 $links = @lrdd($lookup);
81 foreach($links as $link) {
82 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
83 $prf = $link['@attributes']['href'];
90 if(strstr($lookup,' ')) {
91 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
97 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
104 $newname = $r[0]['name'];
109 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
110 if(strpos($with,'@') === 0)
111 $with = substr($with,1);
115 $with = $orig[0]['with'];
118 $sexual = notags(trim($_POST['sexual']));
119 $homepage = notags(trim($_POST['homepage']));
120 $politic = notags(trim($_POST['politic']));
121 $religion = notags(trim($_POST['religion']));
123 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
124 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
125 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
126 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
127 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
128 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
129 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
130 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
131 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
132 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
134 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
140 if($marital != $orig[0]['marital']) $changes[] = '♥ ' . t('Marital Status');
141 if($work != $orig[0]['work']) $changes[] = t('Work/Employment');
142 if($religion != $orig[0]['religion']) $changes[] = t('Religion');
143 if($politic != $orig[0]['politic']) $changes[] = t('Political Views');
145 if($address != $orig[0]['address'] || $locality != $orig[0]['locality'] || $region != $orig[0]['region']
146 || $country_name != $orig[0]['country_name'])
147 $changes[] = t('Location');
149 profile_activity($changes);
153 $r = q("UPDATE `profile`
154 SET `profile-name` = '%s',
162 `postal-code` = '%s',
163 `country-name` = '%s',
170 `pub_keywords` = '%s',
171 `prv_keywords` = '%s',
183 WHERE `id` = %d AND `uid` = %d LIMIT 1",
184 dbesc($profile_name),
193 dbesc($country_name),
200 dbesc($pub_keywords),
201 dbesc($prv_keywords),
212 intval($hide_friends),
218 info( t('Profile updated.') . EOL);
221 if($namechanged && $is_default) {
222 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
223 dbesc(datetime_convert()),
229 // Update global directory in background
230 $url = $_SESSION['my_url'];
231 if($url && strlen(get_config('system','directory_submit_url')))
232 proc_run('php',"include/directory.php","$url");
234 require_once('include/profile_update.php');
241 function profile_activity($changed) {
244 if(! local_user() || ! is_array($changed) || ! count($changed))
247 if($a->user['hidewall'] || get_config('system','block_public'))
250 if(! get_pconfig(local_user(),'system','post_profilechange'))
253 require_once('include/items.php');
255 $self = q("SELECT * FROM `contact` WHERE `self` = 1 AND `uid` = %d LIMIT 1",
263 $arr['uri'] = $arr['parent-uri'] = item_new_uri($a->get_hostname(), local_user());
264 $arr['uid'] = local_user();
265 $arr['contact-id'] = $self[0]['id'];
267 $arr['type'] = 'wall';
270 $arr['author-name'] = $arr['owner-name'] = $self[0]['name'];
271 $arr['author-link'] = $arr['owner-link'] = $self[0]['url'];
272 $arr['author-avatar'] = $arr['owner-avatar'] = $self[0]['thumb'];
273 $arr['verb'] = ACTIVITY_UPDATE;
274 $arr['object-type'] = ACTIVITY_OBJ_PROFILE;
276 $A = '[url=' . $self[0]['url'] . ']' . $self[0]['name'] . '[/url]';
280 $t = count($changed);
282 foreach($changed as $ch) {
283 if(strlen($changes)) {
293 $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]';
295 $arr['body'] = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
297 $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PROFILE . '</type><title>' . $self[0]['name'] . '</title>'
298 . '<id>' . $self[0]['url'] . '/' . $self[0]['name'] . '</id>';
299 $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $self[0]['url'] . '?tab=profile' . '" />' . "\n");
300 $arr['object'] .= xmlify('<link rel="photo" type="image/jpeg" href="' . $self[0]['thumb'] . '" />' . "\n");
301 $arr['object'] .= '</link></object>' . "\n";
302 $arr['last-child'] = 1;
304 $arr['allow_cid'] = $a->user['allow_cid'];
305 $arr['allow_gid'] = $a->user['allow_gid'];
306 $arr['deny_cid'] = $a->user['deny_cid'];
307 $arr['deny_gid'] = $a->user['deny_gid'];
309 $i = item_store($arr);
311 proc_run('php',"include/notifier.php","activity","$i");
316 function profiles_content(&$a) {
319 nav_set_selected('profiles');
322 notice( t('Permission denied.') . EOL);
326 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
327 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
332 notice( t('Profile not found.') . EOL);
333 goaway($a->get_baseurl(true) . '/profiles');
334 return; // NOTREACHED
337 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
339 // move every contact using this profile as their default to the user default
341 $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 ",
342 intval(local_user()),
346 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
351 info( t('Profile deleted.') . EOL);
353 goaway($a->get_baseurl(true) . '/profiles');
354 return; // NOTREACHED
361 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
363 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
365 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
366 intval(local_user()));
367 $num_profiles = count($r0);
369 $name = t('Profile-') . ($num_profiles + 1);
371 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
372 intval(local_user()));
374 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
375 VALUES ( %d, '%s', '%s', '%s', '%s' )",
376 intval(local_user()),
378 dbesc($r1[0]['name']),
379 dbesc($r1[0]['photo']),
380 dbesc($r1[0]['thumb'])
383 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
384 intval(local_user()),
388 info( t('New profile created.') . EOL);
390 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
392 goaway($a->get_baseurl(true) . '/profiles');
395 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
397 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
399 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
400 intval(local_user()));
401 $num_profiles = count($r0);
403 $name = t('Profile-') . ($num_profiles + 1);
404 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
405 intval(local_user()),
409 notice( t('Profile unavailable to clone.') . EOL);
413 $r1[0]['is-default'] = 0;
414 $r1[0]['publish'] = 0;
415 $r1[0]['net-publish'] = 0;
416 $r1[0]['profile-name'] = dbesc($name);
420 $r2 = dbq("INSERT INTO `profile` (`"
421 . implode("`, `", array_keys($r1[0]))
423 . implode("', '", array_values($r1[0]))
426 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
427 intval(local_user()),
430 info( t('New profile created.') . EOL);
432 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
434 goaway($a->get_baseurl(true) . '/profiles');
436 return; // NOTREACHED
440 if(($a->argc > 1) && (intval($a->argv[1]))) {
441 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
446 notice( t('Profile not found.') . EOL);
450 profile_load($a,$a->user['nickname'],$r[0]['id']);
452 require_once('include/profile_selectors.php');
455 $editselect = 'textareas';
456 if(intval(get_pconfig(local_user(),'system','plaintext')))
457 $editselect = 'none';
459 $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array(
460 '$baseurl' => $a->get_baseurl(true),
461 '$editselect' => $editselect,
465 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
466 $hide_friends = replace_macros($opt_tpl,array(
467 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
468 '$yes_str' => t('Yes'),
469 '$no_str' => t('No'),
470 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
471 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
474 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
480 $f = get_config('system','birthday_input_format');
484 $is_default = (($r[0]['is-default']) ? 1 : 0);
485 $tpl = get_markup_template("profile_edit.tpl");
486 $o .= replace_macros($tpl,array(
487 '$form_security_token' => get_form_security_token("profile_edit"),
488 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
489 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
490 '$banner' => t('Edit Profile Details'),
491 '$submit' => t('Submit'),
492 '$viewprof' => t('View this profile'),
493 '$cr_prof' => t('Create a new profile using these settings'),
494 '$cl_prof' => t('Clone this profile'),
495 '$del_prof' => t('Delete this profile'),
496 '$lbl_profname' => t('Profile Name:'),
497 '$lbl_fullname' => t('Your Full Name:'),
498 '$lbl_title' => t('Title/Description:'),
499 '$lbl_gender' => t('Your Gender:'),
500 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
501 '$lbl_address' => t('Street Address:'),
502 '$lbl_city' => t('Locality/City:'),
503 '$lbl_zip' => t('Postal/Zip Code:'),
504 '$lbl_country' => t('Country:'),
505 '$lbl_region' => t('Region/State:'),
506 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
507 '$lbl_with' => t("Who: \x28if applicable\x29"),
508 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
509 '$lbl_sexual' => t('Sexual Preference:'),
510 '$lbl_homepage' => t('Homepage URL:'),
511 '$lbl_politic' => t('Political Views:'),
512 '$lbl_religion' => t('Religious Views:'),
513 '$lbl_pubkey' => t('Public Keywords:'),
514 '$lbl_prvkey' => t('Private Keywords:'),
515 '$lbl_ex2' => t('Example: fishing photography software'),
516 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
517 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
518 '$lbl_about' => t('Tell us about yourself...'),
519 '$lbl_hobbies' => t('Hobbies/Interests'),
520 '$lbl_social' => t('Contact information and Social Networks'),
521 '$lbl_music' => t('Musical interests'),
522 '$lbl_book' => t('Books, literature'),
523 '$lbl_tv' => t('Television'),
524 '$lbl_film' => t('Film/dance/culture/entertainment'),
525 '$lbl_love' => t('Love/romance'),
526 '$lbl_work' => t('Work/employment'),
527 '$lbl_school' => t('School/education'),
528 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
529 '$baseurl' => $a->get_baseurl(true),
530 '$profile_id' => $r[0]['id'],
531 '$profile_name' => $r[0]['profile-name'],
532 '$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>' : ""),
533 '$name' => $r[0]['name'],
534 '$pdesc' => $r[0]['pdesc'],
535 '$dob' => dob($r[0]['dob']),
536 '$hide_friends' => $hide_friends,
537 '$address' => $r[0]['address'],
538 '$locality' => $r[0]['locality'],
539 '$region' => $r[0]['region'],
540 '$postal_code' => $r[0]['postal-code'],
541 '$country_name' => $r[0]['country-name'],
542 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
543 '$gender' => gender_selector($r[0]['gender']),
544 '$marital' => marital_selector($r[0]['marital']),
545 '$with' => strip_tags($r[0]['with']),
546 '$sexual' => sexpref_selector($r[0]['sexual']),
547 '$about' => $r[0]['about'],
548 '$homepage' => $r[0]['homepage'],
549 '$politic' => $r[0]['politic'],
550 '$religion' => $r[0]['religion'],
551 '$pub_keywords' => $r[0]['pub_keywords'],
552 '$prv_keywords' => $r[0]['prv_keywords'],
553 '$music' => $r[0]['music'],
554 '$book' => $r[0]['book'],
555 '$tv' => $r[0]['tv'],
556 '$film' => $r[0]['film'],
557 '$interest' => $r[0]['interest'],
558 '$romance' => $r[0]['romance'],
559 '$work' => $r[0]['work'],
560 '$education' => $r[0]['education'],
561 '$contact' => $r[0]['contact']
564 $arr = array('profile' => $r[0], 'entry' => $o);
565 call_hooks('profile_edit', $arr);
571 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
575 $tpl_header = get_markup_template('profile_listing_header.tpl');
576 $o .= replace_macros($tpl_header,array(
577 '$header' => t('Edit/Manage Profiles'),
578 '$chg_photo' => t('Change profile photo'),
579 '$cr_new' => t('Create New Profile'),
580 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
584 $tpl = get_markup_template('profile_entry.tpl');
587 $o .= replace_macros($tpl, array(
588 '$photo' => $rr['thumb'],
590 '$alt' => t('Profile Image'),
591 '$profile_name' => $rr['profile-name'],
592 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
593 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')