PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.3
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.3
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 3.1.10 All 111 releases
← All changes | includes/Core/Importer/Runners/Finalizer.php +132 -27 3.1.13.5.3 View file →
@@ -3,21 +3,25 @@
3 3 namespace Templately\Core\Importer\Runners;
4 4
5 5
6 6 use Exception;
7 +use Templately\Core\Importer\Utils\AIContentHelper;
7 8 use Templately\Core\Importer\Utils\Utils;
9 +use Templately\Core\Importer\Utils\AIUtils;
10 +use Templately\Utils\Helper;
8 11
9 12 class Finalizer extends BaseRunner {
13 + use AIContentHelper;
10 14 private $options = [];
11 15 private $type_to_check = [ 'templates', 'content' ];
12 16 private $imported_data;
13 17
14 - private $type = '';
15 - private $sub_type = '';
18 + public $type = '';
19 + private $data = [];
20 + public $sub_type = '';
16 21 private $extra_content;
17 22
18 23 private $total_counts = 0;
19 - private $processed_items = 0;
20 24
21 25 /**
22 26 * @var array|mixed
23 27 */
@@ -38,18 +42,20 @@
38 42 public function log_message(): string {
39 43 return __( 'Finalizing Your Imports', 'templately' );
40 44 }
41 45
42 - public function should_run( $data, $imported_data = [] ): bool {
46 + public function should_run( $param_data, $imported_data = [] ): bool {
43 47 $data = [];
44 48
45 49 foreach ( $this->type_to_check as $type ) {
46 50 $contents = ! empty ( $this->manifest[ $type ] ) ? $this->manifest[ $type ] : [];
47 51 if ( $type == 'templates' ) {
48 - $this->prepare( $data, $contents, $type );
52 + // $imported_data["templates"]["__attachments"][691]
53 + $this->prepare( $data, $contents, $type, null, $imported_data );
49 54 } else {
50 55 foreach ( $contents as $post_type => $templates ) {
51 - $this->prepare( $data, $templates, $type, $post_type );
56 + // $imported_data["content"]["__attachments"][$post_type][11]
57 + $this->prepare( $data, $templates, $type, $post_type, $imported_data );
52 58 }
53 59 }
54 60 }
55 61 $this->options = &$data;
@@ -56,14 +62,27 @@
56 62
57 63 return ! empty( $data ) || $this->platform == 'gutenberg';
58 64 }
59 65
60 - private function prepare( &$data, $templates, $type, $sub_type = null ) {
66 + private function prepare( &$data, $templates, $type, $sub_type = null, $imported_data = [] ) {
61 67 if ( empty( $templates ) || ! is_array( $templates ) ) {
62 68 return;
63 69 }
64 70 foreach ( $templates as $id => $template ) {
65 - if ( ! isset( $template['data'] ) && !isset( $template['__attachments']) && !isset($template['has_logo']) ) {
71 + // Check for __attachments in both template and imported_data
72 + $has_attachment = !empty($template['__attachments']);
73 +
74 + if (!$has_attachment && !empty($imported_data)) {
75 + if ($sub_type) {
76 + // $imported_data["content"]["__attachments"]["page"][11]
77 + $has_attachment = isset($imported_data[$type]['__attachments'][$sub_type][$id]);
78 + } else {
79 + // $imported_data["templates"]["__attachments"][691]
80 + $has_attachment = isset($imported_data[$type]['__attachments'][$id]);
81 + }
82 + }
83 +
84 + if ( ! isset( $template['data'] ) && !$has_attachment && !isset($template['has_logo']) && !$this->is_ai_content($id) && !isset($template["page_settings"]["fluent_cart_store_settings"]) ) {
66 85 continue;
67 86 }
68 87
69 88 // if ( ! isset( $template['data']['form'] ) && ! isset( $template['data']['nav_menus'] )) {
@@ -80,8 +99,9 @@
80 99 }
81 100 }
82 101
83 102 public function import( $data, $imported_data ): array {
103 + $this->data = &$data;
84 104 $this->imported_data = &$imported_data;
85 105
86 106 $this->json->imported_data = $this->imported_data;
87 107 $this->json->map_post_ids = Utils::map_old_new_post_ids( $this->imported_data );
@@ -89,22 +109,24 @@
89 109 if ( ! empty( $imported_data['extra-content'] ) ) {
90 110 $this->extra_content = $imported_data['extra-content'];
91 111 }
92 112
93 - $this->log( 0 );
94 113 add_action('templately_import.finalize_gutenberg_attachment', [$this, 'post_log'], 10, 2);
95 114
96 - foreach ( $this->options as $type => $contents ) {
115 + $this->update_settings();
116 +
117 + $this->loop( $this->options, function($type, $contents ) {
97 118 $this->type = $type;
119 +
98 120 if ( $type == 'templates' ) {
99 - $this->finalize_imports( $contents );
121 + $this->finalize_imports( $contents, $type );
100 122 } else {
101 - foreach ( $contents as $post_type => $templates ) {
123 + $this->loop( $contents, function($post_type, $templates ) use($type) {
102 124 $this->sub_type = $post_type;
103 - $this->finalize_imports( $templates );
104 - }
125 + $this->finalize_imports( $templates, $type, $post_type );
126 + }, $type);
105 127 }
106 - }
128 + });
107 129
108 130 if ( $this->platform == 'gutenberg' ) {
109 131 $this->regenerate_assets();
110 132 }
@@ -119,30 +141,113 @@
119 141 rmdir( $upload_dir['basedir'] . '/eb-style/' );
120 142 }
121 143 }
122 144
123 - private function finalize_imports( $templates ) {
124 - foreach ( $templates as $old_template_id => $template_settings ) {
145 + private function finalize_imports( $templates, $type, $post_type = null ) {
146 + // used for counting
147 + $processed = $this->get_loop_result([], 'finalized_imports', false);
148 + $path = $this->dir_path . $this->type . DIRECTORY_SEPARATOR;
149 +
150 + if ( ! empty( $this->sub_type ) ) {
151 + $path .= $this->sub_type . DIRECTORY_SEPARATOR;
152 + }
153 +
154 + $this->loop( $templates, function($old_template_id, $template_settings ) use($type, $post_type, $path, $processed) {
125 155 try {
126 - $path = $this->dir_path . $this->type . DIRECTORY_SEPARATOR;
127 - if ( ! empty( $this->sub_type ) ) {
128 - $path .= $this->sub_type . DIRECTORY_SEPARATOR;
156 +
157 + if($post_type && isset($this->imported_data[$type]['__attachments'][$post_type][$old_template_id])){
158 + $template_settings['__attachments'] = $this->imported_data[$type]['__attachments'][$post_type][$old_template_id];
129 159 }
130 - $path .= "{$old_template_id}.json";
131 - $template_json = Utils::read_json_file( $path );
160 + else if(empty($post_type) && isset($this->imported_data[$type]['__attachments'][$old_template_id])){
161 + $template_settings['__attachments'] = $this->imported_data[$type]['__attachments'][$old_template_id];
162 + }
163 +
164 + // Read the original template file for non-AI content
165 + $original_file = $path . "{$old_template_id}.json";
166 + $template_json = Utils::read_json_file($original_file);
167 +
168 + $processed_pages = get_option("templately_ai_processed_pages", []);
169 + $updated_ids = $processed_pages[$this->process_id] ?? [];
170 + $ai_paths = $this->generateAiFilePaths($old_template_id);
171 + if($this->is_ai_content($old_template_id) && !file_exists($ai_paths['ai_file_path'])){
172 + // Use the static timeout-aware wait handler from AIUtils
173 + AIUtils::handle_sse_wait_with_timeout(
174 + $this->session_id,
175 + 'ai_content_time',
176 + $updated_ids,
177 + $this->ai_page_ids,
178 + [$this, 'sse_message'],
179 + [
180 + 'name' => method_exists($this, 'get_name') ? $this->get_name() : '',
181 + 'post_type' => $post_type,
182 + 'id' => $old_template_id,
183 + ],
184 + $old_template_id // Pass template ID for local site polling
185 + );
186 + }
187 + // Check if this is AI content before processing
188 + if ($this->isAiContent($old_template_id)) {
189 + // Process AI content using AIContentHelper trait
190 + $ai_result = $this->processAiContent($old_template_id);
191 + if($ai_result['is_ai'] && !empty($ai_result['template_json'])){
192 + $template_json = $ai_result['template_json'];
193 + }
194 + }
195 +
132 196 $params = $this->origin->get_request_params();
133 197 $this->json->prepare( $template_json, $template_settings, $this->extra_content['form'][ $old_template_id ] ?? [], $params )->update();
134 198
199 + $processed[] = $old_template_id;
200 + // Add the template to the processed templates and update the session data
201 + $this->set_loop_result( $processed, 'finalized_imports');
135 202 // Broadcast Log
136 - $this->processed_items += 1;
137 - $progress = floor( ( 100 * $this->processed_items ) / $this->total_counts );
203 + $progress = floor( ( 100 * count($processed) ) / $this->total_counts );
204 + if(empty($progress)){
205 + $xyz = 0;
206 + }
138 207 $this->log( $progress );
208 +
139 209 } catch ( Exception $e ) {
140 - continue;
210 +
141 211 }
142 - }
212 +
213 +
214 + }, "$type-$post_type");
143 215 }
144 216
145 217 public function post_log($id, $size_dimension = null){
146 218 $this->log(-1, "Imported attachment: $id" . ( $size_dimension ? " - $size_dimension" : ''), 'eventLog');
147 219 }
148 -}
220 +
221 + private function update_settings() {
222 + $data = $this->data;
223 + $map_post_ids = $this->json->map_post_ids;
224 + $saved_options = get_option('fluent_cart_store_settings', []);
225 + $mapped_keys = [
226 + 'checkout_page_id',
227 + 'custom_payment_page_id',
228 + 'registration_page_id',
229 + 'login_page_id',
230 + 'cart_page_id',
231 + 'receipt_page_id',
232 + 'shop_page_id',
233 + 'customer_profile_page_id',
234 + ];
235 +
236 + foreach ($mapped_keys as $key) {
237 + $old_id = $saved_options[$key] ?? null;
238 + if (!empty($old_id) && isset($map_post_ids[$old_id])) {
239 + $saved_options[$key] = $map_post_ids[$old_id];
240 + }
241 + else if(isset($saved_options[$key])){
242 + unset($saved_options[$key]);
243 + }
244 + }
245 +
246 + update_option('fluent_cart_store_settings', $saved_options);
247 + }
248 +
249 +
250 +
251 +
252 +
253 +}