PluginProbe
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell / 2.8.16
WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell v2.8.16
3.13.3 3.13.2 3.13.1 3.13.0 3.12.13 3.12.12 3.12.11 3.12.10 3.12.9 3.12.8 3.12.7 3.12.6 3.12.5 3.12.4 3.12.3 3.12.1 3.12.2 3.12.0 3.11.1 3.11.0 3.10.9 3.10.8 3.10.7 3.10.6 2.8.16 All 261 releases
wpfunnels / admin / modules / template-library / sources / remote.php

remote.php in WPFunnels – Funnel Builder for WooCommerce with Checkout & One Click Upsell 2.8.16, at admin/modules/template-library/sources/remote.php

461 lines 14.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Remote class
4 *
5 * @package
6 */
7 namespace WPFunnels\TemplateLibrary;
8
9 use WPFunnels\API;
10 use WPFunnels\Rest\Controllers\TemplateLibraryController;
11 use WPFunnels\Wpfnl;
12 use WPFunnels\Wpfnl_functions;
13 use function cli\err;
14 use WPFunnelsPro\AbTesting\Wpfnl_Ab_Testing;
15 class Wpfnl_Source_Remote extends Wpfnl_Source_Base
16 {
17
18 /**
19 * Get souce
20 *
21 * @return String
22 */
23 public function get_source()
24 {
25 return 'remote';
26 }
27
28 /**
29 * Get funnels
30 *
31 * @return Obj
32 */
33 public function get_funnels($arg = [])
34 {
35 return API::get_funnels_data($arg);
36 }
37
38
39 /**
40 * Get funnel
41 */
42 public function get_funnel($template_id)
43 {
44 }
45
46 /**
47 * Get data
48 *
49 * @param Array $args
50 *
51 * @return String
52 */
53 public function get_data(array $args)
54 {
55 }
56
57
58 /**
59 * Import funnel
60 *
61 * @param array $args
62 *
63 * @return array
64 */
65 public function import_funnel($args = [])
66 {
67 $funnel = Wpfnl::$instance->funnel_store;
68 $funnel_id = $funnel->create();
69 $funnel->update_meta($funnel_id, '_is_imported', 'yes');
70
71 if( $funnel_id ){
72 $general_settings = get_option( '_wpfunnels_general_settings' );
73 if( isset( $general_settings['funnel_type'] ) ){
74 if( 'woocommerce' == $general_settings['funnel_type'] ){
75 $general_settings['funnel_type'] = 'sales';
76 update_option( '_wpfunnels_general_settings', $general_settings );
77 }
78 if( 'sales' == $general_settings['funnel_type'] ){
79 if( Wpfnl_functions::is_lms_addon_active() && isset($args['type']) && 'lms' === $args['type'] ){
80 update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'lms' );
81 } elseif( Wpfnl_functions::is_wc_active() && isset($args['type']) && 'wc' === $args['type'] ){
82 update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'wc' );
83 } elseif( isset($args['type']) && 'lead' === $args['type'] ){
84 update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'lead' );
85 }
86 }else{
87 if( isset($args['type']) && 'lead' === $args['type'] ){
88 update_post_meta( $funnel_id, '_wpfnl_funnel_type', 'lead' );
89 }
90 }
91 }
92 }
93
94
95 $remote_id = isset($args['remoteID']) ? $args['remoteID'] : 0;
96 if ( !$remote_id ) {
97 return array(
98 'success' => false,
99 );
100 }
101 $response = TemplateLibraryController::get_funnel( $remote_id );
102 $funnel_data = $response['funnel_data'];
103 update_post_meta( $funnel_id, 'funnel_data', $funnel_data );
104
105 $funnel_title = isset($args['name']) ? $args['name'] : '';
106 $params = array(
107 'ID' => $funnel_id,
108 'post_title' => $funnel_title,
109 'post_name' => sanitize_title($funnel_title),
110 );
111 wp_update_post($params);
112 return [
113 'success' => true,
114 'funnelID' => $funnel_id,
115 ];
116 }
117
118
119 /**
120 * Import step
121 *
122 * @param array $args
123 *
124 * @return array
125 */
126 public function import_step( $args = [] )
127 {
128 if (empty($args['funnelID'])) {
129 return [
130 'success' => true,
131 'message' => __('No funnel id found', 'wpfnl'),
132 ];
133 }
134 do_action('wpfunnel_step_import_start');
135 $response = TemplateLibraryController::get_step($args['step']['ID']);
136
137 $title = $response['title'];
138 $post_content = $response['content'];
139 $post_metas = $response['post_meta'];
140 $builder = Wpfnl_functions::get_builder_type();
141
142 $step = Wpfnl::$instance->step_store;
143 $step_id = $step->create_step($args['funnelID'], $title, $args['step']['step_type'], $post_content);
144 $step->import_metas($step_id, $post_metas);
145
146
147 // re-signing the shortcode signature keys if builder type is oxygen
148 if( 'oxygen' === Wpfnl_functions::get_builder_type() ) {
149 $ct_shortcodes = get_post_meta( $step_id, 'ct_builder_shortcodes', true );
150 $ct_shortcodes = parse_shortcodes($ct_shortcodes, false, false);
151 $shortcodes = parse_components_tree($ct_shortcodes['content']);
152 update_post_meta($step_id, 'ct_builder_shortcodes', $shortcodes);
153 }
154
155 if ( 'divi-builder' === Wpfnl_functions::get_builder_type() ) {
156 if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
157 update_post_meta( $step_id, 'divi_content', $response['data']['divi_content'] );
158 wp_update_post(
159 array(
160 'ID' => $step_id,
161 'post_content' => $response['data']['divi_content']
162 )
163 );
164 }
165 }
166
167 if ( 'gutenberg' === Wpfnl_functions::get_builder_type() ) {
168 if ( isset( $response['data']['rawData'] ) && ! empty( $response['data']['rawData'] ) ) {
169 wp_update_post(
170 array(
171 'ID' => $step_id,
172 'post_content' => $response['data']['rawData']
173 )
174 );
175 }
176 }
177
178 $funnel = Wpfnl::$instance->funnel_store;
179 $funnel->set_id($args['funnelID']);
180 $funnel->set_steps_order();
181 $funnel->save_steps_order( $step_id, $args['step']['step_type'], $title );
182
183 if( isset($args['importType']) && $args['importType'] === 'templates' ) {
184 $this->update_step_id_in_funnel_data_and_identifier( $args['step']['ID'], $step_id, $args );
185 }
186 do_action('wpfunnels/update_ab_testing_start_settings', $step_id);
187 do_action('wpfunnels_step_import_complete');
188 do_action('wpfunnels_after_step_import', $step_id, $builder);
189 update_post_meta($step_id, '_wp_page_template', 'wpfunnels_default');
190
191 $funnel_id = Wpfnl_functions::get_funnel_id_from_step( $step_id );
192 $utm_settings = Wpfnl_functions::get_funnel_utm_settings( $funnel_id );
193 $view_link = get_post_permalink( $step_id );
194
195 if ( $utm_settings[ 'utm_enable' ] == 'on' ) {
196 unset( $utm_settings[ 'utm_enable' ] );
197 $view_link = add_query_arg( $utm_settings, $view_link );
198 $view_link = strtolower( $view_link );
199 }
200
201 return [
202 'success' => true,
203 'stepID' => $step_id,
204 'stepEditLink' => get_edit_post_link( $step_id ),
205 'stepViewLink' => $view_link,
206 'abTestingSettingsData' => $this->get_default_start_setting( $step_id ),
207 ];
208
209
210 }
211
212 /**
213 * Import variation step
214 *
215 * @param Array $args
216 *
217 * @return Array
218 */
219 public function import_variation_step( $args = [] )
220 {
221 if (empty($args['funnelID'])) {
222 return [
223 'success' => true,
224 'message' => __('No funnel id found', 'wpfnl'),
225 ];
226 }
227 do_action('wpfunnel_step_import_start');
228 $response = TemplateLibraryController::get_step($args['step']['id']);
229
230 $title = isset($args['step_name']) ? $args['step_name'] : $response['title'];
231 $post_content = $response['content'];
232 $post_metas = $response['post_meta'];
233
234 $builder = Wpfnl_functions::get_builder_type();
235
236 $step = Wpfnl::$instance->step_store;
237 $step_id = $step->create_step($args['funnelID'], $title, $args['step']['step_type'], $post_content,false);
238 $step->import_metas($step_id, $post_metas);
239
240 if( 'oxygen' === Wpfnl_functions::get_builder_type() ) {
241 $ct_shortcodes = get_post_meta( $step_id, 'ct_builder_shortcodes', true );
242 $ct_shortcodes = parse_shortcodes($ct_shortcodes, false, false);
243 $shortcodes = parse_components_tree($ct_shortcodes['content']);
244 update_post_meta($step_id, 'ct_builder_shortcodes', $shortcodes);
245 }
246
247 if ( 'divi-builder' === Wpfnl_functions::get_builder_type() ) {
248 if ( isset( $response['data']['divi_content'] ) && ! empty( $response['data']['divi_content'] ) ) {
249 update_post_meta( $step_id, 'divi_content', $response['data']['divi_content'] );
250 wp_update_post(
251 array(
252 'ID' => $step_id,
253 'post_content' => $response['data']['divi_content']
254 )
255 );
256 }
257 }
258
259 if ( 'gutenberg' === Wpfnl_functions::get_builder_type() ) {
260 if ( isset( $response['data']['rawData'] ) && ! empty( $response['data']['rawData'] ) ) {
261 wp_update_post(
262 array(
263 'ID' => $step_id,
264 'post_content' => $response['data']['rawData']
265 )
266 );
267 }
268 }
269
270 $funnel = Wpfnl::$instance->funnel_store;
271 $funnel->set_id($args['funnelID']);
272 $funnel->set_steps_order();
273 $funnel->save_steps_order( $step_id, $args['step']['step_type'], $title );
274
275
276 if( isset($args['importType']) && $args['importType'] === 'templates' ) {
277 $this->update_step_id_in_funnel_data_and_identifier( $args['step']['id'], $step_id, $args );
278 }
279
280 $funnel_data = get_post_meta( $args['funnelID'], 'funnel_data', true );
281 $steps = $funnel_data['drawflow']['Home']['data'];
282 foreach ( $steps as $key => $step_data ) {
283 $node_data = $step_data['data'];
284 if ( 'conditional' != $node_data['step_type'] && $step_id == $node_data['step_id'] ) {
285 $step_data['class'] = $step_data['class'].'-'.'has-ab-variation';
286 $funnel_data['drawflow']['Home']['data'][$key] = $step_data;
287 }
288 }
289 update_post_meta($args['funnelID'], 'funnel_data', $funnel_data);
290
291 /**
292 * Update ab testig settings
293 *
294 * @param Integer $args['step_id'] - this is parent step id
295 * @param Integer $step_id - this is parent variant id
296 */
297 do_action('wpfunnels/update_ab_testing_settings', $args['step_id'], $step_id );
298 do_action('wpfunnels_step_import_complete');
299 do_action('wpfunnels_after_step_import', $step_id, $builder);
300 update_post_meta($step_id, '_wp_page_template', 'wpfunnels_default');
301
302 $response = [
303 'success' => true,
304 'stepID' => $step_id,
305 'stepEditLink' => get_edit_post_link($step_id),
306 'stepViewLink' => get_permalink($step_id),
307 ];
308
309 return apply_filters('wpfunnels/modify_import_variant_response', $response, $args['step_id'] );
310
311 }
312
313
314 /**
315 * Get default start settings
316 */
317 private function get_default_start_setting( $step_id ){
318 $step_edit_link = get_edit_post_link($step_id);
319
320 $funnel_id = Wpfnl_functions::get_funnel_id_from_step( $step_id );
321 $utm_settings = Wpfnl_functions::get_funnel_utm_settings( $funnel_id );
322 $view_link = get_post_permalink( $step_id );
323
324 if ( $utm_settings[ 'utm_enable' ] == 'on' ) {
325 unset( $utm_settings[ 'utm_enable' ] );
326 $view_link = add_query_arg( $utm_settings, $view_link );
327 $view_link = strtolower( $view_link );
328 }
329
330 if( 'elementor' == Wpfnl_functions::get_builder_type() ){
331 $step_edit_link = str_replace('/&amp;/g','&',$step_edit_link);
332 $step_edit_link = str_replace('edit','elementor',$step_edit_link);
333 }
334
335 $default_settings = [
336 'is_ab_enabled' => '',
337 'start_settings' => [
338 'auto_winner' => [
339 'is_enabled' => '',
340 'conditions' => [
341 'index' => 'trafiic',
342 'value' => 70
343 ]
344 ],
345 'winner' => '',
346 'is_started' => '',
347 'start_date' => date( 'Y-m-d H:i:s' ),
348 'variations' => [
349 [
350 'id' => $step_id,
351 'traffic' => 100,
352 'step_type'=> get_post_meta($step_id,'_step_type',true),
353 'variation_type' => 'original',
354 'step_edit_link' => $step_edit_link,
355 'step_view_link' => $view_link,
356 'step_title' => get_the_title($step_id),
357 'conversion' => 0,
358 'visit' => 0,
359 'shouldShowAnalytics' => false,
360 ],
361 ],
362 ]
363
364 ];
365
366 return $default_settings;
367 }
368
369
370 /**
371 * Update funnel identifier
372 *
373 * @param $remote_step
374 * @param $new_step
375 * @param $args
376 *
377 * @return void
378 */
379 public function update_step_id_in_funnel_data_and_identifier( $remote_step, $new_step, $args )
380 {
381 $funnel_id = $args['funnelID'];
382 $funnel_identifier = array();
383 $funnel_data = array();
384 $funnel_json = get_post_meta( $funnel_id, 'funnel_data', true );
385 if ($funnel_json) {
386 if(is_array($funnel_json)) {
387 $funnel_data = $funnel_json;
388 } else {
389 $funnel_data = json_decode($funnel_json,1);
390 }
391 $node_data = $funnel_data['drawflow']['Home']['data'];
392 foreach ($node_data as $node_key => $node_value) {
393 if ( isset($node_value['data']['step_id']) && $node_value['data']['step_id'] == $remote_step ) {
394 $post_edit_link = base64_encode(get_edit_post_link($new_step));
395 $post_view_link = base64_encode(get_post_permalink($new_step));
396 $funnel_data['drawflow']['Home']['data'][$node_key]['data']['step_id'] = $new_step;
397 $funnel_data['drawflow']['Home']['data'][$node_key]['data']['step_edit_link'] = $post_edit_link;
398 $funnel_data['drawflow']['Home']['data'][$node_key]['data']['step_view_link'] = $post_view_link;
399 $funnel_data['drawflow']['Home']['data'][$node_key]['html'] = $node_value['data']['step_type'] . $new_step;
400 $funnel_identifier[$node_value['id']] = $new_step;
401 } else {
402 if ($node_value['data']['step_type'] != 'conditional') {
403 $funnel_identifier[$node_value['id']] = $node_value['data']['step_id'];
404 } else {
405 $funnel_identifier[$node_value['id']] = $node_value['data']['node_identifier'];
406 }
407 }
408 }
409 }
410
411 if ( $funnel_data ) {
412 update_post_meta($funnel_id, 'funnel_data', $funnel_data);
413
414 /**
415 * Save steps data
416 */
417 $steps = $this->get_steps( $funnel_data );
418 update_post_meta( $funnel_id, '_steps', $steps );
419 Wpfnl_functions::generate_first_step( $funnel_id, $steps );
420 }
421
422 if ($funnel_identifier) {
423 $funnel_identifier_json = json_encode($funnel_identifier, JSON_UNESCAPED_SLASHES);
424 update_post_meta($funnel_id, 'funnel_identifier', $funnel_identifier_json);
425 }
426 }
427
428
429 /**
430 * Get steps
431 *
432 * @param $funnel_flow_data
433 *
434 * @return array
435 *
436 * @since 2.0.5
437 */
438 private function get_steps( $funnel_flow_data ) {
439 $drawflow = $funnel_flow_data['drawflow'];
440 $steps = array();
441 if( isset( $drawflow['Home']['data'] ) ) {
442 $drawflow_data = $drawflow['Home']['data'];
443 foreach ( $drawflow_data as $key => $data ) {
444 $step_data = $data['data'];
445 $step_type = $step_data['step_type'];
446 if('conditional' !== $step_type) {
447 $step_id = $step_data['step_id'];
448 $step_name = sanitize_text_field(get_the_title($step_data['step_id']));
449 $steps[] = array(
450 'id' => $step_id,
451 'step_type' => $step_type,
452 'name' => $step_name,
453 );
454 }
455
456 }
457 }
458 return $steps;
459 }
460 }
461