From 5dcd0654d44b21503663801b8b5fb5d76ae4f015 Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 24 Jul 2014 21:29:07 -0700 Subject: always provide a profile edit entry in the nav usermenu --- mod/profiles.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index f6392d4ab..60e7efa1f 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -505,8 +505,8 @@ function profiles_content(&$a) { $o .= replace_macros($tpl,array( '$form_security_token' => get_form_security_token("profile_edit"), - '$profile_clone_link' => 'profiles/clone/' . $r[0]['id'] . '?t=' - . get_form_security_token("profile_clone"), + '$profile_clone_link' => ((feature_enabled(local_user(),'multi_profiles')) ? 'profiles/clone/' . $r[0]['id'] . '?t=' + . get_form_security_token("profile_clone") : ''), '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), -- cgit v1.2.3 From ff8351437eab90786b99b940d31dacd133034f09 Mon Sep 17 00:00:00 2001 From: friendica Date: Fri, 1 Aug 2014 01:24:03 -0700 Subject: make the profile minimal by default. Use features to enable the advanced form. --- mod/profiles.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 60e7efa1f..fd0ea39d2 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -485,6 +485,7 @@ function profiles_content(&$a) { '$editselect' => $editselect, )); + $advanced = ((feature_enabled(local_user(),'advanced_profiles')) ? true : false); $opt_tpl = get_markup_template("profile-hide_friends.tpl"); $hide_friends = replace_macros($opt_tpl,array( @@ -558,6 +559,7 @@ function profiles_content(&$a) { '$profile_id' => $r[0]['id'], '$profile_name' => $r[0]['profile_name'], '$default' => (($is_default) ? '

' . t('This is your public profile.
It may be visible to anybody using the internet.') . '

' : ""), + '$advanced' => $advanced, '$name' => $r[0]['name'], '$pdesc' => $r[0]['pdesc'], '$dob' => dob($r[0]['dob']), @@ -569,10 +571,13 @@ function profiles_content(&$a) { '$country_name' => $r[0]['country_name'], '$age' => ((intval($r[0]['dob'])) ? '(' . t('Age: ') . age($r[0]['dob'],$a->user['timezone'],$a->user['timezone']) . ')' : ''), '$gender' => gender_selector($r[0]['gender']), + '$gender_min' => gender_selector_min($r[0]['gender']), '$marital' => marital_selector($r[0]['marital']), + '$marital_min' => marital_selector_min($r[0]['marital']), '$with' => $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']), + '$sexual_min' => sexpref_selector_min($r[0]['sexual']), '$about' => $r[0]['about'], '$homepage' => $r[0]['homepage'], '$hometown' => $r[0]['hometown'], -- cgit v1.2.3 From 32f09b5fc2f06530453502636039fafb0621399b Mon Sep 17 00:00:00 2001 From: Jeroen Date: Fri, 1 Aug 2014 17:45:18 +0000 Subject: Update nl. Added a link from the edit profile page to the edit visibility page. --- mod/profiles.php | 1 + 1 file changed, 1 insertion(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index fd0ea39d2..2062f094f 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -515,6 +515,7 @@ function profiles_content(&$a) { '$banner' => t('Edit Profile Details'), '$submit' => t('Submit'), '$viewprof' => t('View this profile'), + '$editvis' => t('Edit visibility'), '$profpic' => t('Change Profile Photo'), '$cr_prof' => t('Create a new profile using these settings'), '$cl_prof' => t('Clone this profile'), -- cgit v1.2.3 From 44ee18b810b8671c9b522b06a5d8d0e62a3bef00 Mon Sep 17 00:00:00 2001 From: friendica Date: Sat, 2 Aug 2014 23:28:51 -0700 Subject: Let site admin choose what profile fields to support. --- mod/profiles.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 2062f094f..03e6801d2 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -458,11 +458,17 @@ function profiles_content(&$a) { $o = ''; + if(! local_user()) { notice( t('Permission denied.') . EOL); return; } + require_once('include/identity.php'); + + $profile_fields_basic = get_profile_fields_basic(); + $profile_fields_advanced = get_profile_fields_advanced(); + if((argc() > 1) && (intval(argv(1)))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), @@ -486,6 +492,11 @@ function profiles_content(&$a) { )); $advanced = ((feature_enabled(local_user(),'advanced_profiles')) ? true : false); + if($advanced) + $fields = $profile_fields_advanced; + else + $fields = $profile_fields_basic; + $opt_tpl = get_markup_template("profile-hide_friends.tpl"); $hide_friends = replace_macros($opt_tpl,array( @@ -511,11 +522,12 @@ function profiles_content(&$a) { '$profile_drop_link' => 'profiles/drop/' . $r[0]['id'] . '?t=' . get_form_security_token("profile_drop"), + '$fields' => $fields, '$guid' => $r[0]['profile_guid'], '$banner' => t('Edit Profile Details'), '$submit' => t('Submit'), '$viewprof' => t('View this profile'), - '$editvis' => t('Edit visibility'), + '$editvis' => t('Edit visibility'), '$profpic' => t('Change Profile Photo'), '$cr_prof' => t('Create a new profile using these settings'), '$cl_prof' => t('Clone this profile'), -- cgit v1.2.3 From a0695fa04fdc73a20beb216060573e1204950df6 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 4 Aug 2014 04:40:45 -0700 Subject: backend for profile export --- mod/profiles.php | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 03e6801d2..c063599b4 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -126,6 +126,33 @@ function profiles_init(&$a) { return; // NOTREACHED } + if((argc() > 2) && (argv(1) === 'export')) { + + $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", + intval(local_user()), + intval(argv(2)) + ); + if(! $r1) { + notice( t('Profile unavailable to export.') . EOL); + $a->error = 404; + return; + } + header('content-type: application/octet_stream'); + header('content-disposition: attachment; filename="' . $r1[0]['profile_name'] . '.json"' ); + + unset($r1[0]['id']); + unset($r1[0]['aid']); + unset($r1[0]['uid']); + unset($r1[0]['is_default']); + unset($r1[0]['publish']); + unset($r1[0]['profile_name']); + unset($r1[0]['profile_guid']); + echo json_encode($r1[0]); + killme(); + } + + + // Run profile_load() here to make sure the theme is set before // we start loading content -- cgit v1.2.3 From 00fc23bf4e169b4a48ae0bafae12cc3946b38cd6 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 4 Aug 2014 16:47:49 -0700 Subject: issue #551 provide import/export of profiles (if this feature is enabled) --- mod/profiles.php | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index c063599b4..bcaae909b 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -186,6 +186,33 @@ function profiles_post(&$a) { call_hooks('profile_post', $_POST); + // import from json export file. + // Only import fields that are allowed on this hub + + if(x($_FILES,'userfile')) { + $src = $_FILES['userfile']['tmp_name']; + $filesize = intval($_FILES['userfile']['size']); + if($filesize) { + $j = @json_decode(@file_get_contents($src),true); + @unlink($src); + if($j) { + $fields = get_profile_fields_advanced(); + if($fields) { + foreach($j as $jj => $v) { + foreach($fields as $f => $n) { + if($jj == $f) { + $_POST[$f] = $v; + break; + } + } + } + } + } + } + } + + + if((argc() > 1) && (argv(1) !== "new") && intval(argv(1))) { $orig = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($a->argv[1]), @@ -205,6 +232,12 @@ function profiles_post(&$a) { notify( t('Profile Name is required.') . EOL); return; } + + if($_POST['dob']) { + $year = substr($_POST['dob'],0,4); + $month = substr($_POST['dob'],5,2); + $day = substr($_POST['dob'],8,2); + } $year = intval($_POST['year']); if($year < 1900 || $year > 2100 || $year < 0) @@ -559,6 +592,9 @@ function profiles_content(&$a) { '$cr_prof' => t('Create a new profile using these settings'), '$cl_prof' => t('Clone this profile'), '$del_prof' => t('Delete this profile'), + '$exportable' => feature_enabled(local_user(),'profile_export'), + '$lbl_import' => t('Import profile from file'), + '$lbl_export' => t('Export profile to file'), '$lbl_profname' => t('Profile Name:'), '$lbl_fullname' => t('Your Full Name:'), '$lbl_title' => t('Title/Description:'), -- cgit v1.2.3 From a7d95108d04d057b6c07984f46647be7d708632a Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 7 Aug 2014 18:22:50 -0700 Subject: cleanup some text where we said "public" or "visible to anybody on the internet" when that isn't necessarily true. --- mod/profiles.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index bcaae909b..791f93465 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -518,6 +518,7 @@ function profiles_content(&$a) { $o = ''; + $channel = $a->get_channel(); if(! local_user()) { notice( t('Permission denied.') . EOL); @@ -634,7 +635,8 @@ function profiles_content(&$a) { '$baseurl' => $a->get_baseurl(true), '$profile_id' => $r[0]['id'], '$profile_name' => $r[0]['profile_name'], - '$default' => (($is_default) ? '

' . t('This is your public profile.
It may be visible to anybody using the internet.') . '

' : ""), + '$is_default' => $is_default, + '$default' => t('This is your default profile.') . EOL . translate_scope(map_scope($channel['channel_r_profile'])), '$advanced' => $advanced, '$name' => $r[0]['name'], '$pdesc' => $r[0]['pdesc'], -- cgit v1.2.3 From ad4dc666c58ac6d486549ba399991e25585b23ca Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 7 Aug 2014 18:47:09 -0700 Subject: more editing of visibility displays --- mod/profiles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 791f93465..b938e836b 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -707,7 +707,7 @@ function profiles_content(&$a) { '$alt' => t('Profile Image'), '$profile_name' => $rr['profile_name'], '$visible' => (($rr['is_default']) - ? '' . t('visible to everybody') . '' + ? '' . translate_scope(map_scope($channel['channel_r_profile'])) . '' : '' . t('Edit visibility') . '') )); } -- cgit v1.2.3 From b4aed1212930e40377665dc45271f2b1f428511f Mon Sep 17 00:00:00 2001 From: friendica Date: Wed, 20 Aug 2014 23:01:25 -0700 Subject: extensible profiles - add the input form elements. Still needs styling and we're not yet storing the results. And right now we're ignoring the type and only doing type=string. Oh yeah - and I split off starting the second delivery chain into its own function in tag_deliver since it was largely duplicate code. --- mod/profiles.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index b938e836b..d6df09e9a 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -568,6 +568,24 @@ function profiles_content(&$a) { '$no_selected' => (($r[0]['hide_friends'] == 0) ? " checked=\"checked\" " : "") )); + $q = q("select * from profdef where true"); + if($q) { + $extra_fields = array(); + + foreach($q as $qq) { + $mine = q("select v from profext where k = '%s' and hash = '%s' and channel_id = %d limit 1", + dbesc($qq['field_name']), + dbesc($r[0]['profile_guid']), + intval(local_user()) + ); + + if(array_key_exists($qq['field_name'],$fields)) { + $extra_fields[] = array($qq['field_name'],$qq['field_desc'],(($mine) ? $mine[0]['v'] : ''), $qq['field_help']); + } + } + } + +logger('extra_fields: ' . print_r($extra_fields,true)); $f = get_config('system','birthday_input_format'); if(! $f) @@ -674,6 +692,7 @@ function profiles_content(&$a) { '$education' => $r[0]['education'], '$contact' => $r[0]['contact'], '$channels' => $r[0]['channels'], + '$extra_fields' => $extra_fields, )); $arr = array('profile' => $r[0], 'entry' => $o); -- cgit v1.2.3 From feddf5d7fb1d0cecbad69ecd314af0d106c0a9be Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 22:18:11 -0700 Subject: fix saving of extended profile attributes --- mod/profiles.php | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index d6df09e9a..1504f55f0 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -254,6 +254,7 @@ function profiles_post(&$a) { // $month = 1; $day = 1; // } + $dob = '0000-00-00'; $dob = sprintf('%04d-%02d-%02d',$year,$month,$day); @@ -264,6 +265,9 @@ function profiles_post(&$a) { $namechanged = true; + + + $pdesc = escape_tags(trim($_POST['pdesc'])); $gender = escape_tags(trim($_POST['gender'])); $address = escape_tags(trim($_POST['address'])); @@ -344,7 +348,41 @@ function profiles_post(&$a) { $with = $orig[0]['with']; } + $profile_fields_basic = get_profile_fields_basic(); + $profile_fields_advanced = get_profile_fields_advanced(); + $advanced = ((feature_enabled(local_user(),'advanced_profiles')) ? true : false); + if($advanced) + $fields = $profile_fields_advanced; + else + $fields = $profile_fields_basic; + $z = q("select * from profdef where true"); + if($z) { + foreach($z as $zz) { + if(array_key_exists($zz['field_name'],$fields)) { + $w = q("select * from profext where channel_id = %d and hash = '%s' and k = '%s' limit 1", + intval(local_user()), + dbesc($orig[0]['profile_guid']), + dbesc($zz['field_name']) + ); + if($w) { + q("update profext set v = '%s' where id = %d limit 1", + dbesc(escape_tags(trim($_POST[$zz['field_name']]))), + intval($w[0]['id']) + ); + } + else { + q("insert into profdef ( channel_id, hash, k, v ) values ( %d, '%s', '%s', '%s') ", + intval(local_user()), + dbesc($orig[0]['profile_guid']), + dbesc($zz['field_name']), + dbesc(escape_tags(trim($_POST[$zz['field_name']]))) + ); + } + } + } + } + $changes = array(); -- cgit v1.2.3 From 0825ec81c130621bdaccba3aa1f627b08c91128e Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 28 Aug 2014 22:27:05 -0700 Subject: except for a typo --- mod/profiles.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 1504f55f0..6361f56a3 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -372,7 +372,7 @@ function profiles_post(&$a) { ); } else { - q("insert into profdef ( channel_id, hash, k, v ) values ( %d, '%s', '%s', '%s') ", + q("insert into profext ( channel_id, hash, k, v ) values ( %d, '%s', '%s', '%s') ", intval(local_user()), dbesc($orig[0]['profile_guid']), dbesc($zz['field_name']), @@ -383,8 +383,6 @@ function profiles_post(&$a) { } } - - $changes = array(); $value = ''; if($is_default) { -- cgit v1.2.3 From c6d07feff575862b5db8d05e02be6375e51034c7 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 8 Sep 2014 20:35:15 -0700 Subject: This is long overdue - use a symblic constant NULL_DATE instead of the easily mis-typed sequence '0000-00-00 00:00:00' --- mod/profiles.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 6361f56a3..063e714e7 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -304,7 +304,7 @@ function profiles_post(&$a) { $with = ((x($_POST,'with')) ? escape_tags(trim($_POST['with'])) : ''); if(! strlen($howlong)) - $howlong = '0000-00-00 00:00:00'; + $howlong = NULL_DATE; else $howlong = datetime_convert(date_default_timezone_get(),'UTC',$howlong); @@ -707,7 +707,7 @@ logger('extra_fields: ' . print_r($extra_fields,true)); '$marital' => marital_selector($r[0]['marital']), '$marital_min' => marital_selector_min($r[0]['marital']), '$with' => $r[0]['with'], - '$howlong' => ($r[0]['howlong'] === '0000-00-00 00:00:00' ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])), + '$howlong' => ($r[0]['howlong'] === NULL_DATE ? '' : datetime_convert('UTC',date_default_timezone_get(),$r[0]['howlong'])), '$sexual' => sexpref_selector($r[0]['sexual']), '$sexual_min' => sexpref_selector_min($r[0]['sexual']), '$about' => $r[0]['about'], -- cgit v1.2.3 From e06c3e5a911176bd2afc5d9d391e629f282122b8 Mon Sep 17 00:00:00 2001 From: Jeroen Date: Thu, 9 Oct 2014 14:54:04 +0000 Subject: Added and changed on some places div class generic-content-wrapper. And added to redbasic. Other thems can now also theme backgrounds of a lot of pages. I'm not completely done, but till now - this is it. --- mod/profiles.php | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 063e714e7..cde768b1e 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -766,6 +766,9 @@ logger('extra_fields: ' . print_r($extra_fields,true)); : '' . t('Edit visibility') . '') )); } + + $o .= ''; + } return $o; } -- cgit v1.2.3 From 4e9bd8b8f0a2629cf1ad7c7274369e795852a8ab Mon Sep 17 00:00:00 2001 From: marijus Date: Fri, 10 Oct 2014 15:52:56 +0200 Subject: This is a fix to not interfere the ongoing adding of .generic-content-wrapper with the ongoing styling of redbasic theme. adding of .generic-content-wrapper is needed and useful for derivative themes but it should not contain any styling information for redbasic theme. therefor i added .generic-content-wrapper-styled as a quickfix for spots where redbasic is not finished yet. Sidenote: please avoid opening a div in one *.tpl and close it in another or (even worse) open a div in a *.tpl and close it in an already templatified mod/*.php. This will really make the code and templates very, very confusing. --- mod/profiles.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index cde768b1e..5d0416e9a 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -767,8 +767,6 @@ logger('extra_fields: ' . print_r($extra_fields,true)); )); } - $o .= ''; - } return $o; } -- cgit v1.2.3 From bae3029c639bf6f9469dd93bfedc3dce0d8510d7 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 19 Oct 2014 16:12:05 -0700 Subject: merge madness --- mod/profiles.php | 32 ++------------------------------ 1 file changed, 2 insertions(+), 30 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 5d0416e9a..14f24c5cf 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -233,41 +233,13 @@ function profiles_post(&$a) { return; } - if($_POST['dob']) { - $year = substr($_POST['dob'],0,4); - $month = substr($_POST['dob'],5,2); - $day = substr($_POST['dob'],8,2); - } - - $year = intval($_POST['year']); - if($year < 1900 || $year > 2100 || $year < 0) - $year = 0; - $month = intval($_POST['month']); - if(($month > 12) || ($month < 0)) - $month = 0; - $mtab = array(0,31,29,31,30,31,30,31,31,30,31,30,31); - $day = intval($_POST['day']); - if(($day > $mtab[$month]) || ($day < 0)) - $day = 0; - -// if($year && (! ($month && $day))) { -// $month = 1; $day = 1; -// } - - - $dob = '0000-00-00'; - $dob = sprintf('%04d-%02d-%02d',$year,$month,$day); - + $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated? $name = escape_tags(trim($_POST['name'])); if($orig[0]['name'] != $name) $namechanged = true; - - - - $pdesc = escape_tags(trim($_POST['pdesc'])); $gender = escape_tags(trim($_POST['gender'])); $address = escape_tags(trim($_POST['address'])); @@ -654,7 +626,7 @@ logger('extra_fields: ' . print_r($extra_fields,true)); '$lbl_fullname' => t('Your Full Name:'), '$lbl_title' => t('Title/Description:'), '$lbl_gender' => t('Your Gender:'), - '$lbl_bd' => sprintf( t("Birthday \x28%s\x29:"),datesel_format($f)), + '$lbl_bd' => t("Birthday :"), '$lbl_address' => t('Street Address:'), '$lbl_city' => t('Locality/City:'), '$lbl_zip' => t('Postal/Zip Code:'), -- cgit v1.2.3 From d432f4ccd5696565dbc6e726d6d06eb77fd35f77 Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 10 Nov 2014 19:20:23 -0800 Subject: issue #683 - don't linkify homepage field without validating --- mod/profiles.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 14f24c5cf..86de72629 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -514,6 +514,8 @@ function profiles_post(&$a) { } if($is_default) { + // reload the info for the sidebar widget - why does this not work? + profile_load($a,$channel['channel_address']); proc_run('php','include/directory.php',local_user()); } } -- cgit v1.2.3 From 325b269b224615a9c584e0ec631a11d68bb24eb8 Mon Sep 17 00:00:00 2001 From: friendica Date: Tue, 11 Nov 2014 01:05:29 -0800 Subject: the code is a bit crufty, but this should fix issue #687 --- mod/profiles.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 86de72629..bea006384 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -234,6 +234,22 @@ function profiles_post(&$a) { } $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated? + + $y = substr($dob,0,4); + if((! ctype_digit($y)) || ($y < 1900)) + $ignore_year = true; + else + $ignore_year = false; + + if($dob != '0000-00-00') { + if(strpos($dob,'0000-') === 0) { + $ignore_year = true; + $dob = substr($dob,5); + } + $dob = datetime_convert('UTC','UTC',(($ignore_year) ? '1900-' . $dob : $dob),(($ignore_year) ? 'm-d' : 'Y-m-d')); + if($ignore_year) + $dob = '0000-' . $dob; + } $name = escape_tags(trim($_POST['name'])); -- cgit v1.2.3 From 1a5a5c7edb8697c93f8bababbafa80245378dd7e Mon Sep 17 00:00:00 2001 From: Habeas Codice Date: Thu, 13 Nov 2014 12:21:58 -0800 Subject: PostgreSQL support initial commit There were 11 main types of changes: - UPDATE's and DELETE's sometimes had LIMIT 1 at the end of them. This is not only non-compliant but it would certainly not do what whoever wrote it thought it would. It is likely this mistake was just copied from Friendica. All of these instances, the LIMIT 1 was simply removed. - Bitwise operations (and even some non-zero int checks) erroneously rely on MySQL implicit integer-boolean conversion in the WHERE clauses. This is non-compliant (and bad programming practice to boot). Proper explicit boolean conversions were added. New queries should use proper conventions. - MySQL has a different operator for bitwise XOR than postgres. Rather than add yet another dba_ func, I converted them to "& ~" ("AND NOT") when turning off, and "|" ("OR") when turning on. There were no true toggles (XOR). New queries should refrain from using XOR when not necessary. - There are several fields which the schema has marked as NOT NULL, but the inserts don't specify them. The reason this works is because mysql totally ignores the constraint and adds an empty text default automatically. Again, non-compliant, obviously. In these cases a default of empty text was added. - Several statements rely on a non-standard MySQL feature (http://dev.mysql.com/doc/refman/5.5/en/group-by-handling.html). These queries can all be rewritten to be standards compliant. Interestingly enough, the newly rewritten standards compliant queries run a zillion times faster, even on MySQL. - A couple of function/operator name translations were needed (RAND/RANDOM, GROUP_CONCAT/STRING_AGG, UTC_NOW, REGEXP/~, ^/#) -- assist functions added in the dba_ - INTERVALs: postgres requires quotes around the value, mysql requires that there are not quotes around the value -- assist functions added in the dba_ - NULL_DATE's -- Postgres does not allow the invalid date '0000-00-00 00:00:00' (there is no such thing as year 0 or month 0 or day 0). We use '0001-01-01 00:00:00' for postgres. Conversions are handled in Zot/item packets automagically by quoting all dates with dbescdate(). - char(##) specifications in the schema creates fields with blank spaces that aren't trimmed in the code. MySQL apparently treats char(##) as varchar(##), again, non-compliant. Since postgres works better with text fields anyway, this ball of bugs was simply side-stepped by using 'text' datatype for all text fields in the postgres schema. varchar was used in a couple of places where it actually seemed appropriate (size constraint), but without rigorously vetting that all of the PHP code actually validates data, new bugs might come out from under the rug. - postgres doesn't store nul bytes and a few other non-printables in text fields, even when quoted. bytea fields were used when storing binary data (photo.data, attach.data). A new dbescbin() function was added to handle this transparently. - postgres does not support LIMIT #,# syntax. All databases support LIMIT # OFFSET # syntax. Statements were updated to be standard. These changes require corresponding changes in the coding standards. Please review those before adding any code going forward. Still on my TODO list: - remove quotes from non-reserved identifiers and make reserved identifiers use dba func for quoting - Rewrite search queries for better results (both MySQL and Postgres) --- mod/profiles.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 14f24c5cf..2c1ebd394 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -30,7 +30,7 @@ function profiles_init(&$a) { dbesc($profile_guid), intval(local_user()) ); - $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", + $r = q("DELETE FROM `profile` WHERE `id` = %d AND `uid` = %d", intval(argv(2)), intval(local_user()) ); @@ -338,7 +338,7 @@ function profiles_post(&$a) { dbesc($zz['field_name']) ); if($w) { - q("update profext set v = '%s' where id = %d limit 1", + q("update profext set v = '%s' where id = %d", dbesc(escape_tags(trim($_POST[$zz['field_name']]))), intval($w[0]['id']) ); @@ -453,7 +453,7 @@ function profiles_post(&$a) { `work` = '%s', `education` = '%s', `hide_friends` = %d - WHERE `id` = %d AND `uid` = %d LIMIT 1", + WHERE `id` = %d AND `uid` = %d", dbesc($profile_name), dbesc($name), dbesc($pdesc), @@ -506,7 +506,7 @@ function profiles_post(&$a) { $channel = $a->get_channel(); if($namechanged && $is_default) { - $r = q("UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_hash = '%s' limit 1", + $r = q("UPDATE xchan SET xchan_name = '%s', xchan_name_date = '%s' WHERE xchan_hash = '%s'", dbesc($name), dbesc(datetime_convert()), dbesc($channel['xchan_hash']) -- cgit v1.2.3 From 5fac8e80de1951ef9c68925001000d74d3c52a8e Mon Sep 17 00:00:00 2001 From: Thomas Willingham Date: Sat, 13 Dec 2014 15:00:00 +0000 Subject: Issue #739 --- mod/profiles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 910c48743..6ecf7444a 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -585,7 +585,7 @@ function profiles_content(&$a) { $fields = $profile_fields_basic; - $opt_tpl = get_markup_template("profile-hide_friends.tpl"); + $opt_tpl = get_markup_template("profile_hide_friends.tpl"); $hide_friends = replace_macros($opt_tpl,array( '$desc' => t('Hide your contact/friend list from viewers of this profile?'), '$yes_str' => t('Yes'), -- cgit v1.2.3 From 2b3cc585a24cbdf97e8e2382752297bc4f725e12 Mon Sep 17 00:00:00 2001 From: friendica Date: Sun, 21 Dec 2014 14:43:06 -0800 Subject: fix double encoding of homepage in profile activity - not as straight-forward as it looked --- mod/profiles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 6ecf7444a..1d784c506 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -611,7 +611,7 @@ function profiles_content(&$a) { } } -logger('extra_fields: ' . print_r($extra_fields,true)); +//logger('extra_fields: ' . print_r($extra_fields,true)); $f = get_config('system','birthday_input_format'); if(! $f) -- cgit v1.2.3 From 754fec9a547159c38386d70a6b3e1c4b88193690 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Sat, 27 Dec 2014 12:46:59 +0100 Subject: Redirect /profiles to default profile when multi_profiles is off. Fixes #768 --- mod/profiles.php | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 1d784c506..f2695f332 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -156,9 +156,14 @@ function profiles_init(&$a) { // Run profile_load() here to make sure the theme is set before // we start loading content - if((argc() > 1) && (intval(argv(1)))) { + if(((argc() > 1) && (intval(argv(1)))) || !feature_enabled(local_user(),'multi_profiles')) { + if(feature_enabled(local_user(),'multi_profiles')) + $id = $a->argv[1]; + else + $id = q("select id from profile where uid = %d and is_default = 1",local_user())[0]['id']; + $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($a->argv[1]), + intval($id), intval(local_user()) ); if(! count($r)) { @@ -556,9 +561,14 @@ function profiles_content(&$a) { $profile_fields_basic = get_profile_fields_basic(); $profile_fields_advanced = get_profile_fields_advanced(); - if((argc() > 1) && (intval(argv(1)))) { + if(((argc() > 1) && (intval(argv(1)))) || !feature_enabled(local_user(),'multi_profiles')) { + if(feature_enabled(local_user(),'multi_profiles')) + $id = $a->argv[1]; + else + $id = q("select id from profile where uid = %d and is_default = 1",local_user())[0]['id']; + $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", - intval($a->argv[1]), + intval($id), intval(local_user()) ); if(! count($r)) { -- cgit v1.2.3 From 70f0019905f8c44ed875379a9af65988e536b4f4 Mon Sep 17 00:00:00 2001 From: Stefan Parviainen Date: Thu, 1 Jan 2015 10:08:20 +0100 Subject: Checkboxify yesno-fields, but use CSS to show them as switches in Redbasic --- mod/profiles.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index f2695f332..6bdc7f11a 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -596,13 +596,12 @@ function profiles_content(&$a) { $opt_tpl = get_markup_template("profile_hide_friends.tpl"); - $hide_friends = replace_macros($opt_tpl,array( - '$desc' => t('Hide your contact/friend list from viewers of this profile?'), - '$yes_str' => t('Yes'), - '$no_str' => t('No'), - '$yes_selected' => (($r[0]['hide_friends']) ? " checked=\"checked\" " : ""), - '$no_selected' => (($r[0]['hide_friends'] == 0) ? " checked=\"checked\" " : "") - )); + $hide_friends = replace_macros($opt_tpl,array('$field' => array( + 'hide-friends', + t('Hide your contact/friend list from viewers of this profile?'), + $r[0]['hide_friends'], + '', + ))); $q = q("select * from profdef where true"); if($q) { -- cgit v1.2.3 From c7aa8bf1b4c2a7ca4d7bf1552aabcb0c0a54756e Mon Sep 17 00:00:00 2001 From: friendica Date: Thu, 1 Jan 2015 23:47:14 -0800 Subject: syntax issues (with some php versions?), unchecked intval --- mod/profiles.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'mod/profiles.php') diff --git a/mod/profiles.php b/mod/profiles.php index 6bdc7f11a..fa6a6e35c 100644 --- a/mod/profiles.php +++ b/mod/profiles.php @@ -11,7 +11,7 @@ function profiles_init(&$a) { if((argc() > 2) && (argv(1) === "drop") && intval(argv(2))) { $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d AND `is_default` = 0 LIMIT 1", - intval($a->argv[2]), + intval(argv(2)), intval(local_user()) ); if(! count($r)) { @@ -159,9 +159,13 @@ function profiles_init(&$a) { if(((argc() > 1) && (intval(argv(1)))) || !feature_enabled(local_user(),'multi_profiles')) { if(feature_enabled(local_user(),'multi_profiles')) $id = $a->argv[1]; - else - $id = q("select id from profile where uid = %d and is_default = 1",local_user())[0]['id']; - + else { + $x = q("select id from profile where uid = %d and is_default = 1", + intval(local_user()) + ); + if($x) + $id = $x[0]['id']; + } $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($id), intval(local_user()) @@ -564,9 +568,13 @@ function profiles_content(&$a) { if(((argc() > 1) && (intval(argv(1)))) || !feature_enabled(local_user(),'multi_profiles')) { if(feature_enabled(local_user(),'multi_profiles')) $id = $a->argv[1]; - else - $id = q("select id from profile where uid = %d and is_default = 1",local_user())[0]['id']; - + else { + $x = q("select id from profile where uid = %d and is_default = 1", + intval(local_user()) + ); + if($x) + $id = $x[0]['id']; + } $r = q("SELECT * FROM `profile` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($id), intval(local_user()) -- cgit v1.2.3