PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.1.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.1.2
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/GutenbergContent.php +29 -69 3.7.33.1.2 View file →
@@ -3,9 +3,9 @@
3 3 namespace Templately\Core\Importer\Runners;
4 4
5 5 use Templately\Builder\PageTemplates;
6 6 use Templately\Core\Importer\Utils\Utils;
7 -use Templately\Utils\Helper;
7 +use Templately\Core\Importer\WPImport;
8 8 use WP_Error;
9 9
10 10 /**
11 11 * @property GutenbergHelper $json
@@ -28,25 +28,21 @@
28 28 return true;
29 29 }
30 30
31 31 public function get_action(): string {
32 - return 'updateLog';
32 + return 'eventLog';
33 33 }
34 34
35 35 public function log_message(): string {
36 - return __( 'Importing Gutenberg Page and Post Templates', 'templately' );
36 + return __( 'Importing Gutenberg Templates (Pages, Posts etc)', 'templately' );
37 37 }
38 38
39 39 public function import( $data, $imported_data ): array {
40 + $results = [];
40 41 $contents = $this->manifest['content'];
42 + $path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
41 43
42 - // Log start of import
43 - if(!$this->is_key_processed('started', 'import')){
44 - $this->log( 0 );
45 - $this->mark_key_processed('started', 'import');
46 - }
47 -
48 - if(isset($this->manifest['has_settings']) && $this->manifest['has_settings'] && !$this->is_key_processed('global_colors', 'settings')){
44 + if(isset($this->manifest['has_settings']) && $this->manifest['has_settings']){
49 45 $file = $this->dir_path . "settings.json";
50 46 $settings = Utils::read_json_file( $file );
51 47
52 48 if(!empty($data['color'])){
@@ -61,47 +57,26 @@
61 57 $settings['custom_colors'][$key]['color'] = $data['color'][$color['var']] ?? $color['color'];
62 58 }
63 59 }
64 60 }
65 - $logo_url = Utils::get_logo_url($data['logo'] ?? null);
66 - $logo_id = is_array($data['logo'] ?? null) ? ($data['logo']['id'] ?? 0) : 0;
67 - if(!empty($logo_id)){
68 - $site_logo_id = $logo_id;
61 + if(!empty($data['logo']['id'])){
62 + $site_logo_id = $data['logo']['id'];
69 63 $settings['site_logo'] = $site_logo_id;
70 64 Utils::update_option( 'site_logo', $site_logo_id );
71 - $this->origin->update_imported_list('attachment', $logo_id);
72 65 }
73 - else if (!empty($logo_url) && strpos($logo_url, 'data:image/') === 0) {
74 - // Upload base64 data URL
75 - $site_logo = Utils::upload_logo_base64($logo_url, $this->session_id);
76 -
66 + else if(!empty($data['logo']) && empty(get_option('site_logo'))){
67 + // demo logo
68 + $site_logo = Utils::upload_logo($data['logo']);
77 69 if(!empty($site_logo['id'])){
78 70 $settings['site_logo'] = $site_logo['id'];
79 71 Utils::update_option( 'site_logo', $site_logo['id'] );
80 - $this->origin->update_imported_list('attachment', $site_logo['id']);
81 72 }
82 73 }
83 - else if(!empty($logo_url)){
84 - // Upload remote URL
85 - $site_logo = Utils::upload_logo($logo_url, $this->session_id);
86 - if(!empty($site_logo['id'])){
87 - $settings['site_logo'] = $site_logo['id'];
88 - Utils::update_option( 'site_logo', $site_logo['id'] );
89 - $this->origin->update_imported_list('attachment', $site_logo['id']);
90 - }
91 - }
92 74
93 -
94 - if(!empty($data['typography'])){
95 - $settings["global_typography"] = $data['typography'];
96 - }
97 -
98 75 $settings = array_map('json_encode', $settings);
99 76
100 77 // Save the settings to the 'eb_global_styles' option
101 78 Utils::update_option('eb_global_styles', $settings);
102 -
103 - $this->mark_key_processed('global_colors', 'settings');
104 79 }
105 80
106 81 $processed = 0;
107 82 $total = array_reduce($contents, function($carry, $item) {
@@ -107,43 +82,26 @@
107 82 $total = array_reduce($contents, function($carry, $item) {
108 83 return $carry + count($item);
109 84 }, 0);
110 85
111 - $results = $this->loop( $contents, function($type, $posts, $results ) use($total) {
112 - // Inner loop accumulates results for this type
113 - $inner_result = $this->loop( $posts, function($id, $settings, $result ) use($type, $results, $total) {
114 - $path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
115 -
86 + foreach ( $contents as $type => $posts ) {
87 + foreach ( $posts as $id => $settings ) {
116 88 $import = $this->import_page_content( $id, $type, $path, $settings );
117 89
118 90 if ( ! $import ) {
119 - $result[ $type ]['failed'][ $id ] = $import;
91 + $results[ $type ]['failed'][ $id ] = $import;
120 92 } else {
121 - Utils::import_page_settings( $import['id'], $settings );
122 - $result[ $type ]['succeed'][ $id ] = $import['id'];
93 + Utils::import_page_settings( $import, $settings );
94 + $results[ $type ]['succeed'][ $id ] = $import;
123 95 }
124 96
125 - // Broadcast Log - merge with outer results for accurate counting
126 - $merged = array_merge($results, $result);
127 - $processed = 0;
128 - foreach ($merged as $t => $data) {
129 - if (is_array($data) && $t !== '__attachments') {
130 - $processed += count($data['succeed'] ?? []) + count($data['failed'] ?? []);
131 - }
132 - }
133 - $progress = $total > 0 ? floor( ( 100 * $processed ) / $total ) : 100;
134 - $this->log( $progress );
97 + // Broadcast Log
98 + $processed += 1;
99 + $progress = floor( ( 100 * $processed ) / $total );
100 + $this->log( $progress, null, 'eventLog' );
101 + }
102 + }
135 103
136 - $result['__attachments'][$type][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : [];
137 -
138 - return $result;
139 - }, $type);
140 -
141 - // Non-recursive merge of inner result with outer results
142 - $results = array_merge($results, $inner_result);
143 - return $results;
144 - });
145 -
146 104 return [ 'content' => $results ];
147 105 }
148 106
149 107 /**
@@ -182,15 +140,17 @@
182 140 }
183 141
184 142 $attachments = $this->json->parse_images($json_content['content']);
185 143
186 - $result = [];
187 144 if (!empty($attachments)) {
188 - $result['__attachments'] = $attachments;
145 + $manifest_content = &$this->manifest['content'][$type][$id];
146 + if(!isset($manifest_content['__attachments'])){
147 + $manifest_content['__attachments'] = [];
148 + }
149 + $manifest_content['__attachments'] = $attachments;
189 150 }
190 - $result['id'] = $inserted;
191 151
192 - return $result;
152 + return $inserted;
193 153 }
194 154 } catch ( \Exception $e ) {
195 155 return false;
196 156 }
@@ -195,5 +155,5 @@
195 155 return false;
196 156 }
197 157 }
198 158
199 -}
159 +}