]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Make /api/account/update_profile_background_image.format work even
authorZach Copley <zach@status.net>
Tue, 10 Nov 2009 07:56:02 +0000 (23:56 -0800)
committerZach Copley <zach@status.net>
Tue, 10 Nov 2009 07:56:02 +0000 (23:56 -0800)
when there isn't an existing Design for the user. Plus a few other
fixups.

actions/apiaccountratelimitstatus.php
actions/apiaccountupdateprofile.php
actions/apiaccountupdateprofilebackgroundimage.php
actions/apiaccountupdateprofilecolors.php
actions/apiaccountupdateprofileimage.php

index 96179f175b87a582ef60054c83156395461bc7e7..1a5afd552c90d8c1d43b6ecdb0cd257dfd40d356 100644 (file)
@@ -67,7 +67,7 @@ class ApiAccountRateLimitStatusAction extends ApiBareAuthAction
 
         if (!in_array($this->format, array('xml', 'json'))) {
             $this->clientError(
-                _('API method not found!'),
+                _('API method not found.'),
                 404,
                 $this->format
             );
index 8af0fb8660112b0fb53aa8429afe0e72ed88d23d..fd4384a25c465093f042cdeee6c4650ede04b245 100644 (file)
@@ -92,6 +92,15 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
             return;
         }
 
+        if (!in_array($this->format, array('xml', 'json'))) {
+            $this->clientError(
+                _('API method not found.'),
+                404,
+                $this->format
+            );
+            return;
+        }
+
         if (empty($this->user)) {
             $this->clientError(_('No such user.'), 404, $this->format);
             return;
@@ -135,7 +144,7 @@ class ApiAccountUpdateProfileAction extends ApiAuthAction
 
         if (!$result) {
             common_log_db_error($profile, 'UPDATE', __FILE__);
-            $this->serverError(_('Couldn\'t save profile.'));
+            $this->serverError(_('Could not save profile.'));
             return;
         }
 
index 26d55d448bde6761985c1f31ae42272d01b4f846..3537b9f9793354087c6cf11e9a8bb616dc7ece7d 100644 (file)
@@ -89,6 +89,15 @@ class ApiAccountUpdateProfileBackgroundImageAction extends ApiAuthAction
             return;
         }
 
+        if (!in_array($this->format, array('xml', 'json'))) {
+            $this->clientError(
+                _('API method not found.'),
+                404,
+                $this->format
+            );
+            return;
+        }
+
         // Workaround for PHP returning empty $_POST and $_FILES when POST
         // length > post_max_size in php.ini
 
@@ -104,10 +113,46 @@ class ApiAccountUpdateProfileBackgroundImageAction extends ApiAuthAction
         }
 
         if (empty($this->user)) {
-            $this->clientError(_('No such user!'), 404, $this->format);
+            $this->clientError(_('No such user.'), 404, $this->format);
             return;
         }
 
+        $design = $this->user->getDesign();
+
+        // XXX: This is kinda gross, but before we can add a background
+        // img we have to make sure there's a Design because design ID
+        // is part of the img filename.
+
+        if (empty($design)) {
+
+            $this->user->query('BEGIN');
+
+            // save new design
+            $design = new Design();
+            $id = $design->insert();
+
+            if (empty($id)) {
+                common_log_db_error($id, 'INSERT', __FILE__);
+                $this->clientError(_('Unable to save your design settings.'));
+                return;
+            }
+
+            $original              = clone($this->user);
+            $this->user->design_id = $id;
+            $result                = $this->user->update($original);
+
+            if (empty($result)) {
+                common_log_db_error($original, 'UPDATE', __FILE__);
+                $this->clientError(_('Unable to save your design settings.'));
+                $this->user->query('ROLLBACK');
+                return;
+            }
+
+            $this->user->query('COMMIT');
+        }
+
+        // Okay, now get the image and add it to the design
+
         try {
             $imagefile = ImageFile::fromUpload('image');
         } catch (Exception $e) {
@@ -115,8 +160,6 @@ class ApiAccountUpdateProfileBackgroundImageAction extends ApiAuthAction
             return;
         }
 
-        $design = $this->user->getDesign();
-
         $filename = Design::filename(
             $design->id,
             image_type_to_extension($imagefile->type),
@@ -134,16 +177,14 @@ class ApiAccountUpdateProfileBackgroundImageAction extends ApiAuthAction
         }
 
         $original = clone($design);
-
         $design->backgroundimage = $filename;
-
-        $design->setDisposition(true, false, !empty($this->tile));
+        $design->setDisposition(true, false, ($this->tile == 'true'));
 
         $result = $design->update($original);
 
         if ($result === false) {
             common_log_db_error($design, 'UPDATE', __FILE__);
-            $this->showForm(_('Couldn\'t update your design.'));
+            $this->showForm(_('Could not update your design.'));
             return;
         }
 
@@ -154,7 +195,7 @@ class ApiAccountUpdateProfileBackgroundImageAction extends ApiAuthAction
             return;
         }
 
-        $twitter_user = $this->twitterUserArray($this->user->getProfile(), true);
+        $twitter_user = $this->twitterUserArray($profile, true);
 
         if ($this->format == 'xml') {
             $this->initDocument('xml');
index d7d2161fea19d403f85ec8d5eef0bd19d0b63044..3cac829749679353ec4fc608a2ee9894367698da 100644 (file)
@@ -113,6 +113,15 @@ class ApiAccountUpdateProfileColorsAction extends ApiAuthAction
             return;
         }
 
+        if (!in_array($this->format, array('xml', 'json'))) {
+            $this->clientError(
+                _('API method not found.'),
+                404,
+                $this->format
+            );
+            return;
+        }
+
         $design = $this->user->getDesign();
 
         if (!empty($design)) {
@@ -130,7 +139,7 @@ class ApiAccountUpdateProfileColorsAction extends ApiAuthAction
 
             if ($result === false) {
                 common_log_db_error($design, 'UPDATE', __FILE__);
-                $this->clientError(_('Couldn\'t update your design.'));
+                $this->clientError(_('Could not update your design.'));
                 return;
             }
 
@@ -152,7 +161,7 @@ class ApiAccountUpdateProfileColorsAction extends ApiAuthAction
 
             if (empty($id)) {
                 common_log_db_error($id, 'INSERT', __FILE__);
-                $this->clientError(_('Unable to save your design settings!'));
+                $this->clientError(_('Unable to save your design settings.'));
                 return;
             }
 
@@ -162,7 +171,7 @@ class ApiAccountUpdateProfileColorsAction extends ApiAuthAction
 
             if (empty($result)) {
                 common_log_db_error($original, 'UPDATE', __FILE__);
-                $this->clientError(_('Unable to save your design settings!'));
+                $this->clientError(_('Unable to save your design settings.'));
                 $this->user->query('ROLLBACK');
                 return;
             }
@@ -177,7 +186,7 @@ class ApiAccountUpdateProfileColorsAction extends ApiAuthAction
             return;
         }
 
-        $twitter_user = $this->twitterUserArray($this->user->getProfile(), true);
+        $twitter_user = $this->twitterUserArray($profile, true);
 
         if ($this->format == 'xml') {
             $this->initDocument('xml');
index 72fb361bf8bcbdf183bb3e4f9304c4350d5d4d6d..153ef7818ee03a9f09cc74bb4b790b8392e516bb 100644 (file)
@@ -102,7 +102,7 @@ class ApiAccountUpdateProfileImageAction extends ApiAuthAction
         }
 
         if (empty($this->user)) {
-            $this->clientError(_('No such user!'), 404, $this->format);
+            $this->clientError(_('No such user.'), 404, $this->format);
             return;
         }
 
@@ -135,7 +135,7 @@ class ApiAccountUpdateProfileImageAction extends ApiAuthAction
 
         common_broadcast_profile($profile);
 
-        $twitter_user = $this->twitterUserArray($this->user->getProfile(), true);
+        $twitter_user = $this->twitterUserArray($profile, true);
 
         if ($this->format == 'xml') {
             $this->initDocument('xml');