From 78f9629bf3553a709c99e13f480bd225083e5ca5 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 6 Oct 2013 13:38:09 +0200 Subject: [PATCH] Moved shareLocation preference check to Profile class --- actions/apistatusesupdate.php | 16 ++++++------ actions/newnotice.php | 2 +- actions/profilesettings.php | 2 +- classes/Profile.php | 25 ++++++++++++++++++- classes/User.php | 23 ----------------- lib/apiaction.php | 6 ++--- lib/apiauthaction.php | 6 ++--- lib/noticeform.php | 2 +- .../lib/noticetree.php | 4 +-- 9 files changed, 42 insertions(+), 44 deletions(-) diff --git a/actions/apistatusesupdate.php b/actions/apistatusesupdate.php index 374930fff0..ac93d58e33 100644 --- a/actions/apistatusesupdate.php +++ b/actions/apistatusesupdate.php @@ -158,7 +158,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction * * @return boolean success flag */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); @@ -181,9 +181,9 @@ class ApiStatusesUpdateAction extends ApiAuthAction * * @return void */ - function handle($args) + protected function handle() { - parent::handle($args); + parent::handle(); if ($_SERVER['REQUEST_METHOD'] != 'POST') { $this->clientError( @@ -222,7 +222,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction return; } - if (empty($this->auth_user)) { + if (is_null($this->scoped)) { // TRANS: Client error displayed when updating a status for a non-existing user. $this->clientError(_('No such user.'), 404, $this->format); return; @@ -269,7 +269,7 @@ class ApiStatusesUpdateAction extends ApiAuthAction $upload = null; try { - $upload = MediaFile::fromUpload('media', $this->auth_user->getProfile()); + $upload = MediaFile::fromUpload('media', $this->scoped); } catch (Exception $e) { $this->clientError($e->getMessage(), $e->getCode(), $this->format); return; @@ -306,20 +306,20 @@ class ApiStatusesUpdateAction extends ApiAuthAction $options = array('reply_to' => $reply_to); - if ($this->auth_user->shareLocation()) { + if ($this->scoped->shareLocation()) { $locOptions = Notice::locationOptions($this->lat, $this->lon, null, null, - $this->auth_user->getProfile()); + $this->scoped); $options = array_merge($options, $locOptions); } try { $this->notice = Notice::saveNew( - $this->auth_user->id, + $this->scoped->id, $content, $this->source, $options diff --git a/actions/newnotice.php b/actions/newnotice.php index 0d441c0431..0c12c7d74a 100644 --- a/actions/newnotice.php +++ b/actions/newnotice.php @@ -134,7 +134,7 @@ class NewnoticeAction extends FormAction } } - if ($user->shareLocation()) { + if ($this->scoped->shareLocation()) { // use browser data if checked; otherwise profile data if ($this->arg('notice_data-geo')) { $locOptions = Notice::locationOptions($this->trimmed('lat'), diff --git a/actions/profilesettings.php b/actions/profilesettings.php index f588462967..2279732c1e 100644 --- a/actions/profilesettings.php +++ b/actions/profilesettings.php @@ -150,7 +150,7 @@ class ProfilesettingsAction extends SettingsAction // TRANS: Checkbox label in form for profile settings. $this->checkbox('sharelocation', _('Share my current location when posting notices'), ($this->arg('sharelocation')) ? - $this->arg('sharelocation') : $user->shareLocation()); + $this->arg('sharelocation') : $this->scoped->shareLocation()); $this->elementEnd('li'); } Event::handle('EndProfileFormData', array($this)); diff --git a/classes/Profile.php b/classes/Profile.php index da779f9d4f..1f8e7fc882 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -955,7 +955,7 @@ class Profile extends Managed_DataObject // XXX: identical to Notice::getLocation. - function getLocation() + public function getLocation() { $location = null; @@ -978,6 +978,29 @@ class Profile extends Managed_DataObject return $location; } + public function shareLocation() + { + $cfg = common_config('location', 'share'); + + if ($cfg == 'always') { + return true; + } else if ($cfg == 'never') { + return false; + } else { // user + $share = common_config('location', 'sharedefault'); + + // Check if user has a personal setting for this + $prefs = User_location_prefs::getKV('user_id', $this->id); + + if (!empty($prefs)) { + $share = $prefs->share_location; + $prefs->free(); + } + + return $share; + } + } + function hasRole($name) { $has_role = false; diff --git a/classes/User.php b/classes/User.php index 9ad9a4a61f..e9f1d1b2cf 100644 --- a/classes/User.php +++ b/classes/User.php @@ -861,29 +861,6 @@ class User extends Managed_DataObject throw new Exception(_('Not implemented since inbox change.')); } - function shareLocation() - { - $cfg = common_config('location', 'share'); - - if ($cfg == 'always') { - return true; - } else if ($cfg == 'never') { - return false; - } else { // user - $share = common_config('location', 'sharedefault'); - - // Check if user has a personal setting for this - $prefs = User_location_prefs::getKV('user_id', $this->id); - - if (!empty($prefs)) { - $share = $prefs->share_location; - $prefs->free(); - } - - return $share; - } - } - public static function siteOwner() { $owner = self::cacheGet('user:site_owner'); diff --git a/lib/apiaction.php b/lib/apiaction.php index 8fdf91a5ac..781d106cf6 100644 --- a/lib/apiaction.php +++ b/lib/apiaction.php @@ -140,7 +140,7 @@ class ApiAction extends Action * * @return boolean false if user doesn't exist */ - function prepare($args) + protected function prepare(array $args=array()) { StatusNet::setApi(true); // reduce exception reports to aid in debugging parent::prepare($args); @@ -172,10 +172,10 @@ class ApiAction extends Action * * @return void */ - function handle($args) + protected function handle() { header('Access-Control-Allow-Origin: *'); - parent::handle($args); + parent::handle(); } /** diff --git a/lib/apiauthaction.php b/lib/apiauthaction.php index 54b05b3d52..012ed49ceb 100644 --- a/lib/apiauthaction.php +++ b/lib/apiauthaction.php @@ -53,9 +53,7 @@ */ -if (!defined('STATUSNET')) { - exit(1); -} +if (!defined('GNUSOCIAL')) { exit(1); } /** * Actions extending this class will require auth @@ -80,7 +78,7 @@ class ApiAuthAction extends ApiAction * @return boolean success flag * */ - function prepare($args) + protected function prepare(array $args=array()) { parent::prepare($args); diff --git a/lib/noticeform.php b/lib/noticeform.php index 6a0720821d..f4a3ecfd86 100644 --- a/lib/noticeform.php +++ b/lib/noticeform.php @@ -246,7 +246,7 @@ class NoticeForm extends Form $toWidget->show(); $this->out->elementEnd('div'); - if ($this->user->shareLocation()) { + if ($this->profile->shareLocation()) { $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat'); $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon'); $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id'); diff --git a/plugins/GNUsocialProfileExtensions/lib/noticetree.php b/plugins/GNUsocialProfileExtensions/lib/noticetree.php index bdf9d32de9..8930d6c72a 100644 --- a/plugins/GNUsocialProfileExtensions/lib/noticetree.php +++ b/plugins/GNUsocialProfileExtensions/lib/noticetree.php @@ -206,7 +206,7 @@ class ReplyForm extends NoticeForm } $this->out->hidden('notice_in-reply-to', $this->inreplyto, 'inreplyto'); - if ($this->user->shareLocation()) { + if ($this->profile->shareLocation()) { $this->out->hidden('notice_data-lat', empty($this->lat) ? (empty($this->profile->lat) ? null : $this->profile->lat) : $this->lat, 'lat'); $this->out->hidden('notice_data-lon', empty($this->lon) ? (empty($this->profile->lon) ? null : $this->profile->lon) : $this->lon, 'lon'); $this->out->hidden('notice_data-location_id', empty($this->location_id) ? (empty($this->profile->location_id) ? null : $this->profile->location_id) : $this->location_id, 'location_id'); @@ -225,4 +225,4 @@ class ReplyForm extends NoticeForm Event::handle('EndShowNoticeFormData', array($this)); } } -} \ No newline at end of file +}