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 = escape_tags(trim($_POST['about']));
125 $interest = escape_tags(trim($_POST['interest']));
126 $contact = escape_tags(trim($_POST['contact']));
127 $music = escape_tags(trim($_POST['music']));
128 $book = escape_tags(trim($_POST['book']));
129 $tv = escape_tags(trim($_POST['tv']));
130 $film = escape_tags(trim($_POST['film']));
131 $romance = escape_tags(trim($_POST['romance']));
132 $work = escape_tags(trim($_POST['work']));
133 $education = escape_tags(trim($_POST['education']));
134 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
136 $r = q("UPDATE `profile`
137 SET `profile-name` = '%s',
145 `postal-code` = '%s',
146 `country-name` = '%s',
153 `pub_keywords` = '%s',
154 `prv_keywords` = '%s',
166 WHERE `id` = %d AND `uid` = %d LIMIT 1",
167 dbesc($profile_name),
176 dbesc($country_name),
183 dbesc($pub_keywords),
184 dbesc($prv_keywords),
195 intval($hide_friends),
197 intval($_SESSION['uid'])
201 info( t('Profile updated.') . EOL);
204 if($namechanged && $is_default) {
205 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
206 dbesc(datetime_convert()),
212 // Update global directory in background
213 $url = $_SESSION['my_url'];
214 if($url && strlen(get_config('system','directory_submit_url')))
215 proc_run('php',"include/directory.php","$url");
217 require_once('include/profile_update.php');
226 function profiles_content(&$a) {
229 nav_set_selected('profiles');
232 notice( t('Permission denied.') . EOL);
236 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
237 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
242 notice( t('Profile not found.') . EOL);
243 goaway($a->get_baseurl(true) . '/profiles');
244 return; // NOTREACHED
247 check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't');
249 // move every contact using this profile as their default to the user default
251 $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 ",
252 intval(local_user()),
256 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
261 info( t('Profile deleted.') . EOL);
263 goaway($a->get_baseurl(true) . '/profiles');
264 return; // NOTREACHED
271 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
273 check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
275 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
276 intval(local_user()));
277 $num_profiles = count($r0);
279 $name = t('Profile-') . ($num_profiles + 1);
281 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
282 intval(local_user()));
284 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
285 VALUES ( %d, '%s', '%s', '%s', '%s' )",
286 intval(local_user()),
288 dbesc($r1[0]['name']),
289 dbesc($r1[0]['photo']),
290 dbesc($r1[0]['thumb'])
293 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
294 intval(local_user()),
298 info( t('New profile created.') . EOL);
300 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
302 goaway($a->get_baseurl(true) . '/profiles');
305 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
307 check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't');
309 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
310 intval(local_user()));
311 $num_profiles = count($r0);
313 $name = t('Profile-') . ($num_profiles + 1);
314 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
315 intval(local_user()),
319 notice( t('Profile unavailable to clone.') . EOL);
323 $r1[0]['is-default'] = 0;
324 $r1[0]['publish'] = 0;
325 $r1[0]['net-publish'] = 0;
326 $r1[0]['profile-name'] = dbesc($name);
330 $r2 = dbq("INSERT INTO `profile` (`"
331 . implode("`, `", array_keys($r1[0]))
333 . implode("', '", array_values($r1[0]))
336 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
337 intval(local_user()),
340 info( t('New profile created.') . EOL);
342 goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']);
344 goaway($a->get_baseurl(true) . '/profiles');
346 return; // NOTREACHED
350 if(($a->argc > 1) && (intval($a->argv[1]))) {
351 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
356 notice( t('Profile not found.') . EOL);
360 profile_load($a,$a->user['nickname'],$r[0]['id']);
362 require_once('include/profile_selectors.php');
364 $tpl = get_markup_template('profed_head.tpl');
366 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
367 $hide_friends = replace_macros($opt_tpl,array(
368 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
369 '$yes_str' => t('Yes'),
370 '$no_str' => t('No'),
371 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
372 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
376 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl(true)));
377 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"js/country.js\" ></script>";
379 $f = get_config('system','birthday_input_format');
383 $is_default = (($r[0]['is-default']) ? 1 : 0);
384 $tpl = get_markup_template("profile_edit.tpl");
385 $o .= replace_macros($tpl,array(
386 '$form_security_token' => get_form_security_token("profile_edit"),
387 '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_clone"),
388 '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"),
389 '$banner' => t('Edit Profile Details'),
390 '$submit' => t('Submit'),
391 '$viewprof' => t('View this profile'),
392 '$cr_prof' => t('Create a new profile using these settings'),
393 '$cl_prof' => t('Clone this profile'),
394 '$del_prof' => t('Delete this profile'),
395 '$lbl_profname' => t('Profile Name:'),
396 '$lbl_fullname' => t('Your Full Name:'),
397 '$lbl_title' => t('Title/Description:'),
398 '$lbl_gender' => t('Your Gender:'),
399 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
400 '$lbl_address' => t('Street Address:'),
401 '$lbl_city' => t('Locality/City:'),
402 '$lbl_zip' => t('Postal/Zip Code:'),
403 '$lbl_country' => t('Country:'),
404 '$lbl_region' => t('Region/State:'),
405 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
406 '$lbl_with' => t("Who: \x28if applicable\x29"),
407 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
408 '$lbl_sexual' => t('Sexual Preference:'),
409 '$lbl_homepage' => t('Homepage URL:'),
410 '$lbl_politic' => t('Political Views:'),
411 '$lbl_religion' => t('Religious Views:'),
412 '$lbl_pubkey' => t('Public Keywords:'),
413 '$lbl_prvkey' => t('Private Keywords:'),
414 '$lbl_ex2' => t('Example: fishing photography software'),
415 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
416 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
417 '$lbl_about' => t('Tell us about yourself...'),
418 '$lbl_hobbies' => t('Hobbies/Interests'),
419 '$lbl_social' => t('Contact information and Social Networks'),
420 '$lbl_music' => t('Musical interests'),
421 '$lbl_book' => t('Books, literature'),
422 '$lbl_tv' => t('Television'),
423 '$lbl_film' => t('Film/dance/culture/entertainment'),
424 '$lbl_love' => t('Love/romance'),
425 '$lbl_work' => t('Work/employment'),
426 '$lbl_school' => t('School/education'),
427 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
428 '$baseurl' => $a->get_baseurl(true),
429 '$profile_id' => $r[0]['id'],
430 '$profile_name' => $r[0]['profile-name'],
431 '$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>' : ""),
432 '$name' => $r[0]['name'],
433 '$pdesc' => $r[0]['pdesc'],
434 '$dob' => dob($r[0]['dob']),
435 '$hide_friends' => $hide_friends,
436 '$address' => $r[0]['address'],
437 '$locality' => $r[0]['locality'],
438 '$region' => $r[0]['region'],
439 '$postal_code' => $r[0]['postal-code'],
440 '$country_name' => $r[0]['country-name'],
441 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
442 '$gender' => gender_selector($r[0]['gender']),
443 '$marital' => marital_selector($r[0]['marital']),
444 '$with' => strip_tags($r[0]['with']),
445 '$sexual' => sexpref_selector($r[0]['sexual']),
446 '$about' => $r[0]['about'],
447 '$homepage' => $r[0]['homepage'],
448 '$politic' => $r[0]['politic'],
449 '$religion' => $r[0]['religion'],
450 '$pub_keywords' => $r[0]['pub_keywords'],
451 '$prv_keywords' => $r[0]['prv_keywords'],
452 '$music' => $r[0]['music'],
453 '$book' => $r[0]['book'],
454 '$tv' => $r[0]['tv'],
455 '$film' => $r[0]['film'],
456 '$interest' => $r[0]['interest'],
457 '$romance' => $r[0]['romance'],
458 '$work' => $r[0]['work'],
459 '$education' => $r[0]['education'],
460 '$contact' => $r[0]['contact']
463 $arr = array('profile' => $r[0], 'entry' => $o);
464 call_hooks('profile_edit', $arr);
470 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
474 $tpl_header = get_markup_template('profile_listing_header.tpl');
475 $o .= replace_macros($tpl_header,array(
476 '$header' => t('Edit/Manage Profiles'),
477 '$chg_photo' => t('Change profile photo'),
478 '$cr_new' => t('Create New Profile'),
479 '$cr_new_link' => 'profiles/new?t=' . get_form_security_token("profile_new")
483 $tpl = get_markup_template('profile_entry.tpl');
486 $o .= replace_macros($tpl, array(
487 '$photo' => $rr['thumb'],
489 '$alt' => t('Profile Image'),
490 '$profile_name' => $rr['profile-name'],
491 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
492 : '<a href="' . $a->get_baseurl(true) . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')