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)
54 $pdesc = notags(trim($_POST['pdesc']));
55 $gender = notags(trim($_POST['gender']));
56 $address = notags(trim($_POST['address']));
57 $locality = notags(trim($_POST['locality']));
58 $region = notags(trim($_POST['region']));
59 $postal_code = notags(trim($_POST['postal_code']));
60 $country_name = notags(trim($_POST['country_name']));
61 $pub_keywords = notags(trim($_POST['pub_keywords']));
62 $prv_keywords = notags(trim($_POST['prv_keywords']));
63 $marital = notags(trim($_POST['marital']));
64 if($marital != $orig[0]['marital'])
65 $maritalchanged = true;
67 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
69 // linkify the relationship target if applicable
72 if($with != strip_tags($orig[0]['with'])) {
75 if(strpos($lookup,'@') === 0)
76 $lookup = substr($lookup,1);
77 $lookup = str_replace('_',' ', $lookup);
78 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
80 $links = @lrdd($lookup);
82 foreach($links as $link) {
83 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
84 $prf = $link['@attributes']['href'];
91 if(strstr($lookup,' ')) {
92 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
98 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
105 $newname = $r[0]['name'];
110 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
111 if(strpos($with,'@') === 0)
112 $with = substr($with,1);
116 $with = $orig[0]['with'];
119 $sexual = notags(trim($_POST['sexual']));
120 $homepage = notags(trim($_POST['homepage']));
121 $politic = notags(trim($_POST['politic']));
122 $religion = notags(trim($_POST['religion']));
124 $about = fix_mce_lf(escape_tags(trim($_POST['about'])));
125 $interest = fix_mce_lf(escape_tags(trim($_POST['interest'])));
126 $contact = fix_mce_lf(escape_tags(trim($_POST['contact'])));
127 $music = fix_mce_lf(escape_tags(trim($_POST['music'])));
128 $book = fix_mce_lf(escape_tags(trim($_POST['book'])));
129 $tv = fix_mce_lf(escape_tags(trim($_POST['tv'])));
130 $film = fix_mce_lf(escape_tags(trim($_POST['film'])));
131 $romance = fix_mce_lf(escape_tags(trim($_POST['romance'])));
132 $work = fix_mce_lf(escape_tags(trim($_POST['work'])));
133 $education = fix_mce_lf(escape_tags(trim($_POST['education'])));
135 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
137 $r = q("UPDATE `profile`
138 SET `profile-name` = '%s',
146 `postal-code` = '%s',
147 `country-name` = '%s',
154 `pub_keywords` = '%s',
155 `prv_keywords` = '%s',
167 WHERE `id` = %d AND `uid` = %d LIMIT 1",
168 dbesc($profile_name),
177 dbesc($country_name),
184 dbesc($pub_keywords),
185 dbesc($prv_keywords),
196 intval($hide_friends),
198 intval($_SESSION['uid'])
202 info( t('Profile updated.') . EOL);
205 if($namechanged && $is_default) {
206 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
207 dbesc(datetime_convert()),
213 // Update global directory in background
214 $url = $_SESSION['my_url'];
215 if($url && strlen(get_config('system','directory_submit_url')))
216 proc_run('php',"include/directory.php","$url");
218 require_once('include/profile_update.php');
227 function profiles_content(&$a) {
230 nav_set_selected('profiles');
233 notice( t('Permission denied.') . EOL);
237 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
238 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
243 notice( t('Profile not found.') . EOL);
244 goaway($a->get_baseurl(true) . '/profiles');
245 return; // NOTREACHED
248 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
250 // move every contact using this profile as their default to the user default
252 $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 ",
253 intval(local_user()),
257 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
262 info( t('Profile deleted.') . EOL);
264 goaway($a->get_baseurl(true) . '/profiles');
265 return; // NOTREACHED
272 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
274 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
276 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
277 intval(local_user()));
278 $num_profiles = count($r0);
280 $name = t('Profile-') . ($num_profiles + 1);
282 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
283 intval(local_user()));
285 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
286 VALUES ( %d, '%s', '%s', '%s', '%s' )",
287 intval(local_user()),
289 dbesc($r1[0]['name']),
290 dbesc($r1[0]['photo']),
291 dbesc($r1[0]['thumb'])
294 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
295 intval(local_user()),
299 info( t('New profile created.') . EOL);
301 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
303 goaway($a->get_baseurl(true) . '/profiles');
306 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
308 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
310 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
311 intval(local_user()));
312 $num_profiles = count($r0);
314 $name = t('Profile-') . ($num_profiles + 1);
315 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
316 intval(local_user()),
320 notice( t('Profile unavailable to clone.') . EOL);
324 $r1[0]['is-default'] = 0;
325 $r1[0]['publish'] = 0;
326 $r1[0]['net-publish'] = 0;
327 $r1[0]['profile-name'] = dbesc($name);
331 $r2 = dbq("INSERT INTO `profile` (`"
332 . implode("`, `", array_keys($r1[0]))
334 . implode("', '", array_values($r1[0]))
337 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
338 intval(local_user()),
341 info( t('New profile created.') . EOL);
343 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
345 goaway($a->get_baseurl(true) . '/profiles');
347 return; // NOTREACHED
351 if(($a->argc > 1) && (intval($a->argv[1]))) {
352 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
357 notice( t('Profile not found.') . EOL);
361 profile_load($a,$a->user['nickname'],$r[0]['id']);
363 require_once('include/profile_selectors.php');
365 $tpl = get_markup_template('profed_head.tpl');
367 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
368 $hide_friends = replace_macros($opt_tpl,array(
369 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
370 '$yes_str' => t('Yes'),
371 '$no_str' => t('No'),
372 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
373 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
377 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true)));
378 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
380 $f = get_config('system','birthday_input_format');
384 $is_default = (($r[0]['is-default']) ? 1 : 0);
385 $tpl = get_markup_template("profile_edit.tpl");
386 $o .= replace_macros($tpl,array(
387 '$form_security_token' => get_form_security_token("profile_edit"),
388 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
389 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
390 '$banner' => t('Edit Profile Details'),
391 '$submit' => t('Submit'),
392 '$viewprof' => t('View this profile'),
393 '$cr_prof' => t('Create a new profile using these settings'),
394 '$cl_prof' => t('Clone this profile'),
395 '$del_prof' => t('Delete this profile'),
396 '$lbl_profname' => t('Profile Name:'),
397 '$lbl_fullname' => t('Your Full Name:'),
398 '$lbl_title' => t('Title/Description:'),
399 '$lbl_gender' => t('Your Gender:'),
400 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
401 '$lbl_address' => t('Street Address:'),
402 '$lbl_city' => t('Locality/City:'),
403 '$lbl_zip' => t('Postal/Zip Code:'),
404 '$lbl_country' => t('Country:'),
405 '$lbl_region' => t('Region/State:'),
406 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
407 '$lbl_with' => t("Who: \x28if applicable\x29"),
408 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
409 '$lbl_sexual' => t('Sexual Preference:'),
410 '$lbl_homepage' => t('Homepage URL:'),
411 '$lbl_politic' => t('Political Views:'),
412 '$lbl_religion' => t('Religious Views:'),
413 '$lbl_pubkey' => t('Public Keywords:'),
414 '$lbl_prvkey' => t('Private Keywords:'),
415 '$lbl_ex2' => t('Example: fishing photography software'),
416 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
417 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
418 '$lbl_about' => t('Tell us about yourself...'),
419 '$lbl_hobbies' => t('Hobbies/Interests'),
420 '$lbl_social' => t('Contact information and Social Networks'),
421 '$lbl_music' => t('Musical interests'),
422 '$lbl_book' => t('Books, literature'),
423 '$lbl_tv' => t('Television'),
424 '$lbl_film' => t('Film/dance/culture/entertainment'),
425 '$lbl_love' => t('Love/romance'),
426 '$lbl_work' => t('Work/employment'),
427 '$lbl_school' => t('School/education'),
428 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
429 '$baseurl' => $a->get_baseurl(true),
430 '$profile_id' => $r[0]['id'],
431 '$profile_name' => $r[0]['profile-name'],
432 '$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>' : ""),
433 '$name' => $r[0]['name'],
434 '$pdesc' => $r[0]['pdesc'],
435 '$dob' => dob($r[0]['dob']),
436 '$hide_friends' => $hide_friends,
437 '$address' => $r[0]['address'],
438 '$locality' => $r[0]['locality'],
439 '$region' => $r[0]['region'],
440 '$postal_code' => $r[0]['postal-code'],
441 '$country_name' => $r[0]['country-name'],
442 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
443 '$gender' => gender_selector($r[0]['gender']),
444 '$marital' => marital_selector($r[0]['marital']),
445 '$with' => strip_tags($r[0]['with']),
446 '$sexual' => sexpref_selector($r[0]['sexual']),
447 '$about' => $r[0]['about'],
448 '$homepage' => $r[0]['homepage'],
449 '$politic' => $r[0]['politic'],
450 '$religion' => $r[0]['religion'],
451 '$pub_keywords' => $r[0]['pub_keywords'],
452 '$prv_keywords' => $r[0]['prv_keywords'],
453 '$music' => $r[0]['music'],
454 '$book' => $r[0]['book'],
455 '$tv' => $r[0]['tv'],
456 '$film' => $r[0]['film'],
457 '$interest' => $r[0]['interest'],
458 '$romance' => $r[0]['romance'],
459 '$work' => $r[0]['work'],
460 '$education' => $r[0]['education'],
461 '$contact' => $r[0]['contact']
464 $arr = array('profile' => $r[0], 'entry' => $o);
465 call_hooks('profile_edit', $arr);
471 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
475 $tpl_header = get_markup_template('profile_listing_header.tpl');
476 $o .= replace_macros($tpl_header,array(
477 '$header' => t('Edit/Manage Profiles'),
478 '$chg_photo' => t('Change profile photo'),
479 '$cr_new' => t('Create New Profile'),
480 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
484 $tpl = get_markup_template('profile_entry.tpl');
487 $o .= replace_macros($tpl, array(
488 '$photo' => $rr['thumb'],
490 '$alt' => t('Profile Image'),
491 '$profile_name' => $rr['profile-name'],
492 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
493 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')