public static function load()
 {
     xhttp::addHook('data-preparation', array(__CLASS__, 'apply_profile_requestdata'), $priority = 1);
     return true;
 }
 public static function load()
 {
     xhttp::load('profile');
     xhttp::addHook('data-preparation', array(__CLASS__, 'apply_cookies'), 3);
     xhttp::addHook('return-response', array(__CLASS__, 'store_cookies'), 8);
     xhttp_profile::addFunction('export_cookies', array(__CLASS__, 'export_cookies'));
     xhttp_profile::addFunction('import_cookies', array(__CLASS__, 'import_cookies'));
     return true;
 }
 public static function init()
 {
     if (self::$first_run) {
         self::$first_run = false;
     } else {
         return;
     }
     self::$hooks['data-preparation'][8][] = array('xhttp', 'utf8_encode');
 }
 public function call($url, $method, $parameters, $options = array())
 {
     $options = array_merge(array('verbosity' => 'no_white_space'), $options);
     $data['post'] = xmlrpc_encode_request($method, $parameters, $options);
     $data['post'] = str_replace(array('<string>&#60;base64&#62;', '&#60;/base64&#62;</string>'), array('<base64>', '</base64>'), $data['post']);
     $data['headers']['Content-Type'] = 'text/xml';
     $data['method'] = 'post';
     xhttp::addHookToRequest($data, 'data-preparation', array(__CLASS__, 'set_rpc_data'), 8);
     $response = xhttp::fetch($url, $data);
     $response['raw'] = $response['body'];
     $response['body'] = str_replace('i8>', 'i4>', $response['body']);
     $response['body'] = xmlrpc_decode($response['body']);
     if ($response['body'] and xmlrpc_is_fault($response['body'])) {
         $response['rpc_fault'] = $response['body']['faultString'];
         $response['rpc_fault_code'] = $response['body']['faultCode'];
     }
     return $response;
 }
 public static function oauth_sign_request(&$urlparts, &$requestData)
 {
     $profile = isset($requestData['profile']['name']) ? $requestData['profile']['name'] : 'default';
     # Do nothing, if no OAuth options
     if (!isset(self::$datastore[$profile])) {
         return;
     }
     # Required values
     $oauth_data = array('oauth_consumer_key' => self::$datastore[$profile]['consumer_key'], 'oauth_nonce' => md5(mt_rand()), 'oauth_timestamp' => time(), 'oauth_version' => '1.0', 'oauth_signature_method' => 'HMAC-SHA1');
     if (isset(self::$datastore[$profile]['token'])) {
         $oauth_data['oauth_token'] = self::$datastore[$profile]['token'];
     }
     # ADD GET and POST variables
     if (isset($requestData['get'])) {
         $oauth_data = array_merge($oauth_data, $requestData['get']);
     }
     if (isset($requestData['post']) and is_array($requestData['post'])) {
         $oauth_data = array_merge($oauth_data, $requestData['post']);
     }
     # Convert array
     $parameters = array();
     foreach ($oauth_data as $key => $value) {
         $parameters[] = array(self::encode($key), self::encode($value));
     }
     # Sort parameters by key, then by value
     usort($parameters, array(__CLASS__, 'parameter_sort_callback'));
     # Create base string
     $array = array();
     foreach ($parameters as $index => $pair) {
         if ($pair[1] !== null) {
             $array[] = $pair[0] . '=' . $pair[1];
         }
     }
     #foreach($parameters as $index => $pair) $array[] = $pair[0].'='.$pair[1];
     $base_string = implode('&', $array);
     # Generate URL and base string
     $url = xhttp::unparse_url($urlparts);
     $base_string = self::encode(strtoupper($requestData['method'])) . '&' . self::encode($url) . '&' . self::encode($base_string);
     # Combine Consumer Secret and Token Secret
     $secret_key = self::encode(self::$datastore[$profile]['consumer_secret']) . '&' . self::encode(self::$datastore[$profile]['token_secret']);
     self::$last_basestring = $base_string;
     self::$last_secretkey = $secret_key;
     # Generate Signature
     $oauth_data['oauth_signature'] = base64_encode(hash_hmac('sha1', $base_string, $secret_key, true));
     if (self::$datastore[$profile]['method'] == 'get' or self::$datastore[$profile]['method'] == 'post') {
         $method = self::$datastore[$profile]['method'];
         foreach ($oauth_data as $key => $value) {
             if (substr($key, 0, 6) == 'oauth_' and $value !== null) {
                 $requestData[$method][$key] = $value;
             }
         }
     } else {
         # Set Host header
         $requestData['headers']['Host'] = $urlparts['host'] . ':' . $urlparts['port'];
         # Set Authorization Header
         $authorization = 'OAuth ';
         if (isset(self::$datastore[$profile]['realm'])) {
             if (self::$datastore[$profile]['realm']) {
                 $authorization .= 'realm="' . self::$datastore[$profile]['realm'] . '", ';
             }
         } else {
             $authorization .= 'realm="' . $url . '", ';
         }
         foreach ($oauth_data as $key => $value) {
             if (substr($key, 0, 6) == 'oauth_' and $value !== null) {
                 $authorization .= $key . '="' . self::encode($value) . '", ';
             }
         }
         $requestData['headers']['Authorization'] = rtrim($authorization, ', ');
     }
     # Other Headers
     if (!isset($requestData['headers']['User-Agent'])) {
         $requestData['headers']['User-Agent'] = 'sudocode.net xhttp oauth plugin';
     }
     # Clean GET data
     if (isset($requestData['get']) and is_array($requestData['get'])) {
         $vars = array();
         foreach ($requestData['get'] as $key => $value) {
             if (substr($key, 0, 5) != 'oauth' or self::$datastore[$profile]['method'] == 'get') {
                 $vars[$key] = $value;
             }
         }
         $requestData['get'] = $vars;
     }
     # Clean POST data
     if (isset($requestData['post']) and is_array($requestData['post'])) {
         $vars = array();
         foreach ($requestData['post'] as $key => $value) {
             if (substr($key, 0, 5) != 'oauth' or self::$datastore[$profile]['method'] == 'post') {
                 $vars[$key] = $value;
             }
         }
         $requestData['post'] = $vars;
     }
 }
 function exec()
 {
     # http://www.php.net/manual/en/function.curl-multi-exec.php
     $active = null;
     do {
         $mrc = curl_multi_exec($this->handle, $active);
     } while ($mrc == CURLM_CALL_MULTI_PERFORM);
     while ($active && $mrc == CURLM_OK) {
         if (curl_multi_select($this->handle, xhttp_multi::curl_multi_select_timeout) != -1) {
             do {
                 $mrc = curl_multi_exec($this->handle, $active);
             } while ($mrc == CURLM_CALL_MULTI_PERFORM);
         }
     }
     $responses = array();
     foreach ($this->requests as $request) {
         $response = curl_multi_getcontent($request['handle']);
         $responses[] = xhttp::after_curl_execution($request['handle'], $response, $request['data']);
     }
     xhttp_multi::stop();
     return $responses;
 }
Beispiel #7
0
// Extract Auth
preg_match('/Auth=(.+)/', $response['body'], $matches);
$auth = $matches[1];
// You can also cache this auth value for at least 5+ minutes
// Erase POST variables used on the previous xhttp call
$data['post'] = null;
// Set Authorization for authentication
// There is no official documentation and this might change without notice
$data['headers'] = array('Authorization' => 'GoogleLogin auth=' . $auth);
$response = xhttp::fetch('https://www.google.com/voice/b/0', $data);
if (!$response['successful']) {
    echo 'response: ';
    print_r($response);
    die;
}
// Extract _rnr_se | This value does not change* Cache this value
preg_match("/'_rnr_se': '([^']+)'/", $response['body'], $matches);
$rnrse = $matches[1];
// $data['headers'] still contains Auth for authentication
// Set SMS options
$data['post'] = array('_rnr_se' => $rnrse, 'phoneNumber' => $argv[1], 'text' => $argv[2], 'id' => '');
// Send the SMS
$response = xhttp::fetch('https://www.google.com/voice/sms/send/', $data);
// Evaluate the response
$value = json_decode($response['body']);
if ($value->ok) {
} else {
    echo "Unable to send SMS! Error Code ({$value->data->code})\n\n";
    echo 'response: ';
    print_r($response);
}
Beispiel #8
0
	$response = xhttp::fetch('https://graph.facebook.com/oauth/access_token', $data);

	if($response['successful']) {

		

		$data = xhttp::toQueryArray($response['body']);
		$_SESSION['access_token'] = $data['access_token'];
		$_SESSION['loggedin']     = true;

		$data = array();
		$data['get'] = array(
			'access_token'  => $_SESSION['access_token'],
			'fields' => 'id,name,accounts'
		);
		$response = xhttp::fetch('https://graph.facebook.com/me', $data);

		if($response['successful']) {
			$_SESSION['user'] = json_decode($response['body'], true);
			$_SESSION['user']['access_token'] = $_SESSION['access_token'];

		 } else {
			header('content-type: text/plain');
			print_r($response['body']);

		}

	} else {
		print_r($response['body']);
	}
}