Esempio n. 1
0
 /**
  * Returns the current request url
  * @return string
  */
 public static function current_request_url()
 {
     $request_url = SPUtils::url_from_parts(array("host" => $_SERVER["HTTP_HOST"], "scheme" => isset($_SERVER["HTTPS"]) ? "https" : "http", "port" => $_SERVER["SERVER_PORT"], "path" => $_SERVER["SCRIPT_NAME"]));
     $query = "";
     if ($_GET) {
         $query = SPUtils::join_key_values_encode("=", "&", $_GET);
     }
     return rtrim("{$request_url}?{$query}", "?");
 }
Esempio n. 2
0
 /**
  * Add any options, overwrite options etc (a hook for subclasses to modify the request before execution)
  * __request_query_parms is avalable here before the url has been set
  * for post data check the stored post fields
  */
 protected function set_request_options()
 {
     $headers = array();
     $query_str = SPUtils::join_key_values_assoc("=", "&", SPUtils::array_map_assoc($this->__encoding_callback, $this->__request_query_parms));
     $this->__curl_opts[CURLOPT_URL] = SPUtils::url_from_parts($this->__request_url_parts) . ($query_str ? "?{$query_str}" : "");
     if ($this->request_headers && is_array($this->request_headers)) {
         foreach ($this->request_headers as $name => $value) {
             $headers[] = "{$name}: {$value}";
         }
         $this->__curl_opts[CURLOPT_HTTPHEADER] = $headers;
     }
     $this->CURLOPT_FOLLOWLOCATION = $this->auto_redirect;
     if ($this->curl_user_agent) {
         $this->__curl_opts[CURLOPT_USERAGENT] = $this->curl_user_agent;
     }
     if ($this->curl_set_referrer && $this->http_response_location) {
         $this->__curl_opts[CURLOPT_REFERER] = $this->http_response_location;
     }
     if (function_exists("curl_setopt_array")) {
         curl_setopt_array($this->__curl, $this->__curl_opts);
         return;
     }
     foreach ($this->__curl_opts as $key => $value) {
         curl_setopt($this->__curl, $key, $value);
     }
 }
Esempio n. 3
0
 protected function set_request_options()
 {
     $data = $this->__url_encoded_data ? $this->__url_encoded_data : array();
     $query = $this->__request_query_parms ? $this->__request_query_parms : array();
     $auth = $this->base_auth_parms();
     if ($this->request_headers && isset($this->request_headers[$this->auth_header_name])) {
         unset($this->request_headers[$this->auth_header_name]);
     }
     $base_url_array = array_map("strtolower", $this->__request_url_parts);
     if (isset($base_url_array["path"])) {
         $base_url_array["path"] = $this->__request_url_parts["path"];
     }
     $base_url = SPUtils::url_from_parts($base_url_array);
     $base_parm_string = SPOAuthClient::construct_base_string(SPUtils::array_map_assoc($this->__encoding_callback, $query, $data, $auth));
     $this->oauth_signature = SPOAuthClient::sign_base_string($this->oauth_signature_method, SPUtils::join_encoded3896($this->__request_http_method, $base_url, $base_parm_string), $this->oauth_consumer_secret, $this->oauth_token_secret);
     $auth["oauth_signature"] = $this->oauth_signature;
     switch ($this->auth_http_method) {
         case SPConstants::HTTP_METHOD_GET:
             $query = array_merge($query, $auth);
             break;
         case SPConstants::HTTP_METHOD_POST:
             $data = array_merge($data, $auth);
             $this->CURLOPT_POSTFIELDS = SPUtils::join_key_values_assoc("=", "&", SPUtils::array_map_assoc($this->__encoding_callback, $data));
             break;
         case SPOAuthClient::HTTP_AUTH_HEADER:
             $this->request_headers[$this->auth_header_name] = $this->get_auth_header(SPUtils::array_map_assoc($this->__encoding_callback, $auth));
             break;
     }
     $this->__request_query_parms = $query;
     parent::set_request_options();
 }