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