]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/apigroupprofileupdate.php
Making many of the API actions more consistent with coding style
[quix0rs-gnu-social.git] / actions / apigroupprofileupdate.php
index 379e01a428efd09c694b06b62b2c6405b9661317..14ec84326967ccafc8a2ba667579e2ad1fa3ad5d 100644 (file)
@@ -31,8 +31,6 @@ if (!defined('STATUSNET')) {
     exit(1);
 }
 
-require_once INSTALLDIR . '/lib/apiauth.php';
-
 /**
  * API analog to the group edit page
  *
@@ -44,6 +42,7 @@ require_once INSTALLDIR . '/lib/apiauth.php';
  */
 class ApiGroupProfileUpdateAction extends ApiAuthAction
 {
+    protected $needPost = true;
     /**
      * Take arguments for running
      *
@@ -52,7 +51,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
      * @return boolean success flag
      *
      */
-    function prepare($args)
+    protected function prepare($args)
     {
         parent::prepare($args);
 
@@ -75,49 +74,30 @@ class ApiGroupProfileUpdateAction 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(
-                // TRANS: Client error message. POST is a HTTP command. It should not be translated.
-                _('This method requires a POST.'),
-                400, $this->format
-            );
-            return;
-        }
+        parent::handle();
 
         if (!in_array($this->format, array('xml', 'json'))) {
-            $this->clientError(
-                // TRANS: Client error displayed when coming across a non-supported API method.
-                _('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)) {
             // TRANS: Client error displayed when not providing a user or an invalid user.
-            $this->clientError(_('No such user.'), 404, $this->format);
-            return;
+            $this->clientError(_('No such user.'), 404);
         }
 
         if (empty($this->group)) {
             // TRANS: Client error displayed when not providing a group or an invalid group.
-            $this->clientError(_('Group not found.'), 404, $this->format);
-            return false;
+            $this->clientError(_('Group not found.'), 404);
         }
 
         if (!$this->user->isAdmin($this->group)) {
             // TRANS: Client error displayed when trying to edit a group without being an admin.
             $this->clientError(_('You must be an admin to edit the group.'), 403);
-            return false;
         }
 
         $this->group->query('BEGIN');
@@ -157,12 +137,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
             }
 
         } catch (ApiValidationException $ave) {
-            $this->clientError(
-                $ave->getMessage(),
-                403,
-                $this->format
-            );
-            return;
+            $this->clientError($ave->getMessage(), 403);
         }
 
         $result = $this->group->update($orig);
@@ -181,12 +156,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
             }
 
         } catch (ApiValidationException $ave) {
-            $this->clientError(
-                $ave->getMessage(),
-                403,
-                $this->format
-            );
-            return;
+            $this->clientError($ave->getMessage(), 403);
         }
 
         $result = $this->group->setAliases($aliases);
@@ -198,7 +168,7 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
 
         if (!empty($this->nickname) && ($this->nickname != $orig->nickname)) {
             common_log(LOG_INFO, "Saving local group info.");
-            $local = Local_group::staticGet('group_id', $this->group->id);
+            $local = Local_group::getKV('group_id', $this->group->id);
             $local->setNickname($this->nickname);
         }
 
@@ -213,21 +183,20 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
             break;
         default:
             // TRANS: Client error displayed when coming across a non-supported API method.
-            $this->clientError(_('API method not found.'), 404, $this->format);
-            break;
+            $this->clientError(_('API method not found.'), 404);
         }
     }
 
     function nicknameExists($nickname)
     {
-        $group = Local_group::staticGet('nickname', $nickname);
+        $group = Local_group::getKV('nickname', $nickname);
 
         if (!empty($group) &&
             $group->group_id != $this->group->id) {
             return true;
         }
 
-        $alias = Group_alias::staticGet('alias', $nickname);
+        $alias = Group_alias::getKV('alias', $nickname);
 
         if (!empty($alias) &&
             $alias->group_id != $this->group->id) {
@@ -269,13 +238,8 @@ class ApiGroupProfileUpdateAction extends ApiAuthAction
     function validateHomepage()
     {
         if (!is_null($this->homepage)
-        && (strlen($this->homepage) > 0)
-        && !Validate::uri(
-                $this->homepage,
-                array('allowed_schemes' => array('http', 'https')
-                )
-            )
-        ) {
+                && (strlen($this->homepage) > 0)
+                && !common_valid_http_url($this->homepage)) {
             throw new ApiValidationException(
                 // TRANS: API validation exception thrown when homepage URL does not validate.
                 _('Homepage is not a valid URL.')