X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Foauthstore.php;h=1c8e7250092bdb56e644e10fd6f4184eeb3a8f63;hb=1e746da54514d5a062f8e308b8d752c32b60b662;hp=b30fb49d57e2f16b0c737df00d0354492dbd4aa9;hpb=b6aa1511eb868d740f8893160ce8bef387725867;p=quix0rs-gnu-social.git diff --git a/lib/oauthstore.php b/lib/oauthstore.php index b30fb49d57..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; @@ -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__); @@ -362,7 +379,6 @@ class StatusNetOAuthDataStore extends OAuthDataStore array('is_local' => Notice::REMOTE_OMB, 'uri' => $omb_notice->getIdentifierURI())); - } /** @@ -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