|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Borfast\Socializr\Connectors; |
|
4
|
|
|
|
|
5
|
|
|
use OAuth\Common\Storage\Exception\TokenNotFoundException; |
|
6
|
|
|
use Borfast\Socializr\Blog; |
|
7
|
|
|
use Borfast\Socializr\Exceptions\AuthorizationException; |
|
8
|
|
|
use Borfast\Socializr\Exceptions\TumblrPostingException; |
|
9
|
|
|
use Borfast\Socializr\Post; |
|
10
|
|
|
use Borfast\Socializr\Profile; |
|
11
|
|
|
|
|
12
|
|
|
class Tumblr extends AbstractConnector |
|
13
|
|
|
{ |
|
14
|
|
|
public static $provider = 'Tumblr'; |
|
15
|
|
|
|
|
16
|
|
|
|
|
17
|
|
|
public function post(Post $post) |
|
18
|
|
|
{ |
|
19
|
|
|
throw new TumblrPostingException('Trying to post to a Tumblr profile, which does not accept posts; only Tumblr blogs do.'); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Tumblr needs an extra step for authentication before providing an |
|
25
|
|
|
* authorization URL. |
|
26
|
|
|
* |
|
27
|
|
|
* @author Raúl Santos |
|
28
|
|
|
*/ |
|
29
|
|
|
public function getAuthorizationUri(array $params = []) |
|
30
|
|
|
{ |
|
31
|
|
|
$token = $this->service->requestRequestToken(); |
|
|
|
|
|
|
32
|
|
|
$extra = ['oauth_token' => $token->getRequestToken()]; |
|
33
|
|
|
return parent::getAuthorizationUri($extra); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Retrieve the auth token from the provider's response and store it. |
|
39
|
|
|
*/ |
|
40
|
|
|
public function storeOauthToken($params) |
|
41
|
|
|
{ |
|
42
|
|
|
try { |
|
43
|
|
|
$token = $this->service->getStorage()->retrieveAccessToken('Tumblr'); |
|
44
|
|
|
} catch (TokenNotFoundException $e) { |
|
45
|
|
|
throw new AuthorizationException(); |
|
46
|
|
|
} |
|
47
|
|
|
$this->service->requestAccessToken($params['oauth_token'], $params['oauth_verifier'], $token->getRequestTokenSecret()); |
|
|
|
|
|
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
public function getProfile() |
|
51
|
|
|
{ |
|
52
|
|
|
$path = 'user/info'; |
|
53
|
|
|
$result = $this->request($path); |
|
54
|
|
|
$profile_json = json_decode($result, true); |
|
55
|
|
|
|
|
56
|
|
|
$mapping = [ |
|
57
|
|
|
'id' => 'name', |
|
58
|
|
|
'name' => 'name', |
|
59
|
|
|
'username' => 'name', |
|
60
|
|
|
'likes' => 'likes' |
|
61
|
|
|
]; |
|
62
|
|
|
|
|
63
|
|
|
$profile = Profile::create($mapping, $profile_json['response']['user']); |
|
64
|
|
|
$profile->provider = static::$provider; |
|
65
|
|
|
$profile->raw_response = $result; |
|
66
|
|
|
$profile->link = 'https://www.tumblr.com'; |
|
67
|
|
|
|
|
68
|
|
|
return $profile; |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
|
|
72
|
|
|
public function getBlogs() |
|
73
|
|
|
{ |
|
74
|
|
|
$path = 'user/info'; |
|
75
|
|
|
$result = $this->request($path); |
|
76
|
|
|
$profile_json = json_decode($result, true); |
|
77
|
|
|
|
|
78
|
|
|
$mapping = [ |
|
79
|
|
|
'id' => 'name', |
|
80
|
|
|
'link' => 'url', |
|
81
|
|
|
'title' => 'title', |
|
82
|
|
|
'name' => 'name', |
|
83
|
|
|
'description' => 'description', |
|
84
|
|
|
'ask' => 'ask', |
|
85
|
|
|
'ask_anon' => 'ask_anon', |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
$blogs = []; |
|
89
|
|
|
|
|
90
|
|
|
foreach ($profile_json['response']['user']['blogs'] as $blog) { |
|
91
|
|
|
$blogs[$blog['name']] = Blog::create($mapping, $blog); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return $blogs; |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
public function getPermissions() |
|
99
|
|
|
{ |
|
100
|
|
|
return null; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
public function getStats() |
|
104
|
|
|
{ |
|
105
|
|
|
$profile = $this->getProfile(); |
|
106
|
|
|
|
|
107
|
|
|
return $profile->likes; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.