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