3 // FIXME : missing copyright
5 require_once('OAuth.php');
11 protected $provider_id;
12 protected $http_method;
14 function __construct($url, $provider_id, $http_method, $id=0) {
16 $this->provider_id = $provider_id;
17 $this->http_method = $http_method;
21 public function get_id() {
25 function set_id($id) {
29 public function get_url() {
33 public function get_provider_id() {
34 return $this->provider_id;
37 public function get_http_method() {
38 return $this->http_method;
41 function write_to_db() {
42 if ( strlen(trim( $this->url ))==0 || strlen(trim( $this->provider_id ))==0 || strlen(trim( $this->http_method ))==0 ) {
43 exit_error( "Error trying to add the oauth resource. Please try again.", 'oauthconsumer' );
45 $conn = FFOAuthDataStore::singleton();
46 $id = $conn->save_oauth_resource($this);
48 exit_error("Error trying to add new oauth resource to DB", 'oauthconsumer');
55 class OAuthTransaction {
57 protected $consumer; //an OAuthConsumer object
58 protected $token; //an OAuthToken object
59 protected $resource; //an OAuthResource object
60 protected $request; //an OAuthRequest object
65 * @param OAuthProvider $provider
66 * @param OAuthAccessToken $access_token
67 * @param OAuthResource $resource
68 * @param array $post_data (should be in the form of an array)
69 * @param boolean $json
72 function __construct($provider, $access_token, $resource, $post_data=NULL) {
73 $this->consumer = new OAuthConsumer($provider->get_consumer_key(), $provider->get_consumer_secret());
74 $this->token = new OAuthToken($access_token->get_token_key(), $access_token->get_token_secret());
75 $this->resource = $resource;
76 $this->request = OAuthRequest::from_consumer_and_token($this->consumer, $this->token, $resource->get_http_method(), $resource->get_url(), $post_data);
79 function send_request($not_verify_ssl=FALSE) {
80 $hmac = new OAuthSignatureMethod_HMAC_SHA1();
81 $this->request->sign_request($hmac, $this->consumer, $this->token);
82 if(strcasecmp($this->resource->get_http_method(), "get")==0) {
83 return $this->send_http_get($not_verify_ssl);
84 }elseif(strcasecmp($this->resource->get_http_method(), "post")==0) {
85 return $this->send_http_post($not_verify_ssl);
89 function send_http_get($not_verify_ssl) {
91 if (strpos($this->request->get_normalized_http_url(),"?")!=false) $separator = "&";
95 $url = $this->request->get_normalized_http_url().$separator.$this->request->to_postdata();
96 curl_setopt($curl, CURLOPT_URL, $url);
99 curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
100 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
103 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
105 $response = curl_exec ($curl);
111 function send_http_post($not_verify_ssl) {
114 curl_setopt($curl, CURLOPT_POST, TRUE);
116 curl_setopt($curl, CURLOPT_POSTFIELDS, $this->request->to_postdata());
117 curl_setopt($curl, CURLOPT_URL, $this->request->get_normalized_http_url());
119 if($not_verify_ssl) {
120 curl_setopt ($curl, CURLOPT_SSL_VERIFYHOST, 0);
121 curl_setopt ($curl, CURLOPT_SSL_VERIFYPEER, 0);
124 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
126 $response = curl_exec ($curl);