PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 3.1.4
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v3.1.4
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 / importer / batch-process / class-cartflows-importer-beaver-builder.php

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

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