PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.2
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.2
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.2, at classes/batch-process/class-cartflows-importer-beaver-builder.php

229 lines 4.9 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 // Download Images.
61 $data = $this->get_import_data( $data );
62
63 // Update page builder data.
64 update_post_meta( $post_id, '_fl_builder_data', $data );
65 update_post_meta( $post_id, '_fl_builder_draft', $data );
66
67 // Clear all cache.
68 FLBuilderModel::delete_asset_cache_for_all_posts();
69 }
70 }
71
72 /**
73 * Update post meta.
74 *
75 * @param array $data Page builder data.
76 * @return mixed
77 */
78 public function get_import_data( $data ) {
79
80 if ( empty( $data ) ) {
81 return array();
82 }
83
84 foreach ( $data as $key => $el ) {
85
86 // Import 'row' images.
87 if ( 'row' === $el->type ) {
88 $data[ $key ]->settings = self::import_row_images( $el->settings );
89 }
90
91 // Import 'module' images.
92 if ( 'module' === $el->type ) {
93 $data[ $key ]->settings = self::import_module_images( $el->settings );
94 }
95
96 // Import 'column' images.
97 if ( 'column' === $el->type ) {
98 $data[ $key ]->settings = self::import_column_images( $el->settings );
99 }
100 }
101
102 return $data;
103 }
104
105 /**
106 * Import Module Images.
107 *
108 * @param object $settings Module settings object.
109 * @return object
110 */
111 public static function import_module_images( $settings ) {
112
113 /**
114 * 1) Set photos.
115 */
116 $settings = self::import_photo( $settings );
117
118 /**
119 * 2) Set `$settings->data` for Only type 'image-icon'
120 *
121 * @todo Remove the condition `'image-icon' === $settings->type` if `$settings->data` is used only for the Image Icon.
122 */
123 if (
124 isset( $settings->data ) &&
125 isset( $settings->photo ) && ! empty( $settings->photo ) &&
126 'image-icon' === $settings->type
127 ) {
128 $settings->data = FLBuilderPhoto::get_attachment_data( $settings->photo );
129 }
130
131 /**
132 * 3) Set `list item` module images
133 */
134 if ( isset( $settings->add_list_item ) ) {
135 foreach ( $settings->add_list_item as $key => $value ) {
136 $settings->add_list_item[ $key ] = self::import_photo( $value );
137 }
138 }
139
140 return $settings;
141 }
142
143 /**
144 * Import Column Images.
145 *
146 * @param object $settings Column settings object.
147 * @return object
148 */
149 public static function import_column_images( $settings ) {
150
151 // 1) Set BG Images.
152 $settings = self::import_bg_image( $settings );
153
154 return $settings;
155 }
156
157 /**
158 * Import Row Images.
159 *
160 * @param object $settings Row settings object.
161 * @return object
162 */
163 public static function import_row_images( $settings ) {
164
165 // 1) Set BG Images.
166 $settings = self::import_bg_image( $settings );
167
168 return $settings;
169 }
170
171 /**
172 * Helper: Import BG Images.
173 *
174 * @param object $settings Row settings object.
175 * @return object
176 */
177 public static function import_bg_image( $settings ) {
178
179 if (
180 ( ! empty( $settings->bg_image ) && ! empty( $settings->bg_image_src ) )
181 ) {
182 $image = array(
183 'url' => $settings->bg_image_src,
184 'id' => $settings->bg_image,
185 );
186
187 $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
188
189 $settings->bg_image_src = $downloaded_image['url'];
190 $settings->bg_image = $downloaded_image['id'];
191 }
192
193 return $settings;
194 }
195
196 /**
197 * Helper: Import Photo.
198 *
199 * @param object $settings Row settings object.
200 * @return object
201 */
202 public static function import_photo( $settings ) {
203
204 if ( ! empty( $settings->photo ) && ! empty( $settings->photo_src ) ) {
205
206 $image = array(
207 'url' => $settings->photo_src,
208 'id' => $settings->photo,
209 );
210
211 $downloaded_image = CartFlows_Import_Image::get_instance()->import( $image );
212
213 $settings->photo_src = $downloaded_image['url'];
214 $settings->photo = $downloaded_image['id'];
215 }
216
217 return $settings;
218 }
219
220
221 }
222
223 /**
224 * Initialize class object with 'get_instance()' method
225 */
226 CartFlows_Importer_Beaver_Builder::get_instance();
227
228 endif;
229