assets
3 weeks ago
ajax-select2-api.php
3 weeks ago
ajax-select2.php
2 years ago
control-manager.php
4 years ago
image-choose.php
2 years ago
init.php
4 years ago
widget-area-modal.php
3 years ago
widget-area-utils.php
6 months ago
widget-area.php
2 years ago
widget-area-utils.php
122 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Modules\Controls; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | class Widget_Area_Utils { |
| 7 | |
| 8 | function init() { |
| 9 | add_action( 'elementor/editor/after_enqueue_styles', array( $this, 'modal_content' ) ); |
| 10 | |
| 11 | add_action( 'wp_ajax_ekit_widgetarea_content', array( $this, 'ekit_widgetarea_content' ) ); |
| 12 | add_action( 'wp_ajax_nopriv_ekit_widgetarea_content', array( $this, 'ekit_widgetarea_content' ) ); |
| 13 | } |
| 14 | |
| 15 | public function ekit_widgetarea_content() { |
| 16 | |
| 17 | if ( !isset($_POST['nonce']) || !wp_verify_nonce( sanitize_key( wp_unslash( $_POST['nonce'] ) ), 'ekit_pro' ) ) { |
| 18 | wp_die(); |
| 19 | } |
| 20 | |
| 21 | $post_id = isset($_POST['post_id']) ? intval( $_POST['post_id'] ) : 0; |
| 22 | |
| 23 | if ( 'publish' !== get_post_status( $post_id ) ) { |
| 24 | wp_die(); |
| 25 | } |
| 26 | |
| 27 | if ( isset( $post_id ) ) { |
| 28 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Displaying with Elementor content rendering |
| 29 | echo str_replace( '#elementor', '', \ElementsKit_Lite\Utils::render_tab_content( \ElementsKit_Lite\Utils::render_elementor_content( $post_id ), $post_id ) ); |
| 30 | } else { |
| 31 | echo esc_html__( 'Click on the Edit Content button to edit/add the content.', 'elementskit-lite' ); |
| 32 | } |
| 33 | |
| 34 | wp_die(); |
| 35 | } |
| 36 | |
| 37 | public function modal_content() { |
| 38 | ob_start(); ?> |
| 39 | <div class="widgetarea_iframe_modal"> |
| 40 | <?php include 'widget-area-modal.php'; ?> |
| 41 | </div> |
| 42 | <?php |
| 43 | $output = ob_get_contents(); |
| 44 | ob_end_clean(); |
| 45 | |
| 46 | echo \ElementsKit_Lite\Utils::render( $output ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Already escaped inside of the buffering content |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * $index for old version & data support |
| 51 | */ |
| 52 | public static function parse( $content, $widget_key, $tab_id = 1, $isAjax = '', $index = null ) { |
| 53 | $key = ( $content == '' ) ? $widget_key : $content; |
| 54 | $extract_key = explode( '***', $key ); |
| 55 | $extract_key = $extract_key[0]; |
| 56 | ob_start(); |
| 57 | ?> |
| 58 | |
| 59 | <div class="widgetarea_warper widgetarea_warper_editable" data-elementskit-widgetarea-key="<?php echo esc_attr( $extract_key ); ?>" data-elementskit-widgetarea-index="<?php echo esc_attr( $tab_id ); ?>"> |
| 60 | |
| 61 | <?php if ( \Elementor\Plugin::$instance->editor->is_edit_mode() ) : ?> |
| 62 | <div class="widgetarea_warper_edit" data-elementskit-widgetarea-key="<?php echo esc_attr( $extract_key ); ?>" data-elementskit-widgetarea-index="<?php echo esc_attr( $tab_id ); ?>"> |
| 63 | <i class="eicon-edit" aria-hidden="true"></i> |
| 64 | <span><?php esc_html_e( 'Edit Content', 'elementskit-lite' ); ?></span> |
| 65 | </div> |
| 66 | <?php endif; ?> |
| 67 | |
| 68 | <?php |
| 69 | $builder_post_title = 'dynamic-content-widget-' . $extract_key . '-' . $tab_id; |
| 70 | $builder_post = \ElementsKit_Lite\Utils::get_page_by_title( $builder_post_title, 'elementskit_content' ); |
| 71 | |
| 72 | /** |
| 73 | * this checking for already existing content of tab. |
| 74 | */ |
| 75 | $post_id = isset( $builder_post->ID ) ? $builder_post->ID : null; |
| 76 | if ( ! $post_id ) { |
| 77 | $builder_post_title = 'dynamic-content-widget-' . $extract_key . '-' . $index; |
| 78 | $builder_post = \ElementsKit_Lite\Utils::get_page_by_title( $builder_post_title, 'elementskit_content' ); |
| 79 | } |
| 80 | |
| 81 | if ( $isAjax === 'yes' ) { |
| 82 | $post_id = isset( $builder_post->ID ) ? $builder_post->ID : ''; |
| 83 | echo '<div class="ekit-widget-area-container" data-ajax-post-id="' . esc_attr($post_id). '"></div>'; |
| 84 | } else { |
| 85 | ?> |
| 86 | <div class="ekit-widget-area-container"> |
| 87 | <?php |
| 88 | if ( isset( $builder_post->ID ) ) { |
| 89 | $builder_post_id = $builder_post->ID; |
| 90 | |
| 91 | // if wpml is active, get the post id from wpml |
| 92 | if( defined( 'ICL_SITEPRESS_VERSION' ) ) { |
| 93 | $language_details = apply_filters( 'wpml_post_language_details', NULL, get_the_ID() ); |
| 94 | if( !is_wp_error($language_details) ) { |
| 95 | $builder_post_id = apply_filters( 'wpml_object_id', $builder_post_id, 'elementskit_content', true, $language_details['language_code'] ); |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | $builder_content = \ElementsKit_Lite\Utils::render_elementor_content($builder_post_id); |
| 100 | $rendered_tab_content = \ElementsKit_Lite\Utils::render_tab_content($builder_content, $builder_post_id); |
| 101 | // Remove '#elementor' from the rendered content, except when it's part of 'href="#elementor"' |
| 102 | $final_content = preg_replace('/(?<!href=")#elementor/', '', $rendered_tab_content); |
| 103 | |
| 104 | // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Displaying with Elementor content rendering |
| 105 | echo $final_content; |
| 106 | } else { |
| 107 | echo esc_html__( 'Click on the Edit Content button to edit/add the content.', 'elementskit-lite' ); |
| 108 | } |
| 109 | ?> |
| 110 | </div> |
| 111 | <?php |
| 112 | } |
| 113 | ?> |
| 114 | </div> |
| 115 | <?php |
| 116 | $output = ob_get_contents(); |
| 117 | ob_end_clean(); |
| 118 | |
| 119 | return $output; |
| 120 | } |
| 121 | } |
| 122 |