| @@ -6,8 +6,9 @@ | ||
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | namespace RadiusTheme\SB\Controllers; |
| 9 | 9 | |
| 10 | +use Elementor\Plugin; | |
| 10 | 11 | use RadiusTheme\SB\Helpers\Fns; |
| 11 | 12 | use RadiusTheme\SB\Helpers\BuilderFns; |
| 12 | 13 | use RadiusTheme\SB\Traits\SingletonTrait; |
| 13 | 14 | use RadiusTheme\SB\Controllers\Builder\BuilderCpt; |
| @@ -25,13 +26,8 @@ | ||
| 25 | 26 | * Builder Controller |
| 26 | 27 | */ |
| 27 | 28 | class BuilderController { |
| 28 | 29 | /** |
| 29 | - * @var array | |
| 30 | - */ | |
| 31 | - private static $cache = []; | |
| 32 | - | |
| 33 | - /** | |
| 34 | 30 | * Builder page id. |
| 35 | 31 | * |
| 36 | 32 | * @var integer |
| 37 | 33 | */ |
| @@ -61,21 +57,18 @@ | ||
| 61 | 57 | } |
| 62 | 58 | |
| 63 | 59 | BuilderCpt::instance(); |
| 64 | 60 | |
| 65 | - $this->elementor_init(); | |
| 66 | - $this->both_builder_frontend(); | |
| 67 | - | |
| 68 | - // add_action( 'elementor/init', [ $this, 'elementor_init' ] ); | |
| 61 | + add_action( 'elementor/init', [ $this, 'elementor_init' ] ); | |
| 69 | 62 | add_action( 'elementor/editor/before_enqueue_scripts', [ $this, 'editor_scripts' ] ); |
| 70 | - // add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 ); | |
| 63 | + add_action( 'template_redirect', [ $this, 'both_builder_frontend' ], 99 ); | |
| 71 | 64 | |
| 72 | 65 | // RT Select2 Ajax. |
| 73 | - add_action( 'wp_ajax_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 74 | - add_action( 'wp_ajax_nopriv_rtsb_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 66 | + add_action( 'wp_ajax_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 67 | + add_action( 'wp_ajax_nopriv_rt_select2_object_search', [ $this, 'select2_ajax_posts_filter_autocomplete' ] ); | |
| 75 | 68 | // Select2 ajax save data. |
| 76 | - add_action( 'wp_ajax_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 77 | - add_action( 'wp_ajax_nopriv_rtsb_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 69 | + add_action( 'wp_ajax_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 70 | + add_action( 'wp_ajax_nopriv_rt_select2_get_title', [ $this, 'select2_ajax_get_posts_value_titles' ] ); | |
| 78 | 71 | } |
| 79 | 72 | |
| 80 | 73 | /** |
| 81 | 74 | * Apply for frontend. |
| @@ -107,29 +100,21 @@ | ||
| 107 | 100 | * |
| 108 | 101 | * @return void |
| 109 | 102 | */ |
| 110 | 103 | public function add_elementor_widget_categories( $elements_manager ) { |
| 111 | - $categories = []; | |
| 112 | - $builder_id = get_queried_object_id(); | |
| 113 | - $id = Fns::wpml_object_id( $builder_id, BuilderFns::$post_type_tb, 'default' ); | |
| 114 | - $type = BuilderFns::builder_type( $id ); | |
| 104 | + $type = BuilderFns::builder_type( get_the_ID() ); | |
| 105 | + $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; | |
| 106 | + $builder_type = str_replace( 'My Account - ', '', $builder_type ); | |
| 107 | + $categories['rtsb-shopbuilder'] = [ | |
| 108 | + 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), | |
| 109 | + 'icon' => 'fa fa-plug', | |
| 110 | + ]; | |
| 111 | + $categories['rtsb-shopbuilder-general'] = [ | |
| 112 | + 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ), | |
| 113 | + 'icon' => 'fa fa-plug', | |
| 114 | + ]; | |
| 115 | 115 | |
| 116 | - if ( $type ) { | |
| 117 | - $builder_type = ! empty( BuilderFns::builder_page_types()[ $type ] ) ? BuilderFns::builder_page_types()[ $type ] : ''; | |
| 118 | - $builder_type = str_replace( [ 'My Account - ', 'Endpoint: ' ], '', $builder_type ); | |
| 119 | - $categories['rtsb-shopbuilder'] = [ | |
| 120 | - 'title' => esc_html__( 'ShopBuilder', 'shopbuilder' ) . ' - ' . ucfirst( $builder_type ), | |
| 121 | - 'icon' => 'fa fa-plug', | |
| 122 | - ]; | |
| 123 | - } | |
| 124 | - if ( 'quick-view' !== $type ) { | |
| 125 | - $categories['rtsb-shopbuilder-general'] = [ | |
| 126 | - 'title' => esc_html__( 'Shopbuilder - General', 'shopbuilder' ), | |
| 127 | - 'icon' => 'fa fa-plug', | |
| 128 | - ]; | |
| 129 | - } | |
| 130 | - $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); | |
| 131 | - | |
| 116 | + $categories = apply_filters( 'rtsb_elementor_widgets_category_lists', $categories ); | |
| 132 | 117 | $other_categories = $elements_manager->get_categories(); |
| 133 | 118 | $categories = array_merge( |
| 134 | 119 | array_slice( $other_categories, 0, 1 ), |
| 135 | 120 | $categories, |
| @@ -135,10 +120,10 @@ | ||
| 135 | 120 | $categories, |
| 136 | 121 | array_slice( $other_categories, 1 ) |
| 137 | 122 | ); |
| 138 | 123 | |
| 139 | - $set_categories = function ( $categories ) use ( $elements_manager ) { | |
| 140 | - $elements_manager->categories = $categories; | |
| 124 | + $set_categories = function ( $categories ) { | |
| 125 | + $this->categories = $categories; | |
| 141 | 126 | }; |
| 142 | 127 | |
| 143 | 128 | $set_categories->call( $elements_manager, $categories ); |
| 144 | 129 | } |
| @@ -164,11 +149,16 @@ | ||
| 164 | 149 | * |
| 165 | 150 | * @since 1.0.0 |
| 166 | 151 | */ |
| 167 | 152 | public function init_widgets( $widgets_manager ) { |
| 153 | + $product = Fns::get_product(); | |
| 168 | 154 | |
| 169 | - $get_list = ElementList::instance()->get_list( true, 'active' ); | |
| 170 | - foreach ( $get_list as $element ) { | |
| 155 | + // TODO: Need to remove below condition and make compitability in each widgets. | |
| 156 | + if ( ! $product ) { | |
| 157 | + return; | |
| 158 | + } | |
| 159 | + | |
| 160 | + foreach ( ElementList::instance()->get_list( true, 'active' ) as $element ) { | |
| 171 | 161 | if ( isset( $element['active'] ) && 'on' !== $element['active'] ) { |
| 172 | 162 | continue; |
| 173 | 163 | } |
| 174 | 164 | |
| @@ -230,10 +220,23 @@ | ||
| 230 | 220 | * |
| 231 | 221 | * @return array |
| 232 | 222 | */ |
| 233 | 223 | public function rtsb_icons( $tabs = [] ) { |
| 234 | - $custom_icons = Fns::get_custom_icon_names(); | |
| 224 | + $fonts = rtsb()->get_assets_uri( 'fonts/rtsb-icons.json' ); | |
| 235 | 225 | |
| 226 | + $response = wp_remote_get( $fonts ); | |
| 227 | + | |
| 228 | + if ( is_wp_error( $response ) ) { | |
| 229 | + return $tabs; | |
| 230 | + } | |
| 231 | + | |
| 232 | + $icons_json = wp_remote_retrieve_body( $response ); | |
| 233 | + $custom_icons = json_decode( $icons_json, true ); | |
| 234 | + | |
| 235 | + if ( null === $custom_icons ) { | |
| 236 | + return $tabs; | |
| 237 | + } | |
| 238 | + | |
| 236 | 239 | $tabs['shopbuilder-icons'] = [ |
| 237 | 240 | 'name' => 'rtsb-fonts', |
| 238 | 241 | 'label' => esc_html__( 'ShopBuilder Icons', 'shopbuilder' ), |
| 239 | 242 | 'labelIcon' => 'fab fa-elementor', |
| @@ -297,18 +300,8 @@ | ||
| 297 | 300 | |
| 298 | 301 | if ( BuilderFns::is_product() ) { |
| 299 | 302 | $product_id = Fns::get_prepared_product_id(); |
| 300 | 303 | $parent_class = wc_get_product_class( $parent_class, $product_id ); |
| 301 | - if ( function_exists( 'rtwpvs' ) ) { | |
| 302 | - $_product = Fns::get_product(); | |
| 303 | - if ( $_product->is_type( 'variable' ) ) { | |
| 304 | - $parent_class[] = 'rtwpvs-product'; | |
| 305 | - $beside_label = function_exists( 'rtwpvsp' ) && rtwpvs()->get_option( 'attribute_on_click_behavior' ); | |
| 306 | - if ( $beside_label ) { | |
| 307 | - $parent_class[] = 'rtwpvs-selected-term-beside-label'; | |
| 308 | - } | |
| 309 | - } | |
| 310 | - } | |
| 311 | 304 | } |
| 312 | 305 | |
| 313 | 306 | if ( BuilderFns::is_shop() ) { |
| 314 | 307 | $parent_class[] = 'shop'; |
| @@ -324,14 +317,9 @@ | ||
| 324 | 317 | |
| 325 | 318 | ?> |
| 326 | 319 | <!-- Before Content start --> |
| 327 | 320 | <div class="<?php echo esc_attr( implode( ' ', $parent_class ) ); ?>"> |
| 328 | - <?php | |
| 329 | - if ( BuilderFns::is_checkout() ) { | |
| 330 | - if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { | |
| 331 | - return; | |
| 332 | - } | |
| 333 | - ?> | |
| 321 | + <?php if ( BuilderFns::is_checkout() ) { ?> | |
| 334 | 322 | <form name="checkout" method="post" class="rtsb-woocommerce-checkout checkout" action="<?php echo esc_url( wc_get_checkout_url() ); ?>" enctype="multipart/form-data"> |
| 335 | 323 | <?php |
| 336 | 324 | } |
| 337 | 325 | } |
| @@ -353,11 +341,8 @@ | ||
| 353 | 341 | do_action( 'elementor/page_templates/header-footer/after_content' ); |
| 354 | 342 | } |
| 355 | 343 | |
| 356 | 344 | if ( BuilderFns::is_checkout() ) { |
| 357 | - if ( ! apply_filters( 'rtsb/multi/step/checkout/widget', true ) ) { | |
| 358 | - return; | |
| 359 | - } | |
| 360 | 345 | ?> |
| 361 | 346 | </form> |
| 362 | 347 | <?php |
| 363 | 348 | } |
| @@ -372,26 +357,22 @@ | ||
| 372 | 357 | * |
| 373 | 358 | * @return void |
| 374 | 359 | */ |
| 375 | 360 | public function select2_ajax_posts_filter_autocomplete() { |
| 376 | - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 377 | - wp_send_json_error( [] ); | |
| 378 | - } | |
| 361 | + | |
| 379 | 362 | $query_per_page = 15; |
| 380 | 363 | $post_type = 'post'; |
| 381 | 364 | $source_name = 'post_type'; |
| 382 | - $paged = absint( $_POST['page'] ?? 1 ); | |
| 365 | + $paged = $_POST['page'] ?? 1; | |
| 366 | + | |
| 383 | 367 | if ( ! empty( $_POST['post_type'] ) ) { |
| 384 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 385 | 368 | $post_type = sanitize_text_field( $_POST['post_type'] ); |
| 386 | 369 | } |
| 387 | 370 | |
| 388 | 371 | if ( ! empty( $_POST['source_name'] ) ) { |
| 389 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 390 | 372 | $source_name = sanitize_text_field( $_POST['source_name'] ); |
| 391 | 373 | } |
| 392 | 374 | |
| 393 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 394 | 375 | $search = ! empty( $_POST['search'] ) ? sanitize_text_field( $_POST['search'] ) : ''; |
| 395 | 376 | $results = $post_list = []; |
| 396 | 377 | switch ( $source_name ) { |
| 397 | 378 | case 'taxonomy': |
| @@ -451,22 +432,17 @@ | ||
| 451 | 432 | * @return void |
| 452 | 433 | */ |
| 453 | 434 | public function select2_ajax_get_posts_value_titles() { |
| 454 | 435 | |
| 455 | - if ( ! wp_verify_nonce( Fns::get_nonce(), rtsb()->nonceText ) ) { | |
| 456 | - wp_send_json_error( [] ); | |
| 457 | - } | |
| 458 | - | |
| 459 | 436 | if ( empty( $_POST['id'] ) ) { |
| 460 | 437 | wp_send_json_error( [] ); |
| 461 | 438 | } |
| 462 | 439 | |
| 463 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized | |
| 464 | 440 | if ( empty( array_filter( $_POST['id'] ) ) ) { |
| 465 | 441 | wp_send_json_error( [] ); |
| 466 | 442 | } |
| 467 | 443 | $ids = array_map( 'intval', $_POST['id'] ); |
| 468 | - $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 444 | + $source_name = ! empty( $_POST['source_name'] ) ? sanitize_text_field( $_POST['source_name'] ) : ''; | |
| 469 | 445 | |
| 470 | 446 | switch ( $source_name ) { |
| 471 | 447 | case 'taxonomy': |
| 472 | 448 | $args = [ |
| @@ -475,11 +451,9 @@ | ||
| 475 | 451 | 'order' => 'ASC', |
| 476 | 452 | 'include' => implode( ',', $ids ), |
| 477 | 453 | ]; |
| 478 | 454 | |
| 479 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 480 | 455 | if ( $_POST['post_type'] !== 'all' ) { |
| 481 | - // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotValidated, WordPress.Security.ValidatedSanitizedInput.MissingUnslash | |
| 482 | 456 | $args['taxonomy'] = sanitize_text_field( $_POST['post_type'] ); |
| 483 | 457 | } |
| 484 | 458 | |
| 485 | 459 | $response = wp_list_pluck( get_terms( $args ), 'name', 'term_id' ); |
| @@ -497,9 +471,9 @@ | ||
| 497 | 471 | break; |
| 498 | 472 | default: |
| 499 | 473 | $post_info = get_posts( |
| 500 | 474 | [ |
| 501 | - 'post_type' => sanitize_text_field( $_POST['post_type'] ), // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.MissingUnslash, WordPress.Security.ValidatedSanitizedInput.InputNotValidated | |
| 475 | + 'post_type' => sanitize_text_field( $_POST['post_type'] ), | |
| 502 | 476 | 'include' => implode( ',', $ids ), |
| 503 | 477 | ] |
| 504 | 478 | ); |
| 505 | 479 | $response = wp_list_pluck( $post_info, 'post_title', 'ID' ); |
| @@ -558,9 +532,9 @@ | ||
| 558 | 532 | $where .= $wpdb->prepare( " AND {$wpdb->posts}.post_title LIKE %s", '%' . esc_sql( $search ) . '%' ); |
| 559 | 533 | } |
| 560 | 534 | |
| 561 | 535 | $query = "select post_title,ID from $wpdb->posts where post_status = 'publish' {$where} {$limit}"; |
| 562 | - $results = $wpdb->get_results( $query ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.NoCaching | |
| 536 | + $results = $wpdb->get_results( $query ); | |
| 563 | 537 | |
| 564 | 538 | if ( ! empty( $results ) ) { |
| 565 | 539 | foreach ( $results as $row ) { |
| 566 | 540 | $data[ $row->ID ] = $row->post_title . ' [#' . $row->ID . ']'; |
| @@ -591,10 +565,10 @@ | ||
| 591 | 565 | |
| 592 | 566 | $pro_widgets = [ |
| 593 | 567 | [ |
| 594 | 568 | 'name' => 'rtsb-ajax-product-filters', |
| 595 | - 'title' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ), | |
| 596 | - 'description' => esc_html__( 'Ajax Product Filters', 'shopbuilder' ), | |
| 569 | + 'title' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ), | |
| 570 | + 'description' => esc_html__( 'Ajax Product Filters', 'testimonial-slider-showcase' ), | |
| 597 | 571 | 'icon' => 'rtsb-el-custom rtsb-element icon-rtsb-ajax-product-filters rtsb-promotional-element', |
| 598 | 572 | 'categories' => '[ "rtsb-shopbuilder" ]', |
| 599 | 573 | ], |
| 600 | 574 | ]; |
| @@ -605,49 +579,6 @@ | ||
| 605 | 579 | } |
| 606 | 580 | } |
| 607 | 581 | |
| 608 | 582 | return $config; |
| 609 | - } | |
| 610 | - | |
| 611 | - /** | |
| 612 | - * Get Icons. | |
| 613 | - * | |
| 614 | - * @return array | |
| 615 | - */ | |
| 616 | - public function get_icons() { | |
| 617 | - return [ | |
| 618 | - 'heart-empty', | |
| 619 | - 'heart', | |
| 620 | - 'eye', | |
| 621 | - 'exchange', | |
| 622 | - 'plus', | |
| 623 | - 'minus', | |
| 624 | - 'avatar', | |
| 625 | - 'pay', | |
| 626 | - 'share', | |
| 627 | - 'clock', | |
| 628 | - 'check-alt', | |
| 629 | - 'check', | |
| 630 | - 'delete', | |
| 631 | - 'marker', | |
| 632 | - 'list', | |
| 633 | - 'list-2', | |
| 634 | - 'power', | |
| 635 | - 'cart', | |
| 636 | - 'cart-2', | |
| 637 | - 'cart-3', | |
| 638 | - 'downloads', | |
| 639 | - 'zoom', | |
| 640 | - 'user-edit', | |
| 641 | - 'grid', | |
| 642 | - 'filter', | |
| 643 | - 'billing', | |
| 644 | - 'login', | |
| 645 | - 'payment', | |
| 646 | - 'search', | |
| 647 | - 'edit', | |
| 648 | - 'coupon', | |
| 649 | - 'arrows-cw', | |
| 650 | - 'trash-empty', | |
| 651 | - ]; | |
| 652 | 583 | } |
| 653 | 584 | } |