X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=mod%2Fprofiles.php;h=148c632914a568a16b93e562f400b24b79818533;hb=dfca336857d2480c9e808ac3581fb2db3a7064f1;hp=3a52c8fa5ee00f9fce921b449772f3e379ce8eb9;hpb=def6f0b408680c4e5f209890bbf1ad6bf40b5add;p=friendica.git diff --git a/mod/profiles.php b/mod/profiles.php index 3a52c8fa5e..148c632914 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -1,6 +1,145 @@ argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) { + $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1", + intval($a->argv[2]), + intval(local_user()) + ); + if(! count($r)) { + notice( t('Profile not found.') . EOL); + goaway($a->get_baseurl(true) . '/profiles'); + return; // NOTREACHED + } + + check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't'); + + // move every contact using this profile as their default to the user default + + $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 ", + intval(local_user()), + intval($a->argv[2]), + intval(local_user()) + ); + $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($a->argv[2]), + intval(local_user()) + ); + if($r) + info( t('Profile deleted.') . EOL); + + goaway($a->get_baseurl(true) . '/profiles'); + return; // NOTREACHED + } + + + + + + if(($a->argc > 1) && ($a->argv[1] === 'new')) { + + check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); + + $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", + intval(local_user())); + $num_profiles = count($r0); + + $name = t('Profile-') . ($num_profiles + 1); + + $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", + intval(local_user())); + + $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`) + VALUES ( %d, '%s', '%s', '%s', '%s' )", + intval(local_user()), + dbesc($name), + dbesc($r1[0]['name']), + dbesc($r1[0]['photo']), + dbesc($r1[0]['thumb']) + ); + + $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1", + intval(local_user()), + dbesc($name) + ); + + info( t('New profile created.') . EOL); + if(count($r3) == 1) + goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); + + goaway($a->get_baseurl(true) . '/profiles'); + } + + if(($a->argc > 2) && ($a->argv[1] === 'clone')) { + + check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); + + $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", + intval(local_user())); + $num_profiles = count($r0); + + $name = t('Profile-') . ($num_profiles + 1); + $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", + intval(local_user()), + intval($a->argv[2]) + ); + if(! count($r1)) { + notice( t('Profile unavailable to clone.') . EOL); + killme(); + return; + } + unset($r1[0]['id']); + $r1[0]['is-default'] = 0; + $r1[0]['publish'] = 0; + $r1[0]['net-publish'] = 0; + $r1[0]['profile-name'] = dbesc($name); + + dbesc_array($r1[0]); + + $r2 = dbq("INSERT INTO `profile` (`" + . implode("`, `", array_keys($r1[0])) + . "`) VALUES ('" + . implode("', '", array_values($r1[0])) + . "')" ); + + $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1", + intval(local_user()), + dbesc($name) + ); + info( t('New profile created.') . EOL); + if(count($r3) == 1) + goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); + + goaway($a->get_baseurl(true) . '/profiles'); + + return; // NOTREACHED + } + + + if(($a->argc > 1) && (intval($a->argv[1]))) { + $r = q("SELECT id FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", + intval($a->argv[1]), + intval(local_user()) + ); + if(! count($r)) { + notice( t('Profile not found.') . EOL); + killme(); + return; + } + + profile_load($a,$a->user['nickname'],$r[0]['id']); + } + +} + function profiles_post(&$a) { if(! local_user()) { @@ -42,16 +181,28 @@ function profiles_post(&$a) { $day = intval($_POST['day']); if(($day > $mtab[$month]) || ($day < 0)) $day = 0; + + // It's OK to have an empty (0) year, but if you supplied a year you have to have a non-zero month and day + if($year && ! $month) + $month = 1; + if($year && ! $day) + $day = 1; + $dob = '0000-00-00'; $dob = sprintf('%04d-%02d-%02d',$year,$month,$day); $name = notags(trim($_POST['name'])); + if(! strlen($name)) { + $name = '[No Name]'; + } + if($orig[0]['name'] != $name) $namechanged = true; + $pdesc = notags(trim($_POST['pdesc'])); $gender = notags(trim($_POST['gender'])); $address = notags(trim($_POST['address'])); @@ -62,9 +213,15 @@ function profiles_post(&$a) { $pub_keywords = notags(trim($_POST['pub_keywords'])); $prv_keywords = notags(trim($_POST['prv_keywords'])); $marital = notags(trim($_POST['marital'])); + $howlong = notags(trim($_POST['howlong'])); $with = ((x($_POST,'with')) ? notags(trim($_POST['with'])) : ''); + if(! strlen($howlong)) + $howlong = '0000-00-00 00:00:00'; + else + $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong); + // linkify the relationship target if applicable $withchanged = false; @@ -90,7 +247,7 @@ function profiles_post(&$a) { } else { $newname = $lookup; - if(strstr($lookup,' ')) { +/* if(strstr($lookup,' ')) { $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval(local_user()) @@ -101,6 +258,17 @@ function profiles_post(&$a) { dbesc($lookup), intval(local_user()) ); + }*/ + + $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", + dbesc($newname), + intval(local_user()) + ); + if(! $r) { + $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", + dbesc($lookup), + intval(local_user()) + ); } if(count($r)) { $prf = $r[0]['url']; @@ -120,9 +288,13 @@ function profiles_post(&$a) { $sexual = notags(trim($_POST['sexual'])); $homepage = notags(trim($_POST['homepage'])); + $hometown = notags(trim($_POST['hometown'])); $politic = notags(trim($_POST['politic'])); $religion = notags(trim($_POST['religion'])); + $likes = fix_mce_lf(escape_tags(trim($_POST['likes']))); + $dislikes = fix_mce_lf(escape_tags(trim($_POST['dislikes']))); + $about = fix_mce_lf(escape_tags(trim($_POST['about']))); $interest = fix_mce_lf(escape_tags(trim($_POST['interest']))); $contact = fix_mce_lf(escape_tags(trim($_POST['contact']))); @@ -146,9 +318,17 @@ function profiles_post(&$a) { $value = $marital; } if($withchanged) { - $changes[] = '♥ ' . t('Romantic Partner'); + $changes[] = '[color=#ff0000]♥[/color] ' . t('Romantic Partner'); $value = strip_tags($with); - } + } + if($likes != $orig[0]['likes']) { + $changes[] = t('Likes'); + $value = $likes; + } + if($dislikes != $orig[0]['dislikes']) { + $changes[] = t('Dislikes'); + $value = $dislikes; + } if($work != $orig[0]['work']) { $changes[] = t('Work/Employment'); } @@ -176,9 +356,18 @@ function profiles_post(&$a) { $changes[] = t('Interests'); $value = $interest; } - if($address != $orig[0]['address'] || $locality != $orig[0]['locality'] || $region != $orig[0]['region'] + if($address != $orig[0]['address']) { + $changes[] = t('Address'); + // New address not sent in notifications, potential privacy issues + // in case this leaks to unintended recipients. Yes, it's in the public + // profile but that doesn't mean we have to broadcast it to everybody. + } + if($locality != $orig[0]['locality'] || $region != $orig[0]['region'] || $country_name != $orig[0]['country-name']) { $changes[] = t('Location'); + $comma1 = ((($locality) && ($region || $country_name)) ? ', ' : ' '); + $comma2 = (($region && $country_name) ? ', ' : ''); + $value = $locality . $comma1 . $region . $comma2 . $country_name; } profile_activity($changes,$value); @@ -198,12 +387,16 @@ function profiles_post(&$a) { `country-name` = '%s', `marital` = '%s', `with` = '%s', + `howlong` = '%s', `sexual` = '%s', `homepage` = '%s', + `hometown` = '%s', `politic` = '%s', `religion` = '%s', `pub_keywords` = '%s', `prv_keywords` = '%s', + `likes` = '%s', + `dislikes` = '%s', `about` = '%s', `interest` = '%s', `contact` = '%s', @@ -228,12 +421,16 @@ function profiles_post(&$a) { dbesc($country_name), dbesc($marital), dbesc($with), + dbesc($howlong), dbesc($sexual), dbesc($homepage), + dbesc($hometown), dbesc($politic), dbesc($religion), dbesc($pub_keywords), dbesc($prv_keywords), + dbesc($likes), + dbesc($dislikes), dbesc($about), dbesc($interest), dbesc($contact), @@ -258,6 +455,10 @@ function profiles_post(&$a) { dbesc(datetime_convert()), intval(local_user()) ); + $r = q("UPDATE `user` set `username` = '%s' where `uid` = %d limit 1", + dbesc($name), + intval(local_user()) + ); } if($is_default) { @@ -328,7 +529,7 @@ function profile_activity($changed, $value) { $prof = '[url=' . $self[0]['url'] . '?tab=profile' . ']' . t('public profile') . '[/url]'; if($t == 1 && strlen($value)) { - $message = sprintf( t('%1$s changed %2$s to %3$s'), $A, $changes, $value); + $message = sprintf( t('%1$s changed %2$s to “%3$s”'), $A, $changes, $value); $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof); } else @@ -350,135 +551,28 @@ function profile_activity($changed, $value) { $arr['deny_gid'] = $a->user['deny_gid']; $i = item_store($arr); - if($i) + if($i) { + + // give it a permanent link + q("update item set plink = '%s' where id = %d limit 1", + dbesc($a->get_baseurl() . '/display/' . $a->user['nickname'] . '/' . $i), + intval($i) + ); + proc_run('php',"include/notifier.php","activity","$i"); + } } function profiles_content(&$a) { - $o = ''; - nav_set_selected('profiles'); - if(! local_user()) { notice( t('Permission denied.') . EOL); return; } - if(($a->argc > 2) && ($a->argv[1] === "drop") && intval($a->argv[2])) { - $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is-default` = 0 LIMIT 1", - intval($a->argv[2]), - intval(local_user()) - ); - if(! count($r)) { - notice( t('Profile not found.') . EOL); - goaway($a->get_baseurl(true) . '/profiles'); - return; // NOTREACHED - } - - check_form_security_token_redirectOnErr('/profiles', 'profile_drop', 't'); - - // move every contact using this profile as their default to the user default - - $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 ", - intval(local_user()), - intval($a->argv[2]), - intval(local_user()) - ); - $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($a->argv[2]), - intval(local_user()) - ); - if($r) - info( t('Profile deleted.') . EOL); - - goaway($a->get_baseurl(true) . '/profiles'); - return; // NOTREACHED - } - - - - - - if(($a->argc > 1) && ($a->argv[1] === 'new')) { - - check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); - - $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", - intval(local_user())); - $num_profiles = count($r0); - - $name = t('Profile-') . ($num_profiles + 1); - - $r1 = q("SELECT `name`, `photo`, `thumb` FROM `profile` WHERE `uid` = %d AND `is-default` = 1 LIMIT 1", - intval(local_user())); - - $r2 = q("INSERT INTO `profile` (`uid` , `profile-name` , `name`, `photo`, `thumb`) - VALUES ( %d, '%s', '%s', '%s', '%s' )", - intval(local_user()), - dbesc($name), - dbesc($r1[0]['name']), - dbesc($r1[0]['photo']), - dbesc($r1[0]['thumb']) - ); - - $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1", - intval(local_user()), - dbesc($name) - ); - - info( t('New profile created.') . EOL); - if(count($r3) == 1) - goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); - - goaway($a->get_baseurl(true) . '/profiles'); - } - - if(($a->argc > 2) && ($a->argv[1] === 'clone')) { - - check_form_security_token_redirectOnErr('/profiles', 'profile_clone', 't'); - - $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", - intval(local_user())); - $num_profiles = count($r0); - - $name = t('Profile-') . ($num_profiles + 1); - $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", - intval(local_user()), - intval($a->argv[2]) - ); - if(! count($r1)) { - notice( t('Profile unavailable to clone.') . EOL); - return; - } - unset($r1[0]['id']); - $r1[0]['is-default'] = 0; - $r1[0]['publish'] = 0; - $r1[0]['net-publish'] = 0; - $r1[0]['profile-name'] = dbesc($name); - - dbesc_array($r1[0]); - - $r2 = dbq("INSERT INTO `profile` (`" - . implode("`, `", array_keys($r1[0])) - . "`) VALUES ('" - . implode("', '", array_values($r1[0])) - . "')" ); - - $r3 = q("SELECT `id` FROM `profile` WHERE `uid` = %d AND `profile-name` = '%s' LIMIT 1", - intval(local_user()), - dbesc($name) - ); - info( t('New profile created.') . EOL); - if(count($r3) == 1) - goaway($a->get_baseurl(true) . '/profiles/' . $r3[0]['id']); - - goaway($a->get_baseurl(true) . '/profiles'); - - return; // NOTREACHED - } - + $o = ''; if(($a->argc > 1) && (intval($a->argv[1]))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", @@ -490,19 +584,24 @@ function profiles_content(&$a) { return; } - profile_load($a,$a->user['nickname'],$r[0]['id']); - require_once('include/profile_selectors.php'); - $editselect = 'textareas'; - if(intval(get_pconfig(local_user(),'system','plaintext'))) - $editselect = 'none'; +/* $editselect = 'textareas'; + if( intval(get_pconfig(local_user(),'system','plaintext')) || !feature_enabled(local_user(),'richtext') ) + $editselect = 'none';*/ + $editselect = 'none'; + if( feature_enabled(local_user(),'richtext') ) + $editselect = 'textareas'; $a->page['htmlhead'] .= replace_macros(get_markup_template('profed_head.tpl'), array( '$baseurl' => $a->get_baseurl(true), '$editselect' => $editselect, )); + $a->page['end'] .= replace_macros(get_markup_template('profed_end.tpl'), array( + '$baseurl' => $a->get_baseurl(true), + '$editselect' => $editselect, + )); $opt_tpl = get_markup_template("profile-hide-friends.tpl"); @@ -514,9 +613,6 @@ function profiles_content(&$a) { '$no_selected' => (($r[0]['hide-friends'] == 0) ? " checked=\"checked\" " : "") )); - $a->page['htmlhead'] .= ""; - - @@ -532,6 +628,7 @@ function profiles_content(&$a) { '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), '$banner' => t('Edit Profile Details'), '$submit' => t('Submit'), + '$profpic' => t('Change Profile Photo'), '$viewprof' => t('View this profile'), '$cr_prof' => t('Create a new profile using these settings'), '$cl_prof' => t('Clone this profile'), @@ -549,12 +646,16 @@ function profiles_content(&$a) { '$lbl_marital' => t(' Marital Status:'), '$lbl_with' => t("Who: \x28if applicable\x29"), '$lbl_ex1' => t('Examples: cathy123, Cathy Williams, cathy@example.com'), + '$lbl_howlong' => t('Since [date]:'), '$lbl_sexual' => t('Sexual Preference:'), '$lbl_homepage' => t('Homepage URL:'), + '$lbl_hometown' => t('Hometown:'), '$lbl_politic' => t('Political Views:'), '$lbl_religion' => t('Religious Views:'), '$lbl_pubkey' => t('Public Keywords:'), '$lbl_prvkey' => t('Private Keywords:'), + '$lbl_likes' => t('Likes:'), + '$lbl_dislikes' => t('Dislikes:'), '$lbl_ex2' => t('Example: fishing photography software'), '$lbl_pubdsc' => t("\x28Used for suggesting potential friends, can be seen by others\x29"), '$lbl_prvdsc' => t("\x28Used for searching profiles, never shown to others\x29"), @@ -586,13 +687,17 @@ function profiles_content(&$a) { '$gender' => gender_selector($r[0]['gender']), '$marital' => marital_selector($r[0]['marital']), '$with' => strip_tags($r[0]['with']), + '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])), '$sexual' => sexpref_selector($r[0]['sexual']), '$about' => $r[0]['about'], '$homepage' => $r[0]['homepage'], + '$hometown' => $r[0]['hometown'], '$politic' => $r[0]['politic'], '$religion' => $r[0]['religion'], '$pub_keywords' => $r[0]['pub_keywords'], '$prv_keywords' => $r[0]['prv_keywords'], + '$likes' => $r[0]['likes'], + '$dislikes' => $r[0]['dislikes'], '$music' => $r[0]['music'], '$book' => $r[0]['book'], '$tv' => $r[0]['tv'], @@ -628,7 +733,7 @@ function profiles_content(&$a) { foreach($r as $rr) { $o .= replace_macros($tpl, array( - '$photo' => $rr['thumb'], + '$photo' => $a->get_cached_avatar_image($rr['thumb']), '$id' => $rr['id'], '$alt' => t('Profile Image'), '$profile_name' => $rr['profile-name'],