Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../modules/cloud-ki...
File: module.php
<?php
[0] Fix | Delete
namespace Elementor\Modules\CloudKitLibrary;
[1] Fix | Delete
[2] Fix | Delete
use Elementor\Modules\CloudKitLibrary\Data\Controller as Cloud_Kits_Controller;
[3] Fix | Delete
use Elementor\Core\Utils\Exceptions;
[4] Fix | Delete
use Elementor\Plugin;
[5] Fix | Delete
use Elementor\Core\Base\Module as BaseModule;
[6] Fix | Delete
use Elementor\Modules\CloudKitLibrary\Connect\Cloud_Kits;
[7] Fix | Delete
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
[8] Fix | Delete
use Elementor\App\Modules\ImportExport\Module as ImportExport_Module;
[9] Fix | Delete
use Elementor\App\Modules\KitLibrary\Connect\Kit_Library as Kit_Library_Api;
[10] Fix | Delete
[11] Fix | Delete
if ( ! defined( 'ABSPATH' ) ) {
[12] Fix | Delete
exit; // Exit if accessed directly.
[13] Fix | Delete
}
[14] Fix | Delete
[15] Fix | Delete
class Module extends BaseModule {
[16] Fix | Delete
[17] Fix | Delete
public function get_name(): string {
[18] Fix | Delete
return 'cloud-kit-library';
[19] Fix | Delete
}
[20] Fix | Delete
[21] Fix | Delete
public function __construct() {
[22] Fix | Delete
parent::__construct();
[23] Fix | Delete
[24] Fix | Delete
add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
[25] Fix | Delete
$connect_module->register_app( 'cloud-kits', Cloud_Kits::get_class_name() );
[26] Fix | Delete
} );
[27] Fix | Delete
[28] Fix | Delete
if ( Plugin::$instance->experiments->is_feature_active( 'cloud-library' ) ) {
[29] Fix | Delete
add_filter( 'elementor/export/kit/export-result', [ $this, 'handle_export_kit_result' ], 10, 5 );
[30] Fix | Delete
add_filter( 'elementor/import/kit/result/cloud', [ $this, 'handle_import_kit_from_cloud' ], 10, 1 );
[31] Fix | Delete
add_filter( 'elementor/import/kit_thumbnail', [ $this, 'handle_import_kit_thumbnail' ], 10, 3 );
[32] Fix | Delete
[33] Fix | Delete
add_action( 'elementor/kit_library/registered', function () {
[34] Fix | Delete
Plugin::$instance->data_manager_v2->register_controller( new Cloud_Kits_Controller() );
[35] Fix | Delete
} );
[36] Fix | Delete
}
[37] Fix | Delete
}
[38] Fix | Delete
[39] Fix | Delete
public function handle_import_kit_thumbnail( $thumbnail, $kit_id, $referrer ) {
[40] Fix | Delete
if ( ImportExport_Module::REFERRER_KIT_LIBRARY === $referrer ) {
[41] Fix | Delete
[42] Fix | Delete
if ( empty( $kit_id ) ) {
[43] Fix | Delete
return '';
[44] Fix | Delete
}
[45] Fix | Delete
[46] Fix | Delete
$api = new Kit_Library_Api();
[47] Fix | Delete
$kit = $api->get_by_id( $kit_id );
[48] Fix | Delete
[49] Fix | Delete
if ( is_wp_error( $kit ) ) {
[50] Fix | Delete
return '';
[51] Fix | Delete
}
[52] Fix | Delete
[53] Fix | Delete
return $kit->thumbnail;
[54] Fix | Delete
}
[55] Fix | Delete
[56] Fix | Delete
if ( ImportExport_Module::REFERRER_CLOUD === $referrer ) {
[57] Fix | Delete
if ( empty( $kit_id ) ) {
[58] Fix | Delete
return '';
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
$kit = self::get_app()->get_kit( [ 'id' => $kit_id ] );
[62] Fix | Delete
[63] Fix | Delete
if ( is_wp_error( $kit ) ) {
[64] Fix | Delete
return '';
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
return $kit['thumbnailUrl'] ?? '';
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
return $thumbnail;
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
public function handle_export_kit_result( $result, $source, $export, $settings, $file ) {
[74] Fix | Delete
if ( ImportExport_Module::EXPORT_SOURCE_CLOUD !== $source ) {
[75] Fix | Delete
return $result;
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
unset( $result['file'] );
[79] Fix | Delete
[80] Fix | Delete
$raw_screen_shot = base64_decode( substr( $settings['screenShotBlob'], strlen( 'data:image/png;base64,' ) ) );
[81] Fix | Delete
$title = $export['manifest']['title'];
[82] Fix | Delete
$description = $export['manifest']['description'];
[83] Fix | Delete
[84] Fix | Delete
$kit = self::get_app()->create_kit(
[85] Fix | Delete
$title,
[86] Fix | Delete
$description,
[87] Fix | Delete
$file,
[88] Fix | Delete
$raw_screen_shot,
[89] Fix | Delete
$settings['include'],
[90] Fix | Delete
);
[91] Fix | Delete
[92] Fix | Delete
if ( is_wp_error( $kit ) ) {
[93] Fix | Delete
return $kit;
[94] Fix | Delete
}
[95] Fix | Delete
[96] Fix | Delete
$result['kit'] = $kit;
[97] Fix | Delete
[98] Fix | Delete
return $result;
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
public function handle_import_kit_from_cloud( $args ) {
[102] Fix | Delete
$kit = self::get_app()->get_kit( [
[103] Fix | Delete
'id' => $args['kit_id'],
[104] Fix | Delete
] );
[105] Fix | Delete
[106] Fix | Delete
if ( is_wp_error( $kit ) ) {
[107] Fix | Delete
return $kit;
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
if ( empty( $kit['downloadUrl'] ) ) {
[111] Fix | Delete
throw new \Error( ImportExport_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
[112] Fix | Delete
}
[113] Fix | Delete
[114] Fix | Delete
return [
[115] Fix | Delete
'file_name' => self::get_remote_kit_zip( $kit['downloadUrl'] ),
[116] Fix | Delete
'referrer' => ImportExport_Module::REFERRER_CLOUD,
[117] Fix | Delete
'file_url' => $kit['downloadUrl'],
[118] Fix | Delete
'kit' => $kit,
[119] Fix | Delete
];
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
public static function get_remote_kit_zip( $url ) {
[123] Fix | Delete
$remote_zip_request = wp_safe_remote_get( $url );
[124] Fix | Delete
[125] Fix | Delete
if ( is_wp_error( $remote_zip_request ) ) {
[126] Fix | Delete
Plugin::$instance->logger->get_logger()->error( $remote_zip_request->get_error_message() );
[127] Fix | Delete
throw new \Error( ImportExport_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
[128] Fix | Delete
}
[129] Fix | Delete
[130] Fix | Delete
if ( 200 !== $remote_zip_request['response']['code'] ) {
[131] Fix | Delete
Plugin::$instance->logger->get_logger()->error( $remote_zip_request['response']['message'] );
[132] Fix | Delete
throw new \Error( ImportExport_Module::KIT_LIBRARY_ERROR_KEY ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
[133] Fix | Delete
}
[134] Fix | Delete
[135] Fix | Delete
return Plugin::$instance->uploads_manager->create_temp_file( $remote_zip_request['body'], 'kit.zip' );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
public static function get_app(): Cloud_Kits {
[139] Fix | Delete
$cloud_kits_app = Plugin::$instance->common->get_component( 'connect' )->get_app( 'cloud-kits' );
[140] Fix | Delete
[141] Fix | Delete
if ( ! $cloud_kits_app ) {
[142] Fix | Delete
$error_message = esc_html__( 'Cloud-Kits is not instantiated.', 'elementor' );
[143] Fix | Delete
[144] Fix | Delete
throw new \Exception( $error_message, Exceptions::FORBIDDEN ); // phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped
[145] Fix | Delete
}
[146] Fix | Delete
[147] Fix | Delete
return $cloud_kits_app;
[148] Fix | Delete
}
[149] Fix | Delete
}
[150] Fix | Delete
[151] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function