| Current Path : /home/x/b/o/xbodynamge/namtation/wp-content/ |
| Current File : /home/x/b/o/xbodynamge/namtation/wp-content/Request.php.tar |
lebauwcentre/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/Request.php 0000644 00000007423 15114166015 0032061 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use InvalidArgumentException;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* PSR-7 request implementation.
*/
class Request implements \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
{
use MessageTrait;
/** @var string */
private $method;
/** @var string|null */
private $requestTarget;
/** @var UriInterface */
private $uri;
/**
* @param string $method HTTP method
* @param string|UriInterface $uri URI
* @param array $headers Request headers
* @param string|resource|StreamInterface|null $body Request body
* @param string $version Protocol version
*/
public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1')
{
$this->assertMethod($method);
if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) {
$uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri);
}
$this->method = \strtoupper($method);
$this->uri = $uri;
$this->setHeaders($headers);
$this->protocol = $version;
if (!isset($this->headerNames['host'])) {
$this->updateHostFromUri();
}
if ($body !== '' && $body !== null) {
$this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
}
}
public function getRequestTarget()
{
if ($this->requestTarget !== null) {
return $this->requestTarget;
}
$target = $this->uri->getPath();
if ($target == '') {
$target = '/';
}
if ($this->uri->getQuery() != '') {
$target .= '?' . $this->uri->getQuery();
}
return $target;
}
public function withRequestTarget($requestTarget)
{
if (\preg_match('#\\s#', $requestTarget)) {
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
}
$new = clone $this;
$new->requestTarget = $requestTarget;
return $new;
}
public function getMethod()
{
return $this->method;
}
public function withMethod($method)
{
$this->assertMethod($method);
$new = clone $this;
$new->method = \strtoupper($method);
return $new;
}
public function getUri()
{
return $this->uri;
}
public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false)
{
if ($uri === $this->uri) {
return $this;
}
$new = clone $this;
$new->uri = $uri;
if (!$preserveHost || !isset($this->headerNames['host'])) {
$new->updateHostFromUri();
}
return $new;
}
private function updateHostFromUri()
{
$host = $this->uri->getHost();
if ($host == '') {
return;
}
if (($port = $this->uri->getPort()) !== null) {
$host .= ':' . $port;
}
if (isset($this->headerNames['host'])) {
$header = $this->headerNames['host'];
} else {
$header = 'Host';
$this->headerNames['host'] = 'Host';
}
// Ensure Host is the first header.
// See: http://tools.ietf.org/html/rfc7230#section-5.4
$this->headers = [$header => [$host]] + $this->headers;
}
private function assertMethod($method)
{
if (!\is_string($method) || $method === '') {
throw new \InvalidArgumentException('Method must be a non-empty string.');
}
}
}
crosstraining/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/Request.php 0000644 00000007423 15114237316 0032271 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use InvalidArgumentException;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* PSR-7 request implementation.
*/
class Request implements \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
{
use MessageTrait;
/** @var string */
private $method;
/** @var string|null */
private $requestTarget;
/** @var UriInterface */
private $uri;
/**
* @param string $method HTTP method
* @param string|UriInterface $uri URI
* @param array $headers Request headers
* @param string|resource|StreamInterface|null $body Request body
* @param string $version Protocol version
*/
public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1')
{
$this->assertMethod($method);
if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) {
$uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri);
}
$this->method = \strtoupper($method);
$this->uri = $uri;
$this->setHeaders($headers);
$this->protocol = $version;
if (!isset($this->headerNames['host'])) {
$this->updateHostFromUri();
}
if ($body !== '' && $body !== null) {
$this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
}
}
public function getRequestTarget()
{
if ($this->requestTarget !== null) {
return $this->requestTarget;
}
$target = $this->uri->getPath();
if ($target == '') {
$target = '/';
}
if ($this->uri->getQuery() != '') {
$target .= '?' . $this->uri->getQuery();
}
return $target;
}
public function withRequestTarget($requestTarget)
{
if (\preg_match('#\\s#', $requestTarget)) {
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
}
$new = clone $this;
$new->requestTarget = $requestTarget;
return $new;
}
public function getMethod()
{
return $this->method;
}
public function withMethod($method)
{
$this->assertMethod($method);
$new = clone $this;
$new->method = \strtoupper($method);
return $new;
}
public function getUri()
{
return $this->uri;
}
public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false)
{
if ($uri === $this->uri) {
return $this;
}
$new = clone $this;
$new->uri = $uri;
if (!$preserveHost || !isset($this->headerNames['host'])) {
$new->updateHostFromUri();
}
return $new;
}
private function updateHostFromUri()
{
$host = $this->uri->getHost();
if ($host == '') {
return;
}
if (($port = $this->uri->getPort()) !== null) {
$host .= ':' . $port;
}
if (isset($this->headerNames['host'])) {
$header = $this->headerNames['host'];
} else {
$header = 'Host';
$this->headerNames['host'] = 'Host';
}
// Ensure Host is the first header.
// See: http://tools.ietf.org/html/rfc7230#section-5.4
$this->headers = [$header => [$host]] + $this->headers;
}
private function assertMethod($method)
{
if (!\is_string($method) || $method === '') {
throw new \InvalidArgumentException('Method must be a non-empty string.');
}
}
}
home/xbodynamge/www/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/Request.php0000644 00000007423 15114241724 0030305 0 ustar 00 <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use InvalidArgumentException;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* PSR-7 request implementation.
*/
class Request implements \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
{
use MessageTrait;
/** @var string */
private $method;
/** @var string|null */
private $requestTarget;
/** @var UriInterface */
private $uri;
/**
* @param string $method HTTP method
* @param string|UriInterface $uri URI
* @param array $headers Request headers
* @param string|resource|StreamInterface|null $body Request body
* @param string $version Protocol version
*/
public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1')
{
$this->assertMethod($method);
if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) {
$uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri);
}
$this->method = \strtoupper($method);
$this->uri = $uri;
$this->setHeaders($headers);
$this->protocol = $version;
if (!isset($this->headerNames['host'])) {
$this->updateHostFromUri();
}
if ($body !== '' && $body !== null) {
$this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
}
}
public function getRequestTarget()
{
if ($this->requestTarget !== null) {
return $this->requestTarget;
}
$target = $this->uri->getPath();
if ($target == '') {
$target = '/';
}
if ($this->uri->getQuery() != '') {
$target .= '?' . $this->uri->getQuery();
}
return $target;
}
public function withRequestTarget($requestTarget)
{
if (\preg_match('#\\s#', $requestTarget)) {
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
}
$new = clone $this;
$new->requestTarget = $requestTarget;
return $new;
}
public function getMethod()
{
return $this->method;
}
public function withMethod($method)
{
$this->assertMethod($method);
$new = clone $this;
$new->method = \strtoupper($method);
return $new;
}
public function getUri()
{
return $this->uri;
}
public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false)
{
if ($uri === $this->uri) {
return $this;
}
$new = clone $this;
$new->uri = $uri;
if (!$preserveHost || !isset($this->headerNames['host'])) {
$new->updateHostFromUri();
}
return $new;
}
private function updateHostFromUri()
{
$host = $this->uri->getHost();
if ($host == '') {
return;
}
if (($port = $this->uri->getPort()) !== null) {
$host .= ':' . $port;
}
if (isset($this->headerNames['host'])) {
$header = $this->headerNames['host'];
} else {
$header = 'Host';
$this->headerNames['host'] = 'Host';
}
// Ensure Host is the first header.
// See: http://tools.ietf.org/html/rfc7230#section-5.4
$this->headers = [$header => [$host]] + $this->headers;
}
private function assertMethod($method)
{
if (!\is_string($method) || $method === '') {
throw new \InvalidArgumentException('Method must be a non-empty string.');
}
}
}
xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/SearchStatistics/Api/Request.php 0000644 00000022526 15114321727 0027716 0 ustar 00 home <?php
namespace AIOSEO\Plugin\Common\SearchStatistics\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Constructs requests to our microservice.
*
* @since 4.3.0
* @version 4.6.2 Moved from Pro to Common.
*/
class Request {
/**
* The base API route.
*
* @since 4.3.0
*
* @var string
*/
private $base = '';
/**
* The URL scheme.
*
* @since 4.3.0
*
* @var string
*/
private $scheme = 'https://';
/**
* The current API route.
*
* @since 4.3.0
*
* @var string
*/
private $route = '';
/**
* The full API URL endpoint.
*
* @since 4.3.0
*
* @var string
*/
private $url = '';
/**
* The current API method.
*
* @since 4.3.0
*
* @var string
*/
private $method = '';
/**
* The API token.
*
* @since 4.3.0
*
* @var string
*/
private $token = '';
/**
* The API key.
*
* @since 4.3.0
*
* @var string
*/
private $key = '';
/**
* The API trust token.
*
* @since 4.3.0
*
* @var string
*/
private $tt = '';
/**
* Plugin slug.
*
* @since 4.3.0
*
* @var bool|string
*/
private $plugin = false;
/**
* URL to test connection with.
*
* @since 4.3.0
*
* @var string
*/
private $testurl = '';
/**
* The site URL.
*
* @since 4.3.0
*
* @var string
*/
private $siteurl = '';
/**
* The plugin version.
*
* @since 4.3.0
*
* @var string
*/
private $version = '';
/**
* The site identifier.
*
* @since 4.3.0
*
* @var string
*/
private $sitei = '';
/**
* The request args.
*
* @since 4.3.0
*
* @var array
*/
private $args = [];
/**
* Additional data to append to request body.
*
* @since 4.3.0
*
* @var array
*/
protected $additionalData = [];
/**
* Class constructor.
*
* @since 4.3.0
*
* @param string $route The API route.
* @param array $args List of arguments.
* @param string $method The API method.
*/
public function __construct( $route, $args = [], $method = 'POST' ) {
$this->base = trailingslashit( aioseo()->searchStatistics->api->getApiUrl() ) . trailingslashit( aioseo()->searchStatistics->api->getApiVersion() );
$this->route = trailingslashit( $route );
$this->url = trailingslashit( $this->scheme . $this->base . $this->route );
$this->method = $method;
$this->token = ! empty( $args['token'] ) ? $args['token'] : aioseo()->searchStatistics->api->auth->getToken();
$this->key = ! empty( $args['key'] ) ? $args['key'] : aioseo()->searchStatistics->api->auth->getKey();
$this->tt = ! empty( $args['tt'] ) ? $args['tt'] : '';
$this->args = ! empty( $args ) ? $args : [];
$this->siteurl = site_url();
$this->plugin = 'aioseo-' . strtolower( aioseo()->versionPath );
$this->version = aioseo()->version;
$this->sitei = ! empty( $args['sitei'] ) ? $args['sitei'] : '';
$this->testurl = ! empty( $args['testurl'] ) ? $args['testurl'] : '';
}
/**
* Sends and processes the API request.
*
* @since 4.3.0
*
* @return mixed The response.
*/
public function request() {
// Make sure we're not blocked.
$blocked = $this->isBlocked( $this->url );
if ( is_wp_error( $blocked ) ) {
return new \WP_Error(
'api-error',
sprintf(
'The firewall of the server is blocking outbound calls. Please contact your hosting provider to fix this issue. %s',
$blocked->get_error_message()
)
);
}
// 1. BUILD BODY
$body = [];
if ( ! empty( $this->args ) ) {
foreach ( $this->args as $name => $value ) {
$body[ $name ] = $value;
}
}
foreach ( [ 'sitei', 'siteurl', 'version', 'key', 'token', 'tt' ] as $key ) {
if ( ! empty( $this->{$key} ) ) {
$body[ $key ] = $this->{$key};
}
}
// If this is a plugin API request, add the data.
if ( 'info' === $this->route || 'update' === $this->route ) {
$body['aioseoapi-plugin'] = $this->plugin;
}
// Add in additional data if needed.
if ( ! empty( $this->additionalData ) ) {
$body['aioseoapi-data'] = maybe_serialize( $this->additionalData );
}
if ( 'GET' === $this->method ) {
$body['time'] = time(); // Add a timestamp to avoid caching.
}
$body['timezone'] = gmdate( 'e' );
$body['ip'] = ! empty( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '';
// 2. SET HEADERS
$headers = array_merge( [
'Content-Type' => 'application/json',
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0',
'Pragma' => 'no-cache',
'Expires' => 0,
'AIOSEOAPI-Referer' => site_url(),
'AIOSEOAPI-Sender' => 'WordPress',
'X-AIOSEO-Key' => aioseo()->internalOptions->internal->siteAnalysis->connectToken,
], aioseo()->helpers->getApiHeaders() );
// 3. COMPILE REQUEST DATA
$data = [
'headers' => $headers,
'body' => wp_json_encode( $body ),
'timeout' => 3000,
'user-agent' => aioseo()->helpers->getApiUserAgent()
];
// 4. EXECUTE REQUEST
if ( 'GET' === $this->method ) {
$queryString = http_build_query( $body, '', '&' );
unset( $data['body'] );
$response = wp_remote_get( esc_url_raw( $this->url ) . '?' . $queryString, $data );
} else {
$response = wp_remote_post( esc_url_raw( $this->url ), $data );
}
// 5. VALIDATE RESPONSE
if ( is_wp_error( $response ) ) {
return $response;
}
$responseCode = wp_remote_retrieve_response_code( $response );
$responseBody = json_decode( wp_remote_retrieve_body( $response ), true );
if ( is_wp_error( $responseBody ) ) {
return false;
}
if ( 200 !== $responseCode ) {
$type = ! empty( $responseBody['type'] ) ? $responseBody['type'] : 'api-error';
if ( empty( $responseCode ) ) {
return new \WP_Error(
$type,
'The API was unreachable.'
);
}
if ( empty( $responseBody ) || ( empty( $responseBody['message'] ) && empty( $responseBody['error'] ) ) ) {
return new \WP_Error(
$type,
sprintf(
'The API returned a <strong>%s</strong> response',
$responseCode
)
);
}
if ( ! empty( $responseBody['message'] ) ) {
return new \WP_Error(
$type,
sprintf(
'The API returned a <strong>%1$d</strong> response with this message: <strong>%2$s</strong>',
$responseCode, stripslashes( $responseBody['message'] )
)
);
}
if ( ! empty( $responseBody['error'] ) ) {
return new \WP_Error(
$type,
sprintf(
'The API returned a <strong>%1$d</strong> response with this message: <strong>%2$s</strong>', $responseCode,
stripslashes( $responseBody['error'] )
)
);
}
}
// Check if the trust token is required.
if (
! empty( $this->tt ) &&
( empty( $responseBody['tt'] ) || ! hash_equals( $this->tt, $responseBody['tt'] ) )
) {
return new \WP_Error( 'validation-error', 'Invalid API request.' );
}
return $responseBody;
}
/**
* Sets additional data for the request.
*
* @since 4.3.0
*
* @param array $data The additional data.
* @return void
*/
public function setAdditionalData( array $data ) {
$this->additionalData = array_merge( $this->additionalData, $data );
}
/**
* Checks if the given URL is blocked for a request.
*
* @since 4.3.0
*
* @param string $url The URL to test against.
* @return bool|\WP_Error False or WP_Error if it is blocked.
*/
private function isBlocked( $url = '' ) {
// The below page is a test HTML page used for firewall/router login detection
// and for image linking purposes in Google Images. We use it to test outbound connections
// It's on Google's main CDN so it loads in most countries in 0.07 seconds or less. Perfect for our
// use case of testing outbound connections.
$testurl = ! empty( $this->testurl ) ? $this->testurl : 'https://www.google.com/blank.html';
if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) {
if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
$wpHttp = new \WP_Http();
$onBlacklist = $wpHttp->block_request( $url );
if ( $onBlacklist ) {
return new \WP_Error( 'api-error', 'The API was unreachable because the API url is on the WP HTTP blocklist.' );
} else {
$params = [
'sslverify' => false,
'timeout' => 2,
'user-agent' => aioseo()->helpers->getApiUserAgent(),
'body' => ''
];
$response = wp_remote_get( $testurl, $params );
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
return false;
} else {
if ( is_wp_error( $response ) ) {
return $response;
} else {
return new \WP_Error( 'api-error', 'The API was unreachable because the call to Google failed.' );
}
}
}
} else {
return new \WP_Error( 'api-error', 'The API was unreachable because no external hosts are allowed on this site.' );
}
} else {
$params = [
'sslverify' => false,
'timeout' => 2,
'user-agent' => aioseo()->helpers->getApiUserAgent(),
'body' => ''
];
$response = wp_remote_get( $testurl, $params );
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
return false;
} else {
if ( is_wp_error( $response ) ) {
return $response;
} else {
return new \WP_Error( 'api-error', 'The API was unreachable because the call to Google failed.' );
}
}
}
}
} home/xbodynamge/dev/wp-content/plugins/all-in-one-seo-pack/app/Common/Traits/Helpers/Request.php 0000644 00000003440 15114330116 0026636 0 ustar 00 <?php
namespace AIOSEO\Plugin\Common\Traits\Helpers;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Parse the current request.
*
* @since 4.2.1
*/
trait Request {
/**
* Get the server port.
*
* @since 4.2.1
*
* @return string The server port.
*/
private function getServerPort() {
if (
empty( $_SERVER['SERVER_PORT'] ) ||
80 === (int) $_SERVER['SERVER_PORT'] ||
443 === (int) $_SERVER['SERVER_PORT']
) {
return '';
}
return ':' . (int) $_SERVER['SERVER_PORT'];
}
/**
* Get the protocol.
*
* @since 4.2.1
*
* @return string The protocol.
*/
private function getProtocol() {
return is_ssl() ? 'https' : 'http';
}
/**
* Get the server name (from $_SERVER['SERVER_NAME]), or use the request name ($_SERVER['HTTP_HOST']) if not present.
*
* @since 4.2.1
*
* @return string The server name.
*/
private function getServerName() {
$host = $this->getRequestServerName();
if ( isset( $_SERVER['SERVER_NAME'] ) ) {
$host = sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ); // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
}
return $host;
}
/**
* Get the request server name (from $_SERVER['HTTP_HOST]).
*
* @since 4.2.1
*
* @return string The request server name.
*/
private function getRequestServerName() {
$host = '';
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
$host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
}
return $host;
}
/**
* Retrieve the request URL.
*
* @since 4.2.1
*
* @return string The request URL.
*/
public function getRequestUrl() {
$url = '';
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
$url = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
}
return rawurldecode( $url );
}
} namtation/wp-content/plugins/wordpress-seo/vendor_prefixed/guzzlehttp/psr7/src/Request.php 0000644 00000007423 15114415216 0031373 0 ustar 00 home/xbodynamge <?php
namespace YoastSEO_Vendor\GuzzleHttp\Psr7;
use InvalidArgumentException;
use YoastSEO_Vendor\Psr\Http\Message\RequestInterface;
use YoastSEO_Vendor\Psr\Http\Message\StreamInterface;
use YoastSEO_Vendor\Psr\Http\Message\UriInterface;
/**
* PSR-7 request implementation.
*/
class Request implements \YoastSEO_Vendor\Psr\Http\Message\RequestInterface
{
use MessageTrait;
/** @var string */
private $method;
/** @var string|null */
private $requestTarget;
/** @var UriInterface */
private $uri;
/**
* @param string $method HTTP method
* @param string|UriInterface $uri URI
* @param array $headers Request headers
* @param string|resource|StreamInterface|null $body Request body
* @param string $version Protocol version
*/
public function __construct($method, $uri, array $headers = [], $body = null, $version = '1.1')
{
$this->assertMethod($method);
if (!$uri instanceof \YoastSEO_Vendor\Psr\Http\Message\UriInterface) {
$uri = new \YoastSEO_Vendor\GuzzleHttp\Psr7\Uri($uri);
}
$this->method = \strtoupper($method);
$this->uri = $uri;
$this->setHeaders($headers);
$this->protocol = $version;
if (!isset($this->headerNames['host'])) {
$this->updateHostFromUri();
}
if ($body !== '' && $body !== null) {
$this->stream = \YoastSEO_Vendor\GuzzleHttp\Psr7\Utils::streamFor($body);
}
}
public function getRequestTarget()
{
if ($this->requestTarget !== null) {
return $this->requestTarget;
}
$target = $this->uri->getPath();
if ($target == '') {
$target = '/';
}
if ($this->uri->getQuery() != '') {
$target .= '?' . $this->uri->getQuery();
}
return $target;
}
public function withRequestTarget($requestTarget)
{
if (\preg_match('#\\s#', $requestTarget)) {
throw new \InvalidArgumentException('Invalid request target provided; cannot contain whitespace');
}
$new = clone $this;
$new->requestTarget = $requestTarget;
return $new;
}
public function getMethod()
{
return $this->method;
}
public function withMethod($method)
{
$this->assertMethod($method);
$new = clone $this;
$new->method = \strtoupper($method);
return $new;
}
public function getUri()
{
return $this->uri;
}
public function withUri(\YoastSEO_Vendor\Psr\Http\Message\UriInterface $uri, $preserveHost = \false)
{
if ($uri === $this->uri) {
return $this;
}
$new = clone $this;
$new->uri = $uri;
if (!$preserveHost || !isset($this->headerNames['host'])) {
$new->updateHostFromUri();
}
return $new;
}
private function updateHostFromUri()
{
$host = $this->uri->getHost();
if ($host == '') {
return;
}
if (($port = $this->uri->getPort()) !== null) {
$host .= ':' . $port;
}
if (isset($this->headerNames['host'])) {
$header = $this->headerNames['host'];
} else {
$header = 'Host';
$this->headerNames['host'] = 'Host';
}
// Ensure Host is the first header.
// See: http://tools.ietf.org/html/rfc7230#section-5.4
$this->headers = [$header => [$host]] + $this->headers;
}
private function assertMethod($method)
{
if (!\is_string($method) || $method === '') {
throw new \InvalidArgumentException('Method must be a non-empty string.');
}
}
}
xbodynamge/namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/Traits/Helpers/Request.php 0000644 00000003440 15114443407 0030003 0 ustar 00 home <?php
namespace AIOSEO\Plugin\Common\Traits\Helpers;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Parse the current request.
*
* @since 4.2.1
*/
trait Request {
/**
* Get the server port.
*
* @since 4.2.1
*
* @return string The server port.
*/
private function getServerPort() {
if (
empty( $_SERVER['SERVER_PORT'] ) ||
80 === (int) $_SERVER['SERVER_PORT'] ||
443 === (int) $_SERVER['SERVER_PORT']
) {
return '';
}
return ':' . (int) $_SERVER['SERVER_PORT'];
}
/**
* Get the protocol.
*
* @since 4.2.1
*
* @return string The protocol.
*/
private function getProtocol() {
return is_ssl() ? 'https' : 'http';
}
/**
* Get the server name (from $_SERVER['SERVER_NAME]), or use the request name ($_SERVER['HTTP_HOST']) if not present.
*
* @since 4.2.1
*
* @return string The server name.
*/
private function getServerName() {
$host = $this->getRequestServerName();
if ( isset( $_SERVER['SERVER_NAME'] ) ) {
$host = sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ); // phpcs:ignore HM.Security.ValidatedSanitizedInput.InputNotSanitized
}
return $host;
}
/**
* Get the request server name (from $_SERVER['HTTP_HOST]).
*
* @since 4.2.1
*
* @return string The request server name.
*/
private function getRequestServerName() {
$host = '';
if ( isset( $_SERVER['HTTP_HOST'] ) ) {
$host = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ) );
}
return $host;
}
/**
* Retrieve the request URL.
*
* @since 4.2.1
*
* @return string The request URL.
*/
public function getRequestUrl() {
$url = '';
if ( isset( $_SERVER['REQUEST_URI'] ) ) {
$url = sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) );
}
return rawurldecode( $url );
}
} namtation/wp-content/plugins/all-in-one-seo-pack/app/Common/SearchStatistics/Api/Request.php 0000644 00000022526 15115072747 0031140 0 ustar 00 home/xbodynamge <?php
namespace AIOSEO\Plugin\Common\SearchStatistics\Api;
// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
/**
* Constructs requests to our microservice.
*
* @since 4.3.0
* @version 4.6.2 Moved from Pro to Common.
*/
class Request {
/**
* The base API route.
*
* @since 4.3.0
*
* @var string
*/
private $base = '';
/**
* The URL scheme.
*
* @since 4.3.0
*
* @var string
*/
private $scheme = 'https://';
/**
* The current API route.
*
* @since 4.3.0
*
* @var string
*/
private $route = '';
/**
* The full API URL endpoint.
*
* @since 4.3.0
*
* @var string
*/
private $url = '';
/**
* The current API method.
*
* @since 4.3.0
*
* @var string
*/
private $method = '';
/**
* The API token.
*
* @since 4.3.0
*
* @var string
*/
private $token = '';
/**
* The API key.
*
* @since 4.3.0
*
* @var string
*/
private $key = '';
/**
* The API trust token.
*
* @since 4.3.0
*
* @var string
*/
private $tt = '';
/**
* Plugin slug.
*
* @since 4.3.0
*
* @var bool|string
*/
private $plugin = false;
/**
* URL to test connection with.
*
* @since 4.3.0
*
* @var string
*/
private $testurl = '';
/**
* The site URL.
*
* @since 4.3.0
*
* @var string
*/
private $siteurl = '';
/**
* The plugin version.
*
* @since 4.3.0
*
* @var string
*/
private $version = '';
/**
* The site identifier.
*
* @since 4.3.0
*
* @var string
*/
private $sitei = '';
/**
* The request args.
*
* @since 4.3.0
*
* @var array
*/
private $args = [];
/**
* Additional data to append to request body.
*
* @since 4.3.0
*
* @var array
*/
protected $additionalData = [];
/**
* Class constructor.
*
* @since 4.3.0
*
* @param string $route The API route.
* @param array $args List of arguments.
* @param string $method The API method.
*/
public function __construct( $route, $args = [], $method = 'POST' ) {
$this->base = trailingslashit( aioseo()->searchStatistics->api->getApiUrl() ) . trailingslashit( aioseo()->searchStatistics->api->getApiVersion() );
$this->route = trailingslashit( $route );
$this->url = trailingslashit( $this->scheme . $this->base . $this->route );
$this->method = $method;
$this->token = ! empty( $args['token'] ) ? $args['token'] : aioseo()->searchStatistics->api->auth->getToken();
$this->key = ! empty( $args['key'] ) ? $args['key'] : aioseo()->searchStatistics->api->auth->getKey();
$this->tt = ! empty( $args['tt'] ) ? $args['tt'] : '';
$this->args = ! empty( $args ) ? $args : [];
$this->siteurl = site_url();
$this->plugin = 'aioseo-' . strtolower( aioseo()->versionPath );
$this->version = aioseo()->version;
$this->sitei = ! empty( $args['sitei'] ) ? $args['sitei'] : '';
$this->testurl = ! empty( $args['testurl'] ) ? $args['testurl'] : '';
}
/**
* Sends and processes the API request.
*
* @since 4.3.0
*
* @return mixed The response.
*/
public function request() {
// Make sure we're not blocked.
$blocked = $this->isBlocked( $this->url );
if ( is_wp_error( $blocked ) ) {
return new \WP_Error(
'api-error',
sprintf(
'The firewall of the server is blocking outbound calls. Please contact your hosting provider to fix this issue. %s',
$blocked->get_error_message()
)
);
}
// 1. BUILD BODY
$body = [];
if ( ! empty( $this->args ) ) {
foreach ( $this->args as $name => $value ) {
$body[ $name ] = $value;
}
}
foreach ( [ 'sitei', 'siteurl', 'version', 'key', 'token', 'tt' ] as $key ) {
if ( ! empty( $this->{$key} ) ) {
$body[ $key ] = $this->{$key};
}
}
// If this is a plugin API request, add the data.
if ( 'info' === $this->route || 'update' === $this->route ) {
$body['aioseoapi-plugin'] = $this->plugin;
}
// Add in additional data if needed.
if ( ! empty( $this->additionalData ) ) {
$body['aioseoapi-data'] = maybe_serialize( $this->additionalData );
}
if ( 'GET' === $this->method ) {
$body['time'] = time(); // Add a timestamp to avoid caching.
}
$body['timezone'] = gmdate( 'e' );
$body['ip'] = ! empty( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '';
// 2. SET HEADERS
$headers = array_merge( [
'Content-Type' => 'application/json',
'Cache-Control' => 'no-store, no-cache, must-revalidate, max-age=0, post-check=0, pre-check=0',
'Pragma' => 'no-cache',
'Expires' => 0,
'AIOSEOAPI-Referer' => site_url(),
'AIOSEOAPI-Sender' => 'WordPress',
'X-AIOSEO-Key' => aioseo()->internalOptions->internal->siteAnalysis->connectToken,
], aioseo()->helpers->getApiHeaders() );
// 3. COMPILE REQUEST DATA
$data = [
'headers' => $headers,
'body' => wp_json_encode( $body ),
'timeout' => 3000,
'user-agent' => aioseo()->helpers->getApiUserAgent()
];
// 4. EXECUTE REQUEST
if ( 'GET' === $this->method ) {
$queryString = http_build_query( $body, '', '&' );
unset( $data['body'] );
$response = wp_remote_get( esc_url_raw( $this->url ) . '?' . $queryString, $data );
} else {
$response = wp_remote_post( esc_url_raw( $this->url ), $data );
}
// 5. VALIDATE RESPONSE
if ( is_wp_error( $response ) ) {
return $response;
}
$responseCode = wp_remote_retrieve_response_code( $response );
$responseBody = json_decode( wp_remote_retrieve_body( $response ), true );
if ( is_wp_error( $responseBody ) ) {
return false;
}
if ( 200 !== $responseCode ) {
$type = ! empty( $responseBody['type'] ) ? $responseBody['type'] : 'api-error';
if ( empty( $responseCode ) ) {
return new \WP_Error(
$type,
'The API was unreachable.'
);
}
if ( empty( $responseBody ) || ( empty( $responseBody['message'] ) && empty( $responseBody['error'] ) ) ) {
return new \WP_Error(
$type,
sprintf(
'The API returned a <strong>%s</strong> response',
$responseCode
)
);
}
if ( ! empty( $responseBody['message'] ) ) {
return new \WP_Error(
$type,
sprintf(
'The API returned a <strong>%1$d</strong> response with this message: <strong>%2$s</strong>',
$responseCode, stripslashes( $responseBody['message'] )
)
);
}
if ( ! empty( $responseBody['error'] ) ) {
return new \WP_Error(
$type,
sprintf(
'The API returned a <strong>%1$d</strong> response with this message: <strong>%2$s</strong>', $responseCode,
stripslashes( $responseBody['error'] )
)
);
}
}
// Check if the trust token is required.
if (
! empty( $this->tt ) &&
( empty( $responseBody['tt'] ) || ! hash_equals( $this->tt, $responseBody['tt'] ) )
) {
return new \WP_Error( 'validation-error', 'Invalid API request.' );
}
return $responseBody;
}
/**
* Sets additional data for the request.
*
* @since 4.3.0
*
* @param array $data The additional data.
* @return void
*/
public function setAdditionalData( array $data ) {
$this->additionalData = array_merge( $this->additionalData, $data );
}
/**
* Checks if the given URL is blocked for a request.
*
* @since 4.3.0
*
* @param string $url The URL to test against.
* @return bool|\WP_Error False or WP_Error if it is blocked.
*/
private function isBlocked( $url = '' ) {
// The below page is a test HTML page used for firewall/router login detection
// and for image linking purposes in Google Images. We use it to test outbound connections
// It's on Google's main CDN so it loads in most countries in 0.07 seconds or less. Perfect for our
// use case of testing outbound connections.
$testurl = ! empty( $this->testurl ) ? $this->testurl : 'https://www.google.com/blank.html';
if ( defined( 'WP_HTTP_BLOCK_EXTERNAL' ) && WP_HTTP_BLOCK_EXTERNAL ) {
if ( defined( 'WP_ACCESSIBLE_HOSTS' ) ) {
$wpHttp = new \WP_Http();
$onBlacklist = $wpHttp->block_request( $url );
if ( $onBlacklist ) {
return new \WP_Error( 'api-error', 'The API was unreachable because the API url is on the WP HTTP blocklist.' );
} else {
$params = [
'sslverify' => false,
'timeout' => 2,
'user-agent' => aioseo()->helpers->getApiUserAgent(),
'body' => ''
];
$response = wp_remote_get( $testurl, $params );
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
return false;
} else {
if ( is_wp_error( $response ) ) {
return $response;
} else {
return new \WP_Error( 'api-error', 'The API was unreachable because the call to Google failed.' );
}
}
}
} else {
return new \WP_Error( 'api-error', 'The API was unreachable because no external hosts are allowed on this site.' );
}
} else {
$params = [
'sslverify' => false,
'timeout' => 2,
'user-agent' => aioseo()->helpers->getApiUserAgent(),
'body' => ''
];
$response = wp_remote_get( $testurl, $params );
if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 ) {
return false;
} else {
if ( is_wp_error( $response ) ) {
return $response;
} else {
return new \WP_Error( 'api-error', 'The API was unreachable because the call to Google failed.' );
}
}
}
}
}