]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - actions/finishremotesubscribe.php
Make OMB work if the configured domain name does not exclusively contain lower case...
[quix0rs-gnu-social.git] / actions / finishremotesubscribe.php
index 38a56c96200fdab1f65d8c330b0e44bf53596ebe..3e3a817154ddef6c5a81bb413a15817cf7956be8 100644 (file)
@@ -21,7 +21,8 @@ if (!defined('LACONICA')) { exit(1); }
 
 require_once(INSTALLDIR.'/lib/omb.php');
 
-class FinishremotesubscribeAction extends Action {
+class FinishremotesubscribeAction extends Action
+{
 
     function handle($args)
     {
@@ -29,59 +30,59 @@ class FinishremotesubscribeAction extends Action {
         parent::handle($args);
 
         if (common_logged_in()) {
-            common_user_error(_('You can use the local subscription!'));
+            $this->clientError(_('You can use the local subscription!'));
             return;
         }
 
         $omb = $_SESSION['oauth_authorization_request'];
 
         if (!$omb) {
-            common_user_error(_('Not expecting this response!'));
+            $this->clientError(_('Not expecting this response!'));
             return;
         }
 
         common_debug('stored request: '.print_r($omb,true), __FILE__);
 
         common_remove_magic_from_request();
-        $req = OAuthRequest::from_request();
+        $req = OAuthRequest::from_request('POST', common_local_url('finishuserauthorization'));
 
         $token = $req->get_parameter('oauth_token');
 
         # I think this is the success metric
 
         if ($token != $omb['token']) {
-            common_user_error(_('Not authorized.'));
+            $this->clientError(_('Not authorized.'));
             return;
         }
 
         $version = $req->get_parameter('omb_version');
 
         if ($version != OMB_VERSION_01) {
-            common_user_error(_('Unknown version of OMB protocol.'));
+            $this->clientError(_('Unknown version of OMB protocol.'));
             return;
         }
 
         $nickname = $req->get_parameter('omb_listener_nickname');
 
         if (!$nickname) {
-            common_user_error(_('No nickname provided by remote server.'));
+            $this->clientError(_('No nickname provided by remote server.'));
             return;
         }
 
         $profile_url = $req->get_parameter('omb_listener_profile');
 
         if (!$profile_url) {
-            common_user_error(_('No profile URL returned by server.'));
+            $this->clientError(_('No profile URL returned by server.'));
             return;
         }
 
         if (!Validate::uri($profile_url, array('allowed_schemes' => array('http', 'https')))) {
-            common_user_error(_('Invalid profile URL returned by server.'));
+            $this->clientError(_('Invalid profile URL returned by server.'));
             return;
         }
 
         if ($profile_url == common_local_url('showstream', array('nickname' => $nickname))) {
-            common_user_error(_('You can use the local subscription!'));
+            $this->clientError(_('You can use the local subscription!'));
             return;
         }
 
@@ -90,14 +91,14 @@ class FinishremotesubscribeAction extends Action {
         $user = User::staticGet('nickname', $omb['listenee']);
 
         if (!$user) {
-            common_user_error(_('User being listened to doesn\'t exist.'));
+            $this->clientError(_('User being listened to doesn\'t exist.'));
             return;
         }
 
         $other = User::staticGet('uri', $omb['listener']);
 
         if ($other) {
-            common_user_error(_('You can use the local subscription!'));
+            $this->clientError(_('You can use the local subscription!'));
             return;
         }
 
@@ -110,7 +111,7 @@ class FinishremotesubscribeAction extends Action {
         list($newtok, $newsecret) = $this->access_token($omb);
 
         if (!$newtok || !$newsecret) {
-            common_user_error(_('Couldn\'t convert request tokens to access tokens.'));
+            $this->clientError(_('Couldn\'t convert request tokens to access tokens.'));
             return;
         }
 
@@ -135,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;
         }
 
@@ -154,7 +155,7 @@ class FinishremotesubscribeAction extends Action {
             $profile->created = DB_DataObject_Cast::dateTime(); # current time
             $id = $profile->insert();
             if (!$id) {
-                common_server_error(_('Error inserting new profile'));
+                $this->serverError(_('Error inserting new profile'));
                 return;
             }
             $remote->id = $id;
@@ -162,7 +163,7 @@ class FinishremotesubscribeAction extends Action {
 
         if ($avatar_url) {
             if (!$this->add_avatar($profile, $avatar_url)) {
-                common_server_error(_('Error inserting avatar'));
+                $this->serverError(_('Error inserting avatar'));
                 return;
             }
         }
@@ -172,19 +173,19 @@ class FinishremotesubscribeAction extends Action {
 
         if ($exists) {
             if (!$remote->update($orig_remote)) {
-                common_server_error(_('Error updating remote profile'));
+                $this->serverError(_('Error updating remote profile'));
                 return;
             }
         } else {
             $remote->created = DB_DataObject_Cast::dateTime(); # current time
             if (!$remote->insert()) {
-                common_server_error(_('Error inserting remote profile'));
+                $this->serverError(_('Error inserting remote profile'));
                 return;
             }
         }
 
         if ($user->hasBlocked($profile)) {
-            $this->client_error(_('That user has blocked you from subscribing.'));
+            $this->clientError(_('That user has blocked you from subscribing.'));
             return;
         }
 
@@ -214,7 +215,7 @@ class FinishremotesubscribeAction extends Action {
 
         if (!$result) {
             common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
-            common_user_error(_('Couldn\'t insert new subscription.'));
+            $this->clientError(_('Couldn\'t insert new subscription.'));
             return;
         }
 
@@ -229,14 +230,21 @@ class FinishremotesubscribeAction extends Action {
         # show up close to the top of the page
 
         common_redirect(common_local_url('subscribers', array('nickname' =>
-                                                             $user->nickname)));
+                                                             $user->nickname)),
+                        303);
     }
 
     function add_avatar($profile, $url)
     {
         $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
         copy($url, $temp_filename);
-        return $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));
+        return $profile->setOriginal($filename);
     }
 
     function access_token($omb)
@@ -276,9 +284,9 @@ class FinishremotesubscribeAction extends Action {
         $fetcher = Auth_Yadis_Yadis::getHTTPFetcher();
         $result = $fetcher->post($req->get_normalized_http_url(),
                                  $req->to_postdata(),
-                                 array('User-Agent' => 'Laconica/' . LACONICA_VERSION));
+                                 array('User-AgentLaconica/' . LACONICA_VERSION));
 
-        common_debug('got result: "'.print_r($result,TRUE).'"', __FILE__);
+        common_debug('got result: "'.print_r($result,true).'"', __FILE__);
 
         if ($result->status != 200) {
             return null;