<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>callback.php</filename>
    </added>
    <added>
      <filename>connect.php</filename>
    </added>
    <added>
      <filename>html.inc</filename>
    </added>
    <added>
      <filename>redirect.php</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -5,5 +5,6 @@
  * A single location to store configuration.
  */
 
-define(&quot;CONSUMER_KEY&quot;, &quot;CONSUMER_KEY_GOES_HERE&quot;);
-define(&quot;CONSUMER_SECRET&quot;, &quot;CONSUMER_SECRET_GOES_HERE&quot;);
+define(&quot;CONSUMER_KEY&quot;, &quot;&quot;);
+define(&quot;CONSUMER_SECRET&quot;, &quot;&quot;);
+define(&quot;OAUTH_CALLBACK&quot;, &quot;&quot;);</diff>
      <filename>config.php</filename>
    </modified>
    <modified>
      <diff>@@ -1,101 +1,33 @@
 &lt;?php
-// require twitterOAuth lib
-require_once('twitteroauth/twitterOAuth.php');
-
-/* Sessions are used to keep track of tokens while user authenticates with twitter */
-session_start();
-/* Consumer key from twitter */
-$consumer_key = '';
-/* Consumer Secret from twitter */
-$consumer_secret = '';
-/* Set up placeholder */
-$content = NULL;
-/* Set state if previous session */
-$state = $_SESSION['oauth_state'];
-/* Checks if oauth_token is set from returning from twitter */
-$session_token = $_SESSION['oauth_request_token'];
-/* Checks if oauth_token is set from returning from twitter */
-$oauth_token = $_REQUEST['oauth_token'];
-/* Set section var */
-$section = $_REQUEST['section'];
-
-/* Clear PHP sessions */
-if ($_REQUEST['test'] === 'clear') {/*{{{*/
-  session_destroy();
-  session_start();
-}/*}}}*/
-
-/* If oauth_token is missing get it */
-if ($_REQUEST['oauth_token'] != NULL &amp;&amp; $_SESSION['oauth_state'] === 'start') {/*{{{*/
-  $_SESSION['oauth_state'] = $state = 'returned';
-}/*}}}*/
-
-/*
- * Switch based on where in the process you are
- *
- * 'default': Get a request token from twitter for new user
- * 'returned': The user has authorize the app on twitter
+/**
+ * @file
+ * User has successfully authenticated with Twitter. Access tokens saved to session and DB.
  */
-switch ($state) {/*{{{*/
-  default:
-    /* Create TwitterOAuth object with app key/secret */
-    $to = new TwitterOAuth($consumer_key, $consumer_secret);
-    /* Request tokens from twitter */
-    $tok = $to-&gt;getRequestToken();
-
-    /* Save tokens for later */
-    $_SESSION['oauth_request_token'] = $token = $tok['oauth_token'];
-    $_SESSION['oauth_request_token_secret'] = $tok['oauth_token_secret'];
-    $_SESSION['oauth_state'] = &quot;start&quot;;
-
-    /* Build the authorization URL */
-    $request_link = $to-&gt;getAuthorizeURL($token);
 
-    /* Build link that gets user to twitter to authorize the app */
-    $content = 'Click on the link to go to twitter to authorize your account.';
-    $content .= '&lt;br /&gt;&lt;a href=&quot;'.$request_link.'&quot;&gt;'.$request_link.'&lt;/a&gt;';
-    break;
-  case 'returned':
-    /* If the access tokens are already set skip to the API call */
-    if ($_SESSION['oauth_access_token'] === NULL &amp;&amp; $_SESSION['oauth_access_token_secret'] === NULL) {
-      /* Create TwitterOAuth object with app key/secret and token key/secret from default phase */
-      $to = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_request_token'], $_SESSION['oauth_request_token_secret']);
-      /* Request access tokens from twitter */
-      $tok = $to-&gt;getAccessToken();
-
-      /* Save the access tokens. Normally these would be saved in a database for future use. */
-      $_SESSION['oauth_access_token'] = $tok['oauth_token'];
-      $_SESSION['oauth_access_token_secret'] = $tok['oauth_token_secret'];
-    }
-    /* Random copy */
-    $content = 'your account should now be registered with twitter. Check here:&lt;br /&gt;';
-    $content .= '&lt;a href=&quot;https://twitter.com/account/connections&quot;&gt;https://twitter.com/account/connections&lt;/a&gt;';
-
-    /* Create TwitterOAuth with app key/secret and user access key/secret */
-    $to = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_access_token'], $_SESSION['oauth_access_token_secret']);
-    /* Run request on twitter API as user. */
-    $content = $to-&gt;OAuthRequest('https://twitter.com/account/verify_credentials.xml', array(), 'GET');
-    //$content = $to-&gt;OAuthRequest('https://twitter.com/statuses/update.xml', array('status' =&gt; 'Test OAuth update. #testoauth'), 'POST');
-    //$content = $to-&gt;OAuthRequest('https://twitter.com/statuses/replies.xml', array(), 'POST');
-    break;
-}/*}}}*/
-?&gt;
-
-&lt;html&gt;
-  &lt;head&gt;
-    &lt;title&gt;Twitter OAuth in PHP&lt;/title&gt;
-  &lt;/head&gt;
-  &lt;body&gt;
-    &lt;h2&gt;Welcome to a Twitter OAuth PHP example.&lt;/h2&gt;
-    &lt;p&gt;This site is a basic showcase of Twitters new OAuth authentication method. Everything is saved in sessions. If you want to start over &lt;a href='&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;?test=clear'&gt;clear sessions&lt;/a&gt;.&lt;/p&gt;
-
-    &lt;p&gt;
-      Get the code powering this at &lt;a href='http://github.com/abraham/twitteroauth'&gt;http://github.com/abraham/twitteroauth&lt;/a&gt;
-      &lt;br /&gt;
-      Read the documentation at &lt;a href='https://docs.google.com/View?docID=dcf2dzzs_2339fzbfsf4'&gt;https://docs.google.com/View?docID=dcf2dzzs_2339fzbfsf4&lt;/a&gt; 
-    &lt;/p&gt;
-
-    &lt;p&gt;&lt;pre&gt;&lt;?php print_r($content); ?&gt;&lt;pre&gt;&lt;/p&gt;
-
-  &lt;/body&gt;
-&lt;/html&gt;
+/* Load required lib files. */
+session_start();
+require_once('twitteroauth/twitteroauth.php');
+require_once('config.php');
+
+/* Get user access tokens out of the session. */
+$access_token = $_SESSION['access_token'];
+/* If access tokens are not available redirect to connect page. */
+if (empty($access_token['oauth_token']) || empty($access_token['oauth_token_secret'])) {
+    header('Location: '.$home_page.'/clearsessions.php');
+}
+
+/* Create a TwitterOauth object with consumer/user tokens. */
+$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
+
+/* If method is set change API call made. Test is called by default. */
+$content = '&lt;pre&gt;'.$connection-&gt;get('account/verify_credentials').'&lt;/pre&gt;';
+
+/* Some example calls */
+//$connection-&gt;get('users/show', array('screen_name' =&gt; 'abraham')));
+//$connection-&gt;post('statuses/update', array('status' =&gt; date(DATE_RFC822)));
+//$connection-&gt;post('statuses/destroy', array('id' =&gt; 5437877770));
+//$connection-&gt;post('friendships/create', array('id' =&gt; 9436992)));
+//$connection-&gt;post('friendships/destroy', array('id' =&gt; 9436992)));
+
+/* Include HTML to display on the page */
+include('html.inc');</diff>
      <filename>index.php</filename>
    </modified>
    <modified>
      <diff>@@ -11,10 +11,9 @@ class OAuthConsumer {
   public $key;
   public $secret;
 
-  function __construct($key, $secret, $callback_url=NULL) {
+  function __construct($key, $secret) {
     $this-&gt;key = $key;
     $this-&gt;secret = $secret;
-    $this-&gt;callback_url = $callback_url;
   }
 
   function __toString() {
@@ -173,7 +172,7 @@ class OAuthRequest {
   private $http_url;
   // for debug purposes
   public $base_string;
-  public static $version = '1.0';
+  public static $version = '1.0a';
   public static $POST_INPUT = 'php://input';
 
   function __construct($http_method, $http_url, $parameters=NULL) {</diff>
      <filename>twitteroauth/OAuth.php</filename>
    </modified>
    <modified>
      <diff>@@ -7,7 +7,7 @@
  *
  * Code based on:
  * Fire Eagle code - http://github.com/myelin/fireeagle-php-lib
- * twitterlibphp - http://github.com/poseurtech/twitterlibphp
+ * twitterlibphp - http://github.com/jdp/twitterlibphp
  */
 
 /* Load OAuth lib. You can find it at http://oauth.net */
@@ -18,17 +18,21 @@ require_once('OAuth.php');
  */
 class TwitterOAuth {
   /* Contains the last HTTP status code returned */
-  private $http_code;
+  public $http_code;
   /* Contains the last API call */
-  private $last_api_call;
+  public $last_api_call;
   /* Set up the API root URL */
-  public static $host = &quot;https://api.twitter.com/1&quot;;
+  public $host = &quot;https://api.twitter.com/1/&quot;;
   /* Set timeout default */
-  public static $timeout = 30;
+  public $timeout = 30;
   /* Set connect timeout */
-  public static $connecttimeout = 30; 
+  public $connecttimeout = 30; 
   /* Verify SSL Cert */
-  public static $ssl_verifypeer = FALSE;
+  public $ssl_verifypeer = FALSE;
+  /* Respons format */
+  public $format = 'json';
+  /* Decode returne json data */
+  public $decode_json = 'TRUE';
 
 
 
@@ -58,7 +62,7 @@ class TwitterOAuth {
     } else {
       $this-&gt;token = NULL;
     }
-  }/*}}}*/
+  }
 
 
   /**
@@ -66,26 +70,15 @@ class TwitterOAuth {
    *
    * @returns a key/value array containing oauth_token and oauth_token_secret
    */
-  function getRequestToken() {
-    $r = $this-&gt;oAuthRequest($this-&gt;requestTokenURL());
-    $token = $this-&gt;oAuthParseResponse($r);
+  function getRequestToken($oauth_callback = NULL) {
+    $parameters = array();
+    if (!empty($oauth_callback)) {
+      $parameters['oauth_callback'] = $oauth_callback;
+    } 
+    $request = $this-&gt;oAuthRequest($this-&gt;requestTokenURL(), 'GET', $parameters);
+    $token = OAuthUtil::parse_parameters($request);
     $this-&gt;token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
-  }/*}}}*/
-
-  /**
-   * Parse a URL-encoded OAuth response
-   *
-   * @return a key/value array
-   */
-  function oAuthParseResponse($responseString) {
-    $r = array();
-    foreach (explode('&amp;', $responseString) as $param) {
-      $pair = explode('=', $param, 2);
-      if (count($pair) != 2) continue;
-      $r[urldecode($pair[0])] = urldecode($pair[1]);
-    }
-    return $r;
   }
 
   /**
@@ -93,10 +86,16 @@ class TwitterOAuth {
    *
    * @returns a string
    */
-  function getAuthorizeURL($token) {
-    if (is_array($token)) $token = $token['oauth_token'];
-    return $this-&gt;authorizeURL() . '?oauth_token=' . $token;
-  }/*}}}*/
+  function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
+    if (is_array($token)) {
+      $token = $token['oauth_token'];
+    }
+    if (empty($sign_in_with_twitter)) {
+      return $this-&gt;authorizeURL() . &quot;?oauth_token={$token}&quot;;
+    } else {
+       return $this-&gt;authenticateURL() . &quot;?oauth_token={$token}&quot;;
+    }
+  }
 
   /**
    * Exchange the request token and secret for an access token and
@@ -105,32 +104,65 @@ class TwitterOAuth {
    * @returns array(&quot;oauth_token&quot; =&gt; the access token,
    *                &quot;oauth_token_secret&quot; =&gt; the access secret)
    */
-  function getAccessToken($token = NULL) {
-    $r = $this-&gt;oAuthRequest($this-&gt;accessTokenURL());
-    $token = $this-&gt;oAuthParseResponse($r);
+  function getAccessToken($oauth_verifier = FALSE) {
+    $parameters = array();
+    if (!empty($oauth_verifier)) {
+      $parameters['oauth_verifier'] = $oauth_verifier;
+    }
+    $request = $this-&gt;oAuthRequest($this-&gt;accessTokenURL(), 'GET', $parameters);
+    $token = OAuthUtil::parse_parameters($request);
     $this-&gt;token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
-  }/*}}}*/
+  }
+
+  /**
+   * GET wrappwer for oAuthRequest.
+   */
+  function get($url, $parameters = NULL) {
+    return $this-&gt;oAuthRequest($url, 'GET', $parameters);
+  }
+  
+  /**
+   * POST wreapper for oAuthRequest.
+   */
+  function post($url, $parameters) {
+    return $this-&gt;oAuthRequest($url, 'POST', $parameters);
+  }
+
+  /**
+   * DELTE wrapper for oAuthReqeust.
+   */
+  function delete($url, $parameters) {
+    return $this-&gt;oAuthRequest($url, 'DELETE', $parameters);
+  }
 
   /**
    * Format and sign an OAuth / API request
    */
-  function oAuthRequest($url, $args = array(), $method = NULL) {
-    if (empty($method)) $method = empty($args) ? &quot;GET&quot; : &quot;POST&quot;;
-    $req = OAuthRequest::from_consumer_and_token($this-&gt;consumer, $this-&gt;token, $method, $url, $args);
-    $req-&gt;sign_request($this-&gt;sha1_method, $this-&gt;consumer, $this-&gt;token);
+  function oAuthRequest($url, $method, $parameters = array()) {
+    if (isset($parameters['id'])) {
+      $url = &quot;{$url}/{$parameters['id']}&quot;;
+      unset($parameters['id']);
+    }
+    if (strrpos($url, 'https://') !== 0 &amp;&amp; strrpos($url, 'http://') !== 0) {
+      $url = &quot;{$this-&gt;host}{$url}.{$this-&gt;format}&quot;;
+    }
+    $request = OAuthRequest::from_consumer_and_token($this-&gt;consumer, $this-&gt;token, $method, $url, $parameters);
+    $request-&gt;sign_request($this-&gt;sha1_method, $this-&gt;consumer, $this-&gt;token);
     switch ($method) {
-    case 'GET': return $this-&gt;http($req-&gt;to_url());
-    case 'POST': return $this-&gt;http($req-&gt;get_normalized_http_url(), $req-&gt;to_postdata());
+    case 'GET':
+      return $this-&gt;http($request-&gt;to_url(), 'GET');
+    default:
+      return $this-&gt;http($request-&gt;get_normalized_http_url(), $method, $request-&gt;to_postdata());
     }
-  }/*}}}*/
+  }
 
   /**
    * Make an HTTP request
    *
    * @return API results
    */
-  function http($url, $postfields = null) {
+  function http($url, $method, $postfields = NULL) {
     $ci = curl_init();
     /* Curl settings */
     curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, $this-&gt;connecttimeout);
@@ -138,18 +170,24 @@ class TwitterOAuth {
     curl_setopt($ci, CURLOPT_RETURNTRANSFER, TRUE);
     curl_setopt($ci, CURLOPT_HTTPHEADER, array('Expect:'));
     curl_setopt($ci, CURLOPT_SSL_VERIFYPEER, $this-&gt;ssl_verifypeer);
-    curl_setopt($ci, CURLOPT_URL, $this-&gt;url);
-    if (defined(&quot;CURL_CA_BUNDLE_PATH&quot;)) {
-      curl_setopt($ci, CURLOPT_CAINFO, CURL_CA_BUNDLE_PATH);
+    curl_setopt($ci, CURLOPT_URL, $url);
+    switch ($method) {
+      case 'POST':
+        curl_setopt($ci, CURLOPT_POST, TRUE);
+        break;
+      case 'DELETE':
+        curl_setopt($ci, CURLOPT_CUSTOMREQUEST, 'DELETE');
     }
     if (isset($postfields)) {
-      curl_setopt($ci, CURLOPT_POST, 1);
       curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields);
     }
     $response = curl_exec($ci);
     $this-&gt;http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE);
     $this-&gt;last_api_call = $url;
     curl_close ($ci);
+    //if ($this-&gt;format === 'json' &amp;&amp; $this-&gt;decode_json) {
+    //  return json_decode($response);
+    //}
     return $response;
   }
 }</diff>
      <filename>twitteroauth/twitteroauth.php</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>bb524c9de3d4af764bc61f334576ed439318e626</id>
    </parent>
  </parents>
  <author>
    <name>Abraham Williams</name>
    <email>abraham@abrah.am</email>
  </author>
  <url>http://github.com/abraham/twitteroauth/commit/83e36708d3b5f9fa0b32bff7f3381f919acb2cfc</url>
  <id>83e36708d3b5f9fa0b32bff7f3381f919acb2cfc</id>
  <committed-date>2009-11-04T20:27:19-08:00</committed-date>
  <authored-date>2009-11-04T20:27:19-08:00</authored-date>
  <message>version 0.2.0-beta. includes support for oauth 1.0a and fixes several bugs.</message>
  <tree>1f2383b9e80068914011833ebc1f80dc8adc3176</tree>
  <committer>
    <name>Abraham Williams</name>
    <email>abraham@abrah.am</email>
  </committer>
</commit>
