PluginProbe
Elementor Website Builder – more than just a page builder / 3.9.1
Elementor Website Builder – more than just a page builder v3.9.1
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
elementor / includes / template-library / sources / remote.php

remote.php in Elementor Website Builder – more than just a page builder 3.9.1, at includes/template-library/sources/remote.php

240 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Elementor\TemplateLibrary;
3
4 use Elementor\Api;
5 use Elementor\Plugin;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit; // Exit if accessed directly.
9 }
10
11 /**
12 * Elementor template library remote source.
13 *
14 * Elementor template library remote source handler class is responsible for
15 * handling remote templates from Elementor.com servers.
16 *
17 * @since 1.0.0
18 */
19 class Source_Remote extends Source_Base {
20
21 /**
22 * Get remote template ID.
23 *
24 * Retrieve the remote template ID.
25 *
26 * @since 1.0.0
27 * @access public
28 *
29 * @return string The remote template ID.
30 */
31 public function get_id() {
32 return 'remote';
33 }
34
35 /**
36 * Get remote template title.
37 *
38 * Retrieve the remote template title.
39 *
40 * @since 1.0.0
41 * @access public
42 *
43 * @return string The remote template title.
44 */
45 public function get_title() {
46 return esc_html__( 'Remote', 'elementor' );
47 }
48
49 /**
50 * Register remote template data.
51 *
52 * Used to register custom template data like a post type, a taxonomy or any
53 * other data.
54 *
55 * @since 1.0.0
56 * @access public
57 */
58 public function register_data() {}
59
60 /**
61 * Get remote templates.
62 *
63 * Retrieve remote templates from Elementor.com servers.
64 *
65 * @since 1.0.0
66 * @access public
67 *
68 * @param array $args Optional. Nou used in remote source.
69 *
70 * @return array Remote templates.
71 */
72 public function get_items( $args = [] ) {
73 $library_data = Api::get_library_data();
74
75 $templates = [];
76
77 if ( ! empty( $library_data['templates'] ) ) {
78 foreach ( $library_data['templates'] as $template_data ) {
79 $templates[] = $this->prepare_template( $template_data );
80 }
81 }
82
83 return $templates;
84 }
85
86 /**
87 * Get remote template.
88 *
89 * Retrieve a single remote template from Elementor.com servers.
90 *
91 * @since 1.0.0
92 * @access public
93 *
94 * @param int $template_id The template ID.
95 *
96 * @return array Remote template.
97 */
98 public function get_item( $template_id ) {
99 $templates = $this->get_items();
100
101 return $templates[ $template_id ];
102 }
103
104 /**
105 * Save remote template.
106 *
107 * Remote template from Elementor.com servers cannot be saved on the
108 * database as they are retrieved from remote servers.
109 *
110 * @since 1.0.0
111 * @access public
112 *
113 * @param array $template_data Remote template data.
114 *
115 * @return \WP_Error
116 */
117 public function save_item( $template_data ) {
118 return new \WP_Error( 'invalid_request', 'Cannot save template to a remote source' );
119 }
120
121 /**
122 * Update remote template.
123 *
124 * Remote template from Elementor.com servers cannot be updated on the
125 * database as they are retrieved from remote servers.
126 *
127 * @since 1.0.0
128 * @access public
129 *
130 * @param array $new_data New template data.
131 *
132 * @return \WP_Error
133 */
134 public function update_item( $new_data ) {
135 return new \WP_Error( 'invalid_request', 'Cannot update template to a remote source' );
136 }
137
138 /**
139 * Delete remote template.
140 *
141 * Remote template from Elementor.com servers cannot be deleted from the
142 * database as they are retrieved from remote servers.
143 *
144 * @since 1.0.0
145 * @access public
146 *
147 * @param int $template_id The template ID.
148 *
149 * @return \WP_Error
150 */
151 public function delete_template( $template_id ) {
152 return new \WP_Error( 'invalid_request', 'Cannot delete template from a remote source' );
153 }
154
155 /**
156 * Export remote template.
157 *
158 * Remote template from Elementor.com servers cannot be exported from the
159 * database as they are retrieved from remote servers.
160 *
161 * @since 1.0.0
162 * @access public
163 *
164 * @param int $template_id The template ID.
165 *
166 * @return \WP_Error
167 */
168 public function export_template( $template_id ) {
169 return new \WP_Error( 'invalid_request', 'Cannot export template from a remote source' );
170 }
171
172 /**
173 * Get remote template data.
174 *
175 * Retrieve the data of a single remote template from Elementor.com servers.
176 *
177 * @since 1.5.0
178 * @access public
179 *
180 * @param array $args Custom template arguments.
181 * @param string $context Optional. The context. Default is `display`.
182 *
183 * @return array|\WP_Error Remote Template data.
184 */
185 public function get_data( array $args, $context = 'display' ) {
186 $data = Api::get_template_content( $args['template_id'] );
187
188 if ( is_wp_error( $data ) ) {
189 return $data;
190 }
191
192 // Set the Request's state as an Elementor upload request, in order to support unfiltered file uploads.
193 Plugin::$instance->uploads_manager->set_elementor_upload_state( true );
194
195 // BC.
196 $data = (array) $data;
197
198 $data['content'] = $this->replace_elements_ids( $data['content'] );
199 $data['content'] = $this->process_export_import_content( $data['content'], 'on_import' );
200
201 $post_id = $args['editor_post_id'];
202 $document = Plugin::$instance->documents->get( $post_id );
203 if ( $document ) {
204 $data['content'] = $document->get_elements_raw_data( $data['content'], true );
205 }
206
207 // After the upload complete, set the elementor upload state back to false
208 Plugin::$instance->uploads_manager->set_elementor_upload_state( false );
209
210 return $data;
211 }
212
213 /**
214 * @since 2.2.0
215 * @access private
216 */
217 private function prepare_template( array $template_data ) {
218 $favorite_templates = $this->get_user_meta( 'favorites' );
219
220 return [
221 'template_id' => $template_data['id'],
222 'source' => $this->get_id(),
223 'type' => $template_data['type'],
224 'subtype' => $template_data['subtype'],
225 'title' => $template_data['title'],
226 'thumbnail' => $template_data['thumbnail'],
227 'date' => $template_data['tmpl_created'],
228 'author' => $template_data['author'],
229 'tags' => json_decode( $template_data['tags'] ),
230 'isPro' => ( '1' === $template_data['is_pro'] ),
231 'accessLevel' => $template_data['access_level'],
232 'popularityIndex' => (int) $template_data['popularity_index'],
233 'trendIndex' => (int) $template_data['trend_index'],
234 'hasPageSettings' => ( '1' === $template_data['has_page_settings'] ),
235 'url' => $template_data['url'],
236 'favorite' => ! empty( $favorite_templates[ $template_data['id'] ] ),
237 ];
238 }
239 }
240