C:\xampp\htdocs\landing\wp-content\plugins\wpforms-lite\src\Forms\Preview.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
<?php

namespace WPForms\Forms;

/**
 * Form preview.
 *
 * @since 1.5.1
 */
class Preview {

    
/**
     * Form data.
     *
     * @since 1.5.1
     *
     * @var array
     */
    
public $form_data;

    
/**
     * Constructor.
     *
     * @since 1.5.1
     */
    
public function __construct() {

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

        
$this->hooks();
    }

    
/**
     * Check if current page request meets requirements for form preview page.
     *
     * @since 1.5.1
     *
     * @return bool
     */
    
public function is_preview_page() {

        
// Only proceed for the form preview page.
        
if ( empty( $_GET['wpforms_form_preview'] ) ) { // phpcs:ignore
            
return false;
        }

        
// Check for logged in user with correct capabilities.
        
if ( ! \is_user_logged_in() ) {
            return 
false;
        }

        
$form_id = \absint$_GET['wpforms_form_preview'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended

        
if ( ! \wpforms_current_user_can'view_form_single'$form_id ) ) {
            return 
false;
        }

        
// Fetch form details for the entry.
        
$this->form_data = \wpforms()->form->get(
            
$form_id,
            array(
                
'content_only' => true,
            )
        );

        
// Check valid form was found.
        
if ( empty( $this->form_data ) ) {
            return 
false;
        }

        return 
true;
    }

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

        \
add_action'pre_get_posts', array( $this'pre_get_posts' ) );

        \
add_filter'the_title', array( $this'the_title' ), 100);

        \
add_filter'the_content', array( $this'the_content' ), 999 );

        \
add_filter'get_the_excerpt', array( $this'the_content' ), 999 );

        \
add_filter'template_include', array( $this'template_include' ) );

        \
add_filter'post_thumbnail_html''__return_empty_string' );
    }

    
/**
     * Modify query, limit to one post.
     *
     * @since 1.5.1
     *
     * @param \WP_Query $query The WP_Query instance.
     */
    
public function pre_get_posts$query ) {

        if ( ! 
is_admin() && $query->is_main_query() ) {
            
$query->set'posts_per_page');
        }
    }

    
/**
     * Customize form preview page title.
     *
     * @since 1.5.1
     *
     * @param string $title Page title.
     *
     * @return string
     */
    
public function the_title$title ) {

        if ( 
in_the_loop() ) {
            
$title sprintf/* translators: %s - form title. */
                
esc_html__'%s Preview''wpforms-lite' ),
                ! empty( 
$this->form_data['settings']['form_title'] ) ? sanitize_text_field$this->form_data['settings']['form_title'] ) : esc_html__'Form''wpforms-lite' )
            );
        }

        return 
$title;
    }

    
/**
     * Customize form preview page content.
     *
     * @since 1.5.1
     *
     * @return string
     */
    
public function the_content() {

        if ( ! isset( 
$this->form_data['id'] ) ) {
            return 
'';
        }

        if ( ! 
wpforms_current_user_can'view_form_single'$this->form_data['id'] ) ) {
            return 
'';
        }

        
$links = [];

        if ( 
wpforms_current_user_can'edit_form_single'$this->form_data['id'] ) ) {
            
$links[] = [
                
'url'  => esc_url(
                    
add_query_arg(
                        [
                            
'page'    => 'wpforms-builder',
                            
'view'    => 'fields',
                            
'form_id' => absint$this->form_data['id'] ),
                        ],
                         
admin_url'admin.php' )
                    )
                ),
                
'text' => esc_html__'Edit Form''wpforms-lite' ),
            ];
        }

        if ( 
wpforms()->pro && wpforms_current_user_can'view_entries_form_single'$this->form_data['id'] ) ) {
            
$links[] = [
                
'url'  => esc_url(
                    
add_query_arg(
                        [
                            
'page'    => 'wpforms-entries',
                            
'view'    => 'list',
                            
'form_id' => absint$this->form_data['id'] ),
                        ],
                        
admin_url'admin.php' )
                    )
                ),
                
'text' => esc_html__'View Entries''wpforms-lite' ),
            ];
        }

        if ( ! empty( 
$_GET['new_window'] ) ) { // phpcs:ignore
            
$links[] = [
                
'url'  => 'javascript:window.close();',
                
'text' => esc_html__'Close this window''wpforms-lite' ),
            ];
        }

        
$content  '<p>';
        
$content .= esc_html__'This is a preview of your form. This page is not publicly accessible.''wpforms-lite' );
        if ( ! empty( 
$links ) ) {
            
$content .= '<br>';
            foreach ( 
$links as $key => $link ) {
                
$content .= '<a href="' $link['url'] . '">' $link['text'] . '</a>';
                
$l        array_keys$links );
                if ( 
end$l ) !== $key ) {
                    
$content .= ' <span style="display:inline-block;margin:0 6px;opacity: 0.5">|</span> ';
                }
            }
        }
        
$content .= '</p>';

        
$content .= '<p>';
        
$content .= sprintf(
            
wp_kses(
                
/* translators: %s - WPForms doc link. */
                
__'For form testing tips, check out our <a href="%s" target="_blank" rel="noopener noreferrer">complete guide!</a>''wpforms-lite' ),
                [
                    
'a' => [
                        
'href'   => [],
                        
'target' => [],
                        
'rel'    => [],
                    ],
                ]
            ),
            
'https://wpforms.com/docs/how-to-properly-test-your-wordpress-forms-before-launching-checklist/'
        
);
        
$content .= '</p>';

        
$content .= do_shortcode'[wpforms id="' absint$this->form_data['id'] ) . '"]' );

        return 
$content;
    }

    
/**
     * Force page template types.
     *
     * @since 1.5.1
     *
     * @return string
     */
    
public function template_include() {

        return 
locate_template( array( 'page.php''single.php''index.php' ) );
    }
}
x

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