]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Moved shareLocation preference check to Profile class
authorMikael Nordfeldth <mmn@hethane.se>
Sun, 6 Oct 2013 11:38:09 +0000 (13:38 +0200)
committerMikael Nordfeldth <mmn@hethane.se>
Sun, 6 Oct 2013 11:38:09 +0000 (13:38 +0200)
actions/apistatusesupdate.php
actions/newnotice.php
actions/profilesettings.php
classes/Profile.php
classes/User.php
lib/apiaction.php
lib/apiauthaction.php
lib/noticeform.php
plugins/GNUsocialProfileExtensions/lib/noticetree.php

index 374930fff007f9d2d47c4542df4b8f3d5f30a726..ac93d58e33d6b697f3afbc5729bfcab2941c2985 100644 (file)
@@ -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
index 0d441c04316c26c8193521de0a63ec80416bf197..0c12c7d74ad70ca022dfe57b9c0f71ff462473da 100644 (file)
@@ -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'),
index f5884629678a84d1a114da213d431bf531ea03f1..2279732c1eca2145703e5c56d45e4612f0f0cd78 100644 (file)
@@ -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));
index da779f9d4f0dc0a5d07263ba26718928b95621ec..1f8e7fc8822abea86d5094a4099f3e5e4f2fe848 100644 (file)
@@ -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;
index 9ad9a4a61f9afe2d2af5843394ab8daba17725d1..e9f1d1b2cfc0499caafe8e4688084cbf2154bccd 100644 (file)
@@ -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');
index 8fdf91a5ac2b67eec2e043293acb1d5d7315ca89..781d106cf6bf4a68913b54dcd37dd82d891a66bf 100644 (file)
@@ -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();
     }
 
     /**
index 54b05b3d52c49d5fa4a9bf509ec92eb2ff1d4c31..012ed49cebc2dd88ee680da2f56715aa2b86c184 100644 (file)
@@ -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);
 
index 6a0720821d62958fd0a47aee810f738fa7065186..f4a3ecfd865cda367531100807aa4af6271b3f07 100644 (file)
@@ -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');
index bdf9d32de93aadced0c503895f0ad381a4a0f7e1..8930d6c72a68193cc322bdf00d9891007c98912b 100644 (file)
@@ -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
+}