HEX
Server: LiteSpeed
System: Linux mail.aatilis.ir 6.8.0-101-generic #101-Ubuntu SMP PREEMPT_DYNAMIC Mon Feb 9 10:15:05 UTC 2026 x86_64
User: www (1000)
PHP: 8.3.30
Disabled: 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
Upload Files
File: /www/wwwroot/soqatland.com/wp-content/themes/woodmart/inc/classes/class-api.php
<?php
/**
 * API integration.
 *
 * @package xts
 */

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 );
	}
}