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);
24 $is_default = (($orig[0]['is-default']) ? 1 : 0);
26 $profile_name = notags(trim($_POST['profile_name']));
27 if(! strlen($profile_name)) {
28 notify( t('Profile Name is required.') . EOL);
32 $year = intval($_POST['year']);
33 if($year < 1900 || $year > 2100 || $year < 0)
35 $month = intval($_POST['month']);
36 if(($month > 12) || ($month < 0))
38 $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31);
39 $day = intval($_POST['day']);
40 if(($day > $mtab[$month]) || ($day < 0))
43 $dob = sprintf('%04d-%02d-%02d',$year,$month,$day);
46 $name = notags(trim($_POST['name']));
48 if($orig[0]['name'] != $name)
51 $pdesc = notags(trim($_POST['pdesc']));
52 $gender = notags(trim($_POST['gender']));
53 $address = notags(trim($_POST['address']));
54 $locality = notags(trim($_POST['locality']));
55 $region = notags(trim($_POST['region']));
56 $postal_code = notags(trim($_POST['postal_code']));
57 $country_name = notags(trim($_POST['country_name']));
58 $pub_keywords = notags(trim($_POST['pub_keywords']));
59 $prv_keywords = notags(trim($_POST['prv_keywords']));
60 $marital = notags(trim($_POST['marital']));
61 if($marital != $orig[0]['marital'])
62 $maritalchanged = true;
64 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
66 // linkify the relationship target if applicable
69 if($with != strip_tags($orig[0]['with'])) {
72 if(strpos($lookup,'@') === 0)
73 $lookup = substr($lookup,1);
74 $lookup = str_replace('_',' ', $lookup);
75 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
77 $links = @lrdd($lookup);
79 foreach($links as $link) {
80 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
81 $prf = $link['@attributes']['href'];
88 if(strstr($lookup,' ')) {
89 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
95 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
102 $newname = $r[0]['name'];
107 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
108 if(strpos($with,'@') === 0)
109 $with = substr($with,1);
113 $with = $orig[0]['with'];
116 $sexual = notags(trim($_POST['sexual']));
117 $homepage = notags(trim($_POST['homepage']));
118 $politic = notags(trim($_POST['politic']));
119 $religion = notags(trim($_POST['religion']));
121 $about = escape_tags(trim($_POST['about']));
122 $interest = escape_tags(trim($_POST['interest']));
123 $contact = escape_tags(trim($_POST['contact']));
124 $music = escape_tags(trim($_POST['music']));
125 $book = escape_tags(trim($_POST['book']));
126 $tv = escape_tags(trim($_POST['tv']));
127 $film = escape_tags(trim($_POST['film']));
128 $romance = escape_tags(trim($_POST['romance']));
129 $work = escape_tags(trim($_POST['work']));
130 $education = escape_tags(trim($_POST['education']));
131 $hide_friends = (($_POST['hide-friends'] == 1) ? 1: 0);
133 $r = q("UPDATE `profile`
134 SET `profile-name` = '%s',
142 `postal-code` = '%s',
143 `country-name` = '%s',
150 `pub_keywords` = '%s',
151 `prv_keywords` = '%s',
163 WHERE `id` = %d AND `uid` = %d LIMIT 1",
164 dbesc($profile_name),
173 dbesc($country_name),
180 dbesc($pub_keywords),
181 dbesc($prv_keywords),
192 intval($hide_friends),
194 intval($_SESSION['uid'])
198 info( t('Profile updated.') . EOL);
201 if($namechanged && $is_default) {
202 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
203 dbesc(datetime_convert()),
209 // Update global directory in background
210 $url = $_SESSION['my_url'];
211 if($url && strlen(get_config('system','directory_submit_url')))
212 proc_run('php',"include/directory.php","$url");
220 function profiles_content(&$a) {
223 $o .= '<script> $(document).ready(function() { $(\'#nav-profiles-link\').addClass(\'nav-selected\'); });</script>';
226 notice( t('Permission denied.') . EOL);
230 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
231 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
236 notice( t('Profile not found.') . EOL);
237 goaway($a->get_baseurl() . '/profiles');
238 return; // NOTREACHED
241 // move every contact using this profile as their default to the user default
243 $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 ",
244 intval(local_user()),
248 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
253 info( t('Profile deleted.') . EOL);
255 goaway($a->get_baseurl() . '/profiles');
256 return; // NOTREACHED
263 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
265 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
266 intval(local_user()));
267 $num_profiles = count($r0);
269 $name = t('Profile-') . ($num_profiles + 1);
271 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
272 intval(local_user()));
274 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
275 VALUES ( %d, '%s', '%s', '%s', '%s' )",
276 intval(local_user()),
278 dbesc($r1[0]['name']),
279 dbesc($r1[0]['photo']),
280 dbesc($r1[0]['thumb'])
283 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
284 intval(local_user()),
288 info( t('New profile created.') . EOL);
290 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
291 goaway($a->get_baseurl() . '/profiles');
294 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
296 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
297 intval(local_user()));
298 $num_profiles = count($r0);
300 $name = t('Profile-') . ($num_profiles + 1);
301 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
302 intval(local_user()),
306 notice( t('Profile unavailable to clone.') . EOL);
310 $r1[0]['is-default'] = 0;
311 $r1[0]['publish'] = 0;
312 $r1[0]['net-publish'] = 0;
313 $r1[0]['profile-name'] = dbesc($name);
317 $r2 = dbq("INSERT INTO `profile` (`"
318 . implode("`, `", array_keys($r1[0]))
320 . implode("', '", array_values($r1[0]))
323 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
324 intval(local_user()),
327 info( t('New profile created.') . EOL);
329 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
330 goaway($a->get_baseurl() . '/profiles');
331 return; // NOTREACHED
335 if(($a->argc > 1) && (intval($a->argv[1]))) {
336 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
341 notice( t('Profile not found.') . EOL);
345 profile_load($a,$a->user['nickname'],$r[0]['id']);
347 require_once('include/profile_selectors.php');
349 $tpl = get_markup_template('profed_head.tpl');
351 $opt_tpl = get_markup_template("profile-hide-friends.tpl");
352 $hide_friends = replace_macros($opt_tpl,array(
353 '$desc' => t('Hide your contact/friend list from viewers of this profile?'),
354 '$yes_str' => t('Yes'),
355 '$no_str' => t('No'),
356 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
357 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
361 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
362 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
364 $f = get_config('system','birthday_input_format');
368 $is_default = (($r[0]['is-default']) ? 1 : 0);
369 $tpl = get_markup_template("profile_edit.tpl");
370 $o .= replace_macros($tpl,array(
371 '$banner' => t('Edit Profile Details'),
372 '$submit' => t('Submit'),
373 '$viewprof' => t('View this profile'),
374 '$cr_prof' => t('Create a new profile using these settings'),
375 '$cl_prof' => t('Clone this profile'),
376 '$del_prof' => t('Delete this profile'),
377 '$lbl_profname' => t('Profile Name:'),
378 '$lbl_fullname' => t('Your Full Name:'),
379 '$lbl_title' => t('Title/Description:'),
380 '$lbl_gender' => t('Your Gender:'),
381 '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)),
382 '$lbl_address' => t('Street Address:'),
383 '$lbl_city' => t('Locality/City:'),
384 '$lbl_zip' => t('Postal/Zip Code:'),
385 '$lbl_country' => t('Country:'),
386 '$lbl_region' => t('Region/State:'),
387 '$lbl_marital' => t('<span class="heart">♥</span> Marital Status:'),
388 '$lbl_with' => t("Who: \x28if applicable\x29"),
389 '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'),
390 '$lbl_sexual' => t('Sexual Preference:'),
391 '$lbl_homepage' => t('Homepage URL:'),
392 '$lbl_politic' => t('Political Views:'),
393 '$lbl_religion' => t('Religious Views:'),
394 '$lbl_pubkey' => t('Public Keywords:'),
395 '$lbl_prvkey' => t('Private Keywords:'),
396 '$lbl_ex2' => t('Example: fishing photography software'),
397 '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"),
398 '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"),
399 '$lbl_about' => t('Tell us about yourself...'),
400 '$lbl_hobbies' => t('Hobbies/Interests'),
401 '$lbl_social' => t('Contact information and Social Networks'),
402 '$lbl_music' => t('Musical interests'),
403 '$lbl_book' => t('Books, literature'),
404 '$lbl_tv' => t('Television'),
405 '$lbl_film' => t('Film/dance/culture/entertainment'),
406 '$lbl_love' => t('Love/romance'),
407 '$lbl_work' => t('Work/employment'),
408 '$lbl_school' => t('School/education'),
409 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
410 '$baseurl' => $a->get_baseurl(),
411 '$profile_id' => $r[0]['id'],
412 '$profile_name' => $r[0]['profile-name'],
413 '$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>' : ""),
414 '$name' => $r[0]['name'],
415 '$pdesc' => $r[0]['pdesc'],
416 '$dob' => dob($r[0]['dob']),
417 '$hide_friends' => $hide_friends,
418 '$address' => $r[0]['address'],
419 '$locality' => $r[0]['locality'],
420 '$region' => $r[0]['region'],
421 '$postal_code' => $r[0]['postal-code'],
422 '$country_name' => $r[0]['country-name'],
423 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
424 '$gender' => gender_selector($r[0]['gender']),
425 '$marital' => marital_selector($r[0]['marital']),
426 '$with' => strip_tags($r[0]['with']),
427 '$sexual' => sexpref_selector($r[0]['sexual']),
428 '$about' => $r[0]['about'],
429 '$homepage' => $r[0]['homepage'],
430 '$politic' => $r[0]['politic'],
431 '$religion' => $r[0]['religion'],
432 '$pub_keywords' => $r[0]['pub_keywords'],
433 '$prv_keywords' => $r[0]['prv_keywords'],
434 '$music' => $r[0]['music'],
435 '$book' => $r[0]['book'],
436 '$tv' => $r[0]['tv'],
437 '$film' => $r[0]['film'],
438 '$interest' => $r[0]['interest'],
439 '$romance' => $r[0]['romance'],
440 '$work' => $r[0]['work'],
441 '$education' => $r[0]['education'],
442 '$contact' => $r[0]['contact']
445 $arr = array('profile' => $r[0], 'entry' => $o);
446 call_hooks('profile_edit', $arr);
452 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
456 $tpl_header = get_markup_template('profile_listing_header.tpl');
457 $o .= replace_macros($tpl_header,array(
458 '$header' => t('Profiles'),
459 '$chg_photo' => t('Change profile photo'),
460 '$cr_new' => t('Create New Profile')
464 $tpl = get_markup_template('profile_entry.tpl');
467 $o .= replace_macros($tpl, array(
468 '$photo' => $rr['thumb'],
470 '$alt' => t('Profile Image'),
471 '$profile_name' => $rr['profile-name'],
472 '$visible' => (($rr['is-default']) ? '<strong>' . t('visible to everybody') . '</strong>'
473 : '<a href="' . $a->get_baseurl() . '/profperm/' . $rr['id'] . '" />' . t('Edit visibility') . '</a>')