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
$this->register_app();
[32] Fix | Delete
[33] Fix | Delete
add_action( 'elementor/init', function () {
[34] Fix | Delete
$this->set_cloud_library_settings();
[35] Fix | Delete
}, 12 /** After the initiation of the connect cloud library */ );
[36] Fix | Delete
[37] Fix | Delete
add_filter( 'elementor/editor/localize_settings', function ( $settings ) {
[38] Fix | Delete
return $this->localize_settings( $settings );
[39] Fix | Delete
}, 11 /** After Elementor Core */ );
[40] Fix | Delete
[41] Fix | Delete
add_filter( 'elementor/render_mode/module', function( $module_name ) {
[42] Fix | Delete
$render_mode_manager = \Elementor\Plugin::$instance->frontend->render_mode_manager;
[43] Fix | Delete
[44] Fix | Delete
if ( $render_mode_manager ) {
[45] Fix | Delete
$current_render_mode = $render_mode_manager->get_current();
[46] Fix | Delete
[47] Fix | Delete
if ( $current_render_mode instanceof \Elementor\Modules\CloudLibrary\Render_Mode_Preview ) {
[48] Fix | Delete
return 'cloud-library';
[49] Fix | Delete
}
[50] Fix | Delete
}
[51] Fix | Delete
[52] Fix | Delete
return $module_name;
[53] Fix | Delete
}, 12);
[54] Fix | Delete
[55] Fix | Delete
if ( $this->is_screenshot_proxy_mode( $_GET ) ) { // phpcs:ignore -- Checking nonce inside the method.
[56] Fix | Delete
echo $this->get_proxy_data( htmlspecialchars( $_GET['href'] ) ); // phpcs:ignore -- Nonce was checked on the above method
[57] Fix | Delete
die;
[58] Fix | Delete
}
[59] Fix | Delete
}
[60] Fix | Delete
[61] Fix | Delete
public function get_proxy_data( $url ) {
[62] Fix | Delete
$response = wp_safe_remote_get( $url );
[63] Fix | Delete
[64] Fix | Delete
if ( is_wp_error( $response ) ) {
[65] Fix | Delete
return '';
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
$content_type = wp_remote_retrieve_headers( $response )->offsetGet( 'content-type' );
[69] Fix | Delete
[70] Fix | Delete
header( 'content-type: ' . $content_type );
[71] Fix | Delete
[72] Fix | Delete
return wp_remote_retrieve_body( $response );
[73] Fix | Delete
}
[74] Fix | Delete
[75] Fix | Delete
public function localize_settings( $settings ) {
[76] Fix | Delete
if ( isset( $settings['i18n'] ) ) {
[77] Fix | Delete
$settings['i18n']['folder'] = esc_html__( 'Folder', 'elementor' );
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$settings['library']['doc_types'] = $this->get_document_types();
[81] Fix | Delete
[82] Fix | Delete
return $settings;
[83] Fix | Delete
}
[84] Fix | Delete
[85] Fix | Delete
private function register_experiments() {
[86] Fix | Delete
Plugin::$instance->experiments->add_feature( [
[87] Fix | Delete
'name' => $this->get_name(),
[88] Fix | Delete
'title' => esc_html__( 'Cloud Library', 'elementor' ),
[89] Fix | Delete
'release_status' => ExperimentsManager::RELEASE_STATUS_STABLE,
[90] Fix | Delete
'default' => ExperimentsManager::STATE_ACTIVE,
[91] Fix | Delete
'hidden' => true,
[92] Fix | Delete
'mutable' => false,
[93] Fix | Delete
'new_site' => [
[94] Fix | Delete
'always_active' => true,
[95] Fix | Delete
'minimum_installation_version' => '3.32.0',
[96] Fix | Delete
],
[97] Fix | Delete
] );
[98] Fix | Delete
}
[99] Fix | Delete
[100] Fix | Delete
private function register_app() {
[101] Fix | Delete
add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
[102] Fix | Delete
$connect_module->register_app( 'cloud-library', Cloud_Library::get_class_name() );
[103] Fix | Delete
} );
[104] Fix | Delete
[105] Fix | Delete
add_action( 'elementor/frontend/render_mode/register', [ $this, 'register_render_mode' ] );
[106] Fix | Delete
[107] Fix | Delete
add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) {
[108] Fix | Delete
$documents_manager->register_document_type(
[109] Fix | Delete
Documents\Cloud_Template_Preview::TYPE,
[110] Fix | Delete
Documents\Cloud_Template_Preview::get_class_full_name()
[111] Fix | Delete
);
[112] Fix | Delete
});
[113] Fix | Delete
}
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* @param Render_Mode_Manager $manager
[117] Fix | Delete
*
[118] Fix | Delete
* @throws \Exception If render mode registration fails.
[119] Fix | Delete
*/
[120] Fix | Delete
public function register_render_mode( Render_Mode_Manager $manager ) {
[121] Fix | Delete
$manager->register_render_mode( Render_Mode_Preview::class );
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
private function set_cloud_library_settings() {
[125] Fix | Delete
if ( ! Plugin::$instance->common ) {
[126] Fix | Delete
return;
[127] Fix | Delete
}
[128] Fix | Delete
[129] Fix | Delete
/** @var ConnectModule $connect */
[130] Fix | Delete
$connect = Plugin::$instance->common->get_component( 'connect' );
[131] Fix | Delete
[132] Fix | Delete
/** @var Library $library */
[133] Fix | Delete
$library = $connect->get_app( 'library' );
[134] Fix | Delete
[135] Fix | Delete
if ( ! $library ) {
[136] Fix | Delete
return;
[137] Fix | Delete
}
[138] Fix | Delete
[139] Fix | Delete
Plugin::$instance->app->set_settings( 'cloud-library', [
[140] Fix | Delete
'library_connect_url' => esc_url( $library->get_admin_url( 'authorize', [
[141] Fix | Delete
'utm_source' => 'template-library',
[142] Fix | Delete
'utm_medium' => 'wp-dash',
[143] Fix | Delete
'utm_campaign' => 'library-connect',
[144] Fix | Delete
'utm_content' => 'cloud-library',
[145] Fix | Delete
'source' => 'cloud-library',
[146] Fix | Delete
] ) ),
[147] Fix | Delete
'library_connect_title_copy' => esc_html__( 'Connect to your Elementor account', 'elementor' ),
[148] Fix | Delete
'library_connect_sub_title_copy' => esc_html__( 'Then you can find all your templates in one convenient library.', 'elementor' ),
[149] Fix | Delete
'library_connect_button_copy' => esc_html__( 'Connect', 'elementor' ),
[150] Fix | Delete
] );
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
private function get_document_types() {
[154] Fix | Delete
$document_types = Plugin::$instance->documents->get_document_types( [
[155] Fix | Delete
'show_in_library' => true,
[156] Fix | Delete
] );
[157] Fix | Delete
[158] Fix | Delete
$data = [];
[159] Fix | Delete
[160] Fix | Delete
foreach ( $document_types as $name => $document_type ) {
[161] Fix | Delete
$data[ $name ] = $document_type::get_title();
[162] Fix | Delete
}
[163] Fix | Delete
[164] Fix | Delete
return $data;
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
public function print_content() {
[168] Fix | Delete
if ( ! $this->print_preview_callback ) {
[169] Fix | Delete
$this->print_preview_callback = [ $this, 'print_thumbnail_preview_callback' ];
[170] Fix | Delete
}
[171] Fix | Delete
[172] Fix | Delete
call_user_func( $this->print_preview_callback );
[173] Fix | Delete
}
[174] Fix | Delete
[175] Fix | Delete
private function print_thumbnail_preview_callback() {
[176] Fix | Delete
$doc = Plugin::$instance->documents->get_current();
[177] Fix | Delete
[178] Fix | Delete
if ( ! $doc ) {
[179] Fix | Delete
$render_mode = Plugin::$instance->frontend->render_mode_manager->get_current();
[180] Fix | Delete
if ( $render_mode instanceof Render_Mode_Preview ) {
[181] Fix | Delete
$doc = $render_mode->get_document();
[182] Fix | Delete
}
[183] Fix | Delete
}
[184] Fix | Delete
[185] Fix | Delete
if ( ! $doc ) {
[186] Fix | Delete
echo '<div class="elementor-alert elementor-alert-danger">' . esc_html__( 'Document not found for preview.', 'elementor' ) . '</div>';
[187] Fix | Delete
return;
[188] Fix | Delete
}
[189] Fix | Delete
[190] Fix | Delete
Plugin::$instance->documents->switch_to_document( $doc );
[191] Fix | Delete
[192] Fix | Delete
$content = $doc->get_content( true );
[193] Fix | Delete
[194] Fix | Delete
echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
[195] Fix | Delete
}
[196] Fix | Delete
[197] Fix | Delete
[198] Fix | Delete
protected function is_screenshot_proxy_mode( array $query_params ) {
[199] Fix | Delete
$is_proxy = isset( $query_params['screenshot_proxy'] );
[200] Fix | Delete
[201] Fix | Delete
if ( $is_proxy ) {
[202] Fix | Delete
if ( ! wp_verify_nonce( $query_params['nonce'], 'screenshot-proxy' ) ) {
[203] Fix | Delete
// WP >= 6.2-alpha
[204] Fix | Delete
if ( class_exists( '\WpOrg\Requests\Exception\Http\Status403' ) ) {
[205] Fix | Delete
throw new \WpOrg\Requests\Exception\Http\Status403();
[206] Fix | Delete
} else {
[207] Fix | Delete
throw new \Requests_Exception_HTTP_403();
[208] Fix | Delete
}
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
if ( ! $query_params['href'] ) {
[212] Fix | Delete
// WP >= 6.2-alpha
[213] Fix | Delete
if ( class_exists( '\WpOrg\Requests\Exception\Http\Status400' ) ) {
[214] Fix | Delete
throw new \WpOrg\Requests\Exception\Http\Status400();
[215] Fix | Delete
} else {
[216] Fix | Delete
throw new \Requests_Exception_HTTP_400();
[217] Fix | Delete
}
[218] Fix | Delete
}
[219] Fix | Delete
}
[220] Fix | Delete
[221] Fix | Delete
return $is_proxy;
[222] Fix | Delete
}
[223] Fix | Delete
}
[224] Fix | Delete
[225] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function