]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/updateprofile.php
update version in README, add note about status.net
[quix0rs-gnu-social.git] / actions / updateprofile.php
index c79112dace79a514a520814317bd0179f35c2779..9a4cf8e4659b6f51c09fb23a48993457efd52014 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
- * Laconica - a distributed open-source microblogging tool
- * Copyright (C) 2008, Controlez-Vous, Inc.
+ * StatusNet - the distributed open-source microblogging tool
+ * Copyright (C) 2008, 2009, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -17,7 +17,7 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-if (!defined('LACONICA')) { exit(1); }
+if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 require_once(INSTALLDIR.'/lib/omb.php');
 
@@ -29,11 +29,13 @@ class UpdateprofileAction extends Action
         parent::handle($args);
         try {
             common_remove_magic_from_request();
-            $req = OAuthRequest::from_request();
+            $req = OAuthRequest::from_request('POST', common_local_url('updateprofile'));
             # Note: server-to-server function!
             $server = omb_oauth_server();
             list($consumer, $token) = $server->verify_request($req);
             if ($this->update_profile($req, $consumer, $token)) {
+                header('HTTP/1.1 200 OK');
+                header('Content-type: text/plain');
                 print "omb_version=".OMB_VERSION_01;
             }
         } catch (OAuthException $e) {
@@ -77,7 +79,7 @@ class UpdateprofileAction extends Action
         $nickname = $req->get_parameter('omb_listenee_nickname');
         if ($nickname && !Validate::string($nickname, array('min_length' => 1,
                                                             'max_length' => 64,
-                                                            'format' => VALIDATE_NUM . VALIDATE_ALPHA_LOWER))) {
+                                                            'format' => NICKNAME_FMT))) {
             $this->clientError(_('Nickname must have only lowercase letters and numbers and no spaces.'));
             return false;
         }
@@ -93,22 +95,22 @@ class UpdateprofileAction extends Action
         }
         # optional stuff
         $fullname = $req->get_parameter('omb_listenee_fullname');
-        if ($fullname && strlen($fullname) > 255) {
+        if ($fullname && mb_strlen($fullname) > 255) {
             $this->clientError(_("Full name is too long (max 255 chars)."));
             return false;
         }
         $homepage = $req->get_parameter('omb_listenee_homepage');
-        if ($homepage && (!common_valid_http_url($homepage) || strlen($homepage) > 255)) {
+        if ($homepage && (!common_valid_http_url($homepage) || mb_strlen($homepage) > 255)) {
             $this->clientError(sprintf(_("Invalid homepage '%s'"), $homepage));
             return false;
         }
         $bio = $req->get_parameter('omb_listenee_bio');
-        if ($bio && strlen($bio) > 140) {
+        if ($bio && mb_strlen($bio) > 140) {
             $this->clientError(_("Bio is too long (max 140 chars)."));
             return false;
         }
         $location = $req->get_parameter('omb_listenee_location');
-        if ($location && strlen($location) > 255) {
+        if ($location && mb_strlen($location) > 255) {
             $this->clientError(_("Location is too long (max 255 chars)."));
             return false;
         }
@@ -136,22 +138,24 @@ class UpdateprofileAction extends Action
 
         $orig_profile = clone($profile);
 
-        if ($nickname) {
+        /* Use values even if they are an empty string. Parsing an empty string in
+           updateProfile is the specified way of clearing a parameter in OMB. */
+        if (!is_null($nickname)) {
             $profile->nickname = $nickname;
         }
-        if ($profile_url) {
+        if (!is_null($profile_url)) {
             $profile->profileurl = $profile_url;
         }
-        if ($fullname) {
+        if (!is_null($fullname)) {
             $profile->fullname = $fullname;
         }
-        if ($homepage) {
+        if (!is_null($homepage)) {
             $profile->homepage = $homepage;
         }
-        if ($bio) {
+        if (!is_null($bio)) {
             $profile->bio = $bio;
         }
-        if ($location) {
+        if (!is_null($location)) {
             $profile->location = $location;
         }
 
@@ -162,15 +166,17 @@ class UpdateprofileAction extends Action
             if ($avatar) {
                 $temp_filename = tempnam(sys_get_temp_dir(), 'listenee_avatar');
                 copy($avatar, $temp_filename);
-                if (!$profile->setOriginal($temp_filename)) {
+                $imagefile = new ImageFile($profile->id, $temp_filename);
+                $filename = Avatar::filename($profile->id,
+                                     image_type_to_extension($imagefile->type),
+                                     null,
+                                     common_timestamp());
+                rename($temp_filename, Avatar::path($filename));
+                if (!$profile->setOriginal($filename)) {
                     $this->serverError(_('Could not save avatar info'), 500);
                     return false;
                 }
             }
-            header('HTTP/1.1 200 OK');
-            header('Content-type: text/plain');
-            print 'Updated profile';
-            print "\n";
             return true;
         }
     }