PluginProbe
WDesignKit – AI Templates, Widget Builder & MCP Workflow / 1.0.21
WDesignKit – AI Templates, Widget Builder & MCP Workflow v1.0.21
2.6.6 2.6.5 2.6.4 2.6.3 2.6.2 2.6.1 2.6.0 2.5.5 2.5.4 2.5.3 2.5.2 2.5.1 2.5.0 2.4.0 2.3.3 2.3.2 2.3.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 All 128 releases
wdesignkit / includes / admin / class-api.php

class-api.php in WDesignKit – AI Templates, Widget Builder & MCP Workflow 1.0.21, at includes/admin/class-api.php

3,206 lines 104.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The file that defines the core plugin class
4 *
5 * @link https://posimyth.com/
6 * @since 1.0.0
7 *
8 * @package Wdesignkit
9 * @subpackage Wdesignkit/includes
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 use wdkit\Wdkit_Wdesignkit;
17 use wdkit\WdKit_enqueue\Wdkit_Enqueue;
18 use wdkit\wdkit_datahooks\Wdkit_Data_Hooks;
19
20 if ( ! class_exists( 'Wdkit_Api_Call' ) ) {
21
22 /**
23 * Main classs call for all api
24 *
25 * @link https://posimyth.com/
26 * @since 1.0.0
27 */
28 class Wdkit_Api_Call {
29
30 /**
31 * Member Variable
32 *
33 * @var instance
34 */
35 private static $instance;
36
37 /**
38 * Member Variable
39 *
40 * @var staring $wdkit_api
41 */
42 public $wdkit_api = WDKIT_SERVER_SITE_URL . 'api/wp/';
43
44 /**
45 * Member Variable
46 *
47 * @var staring $widget_folder_u_r_l
48 */
49 public $widget_folder_u_r_l = '';
50
51 /**
52 * Member Variable
53 *
54 * @var staring $e_msg_login
55 */
56 public $e_msg_login = 'Login Error: Check your details and try again.';
57
58 /**
59 * Member Variable
60 *
61 * @var staring $e_desc_login
62 */
63 public $e_desc_login = 'Invalid Login Details';
64
65 /**
66 * Member Variable
67 *
68 * @var staring wdkit_onbording_api
69 */
70 public $wdkit_onbording_api = 'https://api.posimyth.com/wp-json/wdkit/v2/wdkit_store_user_data';
71
72 /**
73 * Member Variable
74 *
75 * @var staring wdkit_onbording_end
76 */
77 public $wdkit_onbording_end = 'wkit_onbording_end';
78
79 /**
80 * Initiator
81 */
82 public static function get_instance() {
83 if ( ! isset( self::$instance ) ) {
84 self::$instance = new self();
85 }
86
87 return self::$instance;
88 }
89
90 /**
91 * Define the core functionality of the plugin.
92 */
93 public function __construct() {
94 add_action( 'wp_ajax_get_wdesignkit', array( $this, 'wdkit_api_call' ) );
95 }
96
97 /**
98 * Error JSON message
99 *
100 * @param array $data give array.
101 * @param string $status api code number.
102 * */
103 public function wdkit_error_msg( $data = null, $status = null ) {
104 wp_send_json_error( $data );
105 wp_die();
106 }
107
108 /**
109 * Success JSON message
110 *
111 * @param array $data give array.
112 * @param string $status api code number.
113 * */
114 public function wdkit_success_msg( $data = null, $status = null ) {
115 wp_send_json_success( $data, $status );
116 wp_die();
117 }
118
119 /**
120 * Get Wdkit Api Call Ajax.
121 */
122 public function wdkit_api_call() {
123
124 check_ajax_referer( 'wdkit_nonce', 'kit_nonce' );
125
126 if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
127 wp_send_json_error( array( 'content' => __( 'Insufficient permissions.', 'wdesignkit' ) ) );
128 }
129
130 $type = isset( $_POST['type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['type'] ) ) ) : false;
131 if ( ! $type ) {
132 $this->wdkit_error_msg( __( 'Something went wrong.', 'wdesignkit' ) );
133 }
134
135 switch ( $type ) {
136 case 'onboarding_handler':
137 $data = $this->wdkit_onboarding_handler();
138 break;
139 case 'wkit_login':
140 $data = $this->wdkit_login();
141 break;
142 case 'api_login':
143 $data = $this->wdkit_api_login();
144 break;
145 case 'social_login':
146 $data = $this->wdkit_social_login();
147 break;
148 case 'wkit_meta_data':
149 $data = $this->wdkit_meta_data();
150 break;
151 case 'get_user_info':
152 $id = isset( $_POST['id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['id'] ) ) ) : false;
153 $data = $this->wdkit_get_user_info();
154 break;
155 case 'browse_page':
156 $data = $this->wdkit_browse_page();
157 break;
158 case 'widget_browse_page':
159 $data = $this->wdkit_widget_browse_page();
160 break;
161 case 'kit_template':
162 $id = isset( $_POST['id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['id'] ) ) ) : false;
163 $data = $this->wdkit_template();
164 break;
165 case 'template_remove':
166 $data = $this->wdkit_template_remove();
167 break;
168 case 'save_template':
169 $data = $this->wdkit_put_save_template();
170 break;
171 case 'find_template':
172 $data = $this->wdkit_find_existing_template();
173 break;
174 case 'update_template':
175 $data = $this->wdkit_update_template();
176 break;
177 case 'manage_favorite':
178 $data = $this->wdkit_manage_favorite();
179 break;
180 case 'check_plugins_depends':
181 $data = $this->wdkit_check_plugins_depends();
182 break;
183 case 'install_plugins_depends':
184 $data = $this->wdkit_install_plugins_depends();
185 break;
186 case 'update_latest_plugin':
187 $data = $this->wdkit_update_latest_plugin();
188 break;
189 case 'import_template':
190 $data = $this->wdkit_import_template();
191 break;
192 case 'import_multi_template':
193 $data = $this->wdkit_import_multi_template();
194 break;
195 case 'import_kit_template':
196 $data = $this->wdkit_import_kit_template();
197 break;
198 case 'shared_with_me':
199 $data = $this->wdkit_shared_with_me();
200 break;
201 case 'manage_workspace':
202 $data = $this->wdkit_manage_workspace();
203 break;
204 case 'wkit_manage_widget_workspace':
205 $data = $this->wdkit_manage_widget_workspace();
206 break;
207 case 'wkit_activate_key':
208 $data = $this->wdkit_activate_key();
209 break;
210 case 'wkit_manage_widget_category':
211 $data = $this->wdkit_manage_widget_category();
212 break;
213 case 'wkit_create_widget':
214 $data = $this->wdkit_create_widget();
215 break;
216 case 'wkit_export_widget':
217 $data = $this->wdkit_export_widget();
218 break;
219 case 'wkit_import_widget':
220 $data = $this->wdkit_import_widget();
221 break;
222 case 'wkit_delete_widget':
223 $data = $this->wdkit_delete_widget();
224 break;
225 case 'wkit_download_widget':
226 $data = $this->wdkit_download_widget();
227 break;
228 case 'wkit_public_download_widget':
229 $data = $this->wdkit_public_download_widget();
230 break;
231 case 'wkit_add_widget':
232 $data = $this->wdkit_add_widget();
233 break;
234 case 'wkit_favourite_widget':
235 $data = $this->wdkit_favourite_widget();
236 break;
237 case 'wkit_setting_panel':
238 $data = $this->wdkit_setting_panel();
239 break;
240 case 'media_import':
241 $data = $this->wdkit_media_import();
242 break;
243 case 'active_licence':
244 $data = $this->wdkit_activate_licence();
245 break;
246 case 'delete_licence':
247 $data = $this->wdkit_delete_licence_key();
248 break;
249 case 'sync_licence':
250 $data = $this->wdkit_sync_licence_key();
251 break;
252 case 'wkit_logout':
253 $data = $this->wdkit_logout();
254 break;
255 }
256
257 $this->wdkit_success_msg( $data );
258 }
259
260 /**
261 *
262 * This Function is used for API call
263 *
264 * @since 1.0.0
265 *
266 * @param array $data give array.
267 * @param array $name store data.
268 */
269 protected function wkit_api_call( $data, $name ) {
270 $u_r_l = $this->wdkit_api;
271
272 if ( empty( $u_r_l ) ) {
273 return array(
274 'massage' => esc_html__( 'API Not Found', 'wdesignkit' ),
275 'success' => false,
276 );
277 }
278
279 $args = array(
280 'method' => 'POST',
281 'body' => $data,
282 'timeout' => 100,
283 );
284 $response = wp_remote_post( $u_r_l . $name, $args );
285
286 if ( is_wp_error( $response ) ) {
287 $error_message = $response->get_error_message();
288
289 /* Translators: %s is a placeholder for the error message */
290 $error_message = printf( esc_html__( 'API request error: %s', 'wdesignkit' ), esc_html( $error_message ) );
291
292 return array(
293 'massage' => $error_message,
294 'success' => false,
295 );
296 }
297
298 $status_code = wp_remote_retrieve_response_code( $response );
299 if ( 200 === $status_code ) {
300
301 return array(
302 'data' => json_decode( wp_remote_retrieve_body( $response ) ),
303 'massage' => esc_html__( 'Success', 'wdesignkit' ),
304 'status' => $status_code,
305 'success' => true,
306 );
307 }
308
309 $error_message = printf( 'Server error: %d', esc_html( $status_code ) );
310
311 if ( isset( $error_data->message ) ) {
312 $error_message .= ' (' . $error_data->message . ')';
313 }
314
315 return array(
316 'massage' => $error_message,
317 'status' => $status_code,
318 'success' => false,
319 );
320 }
321
322 /**
323 * This Function is used for API call
324 *
325 * @since 1.0.0
326 *
327 * @param string $user_key Dynamic key.
328 * @param string $user_email User email.
329 * @param string $token User token.
330 */
331 protected function wdkit_set_time_out( $user_key, $user_email, $token, $login_type = '' ) {
332
333 if ( 'normal' === $login_type ) {
334 set_transient(
335 'wdkit_auth_' . $user_key,
336 array(
337 'user_email' => sanitize_email( $user_email ),
338 'token' => $token,
339 ),
340 7776000
341 );
342 } else {
343 set_transient(
344 'wdkit_auth_' . $user_key,
345 array(
346 'user_email' => sanitize_email( $user_email ),
347 'token' => $token,
348 ),
349 86400
350 );
351 }
352 }
353
354 /**
355 *
356 * It is Use for handle onboarding data.
357 *
358 * @since 1.0.9
359 */
360 public function wdkit_onboarding_handler() {
361 $page_template = isset( $_POST['page_template'] ) ? json_decode( wp_unslash( $_POST['page_template'] ), true ) : '';
362 $page_builder = isset( $_POST['page_builder'] ) ? json_decode( wp_unslash( $_POST['page_builder'] ), true ) : '';
363
364 $elementor_plugin = isset( $_POST['elementor_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['elementor_plugin'] ) ) : 0;
365 $tpag_plugin = isset( $_POST['tpag_plugin'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['tpag_plugin'] ) ) : 0;
366 $bricks_theme = isset( $_POST['bricks_theme'] ) ? (int) sanitize_text_field( wp_unslash( $_POST['bricks_theme'] ) ) : 0;
367
368 $server_software = ! empty( $_SERVER['SERVER_SOFTWARE'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_SOFTWARE'] ) ) : '';
369
370 $web_server = $server_software;
371 $memory_limit = ini_get( 'memory_limit' );
372 $max_execution_time = ini_get( 'max_execution_time' );
373 $php_version = phpversion();
374 $wp_version = get_bloginfo( 'version' );
375 $email = get_option( 'admin_email' );
376 $siteurl = get_option( 'siteurl' );
377 $language = get_bloginfo( 'language' );
378
379 // Active Plugin Name.
380 $act_plugin = array();
381 $actplu = get_option( 'active_plugins' );
382 if ( ! function_exists( 'get_plugins' ) ) {
383 require_once ABSPATH . 'wp-admin/includes/plugin.php';
384 }
385
386 $plugins = get_plugins();
387 foreach ( $actplu as $p ) {
388 if ( isset( $plugins[ $p ] ) ) {
389 $act_plugin[] = $plugins[ $p ]['Name'];
390 }
391 }
392
393 $plugin = wp_json_encode( $act_plugin );
394
395 $theme = '';
396 $acthemeobj = wp_get_theme();
397 if ( $acthemeobj->get( 'Name' ) !== null && ! empty( $acthemeobj->get( 'Name' ) ) ) {
398 $theme = $acthemeobj->get( 'Name' );
399 }
400
401 $basic_requirements = array(
402 'elementor_install' => $elementor_plugin,
403 'tpag_install' => $tpag_plugin,
404 'bricks_install' => $bricks_theme,
405 );
406
407 $final = array(
408 'web_server' => $web_server,
409 'memory_limit' => $memory_limit,
410 'max_execution_time' => $max_execution_time,
411 'php_version' => $php_version,
412 'wp_version' => $wp_version,
413 'email' => $email,
414 'site_url' => $siteurl,
415 'site_language' => $language,
416 'theme' => $theme,
417 'plugins' => $act_plugin,
418 'basic_requirements' => $basic_requirements,
419 'page_template' => $page_template,
420 'page_builder' => $page_builder,
421 );
422
423 $response = wp_remote_post(
424 $this->wdkit_onbording_api,
425 array(
426 'method' => 'POST',
427 'body' => wp_json_encode( $final ),
428 )
429 );
430
431 $existing_value = get_option( $this->wdkit_onbording_end );
432 if ( false === $existing_value ) {
433 add_option( $this->wdkit_onbording_end, true );
434 }
435
436 if ( is_wp_error( $response ) ) {
437 $result = array(
438 'success' => false,
439 'messages' => 'Oops',
440 'description' => 'Description',
441 );
442
443 wp_send_json( $result );
444 } else {
445 $status_one = wp_remote_retrieve_response_code( $response );
446
447 if ( 200 === $status_one ) {
448 $get_data_one = wp_remote_retrieve_body( $response );
449
450 $get_res = json_decode( json_decode( $get_data_one, true ), true );
451
452 $result = array(
453 'success' => ! empty( $get_res['success'] ) ? $get_res['success'] : false,
454 'messages' => ! empty( $get_res['messages'] ) ? $get_res['messages'] : 'success',
455 'description' => ! empty( $get_res['description'] ) ? $get_res['description'] : 'Description',
456 );
457
458 wp_send_json( $result );
459 } else {
460
461 $result = array(
462 'success' => false,
463 'messages' => 'Oops',
464 'description' => 'description',
465 );
466
467 wp_send_json( $result );
468 }
469 }
470
471 wp_die();
472 }
473
474 /**
475 *
476 * It is Use for user login with email and password.
477 *
478 * @since 1.0.0
479 */
480 protected function wdkit_login() {
481 $user_email = isset( $_POST['user_email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['user_email'] ) ) ) : false;
482 $user_password = isset( $_POST['user_password'] ) ? sanitize_text_field( wp_unslash( $_POST['user_password'] ) ) : false;
483 $login_type = isset( $_POST['login_type'] ) ? sanitize_text_field( wp_unslash( $_POST['login_type'] ) ) : false;
484 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
485
486 $user_key = strstr( $user_email, '@', true );
487 $response = '';
488
489 delete_transient( 'wdkit_auth_' . $user_key );
490
491 $get_login = get_transient( 'wdkit_auth_' . $user_key );
492
493 if ( ! empty( $user_email ) && ! empty( $user_password ) && false === $get_login ) {
494 $response = WDesignKit_Data_Query::get_data(
495 'login',
496 array(
497 'user_email' => $user_email,
498 'password' => $user_password,
499 'site_url' => $site_url,
500 )
501 );
502
503 if ( ! empty( $response ) && ! empty( $response['success'] ) ) {
504 if ( ! empty( $response['message'] ) && ! empty( $response['token'] ) ) {
505 if ( false === get_transient( 'wdkit_auth_' . $user_key ) ) {
506 $this->wdkit_set_time_out( $user_key, $user_email, $response['token'], $login_type );
507 }
508 }
509 }
510 } elseif ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) {
511 $response = array_merge(
512 array(
513 'success' => true,
514 'message' => esc_html__( 'Success! Login successful.', 'wdesignkit' ),
515 'description' => esc_html__( 'Login successful. Keep it up!', 'wdesignkit' ),
516 ),
517 $get_login
518 );
519 }
520
521 wp_send_json( $response );
522 wp_die();
523 }
524
525 /**
526 *
527 * This Function is used for Login with Api (token)
528 *
529 * @version 1.0.0
530 */
531 protected function wdkit_api_login() {
532 $user_token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
533 $login_type = isset( $_POST['login_type'] ) ? sanitize_text_field( wp_unslash( $_POST['login_type'] ) ) : '';
534
535 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
536
537 if ( empty( $user_token ) ) {
538 $result = array(
539 'success' => false,
540 'token' => '',
541 'data' => array(
542 'message' => $this->e_msg_login,
543 'description' => $this->e_desc_login,
544 ),
545 );
546
547 wp_send_json( $result );
548 wp_die();
549 }
550
551 $array_data = array(
552 'token' => $user_token,
553 'site_url' => $site_url,
554 );
555
556 $response = $this->wkit_api_call( $array_data, 'login/api' );
557
558 $success = ! empty( $response['success'] ) ? is_bool( $response['success'] ) : false;
559
560 if ( empty( $success ) ) {
561 $result = array(
562 'data' => $response,
563 'token' => '',
564 'success' => false,
565 );
566
567 wp_send_json( $result );
568 wp_die();
569 }
570
571 $response = json_decode( wp_json_encode( $response['data'] ), true );
572 $user_email = ! empty( $response['user']['user_email'] ) ? sanitize_email( $response['user']['user_email'] ) : '';
573 $user_key = strstr( $user_email, '@', true );
574
575 $this->wdkit_set_time_out( $user_key, $user_email, $user_token, $login_type );
576
577 $result = array(
578 'success' => true,
579 'data' => $response,
580 'token' => $user_token,
581 );
582
583 wp_send_json( $result );
584 wp_die();
585 }
586
587 /**
588 *
589 * This Function is used for social Login
590 *
591 * @version 1.0.0
592 */
593 protected function wdkit_social_login() {
594 $user_state = isset( $_POST['state'] ) ? sanitize_text_field( wp_unslash( $_POST['state'] ) ) : '';
595 $login_type = isset( $_POST['login_type'] ) ? sanitize_text_field( wp_unslash( $_POST['login_type'] ) ) : '';
596
597 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
598
599 $array_data = array(
600 'state' => $user_state,
601 'site_url' => $site_url,
602 );
603
604 $response = $this->wkit_api_call( $array_data, 'login/ip' );
605 $success = ! empty( $response['success'] ) ? $response['success'] : false;
606
607 if ( empty( $success ) ) {
608 $result = array(
609 'data' => $response,
610 'success' => false,
611 );
612
613 wp_send_json( $result );
614 wp_die();
615 }
616
617 $response = json_decode( wp_json_encode( $response['data'] ), true );
618 $user_email = ! empty( $response['user']['user_email'] ) ? sanitize_email( $response['user']['user_email'] ) : '';
619 $user_token = ! empty( $response['token'] ) ? sanitize_text_field( $response['token'] ) : '';
620 $user_key = strstr( $user_email, '@', true );
621
622 if ( ! empty( $response ) && ! empty( $user_token ) ) {
623 $this->wdkit_set_time_out( $user_key, $user_email, $user_token, $login_type );
624 }
625
626 $result = array(
627 'data' => $response,
628 'token' => $user_token,
629 );
630
631 wp_send_json( $result );
632 wp_die();
633 }
634
635 /**
636 *
637 * It is Use for get meta data for non login user
638 *
639 * @since 1.0.0\
640 */
641 protected function wdkit_meta_data() {
642 $type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : '';
643 $data = array( 'type' => $type );
644
645 $response = $this->wkit_api_call( $data, 'meta' );
646 $success = ! empty( $response['success'] ) ? $response['success'] : false;
647 $status = ! empty( $response['status'] ) ? (int) $response['status'] : 400;
648
649 if ( empty( $success ) ) {
650 $result = array(
651 'plugin' => array(),
652 'builder' => array(),
653 'category' => array(),
654 'widgetscategory' => array(),
655 'tags' => array(),
656 'widgetbuilder' => array(),
657
658 'message' => esc_html__( 'Server Error', 'wdesignkit' ),
659 'description' => esc_html__( 'Server Error, Data Not Found', 'wdesignkit' ),
660 'success' => false,
661 );
662
663 wp_send_json( $result );
664 wp_die();
665 }
666
667 $get_data_one = ! empty( $response['data'] ) ? $response['data'] : array();
668 $statuscode = array( 'HTTP_CODE' => $status );
669
670 $final = json_decode( wp_json_encode( $get_data_one ), true );
671
672 $final['Setting'] = self::wkit_get_settings_panel();
673 $final['widget_list'] = $this->wkit_manage_widget_sequence( array() );
674
675 $final = array(
676 'data' => $final,
677 );
678
679 wp_send_json( $final );
680 wp_die();
681 }
682
683 /**
684 *
685 * It is Use for get all info of user.
686 *
687 * @since 1.0.0
688 */
689 protected function wdkit_get_user_info() {
690 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
691 $builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : '';
692
693 $site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : '';
694
695 $response = array();
696
697 if ( empty( $email ) ) {
698 $response = array(
699 'success' => false,
700 'message' => $this->e_msg_login,
701 'description' => $this->e_desc_login,
702 );
703
704 wp_send_json( $response );
705 wp_die();
706 }
707
708 $token = $this->wdkit_login_user_token( $email );
709 $args = array(
710 'token' => $token,
711 'builder' => $builder,
712 'site_url' => $site_url,
713 );
714
715 $response = WDesignKit_Data_Query::get_data( 'get_user_info', $args );
716 $status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error';
717 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
718
719 /**Condtion user for user logout & expire token*/
720 if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) {
721 delete_transient( 'wdkit_auth_' . $email );
722 }
723
724 $response['Setting'] = $this->wkit_get_settings_panel();
725 $response['widget_list'] = $this->wkit_manage_widget_sequence( $response );
726
727 $response = array(
728 'data' => $response,
729 'success' => true,
730 );
731
732 wp_send_json( $response );
733 wp_die();
734 }
735
736 /**
737 *
738 * It is Use for get all widgets local and server.
739 *
740 * @since 1.0.19
741 * @param string $response userinfo store.
742 */
743 protected function wkit_manage_widget_sequence( $response = array() ) {
744
745 $credits = ! empty( $response['credits']['widget_limit']['meta_value'] ) ? $response['credits']['widget_limit']['meta_value'] : 10;
746 $server_list = ! empty( $response['widgettemplate'] ) ? $response['widgettemplate'] : array();
747 $db_builder_list = ! empty( $response['widgetbuilder'] ) ? $response['widgetbuilder'] : array();
748
749 $placeholderimg = WDKIT_URL . 'assets/images/placeholder.jpg';
750
751 $local_list = $this->wdkit_get_local_widgets();
752
753 $server_w_unique = array_column( $server_list, 'w_unique' );
754
755 $idx_builder = array();
756 foreach ( $db_builder_list as $index => $value ) {
757 $builder_name = ! empty( $value['builder_name'] ) ? $value['builder_name'] : '';
758 $w_id = ! empty( $value['w_id'] ) ? $value['w_id'] : '';
759
760 if ( ! empty( $builder_name ) ) {
761 $idx_builder[ $w_id ] = strtolower( $builder_name );
762 }
763 }
764
765 foreach ( $server_list as $index => $value ) {
766 $get_id = $server_list[ $index ]['builder'] ? $server_list[ $index ]['builder'] : '';
767
768 $server_list[ $index ]['type'] = 'server';
769 $server_list[ $index ]['builder'] = ! empty( $idx_builder[ $get_id ] ) ? $idx_builder[ $get_id ] : '';
770 }
771
772 $count = 0;
773
774 foreach ( $local_list as $key => $value ) {
775 $widget_id = ! empty( $value['widgetdata']['widget_id'] ) ? $value['widgetdata']['widget_id'] : '';
776 $allow_push = isset( $value['widgetdata']['allow_push'] ) ? $value['widgetdata']['allow_push'] : true;
777
778 if ( in_array( $widget_id, $server_w_unique ) ) {
779
780 $index = array_search( $widget_id, $server_w_unique );
781
782 $server_list[ $index ]['title'] = $local_list[ $key ]['widgetdata']['name'];
783 $server_list[ $index ]['w_version'] = $local_list[ $key ]['widgetdata']['widget_version'];
784 $server_list[ $index ]['allow_push'] = $allow_push;
785 $server_list[ $index ]['builder'] = $local_list[ $key ]['widgetdata']['type'];
786 $server_list[ $index ]['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
787 $server_list[ $index ]['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
788
789 $local_list[ $key ] = $server_list[ $index ];
790
791 $local_list[ $key ]['type'] = 'done';
792
793 unset( $server_list[ $index ] );
794 } else {
795 $local_list[ $key ]['widgetdata']['builder'] = $local_list[ $key ]['widgetdata']['type'];
796 $local_list[ $key ]['widgetdata']['w_unique'] = $local_list[ $key ]['widgetdata']['widget_id'];
797 $local_list[ $key ]['widgetdata']['allow_push'] = $allow_push;
798 $local_list[ $key ]['widgetdata']['image'] = ! empty( $local_list[ $key ]['widgetdata']['w_image'] ) ? $local_list[ $key ]['widgetdata']['w_image'] : $placeholderimg;
799 $local_list[ $key ]['widgetdata']['is_activated'] = 'active';
800
801 $local_list[ $key ]['widgetdata']['type'] = 'plugin';
802
803 $local_list[ $key ]['widgetdata']['title'] = $local_list[ $key ]['widgetdata']['name'];
804 unset( $local_list[ $key ]['widgetdata']['name'] );
805 unset( $local_list[ $key ]['widgetdata']['widget_id'] );
806
807 $local_list[ $key ] = $local_list[ $key ]['widgetdata'];
808 }
809 }
810
811 $final = array_merge( $local_list, $server_list );
812
813 $db_widget = array();
814
815 foreach ( $final as $key => $self ) {
816 $is_activated = ! empty( $final[ $key ]['is_activated'] ) ? $final[ $key ]['is_activated'] : 'active';
817
818 if ( 'active' === $is_activated ) {
819 ++$count;
820 }
821
822 if ( ($count > $credits) && ('unlimited' !== $credits)) {
823 $final[ $key ]['is_activated'] = 'deactive';
824 }
825
826 if ( ! empty( $self['is_activated'] ) && 'active' !== $self['is_activated'] ) {
827 $db_widget[] = array(
828 'w_unique' => $self['w_unique'],
829 'builder' => $self['builder'],
830 'title' => $self['title'],
831 'is_activated' => $self['is_activated'],
832 );
833 }
834 }
835
836 $get_db_widget = get_option( 'wkit_deactivate_widgets', array() );
837 if ( empty( $get_db_widget ) ) {
838 add_option( 'wkit_deactivate_widgets', $db_widget, '', 'yes' );
839 } else {
840 update_option( 'wkit_deactivate_widgets', $db_widget );
841 }
842
843 return $final;
844 }
845
846 /**
847 * Browse Page Filter
848 *
849 * @since 1.0.0
850 */
851 protected function wdkit_browse_page() {
852 $args = $this->wdkit_parse_args( $_POST );
853
854 $response = WDesignKit_Data_Query::get_data( 'browse_page', $args );
855
856 wp_send_json( $response );
857 wp_die();
858 }
859
860 /**
861 *
862 * It is Use to get data for widget browse page
863 *
864 * @since 1.0.0
865 */
866 protected function wdkit_widget_browse_page() {
867 $array_data = array(
868 'CurrentPage' => isset( $_POST['page'] ) ? (int) $_POST['page'] : 1,
869 'builder' => isset( $_POST['buildertype'] ) ? wp_unslash( $_POST['buildertype'] ) : '',
870 'category' => isset( $_POST['category'] ) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ) : '',
871 'ParPage' => isset( $_POST['perpage'] ) ? (int) $_POST['perpage'] : 12,
872 'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '',
873 'free_pro' => isset( $_POST['free_pro'] ) ? sanitize_text_field( wp_unslash( $_POST['free_pro'] ) ) : '',
874 );
875
876 $response = $this->wkit_api_call( $array_data, 'browse_widget' );
877 $success = ! empty( $response['success'] ) ? $response['success'] : false;
878
879 if ( empty( $success ) ) {
880 $response = array(
881 'success' => false,
882 'message' => esc_html__( 'Data Not Found', 'wdesignkit' ),
883 'description' => esc_html__( 'Widget List Not Found', 'wdesignkit' ),
884
885 'widgets' => array(),
886 'widgetscount' => 0,
887 'showwidgets' => 0,
888 );
889
890 wp_send_json( $response );
891 wp_die();
892 }
893
894 $response = json_decode( wp_json_encode( $response['data'] ), true );
895
896 wp_send_json( $response );
897 wp_die();
898 }
899
900 /**
901 *
902 * It is Use for get template from kit.
903 *
904 * @since 1.0.0
905 */
906 protected function wdkit_template() {
907 $args = $this->wdkit_parse_args( $_POST );
908
909 $response = WDesignKit_Data_Query::get_data( 'kit_template', $args );
910
911 wp_send_json( $response );
912 wp_die();
913 }
914
915 /**
916 *
917 * It is Use for remove or delete template.
918 *
919 * @since 1.0.0
920 */
921 protected function wdkit_template_remove() {
922 $args = $this->wdkit_parse_args( $_POST );
923
924 $user_email = strtolower( sanitize_email( $args['email'] ) );
925 $response = '';
926
927 if ( empty( $user_email ) || empty( $args['template_id'] ) ) {
928 $response = response()->json(
929 array(
930 'message' => $this->e_msg_login,
931 'description' => $this->e_desc_login,
932 'success' => true,
933 )
934 );
935
936 wp_send_json( $response );
937 wp_die();
938 }
939
940 $args['token'] = $this->wdkit_login_user_token( $user_email );
941
942 unset( $user_email );
943 $response = WDesignKit_Data_Query::get_data( 'template_remove', $args );
944
945 wp_send_json( $response );
946 wp_die();
947 }
948
949 /**
950 *
951 * It is Use for save template from page builder.
952 *
953 * @since 1.0.0
954 */
955 protected function wdkit_put_save_template() {
956 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
957 $response = '';
958
959 if ( empty( $email ) ) {
960 $response = array(
961 'id' => 0,
962 'editpage' => '',
963 'message' => $this->e_msg_login,
964 'description' => $this->e_desc_login,
965 'success' => false,
966 );
967
968 wp_send_json( $response );
969 wp_die();
970 }
971
972 $args = $this->wdkit_parse_args( $_POST );
973 $args['token'] = $this->wdkit_login_user_token( $email );
974 unset( $args['email'] );
975
976 global $post;
977
978 $post_id = get_the_ID();
979 $custom_fields = array();
980 if ( ! empty( $post_id ) ) {
981 $meta_fields = get_post_custom( get_the_ID() );
982
983 foreach ( $meta_fields as $key => $value ) {
984 if ( str_contains( $key, 'nxt-' ) ) {
985 $custom_fields[ $key ] = $value;
986 }
987 }
988
989 if ( ! empty( $custom_fields ) ) {
990 $data = json_decode( $args['data'], true );
991 $data['custom_meta'] = $custom_fields;
992 $args['data'] = wp_json_encode( $data );
993 }
994 }
995
996 $response = WDesignKit_Data_Query::get_data( 'save_template', $args );
997
998 wp_send_json( $response );
999 wp_die();
1000 }
1001
1002 /**
1003 *
1004 * It is For Find User Existing template List.
1005 *
1006 * @since 1.0.6
1007 */
1008 protected function wdkit_find_existing_template() {
1009 $array_data = array(
1010 'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '',
1011 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
1012 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
1013 'u_id' => isset( $_POST['u_id'] ) ? sanitize_text_field( wp_unslash( $_POST['u_id'] ) ) : '',
1014 'builder' => isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '',
1015 'parpage' => isset( $_POST['parpage'] ) ? sanitize_text_field( wp_unslash( $_POST['parpage'] ) ) : 12,
1016 );
1017
1018 $response = $this->wkit_api_call( $array_data, 'existing_template' );
1019
1020 wp_send_json( $response );
1021 wp_die();
1022 }
1023
1024 /**
1025 *
1026 * It is For Update User Existing template List.
1027 *
1028 * @since 1.0.6
1029 */
1030 protected function wdkit_update_template() {
1031 $array_data = array(
1032 'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '',
1033 'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
1034 'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '',
1035 'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '',
1036 );
1037
1038 $response = $this->wkit_api_call( $array_data, 'existing_template' );
1039
1040 wp_send_json( $response );
1041 wp_die();
1042 }
1043
1044 /**
1045 *
1046 * It is Use for manage favourite template.
1047 *
1048 * @since 1.0.0
1049 */
1050 protected function wdkit_manage_favorite() {
1051 $template_id = isset( $_POST['template_id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['template_id'] ) ) ) : 0;
1052 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
1053
1054 if ( empty( $email ) || empty( $template_id ) ) {
1055 $response = array(
1056 'message' => $this->e_msg_login,
1057 'description' => $this->e_desc_login,
1058 'success' => false,
1059 );
1060
1061 wp_send_json( $response );
1062 wp_die();
1063 }
1064
1065 $args = $this->wdkit_parse_args( $_POST );
1066 $args['token'] = $this->wdkit_login_user_token( $email );
1067
1068 unset( $args['email'] );
1069 $response = WDesignKit_Data_Query::get_data( 'manage_favorite', $args );
1070
1071 wp_send_json( $response );
1072 wp_die();
1073 }
1074
1075 /**
1076 *
1077 * It is Use for Check Plugin Dependency of template.
1078 *
1079 * @since 1.0.0
1080 * @version 1.0.9
1081 */
1082 protected function wdkit_check_plugins_depends() {
1083 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array();
1084 $update_plugin = array();
1085
1086 if ( empty( $plugins ) || ! is_array( $plugins ) ) {
1087 $this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) );
1088 }
1089
1090 $all_plugins = $this->get_plugins();
1091 foreach ( $plugins as $plugin ) {
1092 $pluginslug = ! empty( $plugin->plugin_slug ) ? sanitize_text_field( wp_unslash( $plugin->plugin_slug ) ) : '';
1093 $free_pro = ! empty( $plugin->freepro ) ? sanitize_text_field( wp_unslash( $plugin->freepro ) ) : '0';
1094 $type = ! empty( $plugin->type ) ? sanitize_text_field( wp_unslash( $plugin->type ) ) : 'plugin';
1095
1096 if ( is_null( $pluginslug ) ) {
1097 $plugin->status = 'warning';
1098 $update_plugin[] = $plugin;
1099
1100 continue;
1101 }
1102
1103 if ( 'plugin' === $type ) {
1104 if ( ! is_plugin_active( $pluginslug ) ) {
1105 if ( ! isset( $all_plugins[ $pluginslug ] ) ) {
1106 if ( isset( $free_pro ) && '1' === $free_pro ) {
1107 $plugin->status = 'manually';
1108 } else {
1109 $plugin->status = 'unavailable';
1110 }
1111 } else {
1112 $plugin->status = 'inactive';
1113 }
1114
1115 $update_plugin[] = $plugin;
1116 } elseif ( is_plugin_active( $pluginslug ) ) {
1117 $plugin->status = 'active';
1118 $update_plugin[] = $plugin;
1119 }
1120 } elseif ( 'theme' === $type ) {
1121 $theme_array = array_keys( wp_get_themes() );
1122 $theme_slug = get_stylesheet();
1123
1124 if ( $theme_slug === $plugin->original_slug ) {
1125
1126 $plugin->status = 'active';
1127 } else {
1128 $theme_name = $plugin->original_slug;
1129 if ( ! in_array( $theme_name, $theme_array ) ) {
1130 if ( isset( $free_pro ) && '1' === $free_pro ) {
1131 $plugin->status = 'manually';
1132 } else {
1133 $plugin->status = 'unavailable';
1134 }
1135 } else {
1136 $plugin->status = 'inactive';
1137 }
1138 }
1139
1140 $update_plugin[] = $plugin;
1141 }
1142 }
1143
1144 $this->wdkit_success_msg( array( 'plugins' => $update_plugin ) );
1145 }
1146
1147 /**
1148 *
1149 * It is Use for Install dependent plugin.
1150 *
1151 * @since 1.0.0
1152 * @version 1.0.9
1153 */
1154 protected function wdkit_install_plugins_depends() {
1155 $plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array();
1156 $type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin';
1157
1158 $responce = '';
1159 if ( 'plugin' === $type ) {
1160 $responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins );
1161 } elseif ( 'theme' === $type ) {
1162 $theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : '';
1163 if ( ! empty( $theme_name ) ) {
1164
1165 $activate_result = switch_theme( $theme_name );
1166
1167 if ( ! is_wp_error( $activate_result ) ) {
1168 $responce = array(
1169 'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ),
1170 'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ),
1171 'slug' => 'the-plus-addons-for-block-editor',
1172 'status' => 'active',
1173 'success' => true,
1174 );
1175 } else {
1176 $responce = array(
1177 'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ),
1178 'description' => $activate_result->get_error_message(),
1179 'status' => 'inactive',
1180 'success' => false,
1181 );
1182 }
1183 } else {
1184 $responce = array(
1185 'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ),
1186 'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ),
1187 'success' => true,
1188 );
1189 }
1190 }
1191
1192 wp_send_json( $responce );
1193 wp_die();
1194 }
1195
1196 /**
1197 *
1198 * It is Use Update WDesignKit plugin latest version.
1199 *
1200 * @since 1.0.17
1201 */
1202 protected function wdkit_update_latest_plugin() {
1203
1204 return Wdkit_Depends_Installer::get_instance()->wdkit_update_plugin();
1205 }
1206
1207 /**
1208 *
1209 * It is Use for get plugin list.
1210 *
1211 * @since 1.0.0
1212 */
1213 private function get_plugins() {
1214 if ( ! function_exists( 'get_plugins' ) ) {
1215 require_once \ABSPATH . 'wp-admin/includes/plugin.php';
1216 }
1217
1218 return get_plugins();
1219 }
1220
1221 /**
1222 * Get Download Template Content
1223 *
1224 * @since 1.0.0
1225 */
1226 protected function wdkit_import_template() {
1227 $args = $this->wdkit_parse_args( $_POST );
1228
1229 if ( empty( $args['email'] ) ) {
1230 $response = array(
1231 'content' => '',
1232 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
1233 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
1234 'success' => true,
1235 );
1236
1237 wp_send_json( $response );
1238 wp_die();
1239 }
1240
1241 $response = '';
1242 if ( empty( $args['email'] ) || empty( $args['template_id'] ) ) {
1243 $result = array(
1244 'content' => '',
1245 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
1246 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
1247 'success' => false,
1248 );
1249
1250 wp_send_json( $response );
1251 wp_die();
1252 }
1253
1254 $args['token'] = $this->wdkit_login_user_token( $args['email'] );
1255
1256 unset( $args['email'] );
1257 $response = WDesignKit_Data_Query::get_data( 'import_template', $args );
1258 $custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
1259
1260 /** Custom meta Field */
1261 if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) {
1262
1263 $res_content = json_decode( $response['content'], true );
1264 if ( isset( $res_content['custom_meta'] ) && ! empty( $res_content['custom_meta'] ) ) {
1265 $meta_data = $res_content['custom_meta'];
1266
1267 if ( ! empty( $meta_data ) ) {
1268 foreach ( $meta_data as $meta_key => $meta_val ) {
1269 if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
1270 $meta_val[0] = maybe_unserialize( $meta_val[0] );
1271 }
1272
1273 if ( get_post_meta( get_the_ID(), $meta_key, true ) === '' ) {
1274 add_post_meta( get_the_ID(), $meta_key, $meta_val[0] );
1275 } else {
1276 update_post_meta( get_the_ID(), $meta_key, $meta_val[0] );
1277 }
1278 }
1279 }
1280 }
1281 }
1282
1283 wp_send_json( $response );
1284 wp_die();
1285 }
1286
1287 /**
1288 * This Function is Use For Media Import
1289 *
1290 * @since 1.0.0
1291 *
1292 * @param array $content store media content.
1293 * @param string $editor it is check editor.
1294 */
1295 public function wdkit_media_import( $content = array(), $editor = '' ) {
1296
1297 if ( empty( $content ) && empty( $editor ) ) {
1298 $args = $this->wdkit_parse_args( $_POST );
1299 $content = ! empty( $args['content'] ) ? json_decode( $args['content'], true ) : array();
1300 } else {
1301 $args = array(
1302 'content' => $content,
1303 'editor' => $editor,
1304 );
1305 $content = ! empty( $args['content'] ) ? $args['content'] : array();
1306
1307 if ( 'elementor' === $args['editor'] ) {
1308 $content = json_decode( $content, true );
1309 }
1310 }
1311
1312 if ( ! class_exists( 'Wdkit_Import_Images' ) ) {
1313 require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php';
1314 }
1315
1316 if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) {
1317 $media_import = array( $content );
1318 $media_import = self::blocks_import_media_copy_content( $media_import );
1319 $content = $media_import[0];
1320 } elseif ( ! empty( $args['editor'] ) && 'elementor' === $args['editor'] && ! empty( $content ) ) {
1321 $media_import = array( $content );
1322 $media_import = self::widgets_elements_id_change( $media_import );
1323 $media_import = self::widgets_import_media_copy_content( $media_import );
1324 $content = $media_import[0];
1325 }
1326
1327 return $content;
1328 }
1329
1330 /**
1331 * Widgets elements data
1332 *
1333 * @since 1.0.0
1334 * @param string $media_import it is store media data.
1335 */
1336 protected static function widgets_elements_id_change( $media_import ) {
1337 if ( did_action( 'elementor/loaded' ) ) {
1338 return \Elementor\Plugin::instance()->db->iterate_data(
1339 $media_import,
1340 function ( $element ) {
1341 $element['id'] = \Elementor\Utils::generate_random_string();
1342 return $element;
1343 }
1344 );
1345 } else {
1346 return $media_import;
1347 }
1348 }
1349
1350 /**
1351 * Widgets Media import copy content.
1352 *
1353 * @since 1.0.0
1354 *
1355 * @param string $media_import it is store media data.
1356 */
1357 protected static function widgets_import_media_copy_content( $media_import ) {
1358 if ( did_action( 'elementor/loaded' ) ) {
1359
1360 return \Elementor\Plugin::instance()->db->iterate_data(
1361 $media_import,
1362 function ( $element_data ) {
1363 $elements = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $element_data );
1364
1365 if ( ! $elements ) {
1366 return null;
1367 }
1368
1369 return self::widgets_element_import_start( $elements );
1370 }
1371 );
1372 } else {
1373 return $media_import;
1374 }
1375 }
1376
1377 /**
1378 * Start element copy content for media import.
1379 *
1380 * @since 1.0.0
1381 *
1382 * @param string \Elementor\Controls_Stack $element it is store elementor data.
1383 */
1384 protected static function widgets_element_import_start( \Elementor\Controls_Stack $element ) {
1385 $get_element_instance = $element->get_data();
1386 $tp_mi_on_fun = 'on_import';
1387
1388 if ( method_exists( $element, $tp_mi_on_fun ) ) {
1389 $get_element_instance = $element->{$tp_mi_on_fun}( $get_element_instance );
1390 }
1391
1392 foreach ( $element->get_controls() as $get_control ) {
1393 $control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] );
1394 $control_name = $get_control['name'];
1395
1396 if ( ! $control_type ) {
1397 return $get_element_instance;
1398 }
1399
1400 if ( method_exists( $control_type, $tp_mi_on_fun ) ) {
1401 $get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control );
1402 }
1403 }
1404
1405 return $get_element_instance;
1406 }
1407
1408 /**
1409 * Blocks Recursively data
1410 *
1411 * @param string $data_import gutenber data import.
1412 */
1413 public static function blocks_import_media_copy_content( $data_import ) {
1414 if ( ! empty( $data_import ) ) {
1415 foreach ( $data_import[0] as $key => $val ) {
1416 if ( array_key_exists( 'blockName', $val ) && ( empty( $val['blockName'] ) || null === $val['blockName'] || empty( $val['blockName'] ) || ' ' === $val['blockName'] ) ) {
1417 unset( $data_import[0][ $key ] );
1418 }
1419 }
1420 }
1421
1422 return self::blocks_array_recursively_data(
1423 $data_import,
1424 function ( $block_data ) {
1425 $elements = self::blocks_data_instance( $block_data );
1426 return $elements;
1427 }
1428 );
1429 }
1430
1431 /**
1432 * Blocks Recursively data
1433 *
1434 * @param array $data store data.
1435 * @param string $callback store data.
1436 * @param string $args store data.
1437 */
1438 public static function blocks_array_recursively_data( $data, $callback, $args = array() ) {
1439 if ( ( isset( $data['name'] ) && ! empty( $data['name'] ) ) || ( isset( $data['blockName'] ) && ! empty( $data['blockName'] ) ) ) {
1440 if ( ! empty( $data['innerBlocks'] ) ) {
1441 $data['innerBlocks'] = self::blocks_array_recursively_data( $data['innerBlocks'], $callback, $args );
1442 }
1443
1444 return call_user_func( $callback, $data, $args );
1445 }
1446
1447 if ( ! empty( $data ) ) {
1448 $data = (array) $data;
1449 foreach ( $data as $block_key => $block_value ) {
1450 $block_data = self::blocks_array_recursively_data( $data[ $block_key ], $callback, $args );
1451
1452 if ( null === $block_data ) {
1453 continue;
1454 }
1455
1456 $data[ $block_key ] = $block_data;
1457 }
1458 }
1459
1460 return $data;
1461 }
1462
1463 /**
1464 * Check Blocks data media Url
1465 *
1466 * @param array $block_data store data.
1467 * @param array $args store data.
1468 * @param array $block_args store data.
1469 */
1470 public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) {
1471
1472 if ( ( isset( $block_data['name'] ) && isset( $block_data['clientId'] ) && isset( $block_data['attributes'] ) ) || ( isset( $block_data['blockName'] ) && isset( $block_data['attrs'] ) && ! empty( $block_data['attrs'] ) ) ) {
1473 $blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() );
1474 foreach ( $blocks_attr as $block_key => $block_val ) {
1475 if ( isset( $block_val['url'] ) && isset( $block_val['id'] ) && ! empty( $block_val['url'] ) ) {
1476 $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
1477 $blocks_attr[ $block_key ] = $new_media;
1478 } elseif ( isset( $block_val['url'] ) && ! empty( $block_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $block_val['url'] ) ) {
1479 $new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val );
1480 $blocks_attr[ $block_key ] = $new_media;
1481 } elseif ( is_array( $block_val ) && ! empty( $block_val ) ) {
1482 if ( ! array_key_exists( 'md', $block_val ) && ! array_key_exists( 'openTypography', $block_val ) && ! array_key_exists( 'openBorder', $block_val ) && ! array_key_exists( 'openShadow', $block_val ) && ! array_key_exists( 'openFilter', $block_val ) ) {
1483 foreach ( $block_val as $key => $val ) {
1484 if ( is_array( $val ) && ! empty( $val ) ) {
1485
1486 if ( isset( $val['url'] ) && ( isset( $val['Id'] ) || isset( $val['id'] ) ) && ! empty( $val['url'] ) ) {
1487 $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
1488 $blocks_attr[ $block_key ][ $key ] = $new_media;
1489 } elseif ( isset( $val['url'] ) && ! empty( $val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $val['url'] ) ) {
1490 $new_media = Wdkit_Import_Images::wdkit_Import_media( $val );
1491 $blocks_attr[ $block_key ][ $key ] = $new_media;
1492 } else {
1493 foreach ( $val as $sub_key => $sub_val ) {
1494 if ( isset( $sub_val['url'] ) && ( isset( $sub_val['Id'] ) || isset( $sub_val['id'] ) ) && ! empty( $sub_val['url'] ) ) {
1495 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
1496 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
1497 } elseif ( isset( $sub_val['url'] ) && ! empty( $sub_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val['url'] ) ) {
1498 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val );
1499 $blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media;
1500 } elseif ( is_array( $sub_val ) && ! empty( $sub_val ) ) {
1501 foreach ( $sub_val as $sub_key1 => $sub_val1 ) {
1502 if ( isset( $sub_val1['url'] ) && ( isset( $sub_val1['Id'] ) || isset( $sub_val1['id'] ) ) && ! empty( $sub_val1['url'] ) ) {
1503 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
1504 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
1505 } elseif ( isset( $sub_val1['url'] ) && ! empty( $sub_val1['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val1['url'] ) ) {
1506 $new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 );
1507 $blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media;
1508 }
1509 }
1510 }
1511 }
1512 }
1513 }
1514 }
1515 }
1516 }
1517 }
1518 if ( isset( $block_data['attributes'] ) ) {
1519 $block_data['attributes'] = $blocks_attr;
1520 } elseif ( isset( $block_data['attrs'] ) ) {
1521 $block_data['attrs'] = $blocks_attr;
1522 }
1523 }
1524
1525 return $block_data;
1526 }
1527
1528 /**
1529 * Kit Template Import Pages/Sections
1530 *
1531 * @since 1.0.0
1532 * */
1533 protected function wdkit_import_kit_template() {
1534
1535 if ( ! current_user_can( 'manage_options' ) ) {
1536 return false;
1537 }
1538
1539 $page_section = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
1540
1541 if ( isset( $page_section ) ) {
1542 $args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : '';
1543 }
1544
1545 $template_ids = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
1546 $email = ! empty( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : '';
1547 $editor = isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : '';
1548 $website_kit = isset( $_POST['website_kit'] ) ? sanitize_text_field( wp_unslash( $_POST['website_kit'] ) ) : '';
1549
1550 if ( empty( $email ) || empty( $template_ids ) ) {
1551 $output = array(
1552 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
1553 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
1554 'success' => false,
1555 );
1556
1557 wp_send_json( $output );
1558 wp_die();
1559 }
1560
1561 /**Not Usefull*/
1562 if ( isset( $_POST['select'] ) ) {
1563 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
1564 }
1565
1566 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
1567 $args['editor'] = $editor;
1568
1569 $token = $this->wdkit_login_user_token( $email );
1570
1571 $temp_args = array(
1572 'token' => $token,
1573 'template_id' => $template_ids['id'],
1574 'editor' => $editor,
1575 'website_kit' => $website_kit,
1576 );
1577
1578 $response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args );
1579 $output = array();
1580
1581 if ( 'error' === $response['content'] ) {
1582 wp_send_json( $response );
1583 wp_die();
1584 } else {
1585 $output[ $template_ids['id'] ] = $this->import_page_section_content( $args, $template_ids['id'], $response, $template_ids );
1586 $output['message'] = $response['message'];
1587 $output['description'] = $response['description'];
1588 $output['success'] = $response['success'];
1589 }
1590
1591 wp_send_json( $output );
1592 wp_die();
1593 }
1594
1595 /**
1596 * Import single template and section from plugin only
1597 * */
1598 protected function wdkit_import_multi_template() {
1599 $args = $this->wdkit_parse_args( $_POST );
1600
1601 if ( ! current_user_can( 'manage_options' ) ) {
1602 return false;
1603 }
1604
1605 if ( empty( $_POST['template_ids'] ) ) {
1606 $output = array(
1607 'data' => array(),
1608 'message' => esc_html__( 'Invalid import', 'wdesignkit' ),
1609 'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ),
1610 'success' => false,
1611 );
1612
1613 wp_send_json( $output );
1614 wp_die();
1615 }
1616
1617 if ( isset( $_POST['template_ids'] ) ) {
1618 $args['template_ids'] = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array();
1619 }
1620
1621 if ( isset( $_POST['page_section'] ) ) {
1622 $args['page_section'] = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : '';
1623 }
1624
1625 if ( isset( $_POST['select'] ) ) {
1626 $args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : '';
1627 }
1628
1629 $args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false;
1630 if ( ! empty( $args['template_ids'] ) && ! empty( $args['page_section'] ) ) {
1631 $output = array();
1632 if ( is_array( $args['template_ids'] ) ) {
1633 foreach ( $args['template_ids'] as $key => $value ) {
1634 if ( ! empty( $value['id'] ) ) {
1635 $token = $this->wdkit_login_user_token( $args['email'] );
1636 $temp_args = array(
1637 'token' => $token,
1638 'template_id' => $value['id'],
1639 'editor' => $args['editor'],
1640 );
1641
1642 $response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args );
1643
1644 if ( 'error' === $response['content'] ) {
1645 wp_send_json( $response );
1646 wp_die();
1647 } else {
1648 $output[ $value['id'] ] = $this->import_page_section_content( $args, $value['id'], $response, $value );
1649 $output['message'] = $response['message'];
1650 $output['description'] = $response['description'];
1651 $output['success'] = $response['success'];
1652 }
1653 }
1654 }
1655 } else {
1656 $token = $this->wdkit_login_user_token( $args['email'] );
1657 $temp_args = array(
1658 'token' => $token,
1659 'template_id' => $args['template_ids'],
1660 'editor' => $args['editor'],
1661 );
1662
1663 $response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args );
1664
1665 if ( 'error' === $response['content'] ) {
1666 wp_send_json( $response );
1667 wp_die();
1668 } else {
1669 $output[ $args['template_ids'] ] = $this->import_page_section_content( $args, $args['template_ids'], $response );
1670 $output['message'] = $response['message'];
1671 $output['description'] = $response['description'];
1672 $output['success'] = $response['success'];
1673 }
1674 }
1675
1676 $output['success'] = true;
1677
1678 wp_send_json( $output );
1679 wp_die();
1680 }
1681 }
1682
1683 /**
1684 * Import single template and section from plugin only
1685 *
1686 * @param array $args store data.
1687 * @param array $template_id store data.
1688 * @param array $data store data.
1689 * @param array $temp_data store data.
1690 * */
1691 private function import_page_section_content( $args, $template_id, $data, $temp_data = array() ) {
1692 $enqueue_instance = new Wdkit_Enqueue();
1693 $get_post_type = $enqueue_instance->wdkit_get_post_type_list();
1694
1695 $post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page';
1696
1697 if ( 'section' === $post_type ) {
1698 $post_type = $temp_data['wp_post_type'];
1699 }
1700
1701 if ( ! array_key_exists( $post_type, $get_post_type ) ) {
1702 $post_type = 'page';
1703 }
1704
1705 if ( ! empty( $data ) && ! empty( $data['content'] ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) {
1706 $post_content = json_decode( $data['content'] );
1707 $post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : '';
1708 $file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : '';
1709 $content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : '';
1710
1711 if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) {
1712 if ( empty( $content ) ) {
1713 wp_send_json(
1714 array(
1715 'template_id' => $template_id,
1716 'message' => 'Content is Empty.',
1717 )
1718 );
1719 wp_die();
1720 } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) {
1721 $parse_blocks = parse_blocks( stripslashes( $content ) );
1722
1723 $editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor'];
1724 $content = $this->wdkit_media_import( $parse_blocks, $editor );
1725 $content = addslashes( serialize_blocks( $content ) );
1726
1727 $inserted_post = wp_insert_post(
1728 array(
1729 'post_status' => 'publish',
1730 'post_type' => $post_type,
1731 'post_title' => $post_title,
1732 'post_content' => $content,
1733 )
1734 );
1735
1736 if ( is_wp_error( $inserted_post ) ) {
1737 wp_send_json(
1738 array(
1739 'import_failed' => $inserted_post->get_error_message(),
1740 'code' => $inserted_post->get_error_code(),
1741 )
1742 );
1743 wp_die();
1744 }
1745
1746 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
1747 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
1748 if ( ! empty( $custom_meta ) ) {
1749 foreach ( $custom_meta as $meta_key => $meta_val ) {
1750 if ( isset( $meta_val[0] ) && ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
1751 $meta_val[0] = maybe_unserialize( $meta_val[0] );
1752 }
1753
1754 if ( '' === get_post_meta( $inserted_post, $meta_key, true ) && isset( $meta_val[0] ) ) {
1755 add_post_meta( $inserted_post, $meta_key, $meta_val[0] );
1756 }
1757 }
1758 }
1759 }
1760
1761 return array(
1762 'title' => get_the_title( $inserted_post ),
1763 'edit_link' => get_edit_post_link( $inserted_post, 'internal' ),
1764 'view' => get_permalink( $inserted_post ),
1765 );
1766 }
1767 } elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) {
1768 if ( did_action( 'elementor/loaded' ) ) {
1769 if ( empty( $content ) ) {
1770 wp_send_json(
1771 array(
1772 'template_id' => $template_id,
1773 'message' => 'Content is Empty.',
1774 )
1775 );
1776 wp_die();
1777 } elseif ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) {
1778 $post_attributes = array(
1779 'post_title' => $post_title,
1780 'post_type' => $post_type,
1781 'post_status' => 'publish',
1782 );
1783
1784 if ( 'elementor_library' === $post_type ) {
1785 $el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page';
1786 $new_document = \Elementor\Plugin::$instance->documents->create(
1787 $el_type,
1788 $post_attributes
1789 );
1790 } else {
1791 $new_document = \Elementor\Plugin::$instance->documents->create(
1792 $post_attributes['post_type'],
1793 $post_attributes
1794 );
1795 }
1796
1797 if ( is_wp_error( $new_document ) ) {
1798 wp_send_json(
1799 array(
1800 'import_failed' => $new_document->get_error_message(),
1801 'code' => $new_document->get_error_code(),
1802 )
1803 );
1804 wp_die();
1805 }
1806
1807 $settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array();
1808
1809 $content = wp_json_encode( $content );
1810 $content = $this->wdkit_media_import( $content, $file_type );
1811
1812 $new_document->save(
1813 array(
1814 'elements' => $content,
1815 'settings' => ! empty( $settings ) ? $settings : array(),
1816 )
1817 );
1818
1819 $inserted_id = $new_document->get_main_id();
1820
1821 if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) {
1822 $custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : '';
1823 if ( ! empty( $custom_meta ) ) {
1824 foreach ( $custom_meta as $meta_key => $meta_val ) {
1825 if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) {
1826 $meta_val[0] = maybe_unserialize( $meta_val[0] );
1827 }
1828 if ( '' === get_post_meta( $inserted_id, $meta_key, true ) ) {
1829 add_post_meta( $inserted_id, $meta_key, $meta_val[0] );
1830 }
1831 }
1832 }
1833 }
1834
1835 return array(
1836 'title' => get_the_title( $inserted_id ),
1837 'edit_link' => get_edit_post_link( $inserted_id, 'internal' ),
1838 'view' => get_permalink( $inserted_id ),
1839 );
1840 }
1841 } else {
1842 wp_send_json(
1843 array(
1844 'template_id' => $template_id,
1845 'message' => esc_html__( 'Relevant Page Builder not installed or activated', 'wdesignkit' ),
1846 )
1847 );
1848 wp_die();
1849 }
1850 }
1851 }
1852 }
1853
1854 /**
1855 * Share with Me Template and widgets
1856 *
1857 * @since 1.0.0
1858 */
1859 protected function wdkit_shared_with_me() {
1860 $data = isset( $_POST['api_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['api_info'] ) ) ) ) : '';
1861
1862 $array_data = array(
1863 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
1864 'type' => isset( $data->type ) ? sanitize_text_field( wp_unslash( $data->type ) ) : '',
1865 'ParPage' => isset( $data->par_page ) ? (int) $data->par_page : 12,
1866 'CurrentPage' => isset( $data->current_page ) ? (int) $data->current_page : 1,
1867 'builder' => isset( $data->builder ) ? sanitize_text_field( wp_unslash( $data->builder ) ) : '',
1868 );
1869
1870 $response = $this->wkit_api_call( $array_data, 'shared_with_me' );
1871 $success = ! empty( $response['success'] ) ? $response['success'] : false;
1872
1873 wp_send_json( $response );
1874 wp_die();
1875 }
1876
1877 /**
1878 * Add new WorkSpace
1879 *
1880 * @since 1.0.0
1881 */
1882 protected function wdkit_manage_workspace() {
1883 $args = $this->wdkit_parse_args( $_POST );
1884
1885 $user_email = ! empty( $args['email'] ) ? strtolower( sanitize_email( $args['email'] ) ) : '';
1886 $current_wid = ! empty( $_POST['current_wid'] ) ? strtolower( sanitize_text_field( $_POST['current_wid'] ) ) : '';
1887
1888 $args['current_wid'] = $current_wid;
1889
1890 if ( empty( $user_email ) ) {
1891 $response = array(
1892 'message' => $this->e_msg_login,
1893 'description' => $this->e_desc_login,
1894 'success' => false,
1895 );
1896
1897 wp_send_json( $response );
1898 wp_die();
1899 }
1900
1901 $args['token'] = $this->wdkit_login_user_token( $user_email );
1902 unset( $user_email );
1903
1904 $response = WDesignKit_Data_Query::get_data( 'manage_workspace', $args );
1905
1906 return $response;
1907 }
1908
1909 /**
1910 *
1911 * It is Use for manage workspace
1912 *
1913 * @since 1.0.0
1914 */
1915 protected function wdkit_manage_widget_workspace() {
1916 $workspace_info = isset( $_POST['workspace_info'] ) ? sanitize_text_field( wp_unslash( $_POST['workspace_info'] ) ) : array();
1917 $data = isset( $workspace_info ) ? json_decode( stripslashes( $workspace_info ) ) : array();
1918
1919 $array_data = array(
1920 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
1921 'wstype' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
1922 'widget_id' => isset( $data->widget_id ) ? (int) $data->widget_id : '',
1923 'wid' => isset( $data->wid ) ? (int) $data->wid : '',
1924 'current_wid' => isset( $data->current_wid ) ? (int) $data->current_wid : '',
1925 );
1926
1927 $response = $this->wkit_api_call( $array_data, 'manage_workspace' );
1928
1929 wp_send_json( $response['data'] );
1930 wp_die();
1931 }
1932
1933 /**
1934 *
1935 * It is Use for manage api key page
1936 *
1937 * @since 1.0.0
1938 */
1939 protected function wdkit_activate_key() {
1940 $email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : '';
1941 $response = '';
1942
1943 if ( empty( $user_email ) ) {
1944 $response = array(
1945 'message' => $this->e_msg_login,
1946 'description' => $this->e_desc_login,
1947 'success' => false,
1948 );
1949
1950 wp_send_json( $response );
1951 wp_die();
1952 }
1953
1954 $token = $this->wdkit_login_user_token( $email );
1955 $apikey = isset( $_POST['apikey'] ) ? sanitize_key( wp_unslash( $_POST['apikey'] ) ) : '';
1956 $product = isset( $_POST['product'] ) ? sanitize_text_field( wp_unslash( $_POST['product'] ) ) : '';
1957 $product_action = isset( $_POST['product_action'] ) ? sanitize_text_field( wp_unslash( $_POST['product_action'] ) ) : 'activate';
1958 if ( ! empty( $token ) && ! empty( $product ) && ! empty( $product_action ) ) {
1959 $args = array(
1960 'token' => $token,
1961 'product' => $product,
1962 'product_action' => $product_action,
1963 );
1964
1965 if ( 'activate' === $product_action ) {
1966 $args['apikey'] = $apikey;
1967 $args['site_url'] = home_url();
1968 }
1969
1970 $response = Wdkit_Data_Hooks::get_data( 'wkit_activate_key', $args );
1971 }
1972
1973 wp_send_json( $response );
1974 wp_die();
1975 }
1976
1977 /**
1978 *
1979 * Get list local Widget List
1980 *
1981 * @since 1.0.0
1982 */
1983 protected function wdkit_get_local_widgets() {
1984 $builder = array();
1985 $a_c_s_d_s_c = array();
1986 $j_s_o_n_array = array();
1987
1988 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks', 'widget' ) ) {
1989 array_push( $builder, 'bricks' );
1990 }
1991
1992 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor', 'widget' ) ) {
1993 array_push( $builder, 'elementor' );
1994 }
1995
1996 if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg', 'widget' ) ) {
1997 array_push( $builder, 'gutenberg' );
1998 }
1999
2000 foreach ( $builder as $key => $name ) {
2001 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $name;
2002
2003 if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) {
2004 $elementor_list = scandir( $elementor_dir );
2005 $elementor_list = array_diff( $elementor_list, array( '.', '..' ) );
2006
2007 if ( ! empty( $elementor_list ) ) {
2008 foreach ( $elementor_list as $key => $value ) {
2009 $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) ]['data'] = $value;
2010 $a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) ]['builder'] = $name;
2011 }
2012 }
2013 }
2014 }
2015
2016 ksort( $a_c_s_d_s_c );
2017 $a_c_s_d_s_c = array_reverse( $a_c_s_d_s_c );
2018
2019 foreach ( $a_c_s_d_s_c as $key => $value ) {
2020 $elementor_dir = WDKIT_BUILDER_PATH . '/' . $value['builder'];
2021
2022 if ( file_exists( "{$elementor_dir}/{$value['data']}" ) && is_dir( "{$elementor_dir}/{$value['data']}" ) ) {
2023 $sub_dir = scandir( "{$elementor_dir}/{$value['data']}" );
2024 $sub = array_diff( $sub_dir, array( '.', '..' ) );
2025
2026 foreach ( $sub as $sub_dir_value ) {
2027 $file = new SplFileInfo( $sub_dir_value );
2028 $check_ext = $file->getExtension();
2029 $ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
2030
2031 if ( 'json' === $ext ) {
2032 $widget1 = WDKIT_BUILDER_PATH . "/{$value['builder']}/{$value['data']}/{$sub_dir_value}";
2033 $filedata = wp_json_file_decode( $widget1 );
2034 $decode_data = json_decode( wp_json_encode( $filedata ), true );
2035 array_push( $j_s_o_n_array, $decode_data['widget_data'] );
2036 }
2037 }
2038 }
2039 }
2040
2041 return $j_s_o_n_array;
2042 }
2043
2044 /**
2045 *
2046 * It is Use for manage widget category.
2047 *
2048 * @since 1.0.0
2049 */
2050 protected function wdkit_manage_widget_category() {
2051 $data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : '';
2052 $data = json_decode( stripslashes( $data ) );
2053
2054 $type = isset( $data->manage_type ) ? sanitize_text_field( wp_unslash( $data->manage_type ) ) : '';
2055 $wkit_builder_option = get_option( 'wkit_builder' );
2056
2057 if ( empty( $wkit_builder_option ) ) {
2058 add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' );
2059 }
2060
2061 if ( 'get' === $type ) {
2062 if ( ! in_array( 'WDesignKit', $wkit_builder_option ) ) {
2063 update_option( 'wkit_builder', array( 'WDesignKit' ) );
2064 }
2065 } elseif ( 'update' === $type ) {
2066 $list = isset( $data->category_list ) ? $data->category_list : array();
2067 $list = array_unique( $list );
2068 $list = array_values( $list );
2069
2070 if ( ! empty( $list ) ) {
2071 update_option( 'wkit_builder', $list );
2072 }
2073 }
2074
2075 wp_send_json( get_option( 'wkit_builder' ) );
2076 }
2077
2078 /**
2079 *
2080 * Custom_upload_dir
2081 *
2082 * @since 1.0.0
2083 *
2084 * @param array $upload store data.
2085 */
2086 public function custom_upload_dir( $upload ) {
2087 // Specify the path to your custom upload directory.
2088 if ( isset( $this->widget_folder_u_r_l ) && ! empty( $this->widget_folder_u_r_l ) ) {
2089
2090 // Set the custom directory as the upload path.
2091 $upload['path'] = $this->widget_folder_u_r_l;
2092 // Set the URL for the uploaded file.
2093 $upload['url'] = $upload['baseurl'] . $upload['subdir'];
2094 }
2095
2096 return $upload;
2097 }
2098
2099 /**
2100 *
2101 * It is Use for create widget for local
2102 *
2103 * @since 1.0.0
2104 */
2105 protected function wdkit_create_widget() {
2106 $image = '';
2107 if ( isset( $_FILES ) && ! empty( $_FILES ) && isset( $_FILES['image'] ) && ! empty( $_FILES['image'] ) ) {
2108 $image = Wdkit_Data_Hooks::get_super_global_value( $_FILES, 'image' );
2109 }
2110
2111 $icon = '';
2112 if ( isset( $_FILES ) && ! empty( $_FILES ) && isset( $_FILES['icon'] ) && ! empty( $_FILES['icon'] ) ) {
2113 $icon = Wdkit_Data_Hooks::get_super_global_value( $_FILES, 'icon' );
2114 }
2115
2116 $data = ! empty( $_POST['value'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'value', 'cr_widget' ) : '';
2117 $data = ! empty( $data ) ? stripslashes( $data ) : '';
2118 $return = ! empty( $data ) ? json_decode( $data ) : '';
2119
2120 $all_val = ! empty( $return ) ? $return : '';
2121 if ( empty( $all_val ) ) {
2122
2123 $responce = array(
2124 'message' => esc_html__( 'Data Not Found', 'wdesignkit' ),
2125 'description' => esc_html__( 'something went wrong! please try again later.', 'wdesignkit' ),
2126 'success' => false,
2127 );
2128
2129 wp_send_json( $responce );
2130 wp_die();
2131 }
2132
2133 $file_name = ! empty( $all_val->file_name ) ? sanitize_text_field( $all_val->file_name ) : '';
2134 $folder_name = ! empty( $all_val->folder_name ) ? sanitize_text_field( $all_val->folder_name ) : '';
2135 $old_widget = ! empty( $all_val->old_folder ) ? sanitize_text_field( $all_val->old_folder ) : '';
2136 $description = ! empty( $all_val->description ) ? sanitize_text_field( $all_val->description ) : '';
2137 $json_file = ! empty( $all_val->json_file ) ? $all_val->json_file : '';
2138 $function_call = ! empty( $all_val->call ) ? sanitize_text_field( $all_val->call ) : '';
2139 $plugin = ! empty( $all_val->plugin ) ? $all_val->plugin : '';
2140 $d_image = ! empty( $all_val->d_image ) ? $all_val->d_image : '';
2141 $data = json_decode( $json_file );
2142
2143 $elementor_php_file = ! empty( $all_val->elementor_php_file ) ? $all_val->elementor_php_file : '';
2144 $elementor_js = ! empty( $all_val->elementor_js ) ? $all_val->elementor_js : '';
2145 $elementor_css = ! empty( $all_val->elementor_css ) ? $all_val->elementor_css : '';
2146
2147 $gutenberg_php_file = ! empty( $all_val->gutenberg_php_file ) ? $all_val->gutenberg_php_file : '';
2148 $gutenberg_js = ! empty( $all_val->gutenberg_js ) ? $all_val->gutenberg_js : '';
2149 $gutenberg_css = ! empty( $all_val->gutenberg_css ) ? $all_val->gutenberg_css : '';
2150 $external_js_file = ! empty( $all_val->external_js_file ) ? $all_val->external_js_file : '';
2151 $style_file = ! empty( $all_val->style_file ) ? $all_val->style_file : '';
2152
2153 $bricks_php_file = ! empty( $all_val->bricks_php_file ) ? $all_val->bricks_php_file : '';
2154 $bricks_js = ! empty( $all_val->bricks_js ) ? $all_val->bricks_js : '';
2155 $bricks_css = ! empty( $all_val->bricks_css ) ? $all_val->bricks_css : '';
2156
2157 $old_folder = ! empty( $old_widget ) ? str_replace( ' ', '-', $old_widget ) : '';
2158 $widget_type = ! empty( $data->widget_data->widgetdata->type ) ? sanitize_text_field( $data->widget_data->widgetdata->type ) : '';
2159
2160 if ( empty( $widget_type ) ) {
2161 $responce = array(
2162 'message' => esc_html__( 'Builder Type not found', 'wdesignkit' ),
2163 'description' => esc_html__( 'something went wrong! please try again later.', 'wdesignkit' ),
2164 'success' => false,
2165 );
2166
2167 wp_send_json( $responce );
2168 wp_die();
2169 }
2170
2171 $builder_type_path = trailingslashit( WDKIT_BUILDER_PATH ) . trailingslashit( $widget_type );
2172 $widget_file_url = $builder_type_path . $folder_name;
2173
2174 if ( ! is_dir( $widget_file_url ) ) {
2175 wp_mkdir_p( $widget_file_url );
2176 }
2177
2178 include_once ABSPATH . 'wp-admin/includes/file.php';
2179 \WP_Filesystem();
2180 global $wp_filesystem;
2181 $widget_folder_u_r_l = trailingslashit( $widget_file_url ) . $file_name;
2182 $this->widget_folder_u_r_l = $widget_file_url;
2183
2184 if ( 'elementor' === $plugin ) {
2185 $widget_file_list = scandir( $widget_file_url );
2186 $widget_file_list = array_diff( $widget_file_list, array( '.', '..' ) );
2187
2188 foreach ( $widget_file_list as $sub_dir_value ) {
2189 $file = new SplFileInfo( $sub_dir_value );
2190 $check_ext = $file->getExtension();
2191 $extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
2192
2193 if ( 'js' === $extiona || 'css' === $extiona || 'json' === $extiona || 'php' === $extiona ) {
2194 $wp_filesystem->rmdir( "$widget_file_url/$sub_dir_value", true );
2195 }
2196 }
2197
2198 if ( ! empty( $elementor_php_file ) ) {
2199 $wp_filesystem->put_contents( "$widget_folder_u_r_l.php", $elementor_php_file );
2200 }
2201 if ( ! empty( $json_file ) ) {
2202 $wp_filesystem->put_contents( "$widget_folder_u_r_l.json", $json_file );
2203 }
2204 if ( ! empty( $elementor_css ) ) {
2205 $wp_filesystem->put_contents( "$widget_folder_u_r_l.css", $elementor_css );
2206 }
2207 if ( ! empty( $elementor_js ) ) {
2208 $wp_filesystem->put_contents( "$widget_folder_u_r_l.js", $elementor_js );
2209 }
2210 } elseif ( 'bricks' === $plugin ) {
2211
2212 $widget_file_list = scandir( $widget_file_url );
2213 $widget_file_list = array_diff( $widget_file_list, array( '.', '..' ) );
2214
2215 foreach ( $widget_file_list as $sub_dir_value ) {
2216 $file = new SplFileInfo( $sub_dir_value );
2217 $check_ext = $file->getExtension();
2218 $extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
2219
2220 if ( 'js' === $extiona || 'css' === $extiona || 'json' === $extiona || 'php' === $extiona ) {
2221 $wp_filesystem->rmdir( "$widget_file_url/$sub_dir_value", true );
2222 }
2223 }
2224
2225 $wp_filesystem->put_contents( "$widget_folder_u_r_l.php", $bricks_php_file );
2226 $wp_filesystem->put_contents( "$widget_folder_u_r_l.json", $json_file );
2227
2228 if ( ! empty( $bricks_css ) ) {
2229 $wp_filesystem->put_contents( "$widget_folder_u_r_l.css", $bricks_css );
2230 }
2231
2232 if ( ! empty( $bricks_js ) ) {
2233 $wp_filesystem->put_contents( "$widget_folder_u_r_l.js", $bricks_js );
2234 }
2235 } elseif ( 'gutenberg' === $plugin ) {
2236
2237 $widget_file_list = scandir( $widget_file_url );
2238 $widget_file_list = array_diff( $widget_file_list, array( '.', '..' ) );
2239
2240 foreach ( $widget_file_list as $sub_dir_value ) {
2241 $file = new SplFileInfo( $sub_dir_value );
2242 $check_ext = $file->getExtension();
2243 $extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
2244
2245 if ( 'js' === $extiona || 'css' === $extiona || 'json' === $extiona || 'php' === $extiona ) {
2246 $wp_filesystem->rmdir( "$widget_file_url/$sub_dir_value", true );
2247 }
2248 }
2249
2250 if ( ! empty( $external_js_file ) ) {
2251 $wp_filesystem->put_contents( "$widget_file_url/index.js", $external_js_file );
2252 }
2253 $wp_filesystem->put_contents( "$widget_folder_u_r_l.php", $gutenberg_php_file );
2254 $wp_filesystem->put_contents( "$widget_folder_u_r_l.json", $json_file );
2255 if ( ! empty( $gutenberg_css ) ) {
2256 $wp_filesystem->put_contents( "$widget_folder_u_r_l.css", $gutenberg_css );
2257 }
2258 $wp_filesystem->put_contents( "$widget_folder_u_r_l.js", $gutenberg_js );
2259 }
2260
2261 if ( ! empty( $image ) && ! empty( $image['tmp_name'] ) ) {
2262
2263 $img_type = array( 'jpg', 'png' );
2264
2265 foreach ( $img_type as $imgext ) {
2266 $wp_filesystem->rmdir( "$widget_folder_u_r_l . $imgext", true );
2267 }
2268
2269 $ext = $image['type'];
2270 $img_ext = '';
2271 if ( strpos( $ext, 'jpeg' ) ) {
2272 $img_ext = 'jpg';
2273 } elseif ( strpos( $ext, 'png' ) ) {
2274 $img_ext = 'png';
2275 }
2276 if ( ! empty( $img_ext ) ) {
2277 add_filter( 'upload_dir', array( $this, 'custom_upload_dir' ) );
2278
2279 $uploaded_file = wp_handle_upload( $image, array( 'test_form' => false ) );
2280
2281 rename( $uploaded_file['file'], $widget_folder_u_r_l . '.' . $img_ext );
2282
2283 remove_filter( 'upload_dir', array( $this, 'custom_upload_dir' ) );
2284
2285 }
2286 } elseif ( ! empty( $old_widget ) ) {
2287 $img_url = $data->widget_data->widgetdata->w_image;
2288 $img_ext = ! empty( pathinfo( $img_url )['extension'] ) ? pathinfo( $img_url )['extension'] : '';
2289
2290 if ( ! empty( $img_ext ) ) {
2291 $old_widget_folder = str_replace( ' ', '-', $old_widget );
2292 $old_widget_file = str_replace( ' ', '_', $old_widget );
2293 $img_path = "$builder_type_path$old_widget_folder/$old_widget_file.$img_ext";
2294 $img_path = str_replace( '\\', '/', $img_path );
2295
2296 if ( file_exists( $img_path ) ) {
2297 $get_img = $img_path;
2298 $put_img = "$widget_folder_u_r_l.$img_ext";
2299
2300 if ( ! empty( $get_img ) && ! empty( $put_img ) ) {
2301 rename( $get_img, $put_img );
2302 }
2303 }
2304 }
2305 }
2306
2307 if ( ! empty( $d_image ) ) {
2308 $d_image = str_replace( '\\', '', $d_image );
2309 $d_img_url = $d_image;
2310 $img_body = wp_remote_get( $d_img_url );
2311 $img_ext = pathinfo( $d_img_url )['extension'];
2312 $wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$widget_type/$folder_name/$file_name.$img_ext", $img_body['body'] );
2313 }
2314
2315 if ( ! empty( $function_call ) && 'import' !== $function_call && ! empty( $old_folder ) && strtolower( $old_folder ) !== strtolower( $folder_name ) && is_dir( $builder_type_path . $old_folder ) ) {
2316 require_once ABSPATH . 'wp-admin/includes/file.php';
2317 global $wp_filesystem;
2318 WP_Filesystem();
2319 $wp_filesystem->rmdir( $builder_type_path . $old_folder, true );
2320 } elseif ( $old_folder !== $folder_name ) {
2321 rename( WDKIT_BUILDER_PATH . "/$widget_type/$old_folder", WDKIT_BUILDER_PATH . "/$widget_type/$folder_name" );
2322 }
2323
2324 $responce = array(
2325 'message' => esc_html__( 'Update Saved Successfully', 'wdesignkit' ),
2326 'description' => esc_html__( 'Success! Update Saved', 'wdesignkit' ),
2327 'success' => true,
2328 );
2329
2330 wp_send_json( $responce );
2331 wp_die();
2332 }
2333
2334 /**
2335 *
2336 * It is Use for delete widget from server
2337 *
2338 * @since 1.0.0
2339 */
2340 protected function wdkit_import_widget() {
2341 $filename = '';
2342 if ( isset( $_FILES ) && ! empty( $_FILES ) && isset( $_FILES['zipName'] ) && ! empty( $_FILES['zipName'] ) ) {
2343 $filename = ! empty( $_FILES['zipName']['name'] ) ? sanitize_file_name( $_FILES['zipName']['name'] ) : '';
2344 }
2345
2346 $name = rtrim( $filename, '.zip' );
2347 $ext = WDKIT_BUILDER_PATH . '/elementor/dump/';
2348
2349 if ( ! is_dir( $ext ) ) {
2350 wp_mkdir_p( $ext );
2351 } else {
2352 require_once ABSPATH . 'wp-admin/includes/file.php';
2353 global $wp_filesystem;
2354 WP_Filesystem();
2355 $wp_filesystem->rmdir( $ext, true );
2356 }
2357
2358 $dir = WDKIT_BUILDER_PATH . '/elementor/dump';
2359 $getall_json = array();
2360 $zip = new ZipArchive();
2361
2362 $zipname = '';
2363 if ( ! empty( $_FILES['zipName']['tmp_name'] ) ) {
2364 $zipname = $this->wdkit_file_sanitizer_bypass( $_FILES, 'zipName', 'name' );
2365 }
2366
2367 $res = $zip->open( $zipname );
2368 if ( true === $res ) {
2369 $zip->extractTo( $ext );
2370 $zip->close();
2371 $widget_name = $image = $json_file = '';
2372 $list = scandir( $dir );
2373 $list = array_diff( $list, array( '.', '..' ) );
2374 foreach ( $list as $sub_dir_value ) {
2375 $file = new SplFileInfo( $sub_dir_value );
2376 $check_ext = $file->getExtension();
2377 $extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION );
2378 if ( 'json' === $extiona ) {
2379 $json_file = $sub_dir_value;
2380 $u_r_l = wp_json_file_decode( $ext . $sub_dir_value );
2381 if ( ! empty( $u_r_l->widget_data->widgetdata->name ) && ! empty( $u_r_l->widget_data->widgetdata->widget_id ) ) {
2382 $widget_name = $u_r_l->widget_data->widgetdata->name;
2383 $widget_id = $u_r_l->widget_data->widgetdata->widget_id;
2384 $widget_type = ! empty( $u_r_l->widget_data->widgetdata->type ) ? $u_r_l->widget_data->widgetdata->type : '';
2385 }
2386 } elseif ( 'jpg' === $extiona || 'png' === $extiona || 'jpeg' === $extiona ) {
2387 $img_ext = $extiona;
2388 $image = $sub_dir_value;
2389 }
2390 }
2391
2392 if ( ! empty( $widget_name ) && ! empty( $json_file ) ) {
2393 $folder_name = str_replace( ' ', '-', $widget_name );
2394 $file_name = str_replace( ' ', '_', $widget_name );
2395 if ( ! is_dir( WDKIT_BUILDER_PATH . "/{$widget_type}" ) ) {
2396 wp_mkdir_p( WDKIT_BUILDER_PATH . "/{$widget_type}" );
2397 }
2398 $file_path = WDKIT_BUILDER_PATH . "/{$widget_type}/{$folder_name}_{$widget_id}";
2399 $dummy_path = WDKIT_BUILDER_PATH . '/elementor/dump';
2400
2401 if ( is_dir( $dummy_path ) ) {
2402 if ( ! rename( $dummy_path, $file_path ) ) {
2403
2404 require_once ABSPATH . 'wp-admin/includes/file.php';
2405 global $wp_filesystem;
2406 WP_Filesystem();
2407 $wp_filesystem->rmdir( $dummy_path, true );
2408
2409 $responce = (object) array(
2410 'success' => false,
2411 'message' => esc_html__( 'Widget Not imported', 'wdesignkit' ),
2412 'description' => esc_html__( 'Widget alreday exist!', 'wdesignkit' ),
2413 );
2414
2415 wp_send_json( $responce );
2416 wp_die();
2417 }
2418 }
2419
2420 rename( "{$file_path}/{$json_file}", "{$file_path}/{$file_name}_{$widget_id}.json" );
2421
2422 $get_img_file = "{$file_path}/{$image}";
2423
2424 if ( file_exists( $get_img_file ) ) {
2425 rename( $get_img_file, "{$file_path}/{$file_name}_{$widget_id}.{$img_ext}" );
2426 }
2427 }
2428
2429 $responce = (object) array(
2430 'success' => true,
2431 'message' => esc_html__( 'Widget imported', 'wdesignkit' ),
2432 'description' => esc_html__( 'Widget imported successfully', 'wdesignkit' ),
2433 'json' => $u_r_l,
2434 );
2435
2436 wp_send_json( $responce );
2437 wp_die();
2438
2439 } else {
2440 $responce = (object) array(
2441 'success' => false,
2442 'message' => esc_html__( 'Operation Fial!', 'wdesignkit' ),
2443 'description' => esc_html__( 'Widget can not imported', 'wdesignkit' ),
2444 );
2445
2446 wp_send_json( $responce );
2447 wp_die();
2448 }
2449 }
2450
2451 /**
2452 *
2453 * Create Uniq name
2454 *
2455 * @since 1.0.0
2456 */
2457 protected function generate_unique_id() {
2458 $now = new DateTime();
2459 $unique_i_d = $now->format( 'YmdHis' );
2460 $hashed_i_d = (int) $unique_i_d % 10000;
2461 return str_pad( $hashed_i_d, 4, '0', STR_PAD_LEFT );
2462 }
2463
2464 /**
2465 *
2466 * It is Use for delete widget from server
2467 *
2468 * @since 1.0.0
2469 */
2470 protected function wdkit_export_widget() {
2471 $data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : '';
2472 $data = json_decode( stripslashes( $data ) );
2473
2474 $widget_name_temp = isset( $data->widget_name ) ? sanitize_text_field( $data->widget_name ) : '';
2475 $widget_type = isset( $data->widget_type ) ? sanitize_text_field( $data->widget_type ) : '';
2476
2477 $widget_name = str_replace( ' ', '_', $widget_name_temp );
2478 $folder = str_replace( ' ', '-', $widget_name_temp );
2479 $unique_version = $this->generate_unique_id();
2480
2481 if ( empty( $widget_type ) ) {
2482 $result = (object) array(
2483 'success' => false,
2484 'url' => '',
2485 'message' => esc_html__( 'Widget Type Fail', 'wdesignkit' ),
2486 'description' => esc_html__( 'Widget Type Not Exists', 'wdesignkit' ),
2487 );
2488
2489 wp_send_json( $result );
2490 wp_die();
2491 }
2492
2493 $downlod_path = WDKIT_BUILDER_PATH . "/{$widget_type}/";
2494 $new_path = "{$downlod_path}/{$folder}/{$widget_name}";
2495
2496 $download_url = WDKIT_SERVER_PATH . "/{$widget_type}/{$widget_name}.zip";
2497 $zip = new ZipArchive();
2498 $tmp_file = "{$downlod_path}{$widget_name}.zip";
2499
2500 $json_data = wp_json_file_decode( "$new_path.json" );
2501 $img_ext = $json_data->widget_data->widgetdata->img_ext;
2502
2503 if ( true === $zip->open( $tmp_file, ZipArchive::CREATE ) ) {
2504 $widget_wb = str_replace( '-', '_', $folder );
2505 $zip->addFile( "$new_path.json", "$widget_wb.json" );
2506 if ( ! empty( $img_ext ) ) {
2507 $zip->addFile( "$new_path.$img_ext", "$widget_wb.$img_ext" );
2508 }
2509 $zip->close();
2510
2511 $result = (object) array(
2512 'success' => true,
2513 'url' => $download_url,
2514 'message' => esc_html__( 'Widget Exported', 'wdesignkit' ),
2515 'description' => esc_html__( 'Widget Exported successfully', 'wdesignkit' ),
2516 );
2517
2518 wp_send_json( $result );
2519 wp_die();
2520 } else {
2521 $result = (object) array(
2522 'success' => false,
2523 'url' => '',
2524 'message' => esc_html__( 'Widget Exported Fail', 'wdesignkit' ),
2525 'description' => esc_html__( 'something went wrong! please try again later.', 'wdesignkit' ),
2526 );
2527
2528 wp_send_json( $result );
2529 wp_die();
2530 }
2531 }
2532
2533 /**
2534 *
2535 * It is Use for delete widget from server
2536 *
2537 * @since 1.0.0
2538 */
2539 protected function wdkit_delete_widget() {
2540 $data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : '';
2541 $data = json_decode( stripslashes( $data ) );
2542
2543 $delete_type = isset( $data->delete_type ) ? sanitize_text_field( $data->delete_type ) : '';
2544
2545 if ( 'plugin_server' === $delete_type ) {
2546 $array_data = array(
2547 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2548 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
2549 'w_unique' => isset( $data->w_unique ) ? sanitize_text_field( $data->w_unique ) : '',
2550 'id' => isset( $data->id ) ? sanitize_text_field( $data->id ) : '',
2551 );
2552
2553 $response = $this->wkit_api_call( $array_data, 'save_widget' );
2554 $success = ! empty( $response['success'] ) ? $response['success'] : false;
2555
2556 if ( empty( $success ) ) {
2557 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
2558
2559 $result = (object) array(
2560 'success' => false,
2561 'message' => esc_html__( 'Widget Not Deleted', 'wdesignkit' ),
2562 'description' => esc_html__( 'Widget Not Deleted', 'wdesignkit' ),
2563 );
2564
2565 wp_send_json( $result );
2566 wp_die();
2567 }
2568 }
2569
2570 $dir_name = isset( $data->name ) ? sanitize_text_field( $data->name ) : '';
2571 $widget_type = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '';
2572 $dir = WDKIT_BUILDER_PATH . "/{$widget_type}/{$dir_name}";
2573
2574 require_once ABSPATH . 'wp-admin/includes/file.php';
2575 global $wp_filesystem;
2576 WP_Filesystem();
2577 $wp_filesystem->rmdir( $dir, true );
2578
2579 if ( 'plugin_server' === $delete_type ) {
2580 wp_send_json( $response['data'] );
2581 wp_die();
2582 } else {
2583 $result = (object) array(
2584 'success' => true,
2585 'message' => esc_html__( 'widget deleted', 'wdesignkit' ),
2586 'description' => esc_html__( 'Widget deleted successfully', 'wdesignkit' ),
2587 );
2588
2589 wp_send_json( $result );
2590 wp_die();
2591 }
2592 }
2593
2594 /**
2595 *
2596 * It is Use for download widget from widget listing.
2597 *
2598 * @since 1.0.0
2599 */
2600 protected function wdkit_download_widget() {
2601 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
2602 $data = json_decode( stripslashes( $data ) );
2603
2604 $array_data = array(
2605 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2606 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
2607 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
2608 );
2609
2610 $response = $this->wkit_api_call( $array_data, 'save_widget' );
2611 $success = ! empty( $response['success'] ) ? $response['success'] : false;
2612
2613 if ( empty( $success ) ) {
2614 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
2615 $result = (object) array(
2616 'success' => false,
2617 'message' => $massage,
2618 'description' => esc_html__( ' Widget not Downloaded', 'wdesignkit' ),
2619 );
2620
2621 wp_send_json( $result );
2622 wp_die();
2623 }
2624
2625 $response = json_decode( wp_json_encode( $response['data'] ), true );
2626
2627 if ( empty( $response ) || empty( $response['data'] ) ) {
2628 $message = ! empty( $response['message'] ) ? $response['message'] : 'No Response Found';
2629 $description = ! empty( $response['description'] ) ? $response['description'] : 'Widget not Downloaded';
2630
2631 $result = (object) array(
2632 'success' => false,
2633 'message' => esc_html( $message ),
2634 'description' => esc_html( $description ),
2635 );
2636
2637 wp_send_json( $result );
2638 wp_die();
2639 }
2640
2641 $img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : '';
2642 $json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'] ) : '';
2643
2644 if ( empty( $img_url ) && empty( $json_data ) ) {
2645 $responce = (object) array(
2646 'success' => false,
2647 'message' => esc_html__( 'No Response Found', 'wdesignkit' ),
2648 'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ),
2649 );
2650
2651 wp_send_json( $responce );
2652 wp_die();
2653 }
2654
2655 include_once ABSPATH . 'wp-admin/includes/file.php';
2656 \WP_Filesystem();
2657 global $wp_filesystem;
2658
2659 $title = ! empty( $json_data->widget_data->widgetdata->name ) ? sanitize_text_field( $json_data->widget_data->widgetdata->name ) : '';
2660 $builder = ! empty( $json_data->widget_data->widgetdata->type ) ? sanitize_text_field( $json_data->widget_data->widgetdata->type ) : '';
2661 $w_uniq = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? sanitize_text_field( $json_data->widget_data->widgetdata->widget_id ) : '';
2662
2663 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
2664 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
2665 $builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/";
2666
2667 if ( ! is_dir( $builder_type_path ) ) {
2668 wp_mkdir_p( $builder_type_path );
2669 }
2670
2671 if ( ! is_dir( $builder_type_path . $folder_name ) ) {
2672 wp_mkdir_p( $builder_type_path . $folder_name );
2673 }
2674
2675 if ( ! empty( $img_url ) ) {
2676 $img_body = wp_remote_get( $img_url );
2677 $img_ext = pathinfo( $img_url )['extension'];
2678
2679 $wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] );
2680 $json_data->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
2681 }
2682
2683 $result = (object) array(
2684 'success' => false,
2685 'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ),
2686 'description' => '',
2687 'json' => wp_json_encode( $json_data ),
2688 );
2689
2690 wp_send_json( $result );
2691 wp_die();
2692 }
2693
2694 /**
2695 *
2696 * It is Use for download widget from browse page.
2697 *
2698 * @since 1.0.0
2699 */
2700 protected function wdkit_public_download_widget() {
2701 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
2702 $data = json_decode( stripslashes( $data ) );
2703
2704 $array_data = array(
2705 'id' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
2706 'u_id' => isset( $data->u_id ) ? sanitize_text_field( $data->u_id ) : '',
2707 'type' => isset( $data->d_type ) ? sanitize_text_field( $data->d_type ) : '',
2708 );
2709
2710 $response = $this->wkit_api_call( $array_data, 'widget/download' );
2711 $success = ! empty( $response['success'] ) ? $response['success'] : false;
2712
2713 if ( empty( $success ) ) {
2714 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
2715
2716 $result = (object) array(
2717 'success' => false,
2718 'message' => $massage,
2719 'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ),
2720 );
2721
2722 wp_send_json( $result );
2723 wp_die();
2724 }
2725
2726 $response = json_decode( wp_json_encode( $response['data'] ), true );
2727 if ( ! empty( $response ) && ! empty( $response['data'] ) ) {
2728 $img_url = ! empty( $response['data']['image'] ) ? esc_url_raw( $response['data']['image'] ) : '';
2729 $json = ! empty( $response['data']['json'] ) ? wp_json_encode( $response['data']['json'] ) : '';
2730
2731 if ( ! empty( $json ) ) {
2732 include_once ABSPATH . 'wp-admin/includes/file.php';
2733 \WP_Filesystem();
2734 global $wp_filesystem;
2735
2736 $json_data = json_decode( $json );
2737 $json_data = json_decode( $json_data );
2738 $title = ! empty( $json_data->widget_data->widgetdata->name ) ? sanitize_text_field( $json_data->widget_data->widgetdata->name ) : '';
2739 $builder = ! empty( $json_data->widget_data->widgetdata->type ) ? sanitize_text_field( $json_data->widget_data->widgetdata->type ) : '';
2740 $widget_id = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? sanitize_text_field( $json_data->widget_data->widgetdata->widget_id ) : '';
2741
2742 $folder_name = str_replace( ' ', '-', $title ) . '_' . $widget_id;
2743 $file_name = str_replace( ' ', '_', $title ) . '_' . $widget_id;
2744
2745 $builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/";
2746
2747 if ( ! is_dir( $builder_type_path . $folder_name ) ) {
2748 wp_mkdir_p( $builder_type_path . $folder_name );
2749 }
2750
2751 if ( ! empty( $img_url ) ) {
2752 $img_body = wp_remote_get( $img_url );
2753 $img_ext = pathinfo( $img_url )['extension'];
2754 $wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] );
2755
2756 $json_data->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
2757 }
2758
2759 $response = (object) array(
2760 'message' => ! empty( $response['message'] ) ? $response['message'] : '',
2761 'description' => ! empty( $response['description'] ) ? $response['description'] : '',
2762 'success' => ! empty( $response['success'] ) ? $response['success'] : false,
2763 'r_id' => ! empty( $response['data']['rid'] ) ? $response['data']['rid'] : 0,
2764 'json' => wp_json_encode( $json_data ),
2765 );
2766 }
2767 }
2768
2769 wp_send_json( $response );
2770 wp_die();
2771 }
2772
2773 /**
2774 *
2775 * It is Use for sync widget to server
2776 *
2777 * @since 1.0.0
2778 */
2779 protected function wdkit_add_widget() {
2780 $data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : '';
2781 $data = json_decode( stripslashes( $data ) );
2782
2783 $title = isset( $data->title ) ? sanitize_text_field( $data->title ) : '';
2784 $builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '';
2785 $w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '';
2786 $w_image = isset( $data->w_image ) ? esc_url_raw( $data->w_image ) : '';
2787
2788 if ( ! empty( $w_image ) ) {
2789 $w_image = str_replace( '\\', '', $w_image );
2790 $w_image = wp_remote_get( $w_image )['body'];
2791 }
2792
2793 $array_data = array(
2794 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2795 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
2796 'title' => isset( $data->title ) ? sanitize_text_field( $data->title ) : '',
2797 'content' => isset( $data->content ) ? sanitize_text_field( $data->content ) : '',
2798 'builder' => isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '',
2799 'w_data' => isset( $data->w_data ) ? $data->w_data : '',
2800 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
2801 'w_image' => $w_image,
2802 'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '',
2803 'w_version' => isset( $data->w_version ) ? $data->w_version : '',
2804 'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ),
2805 'r_id' => isset( $data->r_id ) ? $data->r_id : 0,
2806 );
2807
2808 $response = $this->wkit_api_call( $array_data, 'save_widget' );
2809 $success = ! empty( $response['success'] ) ? $response['success'] : false;
2810
2811 if ( empty( $success ) ) {
2812 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
2813
2814 $result = (object) array(
2815 'success' => false,
2816 'message' => $massage,
2817 'description' => esc_html__( 'Widget Not Added', 'wdesignkit' ),
2818 );
2819
2820 wp_send_json( $result );
2821 wp_die();
2822 }
2823
2824 $res = ! empty( $response['data'] ) ? $response['data'] : array();
2825
2826 $response = json_decode( wp_json_encode( $res ), true );
2827 $img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : '';
2828
2829 if ( ! empty( $img_url ) && 'error' !== $res ) {
2830 $img_body = wp_remote_get( $img_url );
2831 $img_ext = pathinfo( $img_url )['extension'];
2832 include_once ABSPATH . 'wp-admin/includes/file.php';
2833 \WP_Filesystem();
2834 global $wp_filesystem;
2835 $folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq;
2836 $file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq;
2837 $file_path = WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name";
2838
2839 $u_r_l = wp_json_file_decode( "$file_path.json" );
2840 $u_r_l->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext";
2841
2842 $wp_filesystem->put_contents( "$file_path.json", wp_json_encode( $u_r_l ) );
2843 $wp_filesystem->put_contents( "$file_path.$img_ext", $img_body['body'] );
2844 }
2845
2846 wp_send_json( $response );
2847 wp_die();
2848 }
2849
2850 /**
2851 *
2852 * It is Use for manage favourite widget
2853 *
2854 * @since 1.0.0
2855 */
2856 protected function wdkit_favourite_widget() {
2857 $data = isset( $_POST['widget_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['widget_info'] ) ) ) ) : '';
2858 $array_data = array(
2859 'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '',
2860 'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '',
2861 'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '',
2862 );
2863
2864 $response = $this->wkit_api_call( $array_data, 'save_widget' );
2865 $success = ! empty( $response['success'] ) ? $response['success'] : false;
2866
2867 if ( empty( $success ) ) {
2868 $massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' );
2869
2870 $result = (object) array(
2871 'success' => false,
2872 'message' => $massage,
2873 'description' => '',
2874 );
2875
2876 wp_send_json( $result );
2877 wp_die();
2878 }
2879
2880 wp_send_json( $response );
2881 wp_die();
2882 }
2883
2884 /**
2885 * It is Used Setting Panel Defalut Data Get.
2886 *
2887 * @since 1.0.0
2888 */
2889 protected function wdkit_setting_panel() {
2890 $event = ! empty( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : 'get';
2891
2892 if ( 'get' === $event ) {
2893 return self::wkit_get_settings_panel();
2894 } elseif ( 'set' === $event ) {
2895 $data = ! empty( $_POST['data'] ) ? stripslashes( sanitize_text_field( wp_unslash( $_POST['data'] ) ) ) : array();
2896
2897 $data = json_decode( $data, true );
2898
2899 update_option( 'wkit_settings_panel', $data );
2900 return self::wkit_get_settings_panel();
2901 } else {
2902 return false;
2903 }
2904 }
2905
2906 /**
2907 * Get Setting Panal Data
2908 *
2909 * @since 1.0.0
2910 */
2911 protected static function wkit_get_settings_panel() {
2912
2913 $current_version = WDKIT_VERSION;
2914 $response = wp_remote_get( 'https://api.wordpress.org/plugins/info/1.0/wdesignkit.json' );
2915
2916 if ( is_wp_error( $response ) ) {
2917 return false;
2918 }
2919
2920 $body = wp_remote_retrieve_body( $response );
2921 $data = json_decode( $body );
2922
2923 if ( isset( $data->version ) ) {
2924 $new_version = $data->version;
2925 }
2926
2927 $version_check = array();
2928
2929 if ( $new_version && version_compare( $current_version, $new_version, '<' ) ) {
2930 $version_check['success'] = true;
2931 $version_check['version'] = $new_version;
2932 } else {
2933 $version_check['success'] = false;
2934 $version_check['version'] = $new_version;
2935 }
2936
2937 $get_setting = get_option( 'wkit_settings_panel', false );
2938
2939 return array(
2940 'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true,
2941 'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true,
2942 'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true,
2943 'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true,
2944 'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false,
2945 'debugger_mode' => isset( $get_setting['debugger_mode'] ) ? $get_setting['debugger_mode'] : false,
2946 'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true,
2947 'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true,
2948 'plugin_version' => $version_check,
2949 );
2950 }
2951
2952 /**
2953 *
2954 * Use for Add new licence key.
2955 *
2956 * @since 1.0.0
2957 */
2958 protected function wdkit_activate_licence() {
2959 $args = array(
2960 'token' => ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '',
2961 'licencekey' => ! empty( $_POST['licencekey'] ) ? sanitize_text_field( wp_unslash( $_POST['licencekey'] ) ) : '',
2962 'licencename' => ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '',
2963 'uichemyid' => ! empty( $_POST['uichemyid'] ) ? sanitize_text_field( wp_unslash( $_POST['uichemyid'] ) ) : '',
2964 );
2965
2966 $response = $this->wkit_api_call( $args, 'wkit_activate_key' );
2967
2968 wp_send_json( $response['data'] );
2969 wp_die();
2970 }
2971
2972 /**
2973 *
2974 * Use for Delete licence key.
2975 *
2976 * @since 1.0.0
2977 */
2978 protected function wdkit_delete_licence_key() {
2979 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
2980 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
2981
2982 $args = array(
2983 'token' => $token,
2984 'licencename' => $licencename,
2985 );
2986
2987 $response = $this->wkit_api_call( $args, 'licence_delete' );
2988
2989 wp_send_json( $response['data'] );
2990 wp_die();
2991 }
2992
2993 /**
2994 *
2995 * Use for Sync licence key.
2996 *
2997 * @since 1.0.0
2998 */
2999 protected function wdkit_sync_licence_key() {
3000 $token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '';
3001 $licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '';
3002
3003 $args = array(
3004 'token' => $token,
3005 'licencename' => $licencename,
3006 );
3007
3008 $response = $this->wkit_api_call( $args, 'licence_sync' );
3009
3010 wp_send_json( $response['data'] );
3011 wp_die();
3012 }
3013
3014 /**
3015 *
3016 * It is Use for logout.
3017 *
3018 * @since 1.0.0
3019 */
3020 protected function wdkit_logout() {
3021 $email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false;
3022 $logout_type = isset( $_POST['logout_type'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['logout_type'] ) ) ) : '';
3023
3024 $response = '';
3025
3026 if ( ! empty( $email ) ) {
3027 $token = $this->wdkit_login_user_token( $email );
3028 $args = array( 'token' => $token );
3029
3030 if ( 'session' !== $logout_type ) {
3031 delete_transient( 'wdkit_auth_' . $email );
3032 $response = WDesignKit_Data_Query::get_data( 'logout', $args );
3033 }
3034 }
3035
3036 wp_send_json( $response );
3037 wp_die();
3038 }
3039
3040 /**
3041 *
3042 * It is Use for get token of login user.
3043 *
3044 * @since 1.0.0
3045 *
3046 * @param string $email check user email.
3047 */
3048 protected function wdkit_login_user_token( $email = '' ) {
3049
3050 if ( ! empty( $email ) ) {
3051 $user_key = strstr( $email, '@', true );
3052 $get_login = get_transient( 'wdkit_auth_' . $user_key );
3053
3054 if ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) {
3055 return $get_login['token'];
3056 }
3057 }
3058
3059 return false;
3060 }
3061
3062 /**
3063 * Parse args $_POST
3064 *
3065 * @since 1.0.0
3066 *
3067 * @param string $data send all post data.
3068 * @param string $type store text data.
3069 * @param string $condition store text data.
3070 */
3071 protected function wdkit_sanitizer_bypass( $data, $type, $condition = 'none' ) {
3072
3073 if ( 'none' === $condition ) {
3074 return $data[ $type ];
3075 } elseif ( 'cr_widget' === $condition ) {
3076 return $data[ $type ];
3077 }
3078 }
3079
3080 /**
3081 * Parse args $_POST
3082 *
3083 * @since 1.0.0
3084 *
3085 * @param string $data send all post data.
3086 * @param string $type store text data.
3087 * @param string $condition store text data.
3088 */
3089 protected function wdkit_file_sanitizer_bypass( $data, $type, $condition = 'none' ) {
3090
3091 if ( 'name' === $condition ) {
3092 return wp_normalize_path( $data[ $type ]['tmp_name'] );
3093 }
3094 }
3095
3096 /**
3097 * Parse args $_POST
3098 *
3099 * @since 1.0.0
3100 *
3101 * @param string $data send all post data.
3102 */
3103 protected function wdkit_parse_args( $data = array() ) {
3104 if ( empty( $data ) ) {
3105 return array();
3106 }
3107
3108 $args = array();
3109 if ( isset( $data['email'] ) ) {
3110 $args['email'] = isset( $data['email'] ) ? sanitize_email( $data['email'] ) : '';
3111 }
3112
3113 if ( isset( $data['data'] ) ) {
3114 $args['data'] = isset( $data['data'] ) ? wp_unslash( $data['data'] ) : array();
3115 }
3116
3117 if ( isset( $data['plugins'] ) ) {
3118 $args['plugins'] = isset( $data['plugins'] ) ? wp_unslash( $data['plugins'] ) : array();
3119 }
3120
3121 if ( isset( $data['template_id'] ) ) {
3122 $args['template_id'] = isset( $data['template_id'] ) ? intval( strtolower( sanitize_text_field( $data['template_id'] ) ) ) : '';
3123 }
3124
3125 if ( isset( $data['builder'] ) ) {
3126 $args['builder'] = isset( $data['builder'] ) ? wp_unslash( $data['builder'] ) : '';
3127 }
3128
3129 if ( isset( $data['editor'] ) ) {
3130 $args['editor'] = isset( $data['editor'] ) ? sanitize_text_field( $data['editor'] ) : '';
3131 }
3132
3133 if ( isset( $data['type_upload'] ) ) {
3134 $args['type_upload'] = isset( $data['type_upload'] ) ? sanitize_text_field( $data['type_upload'] ) : '';
3135 }
3136
3137 if ( isset( $data['title'] ) ) {
3138 $args['title'] = isset( $data['title'] ) ? wp_strip_all_tags( $data['title'] ) : '';
3139 }
3140
3141 if ( isset( $data['template_type'] ) ) {
3142 $args['template_type'] = isset( $data['template_type'] ) ? sanitize_text_field( $data['template_type'] ) : '';
3143 }
3144
3145 if ( isset( $data['wstype'] ) ) {
3146 $args['wstype'] = isset( $data['wstype'] ) ? wp_strip_all_tags( $data['wstype'] ) : '';
3147 }
3148
3149 if ( isset( $data['wid'] ) ) {
3150 $args['wid'] = isset( $data['wid'] ) ? intval( strtolower( sanitize_text_field( $data['wid'] ) ) ) : '';
3151 }
3152
3153 if ( isset( $data['perpage'] ) ) {
3154 $args['perpage'] = isset( $data['perpage'] ) ? intval( strtolower( sanitize_text_field( $data['perpage'] ) ) ) : 12;
3155 }
3156
3157 if ( isset( $data['page'] ) ) {
3158 $args['page'] = isset( $data['page'] ) ? intval( strtolower( sanitize_text_field( $data['page'] ) ) ) : 1;
3159 }
3160
3161 if ( isset( $data['buildertype'] ) ) {
3162 $args['buildertype'] = isset( $data['buildertype'] ) ? sanitize_text_field( $data['buildertype'] ) : '';
3163 }
3164
3165 if ( isset( $data['search'] ) ) {
3166 $args['search'] = isset( $data['search'] ) ? sanitize_text_field( $data['search'] ) : '';
3167 }
3168
3169 if ( isset( $data['plugin'] ) ) {
3170 $args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array();
3171 }
3172
3173 if ( isset( $data['tag'] ) ) {
3174 $args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array();
3175 }
3176
3177 if ( isset( $data['category'] ) ) {
3178 $args['category'] = isset( $data['category'] ) ? wp_unslash( $data['category'] ) : array();
3179 }
3180
3181 if ( isset( $data['free_pro'] ) ) {
3182 $args['free_pro'] = isset( $data['free_pro'] ) ? sanitize_text_field( wp_unslash( $data['free_pro'] ) ) : '';
3183 }
3184
3185 if ( isset( $data['wp_post_type'] ) ) {
3186 $args['wp_post_type'] = isset( $data['wp_post_type'] ) ? sanitize_text_field( wp_unslash( $data['wp_post_type'] ) ) : '';
3187 }
3188
3189 if ( isset( $data['favorite'] ) ) {
3190 $args['favorite'] = isset( $data['favorite'] ) ? sanitize_text_field( wp_unslash( $data['favorite'] ) ) : '';
3191 }
3192
3193 if ( isset( $data['content'] ) ) {
3194 $args['content'] = isset( $data['content'] ) ? wp_unslash( $data['content'] ) : '';
3195 }
3196
3197 if ( isset( $data['page_type'] ) ) {
3198 $args['page_type'] = isset( $data['page_type'] ) ? wp_unslash( $data['page_type'] ) : array();
3199 }
3200
3201 return $args;
3202 }
3203 }
3204
3205 Wdkit_Api_Call::get_instance();
3206 }