]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Improve handling of null values in profile parameters.
authorAdrian Lang <mail@adrianlang.de>
Tue, 3 Mar 2009 15:12:05 +0000 (16:12 +0100)
committerAdrian Lang <mail@adrianlang.de>
Mon, 9 Mar 2009 07:06:31 +0000 (08:06 +0100)
This commit fixes two issues:
- Allowing remote users to clear profile parameters via OMB.
- Improved handling of profile parameters which evaluate to
  false ('0' for example)

actions/finishremotesubscribe.php
actions/remotesubscribe.php
actions/updateprofile.php
actions/userauthorization.php
lib/profilelist.php

index acfacbdc1c4c4582372ec5b5a480e57442975fe9..eaf57c2d8fac59ea5862d22b155de58eb1f45e55 100644 (file)
@@ -136,16 +136,16 @@ class FinishremotesubscribeAction extends Action
         $profile->nickname = $nickname;
         $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;
         }
 
index 7ea7acd6d336bb6e04056c1d63fd5e5df5155f3d..a2e01bd3ae9028bbed70c78d85cb4a38873266b9 100644 (file)
@@ -367,16 +367,16 @@ class RemotesubscribeAction extends Action
             return;
         }
 
-        if ($profile->fullname) {
+        if (!is_null($profile->fullname)) {
             $req->set_parameter('omb_listenee_fullname', $profile->fullname);
         }
-        if ($profile->homepage) {
+        if (!is_null($profile->homepage)) {
             $req->set_parameter('omb_listenee_homepage', $profile->homepage);
         }
-        if ($profile->bio) {
+        if (!is_null($profile->bio)) {
             $req->set_parameter('omb_listenee_bio', $profile->bio);
         }
-        if ($profile->location) {
+        if (!is_null($profile->location)) {
             $req->set_parameter('omb_listenee_location', $profile->location);
         }
         $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
index 2268c432f17dd4cea52f00a77cb500a28e9cc745..7dc52fda9eaf69d315d83a585793accb563f7172 100644 (file)
@@ -138,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;
         }
 
index 0566b4b70bd0e825231ead79cd1085c1f74d4ed3..6a76e3a4c20809e9eb37537e1a1258fa77bab3a4 100644 (file)
@@ -113,9 +113,9 @@ class UserauthorizationAction extends Action
         $this->element('a', array('href' => $profile,
                                   'class' => 'external profile nickname'),
                        $nickname);
-        if ($fullname) {
+        if (!is_null($fullname)) {
             $this->elementStart('div', 'fullname');
-            if ($homepage) {
+            if (!is_null($homepage)) {
                 $this->element('a', array('href' => $homepage),
                                $fullname);
             } else {
@@ -123,10 +123,10 @@ class UserauthorizationAction extends Action
             }
             $this->elementEnd('div');
         }
-        if ($location) {
+        if (!is_null($location)) {
             $this->element('div', 'location', $location);
         }
-        if ($bio) {
+        if (!is_null($bio)) {
             $this->element('div', 'bio', $bio);
         }
         $this->elementStart('div', 'license');
@@ -179,16 +179,16 @@ class UserauthorizationAction extends Action
                 $params['omb_listener_nickname'] = $user->nickname;
                 $params['omb_listener_profile'] = common_local_url('showstream',
                                                                    array('nickname' => $user->nickname));
-                if ($profile->fullname) {
+                if (!is_null($profile->fullname)) {
                     $params['omb_listener_fullname'] = $profile->fullname;
                 }
-                if ($profile->homepage) {
+                if (!is_null($profile->homepage)) {
                     $params['omb_listener_homepage'] = $profile->homepage;
                 }
-                if ($profile->bio) {
+                if (!is_null($profile->bio)) {
                     $params['omb_listener_bio'] = $profile->bio;
                 }
-                if ($profile->location) {
+                if (!is_null($profile->location)) {
                     $params['omb_listener_location'] = $profile->location;
                 }
                 $avatar = $profile->getAvatar(AVATAR_PROFILE_SIZE);
@@ -267,16 +267,16 @@ class UserauthorizationAction extends Action
         $profile->nickname = $nickname;
         $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;
         }
 
@@ -409,7 +409,7 @@ class UserauthorizationAction extends Action
                        'omb_listenee_profile', 'omb_listenee_nickname',
                        'omb_listenee_license') as $param)
         {
-            if (!$req->get_parameter($param)) {
+            if (is_null($req->get_parameter($param))) {
                 throw new OAuthException("Required parameter '$param' not found");
             }
         }
index c2040fbc232a980fa2d926d926abbd6850b67614..75053b7a42c6cdb90014b15f026ece5b848a5c9e 100644 (file)
@@ -102,13 +102,13 @@ class ProfileList extends Widget
                                          'alt' =>
                                          ($this->profile->fullname) ? $this->profile->fullname :
                                          $this->profile->nickname));
-        $hasFN = ($this->profile->fullname) ? 'nickname' : 'fn nickname';
+        $hasFN = ($this->profile->fullname !== '') ? 'nickname' : 'fn nickname';
         $this->out->elementStart('span', $hasFN);
         $this->out->raw($this->highlight($this->profile->nickname));
         $this->out->elementEnd('span');
         $this->out->elementEnd('a');
 
-        if ($this->profile->fullname) {
+        if ($this->profile->fullname !== '') {
             $this->out->elementStart('dl', 'entity_fn');
             $this->out->element('dt', null, 'Full name');
             $this->out->elementStart('dd');
@@ -118,7 +118,7 @@ class ProfileList extends Widget
             $this->out->elementEnd('dd');
             $this->out->elementEnd('dl');
         }
-        if ($this->profile->location) {
+        if ($this->profile->location !== '') {
             $this->out->elementStart('dl', 'entity_location');
             $this->out->element('dt', null, _('Location'));
             $this->out->elementStart('dd', 'label');
@@ -126,7 +126,7 @@ class ProfileList extends Widget
             $this->out->elementEnd('dd');
             $this->out->elementEnd('dl');
         }
-        if ($this->profile->homepage) {
+        if ($this->profile->homepage !== '') {
             $this->out->elementStart('dl', 'entity_url');
             $this->out->element('dt', null, _('URL'));
             $this->out->elementStart('dd');
@@ -137,7 +137,7 @@ class ProfileList extends Widget
             $this->out->elementEnd('dd');
             $this->out->elementEnd('dl');
         }
-        if ($this->profile->bio) {
+        if ($this->profile->bio !== '') {
             $this->out->elementStart('dl', 'entity_note');
             $this->out->element('dt', null, _('Note'));
             $this->out->elementStart('dd', 'note');