]> git.mxchange.org Git - friendica-addons.git/blob - statusnet/library/statusnetoauth.php
[statusnet] Remove explicit duplicate OAuth1 library
[friendica-addons.git] / statusnet / library / statusnetoauth.php
1 <?php\r
2 \r
3 use Friendica\Core\Config;\r
4 \r
5 require_once __DIR__ . DIRECTORY_SEPARATOR . 'twitteroauth.php';\r
6 \r
7 /*\r
8  * We have to alter the TwitterOAuth class a little bit to work with any GNU Social\r
9  * installation abroad. Basically it's only make the API path variable and be happy.\r
10  *\r
11  * Thank you guys for the Twitter compatible API!\r
12  */\r
13 class StatusNetOAuth extends TwitterOAuth\r
14 {\r
15         function get_maxlength()\r
16         {\r
17                 $config = $this->get($this->host . 'statusnet/config.json');\r
18                 return $config->site->textlimit;\r
19         }\r
20 \r
21         function accessTokenURL()\r
22         {\r
23                 return $this->host . 'oauth/access_token';\r
24         }\r
25 \r
26         function authenticateURL()\r
27         {\r
28                 return $this->host . 'oauth/authenticate';\r
29         }\r
30 \r
31         function authorizeURL()\r
32         {\r
33                 return $this->host . 'oauth/authorize';\r
34         }\r
35 \r
36         function requestTokenURL()\r
37         {\r
38                 return $this->host . 'oauth/request_token';\r
39         }\r
40 \r
41         function __construct($apipath, $consumer_key, $consumer_secret, $oauth_token = NULL, $oauth_token_secret = NULL)\r
42         {\r
43                 parent::__construct($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);\r
44                 $this->host = $apipath;\r
45         }\r
46 \r
47         /**\r
48          * Make an HTTP request\r
49          *\r
50          * Copied here from the TwitterOAuth library and complemented by applying the proxy settings of Friendica\r
51          *\r
52          * @param string $method\r
53          * @param string $host\r
54          * @param string $path\r
55          * @param array  $parameters\r
56          *\r
57          * @return array|object API results\r
58          */\r
59         function http($url, $method, $postfields = NULL)\r
60         {\r
61                 $this->http_info = [];\r
62                 $ci = curl_init();\r
63                 /* Curl settings */\r
64                 $prx = Config::get('system', 'proxy');\r
65                 if (strlen($prx)) {\r
66                         curl_setopt($ci, CURLOPT_HTTPPROXYTUNNEL, 1);\r
67                         curl_setopt($ci, CURLOPT_PROXY, $prx);\r
68                         $prxusr = Config::get('system', 'proxyuser');\r
69                         if (strlen($prxusr)) {\r
70                                 curl_setopt($ci, CURLOPT_PROXYUSERPWD, $prxusr);\r
71                         }\r
72                 }\r
73                 curl_setopt($ci, CURLOPT_USERAGENT, $this->useragent);\r
74                 curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this->connecttimeout);\r
75                 curl_setopt($ci, CURLOPT_TIMEOUT, $this->timeout);\r
76                 curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);\r
77                 curl_setopt($ci, CURLOPT_HTTPHEADER, ['Expect:']);\r
78                 curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this->ssl_verifypeer);\r
79                 curl_setopt($ci, CURLOPT_HEADERFUNCTION, [$this, 'getHeader']);\r
80                 curl_setopt($ci, CURLOPT_HEADER, FALSE);\r
81 \r
82                 switch ($method) {\r
83                         case 'POST':\r
84                                 curl_setopt($ci, CURLOPT_POST, TRUE);\r
85                                 if (!empty($postfields)) {\r
86                                         curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);\r
87                                 }\r
88                                 break;\r
89                         case 'DELETE':\r
90                                 curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');\r
91                                 if (!empty($postfields)) {\r
92                                         $url = "{$url}?{$postfields}";\r
93                                 }\r
94                 }\r
95 \r
96                 curl_setopt($ci, CURLOPT_URL, $url);\r
97                 $response = curl_exec($ci);\r
98                 $this->http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);\r
99                 $this->http_info = array_merge($this->http_info, curl_getinfo($ci));\r
100                 $this->url = $url;\r
101                 curl_close($ci);\r
102                 return $response;\r
103         }\r
104 }\r