HEX
Server: nginx/1.24.0
System: Linux mail.365consultoria.com 6.8.0-1057-oracle #58~22.04.1-Ubuntu SMP Tue Jun 30 18:20:56 UTC 2026 aarch64
User: www (1002)
PHP: 7.4.33
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/laet.adv.br/wp-content/themes/betheme/functions/importer/class-mfn-importer-api.php
<?php
/**
 * Install pre-built websites remote API
 *
 * @package Betheme
 * @author Muffin group
 * @link https://muffingroup.com
 */

if ( ! defined( 'ABSPATH' ) ){
	exit;
}

class Mfn_Importer_API extends Mfn_API {

	protected $code = '';
	protected $demo = '';

	protected $path_be	= '';
	protected $path_websites	= '';
	protected $path_demo = '';

	/**
	 * The constructor
	 */
	public function __construct( $demo = false ){

		if( ! $demo ){
			return false;
		}

		$this->code = mfn_get_purchase_code();
		$this->demo = $demo;

		$upload_dir = wp_upload_dir();
		$this->path_be = wp_normalize_path( $upload_dir['basedir'] .'/betheme' );
		$this->path_websites = wp_normalize_path( $this->path_be .'/websites' );

		$this->make_dir();
	}

	/**
	 * Directories creation
	 */
	protected function make_dir(){

		$this->path_demo = wp_normalize_path( $this->path_websites .'/'. $this->demo );

		if( ! file_exists( $this->path_be ) ){
			wp_mkdir_p( $this->path_be );
		}

		if( ! file_exists( $this->path_websites ) ){
			wp_mkdir_p( $this->path_websites );
		}

		if( ! file_exists( $this->path_demo ) ){
			wp_mkdir_p( $this->path_demo );
		}
	}

	/**
	 * Delete temporary directory
	 */
	public function delete_temp_dir(){

		// filesystem
		$wp_filesystem = Mfn_Helper::filesystem();

		// director is located outside wp uploads dir
		$upload_dir = wp_upload_dir();
		if( false === strpos( $this->path_demo, $upload_dir['basedir'] ) ){
			return false;
		}

		$wp_filesystem->delete( $this->path_demo, true );
	}

	/**
	 * Remote get demo
	 */
	public function remote_get_demo(){

		$args = array(
			'code' => $this->code,
			'demo' => $this->demo,
		);

		if( mfn_is_hosted() ){
			$args[ 'ish' ] = mfn_get_ish();
		}

		$url = add_query_arg( $args, $this->get_url( 'websites_download' ) );

		$args = array(
			'user-agent' 	=> 'WordPress/'. get_bloginfo( 'version' ) .'; '. network_site_url(),
			'timeout' 		=> 30,
		);

		$response = wp_remote_get( $url, $args );

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

		$body = wp_remote_retrieve_body( $response );

		// remote get fallback
		if( empty( $body ) ){
			if( function_exists( 'ini_get' ) && ini_get( 'allow_url_fopen' ) ){
				$body = @file_get_contents( $url );
			}
		}

		if( empty( $body ) ){
			return new WP_Error( 'error_download', __( 'The package could not be downloaded.', 'mfn-opts' ) );
		}

		if( $json = json_decode( $body, true ) ){
			if( isset( $json['error'] ) ){
				return new WP_Error( 'invalid_response', $json['error'] );
			}
		}

		// filesystem
		$wp_filesystem = Mfn_Helper::filesystem();

		$path_zip = wp_normalize_path( $this->path_demo .'/'. $this->demo .'.zip' );
		$path_unzip = wp_normalize_path( $this->path_demo .'/'. $this->demo );

		if( ! $wp_filesystem->put_contents( $path_zip, $body, FS_CHMOD_FILE ) ){

			// put_contents fallback
			@unlink( $path_zip );
			$fp = @fopen( $path_zip, 'w' );
			$fwrite = @fwrite( $fp, $body );
			@fclose( $fp );
			if( false === $fwrite ){
				return new WP_Error( 'error_fs', __( 'WordPress filesystem error.', 'mfn-opts' ) );
			}

		}

		$unzip = unzip_file( $path_zip, $this->path_demo );
		if( is_wp_error( $unzip ) ){
			return new WP_Error( 'error_unzip', __( 'The package could not be unziped.', 'mfn-opts' ) );
		}

		if( ! is_dir( $path_unzip ) ) {
			return new WP_Error( 'error_folder', sprintf( __( 'Demo data folder does not exist (%s).', 'mfn-opts' ), $path_unzip ) );
		}

		return $path_unzip;
	}

}