function _http_build_query($data, $prefix = null, $sep = null, $key = '', $urlencode = true)
{
    $ret = array();
    foreach ((array) $data as $k => $v) {
        if ($urlencode) {
            $k = urlencode($k);
        }
        if (is_int($k) && $prefix != null) {
            $k = $prefix . $k;
        }
        if (!empty($key)) {
            $k = $key . '%5B' . $k . '%5D';
        }
        if ($v === NULL) {
            continue;
        } elseif ($v === FALSE) {
            $v = '0';
        }
        if (is_array($v) || is_object($v)) {
            array_push($ret, _http_build_query($v, '', $sep, $k, $urlencode));
        } elseif ($urlencode) {
            array_push($ret, $k . '=' . urlencode($v));
        } else {
            array_push($ret, $k . '=' . $v);
        }
    }
    if (NULL === $sep) {
        $sep = ini_get('arg_separator.output');
    }
    return implode($sep, $ret);
}
 public function geocodeAddress($address, $sensor = false)
 {
     $result = null;
     // URL
     $url = sprintf(self::API_END_POINT . '%s/%s?%s', 'geocode', self::OUTPUT_JSON, _http_build_query(array('address' => $address, 'sensor' => $sensor ? 'true' : 'false')));
     $response = wp_remote_get($url);
     if (is_wp_error($response)) {
     } else {
         $body = $response['body'];
         $result = json_decode($body);
     }
     return $result;
 }
Ejemplo n.º 3
0
 /**
  * Constructs and initliaze an Google Maps admin
  */
 public static function bootstrap()
 {
     global $wp_version;
     // Actions and hooks
     if (version_compare($wp_version, '3.3', '<')) {
         add_action('wp_footer', array(__CLASS__, 'printScripts'));
     }
     // Scripts
     wp_register_style('pronamic_google_maps_fix', plugins_url('css/fix.css', Pronamic_Google_Maps_Maps::$file));
     // Scripts
     wp_register_script('pronamic_google_maps_site', plugins_url('js/site.js', Pronamic_Google_Maps_Maps::$file), array('jquery', 'google-jsapi'));
     // Settings
     $other_params_array = array('sensor' => 'false');
     $other_params_array = apply_filters('pronamic_google_maps_load_other_params_array', $other_params_array);
     $other_params_string = _http_build_query($other_params_array, null, '&');
     $other_params_string = apply_filters('pronamic_google_maps_load_other_params_string', $other_params_string);
     wp_localize_script('pronamic_google_maps_site', 'pronamic_google_maps_settings', array('visualRefresh' => get_option('pronamic_google_maps_visual_refresh'), 'other_params' => $other_params_string));
 }
Ejemplo n.º 4
0
 function request_token()
 {
     Keyring_Util::debug('Keyring_Service_OAuth2::request_token()');
     if (!isset($_REQUEST['nonce']) || !wp_verify_nonce($_REQUEST['nonce'], 'keyring-request-' . $this->get_name())) {
         Keyring::error(__('Invalid/missing request nonce.', 'keyring'));
         exit;
     }
     // Need to create a request token now, so that we have a state to pass
     $request_token = new Keyring_Request_Token($this->get_name(), array(), apply_filters('keyring_request_token_meta', array('for' => isset($_REQUEST['for']) ? (string) $_REQUEST['for'] : false), $this->get_name(), array(), $this));
     $request_token = apply_filters('keyring_request_token', $request_token, $this);
     $request_token_id = $this->store_token($request_token);
     $url = $this->authorize_url;
     if (!stristr($url, '?')) {
         $url .= '?';
     }
     $params = array('response_type' => 'code', 'client_id' => $this->key, 'redirect_uri' => $this->callback_url, 'state' => $request_token_id);
     $params = apply_filters('keyring_' . $this->get_name() . '_request_token_params', $params);
     Keyring_Util::debug('OAuth2 Redirect URL: ' . $url . _http_build_query($params, '', '&'));
     wp_redirect($url . _http_build_query($params, '', '&'));
     exit;
 }
Ejemplo n.º 5
0
 function _get_rabobank_data($data, $tran_id)
 {
     // new data
     $n_data = array();
     // map
     $map = array('currencyCode' => 'currency', 'merchantId' => 'merchantID', 'normalReturnUrl' => 'urlSuccess', 'amount' => 'amount', 'transactionReference' => 'purchaseID', 'customerLanguage' => 'language', 'orderId' => 'purchaseID');
     // loop
     foreach ($map as $k => $v) {
         $n_data[$k] = $data[$v];
     }
     // date
     // $n_data['expirationDate']	    = $data['validUntil'];// date(DATE_ISO8601, strtotime('+1 hour'));
     // key version
     $n_data['keyVersion'] = $this->setting['key_version'];
     $n_data['paymentMeanBrandList'] = $this->setting['payment_mean_brand'];
     // current 4217 code
     $n_data['currencyCode'] = mgm_get_currency_iso4217($n_data['currencyCode']);
     $n_data['customerLanguage'] = substr($n_data['customerLanguage'], 0, 2);
     // url
     $n_data['automaticResponseUrl'] = site_url() . '/idealraboomnikassa_proxy.php?url_' . base64_encode(add_query_arg(array('extra' => $data['purchaseID']), $this->setting['notify_url']));
     $n_data['normalReturnUrl'] = site_url() . '/idealraboomnikassa_proxy.php?url_' . base64_encode(add_query_arg(array('extra' => $data['purchaseID']), $this->setting['return_url']));
     // convert = to %3D, rabo strips =
     // $n_data['automaticResponseUrl'] = str_replace('=', '%3D', $n_data['automaticResponseUrl']);
     // $n_data['normalReturnUrl']      = str_replace('=', '%3D', $n_data['normalReturnUrl']);
     // filter null
     $n_data = array_filter($n_data);
     // data string
     $data_str = _http_build_query($n_data, null, '|', '', false);
     $seal_str = $data_str . $this->setting['secret_key'];
     // seal
     $seal = hash('sha256', utf8_encode($seal_str));
     //computeSeal
     // interface
     $interface = 'HP_1.0';
     // return
     return array('Data' => $data_str, 'Seal' => $seal, 'InterfaceVersion' => $interface);
 }
Ejemplo n.º 6
0
 /**
  * Send a HTTP request to a URI.
  *
  * The body and headers are part of the arguments. The 'body' argument is for the body and will
  * accept either a string or an array. The 'headers' argument should be an array, but a string
  * is acceptable. If the 'body' argument is an array, then it will automatically be escaped
  * using http_build_query().
  *
  * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS
  * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send
  * headers. Other protocols are unsupported and most likely will fail.
  *
  * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and
  * 'user-agent'.
  *
  * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow
  * others, but should not be assumed. The 'timeout' is used to sent how long the connection
  * should stay open before failing when no response. 'redirection' is used to track how many
  * redirects were taken and used to sent the amount for other transports, but not all transports
  * accept setting that value.
  *
  * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and
  * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The
  * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is
  * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
  *
  * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP
  * while it performs the request or continue regardless. Actually, that isn't entirely correct.
  * Blocking mode really just means whether the fread should just pull what it can whenever it
  * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading
  * the entire content. It doesn't actually always mean that PHP will continue going after making
  * the request.
  *
  * @access public
  * @since 2.7.0
  * @todo Refactor this code. The code in this method extends the scope of its original purpose
  *		and should be refactored to allow for cleaner abstraction and reduce duplication of the
  *		code. One suggestion is to create a class specifically for the arguments, however
  *		preliminary refactoring to this affect has affect more than just the scope of the
  *		arguments. Something to ponder at least.
  *
  * @param string $url URI resource.
  * @param str|array $args Optional. Override the defaults.
  * @return array containing 'headers', 'body', 'response', 'cookies'
  */
 function request($url, $args = array())
 {
     global $wp_version;
     $defaults = array('method' => 'GET', 'timeout' => apply_filters('http_request_timeout', 5), 'redirection' => apply_filters('http_request_redirection_count', 5), 'httpversion' => apply_filters('http_request_version', '1.0'), 'user-agent' => apply_filters('http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo('url')), 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true);
     $r = wp_parse_args($args, $defaults);
     $r = apply_filters('http_request_args', $r, $url);
     // Allow plugins to short-circuit the request
     $pre = apply_filters('pre_http_request', false, $r, $url);
     if (false !== $pre) {
         return $pre;
     }
     $arrURL = parse_url($url);
     if ($this->block_request($url)) {
         return new WP_Error('http_request_failed', __('User has blocked requests through HTTP.'));
     }
     // Determine if this is a https call and pass that on to the transport functions
     // so that we can blacklist the transports that do not support ssl verification
     $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
     // Determine if this request is to OUR install of WordPress
     $homeURL = parse_url(get_bloginfo('url'));
     $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
     unset($homeURL);
     if (is_null($r['headers'])) {
         $r['headers'] = array();
     }
     if (!is_array($r['headers'])) {
         $processedHeaders = WP_Http::processHeaders($r['headers']);
         $r['headers'] = $processedHeaders['headers'];
     }
     if (isset($r['headers']['User-Agent'])) {
         $r['user-agent'] = $r['headers']['User-Agent'];
         unset($r['headers']['User-Agent']);
     }
     if (isset($r['headers']['user-agent'])) {
         $r['user-agent'] = $r['headers']['user-agent'];
         unset($r['headers']['user-agent']);
     }
     // Construct Cookie: header if any cookies are set
     WP_Http::buildCookieHeader($r);
     if (WP_Http_Encoding::is_available()) {
         $r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();
     }
     if (empty($r['body'])) {
         // Some servers fail when sending content without the content-length header being set.
         // Also, to fix another bug, we only send when doing POST and PUT and the content-length
         // header isn't already set.
         if (($r['method'] == 'POST' || $r['method'] == 'PUT') && !isset($r['headers']['Content-Length'])) {
             $r['headers']['Content-Length'] = 0;
         }
         // The method is ambiguous, because we aren't talking about HTTP methods, the "get" in
         // this case is simply that we aren't sending any bodies and to get the transports that
         // don't support sending bodies along with those which do.
         $transports = WP_Http::_getTransport($r);
     } else {
         if (is_array($r['body']) || is_object($r['body'])) {
             if (!version_compare(phpversion(), '5.1.2', '>=')) {
                 $r['body'] = _http_build_query($r['body'], null, '&');
             } else {
                 $r['body'] = http_build_query($r['body'], null, '&');
             }
             $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
             $r['headers']['Content-Length'] = strlen($r['body']);
         }
         // The method is ambiguous, because we aren't talking about HTTP methods, the "post" in
         // this case is simply that we are sending HTTP body and to get the transports that do
         // support sending the body. Not all do, depending on the limitations of the PHP core
         // limitations.
         $transports = WP_Http::_postTransport($r);
     }
     do_action('http_api_debug', $transports, 'transports_list');
     $response = array('headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array());
     foreach ((array) $transports as $transport) {
         $response = $transport->request($url, $r);
         do_action('http_api_debug', $response, 'response', get_class($transport));
         if (!is_wp_error($response)) {
             return apply_filters('http_response', $response, $r, $url);
         }
     }
     return $response;
 }
Ejemplo n.º 7
0
Archivo: Util.php Proyecto: wp-pay/core
 /**
  * Build URL with the specified parameters
  *
  * @param string $url
  * @param array $parameters
  * @return string
  */
 public static function build_url($url, array $parameters)
 {
     return $url . '?' . _http_build_query($parameters, null, '&');
 }
Ejemplo n.º 8
0
/**
 * From php.net (modified by Mark Jaquith to behave like the native PHP5 function).
 *
 * @since 3.2.0
 * @access private
 *
 * @see http://us1.php.net/manual/en/function.http-build-query.php
 *
 * @param array|object  $data       An array or object of data. Converted to array.
 * @param string        $prefix     Optional. Numeric index. If set, start parameter numbering with it.
 *                                  Default null.
 * @param string        $sep        Optional. Argument separator; defaults to 'arg_separator.output'.
 *                                  Default null.
 * @param string        $key        Optional. Used to prefix key name. Default empty.
 * @param bool          $urlencode  Optional. Whether to use urlencode() in the result. Default true.
 *
 * @return string The query string.
 */
function _http_build_query( $data, $prefix = null, $sep = null, $key = '', $urlencode = true ) {
	$ret = array();

	foreach ( (array) $data as $k => $v ) {
		if ( $urlencode)
			$k = urlencode($k);
		if ( is_int($k) && $prefix != null )
			$k = $prefix.$k;
		if ( !empty($key) )
			$k = $key . '%5B' . $k . '%5D';
		if ( $v === null )
			continue;
		elseif ( $v === false )
			$v = '0';

		if ( is_array($v) || is_object($v) )
			array_push($ret,_http_build_query($v, '', $sep, $k, $urlencode));
		elseif ( $urlencode )
			array_push($ret, $k.'='.urlencode($v));
		else
			array_push($ret, $k.'='.$v);
	}

	if ( null === $sep )
		$sep = ini_get('arg_separator.output');

	return implode($sep, $ret);
}
 /**
  * create recurring profile
  */
 function _create_paypal_profile()
 {
     // double check
     if ($_POST['RESULT'] != 0) {
         return;
     }
     // @todo
     // void the auth
     // $this->_void_auth();
     // tran
     $tran = mgm_get_transaction($_POST['M_CUSTOM']);
     // pack
     $pack = $tran['data'];
     // log
     // mgm_log($pack, $this->module . __FUNCTION__);
     // one time billing cycle
     if (isset($pack['num_cycles']) && (int) $pack['num_cycles'] == 1) {
         // log
         mgm_log('Exit Flag for One time billing', $this->module . __FUNCTION__);
         // exit
         return;
     }
     // log
     mgm_log('Process flag to Create Profile', $this->module . __FUNCTION__);
     // user data
     $user_id = $pack['user_id'];
     $user = get_userdata($user_id);
     // item
     $item = $this->get_pack_item($pack);
     // periods
     $pay_periods = array('d' => 'DAYS', 'w' => 'WEEK', 'm' => 'MONT', 'y' => 'YEAR');
     // day not supported by Paypal
     $pay_terms = array('d' => 365, 'w' => 52, 'm' => 12, 'y' => 1);
     // secured
     $secured = array('PARTNER' => $this->setting['partner'], 'VENDOR' => $this->setting['vendor'], 'USER' => $this->setting['username'], 'PWD' => $this->setting['password'], 'MAXFAILPAYMENTS' => (int) $this->setting['max_failed_payments']);
     // greater than 0, set term to ongoing
     if ((int) $pack['num_cycles'] > 1) {
         $term = $pay_terms[$pack['duration_type']] * ($pack['num_cycles'] - 1);
         // reduce 1 since auth captures first payment right away
     } else {
         $term = 0;
     }
     // exprs
     $duration_exprs = mgm_get_class('subscription_packs')->get_duration_exprs();
     //array('d'=>'DAY','w' => 'WEEK', 'm'=>'MONTH', 'y'=>'YEAR' );
     // start date should be next billing cycle date, //date('mdY', strtotime('+1 DAY')),//MMDDYYYY
     $start_date = date('mdY', strtotime('+' . 1 * (int) $pack['duration'] . ' ' . $duration_exprs[$pack['duration_type']]));
     // method
     switch ($_POST['METHOD']) {
         case 'CC':
             // Credit Card DCC
             // comment
             $comment = sprintf('%s By %s', $item['name'], $user->user_email);
             # code...
             $data = array('TRXTYPE' => 'R', 'TENDER' => 'C', 'ACTION' => 'A', 'PROFILENAME' => $item['name'], 'ORIGID' => $_POST['PNREF'], 'START' => $start_date, 'PAYPERIOD' => $pay_periods[$pack['duration_type']], 'TERM' => $term, 'AMT' => $pack['cost'], 'EMAIL' => $user->user_email, 'DESC' => $item['name'], 'COMMENT1' => $this->_remove_special_chars($comment));
             break;
         case 'P':
             // PayPal, EC
         // PayPal, EC
         default:
             // comment
             $comment = sprintf('%s By %s', $item['name'], $user->user_email);
             # code...
             $data = array('TRXTYPE' => 'R', 'TENDER' => 'P', 'ACTION' => 'A', 'PROFILENAME' => $item['name'], 'BAID' => isset($_POST['BAID']) && !empty($_POST['BAID']) ? $_POST['BAID'] : $_POST['PNREF'], 'START' => $start_date, 'PAYPERIOD' => $pay_periods[$pack['duration_type']], 'TERM' => $term, 'AMT' => $pack['cost'], 'EMAIL' => $user->user_email, 'DESC' => $item['name'], 'COMMENT1' => $this->_remove_special_chars($comment));
             // check, notify admin
             if (!isset($_POST['BAID']) || empty($_POST['BAID'])) {
                 // subject
                 $subject = 'BAID missing in PayPal Payflow Profile Creation';
                 // message
                 $message = sprintf('BAID missing in PayPal Payflow Profile Creation, Please contact PayPal, POST DATA: %s', print_r($_POST, true));
                 // send
                 mgm_notify_admin(null, $subject, $message);
                 // log
                 mgm_log($message, $this->module . __FUNCTION__);
             }
             break;
     }
     // additional fields
     $this->_set_address_fields($user, $data);
     // merge
     $data = array_merge($secured, $data);
     // log
     mgm_log($data, $this->module . __FUNCTION__);
     // data
     $data_post = _http_build_query($data, null, '&', '', false);
     // do not encode
     // link
     $post_url = $this->_get_endpoint();
     //issue #1508
     $url_parsed = parse_url($post_url);
     // domain/host
     $domain = $url_parsed['host'];
     // headers
     $http_headers = array('POST /cgi-bin/webscr HTTP/1.1\\r\\n', 'Content-Type: application/x-www-form-urlencoded\\r\\n', 'Host: ' . $domain . '\\r\\n', 'Connection: close\\r\\n\\r\\n');
     // post
     $http_response = mgm_remote_post($post_url, $data_post, array('headers' => $http_headers, 'timeout' => 30, 'sslverify' => false));
     // parse
     $response = array();
     // parse
     parse_str($http_response, $response);
     // log
     mgm_log($response, $this->module . __FUNCTION__);
     // profile id
     if ($response['RESULT'] == 0) {
         // set in post
         $_POST['PROFILEID'] = $response['PROFILEID'];
         // set in option
         mgm_add_transaction_option(array('transaction_id' => $_POST['M_CUSTOM'], 'option_name' => strtolower($this->module . '_PROFILEID'), 'option_value' => isset($_POST['PROFILEID']) ? $_POST['PROFILEID'] : ''));
     }
 }
Ejemplo n.º 10
0
	/**
	 * Send a HTTP request to a URI.
	 *
	 * The body and headers are part of the arguments. The 'body' argument is for the body and will
	 * accept either a string or an array. The 'headers' argument should be an array, but a string
	 * is acceptable. If the 'body' argument is an array, then it will automatically be escaped
	 * using http_build_query().
	 *
	 * The only URI that are supported in the HTTP Transport implementation are the HTTP and HTTPS
	 * protocols. HTTP and HTTPS are assumed so the server might not know how to handle the send
	 * headers. Other protocols are unsupported and most likely will fail.
	 *
	 * The defaults are 'method', 'timeout', 'redirection', 'httpversion', 'blocking' and
	 * 'user-agent'.
	 *
	 * Accepted 'method' values are 'GET', 'POST', and 'HEAD', some transports technically allow
	 * others, but should not be assumed. The 'timeout' is used to sent how long the connection
	 * should stay open before failing when no response. 'redirection' is used to track how many
	 * redirects were taken and used to sent the amount for other transports, but not all transports
	 * accept setting that value.
	 *
	 * The 'httpversion' option is used to sent the HTTP version and accepted values are '1.0', and
	 * '1.1' and should be a string. Version 1.1 is not supported, because of chunk response. The
	 * 'user-agent' option is the user-agent and is used to replace the default user-agent, which is
	 * 'WordPress/WP_Version', where WP_Version is the value from $wp_version.
	 *
	 * 'blocking' is the default, which is used to tell the transport, whether it should halt PHP
	 * while it performs the request or continue regardless. Actually, that isn't entirely correct.
	 * Blocking mode really just means whether the fread should just pull what it can whenever it
	 * gets bytes or if it should wait until it has enough in the buffer to read or finishes reading
	 * the entire content. It doesn't actually always mean that PHP will continue going after making
	 * the request.
	 *
	 * @access public
	 * @since 2.7.0
	 *
	 * @param string $url URI resource.
	 * @param str|array $args Optional. Override the defaults.
	 * @return array containing 'headers', 'body', 'response', 'cookies'
	 */
	function request( $url, $args = array() ) {
		global $wp_version;

		$defaults = array(
			'method' => 'GET',
			'timeout' => apply_filters( 'http_request_timeout', 5),
			'redirection' => apply_filters( 'http_request_redirection_count', 5),
			'httpversion' => apply_filters( 'http_request_version', '1.0'),
			'user-agent' => apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' )  ),
			'blocking' => true,
			'headers' => array(),
			'cookies' => array(),
			'body' => null,
			'compress' => false,
			'decompress' => true,
			'sslverify' => true
		);

		$r = wp_parse_args( $args, $defaults );
		$r = apply_filters( 'http_request_args', $r, $url );

		$arrURL = parse_url($url);

		if ( $this->block_request( $url ) )
			return new WP_Error('http_request_failed', 'User has blocked requests through HTTP.');

		// Determine if this is a https call and pass that on to the transport functions
		// so that we can blacklist the transports that do not support ssl verification
		$r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';

		// Determine if this request is to OUR install of WordPress
		$homeURL = parse_url(get_bloginfo('url'));
		$r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
		unset($homeURL);

		if ( is_null( $r['headers'] ) )
			$r['headers'] = array();

		if ( ! is_array($r['headers']) ) {
			$processedHeaders = WP_Http::processHeaders($r['headers']);
			$r['headers'] = $processedHeaders['headers'];
		}

		if ( isset($r['headers']['User-Agent']) ) {
			$r['user-agent'] = $r['headers']['User-Agent'];
			unset($r['headers']['User-Agent']);
		}

		if ( isset($r['headers']['user-agent']) ) {
			$r['user-agent'] = $r['headers']['user-agent'];
			unset($r['headers']['user-agent']);
		}

		// Construct Cookie: header if any cookies are set
		WP_Http::buildCookieHeader( $r );

		if ( WP_Http_Encoding::is_available() )
			$r['headers']['Accept-Encoding'] = WP_Http_Encoding::accept_encoding();

		if ( is_null($r['body']) ) {
			// Some servers fail when sending content without the content-length
			// header being set.
			$r['headers']['Content-Length'] = 0;
			$transports = WP_Http::_getTransport($r);
		} else {
			if ( is_array( $r['body'] ) || is_object( $r['body'] ) ) {
				if ( ! version_compare(phpversion(), '5.1.2', '>=') )
					$r['body'] = _http_build_query($r['body'], null, '&');
				else
					$r['body'] = http_build_query($r['body'], null, '&');
				$r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
				$r['headers']['Content-Length'] = strlen($r['body']);
			}

			if ( ! isset( $r['headers']['Content-Length'] ) && ! isset( $r['headers']['content-length'] ) )
				$r['headers']['Content-Length'] = strlen($r['body']);

			$transports = WP_Http::_postTransport($r);
		}

		if ( has_action('http_api_debug') )
			do_action('http_api_debug', $transports, 'transports_list');

		$response = array( 'headers' => array(), 'body' => '', 'response' => array('code' => false, 'message' => false), 'cookies' => array() );
		foreach ( (array) $transports as $transport ) {
			$response = $transport->request($url, $r);

			if ( has_action('http_api_debug') )
				do_action( 'http_api_debug', $response, 'response', get_class($transport) );

			if ( ! is_wp_error($response) )
				return $response;
		}

		return $response;
	}
Ejemplo n.º 11
0
 function _create_upgrade_enc($pack, $data, $tran_id)
 {
     // get member
     $member = mgm_get_member($pack['user_id']);
     // copy
     $enc_data = array();
     // check
     if (isset($member->payment_info->subscr_id) && !empty($member->payment_info->subscr_id)) {
         // set
         $enc_data['subscriptionId'] = $member->payment_info->subscr_id;
         $enc_data['upgradeClientAccnum'] = $data['clientAccnum'];
         $enc_data['upgradeClientSubacc'] = $data['clientSubacc'];
         // return base64_encode();
         if (isset($pack['product']['ccbill_substype_id']) && !empty($pack['product']['ccbill_substype_id'])) {
             // set
             $enc_data['upgradeTypeId'] = trim($pack['product']['ccbill_substype_id']);
             // custom passthrough
             $enc_data['custom'] = $tran_id;
             // str
             $enc_str = _http_build_query($enc_data, null, '&', '', false);
             // enc
             return $enc = $this->encrypt($enc_str, $this->setting['upgrade_enc_key']);
         }
     } else {
         $this->enc_error = __('Member has no active CCBill Subscription, failed to process upgrade', 'mgm');
     }
     // return
     return '';
 }
 /**
  * API helper method get post fields
  *
  * @param none
  * @return string $postfields
  */
 function _get_postfields($user_id)
 {
     // new filter
     $this->postfields = apply_filters('mgm_autoresponder_get_postfields', $this->postfields, $this->code, $user_id);
     // check
     if (is_array($this->postfields)) {
         // return
         return _http_build_query($this->postfields, null, '&', '', true);
     } elseif (is_string($this->postfields)) {
         // return
         return $this->postfields;
     }
     // return as it is
     return $this->postfields;
 }
Ejemplo n.º 13
0
 function _http_build_query($formdata, $numeric_prefix = '', $key_prefix = '')
 {
     if ($numeric_prefix != '' && !is_numeric($numeric_prefix)) {
         $prefix = $numeric_prefix;
     } else {
         $prefix = '';
     }
     if (!is_array($formdata)) {
         return '';
     }
     $str = '';
     foreach ($formdata as $key => $val) {
         if (is_numeric($key)) {
             $key = $prefix . $key;
         }
         if ($str != '') {
             $str .= '&';
         }
         if ($key_prefix != '') {
             $mykey = $key_prefix . "[{$key}]";
         } else {
             $mykey =& $key;
         }
         if (is_array($val)) {
             $str .= _http_build_query($val, '', $mykey);
         } else {
             $str .= $mykey . '=' . urlencode($val);
         }
     }
     return $str;
 }
Ejemplo n.º 14
0
/**
 * Retrieve the raw response from the HTTP request using the GET method.
 *
 * @see wp_remote_request() For more information on the response array format.
 *
 * @since 2.7.0
 *
 * @param string $url Site URL to retrieve.
 * @param array $args Optional. Override the defaults.
 * @return WP_Error|array The response or WP_Error on failure.
 */
function five_remote_get($url, $args = array())
{
    //initializing
    $defaults = array('method' => 'POST', 'timeout' => apply_filters('http_request_timeout', 5), 'redirection' => apply_filters('http_request_redirection_count', 5), 'httpversion' => apply_filters('http_request_version', '1.0'), 'user-agent' => apply_filters('http_headers_useragent', '5TwentyStudiosCMS/1.0; http://www.5twentystudios.com'), 'blocking' => true, 'headers' => array(), 'cookies' => array(), 'body' => null, 'compress' => false, 'decompress' => true, 'sslverify' => true);
    $r = five_parse_args($args, $defaults);
    $r = apply_filters('http_request_args', $r, $url);
    // Allow plugins to short-circuit the request
    $pre = apply_filters('pre_http_request', false, $r, $url);
    if (false !== $pre) {
        return $pre;
    }
    $fiveConfig = fiveConfigurations();
    $arrURL = parse_url($url);
    if (empty($url) || empty($arrURL['scheme'])) {
        return array('error' => 'http_request_insufficient_data', '' => 'A valid URL was not provided.');
    }
    // Determine if this is a https call and pass that on to the transport functions
    // so that we can blacklist the transports that do not support ssl verification
    $r['ssl'] = $arrURL['scheme'] == 'https' || $arrURL['scheme'] == 'ssl';
    // Determine if this request is to OUR install of WordPress
    $homeURL = parse_url($fiveConfig->base->url);
    $r['local'] = $homeURL['host'] == $arrURL['host'] || 'localhost' == $arrURL['host'];
    unset($homeURL);
    if (is_null($r['headers'])) {
        $r['headers'] = array();
    }
    if (!is_array($r['headers'])) {
        $processedHeaders = BCurl::processHeaders($r['headers']);
        $r['headers'] = $processedHeaders['headers'];
    }
    if (isset($r['headers']['User-Agent'])) {
        $r['user-agent'] = $r['headers']['User-Agent'];
        unset($r['headers']['User-Agent']);
    }
    if (isset($r['headers']['user-agent'])) {
        $r['user-agent'] = $r['headers']['user-agent'];
        unset($r['headers']['user-agent']);
    }
    if (BCurl::encoding_is_available()) {
        $r['headers']['Accept-Encoding'] = BCurl::accept_encoding();
    }
    if (empty($r['body'])) {
        $r['body'] = null;
        // Some servers fail when sending content without the content-length header being set.
        // Also, to fix another bug, we only send when doing POST and PUT and the content-length
        // header isn't already set.
        if (($r['method'] == 'POST' || $r['method'] == 'PUT') && !isset($r['headers']['Content-Length'])) {
            $r['headers']['Content-Length'] = 0;
        }
    } else {
        if (is_array($r['body']) || is_object($r['body'])) {
            if (!version_compare(phpversion(), '5.1.2', '>=')) {
                $r['body'] = _http_build_query($r['body'], null, '&');
            } else {
                $r['body'] = http_build_query($r['body'], null, '&');
            }
            $r['headers']['Content-Type'] = 'application/x-www-form-urlencoded; charset=' . get_option('blog_charset');
            $r['headers']['Content-Length'] = strlen($r['body']);
        }
        if (!isset($r['headers']['Content-Length']) && !isset($r['headers']['content-length'])) {
            $r['headers']['Content-Length'] = strlen($r['body']);
        }
    }
    //finally..  make the request
    $bcurl = new BCurl();
    $response = $bcurl->request($url, $r);
    return $response;
}
Ejemplo n.º 15
0
 /**
  * Essentially a copy of WP's build_query but one that doesn't expect pre-urlencoded values.
  *
  * @param array $args An array of key => value pairs
  * @return string A string ready for use as a URL query string.
  */
 public static function build_query($args)
 {
     return _http_build_query($args, '', '&');
 }
Ejemplo n.º 16
0
 /**
  * Create an piped string for the specified data array
  *
  * @param array $data
  * @return string
  */
 public static function create_piped_string(array $data)
 {
     // @see http://core.trac.wordpress.org/browser/tags/3.3.1/wp-includes/functions.php#L1385
     return _http_build_query($data, null, '|', '', false);
 }
Ejemplo n.º 17
0
/**
 * Build URL query based on an associative and, or indexed array.
 *
 * This is a convenient function for easily building url queries. It sets the
 * separator to '&' and uses _http_build_query() function.
 *
 * @see _http_build_query() Used to build the query
 * @link http://us2.php.net/manual/en/function.http-build-query.php more on what
 *		http_build_query() does.
 *
 * @since 2.3.0
 *
 * @param array $data URL-encode key/value pairs.
 * @return string URL encoded string
 */
function build_query($data)
{
    return _http_build_query($data, null, '&', '', false);
}
Ejemplo n.º 18
0
 public function remote_check_comment($params)
 {
     $response = Akismet::http_post(_http_build_query($params, '', '&'), 'comment-check');
     return 'true' === $response[1];
 }