PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.1.10
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.1.10
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-batch-process.php

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

271 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Batch Processing
4 *
5 * @package CartFlows
6 * @since 1.0.0
7 */
8
9 if ( ! class_exists( 'CartFlows_Batch_Process' ) ) :
10
11 /**
12 * CartFlows_Batch_Process
13 *
14 * @since 1.0.0
15 */
16 class CartFlows_Batch_Process {
17
18 /**
19 * Instance
20 *
21 * @since 1.0.0
22 * @var object Class object.
23 * @access private
24 */
25 private static $instance;
26
27 /**
28 * Elementor Batch Instance
29 *
30 * @since 1.1.1 Updated instance name with elementor specific.
31 *
32 * @since 1.0.0
33 * @var object Class object.
34 * @access public
35 */
36 public static $batch_instance_elementor;
37
38 /**
39 * Beaver Builder Batch Instance
40 *
41 * @since 1.1.1
42 * @var object Class object.
43 * @access public
44 */
45 public static $batch_instance_bb;
46
47 /**
48 * Divi Batch Instance
49 *
50 * @since 1.1.1
51 * @var object Class object.
52 * @access public
53 */
54 public static $batch_instance_divi;
55
56 /**
57 * Initiator
58 *
59 * @since 1.0.0
60 * @return object initialized object of class.
61 */
62 public static function get_instance() {
63 if ( ! isset( self::$instance ) ) {
64 self::$instance = new self;
65 }
66 return self::$instance;
67 }
68
69 /**
70 * Constructor
71 *
72 * @since 1.0.0
73 */
74 public function __construct() {
75
76 // Not BB or Elementor then avoid importer.
77 // if ( ! class_exists( '\Elementor\Plugin' ) && ! class_exists( 'FLBuilder' ) ) {
78 // return;
79 // }
80 // Core Helpers - Image.
81 require_once ABSPATH . 'wp-admin/includes/image.php';
82
83 // Core Helpers - Batch Processing.
84 require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-cartflows-importer-image.php';
85 require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-async-request.php';
86 require_once CARTFLOWS_DIR . 'classes/batch-process/helpers/class-wp-background-process.php';
87
88 $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
89
90 // Elementor.
91 if ( ( 'elementor' === $default_page_builder ) && class_exists( '\Elementor\Plugin' ) ) {
92 // Add "elementor" in import [queue].
93 // @todo Remove required `allow_url_fopen` support.
94 if ( ini_get( 'allow_url_fopen' ) ) {
95 require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor.php';
96 require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-elementor-batch.php';
97 self::$batch_instance_elementor = new Cartflows_Importer_Elementor_Batch();
98 }
99 }
100
101 // Beaver Builder.
102 if ( ( 'beaver-builder' === $default_page_builder ) && class_exists( 'FLBuilder' ) ) {
103 require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder.php';
104 require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-beaver-builder-batch.php';
105 self::$batch_instance_bb = new Cartflows_Importer_Beaver_Builder_Batch();
106 }
107
108 // Divi.
109 if ( ( 'divi' === $default_page_builder ) && ( class_exists( 'ET_Builder_Plugin' ) || Cartflows_Compatibility::get_instance()->is_divi_enabled() ) ) {
110 require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi.php';
111 require_once CARTFLOWS_DIR . 'classes/batch-process/class-cartflows-importer-divi-batch.php';
112 self::$batch_instance_divi = new Cartflows_Importer_Divi_Batch();
113 }
114
115 // Start image importing after site import complete.
116 add_action( 'cartflows_after_template_import', array( $this, 'start_batch_process' ) );
117 add_action( 'cartflows_import_complete', array( $this, 'complete_batch_import' ) );
118 add_filter( 'upload_mimes', array( $this, 'custom_upload_mimes' ) );
119 add_filter( 'wp_prepare_attachment_for_js', array( $this, 'add_svg_image_support' ), 10, 3 );
120 }
121
122 /**
123 * Added .svg files as supported format in the uploader.
124 *
125 * @since 1.1.4
126 *
127 * @param array $mimes Already supported mime types.
128 */
129 public function custom_upload_mimes( $mimes ) {
130
131 // Allow SVG files.
132 $mimes['svg'] = 'image/svg+xml';
133 $mimes['svgz'] = 'image/svg+xml';
134
135 // Allow XML files.
136 $mimes['xml'] = 'text/xml';
137
138 return $mimes;
139 }
140
141 /**
142 * Add SVG image support
143 *
144 * @since 1.1.4
145 *
146 * @param array $response Attachment response.
147 * @param object $attachment Attachment object.
148 * @param array $meta Attachment meta data.
149 */
150 function add_svg_image_support( $response, $attachment, $meta ) {
151 if ( ! function_exists( 'simplexml_load_file' ) ) {
152 return $response;
153 }
154
155 if ( ! empty( $response['sizes'] ) ) {
156 return $response;
157 }
158
159 if ( 'image/svg+xml' !== $response['mime'] ) {
160 return $response;
161 }
162
163 $svg_path = get_attached_file( $attachment->ID );
164
165 $dimensions = self::get_svg_dimensions( $svg_path );
166
167 $response['sizes'] = array(
168 'full' => array(
169 'url' => $response['url'],
170 'width' => $dimensions->width,
171 'height' => $dimensions->height,
172 'orientation' => $dimensions->width > $dimensions->height ? 'landscape' : 'portrait',
173 ),
174 );
175
176 return $response;
177 }
178
179 /**
180 * Get SVG Dimensions
181 *
182 * @since 1.1.4.
183 *
184 * @param string $svg SVG file path.
185 * @return array Return SVG file height & width for valid SVG file.
186 */
187 public static function get_svg_dimensions( $svg ) {
188
189 $svg = simplexml_load_file( $svg );
190
191 if ( false === $svg ) {
192 $width = '0';
193 $height = '0';
194 } else {
195 $attributes = $svg->attributes();
196 $width = (string) $attributes->width;
197 $height = (string) $attributes->height;
198 }
199
200 return (object) array(
201 'width' => $width,
202 'height' => $height,
203 );
204 }
205
206 /**
207 * Batch Process Complete.
208 *
209 * @return void
210 */
211 public function complete_batch_import() {
212 wcf()->logger->import_log( '(✓) BATCH Process Complete!' );
213 }
214
215 /**
216 * Start Image Import
217 *
218 * @param integer $post_id Post Id.
219 *
220 * @return void
221 */
222 public function start_batch_process( $post_id = '' ) {
223
224 $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' );
225
226 wcf()->logger->import_log( '(✓) BATCH Started!' );
227 wcf()->logger->import_log( '(✓) Step ID ' . $post_id );
228
229 // Add "elementor" in import [queue].
230 if ( 'beaver-builder' === $default_page_builder && self::$batch_instance_bb ) {
231
232 // Add to queue.
233 self::$batch_instance_bb->push_to_queue( $post_id );
234
235 // Dispatch Queue.
236 self::$batch_instance_bb->save()->dispatch();
237
238 wcf()->logger->import_log( '(✓) Dispatch "Beaver Builder" Request..' );
239
240 } elseif ( 'elementor' === $default_page_builder && self::$batch_instance_elementor ) {
241
242 // Add to queue.
243 self::$batch_instance_elementor->push_to_queue( $post_id );
244
245 // Dispatch Queue.
246 self::$batch_instance_elementor->save()->dispatch();
247
248 wcf()->logger->import_log( '(✓) Dispatch "Elementor" Request..' );
249 } elseif ( 'divi' === $default_page_builder && self::$batch_instance_divi ) {
250
251 // Add to queue.
252 self::$batch_instance_divi->push_to_queue( $post_id );
253
254 // Dispatch Queue.
255 self::$batch_instance_divi->save()->dispatch();
256
257 wcf()->logger->import_log( '(✓) Dispatch "Divi" Request..' );
258 } else {
259 wcf()->logger->import_log( '(✕) Could not import image due to allow_url_fopen() is disabled!' );
260 }
261 }
262
263 }
264
265 /**
266 * Kicking this off by calling 'get_instance()' method
267 */
268 CartFlows_Batch_Process::get_instance();
269
270 endif;
271