Index: trunk/extensions/TweetANew/TweetANew.body.php |
— | — | @@ -245,7 +245,7 @@ |
246 | 246 | } |
247 | 247 | |
248 | 248 | # Make connection to Twitter |
249 | | - $connection = new tmhOAuth( array( |
| 249 | + $tmhOAuth = new tmhOAuth( array( |
250 | 250 | 'consumer_key' => $wgTweetANewTwitter['ConsumerKey'], |
251 | 251 | 'consumer_secret' => $wgTweetANewTwitter['ConsumerSecret'], |
252 | 252 | 'user_token' => $wgTweetANewTwitter['AccessToken'], |
— | — | @@ -253,8 +253,8 @@ |
254 | 254 | ) ); |
255 | 255 | |
256 | 256 | # Make tweet message |
257 | | - $connection->request( 'POST', |
258 | | - $connection->url( '1/statuses/update' ), |
| 257 | + $tmhOAuth->request( 'POST', |
| 258 | + $tmhOAuth->url( '1/statuses/update' ), |
259 | 259 | array( 'status' => $tweet_text ) |
260 | 260 | ); |
261 | 261 | return true; |
Index: trunk/extensions/TweetANew/lib/tmhOAuth.php |
— | — | @@ -7,12 +7,12 @@ |
8 | 8 | * REST requests. OAuth authentication is sent using the an Authorization Header. |
9 | 9 | * |
10 | 10 | * @author themattharris |
11 | | - * @version 0.60 |
| 11 | + * @version 0.57 |
12 | 12 | * |
13 | | - * 29 December 2011 |
| 13 | + * 11 December 2011 |
14 | 14 | */ |
15 | 15 | class tmhOAuth { |
16 | | - const VERSION = 0.60; |
| 16 | + const VERSION = 0.57; |
17 | 17 | |
18 | 18 | /** |
19 | 19 | * Creates a new tmhOAuth object |
— | — | @@ -28,40 +28,27 @@ |
29 | 29 | // default configuration options |
30 | 30 | $this->config = array_merge( |
31 | 31 | array( |
32 | | - // leave 'user_agent' blank for default, otherwise set this to |
33 | | - // something that clearly identifies your app |
34 | | - 'user_agent' => '', |
35 | | - |
36 | | - 'use_ssl' => true, |
37 | | - 'host' => 'api.twitter.com', |
38 | | - |
| 32 | + 'user_agent' => 'tmhOAuth ' . self::VERSION . ' - //github.com/themattharris/tmhOAuth', |
39 | 33 | 'consumer_key' => '', |
40 | 34 | 'consumer_secret' => '', |
41 | 35 | 'user_token' => '', |
42 | 36 | 'user_secret' => '', |
| 37 | + 'use_ssl' => true, |
| 38 | + 'host' => 'api.twitter.com', |
| 39 | + 'debug' => false, |
43 | 40 | 'force_nonce' => false, |
44 | 41 | 'nonce' => false, // used for checking signatures. leave as false for auto |
45 | 42 | 'force_timestamp' => false, |
46 | 43 | 'timestamp' => false, // used for checking signatures. leave as false for auto |
47 | | - |
48 | | - // oauth signing variables that are not dynamic |
49 | 44 | 'oauth_version' => '1.0', |
50 | | - 'oauth_signature_method' => 'HMAC-SHA1', |
51 | 45 | |
52 | 46 | // you probably don't want to change any of these curl values |
53 | 47 | 'curl_connecttimeout' => 30, |
54 | 48 | 'curl_timeout' => 10, |
55 | | - |
56 | | - // for security these should always be set to true. |
57 | | - 'curl_ssl_verifyhost' => true, |
58 | | - 'curl_ssl_verifypeer' => true, |
59 | | - |
60 | | - // you can get the latest cacert.pem from here http://curl.haxx.se/ca/cacert.pem |
61 | | - 'curl_cainfo' => dirname(__FILE__) . '/cacert.pem', |
62 | | - 'curl_capath' => dirname(__FILE__), |
63 | | - |
| 49 | + // for security you may want to set this to TRUE. If you do you need |
| 50 | + // to install the servers certificate in your local certificate store. |
| 51 | + 'curl_ssl_verifypeer' => false, |
64 | 52 | 'curl_followlocation' => false, // whether to follow redirects or not |
65 | | - |
66 | 53 | // support for proxy servers |
67 | 54 | 'curl_proxy' => false, // really you don't want to use this if you are using streaming |
68 | 55 | 'curl_proxyuserpwd' => false, // format username:password for proxy, if required |
— | — | @@ -72,30 +59,15 @@ |
73 | 60 | 'streaming_eol' => "\r\n", |
74 | 61 | 'streaming_metrics_interval' => 60, |
75 | 62 | |
76 | | - // header or querystring. You should always use header! |
77 | | - // this is just to help me debug other developers implementations |
| 63 | + // header or querystring. You should always use header |
| 64 | + // this is just to help me debug other developers |
| 65 | + // implementations |
78 | 66 | 'as_header' => true, |
79 | | - 'debug' => false, |
80 | 67 | ), |
81 | 68 | $config |
82 | 69 | ); |
83 | | - $this->set_user_agent(); |
84 | 70 | } |
85 | 71 | |
86 | | - function set_user_agent() { |
87 | | - if (!empty($this->config['user_agent'])) |
88 | | - return; |
89 | | - |
90 | | - if ($this->config['curl_ssl_verifyhost'] && $this->config['curl_ssl_verifypeer']) { |
91 | | - $ssl = '+SSL'; |
92 | | - } else { |
93 | | - $ssl = '-SSL'; |
94 | | - } |
95 | | - |
96 | | - $ua = 'tmhOAuth ' . self::VERSION . $ssl . ' - //github.com/themattharris/tmhOAuth'; |
97 | | - $this->config['user_agent'] = $ua; |
98 | | - } |
99 | | - |
100 | 72 | /** |
101 | 73 | * Generates a random OAuth nonce. |
102 | 74 | * If 'force_nonce' is true a nonce is not generated and the value in the configuration will be retained. |
— | — | @@ -111,7 +83,7 @@ |
112 | 84 | shuffle($sequence); |
113 | 85 | |
114 | 86 | $prefix = $include_time ? microtime() : ''; |
115 | | - $this->config['nonce'] = md5(substr($prefix . implode('', $sequence), 0, $length)); |
| 87 | + $this->config['nonce'] = md5(substr($prefix . implode($sequence), 0, $length)); |
116 | 88 | } |
117 | 89 | } |
118 | 90 | |
— | — | @@ -174,7 +146,7 @@ |
175 | 147 | 'oauth_nonce' => $this->config['nonce'], |
176 | 148 | 'oauth_timestamp' => $this->config['timestamp'], |
177 | 149 | 'oauth_consumer_key' => $this->config['consumer_key'], |
178 | | - 'oauth_signature_method' => $this->config['oauth_signature_method'], |
| 150 | + 'oauth_signature_method' => 'HMAC-SHA1', |
179 | 151 | ); |
180 | 152 | |
181 | 153 | // include the user token if it exists |
— | — | @@ -289,11 +261,6 @@ |
290 | 262 | unset($_signing_params['oauth_callback']); |
291 | 263 | } |
292 | 264 | |
293 | | - if (isset($_signing_params['oauth_verifier'])) { |
294 | | - $this->auth_params['oauth_verifier'] = $_signing_params['oauth_verifier']; |
295 | | - unset($_signing_params['oauth_verifier']); |
296 | | - } |
297 | | - |
298 | 265 | // request_params is already set if we're doing multipart, if not we need to set them now |
299 | 266 | if ( ! $this->config['multipart']) |
300 | 267 | $this->request_params = array_diff_key($_signing_params, $this->get_defaults()); |
— | — | @@ -568,26 +535,18 @@ |
569 | 536 | CURLOPT_USERAGENT => $this->config['user_agent'], |
570 | 537 | CURLOPT_CONNECTTIMEOUT => $this->config['curl_connecttimeout'], |
571 | 538 | CURLOPT_TIMEOUT => $this->config['curl_timeout'], |
572 | | - CURLOPT_RETURNTRANSFER => true, |
| 539 | + CURLOPT_RETURNTRANSFER => TRUE, |
573 | 540 | CURLOPT_SSL_VERIFYPEER => $this->config['curl_ssl_verifypeer'], |
574 | | - CURLOPT_SSL_VERIFYHOST => $this->config['curl_ssl_verifyhost'], |
575 | | - |
576 | 541 | CURLOPT_FOLLOWLOCATION => $this->config['curl_followlocation'], |
577 | 542 | CURLOPT_PROXY => $this->config['curl_proxy'], |
578 | 543 | CURLOPT_ENCODING => $this->config['curl_encoding'], |
579 | 544 | CURLOPT_URL => $this->url, |
580 | 545 | // process the headers |
581 | 546 | CURLOPT_HEADERFUNCTION => array($this, 'curlHeader'), |
582 | | - CURLOPT_HEADER => false, |
| 547 | + CURLOPT_HEADER => FALSE, |
583 | 548 | CURLINFO_HEADER_OUT => true, |
584 | 549 | )); |
585 | 550 | |
586 | | - if ($this->config['curl_cainfo'] !== false) |
587 | | - curl_setopt($c, CURLOPT_CAINFO, $this->config['curl_cainfo']); |
588 | | - |
589 | | - if ($this->config['curl_capath'] !== false) |
590 | | - curl_setopt($c, CURLOPT_CAPATH, $this->config['curl_capath']); |
591 | | - |
592 | 551 | if ($this->config['curl_proxyuserpwd'] !== false) |
593 | 552 | curl_setopt($c, CURLOPT_PROXYUSERPWD, $this->config['curl_proxyuserpwd']); |
594 | 553 | |
— | — | @@ -602,7 +561,7 @@ |
603 | 562 | case 'GET': |
604 | 563 | break; |
605 | 564 | case 'POST': |
606 | | - curl_setopt($c, CURLOPT_POST, true); |
| 565 | + curl_setopt($c, CURLOPT_POST, TRUE); |
607 | 566 | break; |
608 | 567 | default: |
609 | 568 | curl_setopt($c, CURLOPT_CUSTOMREQUEST, $this->method); |
— | — | @@ -640,16 +599,12 @@ |
641 | 600 | $response = curl_exec($c); |
642 | 601 | $code = curl_getinfo($c, CURLINFO_HTTP_CODE); |
643 | 602 | $info = curl_getinfo($c); |
644 | | - $error = curl_error($c); |
645 | | - $errno = curl_errno($c); |
646 | 603 | curl_close($c); |
647 | 604 | |
648 | 605 | // store the response |
649 | 606 | $this->response['code'] = $code; |
650 | 607 | $this->response['response'] = $response; |
651 | 608 | $this->response['info'] = $info; |
652 | | - $this->response['error'] = $error; |
653 | | - $this->response['errno'] = $errno; |
654 | 609 | return $code; |
655 | 610 | } |
656 | 611 | } |