C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\src\Integrations\Divi\Divi.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
<?php

namespace WPForms\Integrations\Divi;

use 
WPForms\Integrations\IntegrationInterface;

/**
 * Class Divi.
 *
 * @since 1.6.3
 */
class Divi implements IntegrationInterface {

    
/**
     * Load integration.
     *
     * @since 1.6.3
     *
     * @return bool
     */
    
public function allow_load() {

        if ( 
function_exists'et_divi_builder_init_plugin' ) ) {
            return 
true;
        }

        
$allow_themes = [ 'Divi''Extra' ];
        
$theme        wp_get_theme();
        
$theme_name   $theme->get_template();
        
$theme_parent $theme->parent();

        return (bool) 
array_intersect( [ $theme_name$theme_parent ], $allow_themes );
    }

    
/**
     * Load integration.
     *
     * @since 1.6.3
     */
    
public function load() {

        
$this->hooks();
    }

    
/**
     * Hooks.
     *
     * @since 1.6.3
     */
    
public function hooks() {

        
add_action'et_builder_ready', [ $this'register_module' ] );
        
add_action'wp_enqueue_scripts', [ $this'frontend_styles' ], );

        if ( 
wp_doing_ajax() ) {
            
add_action'wp_ajax_wpforms_divi_preview', [ $this'preview' ] );
        }

        if ( 
$this->is_divi_builder() ) {
            
add_filter'wpforms_global_assets''__return_true' );
            
add_action'wp_enqueue_scripts', [ $this'builder_styles' ], 12 );
            
add_action'wp_enqueue_scripts', [ $this'builder_scripts' ] );
        }
    }

    
/**
     * Check is divi builder page.
     *
     * @since 1.6.3
     *
     * @return bool
     */
    
private function is_divi_builder() {

        return ! empty( 
$_GET['et_fb'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
    
}


    
/**
     * Get current style name.
     * Overwrite styles for the Divi plugin.
     *
     * @since 1.6.3
     *
     * @return string
     */
    
public function get_current_styles_name() {

        
$disable_css absintwpforms_setting'disable-css') );
        if ( 
=== $disable_css ) {
            return 
'full';
        }
        if ( 
=== $disable_css ) {
            return 
'base';
        }

        return 
'';
    }

    
/**
     * Is the Divi plugin loaded.
     *
     * @since 1.6.3
     *
     * @return bool
     */
    
protected function is_divi_plugin_loaded() {

        if ( ! 
is_singular() ) {
            return 
false;
        }

        return 
function_exists'et_is_builder_plugin_active' ) && et_is_builder_plugin_active();
    }

    
/**
     * Register frontend styles.
     *
     * @since 1.6.3
     */
    
public function frontend_styles() {

        if ( ! 
$this->is_divi_plugin_loaded() ) {
            return;
        }

        
$min wpforms_get_min_suffix();

        
$styles_name $this->get_current_styles_name();

        if ( 
$styles_name ) {
            
// Load CSS per global setting.
            
wp_register_style(
                
"wpforms-{$styles_name}",
                
WPFORMS_PLUGIN_URL "assets/css/integrations/divi/wpforms-{$styles_name}{$min}.css",
                [],
                
WPFORMS_VERSION
            
);
        }
        
wp_register_style(
            
'wpforms-choicesjs',
            
WPFORMS_PLUGIN_URL "assets/css/integrations/divi/choices{$min}.css",
            [],
            \
WPForms_Field_Select::CHOICES_VERSION
        
);
    }

    
/**
     * Load styles for builder.
     *
     * @since 1.6.3
     */
    
public function builder_styles() {

        
$min wpforms_get_min_suffix();

        
wp_enqueue_style(
            
'wpforms-integrations',
            
WPFORMS_PLUGIN_URL "assets/css/admin-integrations{$min}.css",
            
null,
            
WPFORMS_VERSION
        
);
    }

    
/**
     * Load scripts for builder.
     *
     * @since 1.6.3
     */
    
public function builder_scripts() {

        
wp_enqueue_script(
            
'wpforms-divi',
            
// The unminified version is not supported by the browser.
            
WPFORMS_PLUGIN_URL 'assets/js/integrations/divi/formselector.min.js',
            [ 
'react''react-dom' ],
            
WPFORMS_VERSION,
            
true
        
);

        
wp_localize_script(
            
'wpforms-divi',
            
'wpforms_divi_builder',
            [
                
'ajax_url'          => admin_url'admin-ajax.php' ),
                
'nonce'             => wp_create_nonce'wpforms_divi_builder' ),
                
'placeholder'       => WPFORMS_PLUGIN_URL 'assets/images/sullie-alt.png',
                
'placeholder_title' => esc_html__'WPForms''wpforms-lite' ),
            ]
        );
    }

    
/**
     * Register module.
     *
     * @since 1.6.3
     */
    
public function register_module() {

        if ( ! 
class_exists'ET_Builder_Module' ) ) {
            return;
        }

        new 
WPFormsSelector();
    }

    
/**
     * Ajax handler for the form preview.
     *
     * @since 1.6.3
     */
    
public function preview() {

        
check_ajax_referer'wpforms_divi_builder''nonce' );

        
$form_id    absintfilter_inputINPUT_POST'form_id'FILTER_SANITIZE_NUMBER_INT ) );
        
$show_title 'on' === filter_inputINPUT_POST'show_title'FILTER_SANITIZE_STRING );
        
$show_desc  'on' === filter_inputINPUT_POST'show_desc'FILTER_SANITIZE_STRING );

        
add_filter(
            
'wpforms_frontend_container_class',
            function ( 
$classes ) {

                
$classes[] = 'wpforms-gutenberg-form-selector';
                
$classes[] = 'wpforms-container-full';

                return 
$classes;
            }
        );
        
add_action(
            
'wpforms_frontend_output',
            function () {

                echo 
'<fieldset disabled>';
            },
            
3
        
);
        
add_action(
            
'wpforms_frontend_output',
            function () {

                echo 
'</fieldset>';
            },
            
30
        
);

        
wp_send_json_success(
            
do_shortcode(
                
sprintf(
                    
'[wpforms id="%1$s" title="%2$s" description="%3$s"]',
                    
absint$form_id ),
                    (bool) 
apply_filters'wpforms_divi_builder_form_title'$show_title$form_id ),
                    (bool) 
apply_filters'wpforms_divi_builder_form_desc'$show_desc$form_id )
                )
            )
        );
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586