PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.1.9
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.1.9
3.8.0 3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 All 112 releases
← All changes | includes/Core/Importer/Runners/Templates.php +83 -12 3.1.1 → 3.1.9 View file →
@@ -32,22 +32,39 @@
32 32 /**
33 33 * @throws Exception
34 34 */
35 35 public function import( $data, $imported_data ): array {
36 - $results = [];
36 + $results = $data["imported_data"]["templates"] ?? [];
37 37 $templates = $this->manifest['templates'];
38 38 $path = $this->dir_path . 'templates' . DIRECTORY_SEPARATOR;
39 39
40 40 $_extra_pages = [];
41 41
42 + // Get the processed templates from the session data
43 + $processed_templates = $this->origin->get_progress();
44 +
45 + if(empty($processed_templates)){
46 + $this->log( 0 );
47 + $processed_templates = ["__started__"];
48 + $this->origin->update_progress( $processed_templates);
49 + $this->create_page_template();
50 + }
51 +
42 52 $total = count( $templates );
43 - $processed = 0;
53 +
54 +
44 55 foreach ( $templates as $id => $template_settings ) {
56 + // Broadcast Log
57 + // If the template has been processed, skip it
58 + if (in_array($id, $processed_templates)) {
59 + continue;
60 + }
61 +
45 62 $template_content = Utils::read_json_file( $path . $id . '.json' );
46 63
47 64 $import = $this->import_template( $id, $template_settings, $template_content );
48 65 if ( $import ) {
49 - $results['succeed'][ $id ] = $import;
66 + $results['succeed'][ $id ] = $import['id'];
50 67 $results['template_types'][] = $template_settings['type'];
51 68
52 69 if ( $template_settings['type'] === 'archive' || $template_settings['type'] === 'product_archive' || $template_settings['type'] === 'course_archive' ) {
53 70 $page_id = $this->create_archive_page( $template_settings, $this->manifest['platform'] );
@@ -54,9 +71,9 @@
54 71 if ( $page_id ) {
55 72 $_extra_pages['archive_settings'] = [
56 73 'old_id' => $id,
57 74 'page_id' => $page_id,
58 - 'archive_id' => $import
75 + 'archive_id' => $import['id']
59 76 ];
60 77 }
61 78 }
62 79
@@ -64,11 +81,30 @@
64 81 $results['failed'][ $id ] = $import;
65 82 }
66 83
67 84 // Broadcast Log
68 - $processed += 1;
85 + $processed = 0;
86 + array_walk_recursive($results, function($item) use (&$processed) {
87 + $processed++;
88 + });
69 89 $progress = floor( ( 100 * $processed ) / $total );
70 90 $this->log( $progress );
91 +
92 + $results['__attachments'][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : [];
93 + // Add the template to the processed templates and update the session data
94 + $processed_templates[] = $id;
95 + $this->origin->update_progress( $processed_templates, array_merge( [ 'templates' => $results ], $_extra_pages ));
96 +
97 + // If it's not the last item, send the SSE message and exit
98 + if( end($templates) !== $template_settings ) {
99 + $this->sse_message( [
100 + 'type' => 'continue',
101 + 'action' => 'continue',
102 + 'i' => $id,
103 + 'results' => __METHOD__ . '::' . __LINE__,
104 + ] );
105 + exit;
106 + }
71 107 }
72 108
73 109 return array_merge( [ 'templates' => $results ], $_extra_pages );
74 110 }
@@ -86,8 +122,9 @@
86 122 'post_type' => 'templately_library',
87 123 ];
88 124
89 125 $meta = [];
126 + $result = [];
90 127
91 128 if ( $this->manifest['platform'] == 'gutenberg' ) {
92 129 $meta['_wp_page_template'] = PageTemplates::TEMPLATE_HEADER_FOOTER;
93 130 }
@@ -100,17 +137,19 @@
100 137 if (!$template->is_elementor_template()) {
101 138 $attachments = $this->json->parse_images($template_content['content']);
102 139
103 140 if (!empty($attachments)) {
104 - $manifest_content = &$this->manifest['templates'][$id];
105 - if(!isset($manifest_content['__attachments'])){
106 - $manifest_content['__attachments'] = [];
107 - }
108 - $manifest_content['__attachments'] = $attachments;
141 + $result['__attachments'] = $attachments;
142 + // $manifest_content = &$this->manifest['templates'][$id];
143 + // if(!isset($manifest_content['__attachments'])){
144 + // $manifest_content['__attachments'] = [];
145 + // }
146 + // $manifest_content['__attachments'] = $attachments;
109 147 }
110 148 }
111 149
112 150 $template_content['id'] = $id;
151 + unset($template_settings['conditions']);
113 152 $template_content['import_settings'] = $template_settings;
114 153 $template->import( $template_content );
115 154
116 155 if($template->has_logo($template_content)){
@@ -115,10 +154,10 @@
115 154
116 155 if($template->has_logo($template_content)){
117 156 $this->manifest['templates'][$id]['has_logo'] = true;
118 157 }
119 -
120 - return $template->get_main_id();
158 + $result['id'] = $template->get_main_id();
159 + return $result;
121 160 }
122 161
123 162
124 163 /**
@@ -152,7 +191,39 @@
152 191 }
153 192 return $archive_page;
154 193 } catch ( \Exception $e ) {
155 194 return false;
195 + }
196 + }
197 +
198 + /**
199 + * Only for gutenberg create a single page template.
200 + * @return void
201 + */
202 + private function create_page_template() {
203 + try {
204 + $meta = [];
205 + $data = [];
206 +
207 + $post_data = [
208 + 'post_title' => 'Single Page - (by Templately)',
209 + 'post_status' => 'publish',
210 + 'post_type' => 'templately_library',
211 + ];
212 +
213 + if ( $this->manifest['platform'] == 'elementor' ) {
214 + $meta['_wp_page_template'] = 'elementor_header_footer';
215 + $data = json_decode('{"content":[{"id":"4a86515d","settings":[],"elements":[{"id":"30a46db1","settings":{"content_width":"full"},"elements":[],"isInner":false,"widgetType":"tl-post-content","elType":"widget"}],"isInner":false,"elType":"container"}],"settings":{"template":"elementor_header_footer"},"metadata":[]}', true);
216 + } elseif ( $this->manifest['platform'] == 'gutenberg' ) {
217 + $meta['_wp_page_template'] = PageTemplates::TEMPLATE_HEADER_FOOTER;
218 + $data = ['content' => '<!-- wp:post-content /-->'];
219 + }
220 +
221 + $template = $this->factory->create( 'page_single', $post_data, $meta );
222 + $template->import( $data );
223 +
224 + // return $archive_page;
225 + } catch ( \Exception $e ) {
226 + return;
156 227 }
157 228 }
158 229 }