Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions classes/twitter/connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ protected function init_connection($url)
*/
public function get($url, $params)
{

$this->init_connection($url.'?'.http_build_query($params['request'],'','&'));
$request = isset( $params['request'] )? http_build_query($params['request'], '', '&') : null;

$this->init_connection($url.'?'.$request );
$response = $this->add_curl($url, $params);

return $response;
Expand Down
119 changes: 100 additions & 19 deletions classes/twitter/oauth.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ class Twitter_Oauth {
protected $access_token_url = 'http://api.twitter.com/oauth/access_token';
protected $signature_method = 'HMAC-SHA1';
protected $version = '1.0';
protected $api_url = 'http://api.twitter.com/1';
protected $search_url = 'http://search.twitter.com/';
protected $api_url = 'http://api.twitter.com/1.1';
protected $search_url = 'https://search.twitter.com/';
protected $callback = null;
protected $errors = array();
protected $enable_debug = false;
protected $enable_debug = true;

/**
* Loads in the Twitter config and sets everything up.
Expand Down Expand Up @@ -140,7 +140,7 @@ public function logged_in()
{
$access_key = $this->get_access_key();
$access_secret = $this->get_access_secret();
$logged_in = false;

if ($this->get_access_key() !== null && $this->get_access_secret() !== null)
Expand All @@ -159,21 +159,35 @@ public function logged_in()
*/
protected function check_login()
{

if (isset($_GET['oauth_token']))
{
$this->set_access_key($_GET['oauth_token']);
if ( isset( $_GET['oauth_verifier'] ) && !empty( $_GET['oauth_verifier'] ) ){
$this->set_access_verifier( $_GET['oauth_verifier'] );
}


$this->set_access_key( $_GET['oauth_token'] );

$token = $this->get_access_token();

$token = $token->_result;


if ( is_array( $token ) && isset( $token['error'] ) && !empty( $token['error']) ){
\Session::delete('twitter_oauthtokens');
return $token;
}

$token = $token->_result;

$token = (is_bool($token)) ? $token : (object) $token;
if ( ! empty($token->oauth_token) && ! empty($token->oauth_token_secret))
{
$this->set_access_key($token->oauth_token);
$this->set_access_secret($token->oauth_token_secret);

$this->unset_access_verifier();
}
\Response::redirect(\Uri::current());
return null;
}
Expand All @@ -185,9 +199,9 @@ protected function check_login()
* @return null
*/
public function login()
{
{
if (($this->get_access_key() === null || $this->get_access_secret() === null))
{
{
\Response::redirect($this->get_auth_url());
return;
}
Expand Down Expand Up @@ -246,6 +260,19 @@ public function get_access_key()
$tokens = \Session::get('twitter_oauthtokens');
return ($tokens === null || ! isset($tokens['access_key']) || empty($tokens['access_key'])) ? null : $tokens['access_key'];
}

/**
* Gets the Access Key Verifier from the Session.
*
* @return string|null The Access Key
*/
public function get_access_verifier()
{
$tokens = \Session::get('twitter_oauthtokens');

return ($tokens === null || ! isset($tokens['access_verifier']) || empty($tokens['access_verifier'])) ? null : $tokens['access_verifier'];
}


/**
* Gets the Access Secret from the Session.
Expand All @@ -257,18 +284,19 @@ public function get_access_secret()
$tokens = \Session::get('twitter_oauthtokens');
return ($tokens === false || ! isset($tokens['access_secret']) || empty($tokens['access_secret'])) ? null : $tokens['access_secret'];
}


/**
* Sets the access key in the session
*
* @param string $access_key The access key
* @return $this
*/
public function set_access_key($access_key)
public function set_access_key( $access_key )
{
$tokens = \Session::get('twitter_oauthtokens');

if ($tokens === false || ! is_array($tokens))
if ($tokens === false || ! is_array($tokens))
{
$tokens = array('access_key' => $access_key);
}
Expand All @@ -282,6 +310,55 @@ public function set_access_key($access_key)
return $this;
}


/**
* Sets the access key verifier in the session
*
* @param string $access_key The access key
* @return $this
*/
public function set_access_verifier( $verifier )
{
$tokens = \Session::get('twitter_oauthtokens');

if ($tokens === false || ! is_array($tokens))
{
$tokens = array('access_verifier' => $verifier);
}
else
{
$tokens['access_verifier'] = $verifier;
}

\Session::set('twitter_oauthtokens', $tokens);

return $this;
}


/**
* Unsets the access key verifier in the session
*
* @return $this
*/
public function unset_access_verifier( )
{
$tokens = \Session::get('twitter_oauthtokens');

if ($tokens === false || ! is_array($tokens))
{
$tokens = array( );
}
else
{
unset( $tokens['access_verifier'] );
}

\Session::set('twitter_oauthtokens', $tokens);

return $this;
}

/**
* Sets the access secret in the session
*
Expand Down Expand Up @@ -339,7 +416,7 @@ public function get_auth_url()
* @return string The request token
*/
protected function get_request_token()
{
{
return $this->http_request('GET', $this->request_token_url);
}

Expand All @@ -349,10 +426,12 @@ protected function get_request_token()
* @return string The access token
*/
protected function get_access_token()
{
return $this->http_request('GET', $this->access_token_url);
{
// $result = $this->http_request('GET', $this->access_token_url, array( 'oauth_verifier' => $this->get_access_verifier() ) );
return $this->http_request('POST', $this->access_token_url, array( 'oauth_verifier' => $this->get_access_verifier() ) );
}


/**
* Sends the request to Twitter and returns the response.
*
Expand All @@ -368,11 +447,11 @@ protected function http_request($method = null, $url = null, $params = null)
return false;
}

if (empty($params['oauth_signature']))
if (empty($params['oauth_signature']))
{
$params = $this->prep_params($method, $url, $params);
}

$this->connection = new \Twitter_Connection();

try
Expand Down Expand Up @@ -454,6 +533,8 @@ protected function prep_params($method = null, $url = null, $params = null)
$oauth['oauth_timestamp'] = time();
$oauth['oauth_signature_method'] = $this->signature_method;
$oauth['oauth_version'] = $this->version;



array_walk($oauth, array($this, 'encode_rfc3986'));

Expand Down