Edit File by line
/home/zeestwma/richards.../wp-conte.../plugins/elemento.../modules/cloud-li...
File: module.php
<?php
[0] Fix | Delete
namespace Elementor\Modules\CloudLibrary;
[1] Fix | Delete
[2] Fix | Delete
use Elementor\Core\Base\Module as BaseModule;
[3] Fix | Delete
use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
[4] Fix | Delete
use Elementor\Core\Documents_Manager;
[5] Fix | Delete
use Elementor\Core\Frontend\Render_Mode_Manager;
[6] Fix | Delete
use Elementor\Modules\CloudLibrary\Connect\Cloud_Library;
[7] Fix | Delete
use Elementor\Core\Common\Modules\Connect\Apps\Library;
[8] Fix | Delete
use Elementor\Core\Experiments\Manager as ExperimentsManager;
[9] Fix | Delete
use Elementor\Plugin;
[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
/**
[18] Fix | Delete
* @var callable
[19] Fix | Delete
*/
[20] Fix | Delete
protected $print_preview_callback;
[21] Fix | Delete
[22] Fix | Delete
public function get_name(): string {
[23] Fix | Delete
return 'cloud-library';
[24] Fix | Delete
}
[25] Fix | Delete
[26] Fix | Delete
public function __construct() {
[27] Fix | Delete
parent::__construct();
[28] Fix | Delete
[29] Fix | Delete
$this->register_experiments();
[30] Fix | Delete
[31] Fix | Delete
if ( Plugin::$instance->experiments->is_feature_active( $this->get_name() ) ) {
[32] Fix | Delete
$this->register_app();
[33] Fix | Delete
[34] Fix | Delete
add_action( 'elementor/init', function () {
[35] Fix | Delete
$this->set_cloud_library_settings();
[36] Fix | Delete
}, 12 /** After the initiation of the connect cloud library */ );
[37] Fix | Delete
[38] Fix | Delete
add_filter( 'elementor/editor/localize_settings', function ( $settings ) {
[39] Fix | Delete
return $this->localize_settings( $settings );
[40] Fix | Delete
}, 11 /** After Elementor Core */ );
[41] Fix | Delete
[42] Fix | Delete
add_filter( 'elementor/render_mode/module', function( $module_name ) {
[43] Fix | Delete
$render_mode_manager = \Elementor\Plugin::$instance->frontend->render_mode_manager;
[44] Fix | Delete
[45] Fix | Delete
if ( $render_mode_manager && $render_mode_manager->get_current() instanceof \Elementor\Modules\CloudLibrary\Render_Mode_Preview ) {
[46] Fix | Delete
return 'cloud-library';
[47] Fix | Delete
}
[48] Fix | Delete
[49] Fix | Delete
return $module_name;
[50] Fix | Delete
}, 12);
[51] Fix | Delete
[52] Fix | Delete
if ( $this->is_screenshot_proxy_mode( $_GET ) ) { // phpcs:ignore -- Checking nonce inside the method.
[53] Fix | Delete
echo $this->get_proxy_data( htmlspecialchars( $_GET['href'] ) ); // phpcs:ignore -- Nonce was checked on the above method
[54] Fix | Delete
die;
[55] Fix | Delete
}
[56] Fix | Delete
}
[57] Fix | Delete
}
[58] Fix | Delete
[59] Fix | Delete
public function get_proxy_data( $url ) {
[60] Fix | Delete
$response = wp_safe_remote_get( utf8_decode( $url ) );
[61] Fix | Delete
[62] Fix | Delete
if ( is_wp_error( $response ) ) {
[63] Fix | Delete
return '';
[64] Fix | Delete
}
[65] Fix | Delete
[66] Fix | Delete
$content_type = wp_remote_retrieve_headers( $response )->offsetGet( 'content-type' );
[67] Fix | Delete
[68] Fix | Delete
header( 'content-type: ' . $content_type );
[69] Fix | Delete
[70] Fix | Delete
return wp_remote_retrieve_body( $response );
[71] Fix | Delete
}
[72] Fix | Delete
[73] Fix | Delete
public function localize_settings( $settings ) {
[74] Fix | Delete
if ( isset( $settings['i18n'] ) ) {
[75] Fix | Delete
$settings['i18n']['folder'] = esc_html__( 'Folder', 'elementor' );
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
$settings['library']['doc_types'] = $this->get_document_types();
[79] Fix | Delete
[80] Fix | Delete
return $settings;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
private function register_experiments() {
[84] Fix | Delete
Plugin::$instance->experiments->add_feature( [
[85] Fix | Delete
'name' => $this->get_name(),
[86] Fix | Delete
'title' => esc_html__( 'Cloud Library', 'elementor' ),
[87] Fix | Delete
'description' => esc_html__( 'Cloud Templates and Website Templates empowers you to save and manage design elements across all your projects. This feature is associated and connected to your Elementor Pro account and can be accessed from any website associated with your account.', 'elementor' ),
[88] Fix | Delete
'release_status' => ExperimentsManager::RELEASE_STATUS_BETA,
[89] Fix | Delete
'default' => ExperimentsManager::STATE_ACTIVE,
[90] Fix | Delete
] );
[91] Fix | Delete
}
[92] Fix | Delete
[93] Fix | Delete
private function register_app() {
[94] Fix | Delete
add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
[95] Fix | Delete
$connect_module->register_app( 'cloud-library', Cloud_Library::get_class_name() );
[96] Fix | Delete
} );
[97] Fix | Delete
[98] Fix | Delete
add_action( 'elementor/frontend/render_mode/register', [ $this, 'register_render_mode' ] );
[99] Fix | Delete
[100] Fix | Delete
add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) {
[101] Fix | Delete
$documents_manager->register_document_type(
[102] Fix | Delete
Documents\Cloud_Template_Preview::TYPE,
[103] Fix | Delete
Documents\Cloud_Template_Preview::get_class_full_name()
[104] Fix | Delete
);
[105] Fix | Delete
});
[106] Fix | Delete
}
[107] Fix | Delete
[108] Fix | Delete
/**
[109] Fix | Delete
* @param Render_Mode_Manager $manager
[110] Fix | Delete
*
[111] Fix | Delete
* @throws \Exception
[112] Fix | Delete
*/
[113] Fix | Delete
public function register_render_mode( Render_Mode_Manager $manager ) {
[114] Fix | Delete
$manager->register_render_mode( Render_Mode_Preview::class );
[115] Fix | Delete
}
[116] Fix | Delete
[117] Fix | Delete
private function set_cloud_library_settings() {
[118] Fix | Delete
if ( ! Plugin::$instance->common ) {
[119] Fix | Delete
return;
[120] Fix | Delete
}
[121] Fix | Delete
[122] Fix | Delete
/** @var ConnectModule $connect */
[123] Fix | Delete
$connect = Plugin::$instance->common->get_component( 'connect' );
[124] Fix | Delete
[125] Fix | Delete
/** @var Library $library */
[126] Fix | Delete
$library = $connect->get_app( 'library' );
[127] Fix | Delete
[128] Fix | Delete
if ( ! $library ) {
[129] Fix | Delete
return;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
Plugin::$instance->app->set_settings( 'cloud-library', [
[133] Fix | Delete
'library_connect_url' => esc_url( $library->get_admin_url( 'authorize', [
[134] Fix | Delete
'utm_source' => 'template-library',
[135] Fix | Delete
'utm_medium' => 'wp-dash',
[136] Fix | Delete
'utm_campaign' => 'library-connect',
[137] Fix | Delete
'utm_content' => 'cloud-library',
[138] Fix | Delete
'source' => 'cloud-library',
[139] Fix | Delete
] ) ),
[140] Fix | Delete
'library_connect_title_copy' => esc_html__( 'Connect to your Elementor account', 'elementor' ),
[141] Fix | Delete
'library_connect_sub_title_copy' => esc_html__( 'Then you can find all your templates in one convenient library.', 'elementor' ),
[142] Fix | Delete
'library_connect_button_copy' => esc_html__( 'Connect', 'elementor' ),
[143] Fix | Delete
] );
[144] Fix | Delete
}
[145] Fix | Delete
[146] Fix | Delete
private function get_document_types() {
[147] Fix | Delete
$document_types = Plugin::$instance->documents->get_document_types( [
[148] Fix | Delete
'show_in_library' => true,
[149] Fix | Delete
] );
[150] Fix | Delete
[151] Fix | Delete
$data = [];
[152] Fix | Delete
[153] Fix | Delete
foreach ( $document_types as $name => $document_type ) {
[154] Fix | Delete
$data[ $name ] = $document_type::get_title();
[155] Fix | Delete
}
[156] Fix | Delete
[157] Fix | Delete
return $data;
[158] Fix | Delete
}
[159] Fix | Delete
[160] Fix | Delete
public function print_content() {
[161] Fix | Delete
if ( ! $this->print_preview_callback ) {
[162] Fix | Delete
$this->print_preview_callback = [ $this, 'print_thumbnail_preview_callback' ];
[163] Fix | Delete
}
[164] Fix | Delete
[165] Fix | Delete
call_user_func( $this->print_preview_callback );
[166] Fix | Delete
}
[167] Fix | Delete
[168] Fix | Delete
private function print_thumbnail_preview_callback() {
[169] Fix | Delete
$doc = Plugin::$instance->documents->get_current();
[170] Fix | Delete
[171] Fix | Delete
// PHPCS - should not be escaped.
[172] Fix | Delete
echo Plugin::$instance->frontend->get_builder_content_for_display( $doc->get_main_id(), true ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[173] Fix | Delete
[174] Fix | Delete
wp_delete_post( $doc->get_main_id(), true );
[175] Fix | Delete
}
[176] Fix | Delete
[177] Fix | Delete
[178] Fix | Delete
protected function is_screenshot_proxy_mode( array $query_params ) {
[179] Fix | Delete
$is_proxy = isset( $query_params['screenshot_proxy'] );
[180] Fix | Delete
[181] Fix | Delete
if ( $is_proxy ) {
[182] Fix | Delete
if ( ! wp_verify_nonce( $query_params['nonce'], 'screenshot-proxy' ) ) {
[183] Fix | Delete
// WP >= 6.2-alpha
[184] Fix | Delete
if ( class_exists( '\WpOrg\Requests\Exception\Http\Status403' ) ) {
[185] Fix | Delete
throw new \WpOrg\Requests\Exception\Http\Status403();
[186] Fix | Delete
} else {
[187] Fix | Delete
throw new \Requests_Exception_HTTP_403();
[188] Fix | Delete
}
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
if ( ! $query_params['href'] ) {
[192] Fix | Delete
// WP >= 6.2-alpha
[193] Fix | Delete
if ( class_exists( '\WpOrg\Requests\Exception\Http\Status400' ) ) {
[194] Fix | Delete
throw new \WpOrg\Requests\Exception\Http\Status400();
[195] Fix | Delete
} else {
[196] Fix | Delete
throw new \Requests_Exception_HTTP_400();
[197] Fix | Delete
}
[198] Fix | Delete
}
[199] Fix | Delete
}
[200] Fix | Delete
[201] Fix | Delete
return $is_proxy;
[202] Fix | Delete
}
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function