]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/oauthstore.php
Update admin panel instructions in the TwitterBridge README
[quix0rs-gnu-social.git] / lib / oauthstore.php
index df63cc1512c12e800158d335606c52a8b9294b6c..570343b82dc7f87207d184eb815678783e2dda89 100644 (file)
@@ -21,9 +21,9 @@ if (!defined('STATUSNET') && !defined('LACONICA')) { exit(1); }
 
 require_once 'libomb/datastore.php';
 
+// @todo FIXME: Class documentation missing.
 class StatusNetOAuthDataStore extends OAuthDataStore
 {
-
     // We keep a record of who's contacted us
     function lookup_consumer($consumer_key)
     {
@@ -55,17 +55,26 @@ 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."
-
     // XXX: It's not clear why the token is here
-
     function lookup_nonce($consumer, $token, $nonce, $timestamp)
     {
         $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;
@@ -93,7 +102,6 @@ class StatusNetOAuthDataStore extends OAuthDataStore
     }
 
     // defined in OAuthDataStore, but not implemented anywhere
-
     function fetch_request_token($consumer)
     {
         return $this->new_request_token($consumer);
@@ -150,7 +158,6 @@ class StatusNetOAuthDataStore extends OAuthDataStore
     }
 
     // defined in OAuthDataStore, but not implemented anywhere
-
     function fetch_access_token($consumer)
     {
         return $this->new_access_token($consumer);
@@ -221,7 +228,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
      **/
     public function getProfile($identifier_uri) {
         /* getProfile is only used for remote profiles by libomb.
-           TODO: Make it work with local ones anyway. */
+           @TODO: Make it work with local ones anyway. */
         $remote = Remote_profile::staticGet('uri', $identifier_uri);
         if (!$remote) throw new Exception('No such remote profile');
         $profile = Profile::staticGet('id', $remote->id);
@@ -253,8 +260,8 @@ class StatusNetOAuthDataStore extends OAuthDataStore
                 $profile = Profile::staticGet($remote->id);
                 $orig_remote = clone($remote);
                 $orig_profile = clone($profile);
-                # XXX: compare current postNotice and updateProfile URLs to the ones
-                # stored in the DB to avoid (possibly...) above attack
+                // XXX: compare current postNotice and updateProfile URLs to the ones
+                // stored in the DB to avoid (possibly...) above attack
             } else {
                 $exists = false;
                 $remote = new Remote_profile();
@@ -280,7 +287,8 @@ class StatusNetOAuthDataStore extends OAuthDataStore
                 $profile->created = DB_DataObject_Cast::dateTime(); # current time
                 $id = $profile->insert();
                 if (!$id) {
-                    throw new Exception(_('Error inserting new profile'));
+                    // TRANS: Exception thrown when creating a new profile fails in OAuth store.
+                    throw new Exception(_('Error inserting new profile.'));
                 }
                 $remote->id = $id;
             }
@@ -288,7 +296,8 @@ 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'));
+                    // TRANS: Exception thrown when creating a new avatar fails in OAuth store.
+                    throw new Exception(_('Error inserting avatar.'));
                 }
             } else {
                 $avatar = $profile->getOriginalAvatar();
@@ -303,12 +312,14 @@ class StatusNetOAuthDataStore extends OAuthDataStore
 
             if ($exists) {
                 if (!$remote->update($orig_remote)) {
-                    throw new Exception(_('Error updating remote profile'));
+                    // TRANS: Exception thrown when updating a remote profile fails in OAuth store.
+                    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'));
+                    // TRANS: Exception thrown when creating a remote profile fails in OAuth store.
+                    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__);
@@ -362,7 +379,6 @@ class StatusNetOAuthDataStore extends OAuthDataStore
                                   array('is_local' => Notice::REMOTE_OMB,
                                         'uri' => $omb_notice->getIdentifierURI()));
 
-        common_broadcast_notice($notice, true);
     }
 
     /**
@@ -391,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
@@ -463,6 +479,7 @@ class StatusNetOAuthDataStore extends OAuthDataStore
 
         if (!$subscriber->hasRight(Right::SUBSCRIBE)) {
             common_log(LOG_INFO, __METHOD__ . ": remote subscriber banned ($subscriber_uri subbing to $subscribed_user_uri)");
+            // TRANS: Error message displayed to a banned user when they try to subscribe.
             return _('You have been banned from subscribing.');
         }
 
@@ -488,7 +505,8 @@ class StatusNetOAuthDataStore extends OAuthDataStore
 
         if (!$result) {
             common_log_db_error($sub, ($sub_exists) ? 'UPDATE' : 'INSERT', __FILE__);
-            throw new Exception(_('Couldn\'t insert new subscription.'));
+            // TRANS: Exception thrown when creating a new subscription fails in OAuth store.
+            throw new Exception(_('Could not insert new subscription.'));
             return;
         }
 
@@ -500,4 +518,3 @@ class StatusNetOAuthDataStore extends OAuthDataStore
         }
     }
 }
-?>