X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Foauthstore.php;h=1c8e7250092bdb56e644e10fd6f4184eeb3a8f63;hb=1e746da54514d5a062f8e308b8d752c32b60b662;hp=e69a00f55f2ab61e588a763e882e926d2c962c06;hpb=a535ccdc4eba320ad88dc531329ae63c7f09c258;p=quix0rs-gnu-social.git diff --git a/lib/oauthstore.php b/lib/oauthstore.php index e69a00f55f..1c8e725009 100644 --- a/lib/oauthstore.php +++ b/lib/oauthstore.php @@ -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; @@ -156,7 +167,6 @@ class StatusNetOAuthDataStore extends OAuthDataStore return $this->new_access_token($consumer); } - /** * Revoke specified OAuth token * @@ -281,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; } @@ -289,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(); @@ -304,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.')); } } } @@ -318,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); } @@ -343,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__); @@ -352,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__); @@ -360,13 +376,9 @@ class StatusNetOAuthDataStore extends OAuthDataStore $notice = Notice::saveNew($author->id, $omb_notice->getContent(), 'omb', - false, - null, - $omb_notice->getIdentifierURI()); - if (is_string($notice)) { - throw new Exception($notice); - } - common_broadcast_notice($notice, true); + array('is_local' => Notice::REMOTE_OMB, + 'uri' => $omb_notice->getIdentifierURI())); + } /** @@ -395,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 @@ -410,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; } @@ -465,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;