Permalink
Browse files

Update EpiOAuth.php

  • Loading branch information...
dlnetworks committed Feb 28, 2014
1 parent d29e428 commit 4ee0153771b091d06d72a7c84931365a54636ddb
Showing with 44 additions and 8 deletions.
  1. +44 −8 EpiOAuth.php
View
@@ -1,5 +1,4 @@
<?php
class EpiOAuth
{
public $version = '1.0';
@@ -12,9 +11,11 @@ class EpiOAuth
protected $consumerSecret;
protected $token;
protected $tokenSecret;
protected $callback;
protected $signatureMethod;
protected $debug = false;
protected $useSSL = false;
protected $followLocation = false;
protected $headers = array();
protected $userAgent = 'EpiOAuth (http://github.com/jmathai/twitter-async/tree/)';
protected $connectionTimeout = 5;
@@ -30,6 +31,10 @@ public function addHeader($header)
public function getAccessToken($params = null)
{
if (isset($_GET['oauth_verifier']) && !isset($params['oauth_verifier']))
{
$params['oauth_verifier'] = $_GET['oauth_verifier'];
}
$resp = $this->httpRequest('POST', $this->getUrl($this->accessTokenUrl), $params);
return new EpiOAuthResponse($resp);
}
@@ -57,6 +62,10 @@ public function getAuthorizationUrl($token = null)
public function getRequestToken($params = null)
{
if (isset($this->callback) && !isset($params['oauth_callback']))
{
$params['oauth_callback'] = $this->callback;
}
$resp = $this->httpRequest('POST', $this->getUrl($this->requestTokenUrl), $params);
return new EpiOAuthResponse($resp);
}
@@ -97,6 +106,11 @@ public function setDebug($bool=false)
$this->debug = (bool)$bool;
}
public function setFollowLocation($bool)
{
$this->followLocation = (bool)$bool;
}
public function setTimeout($requestTimeout = null, $connectionTimeout = null)
{
if($requestTimeout !== null)
@@ -109,7 +123,12 @@ public function setToken($token = null, $secret = null)
{
$this->token = $token;
$this->tokenSecret = $secret;
}
}
public function setCallback($callback = null)
{
$this->callback = $callback;
}
public function useSSL($use = false)
{
@@ -146,14 +165,23 @@ protected function curlInit($url)
curl_setopt($ch, CURLOPT_HTTPHEADER, $this->headers);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->requestTimeout);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $this->connectionTimeout);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, '');
if($this->followLocation)
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if(isset($_SERVER ['SERVER_ADDR']) && !empty($_SERVER['SERVER_ADDR']) && $_SERVER['SERVER_ADDR'] != '127.0.0.1')
curl_setopt($ch, CURLOPT_INTERFACE, $_SERVER ['SERVER_ADDR']);
if($this->useSSL === true)
// if the certificate exists then use it, else bypass ssl checks
if(file_exists($cert = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'ca-bundle.crt'))
{
curl_setopt($ch, CURLOPT_CAINFO, $cert);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
}
else
{
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
return $ch;
}
@@ -194,12 +222,20 @@ protected function generateSignature($method = null, $url = null, $params = null
return $this->signString($signatureBaseString);
}
protected function executeCurl($ch)
{
if($this->isAsynchronous)
return $this->curl->addCurl($ch);
else
return $this->curl->addEasyCurl($ch);
}
protected function httpDelete($url, $params) {
$this->addDefaultHeaders($url, $params['oauth']);
$ch = $this->curlInit($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
$resp = $this->curl->addCurl($ch);
$resp = $this->executeCurl($ch);
$this->emptyHeaders();
return $resp;
}
@@ -217,7 +253,7 @@ protected function httpGet($url, $params = null)
}
$this->addDefaultHeaders($url, $params['oauth']);
$ch = $this->curlInit($url);
$resp = $this->curl->addCurl($ch);
$resp = $this->executeCurl($ch);
$this->emptyHeaders();
return $resp;
@@ -234,7 +270,7 @@ protected function httpPost($url, $params = null, $isMultipart)
curl_setopt($ch, CURLOPT_POSTFIELDS, $params['request']);
else
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->buildHttpQueryRaw($params['request']));
$resp = $this->curl->addCurl($ch);
$resp = $this->executeCurl($ch);
$this->emptyHeaders();
return $resp;

0 comments on commit 4ee0153

Please sign in to comment.