PluginProbe
Elementor Website Builder – more than just a page builder / 3.28.4
Elementor Website Builder – more than just a page builder v3.28.4
4.3.0-beta2 4.3.0-beta1 4.2.4 4.2.3 4.2.2 4.2.1 4.2.0 4.1.5 4.2.0-beta2 4.2.0-dev2 4.2.0-beta1 4.1.4 4.1.3 4.1.2 4.1.1 4.1.0 4.1.0-beta3 4.1.0-dev3 4.0.9 4.1.0-beta2 4.1.0-dev2 4.0.8 4.1.0-beta1 4.1.0-dev1 4.0.7 All 451 releases
← All changes | modules/cloud-library/module.php +18 -147 4.1.0-dev33.28.4 View file →
@@ -2,10 +2,8 @@
2 2 namespace Elementor\Modules\CloudLibrary;
3 3
4 4 use Elementor\Core\Base\Module as BaseModule;
5 5 use Elementor\Core\Common\Modules\Connect\Module as ConnectModule;
6 -use Elementor\Core\Documents_Manager;
7 -use Elementor\Core\Frontend\Render_Mode_Manager;
8 6 use Elementor\Modules\CloudLibrary\Connect\Cloud_Library;
9 7 use Elementor\Core\Common\Modules\Connect\Apps\Library;
10 8 use Elementor\Core\Experiments\Manager as ExperimentsManager;
11 9 use Elementor\Plugin;
@@ -15,13 +13,8 @@
15 13 }
16 14
17 15 class Module extends BaseModule {
18 16
19 - /**
20 - * @var callable
21 - */
22 - protected $print_preview_callback;
23 -
24 17 public function get_name(): string {
25 18 return 'cloud-library';
26 19 }
27 20
@@ -27,86 +20,36 @@
27 20
28 21 public function __construct() {
29 22 parent::__construct();
30 23
31 - $this->register_app();
24 + $this->register_experiment();
32 25
33 - add_action( 'elementor/init', function () {
34 - $this->set_cloud_library_settings();
35 - }, 12 /** After the initiation of the connect cloud library */ );
26 + if ( Plugin::$instance->experiments->is_feature_active( $this->get_name() ) ) {
27 + $this->register_app();
36 28
37 - add_filter( 'elementor/editor/localize_settings', function ( $settings ) {
38 - return $this->localize_settings( $settings );
39 - }, 11 /** After Elementor Core */ );
40 -
41 - add_filter( 'elementor/render_mode/module', function( $module_name ) {
42 - $render_mode_manager = \Elementor\Plugin::$instance->frontend->render_mode_manager;
43 -
44 - if ( $render_mode_manager ) {
45 - $current_render_mode = $render_mode_manager->get_current();
46 -
47 - if ( $current_render_mode instanceof \Elementor\Modules\CloudLibrary\Render_Mode_Preview ) {
48 - return 'cloud-library';
49 - }
50 - }
51 -
52 - return $module_name;
53 - }, 12);
54 -
55 - if ( $this->is_screenshot_proxy_mode( $_GET ) ) { // phpcs:ignore -- Checking nonce inside the method.
56 - echo $this->get_proxy_data( htmlspecialchars( $_GET['href'] ) ); // phpcs:ignore -- Nonce was checked on the above method
57 - die;
29 + add_action( 'elementor/init', function () {
30 + $this->set_cloud_library_settings();
31 + }, 12 /** After the initiation of the connect cloud library */ );
58 32 }
59 33 }
60 34
61 - public function get_proxy_data( $url ) {
62 - $response = wp_safe_remote_get( $url );
63 -
64 - if ( is_wp_error( $response ) ) {
65 - return '';
66 - }
67 -
68 - $content_type = wp_remote_retrieve_headers( $response )->offsetGet( 'content-type' );
69 -
70 - header( 'content-type: ' . $content_type );
71 -
72 - return wp_remote_retrieve_body( $response );
35 + private function register_experiment() {
36 + Plugin::$instance->experiments->add_feature( [
37 + 'name' => $this->get_name(),
38 + 'title' => esc_html__( 'Cloud Library', 'elementor' ),
39 + 'description' => esc_html__( 'Enable Cloud Library.', 'elementor' ),
40 + 'release_status' => ExperimentsManager::RELEASE_STATUS_DEV,
41 + 'default' => ExperimentsManager::STATE_INACTIVE,
42 + 'hidden' => true,
43 + ] );
73 44 }
74 45
75 - public function localize_settings( $settings ) {
76 - if ( isset( $settings['i18n'] ) ) {
77 - $settings['i18n']['folder'] = esc_html__( 'Folder', 'elementor' );
78 - }
79 -
80 - $settings['library']['doc_types'] = $this->get_document_types();
81 -
82 - return $settings;
83 - }
84 -
85 46 private function register_app() {
86 47 add_action( 'elementor/connect/apps/register', function ( ConnectModule $connect_module ) {
87 48 $connect_module->register_app( 'cloud-library', Cloud_Library::get_class_name() );
88 49 } );
89 -
90 - add_action( 'elementor/frontend/render_mode/register', [ $this, 'register_render_mode' ] );
91 -
92 - add_action( 'elementor/documents/register', function ( Documents_Manager $documents_manager ) {
93 - $documents_manager->register_document_type(
94 - Documents\Cloud_Template_Preview::TYPE,
95 - Documents\Cloud_Template_Preview::get_class_full_name()
96 - );
97 - });
98 50 }
99 51
100 - /**
101 - * @param Render_Mode_Manager $manager
102 - *
103 - * @throws \Exception If render mode registration fails.
104 - */
105 - public function register_render_mode( Render_Mode_Manager $manager ) {
106 - $manager->register_render_mode( Render_Mode_Preview::class );
107 - }
108 -
109 52 private function set_cloud_library_settings() {
110 53 if ( ! Plugin::$instance->common ) {
111 54 return;
112 55 }
@@ -126,83 +69,11 @@
126 69 'utm_source' => 'template-library',
127 70 'utm_medium' => 'wp-dash',
128 71 'utm_campaign' => 'library-connect',
129 72 'utm_content' => 'cloud-library',
130 - 'source' => 'cloud-library',
131 73 ] ) ),
132 - 'library_connect_title_copy' => esc_html__( 'Connect to your Elementor account', 'elementor' ),
133 - 'library_connect_sub_title_copy' => esc_html__( 'Then you can find all your templates in one convenient library.', 'elementor' ),
134 - 'library_connect_button_copy' => esc_html__( 'Connect', 'elementor' ),
74 + 'library_connect_title' => esc_html__( 'Connect', 'elementor' ),
75 + 'library_connect_sub_title' => esc_html__( 'Sub Title', 'elementor' ),
76 + 'library_connect_button_text' => esc_html__( 'Connect', 'elementor' ),
135 77 ] );
136 - }
137 -
138 - private function get_document_types() {
139 - $document_types = Plugin::$instance->documents->get_document_types( [
140 - 'show_in_library' => true,
141 - ] );
142 -
143 - $data = [];
144 -
145 - foreach ( $document_types as $name => $document_type ) {
146 - $data[ $name ] = $document_type::get_title();
147 - }
148 -
149 - return $data;
150 - }
151 -
152 - public function print_content() {
153 - if ( ! $this->print_preview_callback ) {
154 - $this->print_preview_callback = [ $this, 'print_thumbnail_preview_callback' ];
155 - }
156 -
157 - call_user_func( $this->print_preview_callback );
158 - }
159 -
160 - private function print_thumbnail_preview_callback() {
161 - $doc = Plugin::$instance->documents->get_current();
162 -
163 - if ( ! $doc ) {
164 - $render_mode = Plugin::$instance->frontend->render_mode_manager->get_current();
165 - if ( $render_mode instanceof Render_Mode_Preview ) {
166 - $doc = $render_mode->get_document();
167 - }
168 - }
169 -
170 - if ( ! $doc ) {
171 - echo '<div class="elementor-alert elementor-alert-danger">' . esc_html__( 'Document not found for preview.', 'elementor' ) . '</div>';
172 - return;
173 - }
174 -
175 - Plugin::$instance->documents->switch_to_document( $doc );
176 -
177 - $content = $doc->get_content( true );
178 -
179 - echo $content; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
180 - }
181 -
182 -
183 - protected function is_screenshot_proxy_mode( array $query_params ) {
184 - $is_proxy = isset( $query_params['screenshot_proxy'] );
185 -
186 - if ( $is_proxy ) {
187 - if ( ! wp_verify_nonce( $query_params['nonce'], 'screenshot-proxy' ) ) {
188 - // WP >= 6.2-alpha
189 - if ( class_exists( '\WpOrg\Requests\Exception\Http\Status403' ) ) {
190 - throw new \WpOrg\Requests\Exception\Http\Status403();
191 - } else {
192 - throw new \Requests_Exception_HTTP_403();
193 - }
194 - }
195 -
196 - if ( ! $query_params['href'] ) {
197 - // WP >= 6.2-alpha
198 - if ( class_exists( '\WpOrg\Requests\Exception\Http\Status400' ) ) {
199 - throw new \WpOrg\Requests\Exception\Http\Status400();
200 - } else {
201 - throw new \Requests_Exception_HTTP_400();
202 - }
203 - }
204 - }
205 -
206 - return $is_proxy;
207 78 }
208 79 }