PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.11
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.11
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / classes / batch-process / class-cartflows-importer-beaver-builder.php

class-cartflows-importer-beaver-builder.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.1.11, at classes/batch-process/class-cartflows-importer-beaver-builder.php

230 lines 4.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Beaver Builder Importer
4 *
5 * @package CartFlows
6 * @since 1.1.1
7 */
8
9 if ( ! class_exists( 'CartFlows_Importer_Beaver_Builder' ) ) :
10
11 /**
12 * CartFlows Import Beaver Builder
13 *
14 * @since 1.1.1
15 */
16 class CartFlows_Importer_Beaver_Builder {
17
18 /**
19 * Instance
20 *
21 * @since 1.1.1
22 * @access private
23 * @var object Class object.
24 */
25 private static $instance;
26
27 /**
28 * Initiator
29 *
30 * @since 1.1.1
31 * @return object initialized object of class.
32 */
33 public static function get_instance() {
34
35 if ( ! isset( self::$instance ) ) {
36 self::$instance = new self;
37 }
38 return self::$instance;
39 }
40
41 /**
42 * Constructor
43 *
44 * @since 1.1.1
45 */
46 public function __construct() {
47 }
48
49 /**
50 * Update post meta.
51 *
52 * @param integer $post_id Post ID.
53 * @return void
54 */
55 public function import_single_post( $post_id = 0 ) {
56
57 $data = get_post_meta( $post_id, '_fl_builder_data', true );
58 if ( ! empty( $data ) ) {
59
60 $data = $this->get_import_data( $data );
61
62 // Update page builder data.
63 update_post_meta( $post_id, '_fl_builder_data', $data );
64 update_post_meta( $post_id, '_fl_builder_draft', $data );
65
66 // Clear all cache.
67 FLBuilderModel::delete_asset_cache_for_all_posts();
68 } else {
69 wcf()->logger->import_log( '(✕) Not have "Beaver Builder" Data. Post meta _fl_builder_data is empty!' );
70 }
71 }
72
73 /**
74 * Update post meta.
75 *
76 * @param array $data Page builder data.
77 * @return mixed
78 */
79 public function get_import_data( $data ) {
80
81 if ( empty( $data ) ) {
82 return array();
83 }
84
85 foreach ( $data as $key => $el ) {
86
87 // Import 'row' images.
88 if ( 'row' === $el->type ) {
89 $data[ $key ]->settings = self::import_row_images( $el->settings );
90 }
91
92 // Import 'module' images.
93 if ( 'module' === $el->type ) {
94 $data[ $key ]->settings = self::import_module_images( $el->settings );
95 }
96
97 // Import 'column' images.
98 if ( 'column' === $el->type ) {
99 $data[ $key ]->settings = self::import_column_images( $el->settings );
100 }
101 }
102
103 return $data;
104 }
105
106 /**
107 * Import Module Images.
108 *
109 * @param object $settings Module settings object.
110 * @return object
111 */
112 public static function import_module_images( $settings ) {
113
114 /**
115 * 1) Set photos.
116 */
117 $settings = self::import_photo( $settings );
118
119 /**
120 * 2) Set `$settings->data` for Only type 'image-icon'
121 *
122 * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
123 */
124 if (
125 isset( $settings->data ) &&
126 isset( $settings->photo ) && ! empty( $settings->photo ) &&
127 'image-icon' === $settings->type
128 ) {
129 $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
130 }
131
132 /**
133 * 3) Set `list item` module images
134 */
135 if ( isset( $settings->add_list_item ) ) {
136 foreach ( $settings->add_list_item as $key => $value ) {
137 $settings->add_list_item[ $key ] = self::import_photo( $value );
138 }
139 }
140
141 return $settings;
142 }
143
144 /**
145 * Import Column Images.
146 *
147 * @param object $settings Column settings object.
148 * @return object
149 */
150 public static function import_column_images( $settings ) {
151
152 // 1) Set BG Images.
153 $settings = self::import_bg_image( $settings );
154
155 return $settings;
156 }
157
158 /**
159 * Import Row Images.
160 *
161 * @param object $settings Row settings object.
162 * @return object
163 */
164 public static function import_row_images( $settings ) {
165
166 // 1) Set BG Images.
167 $settings = self::import_bg_image( $settings );
168
169 return $settings;
170 }
171
172 /**
173 * Helper: Import BG Images.
174 *
175 * @param object $settings Row settings object.
176 * @return object
177 */
178 public static function import_bg_image( $settings ) {
179
180 if (
181 ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
182 ) {
183 $image = array(
184 'url' => $settings->bg_image_src,
185 'id' => $settings->bg_image,
186 );
187
188 $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
189
190 $settings->bg_image_src = $downloaded_image['url'];
191 $settings->bg_image = $downloaded_image['id'];
192 }
193
194 return $settings;
195 }
196
197 /**
198 * Helper: Import Photo.
199 *
200 * @param object $settings Row settings object.
201 * @return object
202 */
203 public static function import_photo( $settings ) {
204
205 if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
206
207 $image = array(
208 'url' => $settings->photo_src,
209 'id' => $settings->photo,
210 );
211
212 $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
213
214 $settings->photo_src = $downloaded_image['url'];
215 $settings->photo = $downloaded_image['id'];
216 }
217
218 return $settings;
219 }
220
221
222 }
223
224 /**
225 * Initialize class object with 'get_instance()' method
226 */
227 CartFlows_Importer_Beaver_Builder::get_instance();
228
229 endif;
230