C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\src\Integrations\Gutenberg\FormSelector.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
259
260
261
262
263
264
265
266
<?php

namespace WPForms\Integrations\Gutenberg;

use 
WPForms\Integrations\IntegrationInterface;

/**
 * Form Selector Gutenberg block with live preview.
 *
 * @since 1.4.8
 */
class FormSelector implements IntegrationInterface {

    
/**
     * Indicate if current integration is allowed to load.
     *
     * @since 1.4.8
     *
     * @return bool
     */
    
public function allow_load() {
        return \
function_exists'register_block_type' );
    }

    
/**
     * Load an integration.
     *
     * @since 1.4.8
     */
    
public function load() {
        
$this->hooks();
    }

    
/**
     * Integration hooks.
     *
     * @since 1.4.8
     */
    
protected function hooks() {

        \
add_action'init', array( $this'register_block' ) );
        \
add_action'enqueue_block_editor_assets', array( $this'enqueue_block_editor_assets' ) );
    }

    
/**
     * Register WPForms Gutenberg block on the backend.
     *
     * @since 1.4.8
     */
    
public function register_block() {

        
$css_file            false;
        
$disable_css_setting wpforms_setting'disable-css''1' );
        
$min                 wpforms_get_min_suffix();

        if ( 
is_admin() ) {
            \
wp_enqueue_style(
                
'wpforms-integrations',
                
WPFORMS_PLUGIN_URL "assets/css/admin-integrations{$min}.css",
                [],
                
WPFORMS_VERSION
            
);
        }

        if ( 
'1' === $disable_css_setting ) {
            
$css_file 'full';
        } elseif ( 
'2' === $disable_css_setting ) {
            
$css_file 'base';
        }

        if ( 
$css_file ) {
            \
wp_register_style(
                
'wpforms-gutenberg-form-selector',
                
WPFORMS_PLUGIN_URL "assets/css/wpforms-{$css_file}{$min}.css",
                [ 
'wp-edit-blocks' ],
                
WPFORMS_VERSION
            
);
        }

        
$attributes = [
            
'formId'       => [
                
'type' => 'string',
            ],
            
'displayTitle' => [
                
'type' => 'boolean',
            ],
            
'displayDesc'  => [
                
'type' => 'boolean',
            ],
            
'className'    => [
                
'type' => 'string',
            ],
        ];

        \
register_block_type(
            
'wpforms/form-selector',
            [
                
'attributes'      => \apply_filters'wpforms_gutenberg_form_selector_attributes'$attributes ),
                
'editor_style'    => $css_file 'wpforms-gutenberg-form-selector' '',
                
'render_callback' => [ $this'get_form_html' ],
            ]
        );
    }

    
/**
     * Load WPForms Gutenberg block scripts.
     *
     * @since 1.4.8
     */
    
public function enqueue_block_editor_assets() {

        
$i18n = array(
            
'title'             => \esc_html__'WPForms''wpforms-lite' ),
            
'description'       => \esc_html__'Select and display one of your forms.''wpforms-lite' ),
            
'form_keywords'     => array(
                \
esc_html__'form''wpforms-lite' ),
                \
esc_html__'contact''wpforms-lite' ),
                \
esc_html__'survey''wpforms-lite' ),
                
'the dude',
            ),
            
'form_select'       => \esc_html__'Select a Form''wpforms-lite' ),
            
'form_settings'     => \esc_html__'Form Settings''wpforms-lite' ),
            
'form_selected'     => \esc_html__'Form''wpforms-lite' ),
            
'show_title'        => \esc_html__'Show Title''wpforms-lite' ),
            
'show_description'  => \esc_html__'Show Description''wpforms-lite' ),
            
'panel_notice_head' => \esc_html__'Heads up!''wpforms-lite' ),
            
'panel_notice_text' => \esc_html__'Do not forget to test your form.''wpforms-lite' ),
            
'panel_notice_link' => \esc_html__'Check out our complete guide!''wpforms-lite' ),
        );

        if ( 
version_compare$GLOBALS['wp_version'], '5.1.1''<=' ) ) {
            
array_pop$i18n['form_keywords'] );
        }

        \
wp_enqueue_script(
            
'wpforms-gutenberg-form-selector',
            
// The unminified version is not supported by the browser.
            
WPFORMS_PLUGIN_URL 'assets/js/components/admin/gutenberg/formselector.min.js',
            array( 
'wp-blocks''wp-i18n''wp-element' ),
            
WPFORMS_VERSION,
            
true
        
);

        
$forms = \wpforms()->form->get'', array( 'order' => 'DESC' ) );
        
$forms = ! empty( $forms ) ? $forms : array();
        
$forms array_map(
            function( 
$form ) {
                
$form->post_title htmlspecialchars_decode$form->post_titleENT_QUOTES );
                return 
$form;
            },
            
$forms
        
);

        \
wp_localize_script(
            
'wpforms-gutenberg-form-selector',
            
'wpforms_gutenberg_form_selector',
            array(
                
'logo_url'          => WPFORMS_PLUGIN_URL 'assets/images/sullie-alt.png',
                
'block_preview_url' => WPFORMS_PLUGIN_URL 'assets/images/integrations/gutenberg/block-preview.png',
                
'wpnonce'           => \wp_create_nonce'wpforms-gutenberg-form-selector' ),
                
'forms'             => $forms,
                
'i18n'              => $i18n,
            )
        );
    }

    
/**
     * Get form HTML to display in a WPForms Gutenberg block.
     *
     * @param array $attr Attributes passed by WPForms Gutenberg block.
     *
     * @since 1.4.8
     *
     * @return string
     */
    
public function get_form_html$attr ) {

        
$id = ! empty( $attr['formId'] ) ? \absint$attr['formId'] ) : 0;

        if ( empty( 
$id ) ) {
            return 
'';
        }

        
$title = ! empty( $attr['displayTitle'] ) ? true false;
        
$desc  = ! empty( $attr['displayDesc'] ) ? true false;

        
// Disable form fields if called from the Gutenberg editor.
        
if ( $this->is_gb_editor() ) {

            \
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
            
);
        }

        if ( ! empty( 
$attr['className'] ) ) {
            \
add_filter(
                
'wpforms_frontend_container_class',
                function ( 
$classes ) use ( $attr ) {
                    
$cls array_map'esc_attr'explode' '$attr['className'] ) );
                    return 
array_uniquearray_merge$classes$cls ) );
                }
            );
        }

        \
ob_start();

        \
do_action'wpforms_gutenberg_block_before' );

        if ( 
$this->is_gb_editor() ) {
            
wpforms_display(
                
$id,
                
apply_filters'wpforms_gutenberg_block_form_title'$title$id ),
                
apply_filters'wpforms_gutenberg_block_form_desc'$desc$id )
            );
        } else {
            
printf(
                
'[wpforms id="%s" title="%d" description="%d"]',
                
absint$id ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                
apply_filters'wpforms_gutenberg_block_form_title'$title$id ), // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
                
apply_filters'wpforms_gutenberg_block_form_desc'$desc$id // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
            
);
        }

        \
do_action'wpforms_gutenberg_block_after' );

        
$content = \ob_get_clean();

        if ( empty( 
$content ) ) {
            
$content '<div class="components-placeholder"><div class="components-placeholder__label"></div><div class="components-placeholder__fieldset">' . \esc_html__'The form cannot be displayed.''wpforms-lite' ) . '</div></div>';
        }

        return \
apply_filters'wpforms_gutenberg_block_form_content'$content$id );
    }

    
/**
     * Checking if is Gutenberg REST API call.
     *
     * @since 1.5.7
     *
     * @return bool True if is Gutenberg REST API call.
     */
    
public function is_gb_editor() {

        
// TODO: Find a better way to check if is GB editor API call.
        
return \defined'REST_REQUEST' ) && REST_REQUEST && ! empty( $_REQUEST['context'] ) && 'edit' === $_REQUEST['context']; // phpcs:ignore
    
}
}
x

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