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 $keywords = notags(trim($_POST['keywords']));
59 $marital = notags(trim($_POST['marital']));
60 if($marital != $orig[0]['marital'])
61 $maritalchanged = true;
63 $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : '');
65 // linkify the relationship target if applicable
68 if($with != strip_tags($orig[0]['with'])) {
71 if(strpos($lookup,'@') === 0)
72 $lookup = substr($lookup,1);
73 $lookup = str_replace('_',' ', $lookup);
74 if(strpos($lookup,'@') || (strpos($lookup,'http://'))) {
76 $links = @lrdd($lookup);
78 foreach($links as $link) {
79 if($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
80 $prf = $link['@attributes']['href'];
87 if(strstr($lookup,' ')) {
88 $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
94 $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
101 $newname = $r[0]['name'];
106 $with = str_replace($lookup,'<a href="' . $prf . '">' . $newname . '</a>', $with);
107 if(strpos($with,'@') === 0)
108 $with = substr($with,1);
112 $with = $orig[0]['with'];
115 $sexual = notags(trim($_POST['sexual']));
116 $homepage = notags(trim($_POST['homepage']));
117 $politic = notags(trim($_POST['politic']));
118 $religion = notags(trim($_POST['religion']));
120 $about = escape_tags(trim($_POST['about']));
121 $interest = escape_tags(trim($_POST['interest']));
122 $contact = escape_tags(trim($_POST['contact']));
123 $music = escape_tags(trim($_POST['music']));
124 $book = escape_tags(trim($_POST['book']));
125 $tv = escape_tags(trim($_POST['tv']));
126 $film = escape_tags(trim($_POST['film']));
127 $romance = escape_tags(trim($_POST['romance']));
128 $work = escape_tags(trim($_POST['work']));
129 $education = escape_tags(trim($_POST['education']));
130 $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',
162 WHERE `id` = %d AND `uid` = %d LIMIT 1",
163 dbesc($profile_name),
172 dbesc($country_name),
190 intval($hide_friends),
192 intval($_SESSION['uid'])
196 notice( t('Profile updated.') . EOL);
199 if($namechanged && $is_default) {
200 $r = q("UPDATE `contact` SET `name-date` = '%s' WHERE `self` = 1 AND `uid` = %d LIMIT 1",
201 dbesc(datetime_convert()),
207 // Update global directory in background
208 $url = $_SESSION['my_url'];
209 if($url && strlen(get_config('system','directory_submit_url')))
210 proc_run('php',"include/directory.php","$url");
218 function profiles_content(&$a) {
221 $o .= '<script> $(document).ready(function() { $(\'#nav-profiles-link\').addClass(\'nav-selected\'); });</script>';
224 notice( t('Permission denied.') . EOL);
228 if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) {
229 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1",
234 notice( t('Profile not found.') . EOL);
235 goaway($a->get_baseurl() . '/profiles');
236 return; // NOTREACHED
239 // move every contact using this profile as their default to the user default
241 $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 ",
242 intval(local_user()),
246 $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
251 notice( t('Profile deleted.') . EOL);
253 goaway($a->get_baseurl() . '/profiles');
254 return; // NOTREACHED
261 if(($a->argc > 1) && ($a->argv[1] === 'new')) {
263 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
264 intval(local_user()));
265 $num_profiles = count($r0);
267 $name = t('Profile-') . ($num_profiles + 1);
269 $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1",
270 intval(local_user()));
272 $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`)
273 VALUES ( %d, '%s', '%s', '%s', '%s' )",
274 intval(local_user()),
276 dbesc($r1[0]['name']),
277 dbesc($r1[0]['photo']),
278 dbesc($r1[0]['thumb'])
281 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
282 intval(local_user()),
286 notice( t('New profile created.') . EOL);
288 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
289 goaway($a->get_baseurl() . '/profiles');
292 if(($a->argc > 2) && ($a->argv[1] === 'clone')) {
294 $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
295 intval(local_user()));
296 $num_profiles = count($r0);
298 $name = t('Profile-') . ($num_profiles + 1);
299 $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
300 intval(local_user()),
304 notice( t('Profile unavailable to clone.') . EOL);
308 $r1[0]['is-default'] = 0;
309 $r1[0]['publish'] = 0;
310 $r1[0]['net-publish'] = 0;
311 $r1[0]['profile-name'] = dbesc($name);
315 $r2 = dbq("INSERT INTO `profile` (`"
316 . implode("`, `", array_keys($r1[0]))
318 . implode("', '", array_values($r1[0]))
321 $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1",
322 intval(local_user()),
325 notice( t('New profile created.') . EOL);
327 goaway($a->get_baseurl() . '/profiles/' . $r3[0]['id']);
328 goaway($a->get_baseurl() . '/profiles');
329 return; // NOTREACHED
333 if(($a->argc > 1) && (intval($a->argv[1]))) {
334 $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1",
339 notice( t('Profile not found.') . EOL);
343 profile_load($a,$a->user['nickname'],$r[0]['id']);
345 require_once('include/profile_selectors.php');
347 $tpl = load_view_file('view/profed_head.tpl');
349 $opt_tpl = load_view_file("view/profile-hide-friends.tpl");
350 $hide_friends = replace_macros($opt_tpl,array(
351 '$yes_selected' => (($r[0]['hide-friends']) ? " checked=\"checked\" " : ""),
352 '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "")
356 $a->page['htmlhead'] .= replace_macros($tpl, array('$baseurl' => $a->get_baseurl()));
357 $a->page['htmlhead'] .= "<script type=\"text/javascript\" src=\"include/country.js\" ></script>";
360 $is_default = (($r[0]['is-default']) ? 1 : 0);
361 $tpl = load_view_file("view/profile_edit.tpl");
362 $o .= replace_macros($tpl,array(
363 '$disabled' => (($is_default) ? 'onclick="return false;" style="color: #BBBBFF;"' : ''),
364 '$baseurl' => $a->get_baseurl(),
365 '$profile_id' => $r[0]['id'],
366 '$profile_name' => $r[0]['profile-name'],
367 '$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>' : ""),
368 '$name' => $r[0]['name'],
369 '$pdesc' => $r[0]['pdesc'],
370 '$dob' => dob($r[0]['dob']),
371 '$hide_friends' => $hide_friends,
372 '$address' => $r[0]['address'],
373 '$locality' => $r[0]['locality'],
374 '$region' => $r[0]['region'],
375 '$postal_code' => $r[0]['postal-code'],
376 '$country_name' => $r[0]['country-name'],
377 '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''),
378 '$gender' => gender_selector($r[0]['gender']),
379 '$marital' => marital_selector($r[0]['marital']),
380 '$with' => strip_tags($r[0]['with']),
381 '$sexual' => sexpref_selector($r[0]['sexual']),
382 '$about' => $r[0]['about'],
383 '$homepage' => $r[0]['homepage'],
384 '$politic' => $r[0]['politic'],
385 '$religion' => $r[0]['religion'],
386 '$keywords' => $r[0]['keywords'],
387 '$music' => $r[0]['music'],
388 '$book' => $r[0]['book'],
389 '$tv' => $r[0]['tv'],
390 '$film' => $r[0]['film'],
391 '$interest' => $r[0]['interest'],
392 '$romance' => $r[0]['romance'],
393 '$work' => $r[0]['work'],
394 '$education' => $r[0]['education'],
395 '$contact' => $r[0]['contact']
398 $arr = array('profile' => $r[0], 'entry' => $o);
399 call_hooks('profile_edit', $arr);
405 $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
409 $o .= load_view_file('view/profile_listing_header.tpl');
410 $tpl_default = load_view_file('view/profile_entry_default.tpl');
411 $tpl = load_view_file('view/profile_entry.tpl');
414 $template = (($rr['is-default']) ? $tpl_default : $tpl);
415 $o .= replace_macros($template, array(
416 '$photo' => $rr['thumb'],
418 '$alt' => t('Profile Image'),
419 '$profile_name' => $rr['profile-name']