| Server IP : 89.39.208.18 / Your IP : 216.73.217.74 Web Server : LiteSpeed System : User : ( ) PHP Version : 7.4.33 Disable Function : eval,./,ln,passthru,dl,system,exec,popen,shell_exec,posix_getpwuid,posix_uname,ftp_exec,posix_uname,posix_getpwuid,posix_kill,posix_mkfifo,posix_setpgid,posix_setsid,posix_setuid,get_current_user,getmyuid,getmygid,listen,chgrp,apache_note,apache_setenv,apache_child_terminate,closelog,debugger_off,debugge_on,ini_restore,netscript,escapeshellarg,cmd,backtick,virtual,show_sourc,show_source,pclose,pcntl_exec,datasec,old_offset,ctrl_dir,ini_alter,leak,listen,chgrp,apache_setenv,define_syslog_variables,root,diskfreespace,disk_free_space,disk_total_space,posix_kill,getmyuid,getmygid,apache_child_terminate,php_ini_scanned_files,ls,ps_aux,chown,getrusage,posixc,posame,chgrp,posix_setuid,posix_setsid,posix_setgid,apache_note,apache_setenv,x_getuid,e_ini_file,nfo,SQL,mysql_li,t_dbs,filegroup,highlight_file,ilegetcontents,get_dir,popen,popens,pfsockopen,dos_conv,apache_get_modules,crack_check,crack_closedict,rar_open,bzopen,bzread,bzwrite,shellcode,posix_isatty,posix_getservbyname,escapeshellarg,hypot,pg_host,pos,posix_access,inurl,posix_times,posix_mknod,pclose,ps_fill,symlink,id,escapeshellcmd,php_uname,phpinfo MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home3/./mahyarcake/./www/wp-content/plugins/elementor-pro/modules/forms/classes/ |
Upload File : |
<?php
namespace ElementorPro\Modules\Forms\Classes;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
class Rest_Client {
private $api_base_url = '';
private $user_agent = 'Elementor Forms (elementor.com)';
public $request_cache = [];
private $headers = [];
private $request_args = [];
public function __construct( $rest_base_url ) {
$this->api_base_url = $rest_base_url;
//setup defaults
$this->set_request_arg( 'timeout', 30 )
->set_request_arg( 'sslverify', false )
->add_headers( 'User-Agent', $this->user_agent );
/**
* Initiate Elementor form REST API client.
*
* Fires when Elementor forms are initiated on REST API client.
*
* @since 2.4.0
*
* @param Rest_Client $this An instance of form REST API client.
*/
do_action( 'elementor-pro/forms/rest_client/init', $this );
return $this;
}
/**
* Set REST API base url.
*
* @param string $url
*/
public function set_base_url( $url ) {
$this->api_base_url = $url;
}
/**
* Get REST API base url.
*
* @return string
*/
public function get_base_url() {
return $this->api_base_url;
}
/**
* Add headers to REST API.
*
* @param $key Header key.
* @param $value Optional. Header value. Default is null.
*
* @return $this An instance of REST API client.
*/
public function add_headers( $key, $value = null ) {
if ( ! is_array( $key ) ) {
$this->headers[ $key ] = $value;
return $this;
}
foreach ( $key as $header => $header_value ) {
$this->headers[ $header ] = $header_value;
}
return $this;
}
/**
* Set REST API request arguments.
*
* @param string $name Optional. Request argument name. Default is ''.
* @param null $value Optional. Request argument value. Default is null.
*
* @return $this An instance of REST API client.
*/
public function set_request_arg( $name = '', $value = null ) {
$this->request_args[ $name ] = $value;
return $this;
}
/**
* @uses request
*
* @param string $endpoint Optional. Default is ''.
* @param null $data Optional. Default is null.
*
* @return array|mixed
* @throws \Exception
*/
public function post( $endpoint = '', $data = null ) {
$request_body = wp_json_encode( $data );
return $this->request( 'POST', $endpoint, $request_body );
}
/**
* @uses request
*
* @param string $endpoint Optional. Default is ''.
* @param null $data Optional. Default is null.
*
* @return array|mixed
* @throws \Exception
*/
public function get( $endpoint = '', $data = null ) {
return $this->request( 'GET', $endpoint, $data );
}
/**
* @param string $method Optional. Default is 'GET'.
* @param string $endpoint Optional. Default is ''.
* @param null $request_body Optional. Default is null.
* @param int $valid_response_code Optional. Default is '200'.
*
* @return array
* @throws \Exception
*/
public function request( $method = 'GET', $endpoint = '', $request_body = null, $valid_response_code = 200 ) {
$request_url = $this->api_base_url . $endpoint;
$base_args = [
'method' => $method,
'headers' => $this->headers,
];
$api_request_args = array_merge( $base_args, $this->request_args );
if ( null !== $request_body ) {
if ( in_array( $method, [ 'POST', 'PUT' ] ) ) {
$api_request_args['body'] = $request_body;
} else {
$request_url = add_query_arg( $request_body, $request_url );
}
}
$cache_key = md5( $method . $endpoint . json_encode( $api_request_args ) );
if ( isset( $this->request_cache[ $cache_key ] ) && isset( $this->request_cache[ $cache_key ]['parsed'] ) ) {
$this->request_cache[ $cache_key ]['parsed'];
}
$response = wp_remote_request( $request_url, $api_request_args );
$response_code = (int) wp_remote_retrieve_response_code( $response );
$this->request_cache[ $cache_key ]['raw'] = $response;
if ( is_wp_error( $response ) || $valid_response_code !== $response_code ) {
throw new \Exception( "Rest Client Error: response code {$response_code}." );
}
$response_body = json_decode( wp_remote_retrieve_body( $response ), true );
if ( ! is_array( $response_body ) ) {
throw new \Exception( 'Rest Client Error: unexpected response type.' );
}
$return = [
'code' => $response_code,
'body' => $response_body,
];
$this->request_cache[ $cache_key ]['parsed'] = $return;
return $return;
}
}