| Server IP : 38.190.208.107 / Your IP : 216.73.217.46 Web Server : nginx/1.28.1 System : Linux ht2026040333114 6.1.0-10-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.37-1 (2023-07-03) x86_64 User : root ( 0) PHP Version : 8.2.28 Disable Function : passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv,eval,assert,passthru,system,exec,shell_exec,popen,proc_open MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /www/wwwroot/test20.chuangfenglink.xyz/wp-content/themes/woodmart/inc/classes/ |
Upload File : |
<?php
/**
* API integration.
*
* @package woodmart
*/
namespace XTS;
if ( ! defined( 'WOODMART_THEME_DIR' ) ) {
exit( 'No direct script access allowed' );
}
/**
* Communicate with server API (activate, update)
*/
class Api {
/**
* Site token.
*
* @var string
*/
public $token = '';
/**
* Api url.
*
* @var string
*/
public $base_url;
/**
* Request url.
*
* @var string
*/
public $url = '';
/**
* Constructor.
*/
public function __construct() {
$this->base_url = WOODMART_API_URL;
}
/**
* Send HTTP request.
*
* @param string $endpoint Api endpoint.
* @param array $data Additional attributes params.
* @param string $method Method request.
* @param string $base_url Send request to another API.
*
* @return array|\WP_Error
*/
public function call( $endpoint, $data = array(), $method = 'get', $base_url = '' ) {
$headers = $this->get_headers( $method );
switch ( $method ) {
case 'get':
return wp_remote_get(
$this->get_url( $endpoint, $data, $base_url ),
array(
'headers' => $headers,
)
);
case 'post':
return wp_remote_post(
$this->get_url( $endpoint, array(), $base_url ),
array(
'headers' => $headers,
'body' => wp_json_encode( $data ),
'method' => 'POST',
'data_format' => 'body',
)
);
}
}
/**
* Get header request.
*
* @param string $method Request method.
*
* @return array
*/
public function get_headers( $method ) {
$headers = array( 'User-Agent' => 'Woodmart-Theme/' . woodmart_get_theme_info( 'Version' ) );
if ( 'post' === $method ) {
$headers['Content-Type'] = 'application/json; charset=utf-8';
} elseif ( ! empty( $this->token ) ) {
$headers['Authorization'] = 'Bearer ' . $this->token;
}
return $headers;
}
/**
* Get request url.
*
* @param string $endpoint Api endpoint.
* @param array $args Additional attributes params.
* @param string $base_url Send request to another API.
*
* @return string
*/
public function get_url( $endpoint, $args = array(), $base_url = '' ) {
$this->url = ! empty( $base_url ) ? $base_url : $this->base_url;
$this->url .= $endpoint;
if ( ! empty( $args ) ) {
foreach ( $args as $key => $value ) {
$this->add_url_param( $key, $value );
}
}
return $this->url;
}
/**
* Merge additional attribute params in url.
*
* @param string $key Attribute key.
* @param string $value Attribute value.
*
* @return void
*/
public function add_url_param( $key, $value ) {
$this->url = add_query_arg( $key, $value, $this->url );
}
}