]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apiaccountupdateprofile.php
Merge branch 'nginx-sample' into 'nightly'
[quix0rs-gnu-social.git] / actions / apiaccountupdateprofile.php
index 9b371ea95764e1f829e7c9bce1eba8cffcb3859a..8767dabf8528a6ef23c597bb7b4a8de47903ba8a 100644 (file)
@@ -31,8 +31,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/apiauth.php';
-
 /**
  * API analog to the profile settings page
  * Only the parameters specified will be updated.
@@ -43,9 +41,9 @@ require_once INSTALLDIR . '/lib/apiauth.php';
  * @license  http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0
  * @link     http://status.net/
  */
-
 class ApiAccountUpdateProfileAction extends ApiAuthAction
 {
+    protected $needPost = true;
 
     /**
      * Take arguments for running
@@ -53,10 +51,8 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
      * @param array $args $_REQUEST args
      *
      * @return boolean success flag
-     *
      */
-
-    function prepare($args)
+    protected function prepare(array $args=array())
     {
         parent::prepare($args);
 
@@ -75,62 +71,38 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
      *
      * See which request params have been set, and update the profile
      *
-     * @param array $args $_REQUEST data (unused)
-     *
      * @return void
      */
-
-    function handle($args)
+    protected function handle()
     {
-        parent::handle($args);
-
-        if ($_SERVER['REQUEST_METHOD'] != 'POST') {
-            $this->clientError(
-                _('This method requires a POST.'),
-                400, $this->format
-            );
-            return;
-        }
+        parent::handle();
 
         if (!in_array($this->format, array('xml', 'json'))) {
-            $this->clientError(
-                _('API method not found.'),
-                404,
-                $this->format
-            );
-            return;
+            // TRANS: Client error displayed when coming across a non-supported API method.
+            $this->clientError(_('API method not found.'), 404);
         }
 
         if (empty($this->user)) {
-            $this->clientError(_('No such user.'), 404, $this->format);
-            return;
+            // TRANS: Client error displayed if a user could not be found.
+            $this->clientError(_('No such user.'), 404);
         }
 
         $profile = $this->user->getProfile();
 
         if (empty($profile)) {
+            // TRANS: Error message displayed when referring to a user without a profile.
             $this->clientError(_('User has no profile.'));
-            return;
         }
 
         $original = clone($profile);
 
-        if (!empty($this->name)) {
-            $profile->fullname = $this->name;
-        }
-
-        if (!empty($this->url)) {
-            $profile->homepage = $this->url;
-        }
-
-        if (!empty($this->description)) {
-            $profile->bio = $this->description;
-        }
+        $profile->fullname = $this->name;
+        $profile->homepage = $this->url;
+        $profile->bio = $this->description;
+        $profile->location = $this->location;
 
         if (!empty($this->location)) {
-            $profile->location = $this->location;
-
-            $loc = Location::fromName($location);
+            $loc = Location::fromName($this->location);
 
             if (!empty($loc)) {
                 $profile->lat         = $loc->lat;
@@ -138,23 +110,27 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
                 $profile->location_id = $loc->location_id;
                 $profile->location_ns = $loc->location_ns;
             }
+        } else {
+            // location is empty so reset the extrapolated information too
+            $profile->lat = '';
+            $profile->lon = '';
+            $profile->location_id = '';
+            $profile->location_ns = '';
         }
 
         $result = $profile->update($original);
 
         if (!$result) {
             common_log_db_error($profile, 'UPDATE', __FILE__);
+            // TRANS: Server error displayed if a user profile could not be saved.
             $this->serverError(_('Could not save profile.'));
-            return;
         }
 
-        common_broadcast_profile($profile);
-
         $twitter_user = $this->twitterUserArray($profile, true);
 
         if ($this->format == 'xml') {
             $this->initDocument('xml');
-            $this->showTwitterXmlUser($twitter_user);
+            $this->showTwitterXmlUser($twitter_user, 'user', true);
             $this->endDocument('xml');
         } elseif ($this->format == 'json') {
             $this->initDocument('json');
@@ -162,5 +138,4 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
             $this->endDocument('json');
         }
     }
-
 }