| 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 'import_template': |
| 187 |
$data = $this->wdkit_import_template(); |
| 188 |
break; |
| 189 |
case 'import_multi_template': |
| 190 |
$data = $this->wdkit_import_multi_template(); |
| 191 |
break; |
| 192 |
case 'import_kit_template': |
| 193 |
$data = $this->wdkit_import_kit_template(); |
| 194 |
break; |
| 195 |
case 'shared_with_me': |
| 196 |
$data = $this->wdkit_shared_with_me(); |
| 197 |
break; |
| 198 |
case 'manage_workspace': |
| 199 |
$data = $this->wdkit_manage_workspace(); |
| 200 |
break; |
| 201 |
case 'wkit_manage_widget_workspace': |
| 202 |
$data = $this->wdkit_manage_widget_workspace(); |
| 203 |
break; |
| 204 |
case 'wkit_activate_key': |
| 205 |
$data = $this->wdkit_activate_key(); |
| 206 |
break; |
| 207 |
case 'wkit_get_widget_list': |
| 208 |
$data = $this->wdkit_get_widget_list(); |
| 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 |
* @access public |
| 531 |
*/ |
| 532 |
protected function wdkit_api_login() { |
| 533 |
$user_token = isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; |
| 534 |
$login_type = isset( $_POST['login_type'] ) ? sanitize_text_field( wp_unslash( $_POST['login_type'] ) ) : ''; |
| 535 |
|
| 536 |
$site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : ''; |
| 537 |
|
| 538 |
if ( empty( $user_token ) ) { |
| 539 |
$result = array( |
| 540 |
'success' => false, |
| 541 |
'token' => '', |
| 542 |
'data' => array( |
| 543 |
'message' => $this->e_msg_login, |
| 544 |
'description' => $this->e_desc_login, |
| 545 |
), |
| 546 |
); |
| 547 |
|
| 548 |
wp_send_json( $result ); |
| 549 |
wp_die(); |
| 550 |
} |
| 551 |
|
| 552 |
$array_data = array( |
| 553 |
'token' => $user_token, |
| 554 |
'site_url' => $site_url, |
| 555 |
); |
| 556 |
|
| 557 |
$response = $this->wkit_api_call( $array_data, 'login/api' ); |
| 558 |
|
| 559 |
$success = ! empty( $response['success'] ) ? is_bool( $response['success'] ) : false; |
| 560 |
|
| 561 |
if ( empty( $success ) ) { |
| 562 |
$result = array( |
| 563 |
'data' => $response, |
| 564 |
'token' => '', |
| 565 |
'success' => false, |
| 566 |
); |
| 567 |
|
| 568 |
wp_send_json( $result ); |
| 569 |
wp_die(); |
| 570 |
} |
| 571 |
|
| 572 |
$response = json_decode( wp_json_encode( $response['data'] ), true ); |
| 573 |
$user_email = ! empty( $response['user']['user_email'] ) ? sanitize_email( $response['user']['user_email'] ) : ''; |
| 574 |
$user_key = strstr( $user_email, '@', true ); |
| 575 |
|
| 576 |
$this->wdkit_set_time_out( $user_key, $user_email, $user_token, $login_type ); |
| 577 |
|
| 578 |
$result = array( |
| 579 |
'success' => true, |
| 580 |
'data' => $response, |
| 581 |
'token' => $user_token, |
| 582 |
); |
| 583 |
|
| 584 |
wp_send_json( $result ); |
| 585 |
wp_die(); |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* |
| 590 |
* This Function is used for social Login |
| 591 |
* |
| 592 |
* @version 1.0.0 |
| 593 |
* @access public |
| 594 |
*/ |
| 595 |
protected function wdkit_social_login() { |
| 596 |
$user_state = isset( $_POST['state'] ) ? sanitize_text_field( wp_unslash( $_POST['state'] ) ) : ''; |
| 597 |
$login_type = isset( $_POST['login_type'] ) ? sanitize_text_field( wp_unslash( $_POST['login_type'] ) ) : ''; |
| 598 |
|
| 599 |
$site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : ''; |
| 600 |
|
| 601 |
$array_data = array( |
| 602 |
'state' => $user_state, |
| 603 |
'site_url' => $site_url |
| 604 |
); |
| 605 |
|
| 606 |
$response = $this->wkit_api_call( $array_data, 'login/ip' ); |
| 607 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 608 |
|
| 609 |
if ( empty( $success ) ) { |
| 610 |
$result = array( |
| 611 |
'data' => $response, |
| 612 |
'success' => false, |
| 613 |
); |
| 614 |
|
| 615 |
wp_send_json( $result ); |
| 616 |
wp_die(); |
| 617 |
} |
| 618 |
|
| 619 |
$response = json_decode( wp_json_encode( $response['data'] ), true ); |
| 620 |
$user_email = ! empty( $response['user']['user_email'] ) ? sanitize_email( $response['user']['user_email'] ) : ''; |
| 621 |
$user_token = ! empty( $response['token'] ) ? sanitize_text_field( $response['token'] ) : ''; |
| 622 |
$user_key = strstr( $user_email, '@', true ); |
| 623 |
|
| 624 |
if ( ! empty( $response ) && ! empty( $user_token ) ) { |
| 625 |
$this->wdkit_set_time_out( $user_key, $user_email, $user_token, $login_type ); |
| 626 |
} |
| 627 |
|
| 628 |
$result = array( |
| 629 |
'data' => $response, |
| 630 |
'token' => $user_token, |
| 631 |
); |
| 632 |
|
| 633 |
wp_send_json( $result ); |
| 634 |
wp_die(); |
| 635 |
} |
| 636 |
|
| 637 |
/** |
| 638 |
* |
| 639 |
* It is Use for get meta data for non login user |
| 640 |
* |
| 641 |
* @since 1.0.0\ |
| 642 |
*/ |
| 643 |
protected function wdkit_meta_data() { |
| 644 |
$type = isset( $_POST['meta_type'] ) ? sanitize_text_field( wp_unslash( $_POST['meta_type'] ) ) : ''; |
| 645 |
$data = array( 'type' => $type ); |
| 646 |
|
| 647 |
$response = $this->wkit_api_call( $data, 'meta' ); |
| 648 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 649 |
$status = ! empty( $response['status'] ) ? (int) $response['status'] : 400; |
| 650 |
|
| 651 |
if ( empty( $success ) ) { |
| 652 |
$result = array( |
| 653 |
'plugin' => array(), |
| 654 |
'builder' => array(), |
| 655 |
'category' => array(), |
| 656 |
'widgetscategory' => array(), |
| 657 |
'tags' => array(), |
| 658 |
'widgetbuilder' => array(), |
| 659 |
|
| 660 |
'message' => esc_html__( 'Server Error', 'wdesignkit' ), |
| 661 |
'description' => esc_html__( 'Server Error, Data Not Found', 'wdesignkit' ), |
| 662 |
'success' => false, |
| 663 |
); |
| 664 |
|
| 665 |
wp_send_json( $result ); |
| 666 |
wp_die(); |
| 667 |
} |
| 668 |
|
| 669 |
$get_data_one = ! empty( $response['data'] ) ? $response['data'] : array(); |
| 670 |
$statuscode = array( 'HTTP_CODE' => $status ); |
| 671 |
|
| 672 |
$final = json_decode( wp_json_encode( $get_data_one ), true ); |
| 673 |
|
| 674 |
$final['Setting'] = self::wkit_get_settings_panel(); |
| 675 |
|
| 676 |
$final = array( |
| 677 |
'data' => $final, |
| 678 |
); |
| 679 |
|
| 680 |
wp_send_json( $final ); |
| 681 |
wp_die(); |
| 682 |
} |
| 683 |
|
| 684 |
/** |
| 685 |
* |
| 686 |
* It is Use for get all info of user. |
| 687 |
* |
| 688 |
* @since 1.0.0 |
| 689 |
* @access public |
| 690 |
*/ |
| 691 |
protected function wdkit_get_user_info() { |
| 692 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 693 |
$builder = isset( $_POST['builder'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['builder'] ) ) ) : ''; |
| 694 |
|
| 695 |
$site_url = isset( $_POST['site_url'] ) ? esc_url_raw( wp_unslash( $_POST['site_url'] ) ) : ''; |
| 696 |
|
| 697 |
$response = array(); |
| 698 |
|
| 699 |
if ( empty( $email ) ) { |
| 700 |
$response = array( |
| 701 |
'success' => false, |
| 702 |
'message' => $this->e_msg_login, |
| 703 |
'description' => $this->e_desc_login, |
| 704 |
); |
| 705 |
|
| 706 |
wp_send_json( $response ); |
| 707 |
wp_die(); |
| 708 |
} |
| 709 |
|
| 710 |
$token = $this->wdkit_login_user_token( $email ); |
| 711 |
$args = array( |
| 712 |
'token' => $token, |
| 713 |
'builder' => $builder, |
| 714 |
'site_url' => $site_url, |
| 715 |
); |
| 716 |
|
| 717 |
$response = WDesignKit_Data_Query::get_data( 'get_user_info', $args ); |
| 718 |
$status = ( ! empty( $response['status'] ) ) ? sanitize_text_field( $response['status'] ) : 'error'; |
| 719 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 720 |
|
| 721 |
/**Condtion user for user logout & expire token*/ |
| 722 |
if ( 'Token is Expired' === $status || 'Authorization Token not found' === $status ) { |
| 723 |
delete_transient( 'wdkit_auth_' . $email ); |
| 724 |
} |
| 725 |
|
| 726 |
$response['Setting'] = self::wkit_get_settings_panel(); |
| 727 |
|
| 728 |
$response = array( |
| 729 |
'data' => $response, |
| 730 |
'success' => true, |
| 731 |
); |
| 732 |
|
| 733 |
wp_send_json( $response ); |
| 734 |
wp_die(); |
| 735 |
} |
| 736 |
|
| 737 |
/** |
| 738 |
* Browse Page Filter |
| 739 |
* |
| 740 |
* @since 1.0.0 |
| 741 |
*/ |
| 742 |
protected function wdkit_browse_page() { |
| 743 |
$args = $this->wdkit_parse_args( $_POST ); |
| 744 |
|
| 745 |
$response = WDesignKit_Data_Query::get_data( 'browse_page', $args ); |
| 746 |
|
| 747 |
wp_send_json( $response ); |
| 748 |
wp_die(); |
| 749 |
} |
| 750 |
|
| 751 |
/** |
| 752 |
* |
| 753 |
* It is Use to get data for widget browse page |
| 754 |
* |
| 755 |
* @since 1.0.0 |
| 756 |
* @access public |
| 757 |
*/ |
| 758 |
protected function wdkit_widget_browse_page() { |
| 759 |
$array_data = array( |
| 760 |
'CurrentPage' => isset( $_POST['page'] ) ? (int) $_POST['page'] : 1, |
| 761 |
'builder' => isset( $_POST['buildertype'] ) ? sanitize_text_field( wp_unslash( $_POST['buildertype'] ) ) : '', |
| 762 |
'category' => isset( $_POST['category'] ) ? sanitize_text_field( wp_unslash( $_POST['category'] ) ) : '', |
| 763 |
'ParPage' => isset( $_POST['perpage'] ) ? (int) $_POST['perpage'] : 12, |
| 764 |
'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '', |
| 765 |
'free_pro' => isset( $_POST['free_pro'] ) ? sanitize_text_field( wp_unslash( $_POST['free_pro'] ) ) : '', |
| 766 |
); |
| 767 |
|
| 768 |
$response = $this->wkit_api_call( $array_data, 'browse_widget' ); |
| 769 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 770 |
|
| 771 |
if ( empty( $success ) ) { |
| 772 |
$response = array( |
| 773 |
'success' => false, |
| 774 |
'message' => esc_html__( 'Data Not Found', 'wdesignkit' ), |
| 775 |
'description' => esc_html__( 'Widget List Not Found', 'wdesignkit' ), |
| 776 |
|
| 777 |
'widgets' => array(), |
| 778 |
'widgetscount' => 0, |
| 779 |
'showwidgets' => 0, |
| 780 |
); |
| 781 |
|
| 782 |
wp_send_json( $response ); |
| 783 |
wp_die(); |
| 784 |
} |
| 785 |
|
| 786 |
$response = json_decode( wp_json_encode( $response['data'] ), true ); |
| 787 |
|
| 788 |
wp_send_json( $response ); |
| 789 |
wp_die(); |
| 790 |
} |
| 791 |
|
| 792 |
/** |
| 793 |
* |
| 794 |
* It is Use for get template from kit. |
| 795 |
* |
| 796 |
* @since 1.0.0 |
| 797 |
*/ |
| 798 |
protected function wdkit_template() { |
| 799 |
$args = $this->wdkit_parse_args( $_POST ); |
| 800 |
|
| 801 |
$response = WDesignKit_Data_Query::get_data( 'kit_template', $args ); |
| 802 |
|
| 803 |
wp_send_json( $response ); |
| 804 |
wp_die(); |
| 805 |
} |
| 806 |
|
| 807 |
/** |
| 808 |
* |
| 809 |
* It is Use for remove or delete template. |
| 810 |
* |
| 811 |
* @since 1.0.0 |
| 812 |
* @access public |
| 813 |
*/ |
| 814 |
protected function wdkit_template_remove() { |
| 815 |
$args = $this->wdkit_parse_args( $_POST ); |
| 816 |
|
| 817 |
$user_email = strtolower( sanitize_email( $args['email'] ) ); |
| 818 |
$response = ''; |
| 819 |
|
| 820 |
if ( empty( $user_email ) || empty( $args['template_id'] ) ) { |
| 821 |
$response = response()->json( |
| 822 |
array( |
| 823 |
'message' => $this->e_msg_login, |
| 824 |
'description' => $this->e_desc_login, |
| 825 |
'success' => true, |
| 826 |
) |
| 827 |
); |
| 828 |
|
| 829 |
wp_send_json( $response ); |
| 830 |
wp_die(); |
| 831 |
} |
| 832 |
|
| 833 |
$args['token'] = $this->wdkit_login_user_token( $user_email ); |
| 834 |
|
| 835 |
unset( $user_email ); |
| 836 |
$response = WDesignKit_Data_Query::get_data( 'template_remove', $args ); |
| 837 |
|
| 838 |
wp_send_json( $response ); |
| 839 |
wp_die(); |
| 840 |
} |
| 841 |
|
| 842 |
/** |
| 843 |
* |
| 844 |
* It is Use for save template from page builder. |
| 845 |
* |
| 846 |
* @since 1.0.0 |
| 847 |
*/ |
| 848 |
protected function wdkit_put_save_template() { |
| 849 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 850 |
$response = ''; |
| 851 |
|
| 852 |
if ( empty( $email ) ) { |
| 853 |
$response = array( |
| 854 |
'id' => 0, |
| 855 |
'editpage' => '', |
| 856 |
'message' => $this->e_msg_login, |
| 857 |
'description' => $this->e_desc_login, |
| 858 |
'success' => false, |
| 859 |
); |
| 860 |
|
| 861 |
wp_send_json( $response ); |
| 862 |
wp_die(); |
| 863 |
} |
| 864 |
|
| 865 |
$args = $this->wdkit_parse_args( $_POST ); |
| 866 |
$args['token'] = $this->wdkit_login_user_token( $email ); |
| 867 |
unset( $args['email'] ); |
| 868 |
|
| 869 |
global $post; |
| 870 |
|
| 871 |
$post_id = get_the_ID(); |
| 872 |
$custom_fields = array(); |
| 873 |
if ( ! empty( $post_id ) ) { |
| 874 |
$meta_fields = get_post_custom( get_the_ID() ); |
| 875 |
|
| 876 |
foreach ( $meta_fields as $key => $value ) { |
| 877 |
if ( str_contains( $key, 'nxt-' ) ) { |
| 878 |
$custom_fields[ $key ] = $value; |
| 879 |
} |
| 880 |
} |
| 881 |
|
| 882 |
if ( ! empty( $custom_fields ) ) { |
| 883 |
$data = json_decode( $args['data'], true ); |
| 884 |
$data['custom_meta'] = $custom_fields; |
| 885 |
$args['data'] = wp_json_encode( $data ); |
| 886 |
} |
| 887 |
} |
| 888 |
|
| 889 |
$response = WDesignKit_Data_Query::get_data( 'save_template', $args ); |
| 890 |
|
| 891 |
wp_send_json( $response ); |
| 892 |
wp_die(); |
| 893 |
} |
| 894 |
|
| 895 |
/** |
| 896 |
* |
| 897 |
* It is For Find User Existing template List. |
| 898 |
* |
| 899 |
* @since 1.0.6 |
| 900 |
*/ |
| 901 |
protected function wdkit_find_existing_template() { |
| 902 |
$array_data = array( |
| 903 |
'search' => isset( $_POST['search'] ) ? sanitize_text_field( wp_unslash( $_POST['search'] ) ) : '', |
| 904 |
'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', |
| 905 |
'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '', |
| 906 |
'u_id' => isset( $_POST['u_id'] ) ? sanitize_text_field( wp_unslash( $_POST['u_id'] ) ) : '', |
| 907 |
'builder' => isset( $_POST['builder'] ) ? sanitize_text_field( wp_unslash( $_POST['builder'] ) ) : '', |
| 908 |
'parpage' => isset( $_POST['parpage'] ) ? sanitize_text_field( wp_unslash( $_POST['parpage'] ) ) : 12, |
| 909 |
); |
| 910 |
|
| 911 |
$response = $this->wkit_api_call( $array_data, 'existing_template' ); |
| 912 |
|
| 913 |
wp_send_json( $response ); |
| 914 |
wp_die(); |
| 915 |
} |
| 916 |
|
| 917 |
/** |
| 918 |
* |
| 919 |
* It is For Update User Existing template List. |
| 920 |
* |
| 921 |
* @since 1.0.6 |
| 922 |
*/ |
| 923 |
protected function wdkit_update_template() { |
| 924 |
$array_data = array( |
| 925 |
'data' => isset( $_POST['data'] ) ? wp_unslash( $_POST['data'] ) : '', |
| 926 |
'token' => isset( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', |
| 927 |
'type' => isset( $_POST['type'] ) ? sanitize_text_field( wp_unslash( $_POST['type'] ) ) : '', |
| 928 |
'id' => isset( $_POST['id'] ) ? sanitize_text_field( wp_unslash( $_POST['id'] ) ) : '', |
| 929 |
); |
| 930 |
|
| 931 |
$response = $this->wkit_api_call( $array_data, 'existing_template' ); |
| 932 |
|
| 933 |
wp_send_json( $response ); |
| 934 |
wp_die(); |
| 935 |
} |
| 936 |
|
| 937 |
/** |
| 938 |
* |
| 939 |
* It is Use for manage favourite template. |
| 940 |
* |
| 941 |
* @since 1.0.0 |
| 942 |
*/ |
| 943 |
protected function wdkit_manage_favorite() { |
| 944 |
$template_id = isset( $_POST['template_id'] ) ? strtolower( sanitize_text_field( wp_unslash( $_POST['template_id'] ) ) ) : 0; |
| 945 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 946 |
|
| 947 |
if ( empty( $email ) || empty( $template_id ) ) { |
| 948 |
$response = array( |
| 949 |
'message' => $this->e_msg_login, |
| 950 |
'description' => $this->e_desc_login, |
| 951 |
'success' => false, |
| 952 |
); |
| 953 |
|
| 954 |
wp_send_json( $response ); |
| 955 |
wp_die(); |
| 956 |
} |
| 957 |
|
| 958 |
$args = $this->wdkit_parse_args( $_POST ); |
| 959 |
$args['token'] = $this->wdkit_login_user_token( $email ); |
| 960 |
|
| 961 |
unset( $args['email'] ); |
| 962 |
$response = WDesignKit_Data_Query::get_data( 'manage_favorite', $args ); |
| 963 |
|
| 964 |
wp_send_json( $response ); |
| 965 |
wp_die(); |
| 966 |
} |
| 967 |
|
| 968 |
/** |
| 969 |
* |
| 970 |
* It is Use for Check Plugin Dependency of template. |
| 971 |
* |
| 972 |
* @since 1.0.0 |
| 973 |
* @version 1.0.9 |
| 974 |
*/ |
| 975 |
protected function wdkit_check_plugins_depends() { |
| 976 |
$plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ) ) : array(); |
| 977 |
$update_plugin = array(); |
| 978 |
|
| 979 |
if ( empty( $plugins ) || ! is_array( $plugins ) ) { |
| 980 |
$this->wdkit_error_msg( array( 'plugins' => 'No Plugins' ) ); |
| 981 |
} |
| 982 |
|
| 983 |
$all_plugins = $this->get_plugins(); |
| 984 |
foreach ( $plugins as $plugin ) { |
| 985 |
$pluginslug = ! empty( $plugin->plugin_slug ) ? sanitize_text_field( wp_unslash( $plugin->plugin_slug ) ) : ''; |
| 986 |
$free_pro = ! empty( $plugin->freepro ) ? sanitize_text_field( wp_unslash( $plugin->freepro ) ) : '0'; |
| 987 |
$type = ! empty( $plugin->type ) ? sanitize_text_field( wp_unslash( $plugin->type ) ) : 'plugin'; |
| 988 |
|
| 989 |
if ( is_null( $pluginslug ) ) { |
| 990 |
$plugin->status = 'warning'; |
| 991 |
$update_plugin[] = $plugin; |
| 992 |
|
| 993 |
continue; |
| 994 |
} |
| 995 |
|
| 996 |
if ( 'plugin' === $type ) { |
| 997 |
if ( ! is_plugin_active( $pluginslug ) ) { |
| 998 |
if ( ! isset( $all_plugins[ $pluginslug ] ) ) { |
| 999 |
if ( isset( $free_pro ) && '1' === $free_pro ) { |
| 1000 |
$plugin->status = 'manually'; |
| 1001 |
} else { |
| 1002 |
$plugin->status = 'unavailable'; |
| 1003 |
} |
| 1004 |
} else { |
| 1005 |
$plugin->status = 'inactive'; |
| 1006 |
} |
| 1007 |
|
| 1008 |
$update_plugin[] = $plugin; |
| 1009 |
} elseif ( is_plugin_active( $pluginslug ) ) { |
| 1010 |
$plugin->status = 'active'; |
| 1011 |
$update_plugin[] = $plugin; |
| 1012 |
} |
| 1013 |
} elseif ( 'theme' === $type ) { |
| 1014 |
$theme_array = array_keys( wp_get_themes() ); |
| 1015 |
$current_themes = get_current_theme(); |
| 1016 |
$theme_slug = get_stylesheet(); |
| 1017 |
|
| 1018 |
if ( $theme_slug === $plugin->original_slug ) { |
| 1019 |
|
| 1020 |
$plugin->status = 'active'; |
| 1021 |
} else { |
| 1022 |
$theme_name = $plugin->original_slug; |
| 1023 |
if ( ! in_array( $theme_name, $theme_array ) ) { |
| 1024 |
if ( isset( $free_pro ) && '1' === $free_pro ) { |
| 1025 |
$plugin->status = 'manually'; |
| 1026 |
} else { |
| 1027 |
$plugin->status = 'unavailable'; |
| 1028 |
} |
| 1029 |
} else { |
| 1030 |
$plugin->status = 'inactive'; |
| 1031 |
} |
| 1032 |
} |
| 1033 |
|
| 1034 |
$update_plugin[] = $plugin; |
| 1035 |
} |
| 1036 |
} |
| 1037 |
|
| 1038 |
$this->wdkit_success_msg( array( 'plugins' => $update_plugin ) ); |
| 1039 |
} |
| 1040 |
|
| 1041 |
/** |
| 1042 |
* |
| 1043 |
* It is Use for Install dependent plugin. |
| 1044 |
* |
| 1045 |
* @since 1.0.0 |
| 1046 |
* @version 1.0.9 |
| 1047 |
*/ |
| 1048 |
protected function wdkit_install_plugins_depends() { |
| 1049 |
$plugins = isset( $_POST['plugins'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['plugins'] ) ), true ) : array(); |
| 1050 |
$type = ! empty( $plugins['type'] ) ? $plugins['type'] : 'plugin'; |
| 1051 |
|
| 1052 |
$responce = ''; |
| 1053 |
if ( 'plugin' === $type ) { |
| 1054 |
$responce = Wdkit_Depends_Installer::get_instance()->wdkit_install_plugin( $plugins ); |
| 1055 |
} elseif ( 'theme' === $type ) { |
| 1056 |
$theme_name = ! empty( $plugins['original_slug'] ) ? $plugins['original_slug'] : ''; |
| 1057 |
if ( ! empty( $theme_name ) ) { |
| 1058 |
|
| 1059 |
$activate_result = switch_theme( $theme_name ); |
| 1060 |
|
| 1061 |
if ( ! is_wp_error( $activate_result ) ) { |
| 1062 |
$responce = array( |
| 1063 |
'message' => esc_html__( 'Theme activated successfully', 'wdesignkit' ), |
| 1064 |
'description' => esc_html__( 'Theme successfully activated', 'wdesignkit' ), |
| 1065 |
'slug' => 'the-plus-addons-for-block-editor', |
| 1066 |
'status' => 'active', |
| 1067 |
'success' => true, |
| 1068 |
); |
| 1069 |
} else { |
| 1070 |
$responce = array( |
| 1071 |
'message' => esc_html__( 'Theme Not Activated !', 'wdesignkit' ), |
| 1072 |
'description' => $activate_result->get_error_message(), |
| 1073 |
'status' => 'inactive', |
| 1074 |
'success' => false, |
| 1075 |
); |
| 1076 |
} |
| 1077 |
} else { |
| 1078 |
$responce = array( |
| 1079 |
'message' => esc_html__( 'Theme Name not Found', 'wdesignkit' ), |
| 1080 |
'description' => esc_html__( 'Can Not Found Theme Name you Enterd.', 'wdesignkit' ), |
| 1081 |
'success' => true, |
| 1082 |
); |
| 1083 |
} |
| 1084 |
} |
| 1085 |
|
| 1086 |
wp_send_json( $responce ); |
| 1087 |
wp_die(); |
| 1088 |
} |
| 1089 |
|
| 1090 |
/** |
| 1091 |
* |
| 1092 |
* It is Use for get plugin list. |
| 1093 |
* |
| 1094 |
* @since 1.0.0 |
| 1095 |
*/ |
| 1096 |
private function get_plugins() { |
| 1097 |
if ( ! function_exists( 'get_plugins' ) ) { |
| 1098 |
require_once \ABSPATH . 'wp-admin/includes/plugin.php'; |
| 1099 |
} |
| 1100 |
|
| 1101 |
return get_plugins(); |
| 1102 |
} |
| 1103 |
|
| 1104 |
/** |
| 1105 |
* Get Download Template Content |
| 1106 |
* |
| 1107 |
* @since 1.0.0 |
| 1108 |
*/ |
| 1109 |
protected function wdkit_import_template() { |
| 1110 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1111 |
|
| 1112 |
if ( empty( $args['email'] ) ) { |
| 1113 |
$response = array( |
| 1114 |
'content' => '', |
| 1115 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1116 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1117 |
'success' => true, |
| 1118 |
); |
| 1119 |
|
| 1120 |
wp_send_json( $response ); |
| 1121 |
wp_die(); |
| 1122 |
} |
| 1123 |
|
| 1124 |
$response = ''; |
| 1125 |
if ( empty( $args['email'] ) || empty( $args['template_id'] ) ) { |
| 1126 |
$result = array( |
| 1127 |
'content' => '', |
| 1128 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1129 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1130 |
'success' => false, |
| 1131 |
); |
| 1132 |
|
| 1133 |
wp_send_json( $response ); |
| 1134 |
wp_die(); |
| 1135 |
} |
| 1136 |
|
| 1137 |
$args['token'] = $this->wdkit_login_user_token( $args['email'] ); |
| 1138 |
|
| 1139 |
unset( $args['email'] ); |
| 1140 |
$response = WDesignKit_Data_Query::get_data( 'import_template', $args ); |
| 1141 |
$custom_meta = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; |
| 1142 |
|
| 1143 |
/** Custom meta Field */ |
| 1144 |
if ( ! empty( $custom_meta ) && 'true' === $custom_meta && ! empty( $response ) && ! empty( $response['content'] ) ) { |
| 1145 |
|
| 1146 |
$res_content = json_decode( $response['content'], true ); |
| 1147 |
if ( isset( $res_content['custom_meta'] ) && ! empty( $res_content['custom_meta'] ) ) { |
| 1148 |
$meta_data = $res_content['custom_meta']; |
| 1149 |
|
| 1150 |
if ( ! empty( $meta_data ) ) { |
| 1151 |
foreach ( $meta_data as $meta_key => $meta_val ) { |
| 1152 |
if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { |
| 1153 |
$meta_val[0] = maybe_unserialize( $meta_val[0] ); |
| 1154 |
} |
| 1155 |
|
| 1156 |
if ( get_post_meta( get_the_ID(), $meta_key, true ) === '' ) { |
| 1157 |
add_post_meta( get_the_ID(), $meta_key, $meta_val[0] ); |
| 1158 |
} else { |
| 1159 |
update_post_meta( get_the_ID(), $meta_key, $meta_val[0] ); |
| 1160 |
} |
| 1161 |
} |
| 1162 |
} |
| 1163 |
} |
| 1164 |
} |
| 1165 |
|
| 1166 |
wp_send_json( $response ); |
| 1167 |
wp_die(); |
| 1168 |
} |
| 1169 |
|
| 1170 |
/** |
| 1171 |
* This Function is Use For Media Import |
| 1172 |
* |
| 1173 |
* @since 1.0.0 |
| 1174 |
* |
| 1175 |
* @param array $content store media content. |
| 1176 |
* @param string $editor it is check editor. |
| 1177 |
*/ |
| 1178 |
public function wdkit_media_import( $content = array(), $editor = '' ) { |
| 1179 |
|
| 1180 |
if ( empty( $content ) && empty( $editor ) ) { |
| 1181 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1182 |
$content = ! empty( $args['content'] ) ? json_decode( $args['content'], true ) : array(); |
| 1183 |
} else { |
| 1184 |
$args = array( |
| 1185 |
'content' => $content, |
| 1186 |
'editor' => $editor, |
| 1187 |
); |
| 1188 |
$content = ! empty( $args['content'] ) ? $args['content'] : array(); |
| 1189 |
|
| 1190 |
if ( 'elementor' === $args['editor'] ) { |
| 1191 |
$content = json_decode( $content, true ); |
| 1192 |
} |
| 1193 |
} |
| 1194 |
|
| 1195 |
if ( ! class_exists( 'Wdkit_Import_Images' ) ) { |
| 1196 |
require_once WDKIT_INCLUDES . 'admin/class-wdkit-import-images.php'; |
| 1197 |
} |
| 1198 |
|
| 1199 |
if ( ! empty( $args['editor'] ) && 'gutenberg' === $args['editor'] && ! empty( $content ) ) { |
| 1200 |
$media_import = array( $content ); |
| 1201 |
$media_import = self::blocks_import_media_copy_content( $media_import ); |
| 1202 |
$content = $media_import[0]; |
| 1203 |
} elseif ( ! empty( $args['editor'] ) && 'elementor' === $args['editor'] && ! empty( $content ) ) { |
| 1204 |
$media_import = array( $content ); |
| 1205 |
$media_import = self::widgets_elements_id_change( $media_import ); |
| 1206 |
$media_import = self::widgets_import_media_copy_content( $media_import ); |
| 1207 |
$content = $media_import[0]; |
| 1208 |
} |
| 1209 |
|
| 1210 |
return $content; |
| 1211 |
} |
| 1212 |
|
| 1213 |
/** |
| 1214 |
* Widgets elements data |
| 1215 |
* |
| 1216 |
* @since 1.0.0 |
| 1217 |
* @param string $media_import it is store media data. |
| 1218 |
*/ |
| 1219 |
protected static function widgets_elements_id_change( $media_import ) { |
| 1220 |
if ( did_action( 'elementor/loaded' ) ) { |
| 1221 |
return \Elementor\Plugin::instance()->db->iterate_data( |
| 1222 |
$media_import, |
| 1223 |
function ( $element ) { |
| 1224 |
$element['id'] = \Elementor\Utils::generate_random_string(); |
| 1225 |
return $element; |
| 1226 |
} |
| 1227 |
); |
| 1228 |
} else { |
| 1229 |
return $media_import; |
| 1230 |
} |
| 1231 |
} |
| 1232 |
|
| 1233 |
/** |
| 1234 |
* Widgets Media import copy content. |
| 1235 |
* |
| 1236 |
* @since 1.0.0 |
| 1237 |
* |
| 1238 |
* @param string $media_import it is store media data. |
| 1239 |
*/ |
| 1240 |
protected static function widgets_import_media_copy_content( $media_import ) { |
| 1241 |
if ( did_action( 'elementor/loaded' ) ) { |
| 1242 |
|
| 1243 |
return \Elementor\Plugin::instance()->db->iterate_data( |
| 1244 |
$media_import, |
| 1245 |
function ( $element_data ) { |
| 1246 |
$elements = \Elementor\Plugin::instance()->elements_manager->create_element_instance( $element_data ); |
| 1247 |
|
| 1248 |
if ( ! $elements ) { |
| 1249 |
return null; |
| 1250 |
} |
| 1251 |
|
| 1252 |
return self::widgets_element_import_start( $elements ); |
| 1253 |
} |
| 1254 |
); |
| 1255 |
} else { |
| 1256 |
return $media_import; |
| 1257 |
} |
| 1258 |
} |
| 1259 |
|
| 1260 |
/** |
| 1261 |
* Start element copy content for media import. |
| 1262 |
* |
| 1263 |
* @since 1.0.0 |
| 1264 |
* |
| 1265 |
* @param string \Elementor\Controls_Stack $element it is store elementor data. |
| 1266 |
*/ |
| 1267 |
protected static function widgets_element_import_start( \Elementor\Controls_Stack $element ) { |
| 1268 |
$get_element_instance = $element->get_data(); |
| 1269 |
$tp_mi_on_fun = 'on_import'; |
| 1270 |
|
| 1271 |
if ( method_exists( $element, $tp_mi_on_fun ) ) { |
| 1272 |
$get_element_instance = $element->{$tp_mi_on_fun}( $get_element_instance ); |
| 1273 |
} |
| 1274 |
|
| 1275 |
foreach ( $element->get_controls() as $get_control ) { |
| 1276 |
$control_type = \Elementor\Plugin::instance()->controls_manager->get_control( $get_control['type'] ); |
| 1277 |
$control_name = $get_control['name']; |
| 1278 |
|
| 1279 |
if ( ! $control_type ) { |
| 1280 |
return $get_element_instance; |
| 1281 |
} |
| 1282 |
|
| 1283 |
if ( method_exists( $control_type, $tp_mi_on_fun ) ) { |
| 1284 |
$get_element_instance['settings'][ $control_name ] = $control_type->{$tp_mi_on_fun}( $element->get_settings( $control_name ), $get_control ); |
| 1285 |
} |
| 1286 |
} |
| 1287 |
|
| 1288 |
return $get_element_instance; |
| 1289 |
} |
| 1290 |
|
| 1291 |
/** |
| 1292 |
* Blocks Recursively data |
| 1293 |
* |
| 1294 |
* @param string $data_import gutenber data import. |
| 1295 |
*/ |
| 1296 |
public static function blocks_import_media_copy_content( $data_import ) { |
| 1297 |
if ( ! empty( $data_import ) ) { |
| 1298 |
foreach ( $data_import[0] as $key => $val ) { |
| 1299 |
if ( array_key_exists( 'blockName', $val ) && ( empty( $val['blockName'] ) || null === $val['blockName'] || empty( $val['blockName'] ) || ' ' === $val['blockName'] ) ) { |
| 1300 |
unset( $data_import[0][ $key ] ); |
| 1301 |
} |
| 1302 |
} |
| 1303 |
} |
| 1304 |
|
| 1305 |
return self::blocks_array_recursively_data( |
| 1306 |
$data_import, |
| 1307 |
function ( $block_data ) { |
| 1308 |
$elements = self::blocks_data_instance( $block_data ); |
| 1309 |
return $elements; |
| 1310 |
} |
| 1311 |
); |
| 1312 |
} |
| 1313 |
|
| 1314 |
/** |
| 1315 |
* Blocks Recursively data |
| 1316 |
* |
| 1317 |
* @param array $data store data. |
| 1318 |
* @param string $callback store data. |
| 1319 |
* @param string $args store data. |
| 1320 |
*/ |
| 1321 |
public static function blocks_array_recursively_data( $data, $callback, $args = array() ) { |
| 1322 |
if ( ( isset( $data['name'] ) && ! empty( $data['name'] ) ) || ( isset( $data['blockName'] ) && ! empty( $data['blockName'] ) ) ) { |
| 1323 |
if ( ! empty( $data['innerBlocks'] ) ) { |
| 1324 |
$data['innerBlocks'] = self::blocks_array_recursively_data( $data['innerBlocks'], $callback, $args ); |
| 1325 |
} |
| 1326 |
|
| 1327 |
return call_user_func( $callback, $data, $args ); |
| 1328 |
} |
| 1329 |
|
| 1330 |
if ( ! empty( $data ) ) { |
| 1331 |
$data = (array) $data; |
| 1332 |
foreach ( $data as $block_key => $block_value ) { |
| 1333 |
$block_data = self::blocks_array_recursively_data( $data[ $block_key ], $callback, $args ); |
| 1334 |
|
| 1335 |
if ( null === $block_data ) { |
| 1336 |
continue; |
| 1337 |
} |
| 1338 |
|
| 1339 |
$data[ $block_key ] = $block_data; |
| 1340 |
} |
| 1341 |
} |
| 1342 |
|
| 1343 |
return $data; |
| 1344 |
} |
| 1345 |
|
| 1346 |
/** |
| 1347 |
* Check Blocks data media Url |
| 1348 |
* |
| 1349 |
* @param array $block_data store data. |
| 1350 |
* @param array $args store data. |
| 1351 |
* @param array $block_args store data. |
| 1352 |
*/ |
| 1353 |
public static function blocks_data_instance( array $block_data, array $args = array(), $block_args = null ) { |
| 1354 |
|
| 1355 |
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'] ) ) ) { |
| 1356 |
$blocks_attr = isset( $block_data['attributes'] ) ? $block_data['attributes'] : ( isset( $block_data['attrs'] ) ? $block_data['attrs'] : array() ); |
| 1357 |
foreach ( $blocks_attr as $block_key => $block_val ) { |
| 1358 |
if ( isset( $block_val['url'] ) && isset( $block_val['id'] ) && ! empty( $block_val['url'] ) ) { |
| 1359 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val ); |
| 1360 |
$blocks_attr[ $block_key ] = $new_media; |
| 1361 |
} elseif ( isset( $block_val['url'] ) && ! empty( $block_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $block_val['url'] ) ) { |
| 1362 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $block_val ); |
| 1363 |
$blocks_attr[ $block_key ] = $new_media; |
| 1364 |
} elseif ( is_array( $block_val ) && ! empty( $block_val ) ) { |
| 1365 |
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 ) ) { |
| 1366 |
foreach ( $block_val as $key => $val ) { |
| 1367 |
if ( is_array( $val ) && ! empty( $val ) ) { |
| 1368 |
|
| 1369 |
if ( isset( $val['url'] ) && ( isset( $val['Id'] ) || isset( $val['id'] ) ) && ! empty( $val['url'] ) ) { |
| 1370 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $val ); |
| 1371 |
$blocks_attr[ $block_key ][ $key ] = $new_media; |
| 1372 |
} elseif ( isset( $val['url'] ) && ! empty( $val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $val['url'] ) ) { |
| 1373 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $val ); |
| 1374 |
$blocks_attr[ $block_key ][ $key ] = $new_media; |
| 1375 |
} else { |
| 1376 |
foreach ( $val as $sub_key => $sub_val ) { |
| 1377 |
if ( isset( $sub_val['url'] ) && ( isset( $sub_val['Id'] ) || isset( $sub_val['id'] ) ) && ! empty( $sub_val['url'] ) ) { |
| 1378 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val ); |
| 1379 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media; |
| 1380 |
} elseif ( isset( $sub_val['url'] ) && ! empty( $sub_val['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val['url'] ) ) { |
| 1381 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val ); |
| 1382 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ] = $new_media; |
| 1383 |
} elseif ( is_array( $sub_val ) && ! empty( $sub_val ) ) { |
| 1384 |
foreach ( $sub_val as $sub_key1 => $sub_val1 ) { |
| 1385 |
if ( isset( $sub_val1['url'] ) && ( isset( $sub_val1['Id'] ) || isset( $sub_val1['id'] ) ) && ! empty( $sub_val1['url'] ) ) { |
| 1386 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 ); |
| 1387 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media; |
| 1388 |
} elseif ( isset( $sub_val1['url'] ) && ! empty( $sub_val1['url'] ) && preg_match( '/\.(jpg|png|jpeg|gif|svg|webp)$/', $sub_val1['url'] ) ) { |
| 1389 |
$new_media = Wdkit_Import_Images::wdkit_Import_media( $sub_val1 ); |
| 1390 |
$blocks_attr[ $block_key ][ $key ][ $sub_key ][ $sub_key1 ] = $new_media; |
| 1391 |
} |
| 1392 |
} |
| 1393 |
} |
| 1394 |
} |
| 1395 |
} |
| 1396 |
} |
| 1397 |
} |
| 1398 |
} |
| 1399 |
} |
| 1400 |
} |
| 1401 |
if ( isset( $block_data['attributes'] ) ) { |
| 1402 |
$block_data['attributes'] = $blocks_attr; |
| 1403 |
} elseif ( isset( $block_data['attrs'] ) ) { |
| 1404 |
$block_data['attrs'] = $blocks_attr; |
| 1405 |
} |
| 1406 |
} |
| 1407 |
|
| 1408 |
return $block_data; |
| 1409 |
} |
| 1410 |
|
| 1411 |
/** |
| 1412 |
* Kit Template Import Pages/Sections |
| 1413 |
* |
| 1414 |
* @since 1.0.0 |
| 1415 |
* */ |
| 1416 |
protected function wdkit_import_kit_template() { |
| 1417 |
|
| 1418 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 1419 |
return false; |
| 1420 |
} |
| 1421 |
|
| 1422 |
$page_section = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : ''; |
| 1423 |
|
| 1424 |
if ( isset( $page_section ) ) { |
| 1425 |
$args['page_section'] = ! empty( $page_section ) ? sanitize_text_field( wp_unslash( $page_section ) ) : ''; |
| 1426 |
} |
| 1427 |
|
| 1428 |
$template_ids = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array(); |
| 1429 |
$email = ! empty( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : ''; |
| 1430 |
$editor = isset( $_POST['editor'] ) ? sanitize_text_field( wp_unslash( $_POST['editor'] ) ) : ''; |
| 1431 |
|
| 1432 |
if ( empty( $email ) || empty( $template_ids ) ) { |
| 1433 |
$output = array( |
| 1434 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1435 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1436 |
'success' => false, |
| 1437 |
); |
| 1438 |
|
| 1439 |
wp_send_json( $output ); |
| 1440 |
wp_die(); |
| 1441 |
} |
| 1442 |
|
| 1443 |
/**Not Usefull*/ |
| 1444 |
if ( isset( $_POST['select'] ) ) { |
| 1445 |
$args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : ''; |
| 1446 |
} |
| 1447 |
|
| 1448 |
$args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; |
| 1449 |
$args['editor'] = $editor; |
| 1450 |
|
| 1451 |
$token = $this->wdkit_login_user_token( $email ); |
| 1452 |
|
| 1453 |
$temp_args = array( |
| 1454 |
'token' => $token, |
| 1455 |
'template_id' => $template_ids['id'], |
| 1456 |
'editor' => $editor, |
| 1457 |
); |
| 1458 |
|
| 1459 |
$response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args ); |
| 1460 |
$output = array(); |
| 1461 |
|
| 1462 |
if ( 'error' === $response['content'] ) { |
| 1463 |
wp_send_json( $response ); |
| 1464 |
wp_die(); |
| 1465 |
} else { |
| 1466 |
$output[ $template_ids['id'] ] = $this->import_page_section_content( $args, $template_ids['id'], $response, $template_ids ); |
| 1467 |
$output['message'] = $response['message']; |
| 1468 |
$output['description'] = $response['description']; |
| 1469 |
$output['success'] = $response['success']; |
| 1470 |
} |
| 1471 |
|
| 1472 |
wp_send_json( $output ); |
| 1473 |
wp_die(); |
| 1474 |
} |
| 1475 |
|
| 1476 |
/** |
| 1477 |
* Import single template and section from plugin only |
| 1478 |
* */ |
| 1479 |
protected function wdkit_import_multi_template() { |
| 1480 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1481 |
|
| 1482 |
if ( ! current_user_can( 'manage_options' ) ) { |
| 1483 |
return false; |
| 1484 |
} |
| 1485 |
|
| 1486 |
if ( empty( $_POST['template_ids'] ) ) { |
| 1487 |
$output = array( |
| 1488 |
'data' => array(), |
| 1489 |
'message' => esc_html__( 'Invalid import', 'wdesignkit' ), |
| 1490 |
'description' => esc_html__( 'Invalid import: Check your details and try again.', 'wdesignkit' ), |
| 1491 |
'success' => false, |
| 1492 |
); |
| 1493 |
|
| 1494 |
wp_send_json( $output ); |
| 1495 |
wp_die(); |
| 1496 |
} |
| 1497 |
|
| 1498 |
if ( isset( $_POST['template_ids'] ) ) { |
| 1499 |
$args['template_ids'] = ! empty( $_POST['template_ids'] ) ? json_decode( sanitize_text_field( wp_unslash( $_POST['template_ids'] ) ), true ) : array(); |
| 1500 |
} |
| 1501 |
|
| 1502 |
if ( isset( $_POST['page_section'] ) ) { |
| 1503 |
$args['page_section'] = ! empty( $_POST['page_section'] ) ? sanitize_text_field( wp_unslash( $_POST['page_section'] ) ) : ''; |
| 1504 |
} |
| 1505 |
|
| 1506 |
if ( isset( $_POST['select'] ) ) { |
| 1507 |
$args['post_type'] = ! empty( $_POST['select'] ) ? sanitize_text_field( wp_unslash( $_POST['select'] ) ) : ''; |
| 1508 |
} |
| 1509 |
|
| 1510 |
$args['custom_meta'] = isset( $_POST['custom_meta'] ) ? sanitize_text_field( wp_unslash( $_POST['custom_meta'] ) ) : false; |
| 1511 |
if ( ! empty( $args['template_ids'] ) && ! empty( $args['page_section'] ) ) { |
| 1512 |
$output = array(); |
| 1513 |
if ( is_array( $args['template_ids'] ) ) { |
| 1514 |
foreach ( $args['template_ids'] as $key => $value ) { |
| 1515 |
if ( ! empty( $value['id'] ) ) { |
| 1516 |
$token = $this->wdkit_login_user_token( $args['email'] ); |
| 1517 |
$temp_args = array( |
| 1518 |
'token' => $token, |
| 1519 |
'template_id' => $value['id'], |
| 1520 |
'editor' => $args['editor'], |
| 1521 |
); |
| 1522 |
|
| 1523 |
$response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args ); |
| 1524 |
|
| 1525 |
if ( 'error' === $response['content'] ) { |
| 1526 |
wp_send_json( $response ); |
| 1527 |
wp_die(); |
| 1528 |
} else { |
| 1529 |
$output[ $value['id'] ] = $this->import_page_section_content( $args, $value['id'], $response, $value ); |
| 1530 |
$output['message'] = $response['message']; |
| 1531 |
$output['description'] = $response['description']; |
| 1532 |
$output['success'] = $response['success']; |
| 1533 |
} |
| 1534 |
} |
| 1535 |
} |
| 1536 |
} else { |
| 1537 |
$token = $this->wdkit_login_user_token( $args['email'] ); |
| 1538 |
$temp_args = array( |
| 1539 |
'token' => $token, |
| 1540 |
'template_id' => $args['template_ids'], |
| 1541 |
'editor' => $args['editor'], |
| 1542 |
); |
| 1543 |
|
| 1544 |
$response = WDesignKit_Data_Query::get_data( 'import_template', $temp_args ); |
| 1545 |
|
| 1546 |
if ( 'error' === $response['content'] ) { |
| 1547 |
wp_send_json( $response ); |
| 1548 |
wp_die(); |
| 1549 |
} else { |
| 1550 |
$output[ $args['template_ids'] ] = $this->import_page_section_content( $args, $args['template_ids'], $response ); |
| 1551 |
$output['message'] = $response['message']; |
| 1552 |
$output['description'] = $response['description']; |
| 1553 |
$output['success'] = $response['success']; |
| 1554 |
} |
| 1555 |
} |
| 1556 |
|
| 1557 |
$output['success'] = true; |
| 1558 |
|
| 1559 |
wp_send_json( $output ); |
| 1560 |
wp_die(); |
| 1561 |
} |
| 1562 |
} |
| 1563 |
|
| 1564 |
/** |
| 1565 |
* Import single template and section from plugin only |
| 1566 |
* |
| 1567 |
* @param array $args store data. |
| 1568 |
* @param array $template_id store data. |
| 1569 |
* @param array $data store data. |
| 1570 |
* @param array $temp_data store data. |
| 1571 |
* */ |
| 1572 |
private function import_page_section_content( $args, $template_id, $data, $temp_data = array() ) { |
| 1573 |
$enqueue_instance = new Wdkit_Enqueue(); |
| 1574 |
$get_post_type = $enqueue_instance->wdkit_get_post_type_list(); |
| 1575 |
|
| 1576 |
$post_type = ! empty( $temp_data['type'] ) ? sanitize_text_field( wp_unslash( $temp_data['type'] ) ) : 'page'; |
| 1577 |
|
| 1578 |
if ( ! array_key_exists( $post_type, $get_post_type ) ) { |
| 1579 |
$post_type = 'page'; |
| 1580 |
} |
| 1581 |
|
| 1582 |
if ( ! empty( $data ) && ! empty( $data['content'] ) && ! empty( $template_id ) && ! empty( $post_type ) && current_user_can( 'manage_options' ) ) { |
| 1583 |
$post_content = json_decode( $data['content'] ); |
| 1584 |
$post_title = isset( $post_content->title ) ? sanitize_text_field( $post_content->title ) : ''; |
| 1585 |
$file_type = isset( $post_content->file_type ) ? sanitize_text_field( $post_content->file_type ) : ''; |
| 1586 |
$content = isset( $post_content->content ) ? wp_slash( $post_content->content ) : ''; |
| 1587 |
|
| 1588 |
if ( 'gutenberg' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'wp_block' === $file_type ) ) { |
| 1589 |
if ( empty( $content ) ) { |
| 1590 |
wp_send_json( |
| 1591 |
array( |
| 1592 |
'template_id' => $template_id, |
| 1593 |
'message' => 'Content is Empty.', |
| 1594 |
) |
| 1595 |
); |
| 1596 |
wp_die(); |
| 1597 |
} elseif ( ! empty( $content ) && ! empty( $file_type ) && 'wp_block' === $file_type ) { |
| 1598 |
$parse_blocks = parse_blocks( stripslashes( $content ) ); |
| 1599 |
|
| 1600 |
$editor = ( 'wdkit' === $args['editor'] ) ? 'gutenberg' : $args['editor']; |
| 1601 |
$content = $this->wdkit_media_import( $parse_blocks, $editor ); |
| 1602 |
$content = addslashes( serialize_blocks( $content ) ); |
| 1603 |
|
| 1604 |
$inserted_post = wp_insert_post( |
| 1605 |
array( |
| 1606 |
'post_status' => 'publish', |
| 1607 |
'post_type' => $post_type, |
| 1608 |
'post_title' => $post_title, |
| 1609 |
'post_content' => $content, |
| 1610 |
) |
| 1611 |
); |
| 1612 |
|
| 1613 |
if ( is_wp_error( $inserted_post ) ) { |
| 1614 |
wp_send_json( |
| 1615 |
array( |
| 1616 |
'import_failed' => $inserted_post->get_error_message(), |
| 1617 |
'code' => $inserted_post->get_error_code(), |
| 1618 |
) |
| 1619 |
); |
| 1620 |
wp_die(); |
| 1621 |
} |
| 1622 |
|
| 1623 |
if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) { |
| 1624 |
$custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : ''; |
| 1625 |
if ( ! empty( $custom_meta ) ) { |
| 1626 |
foreach ( $custom_meta as $meta_key => $meta_val ) { |
| 1627 |
if ( isset( $meta_val[0] ) && ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { |
| 1628 |
$meta_val[0] = maybe_unserialize( $meta_val[0] ); |
| 1629 |
} |
| 1630 |
|
| 1631 |
if ( '' === get_post_meta( $inserted_post, $meta_key, true ) && isset( $meta_val[0] ) ) { |
| 1632 |
add_post_meta( $inserted_post, $meta_key, $meta_val[0] ); |
| 1633 |
} |
| 1634 |
} |
| 1635 |
} |
| 1636 |
} |
| 1637 |
|
| 1638 |
return array( |
| 1639 |
'title' => get_the_title( $inserted_post ), |
| 1640 |
'edit_link' => get_edit_post_link( $inserted_post, 'internal' ), |
| 1641 |
'view' => get_permalink( $inserted_post ), |
| 1642 |
); |
| 1643 |
} |
| 1644 |
} elseif ( 'elementor' === $args['editor'] || ( 'wdkit' === $args['editor'] && ! empty( $file_type ) && 'elementor' === $file_type ) ) { |
| 1645 |
if ( did_action( 'elementor/loaded' ) ) { |
| 1646 |
if ( empty( $content ) ) { |
| 1647 |
wp_send_json( |
| 1648 |
array( |
| 1649 |
'template_id' => $template_id, |
| 1650 |
'message' => 'Content is Empty.', |
| 1651 |
) |
| 1652 |
); |
| 1653 |
wp_die(); |
| 1654 |
} elseif ( ! empty( $content ) && ! empty( $file_type ) && 'elementor' === $file_type ) { |
| 1655 |
$post_attributes = array( |
| 1656 |
'post_title' => $post_title, |
| 1657 |
'post_type' => $post_type, |
| 1658 |
'post_status' => 'publish', |
| 1659 |
); |
| 1660 |
|
| 1661 |
if ( 'elementor_library' === $post_type ) { |
| 1662 |
$el_type = ( isset( $post_content->el_type ) && ! empty( $post_content->el_type ) ) ? sanitize_text_field( $post_content->el_type ) : 'page'; |
| 1663 |
$new_document = \Elementor\Plugin::$instance->documents->create( |
| 1664 |
$el_type, |
| 1665 |
$post_attributes |
| 1666 |
); |
| 1667 |
} else { |
| 1668 |
$new_document = \Elementor\Plugin::$instance->documents->create( |
| 1669 |
$post_attributes['post_type'], |
| 1670 |
$post_attributes |
| 1671 |
); |
| 1672 |
} |
| 1673 |
|
| 1674 |
if ( is_wp_error( $new_document ) ) { |
| 1675 |
wp_send_json( |
| 1676 |
array( |
| 1677 |
'import_failed' => $new_document->get_error_message(), |
| 1678 |
'code' => $new_document->get_error_code(), |
| 1679 |
) |
| 1680 |
); |
| 1681 |
wp_die(); |
| 1682 |
} |
| 1683 |
|
| 1684 |
$settings = ( isset( $post_content->settings ) && ! empty( $post_content->settings ) ) ? json_decode( wp_json_encode( $post_content->settings ), true ) : array(); |
| 1685 |
|
| 1686 |
$content = wp_json_encode( $content ); |
| 1687 |
$content = $this->wdkit_media_import( $content, $file_type ); |
| 1688 |
|
| 1689 |
$new_document->save( |
| 1690 |
array( |
| 1691 |
'elements' => $content, |
| 1692 |
'settings' => ! empty( $settings ) ? $settings : array(), |
| 1693 |
) |
| 1694 |
); |
| 1695 |
|
| 1696 |
$inserted_id = $new_document->get_main_id(); |
| 1697 |
|
| 1698 |
if ( ! empty( $args['custom_meta'] ) && 'true' == $args['custom_meta'] ) { |
| 1699 |
$custom_meta = isset( $post_content->custom_meta ) ? json_decode( wp_json_encode( $post_content->custom_meta ), true ) : ''; |
| 1700 |
if ( ! empty( $custom_meta ) ) { |
| 1701 |
foreach ( $custom_meta as $meta_key => $meta_val ) { |
| 1702 |
if ( ! empty( $meta_val[0] ) && is_serialized( $meta_val[0] ) ) { |
| 1703 |
$meta_val[0] = maybe_unserialize( $meta_val[0] ); |
| 1704 |
} |
| 1705 |
if ( '' === get_post_meta( $inserted_id, $meta_key, true ) ) { |
| 1706 |
add_post_meta( $inserted_id, $meta_key, $meta_val[0] ); |
| 1707 |
} |
| 1708 |
} |
| 1709 |
} |
| 1710 |
} |
| 1711 |
|
| 1712 |
return array( |
| 1713 |
'title' => get_the_title( $inserted_id ), |
| 1714 |
'edit_link' => get_edit_post_link( $inserted_id, 'internal' ), |
| 1715 |
'view' => get_permalink( $inserted_id ), |
| 1716 |
); |
| 1717 |
} |
| 1718 |
} else { |
| 1719 |
wp_send_json( |
| 1720 |
array( |
| 1721 |
'template_id' => $template_id, |
| 1722 |
'message' => esc_html__( 'Relevant Page Builder not installed or activated', 'wdesignkit' ), |
| 1723 |
) |
| 1724 |
); |
| 1725 |
wp_die(); |
| 1726 |
} |
| 1727 |
} |
| 1728 |
} |
| 1729 |
} |
| 1730 |
|
| 1731 |
/** |
| 1732 |
* Share with Me Template and widgets |
| 1733 |
* |
| 1734 |
* @since 1.0.0 |
| 1735 |
*/ |
| 1736 |
protected function wdkit_shared_with_me() { |
| 1737 |
$data = isset( $_POST['api_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['api_info'] ) ) ) ) : ''; |
| 1738 |
|
| 1739 |
$array_data = array( |
| 1740 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 1741 |
'type' => isset( $data->type ) ? sanitize_text_field( wp_unslash( $data->type ) ) : '', |
| 1742 |
'ParPage' => isset( $data->par_page ) ? (int) $data->par_page : 12, |
| 1743 |
'CurrentPage' => isset( $data->current_page ) ? (int) $data->current_page : 1, |
| 1744 |
'builder' => isset( $data->builder ) ? sanitize_text_field( wp_unslash( $data->builder ) ) : '', |
| 1745 |
); |
| 1746 |
|
| 1747 |
$response = $this->wkit_api_call( $array_data, 'shared_with_me' ); |
| 1748 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 1749 |
|
| 1750 |
wp_send_json( $response ); |
| 1751 |
wp_die(); |
| 1752 |
} |
| 1753 |
|
| 1754 |
/** |
| 1755 |
* Add new WorkSpace |
| 1756 |
* |
| 1757 |
* @since 1.0.0 |
| 1758 |
*/ |
| 1759 |
protected function wdkit_manage_workspace() { |
| 1760 |
$args = $this->wdkit_parse_args( $_POST ); |
| 1761 |
|
| 1762 |
$user_email = ! empty( $args['email'] ) ? strtolower( sanitize_email( $args['email'] ) ) : ''; |
| 1763 |
$current_wid = ! empty( $_POST['current_wid'] ) ? strtolower( sanitize_text_field( $_POST['current_wid'] ) ) : ''; |
| 1764 |
|
| 1765 |
$args['current_wid'] = $current_wid; |
| 1766 |
|
| 1767 |
if ( empty( $user_email ) ) { |
| 1768 |
$response = array( |
| 1769 |
'message' => $this->e_msg_login, |
| 1770 |
'description' => $this->e_desc_login, |
| 1771 |
'success' => false, |
| 1772 |
); |
| 1773 |
|
| 1774 |
wp_send_json( $response ); |
| 1775 |
wp_die(); |
| 1776 |
} |
| 1777 |
|
| 1778 |
$args['token'] = $this->wdkit_login_user_token( $user_email ); |
| 1779 |
unset( $user_email ); |
| 1780 |
|
| 1781 |
$response = WDesignKit_Data_Query::get_data( 'manage_workspace', $args ); |
| 1782 |
|
| 1783 |
return $response; |
| 1784 |
} |
| 1785 |
|
| 1786 |
/** |
| 1787 |
* |
| 1788 |
* It is Use for manage workspace |
| 1789 |
* |
| 1790 |
* @since 1.0.0 |
| 1791 |
*/ |
| 1792 |
protected function wdkit_manage_widget_workspace() { |
| 1793 |
$Workspace_info = isset( $_POST['workspace_info'] ) ? sanitize_text_field( wp_unslash( $_POST['workspace_info'] ) ) : array(); |
| 1794 |
$data = isset( $Workspace_info ) ? json_decode( stripslashes( $Workspace_info ) ) : array(); |
| 1795 |
|
| 1796 |
$array_data = array( |
| 1797 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 1798 |
'wstype' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 1799 |
'widget_id' => isset( $data->widget_id ) ? (int) $data->widget_id : '', |
| 1800 |
'wid' => isset( $data->wid ) ? (int) $data->wid : '', |
| 1801 |
'current_wid' => isset( $data->current_wid ) ? (int) $data->current_wid : '', |
| 1802 |
); |
| 1803 |
|
| 1804 |
$response = $this->wkit_api_call( $array_data, 'manage_workspace' ); |
| 1805 |
|
| 1806 |
wp_send_json( $response['data'] ); |
| 1807 |
wp_die(); |
| 1808 |
} |
| 1809 |
|
| 1810 |
/** |
| 1811 |
* |
| 1812 |
* It is Use for manage api key page |
| 1813 |
* |
| 1814 |
* @since 1.0.0 |
| 1815 |
*/ |
| 1816 |
protected function wdkit_activate_key() { |
| 1817 |
$email = isset( $_POST['email'] ) ? sanitize_email( wp_unslash( $_POST['email'] ) ) : ''; |
| 1818 |
$response = ''; |
| 1819 |
|
| 1820 |
if ( empty( $user_email ) ) { |
| 1821 |
$response = array( |
| 1822 |
'message' => $this->e_msg_login, |
| 1823 |
'description' => $this->e_desc_login, |
| 1824 |
'success' => false, |
| 1825 |
); |
| 1826 |
|
| 1827 |
wp_send_json( $response ); |
| 1828 |
wp_die(); |
| 1829 |
} |
| 1830 |
|
| 1831 |
$token = $this->wdkit_login_user_token( $email ); |
| 1832 |
$apikey = isset( $_POST['apikey'] ) ? sanitize_key( wp_unslash( $_POST['apikey'] ) ) : ''; |
| 1833 |
$product = isset( $_POST['product'] ) ? sanitize_text_field( wp_unslash( $_POST['product'] ) ) : ''; |
| 1834 |
$product_action = isset( $_POST['product_action'] ) ? sanitize_text_field( wp_unslash( $_POST['product_action'] ) ) : 'activate'; |
| 1835 |
if ( ! empty( $token ) && ! empty( $product ) && ! empty( $product_action ) ) { |
| 1836 |
$args = array( |
| 1837 |
'token' => $token, |
| 1838 |
'product' => $product, |
| 1839 |
'product_action' => $product_action, |
| 1840 |
); |
| 1841 |
|
| 1842 |
if ( 'activate' === $product_action ) { |
| 1843 |
$args['apikey'] = $apikey; |
| 1844 |
$args['site_url'] = home_url(); |
| 1845 |
} |
| 1846 |
|
| 1847 |
$response = Wdkit_Data_Hooks::get_data( 'wkit_activate_key', $args ); |
| 1848 |
} |
| 1849 |
|
| 1850 |
wp_send_json( $response ); |
| 1851 |
wp_die(); |
| 1852 |
} |
| 1853 |
|
| 1854 |
/** |
| 1855 |
* |
| 1856 |
* It is Use for get local widget list. |
| 1857 |
* |
| 1858 |
* @since 1.0.0 |
| 1859 |
*/ |
| 1860 |
protected function wdkit_get_widget_list() { |
| 1861 |
$builder = array(); |
| 1862 |
$a_c_s_d_s_c = array(); |
| 1863 |
$j_s_o_n_array = array(); |
| 1864 |
|
| 1865 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'bricks' ) ) { |
| 1866 |
array_push( $builder, 'bricks' ); |
| 1867 |
} |
| 1868 |
|
| 1869 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'elementor' ) ) { |
| 1870 |
array_push( $builder, 'elementor' ); |
| 1871 |
} |
| 1872 |
|
| 1873 |
if ( Wdkit_Wdesignkit::wdkit_is_compatible( 'gutenberg' ) ) { |
| 1874 |
array_push( $builder, 'gutenberg' ); |
| 1875 |
} |
| 1876 |
|
| 1877 |
foreach ( $builder as $key => $name ) { |
| 1878 |
$elementor_dir = WDKIT_BUILDER_PATH . '/' . $name; |
| 1879 |
|
| 1880 |
if ( ! empty( $elementor_dir ) && is_dir( $elementor_dir ) ) { |
| 1881 |
$elementor_list = scandir( $elementor_dir ); |
| 1882 |
$elementor_list = array_diff( $elementor_list, array( '.', '..' ) ); |
| 1883 |
|
| 1884 |
if ( ! empty( $elementor_list ) ) { |
| 1885 |
foreach ( $elementor_list as $key => $value ) { |
| 1886 |
$a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) ]['data'] = $value; |
| 1887 |
$a_c_s_d_s_c[ filemtime( "{$elementor_dir}/{$value}" ) ]['builder'] = $name; |
| 1888 |
} |
| 1889 |
} |
| 1890 |
} |
| 1891 |
} |
| 1892 |
|
| 1893 |
ksort( $a_c_s_d_s_c ); |
| 1894 |
$a_c_s_d_s_c = array_reverse( $a_c_s_d_s_c ); |
| 1895 |
|
| 1896 |
foreach ( $a_c_s_d_s_c as $key => $value ) { |
| 1897 |
$elementor_dir = WDKIT_BUILDER_PATH . '/' . $value['builder']; |
| 1898 |
|
| 1899 |
if ( file_exists( "{$elementor_dir}/{$value['data']}" ) && is_dir( "{$elementor_dir}/{$value['data']}" ) ) { |
| 1900 |
$sub_dir = scandir( "{$elementor_dir}/{$value['data']}" ); |
| 1901 |
$sub = array_diff( $sub_dir, array( '.', '..' ) ); |
| 1902 |
|
| 1903 |
foreach ( $sub as $sub_dir_value ) { |
| 1904 |
$file = new SplFileInfo( $sub_dir_value ); |
| 1905 |
$check_ext = $file->getExtension(); |
| 1906 |
$ext = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 1907 |
|
| 1908 |
if ( 'json' === $ext ) { |
| 1909 |
$widget1 = WDKIT_BUILDER_PATH . "/{$value['builder']}/{$value['data']}/{$sub_dir_value}"; |
| 1910 |
$filedata = wp_json_file_decode( $widget1 ); |
| 1911 |
$decode_data = json_decode( wp_json_encode( $filedata ), true ); |
| 1912 |
array_push( $j_s_o_n_array, $decode_data['widget_data'] ); |
| 1913 |
} |
| 1914 |
} |
| 1915 |
} |
| 1916 |
} |
| 1917 |
|
| 1918 |
wp_send_json( $j_s_o_n_array ); |
| 1919 |
wp_die(); |
| 1920 |
} |
| 1921 |
|
| 1922 |
/** |
| 1923 |
* |
| 1924 |
* It is Use for manage widget category. |
| 1925 |
* |
| 1926 |
* @since 1.0.0 |
| 1927 |
*/ |
| 1928 |
protected function wdkit_manage_widget_category() { |
| 1929 |
$data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : ''; |
| 1930 |
$data = json_decode( stripslashes( $data ) ); |
| 1931 |
|
| 1932 |
$type = isset( $data->manage_type ) ? sanitize_text_field( wp_unslash( $data->manage_type ) ) : ''; |
| 1933 |
$wkit_builder_option = get_option( 'wkit_builder' ); |
| 1934 |
|
| 1935 |
if ( empty( $wkit_builder_option ) ) { |
| 1936 |
add_option( 'wkit_builder', array( 'WDesignKit' ), '', 'yes' ); |
| 1937 |
} |
| 1938 |
|
| 1939 |
if ( 'get' === $type ) { |
| 1940 |
if ( ! in_array( 'WDesignKit', $wkit_builder_option ) ) { |
| 1941 |
update_option( 'wkit_builder', array( 'WDesignKit' ) ); |
| 1942 |
} |
| 1943 |
} elseif ( 'update' === $type ) { |
| 1944 |
$list = isset( $data->category_list ) ? $data->category_list : array(); |
| 1945 |
$list = array_unique( $list ); |
| 1946 |
$list = array_values( $list ); |
| 1947 |
|
| 1948 |
if ( ! empty( $list ) ) { |
| 1949 |
update_option( 'wkit_builder', $list ); |
| 1950 |
} |
| 1951 |
} |
| 1952 |
|
| 1953 |
wp_send_json( get_option( 'wkit_builder' ) ); |
| 1954 |
} |
| 1955 |
|
| 1956 |
/** |
| 1957 |
* |
| 1958 |
* Custom_upload_dir |
| 1959 |
* |
| 1960 |
* @since 1.0.0 |
| 1961 |
* |
| 1962 |
* @param array $upload store data. |
| 1963 |
*/ |
| 1964 |
public function custom_upload_dir( $upload ) { |
| 1965 |
// Specify the path to your custom upload directory. |
| 1966 |
if ( isset( $this->widget_folder_u_r_l ) && ! empty( $this->widget_folder_u_r_l ) ) { |
| 1967 |
|
| 1968 |
// Set the custom directory as the upload path. |
| 1969 |
$upload['path'] = $this->widget_folder_u_r_l; |
| 1970 |
// Set the URL for the uploaded file. |
| 1971 |
$upload['url'] = $upload['baseurl'] . $upload['subdir']; |
| 1972 |
} |
| 1973 |
|
| 1974 |
return $upload; |
| 1975 |
} |
| 1976 |
|
| 1977 |
/** |
| 1978 |
* |
| 1979 |
* It is Use for create widget for local |
| 1980 |
* |
| 1981 |
* @since 1.0.0 |
| 1982 |
*/ |
| 1983 |
protected function wdkit_create_widget() { |
| 1984 |
$image = ''; |
| 1985 |
if ( isset( $_FILES ) && ! empty( $_FILES ) && isset( $_FILES['image'] ) && ! empty( $_FILES['image'] ) ) { |
| 1986 |
$image = Wdkit_Data_Hooks::get_super_global_value( $_FILES, 'image' ); |
| 1987 |
} |
| 1988 |
|
| 1989 |
$icon = ''; |
| 1990 |
if ( isset( $_FILES ) && ! empty( $_FILES ) && isset( $_FILES['icon'] ) && ! empty( $_FILES['icon'] ) ) { |
| 1991 |
$icon = Wdkit_Data_Hooks::get_super_global_value( $_FILES, 'icon' ); |
| 1992 |
} |
| 1993 |
|
| 1994 |
$data = ! empty( $_POST['value'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'value', 'cr_widget' ) : ''; |
| 1995 |
$data = ! empty( $data ) ? stripslashes( $data ) : ''; |
| 1996 |
$return = ! empty( $data ) ? json_decode( $data ) : ''; |
| 1997 |
|
| 1998 |
$all_val = ! empty( $return ) ? $return : ''; |
| 1999 |
if ( empty( $all_val ) ) { |
| 2000 |
|
| 2001 |
$responce = array( |
| 2002 |
'message' => esc_html__( 'Data Not Found', 'wdesignkit' ), |
| 2003 |
'description' => esc_html__( 'something went wrong! please try again later.', 'wdesignkit' ), |
| 2004 |
'success' => false, |
| 2005 |
); |
| 2006 |
|
| 2007 |
wp_send_json( $responce ); |
| 2008 |
wp_die(); |
| 2009 |
} |
| 2010 |
|
| 2011 |
$file_name = ! empty( $all_val->file_name ) ? sanitize_text_field( $all_val->file_name ) : ''; |
| 2012 |
$folder_name = ! empty( $all_val->folder_name ) ? sanitize_text_field( $all_val->folder_name ) : ''; |
| 2013 |
$old_widget = ! empty( $all_val->old_folder ) ? sanitize_text_field( $all_val->old_folder ) : ''; |
| 2014 |
$description = ! empty( $all_val->description ) ? sanitize_text_field( $all_val->description ) : ''; |
| 2015 |
$json_file = ! empty( $all_val->json_file ) ? $all_val->json_file : ''; |
| 2016 |
$function_call = ! empty( $all_val->call ) ? sanitize_text_field( $all_val->call ) : ''; |
| 2017 |
$plugin = ! empty( $all_val->plugin ) ? $all_val->plugin : ''; |
| 2018 |
$d_image = ! empty( $all_val->d_image ) ? $all_val->d_image : ''; |
| 2019 |
$data = json_decode( $json_file ); |
| 2020 |
|
| 2021 |
$elementor_php_file = ! empty( $all_val->elementor_php_file ) ? $all_val->elementor_php_file : ''; |
| 2022 |
$elementor_js = ! empty( $all_val->elementor_js ) ? $all_val->elementor_js : ''; |
| 2023 |
$elementor_css = ! empty( $all_val->elementor_css ) ? $all_val->elementor_css : ''; |
| 2024 |
|
| 2025 |
$gutenberg_php_file = ! empty( $all_val->gutenberg_php_file ) ? $all_val->gutenberg_php_file : ''; |
| 2026 |
$gutenberg_js = ! empty( $all_val->gutenberg_js ) ? $all_val->gutenberg_js : ''; |
| 2027 |
$gutenberg_css = ! empty( $all_val->gutenberg_css ) ? $all_val->gutenberg_css : ''; |
| 2028 |
$external_js_file = ! empty( $all_val->external_js_file ) ? $all_val->external_js_file : ''; |
| 2029 |
$style_file = ! empty( $all_val->style_file ) ? $all_val->style_file : ''; |
| 2030 |
|
| 2031 |
$bricks_php_file = ! empty( $all_val->bricks_php_file ) ? $all_val->bricks_php_file : ''; |
| 2032 |
$bricks_js = ! empty( $all_val->bricks_js ) ? $all_val->bricks_js : ''; |
| 2033 |
$bricks_css = ! empty( $all_val->bricks_css ) ? $all_val->bricks_css : ''; |
| 2034 |
|
| 2035 |
$old_folder = ! empty( $old_widget ) ? str_replace( ' ', '-', $old_widget ) : ''; |
| 2036 |
$widget_type = ! empty( $data->widget_data->widgetdata->type ) ? sanitize_text_field( $data->widget_data->widgetdata->type ) : ''; |
| 2037 |
|
| 2038 |
if ( empty( $widget_type ) ) { |
| 2039 |
$responce = array( |
| 2040 |
'message' => esc_html__( 'Builder Type not found', 'wdesignkit' ), |
| 2041 |
'description' => esc_html__( 'something went wrong! please try again later.', 'wdesignkit' ), |
| 2042 |
'success' => false, |
| 2043 |
); |
| 2044 |
|
| 2045 |
wp_send_json( $responce ); |
| 2046 |
wp_die(); |
| 2047 |
} |
| 2048 |
|
| 2049 |
$builder_type_path = trailingslashit( WDKIT_BUILDER_PATH ) . trailingslashit( $widget_type ); |
| 2050 |
$widget_file_url = $builder_type_path . $folder_name; |
| 2051 |
|
| 2052 |
if ( ! is_dir( $widget_file_url ) ) { |
| 2053 |
wp_mkdir_p( $widget_file_url ); |
| 2054 |
} |
| 2055 |
|
| 2056 |
include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2057 |
\WP_Filesystem(); |
| 2058 |
global $wp_filesystem; |
| 2059 |
$widget_folder_u_r_l = trailingslashit( $widget_file_url ) . $file_name; |
| 2060 |
$this->widget_folder_u_r_l = $widget_file_url; |
| 2061 |
|
| 2062 |
if ( 'elementor' === $plugin ) { |
| 2063 |
$widget_file_list = scandir( $widget_file_url ); |
| 2064 |
$widget_file_list = array_diff( $widget_file_list, array( '.', '..' ) ); |
| 2065 |
|
| 2066 |
foreach ( $widget_file_list as $sub_dir_value ) { |
| 2067 |
$file = new SplFileInfo( $sub_dir_value ); |
| 2068 |
$check_ext = $file->getExtension(); |
| 2069 |
$extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 2070 |
|
| 2071 |
if ( 'js' === $extiona || 'css' === $extiona || 'json' === $extiona || 'php' === $extiona ) { |
| 2072 |
$wp_filesystem->rmdir( "$widget_file_url/$sub_dir_value", true ); |
| 2073 |
} |
| 2074 |
} |
| 2075 |
|
| 2076 |
if ( ! empty( $elementor_php_file ) ) { |
| 2077 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.php", $elementor_php_file ); |
| 2078 |
} |
| 2079 |
if ( ! empty( $json_file ) ) { |
| 2080 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.json", $json_file ); |
| 2081 |
} |
| 2082 |
if ( ! empty( $elementor_css ) ) { |
| 2083 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.css", $elementor_css ); |
| 2084 |
} |
| 2085 |
if ( ! empty( $elementor_js ) ) { |
| 2086 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.js", $elementor_js ); |
| 2087 |
} |
| 2088 |
} elseif ( 'bricks' === $plugin ) { |
| 2089 |
|
| 2090 |
$widget_file_list = scandir( $widget_file_url ); |
| 2091 |
$widget_file_list = array_diff( $widget_file_list, array( '.', '..' ) ); |
| 2092 |
|
| 2093 |
foreach ( $widget_file_list as $sub_dir_value ) { |
| 2094 |
$file = new SplFileInfo( $sub_dir_value ); |
| 2095 |
$check_ext = $file->getExtension(); |
| 2096 |
$extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 2097 |
|
| 2098 |
if ( 'js' === $extiona || 'css' === $extiona || 'json' === $extiona || 'php' === $extiona ) { |
| 2099 |
$wp_filesystem->rmdir( "$widget_file_url/$sub_dir_value", true ); |
| 2100 |
} |
| 2101 |
} |
| 2102 |
|
| 2103 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.php", $bricks_php_file ); |
| 2104 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.json", $json_file ); |
| 2105 |
|
| 2106 |
if ( ! empty( $bricks_css ) ) { |
| 2107 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.css", $bricks_css ); |
| 2108 |
} |
| 2109 |
|
| 2110 |
if ( ! empty( $bricks_js ) ) { |
| 2111 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.js", $bricks_js ); |
| 2112 |
} |
| 2113 |
} elseif ( 'gutenberg' === $plugin ) { |
| 2114 |
|
| 2115 |
$widget_file_list = scandir( $widget_file_url ); |
| 2116 |
$widget_file_list = array_diff( $widget_file_list, array( '.', '..' ) ); |
| 2117 |
|
| 2118 |
foreach ( $widget_file_list as $sub_dir_value ) { |
| 2119 |
$file = new SplFileInfo( $sub_dir_value ); |
| 2120 |
$check_ext = $file->getExtension(); |
| 2121 |
$extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 2122 |
|
| 2123 |
if ( 'js' === $extiona || 'css' === $extiona || 'json' === $extiona || 'php' === $extiona ) { |
| 2124 |
$wp_filesystem->rmdir( "$widget_file_url/$sub_dir_value", true ); |
| 2125 |
} |
| 2126 |
} |
| 2127 |
|
| 2128 |
if ( ! empty( $external_js_file ) ) { |
| 2129 |
$wp_filesystem->put_contents( "$widget_file_url/index.js", $external_js_file ); |
| 2130 |
} |
| 2131 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.php", $gutenberg_php_file ); |
| 2132 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.json", $json_file ); |
| 2133 |
if ( ! empty( $gutenberg_css ) ) { |
| 2134 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.css", $gutenberg_css ); |
| 2135 |
} |
| 2136 |
$wp_filesystem->put_contents( "$widget_folder_u_r_l.js", $gutenberg_js ); |
| 2137 |
} |
| 2138 |
|
| 2139 |
if ( ! empty( $image ) && ! empty( $image['tmp_name'] ) ) { |
| 2140 |
|
| 2141 |
$img_type = array( 'jpg', 'png' ); |
| 2142 |
|
| 2143 |
foreach ( $img_type as $imgext ) { |
| 2144 |
$wp_filesystem->rmdir( "$widget_folder_u_r_l . $imgext", true ); |
| 2145 |
} |
| 2146 |
|
| 2147 |
$ext = $image['type']; |
| 2148 |
$img_ext = ''; |
| 2149 |
if ( strpos( $ext, 'jpeg' ) ) { |
| 2150 |
$img_ext = 'jpg'; |
| 2151 |
} elseif ( strpos( $ext, 'png' ) ) { |
| 2152 |
$img_ext = 'png'; |
| 2153 |
} |
| 2154 |
if ( ! empty( $img_ext ) ) { |
| 2155 |
add_filter( 'upload_dir', array( $this, 'custom_upload_dir' ) ); |
| 2156 |
|
| 2157 |
$uploaded_file = wp_handle_upload( $image, array( 'test_form' => false ) ); |
| 2158 |
|
| 2159 |
rename( $uploaded_file['file'], $widget_folder_u_r_l . '.' . $img_ext ); |
| 2160 |
|
| 2161 |
remove_filter( 'upload_dir', array( $this, 'custom_upload_dir' ) ); |
| 2162 |
|
| 2163 |
} |
| 2164 |
} elseif ( ! empty( $old_widget ) ) { |
| 2165 |
$img_url = $data->widget_data->widgetdata->w_image; |
| 2166 |
$img_ext = ! empty( pathinfo( $img_url )['extension'] ) ? pathinfo( $img_url )['extension'] : ''; |
| 2167 |
|
| 2168 |
if ( ! empty( $img_ext ) ) { |
| 2169 |
$old_widget_folder = str_replace( ' ', '-', $old_widget ); |
| 2170 |
$old_widget_file = str_replace( ' ', '_', $old_widget ); |
| 2171 |
$img_path = "$builder_type_path$old_widget_folder/$old_widget_file.$img_ext"; |
| 2172 |
$img_path = str_replace( '\\', '/', $img_path ); |
| 2173 |
|
| 2174 |
if ( file_exists( $img_path ) ) { |
| 2175 |
$get_img = $img_path; |
| 2176 |
$put_img = "$widget_folder_u_r_l.$img_ext"; |
| 2177 |
|
| 2178 |
if ( ! empty( $get_img ) && ! empty( $put_img ) ) { |
| 2179 |
rename( $get_img, $put_img ); |
| 2180 |
} |
| 2181 |
} |
| 2182 |
} |
| 2183 |
} |
| 2184 |
|
| 2185 |
if ( ! empty( $d_image ) ) { |
| 2186 |
$d_image = str_replace( '\\', '', $d_image ); |
| 2187 |
$d_img_url = $d_image; |
| 2188 |
$img_body = wp_remote_get( $d_img_url ); |
| 2189 |
$img_ext = pathinfo( $d_img_url )['extension']; |
| 2190 |
$wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$widget_type/$folder_name/$file_name.$img_ext", $img_body['body'] ); |
| 2191 |
} |
| 2192 |
|
| 2193 |
if ( ! empty( $function_call ) && 'import' !== $function_call && ! empty( $old_folder ) && strtolower( $old_folder ) !== strtolower( $folder_name ) && is_dir( $builder_type_path . $old_folder ) ) { |
| 2194 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2195 |
global $wp_filesystem; |
| 2196 |
WP_Filesystem(); |
| 2197 |
$wp_filesystem->rmdir( $builder_type_path . $old_folder, true ); |
| 2198 |
} elseif ( $old_folder !== $folder_name ) { |
| 2199 |
rename( WDKIT_BUILDER_PATH . "/$widget_type/$old_folder", WDKIT_BUILDER_PATH . "/$widget_type/$folder_name" ); |
| 2200 |
} |
| 2201 |
|
| 2202 |
$responce = array( |
| 2203 |
'message' => esc_html__( 'Update Saved Successfully', 'wdesignkit' ), |
| 2204 |
'description' => esc_html__( 'Success! Update Saved', 'wdesignkit' ), |
| 2205 |
'success' => true, |
| 2206 |
); |
| 2207 |
|
| 2208 |
wp_send_json( $responce ); |
| 2209 |
wp_die(); |
| 2210 |
} |
| 2211 |
|
| 2212 |
/** |
| 2213 |
* |
| 2214 |
* It is Use for delete widget from server |
| 2215 |
* |
| 2216 |
* @since 1.0.0 |
| 2217 |
*/ |
| 2218 |
protected function wdkit_import_widget() { |
| 2219 |
$filename = ''; |
| 2220 |
if ( isset( $_FILES ) && ! empty( $_FILES ) && isset( $_FILES['zipName'] ) && ! empty( $_FILES['zipName'] ) ) { |
| 2221 |
$filename = ! empty( $_FILES['zipName']['name'] ) ? sanitize_file_name( $_FILES['zipName']['name'] ) : ''; |
| 2222 |
} |
| 2223 |
|
| 2224 |
$name = rtrim( $filename, '.zip' ); |
| 2225 |
$ext = WDKIT_BUILDER_PATH . '/elementor/dump/'; |
| 2226 |
|
| 2227 |
if ( ! is_dir( $ext ) ) { |
| 2228 |
wp_mkdir_p( $ext ); |
| 2229 |
} else { |
| 2230 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2231 |
global $wp_filesystem; |
| 2232 |
WP_Filesystem(); |
| 2233 |
$wp_filesystem->rmdir( $ext, true ); |
| 2234 |
} |
| 2235 |
|
| 2236 |
$dir = WDKIT_BUILDER_PATH . '/elementor/dump'; |
| 2237 |
$getall_json = array(); |
| 2238 |
$zip = new ZipArchive(); |
| 2239 |
|
| 2240 |
$zipname = ''; |
| 2241 |
if ( ! empty( $_FILES['zipName']['tmp_name'] ) ) { |
| 2242 |
$zipname = $this->wdkit_file_sanitizer_bypass( $_FILES, 'zipName', 'name' ); |
| 2243 |
} |
| 2244 |
|
| 2245 |
$res = $zip->open( $zipname ); |
| 2246 |
if ( true === $res ) { |
| 2247 |
$zip->extractTo( $ext ); |
| 2248 |
$zip->close(); |
| 2249 |
$widget_name = $image = $json_file = ''; |
| 2250 |
$list = scandir( $dir ); |
| 2251 |
$list = array_diff( $list, array( '.', '..' ) ); |
| 2252 |
foreach ( $list as $sub_dir_value ) { |
| 2253 |
$file = new SplFileInfo( $sub_dir_value ); |
| 2254 |
$check_ext = $file->getExtension(); |
| 2255 |
$extiona = pathinfo( $sub_dir_value, PATHINFO_EXTENSION ); |
| 2256 |
if ( 'json' === $extiona ) { |
| 2257 |
$json_file = $sub_dir_value; |
| 2258 |
$u_r_l = wp_json_file_decode( $ext . $sub_dir_value ); |
| 2259 |
if ( ! empty( $u_r_l->widget_data->widgetdata->name ) && ! empty( $u_r_l->widget_data->widgetdata->widget_id ) ) { |
| 2260 |
$widget_name = $u_r_l->widget_data->widgetdata->name; |
| 2261 |
$widget_id = $u_r_l->widget_data->widgetdata->widget_id; |
| 2262 |
$widget_type = ! empty( $u_r_l->widget_data->widgetdata->type ) ? $u_r_l->widget_data->widgetdata->type : ''; |
| 2263 |
} |
| 2264 |
} elseif ( 'jpg' === $extiona || 'png' === $extiona || 'jpeg' === $extiona ) { |
| 2265 |
$img_ext = $extiona; |
| 2266 |
$image = $sub_dir_value; |
| 2267 |
} |
| 2268 |
} |
| 2269 |
|
| 2270 |
if ( ! empty( $widget_name ) && ! empty( $json_file ) ) { |
| 2271 |
$folder_name = str_replace( ' ', '-', $widget_name ); |
| 2272 |
$file_name = str_replace( ' ', '_', $widget_name ); |
| 2273 |
$file_path = WDKIT_BUILDER_PATH . "/{$widget_type}/{$folder_name}_{$widget_id}"; |
| 2274 |
$dummy_path = WDKIT_BUILDER_PATH . '/elementor/dump'; |
| 2275 |
|
| 2276 |
if ( is_dir( $dummy_path ) ) { |
| 2277 |
if ( ! rename( $dummy_path, $file_path ) ) { |
| 2278 |
|
| 2279 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2280 |
global $wp_filesystem; |
| 2281 |
WP_Filesystem(); |
| 2282 |
$wp_filesystem->rmdir( $dummy_path, true ); |
| 2283 |
|
| 2284 |
$responce = (object) array( |
| 2285 |
'success' => false, |
| 2286 |
'message' => esc_html__( 'Widget Not imported', 'wdesignkit' ), |
| 2287 |
'description' => esc_html__( 'Widget alreday exist!', 'wdesignkit' ), |
| 2288 |
); |
| 2289 |
|
| 2290 |
wp_send_json( $responce ); |
| 2291 |
wp_die(); |
| 2292 |
} |
| 2293 |
} |
| 2294 |
|
| 2295 |
rename( "{$file_path}/{$json_file}", "{$file_path}/{$file_name}_{$widget_id}.json" ); |
| 2296 |
|
| 2297 |
$get_img_file = "{$file_path}/{$image}"; |
| 2298 |
|
| 2299 |
if ( file_exists( $get_img_file ) ) { |
| 2300 |
rename( $get_img_file, "{$file_path}/{$file_name}_{$widget_id}.{$img_ext}" ); |
| 2301 |
} |
| 2302 |
} |
| 2303 |
|
| 2304 |
$responce = (object) array( |
| 2305 |
'success' => true, |
| 2306 |
'message' => esc_html__( 'Widget imported', 'wdesignkit' ), |
| 2307 |
'description' => esc_html__( 'Widget imported successfully', 'wdesignkit' ), |
| 2308 |
'json' => $u_r_l, |
| 2309 |
); |
| 2310 |
|
| 2311 |
wp_send_json( $responce ); |
| 2312 |
wp_die(); |
| 2313 |
|
| 2314 |
} else { |
| 2315 |
$responce = (object) array( |
| 2316 |
'success' => false, |
| 2317 |
'message' => esc_html__( 'Operation Fial!', 'wdesignkit' ), |
| 2318 |
'description' => esc_html__( 'Widget imported successfully', 'wdesignkit' ), |
| 2319 |
); |
| 2320 |
|
| 2321 |
wp_send_json( $responce ); |
| 2322 |
wp_die(); |
| 2323 |
} |
| 2324 |
} |
| 2325 |
|
| 2326 |
/** |
| 2327 |
* |
| 2328 |
* Create Uniq name |
| 2329 |
* |
| 2330 |
* @since 1.0.0 |
| 2331 |
*/ |
| 2332 |
protected function generate_unique_id() { |
| 2333 |
$now = new DateTime(); |
| 2334 |
$unique_i_d = $now->format( 'YmdHis' ); |
| 2335 |
$hashed_i_d = (int) $unique_i_d % 10000; |
| 2336 |
return str_pad( $hashed_i_d, 4, '0', STR_PAD_LEFT ); |
| 2337 |
} |
| 2338 |
|
| 2339 |
/** |
| 2340 |
* |
| 2341 |
* It is Use for delete widget from server |
| 2342 |
* |
| 2343 |
* @since 1.0.0 |
| 2344 |
*/ |
| 2345 |
protected function wdkit_export_widget() { |
| 2346 |
$data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : ''; |
| 2347 |
$data = json_decode( stripslashes( $data ) ); |
| 2348 |
|
| 2349 |
$widget_name_temp = isset( $data->widget_name ) ? sanitize_text_field( $data->widget_name ) : ''; |
| 2350 |
$widget_type = isset( $data->widget_type ) ? sanitize_text_field( $data->widget_type ) : ''; |
| 2351 |
|
| 2352 |
$widget_name = str_replace( ' ', '_', $widget_name_temp ); |
| 2353 |
$folder = str_replace( ' ', '-', $widget_name_temp ); |
| 2354 |
$unique_version = $this->generate_unique_id(); |
| 2355 |
|
| 2356 |
if ( empty( $widget_type ) ) { |
| 2357 |
$result = (object) array( |
| 2358 |
'success' => false, |
| 2359 |
'url' => '', |
| 2360 |
'message' => esc_html__( 'Widget Type Fail', 'wdesignkit' ), |
| 2361 |
'description' => esc_html__( 'Widget Type Not Exists', 'wdesignkit' ), |
| 2362 |
); |
| 2363 |
|
| 2364 |
wp_send_json( $result ); |
| 2365 |
wp_die(); |
| 2366 |
} |
| 2367 |
|
| 2368 |
$downlod_path = WDKIT_BUILDER_PATH . "/{$widget_type}/"; |
| 2369 |
$new_path = "{$downlod_path}/{$folder}/{$widget_name}"; |
| 2370 |
|
| 2371 |
$download_url = WDKIT_SERVER_PATH . "/{$widget_type}/{$widget_name}.zip"; |
| 2372 |
$zip = new ZipArchive(); |
| 2373 |
$tmp_file = "{$downlod_path}{$widget_name}.zip"; |
| 2374 |
|
| 2375 |
$json_data = wp_json_file_decode( "$new_path.json" ); |
| 2376 |
$img_ext = $json_data->widget_data->widgetdata->img_ext; |
| 2377 |
|
| 2378 |
if ( true === $zip->open( $tmp_file, ZipArchive::CREATE ) ) { |
| 2379 |
$widget_wb = str_replace( '-', '_', $folder ); |
| 2380 |
$zip->addFile( "$new_path.json", "$widget_wb.json" ); |
| 2381 |
if ( ! empty( $img_ext ) ) { |
| 2382 |
$zip->addFile( "$new_path.$img_ext", "$widget_wb.$img_ext" ); |
| 2383 |
} |
| 2384 |
$zip->close(); |
| 2385 |
|
| 2386 |
$result = (object) array( |
| 2387 |
'success' => true, |
| 2388 |
'url' => $download_url, |
| 2389 |
'message' => esc_html__( 'Widget Exported', 'wdesignkit' ), |
| 2390 |
'description' => esc_html__( 'Widget Exported successfully', 'wdesignkit' ), |
| 2391 |
); |
| 2392 |
|
| 2393 |
wp_send_json( $result ); |
| 2394 |
wp_die(); |
| 2395 |
} else { |
| 2396 |
$result = (object) array( |
| 2397 |
'success' => false, |
| 2398 |
'url' => '', |
| 2399 |
'message' => esc_html__( 'Widget Exported Fail', 'wdesignkit' ), |
| 2400 |
'description' => esc_html__( 'something went wrong! please try again later.', 'wdesignkit' ), |
| 2401 |
); |
| 2402 |
|
| 2403 |
wp_send_json( $result ); |
| 2404 |
wp_die(); |
| 2405 |
} |
| 2406 |
} |
| 2407 |
|
| 2408 |
/** |
| 2409 |
* |
| 2410 |
* It is Use for delete widget from server |
| 2411 |
* |
| 2412 |
* @since 1.0.0 |
| 2413 |
*/ |
| 2414 |
protected function wdkit_delete_widget() { |
| 2415 |
$data = isset( $_POST['info'] ) ? sanitize_text_field( wp_unslash( $_POST['info'] ) ) : ''; |
| 2416 |
$data = json_decode( stripslashes( $data ) ); |
| 2417 |
|
| 2418 |
$delete_type = isset( $data->delete_type ) ? sanitize_text_field( $data->delete_type ) : ''; |
| 2419 |
|
| 2420 |
if ( 'plugin_server' === $delete_type ) { |
| 2421 |
$array_data = array( |
| 2422 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2423 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2424 |
'w_unique' => isset( $data->w_unique ) ? sanitize_text_field( $data->w_unique ) : '', |
| 2425 |
'id' => isset( $data->id ) ? sanitize_text_field( $data->id ) : '', |
| 2426 |
); |
| 2427 |
|
| 2428 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2429 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2430 |
|
| 2431 |
if ( empty( $success ) ) { |
| 2432 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2433 |
|
| 2434 |
$result = (object) array( |
| 2435 |
'success' => false, |
| 2436 |
'message' => esc_html__( 'Widget Not Deleted', 'wdesignkit' ), |
| 2437 |
'description' => esc_html__( 'Widget Not Deleted', 'wdesignkit' ), |
| 2438 |
); |
| 2439 |
|
| 2440 |
wp_send_json( $result ); |
| 2441 |
wp_die(); |
| 2442 |
} |
| 2443 |
} |
| 2444 |
|
| 2445 |
$dir_name = isset( $data->name ) ? sanitize_text_field( $data->name ) : ''; |
| 2446 |
$widget_type = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : ''; |
| 2447 |
$dir = WDKIT_BUILDER_PATH . "/{$widget_type}/{$dir_name}"; |
| 2448 |
|
| 2449 |
require_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2450 |
global $wp_filesystem; |
| 2451 |
WP_Filesystem(); |
| 2452 |
$wp_filesystem->rmdir( $dir, true ); |
| 2453 |
|
| 2454 |
if ( 'plugin_server' === $delete_type ) { |
| 2455 |
wp_send_json( $response['data'] ); |
| 2456 |
wp_die(); |
| 2457 |
} else { |
| 2458 |
$result = (object) array( |
| 2459 |
'success' => true, |
| 2460 |
'message' => esc_html__( 'widget deleted', 'wdesignkit' ), |
| 2461 |
'description' => esc_html__( 'Widget deleted successfully', 'wdesignkit' ), |
| 2462 |
); |
| 2463 |
|
| 2464 |
wp_send_json( $result ); |
| 2465 |
wp_die(); |
| 2466 |
} |
| 2467 |
} |
| 2468 |
|
| 2469 |
/** |
| 2470 |
* |
| 2471 |
* It is Use for download widget from widget listing. |
| 2472 |
* |
| 2473 |
* @since 1.0.0 |
| 2474 |
*/ |
| 2475 |
protected function wdkit_download_widget() { |
| 2476 |
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : ''; |
| 2477 |
$data = json_decode( stripslashes( $data ) ); |
| 2478 |
|
| 2479 |
$array_data = array( |
| 2480 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2481 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2482 |
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2483 |
); |
| 2484 |
|
| 2485 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2486 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2487 |
|
| 2488 |
if ( empty( $success ) ) { |
| 2489 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2490 |
$result = (object) array( |
| 2491 |
'success' => false, |
| 2492 |
'message' => $massage, |
| 2493 |
'description' => esc_html__( ' Widget not Downloaded', 'wdesignkit' ), |
| 2494 |
); |
| 2495 |
|
| 2496 |
wp_send_json( $result ); |
| 2497 |
wp_die(); |
| 2498 |
} |
| 2499 |
|
| 2500 |
$response = json_decode( wp_json_encode( $response['data'] ), true ); |
| 2501 |
|
| 2502 |
if ( empty( $response ) || empty( $response['data'] ) ) { |
| 2503 |
$message = ! empty( $response['message'] ) ? $response['message'] : 'No Response Found'; |
| 2504 |
$description = ! empty( $response['description'] ) ? $response['description'] : 'Widget not Downloaded'; |
| 2505 |
|
| 2506 |
$result = (object) array( |
| 2507 |
'success' => false, |
| 2508 |
'message' => esc_html( $message ), |
| 2509 |
'description' => esc_html( $description ), |
| 2510 |
); |
| 2511 |
|
| 2512 |
wp_send_json( $result ); |
| 2513 |
wp_die(); |
| 2514 |
} |
| 2515 |
|
| 2516 |
$img_url = ! empty( $response['data']['image'] ) ? $response['data']['image'] : ''; |
| 2517 |
$json_data = ! empty( $response['data']['json'] ) ? json_decode( $response['data']['json'] ) : ''; |
| 2518 |
|
| 2519 |
if ( empty( $img_url ) && empty( $json_data ) ) { |
| 2520 |
$responce = (object) array( |
| 2521 |
'success' => false, |
| 2522 |
'message' => esc_html__( 'No Response Found', 'wdesignkit' ), |
| 2523 |
'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ), |
| 2524 |
); |
| 2525 |
|
| 2526 |
wp_send_json( $responce ); |
| 2527 |
wp_die(); |
| 2528 |
} |
| 2529 |
|
| 2530 |
include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2531 |
\WP_Filesystem(); |
| 2532 |
global $wp_filesystem; |
| 2533 |
|
| 2534 |
$title = ! empty( $json_data->widget_data->widgetdata->name ) ? sanitize_text_field( $json_data->widget_data->widgetdata->name ) : ''; |
| 2535 |
$builder = ! empty( $json_data->widget_data->widgetdata->type ) ? sanitize_text_field( $json_data->widget_data->widgetdata->type ) : ''; |
| 2536 |
$w_uniq = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? sanitize_text_field( $json_data->widget_data->widgetdata->widget_id ) : ''; |
| 2537 |
|
| 2538 |
$folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq; |
| 2539 |
$file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq; |
| 2540 |
$builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/"; |
| 2541 |
|
| 2542 |
if ( ! is_dir( $builder_type_path ) ) { |
| 2543 |
wp_mkdir_p( $builder_type_path ); |
| 2544 |
} |
| 2545 |
|
| 2546 |
if ( ! is_dir( $builder_type_path . $folder_name ) ) { |
| 2547 |
wp_mkdir_p( $builder_type_path . $folder_name ); |
| 2548 |
} |
| 2549 |
|
| 2550 |
if ( ! empty( $img_url ) ) { |
| 2551 |
$img_body = wp_remote_get( $img_url ); |
| 2552 |
$img_ext = pathinfo( $img_url )['extension']; |
| 2553 |
|
| 2554 |
$wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] ); |
| 2555 |
$json_data->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext"; |
| 2556 |
} |
| 2557 |
|
| 2558 |
$result = (object) array( |
| 2559 |
'success' => false, |
| 2560 |
'message' => ! empty( $response['message'] ) ? $response['message'] : esc_html__( 'no message', 'wdesignkit' ), |
| 2561 |
'description' => '', |
| 2562 |
'json' => wp_json_encode( $json_data ), |
| 2563 |
); |
| 2564 |
|
| 2565 |
wp_send_json( $result ); |
| 2566 |
wp_die(); |
| 2567 |
} |
| 2568 |
|
| 2569 |
/** |
| 2570 |
* |
| 2571 |
* It is Use for download widget from browse page. |
| 2572 |
* |
| 2573 |
* @since 1.0.0 |
| 2574 |
*/ |
| 2575 |
protected function wdkit_public_download_widget() { |
| 2576 |
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : ''; |
| 2577 |
$data = json_decode( stripslashes( $data ) ); |
| 2578 |
|
| 2579 |
$array_data = array( |
| 2580 |
'id' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2581 |
'u_id' => isset( $data->u_id ) ? sanitize_text_field( $data->u_id ) : '', |
| 2582 |
'type' => isset( $data->d_type ) ? sanitize_text_field( $data->d_type ) : '', |
| 2583 |
); |
| 2584 |
|
| 2585 |
$response = $this->wkit_api_call( $array_data, 'widget/download' ); |
| 2586 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2587 |
|
| 2588 |
if ( empty( $success ) ) { |
| 2589 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2590 |
|
| 2591 |
$result = (object) array( |
| 2592 |
'success' => false, |
| 2593 |
'message' => $massage, |
| 2594 |
'description' => esc_html__( 'Widget not Downloaded', 'wdesignkit' ), |
| 2595 |
); |
| 2596 |
|
| 2597 |
wp_send_json( $result ); |
| 2598 |
wp_die(); |
| 2599 |
} |
| 2600 |
|
| 2601 |
$response = json_decode( wp_json_encode( $response['data'] ), true ); |
| 2602 |
if ( ! empty( $response ) && ! empty( $response['data'] ) ) { |
| 2603 |
$img_url = ! empty( $response['data']['image'] ) ? esc_url_raw( $response['data']['image'] ) : ''; |
| 2604 |
$json = ! empty( $response['data']['json'] ) ? wp_json_encode( $response['data']['json'] ) : ''; |
| 2605 |
|
| 2606 |
if ( ! empty( $json ) ) { |
| 2607 |
include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2608 |
\WP_Filesystem(); |
| 2609 |
global $wp_filesystem; |
| 2610 |
|
| 2611 |
$json_data = json_decode( $json ); |
| 2612 |
$json_data = json_decode( $json_data ); |
| 2613 |
$title = ! empty( $json_data->widget_data->widgetdata->name ) ? sanitize_text_field( $json_data->widget_data->widgetdata->name ) : ''; |
| 2614 |
$builder = ! empty( $json_data->widget_data->widgetdata->type ) ? sanitize_text_field( $json_data->widget_data->widgetdata->type ) : ''; |
| 2615 |
$widget_id = ! empty( $json_data->widget_data->widgetdata->widget_id ) ? sanitize_text_field( $json_data->widget_data->widgetdata->widget_id ) : ''; |
| 2616 |
|
| 2617 |
$folder_name = str_replace( ' ', '-', $title ) . '_' . $widget_id; |
| 2618 |
$file_name = str_replace( ' ', '_', $title ) . '_' . $widget_id; |
| 2619 |
|
| 2620 |
$builder_type_path = WDKIT_BUILDER_PATH . "/{$builder}/"; |
| 2621 |
|
| 2622 |
if ( ! is_dir( $builder_type_path . $folder_name ) ) { |
| 2623 |
wp_mkdir_p( $builder_type_path . $folder_name ); |
| 2624 |
} |
| 2625 |
|
| 2626 |
if ( ! empty( $img_url ) ) { |
| 2627 |
$img_body = wp_remote_get( $img_url ); |
| 2628 |
$img_ext = pathinfo( $img_url )['extension']; |
| 2629 |
$wp_filesystem->put_contents( WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name.$img_ext", $img_body['body'] ); |
| 2630 |
|
| 2631 |
$json_data->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext"; |
| 2632 |
} |
| 2633 |
|
| 2634 |
$response = (object) array( |
| 2635 |
'message' => ! empty( $response['message'] ) ? $response['message'] : '', |
| 2636 |
'description' => ! empty( $response['description'] ) ? $response['description'] : '', |
| 2637 |
'success' => ! empty( $response['success'] ) ? $response['success'] : false, |
| 2638 |
'r_id' => ! empty( $response['data']['rid'] ) ? $response['data']['rid'] : 0, |
| 2639 |
'json' => wp_json_encode( $json_data ), |
| 2640 |
); |
| 2641 |
} |
| 2642 |
} |
| 2643 |
|
| 2644 |
wp_send_json( $response ); |
| 2645 |
wp_die(); |
| 2646 |
} |
| 2647 |
|
| 2648 |
/** |
| 2649 |
* |
| 2650 |
* It is Use for sync widget to server |
| 2651 |
* |
| 2652 |
* @since 1.0.0 |
| 2653 |
*/ |
| 2654 |
protected function wdkit_add_widget() { |
| 2655 |
$data = ! empty( $_POST['widget_info'] ) ? $this->wdkit_sanitizer_bypass( $_POST, 'widget_info', 'none' ) : ''; |
| 2656 |
$data = json_decode( stripslashes( $data ) ); |
| 2657 |
|
| 2658 |
$title = isset( $data->title ) ? sanitize_text_field( $data->title ) : ''; |
| 2659 |
$builder = isset( $data->builder ) ? sanitize_text_field( $data->builder ) : ''; |
| 2660 |
$w_uniq = isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : ''; |
| 2661 |
$w_image = isset( $data->w_image ) ? esc_url_raw( $data->w_image ) : ''; |
| 2662 |
|
| 2663 |
if ( ! empty( $w_image ) ) { |
| 2664 |
$w_image = str_replace( '\\', '', $w_image ); |
| 2665 |
$w_image = wp_remote_get( $w_image )['body']; |
| 2666 |
} |
| 2667 |
|
| 2668 |
$array_data = array( |
| 2669 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2670 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2671 |
'title' => isset( $data->title ) ? sanitize_text_field( $data->title ) : '', |
| 2672 |
'content' => isset( $data->content ) ? sanitize_text_field( $data->content ) : '', |
| 2673 |
'builder' => isset( $data->builder ) ? sanitize_text_field( $data->builder ) : '', |
| 2674 |
'w_data' => isset( $data->w_data ) ? $data->w_data : '', |
| 2675 |
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2676 |
'w_image' => $w_image, |
| 2677 |
'w_imgext' => isset( $data->w_imgext ) ? sanitize_text_field( $data->w_imgext ) : '', |
| 2678 |
'w_version' => isset( $data->w_version ) ? $data->w_version : '', |
| 2679 |
'w_updates' => ! empty( $data->w_updates ) ? serialize( $data->w_updates ) : serialize( array() ), |
| 2680 |
'r_id' => isset( $data->r_id ) ? $data->r_id : 0, |
| 2681 |
); |
| 2682 |
|
| 2683 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2684 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2685 |
|
| 2686 |
if ( empty( $success ) ) { |
| 2687 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2688 |
|
| 2689 |
$result = (object) array( |
| 2690 |
'success' => false, |
| 2691 |
'message' => $massage, |
| 2692 |
'description' => esc_html__( 'Widget Not Added', 'wdesignkit' ), |
| 2693 |
); |
| 2694 |
|
| 2695 |
wp_send_json( $result ); |
| 2696 |
wp_die(); |
| 2697 |
} |
| 2698 |
|
| 2699 |
$res = ! empty( $response['data'] ) ? $response['data'] : array(); |
| 2700 |
|
| 2701 |
$response = json_decode( wp_json_encode( $res ), true ); |
| 2702 |
$img_url = ! empty( $response['data']['imgurl'] ) ? $response['data']['imgurl'] : ''; |
| 2703 |
|
| 2704 |
if ( ! empty( $img_url ) && 'error' !== $res ) { |
| 2705 |
$img_body = wp_remote_get( $img_url ); |
| 2706 |
$img_ext = pathinfo( $img_url )['extension']; |
| 2707 |
include_once ABSPATH . 'wp-admin/includes/file.php'; |
| 2708 |
\WP_Filesystem(); |
| 2709 |
global $wp_filesystem; |
| 2710 |
$folder_name = str_replace( ' ', '-', $title ) . '_' . $w_uniq; |
| 2711 |
$file_name = str_replace( ' ', '_', $title ) . '_' . $w_uniq; |
| 2712 |
$file_path = WDKIT_BUILDER_PATH . "/$builder/$folder_name/$file_name"; |
| 2713 |
|
| 2714 |
$u_r_l = wp_json_file_decode( "$file_path.json" ); |
| 2715 |
$u_r_l->widget_data->widgetdata->w_image = WDKIT_SERVER_PATH . "/$builder/$folder_name/$file_name.$img_ext"; |
| 2716 |
|
| 2717 |
$wp_filesystem->put_contents( "$file_path.json", wp_json_encode( $u_r_l ) ); |
| 2718 |
$wp_filesystem->put_contents( "$file_path.$img_ext", $img_body['body'] ); |
| 2719 |
} |
| 2720 |
|
| 2721 |
wp_send_json( $response ); |
| 2722 |
wp_die(); |
| 2723 |
} |
| 2724 |
|
| 2725 |
/** |
| 2726 |
* |
| 2727 |
* It is Use for manage favourite widget |
| 2728 |
* |
| 2729 |
* @since 1.0.0 |
| 2730 |
*/ |
| 2731 |
protected function wdkit_favourite_widget() { |
| 2732 |
$data = isset( $_POST['widget_info'] ) ? json_decode( stripslashes( sanitize_text_field( wp_unslash( $_POST['widget_info'] ) ) ) ) : ''; |
| 2733 |
$array_data = array( |
| 2734 |
'token' => isset( $data->token ) ? sanitize_text_field( $data->token ) : '', |
| 2735 |
'type' => isset( $data->type ) ? sanitize_text_field( $data->type ) : '', |
| 2736 |
'w_unique' => isset( $data->w_uniq ) ? sanitize_text_field( $data->w_uniq ) : '', |
| 2737 |
); |
| 2738 |
|
| 2739 |
$response = $this->wkit_api_call( $array_data, 'save_widget' ); |
| 2740 |
$success = ! empty( $response['success'] ) ? $response['success'] : false; |
| 2741 |
|
| 2742 |
if ( empty( $success ) ) { |
| 2743 |
$massage = ! empty( $response['massage'] ) ? $response['massage'] : esc_html__( 'server error', 'wdesignkit' ); |
| 2744 |
|
| 2745 |
$result = (object) array( |
| 2746 |
'success' => false, |
| 2747 |
'message' => $massage, |
| 2748 |
'description' => '', |
| 2749 |
); |
| 2750 |
|
| 2751 |
wp_send_json( $result ); |
| 2752 |
wp_die(); |
| 2753 |
} |
| 2754 |
|
| 2755 |
wp_send_json( $response ); |
| 2756 |
wp_die(); |
| 2757 |
} |
| 2758 |
|
| 2759 |
/** |
| 2760 |
* It is Used Setting Panel Defalut Data Get. |
| 2761 |
* |
| 2762 |
* @since 1.0.0 |
| 2763 |
*/ |
| 2764 |
protected function wdkit_setting_panel() { |
| 2765 |
$event = ! empty( $_POST['event'] ) ? sanitize_text_field( wp_unslash( $_POST['event'] ) ) : 'get'; |
| 2766 |
|
| 2767 |
if ( 'get' === $event ) { |
| 2768 |
return self::wkit_get_settings_panel(); |
| 2769 |
} elseif ( 'set' === $event ) { |
| 2770 |
$data = ! empty( $_POST['data'] ) ? stripslashes( sanitize_text_field( wp_unslash( $_POST['data'] ) ) ) : array(); |
| 2771 |
|
| 2772 |
$data = json_decode( $data, true ); |
| 2773 |
|
| 2774 |
update_option( 'wkit_settings_panel', $data ); |
| 2775 |
return self::wkit_get_settings_panel(); |
| 2776 |
} else { |
| 2777 |
return false; |
| 2778 |
} |
| 2779 |
} |
| 2780 |
|
| 2781 |
/** |
| 2782 |
* Get Setting Panal Data |
| 2783 |
* |
| 2784 |
* @since 1.0.0 |
| 2785 |
*/ |
| 2786 |
protected static function wkit_get_settings_panel() { |
| 2787 |
$get_setting = get_option( 'wkit_settings_panel', false ); |
| 2788 |
|
| 2789 |
return array( |
| 2790 |
'builder' => isset( $get_setting['builder'] ) ? $get_setting['builder'] : true, |
| 2791 |
'template' => isset( $get_setting['template'] ) ? $get_setting['template'] : true, |
| 2792 |
'gutenberg_builder' => isset( $get_setting['gutenberg_builder'] ) ? $get_setting['gutenberg_builder'] : true, |
| 2793 |
'elementor_builder' => isset( $get_setting['elementor_builder'] ) ? $get_setting['elementor_builder'] : true, |
| 2794 |
'bricks_builder' => isset( $get_setting['bricks_builder'] ) ? $get_setting['bricks_builder'] : false, |
| 2795 |
'debugger_mode' => isset( $get_setting['debugger_mode'] ) ? $get_setting['debugger_mode'] : false, |
| 2796 |
'gutenberg_template' => isset( $get_setting['gutenberg_template'] ) ? $get_setting['gutenberg_template'] : true, |
| 2797 |
'elementor_template' => isset( $get_setting['elementor_template'] ) ? $get_setting['elementor_template'] : true, |
| 2798 |
); |
| 2799 |
} |
| 2800 |
|
| 2801 |
/** |
| 2802 |
* |
| 2803 |
* Use for Add new licence key. |
| 2804 |
* |
| 2805 |
* @since 1.0.0 |
| 2806 |
*/ |
| 2807 |
protected function wdkit_activate_licence() { |
| 2808 |
$args = array( |
| 2809 |
'token' => ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : '', |
| 2810 |
'licencekey' => ! empty( $_POST['licencekey'] ) ? sanitize_text_field( wp_unslash( $_POST['licencekey'] ) ) : '', |
| 2811 |
'licencename' => ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : '', |
| 2812 |
); |
| 2813 |
|
| 2814 |
$response = $this->wkit_api_call( $args, 'wkit_activate_key' ); |
| 2815 |
|
| 2816 |
wp_send_json( $response['data'] ); |
| 2817 |
wp_die(); |
| 2818 |
} |
| 2819 |
|
| 2820 |
/** |
| 2821 |
* |
| 2822 |
* Use for Delete licence key. |
| 2823 |
* |
| 2824 |
* @since 1.0.0 |
| 2825 |
*/ |
| 2826 |
protected function wdkit_delete_licence_key() { |
| 2827 |
$token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; |
| 2828 |
$licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : ''; |
| 2829 |
|
| 2830 |
$args = array( |
| 2831 |
'token' => $token, |
| 2832 |
'licencename' => $licencename, |
| 2833 |
); |
| 2834 |
|
| 2835 |
$response = $this->wkit_api_call( $args, 'licence_delete' ); |
| 2836 |
|
| 2837 |
wp_send_json( $response['data'] ); |
| 2838 |
wp_die(); |
| 2839 |
} |
| 2840 |
|
| 2841 |
/** |
| 2842 |
* |
| 2843 |
* Use for Sync licence key. |
| 2844 |
* |
| 2845 |
* @since 1.0.0 |
| 2846 |
*/ |
| 2847 |
protected function wdkit_sync_licence_key() { |
| 2848 |
$token = ! empty( $_POST['token'] ) ? sanitize_text_field( wp_unslash( $_POST['token'] ) ) : ''; |
| 2849 |
$licencename = ! empty( $_POST['licencename'] ) ? sanitize_text_field( wp_unslash( $_POST['licencename'] ) ) : ''; |
| 2850 |
|
| 2851 |
$args = array( |
| 2852 |
'token' => $token, |
| 2853 |
'licencename' => $licencename, |
| 2854 |
); |
| 2855 |
|
| 2856 |
$response = $this->wkit_api_call( $args, 'licence_sync' ); |
| 2857 |
|
| 2858 |
wp_send_json( $response['data'] ); |
| 2859 |
wp_die(); |
| 2860 |
} |
| 2861 |
|
| 2862 |
/** |
| 2863 |
* |
| 2864 |
* It is Use for logout. |
| 2865 |
* |
| 2866 |
* @since 1.0.0 |
| 2867 |
*/ |
| 2868 |
protected function wdkit_logout() { |
| 2869 |
$email = isset( $_POST['email'] ) ? strtolower( sanitize_email( wp_unslash( $_POST['email'] ) ) ) : false; |
| 2870 |
$response = ''; |
| 2871 |
|
| 2872 |
if ( ! empty( $email ) ) { |
| 2873 |
$token = $this->wdkit_login_user_token( $email ); |
| 2874 |
$args = array( 'token' => $token ); |
| 2875 |
|
| 2876 |
delete_transient( 'wdkit_auth_' . $email ); |
| 2877 |
$response = WDesignKit_Data_Query::get_data( 'logout', $args ); |
| 2878 |
} |
| 2879 |
|
| 2880 |
wp_send_json( $response ); |
| 2881 |
wp_die(); |
| 2882 |
} |
| 2883 |
|
| 2884 |
/** |
| 2885 |
* |
| 2886 |
* It is Use for get token of login user. |
| 2887 |
* |
| 2888 |
* @since 1.0.0 |
| 2889 |
* |
| 2890 |
* @param string $email check user email. |
| 2891 |
*/ |
| 2892 |
protected function wdkit_login_user_token( $email = '' ) { |
| 2893 |
|
| 2894 |
if ( ! empty( $email ) ) { |
| 2895 |
$user_key = strstr( $email, '@', true ); |
| 2896 |
$get_login = get_transient( 'wdkit_auth_' . $user_key ); |
| 2897 |
|
| 2898 |
if ( ! empty( $get_login ) && ! empty( $get_login['token'] ) ) { |
| 2899 |
return $get_login['token']; |
| 2900 |
} |
| 2901 |
} |
| 2902 |
|
| 2903 |
return false; |
| 2904 |
} |
| 2905 |
|
| 2906 |
/** |
| 2907 |
* Parse args $_POST |
| 2908 |
* |
| 2909 |
* @since 1.0.0 |
| 2910 |
* |
| 2911 |
* @param string $data send all post data. |
| 2912 |
* @param string $type store text data. |
| 2913 |
* @param string $condition store text data. |
| 2914 |
*/ |
| 2915 |
protected function wdkit_sanitizer_bypass( $data, $type, $condition = 'none' ) { |
| 2916 |
|
| 2917 |
if ( 'none' === $condition ) { |
| 2918 |
return $data[ $type ]; |
| 2919 |
} elseif ( 'cr_widget' === $condition ) { |
| 2920 |
return $data[ $type ]; |
| 2921 |
} |
| 2922 |
} |
| 2923 |
|
| 2924 |
/** |
| 2925 |
* Parse args $_POST |
| 2926 |
* |
| 2927 |
* @since 1.0.0 |
| 2928 |
* |
| 2929 |
* @param string $data send all post data. |
| 2930 |
* @param string $type store text data. |
| 2931 |
* @param string $condition store text data. |
| 2932 |
*/ |
| 2933 |
protected function wdkit_file_sanitizer_bypass( $data, $type, $condition = 'none' ) { |
| 2934 |
|
| 2935 |
if ( 'name' === $condition ) { |
| 2936 |
return wp_normalize_path( $data[ $type ]['tmp_name'] ); |
| 2937 |
} |
| 2938 |
} |
| 2939 |
|
| 2940 |
/** |
| 2941 |
* Parse args $_POST |
| 2942 |
* |
| 2943 |
* @since 1.0.0 |
| 2944 |
* |
| 2945 |
* @param string $data send all post data. |
| 2946 |
*/ |
| 2947 |
protected function wdkit_parse_args( $data = array() ) { |
| 2948 |
if ( empty( $data ) ) { |
| 2949 |
return array(); |
| 2950 |
} |
| 2951 |
|
| 2952 |
$args = array(); |
| 2953 |
if ( isset( $data['email'] ) ) { |
| 2954 |
$args['email'] = isset( $data['email'] ) ? sanitize_email( $data['email'] ) : ''; |
| 2955 |
} |
| 2956 |
|
| 2957 |
if ( isset( $data['data'] ) ) { |
| 2958 |
$args['data'] = isset( $data['data'] ) ? wp_unslash( $data['data'] ) : array(); |
| 2959 |
} |
| 2960 |
|
| 2961 |
if ( isset( $data['plugins'] ) ) { |
| 2962 |
$args['plugins'] = isset( $data['plugins'] ) ? wp_unslash( $data['plugins'] ) : array(); |
| 2963 |
} |
| 2964 |
|
| 2965 |
if ( isset( $data['template_id'] ) ) { |
| 2966 |
$args['template_id'] = isset( $data['template_id'] ) ? intval( strtolower( sanitize_text_field( $data['template_id'] ) ) ) : ''; |
| 2967 |
} |
| 2968 |
|
| 2969 |
if ( isset( $data['builder'] ) ) { |
| 2970 |
$args['builder'] = isset( $data['builder'] ) ? sanitize_text_field( $data['builder'] ) : ''; |
| 2971 |
} |
| 2972 |
|
| 2973 |
if ( isset( $data['editor'] ) ) { |
| 2974 |
$args['editor'] = isset( $data['editor'] ) ? sanitize_text_field( $data['editor'] ) : ''; |
| 2975 |
} |
| 2976 |
|
| 2977 |
if ( isset( $data['type_upload'] ) ) { |
| 2978 |
$args['type_upload'] = isset( $data['type_upload'] ) ? sanitize_text_field( $data['type_upload'] ) : ''; |
| 2979 |
} |
| 2980 |
|
| 2981 |
if ( isset( $data['title'] ) ) { |
| 2982 |
$args['title'] = isset( $data['title'] ) ? wp_strip_all_tags( $data['title'] ) : ''; |
| 2983 |
} |
| 2984 |
|
| 2985 |
if ( isset( $data['template_type'] ) ) { |
| 2986 |
$args['template_type'] = isset( $data['template_type'] ) ? sanitize_text_field( $data['template_type'] ) : ''; |
| 2987 |
} |
| 2988 |
|
| 2989 |
if ( isset( $data['wstype'] ) ) { |
| 2990 |
$args['wstype'] = isset( $data['wstype'] ) ? wp_strip_all_tags( $data['wstype'] ) : ''; |
| 2991 |
} |
| 2992 |
|
| 2993 |
if ( isset( $data['wid'] ) ) { |
| 2994 |
$args['wid'] = isset( $data['wid'] ) ? intval( strtolower( sanitize_text_field( $data['wid'] ) ) ) : ''; |
| 2995 |
} |
| 2996 |
|
| 2997 |
if ( isset( $data['perpage'] ) ) { |
| 2998 |
$args['perpage'] = isset( $data['perpage'] ) ? intval( strtolower( sanitize_text_field( $data['perpage'] ) ) ) : 12; |
| 2999 |
} |
| 3000 |
|
| 3001 |
if ( isset( $data['page'] ) ) { |
| 3002 |
$args['page'] = isset( $data['page'] ) ? intval( strtolower( sanitize_text_field( $data['page'] ) ) ) : 1; |
| 3003 |
} |
| 3004 |
|
| 3005 |
if ( isset( $data['buildertype'] ) ) { |
| 3006 |
$args['buildertype'] = isset( $data['buildertype'] ) ? sanitize_text_field( $data['buildertype'] ) : ''; |
| 3007 |
} |
| 3008 |
|
| 3009 |
if ( isset( $data['search'] ) ) { |
| 3010 |
$args['search'] = isset( $data['search'] ) ? sanitize_text_field( $data['search'] ) : ''; |
| 3011 |
} |
| 3012 |
|
| 3013 |
if ( isset( $data['plugin'] ) ) { |
| 3014 |
$args['plugin'] = isset( $data['plugin'] ) ? wp_unslash( $data['plugin'] ) : array(); |
| 3015 |
} |
| 3016 |
|
| 3017 |
if ( isset( $data['tag'] ) ) { |
| 3018 |
$args['tag'] = isset( $data['tag'] ) ? wp_unslash( $data['tag'] ) : array(); |
| 3019 |
} |
| 3020 |
|
| 3021 |
if ( isset( $data['category'] ) ) { |
| 3022 |
$args['category'] = isset( $data['category'] ) ? wp_unslash( $data['category'] ) : array(); |
| 3023 |
} |
| 3024 |
|
| 3025 |
if ( isset( $data['free_pro'] ) ) { |
| 3026 |
$args['free_pro'] = isset( $data['free_pro'] ) ? sanitize_text_field( wp_unslash( $data['free_pro'] ) ) : ''; |
| 3027 |
} |
| 3028 |
|
| 3029 |
if ( isset( $data['wp_post_type'] ) ) { |
| 3030 |
$args['wp_post_type'] = isset( $data['wp_post_type'] ) ? sanitize_text_field( wp_unslash( $data['wp_post_type'] ) ) : ''; |
| 3031 |
} |
| 3032 |
|
| 3033 |
if ( isset( $data['favorite'] ) ) { |
| 3034 |
$args['favorite'] = isset( $data['favorite'] ) ? sanitize_text_field( wp_unslash( $data['favorite'] ) ) : ''; |
| 3035 |
} |
| 3036 |
|
| 3037 |
if ( isset( $data['content'] ) ) { |
| 3038 |
$args['content'] = isset( $data['content'] ) ? wp_unslash( $data['content'] ) : ''; |
| 3039 |
} |
| 3040 |
|
| 3041 |
if ( isset( $data['page_type'] ) ) { |
| 3042 |
$args['page_type'] = isset( $data['page_type'] ) ? wp_unslash( $data['page_type'] ) : array(); |
| 3043 |
} |
| 3044 |
|
| 3045 |
return $args; |
| 3046 |
} |
| 3047 |
} |
| 3048 |
|
| 3049 |
Wdkit_Api_Call::get_instance(); |
| 3050 |
} |
| 3051 |
|