]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/oauthstore.php
Merge remote branch 'gitorious/1.0.x' into 1.0.x
[quix0rs-gnu-social.git] / lib / oauthstore.php
index d617a7df7e6216f52d72d0beec8892487256f94b..1c8e7250092bdb56e644e10fd6f4184eeb3a8f63 100644 (file)
@@ -55,6 +55,17 @@ class StatusNetOAuthDataStore extends OAuthDataStore
         }
     }
 
+    function getTokenByKey($token_key)
+    {
+        $t = new Token();
+        $t->tok = $token_key;
+        if ($t->find(true)) {
+            return $t;
+        } else {
+            return null;
+        }
+    }
+
     // http://oauth.net/core/1.0/#nonce
     // "The Consumer SHALL then generate a Nonce value that is unique for
     // all requests with that timestamp."
@@ -65,7 +76,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
     {
         $n = new Nonce();
         $n->consumer_key = $consumer->key;
-        $n->ts = $timestamp;
+        $n->ts = common_sql_date($timestamp);
         $n->nonce = $nonce;
         if ($n->find(true)) {
             return true;
@@ -280,7 +291,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
                 $profile->created = DB_DataObject_Cast::dateTime(); # current time
                 $id = $profile->insert();
                 if (!$id) {
-                    throw new Exception(_('Error inserting new profile'));
+                    throw new Exception(_('Error inserting new profile.'));
                 }
                 $remote->id = $id;
             }
@@ -288,7 +299,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
             $avatar_url = $omb_profile->getAvatarURL();
             if ($avatar_url) {
                 if (!$this->add_avatar($profile, $avatar_url)) {
-                    throw new Exception(_('Error inserting avatar'));
+                    throw new Exception(_('Error inserting avatar.'));
                 }
             } else {
                 $avatar = $profile->getOriginalAvatar();
@@ -303,12 +314,12 @@ class StatusNetOAuthDataStore extends OAuthDataStore
 
             if ($exists) {
                 if (!$remote->update($orig_remote)) {
-                    throw new Exception(_('Error updating remote profile'));
+                    throw new Exception(_('Error updating remote profile.'));
                 }
             } else {
                 $remote->created = DB_DataObject_Cast::dateTime(); # current time
                 if (!$remote->insert()) {
-                    throw new Exception(_('Error inserting remote profile'));
+                    throw new Exception(_('Error inserting remote profile.'));
                 }
             }
         }
@@ -317,13 +328,18 @@ class StatusNetOAuthDataStore extends OAuthDataStore
     function add_avatar($profile, $url)
     {
         $temp_filename = tempnam(sys_get_temp_dir(), 'listener_avatar');
-        copy($url, $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));
+        try {
+            copy($url, $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));
+        } catch (Exception $e) {
+            unlink($temp_filename);
+            throw $e;
+        }
         return $profile->setOriginal($filename);
     }
 
@@ -342,7 +358,8 @@ class StatusNetOAuthDataStore extends OAuthDataStore
      **/
     public function saveNotice(&$omb_notice) {
         if (Notice::staticGet('uri', $omb_notice->getIdentifierURI())) {
-            throw new Exception(_('Duplicate notice'));
+            // TRANS: Exception thrown when a notice is denied because it has been sent before.
+            throw new Exception(_('Duplicate notice.'));
         }
         $author_uri = $omb_notice->getAuthor()->getIdentifierURI();
         common_log(LOG_DEBUG, $author_uri, __FILE__);
@@ -351,7 +368,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
             $author = User::staticGet('uri', $author_uri);
         }
         if (!$author) {
-            throw new Exception('No such user');
+            throw new Exception('No such user.');
         }
 
         common_log(LOG_DEBUG, print_r($author, true), __FILE__);
@@ -359,11 +376,9 @@ class StatusNetOAuthDataStore extends OAuthDataStore
         $notice = Notice::saveNew($author->id,
                                   $omb_notice->getContent(),
                                   'omb',
-                                  false,
-                                  null,
-                                  $omb_notice->getIdentifierURI());
+                                  array('is_local' => Notice::REMOTE_OMB,
+                                        'uri' => $omb_notice->getIdentifierURI()));
 
-        common_broadcast_notice($notice, true);
     }
 
     /**
@@ -392,7 +407,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
         $sub->subscribed = $user->id;
 
         if (!$sub->find(true)) {
-            return 0;
+            return array();
         }
 
         /* Since we do not use OMB_Service_Provider’s action methods, there
@@ -407,7 +422,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
             $user = User::staticGet('uri', $uri);
         }
         if (!$user) {
-            throw new Exception('No such user');
+            throw new Exception('No such user.');
         }
         return $user;
     }
@@ -462,6 +477,11 @@ class StatusNetOAuthDataStore extends OAuthDataStore
         $subscribed = $this->_getAnyProfile($subscribed_user_uri);
         $subscriber = $this->_getAnyProfile($subscriber_uri);
 
+        if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
+            common_log(LOG_INFO, __METHOD__ . ": remote subscriber banned ($subscriber_uri subbing to $subscribed_user_uri)");
+            return _('You have been banned from subscribing.');
+        }
+
         $sub->subscribed = $subscribed->id;
         $sub->subscriber = $subscriber->id;