summaryrefslogtreecommitdiff
path: root/actions
diff options
context:
space:
mode:
authorEvan Prodromou <evan@status.net>2009-12-28 14:44:05 -0800
committerEvan Prodromou <evan@status.net>2009-12-28 14:44:05 -0800
commite009f613d39d81e98d1438dbc182515b332a5ece (patch)
treec3b5c02641b3d575db0a8d2cd3e6ce79f2c0864b /actions
parent39bdda9c7e7ee7571298c84c406a9dd74805f050 (diff)
let users set location prefs from profile form
Diffstat (limited to 'actions')
-rw-r--r--actions/profilesettings.php43
1 files changed, 38 insertions, 5 deletions
diff --git a/actions/profilesettings.php b/actions/profilesettings.php
index 58bf838d7..7db86a6c8 100644
--- a/actions/profilesettings.php
+++ b/actions/profilesettings.php
@@ -133,11 +133,13 @@ class ProfilesettingsAction extends AccountSettingsAction
($this->arg('location')) ? $this->arg('location') : $profile->location,
_('Where you are, like "City, State (or Region), Country"'));
$this->elementEnd('li');
- $this->elementStart('li');
- $this->checkbox('sharelocation', _('Share my current location when posting notices'),
- ($this->arg('sharelocation')) ?
- $this->arg('sharelocation') : $user->shareLocation());
- $this->elementEnd('li');
+ if (common_config('location', 'share') == 'user') {
+ $this->elementStart('li');
+ $this->checkbox('sharelocation', _('Share my current location when posting notices'),
+ ($this->arg('sharelocation')) ?
+ $this->arg('sharelocation') : $user->shareLocation());
+ $this->elementEnd('li');
+ }
Event::handle('EndProfileFormData', array($this));
$this->elementStart('li');
$this->input('tags', _('Tags'),
@@ -323,6 +325,37 @@ class ProfilesettingsAction extends AccountSettingsAction
$profile->profileurl = common_profile_url($nickname);
+ if (common_config('location', 'share') == 'user') {
+
+ $exists = false;
+
+ $prefs = User_location_prefs::staticGet('user_id', $user->id);
+
+ if (empty($prefs)) {
+ $prefs = new User_location_prefs();
+
+ $prefs->user_id = $user->id;
+ $prefs->created = common_sql_now();
+ } else {
+ $exists = true;
+ $orig = clone($prefs);
+ }
+
+ $prefs->share_location = $this->boolean('sharelocation');
+
+ if ($exists) {
+ $result = $prefs->update($orig);
+ } else {
+ $result = $prefs->insert();
+ }
+
+ if ($result === false) {
+ common_log_db_error($prefs, ($exists) ? 'UPDATE' : 'INSERT', __FILE__);
+ $this->serverError(_('Couldn\'t save location prefs.'));
+ return;
+ }
+ }
+
common_debug('Old profile: ' . common_log_objstring($orig_profile), __FILE__);
common_debug('New profile: ' . common_log_objstring($profile), __FILE__);