PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.0.1
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.0.1
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 +5 -89 3.1.103.0.1 View file →
@@ -3,14 +3,10 @@
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\Core\Importer\WPImport;
8 7 use WP_Error;
9 8
10 -/**
11 - * @property GutenbergHelper $json
12 - */
13 9 class GutenbergContent extends BaseRunner {
14 10
15 11 public function get_name(): string {
16 12 return 'content';
@@ -36,62 +32,12 @@
36 32 return __( 'Importing Gutenberg Templates (Pages, Posts etc)', 'templately' );
37 33 }
38 34
39 35 public function import( $data, $imported_data ): array {
40 - $results = $data["imported_data"]["content"] ?? [];
36 + $results = [];
41 37 $contents = $this->manifest['content'];
42 38 $path = $this->dir_path . 'content' . DIRECTORY_SEPARATOR;
43 39
44 - $processed_templates = $this->origin->get_progress();
45 -
46 - if(empty($processed_templates)){
47 - $this->log( 0 );
48 - $processed_templates = ["__started__"];
49 - $this->origin->update_progress( $processed_templates);
50 - }
51 -
52 - if(isset($this->manifest['has_settings']) && $this->manifest['has_settings'] && !in_array("global_colors", $processed_templates)){
53 - $file = $this->dir_path . "settings.json";
54 - $settings = Utils::read_json_file( $file );
55 -
56 - if(!empty($data['color'])){
57 - if (isset($settings['global_colors'])) {
58 - foreach ($settings['global_colors'] as $key => $color) {
59 - $settings['global_colors'][$key]['color'] = $data['color'][$color['var']] ?? $color['color'];
60 - }
61 - }
62 -
63 - if (isset($settings['custom_colors'])) {
64 - foreach ($settings['custom_colors'] as $key => $color) {
65 - $settings['custom_colors'][$key]['color'] = $data['color'][$color['var']] ?? $color['color'];
66 - }
67 - }
68 - }
69 - if(!empty($data['logo']['id'])){
70 - $site_logo_id = $data['logo']['id'];
71 - $settings['site_logo'] = $site_logo_id;
72 - Utils::update_option( 'site_logo', $site_logo_id );
73 - $this->origin->update_imported_list('attachment', $data['logo']['id']);
74 - }
75 - else if(!empty($data['logo']) && empty(get_option('site_logo'))){
76 - // demo logo
77 - $site_logo = Utils::upload_logo($data['logo']);
78 - if(!empty($site_logo['id'])){
79 - $settings['site_logo'] = $site_logo['id'];
80 - Utils::update_option( 'site_logo', $site_logo['id'] );
81 - $this->origin->update_imported_list('attachment', $site_logo['id']);
82 - }
83 - }
84 -
85 - $settings = array_map('json_encode', $settings);
86 -
87 - // Save the settings to the 'eb_global_styles' option
88 - Utils::update_option('eb_global_styles', $settings);
89 -
90 - $processed_templates[] = "global_colors";
91 - $this->origin->update_progress( $processed_templates, [ 'content' => $results ]);
92 - }
93 -
94 40 $processed = 0;
95 41 $total = array_reduce($contents, function($carry, $item) {
96 42 return $carry + count($item);
97 43 }, 0);
@@ -97,42 +43,21 @@
97 43 }, 0);
98 44
99 45 foreach ( $contents as $type => $posts ) {
100 46 foreach ( $posts as $id => $settings ) {
101 - if (in_array("$type::$id", $processed_templates)) {
102 - continue;
103 - }
104 47 $import = $this->import_page_content( $id, $type, $path, $settings );
105 48
106 49 if ( ! $import ) {
107 50 $results[ $type ]['failed'][ $id ] = $import;
108 51 } else {
109 - Utils::import_page_settings( $import['id'], $settings );
110 - $results[ $type ]['succeed'][ $id ] = $import['id'];
52 + Utils::import_page_settings( $import, $settings );
53 + $results[ $type ]['succeed'][ $id ] = $import;
111 54 }
112 55
113 56 // Broadcast Log
114 - $processed = 0;
115 - array_walk_recursive($results, function($item) use (&$processed) {
116 - $processed++;
117 - });
57 + $processed += 1;
118 58 $progress = floor( ( 100 * $processed ) / $total );
119 59 $this->log( $progress, null, 'eventLog' );
120 -
121 -
122 - $results['__attachments'][$type][ $id ] = isset($import['__attachments']) ? $import['__attachments'] : [];
123 - // Add the template to the processed templates and update the session data
124 - $processed_templates[] = "$type::$id";
125 - $this->origin->update_progress( $processed_templates, [ 'content' => $results ]);
126 - // If it's not the last item, send the SSE message and exit
127 - if( end($contents) !== $posts || end($posts) !== $settings) {
128 - $this->sse_message( [
129 - 'type' => 'continue',
130 - 'action' => 'continue',
131 - 'results' => __METHOD__ . '::' . __LINE__,
132 - ] );
133 - exit;
134 - }
135 60 }
136 61 }
137 62
138 63 return [ 'content' => $results ];
@@ -172,20 +97,11 @@
172 97 if ( is_wp_error( $inserted ) ) {
173 98 return false;
174 99 }
175 100
176 - $attachments = $this->json->parse_images($json_content['content']);
177 -
178 - $result = [];
179 - if (!empty($attachments)) {
180 - $result['__attachments'] = $attachments;
181 - }
182 - $result['id'] = $inserted;
183 -
184 - return $result;
101 + return $inserted;
185 102 }
186 103 } catch ( \Exception $e ) {
187 104 return false;
188 105 }
189 106 }
190 -
191 107 }