/var/www/html_us/wp-content/plugins/contact-form-7/modules/akismet.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
<?php
/**
 * The Akismet integration module
 *
 * @link https://akismet.com/development/api/
 */


add_filter'wpcf7_spam''wpcf7_akismet'10);

function 
wpcf7_akismet$spam$submission ) {
    if ( 
$spam ) {
        return 
$spam;
    }

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

    if ( ! 
$params wpcf7_akismet_submitted_params() ) {
        return 
false;
    }

    
$c = array();

    
$c['comment_author'] = $params['author'];
    
$c['comment_author_email'] = $params['author_email'];
    
$c['comment_author_url'] = $params['author_url'];
    
$c['comment_content'] = $params['content'];

    
$c['blog'] = get_option'home' );
    
$c['blog_lang'] = get_locale();
    
$c['blog_charset'] = get_option'blog_charset' );
    
$c['user_ip'] = $_SERVER['REMOTE_ADDR'];
    
$c['user_agent'] = $_SERVER['HTTP_USER_AGENT'];
    
$c['referrer'] = $_SERVER['HTTP_REFERER'];
    
$c['comment_type'] = 'contact-form';

    
$datetime date_create_immutable(
        
'@' $submission->get_meta'timestamp' )
    );

    if ( 
$datetime ) {
        
$c['comment_date_gmt'] = $datetime->formatDATE_ATOM );
    }

    if ( 
$permalink get_permalink() ) {
        
$c['permalink'] = $permalink;
    }

    
$ignore = array( 'HTTP_COOKIE''HTTP_COOKIE2''PHP_AUTH_PW' );

    foreach ( 
$_SERVER as $key => $value ) {
        if ( ! 
in_array$key, (array) $ignore ) ) {
            
$c["$key"] = $value;
        }
    }

    
$c apply_filters'wpcf7_akismet_parameters'$c );

    if ( 
wpcf7_akismet_comment_check$c ) ) {
        
$spam true;

        
$submission->add_spam_log( array(
            
'agent' => 'akismet',
            
'reason' => __"Akismet returns a spam response."'contact-form-7' ),
        ) );
    } else {
        
$spam false;
    }

    return 
$spam;
}


/**
 * Returns true if Akismet is active and has a valid API key.
 */
function wpcf7_akismet_is_available() {
    if ( 
is_callable( array( 'Akismet''get_api_key' ) ) ) {
        return (bool) 
Akismet::get_api_key();
    }

    return 
false;
}


/**
 * Returns an array of parameters based on the current form submission.
 * Returns false if Akismet is not active on the contact form.
 */
function wpcf7_akismet_submitted_params() {
    
$akismet_tags array_filter(
        
wpcf7_scan_form_tags(),
        function ( 
$tag ) {
            
$akismet_option $tag->get_option'akismet',
                
'(author|author_email|author_url)',
                
true
            
);

            return (bool) 
$akismet_option;
        }
    );

    if ( ! 
$akismet_tags ) { // Akismet is not active on this contact form.
        
return false;
    }

    
$params = array(
        
'author' => '',
        
'author_email' => '',
        
'author_url' => '',
        
'content' => '',
    );

    foreach ( (array) 
$_POST as $key => $val ) {
        if ( 
'_wpcf7' == substr$key0)
        or 
'_wpnonce' == $key ) {
            continue;
        }

        
$vals array_filter(
            
wpcf7_array_flatten$val ),
            function ( 
$val ) {
                return 
'' !== trim$val );
            }
        );

        if ( empty( 
$vals ) ) {
            continue;
        }

        if ( 
$tags wpcf7_scan_form_tags( array( 'name' => $key ) ) ) {
            
$tag $tags[0];

            
$akismet_option $tag->get_option'akismet',
                
'(author|author_email|author_url)',
                
true
            
);

            if ( 
'author' === $akismet_option ) {
                
$params['author'] = sprintf(
                    
'%s %s',
                    
$params['author'],
                    
implode' '$vals )
                );

                continue;
            }

            if ( 
'author_email' === $akismet_option
            
and '' === $params['author_email'] ) {
                
$params['author_email'] = $vals[0];
                continue;
            }

            if ( 
'author_url' === $akismet_option
            
and '' === $params['author_url'] ) {
                
$params['author_url'] = $vals[0];
                continue;
            }

            
$vals array_filter(
                
$vals,
                function ( 
$val ) use ( $tag ) {
                    if ( 
wpcf7_form_tag_supports$tag->type'selectable-values' )
                    and 
in_array$val$tag->labels ) ) {
                        return 
false;
                    } else {
                        return 
true;
                    }
                }
            );
        }

        if ( 
$vals ) {
            
$params['content'] .= "\n\n" implode', '$vals );
        }
    }

    
$params array_map'trim'$params );

    return 
$params;
}


/**
 * Sends data to Akismet.
 *
 * @param array $comment Submission and environment data.
 * @return bool True if Akismet called it spam, or false otherwise.
 */
function wpcf7_akismet_comment_check$comment ) {
    
$spam false;
    
$query_string wpcf7_build_query$comment );

    if ( 
is_callable( array( 'Akismet''http_post' ) ) ) {
        
$response Akismet::http_post$query_string'comment-check' );
    } else {
        return 
$spam;
    }

    if ( 
'true' == $response[1] ) {
        
$spam true;
    }

    if ( 
$submission WPCF7_Submission::get_instance() ) {
        
$submission->akismet = array( 'comment' => $comment'spam' => $spam );
    }

    return 
apply_filters'wpcf7_akismet_comment_check'$spam$comment );
}


add_filter'wpcf7_posted_data''wpcf7_akismet_posted_data'10);

/**
 * Removes Akismet-related properties from the posted data.
 *
 * This does not affect the $_POST variable itself.
 *
 * @link https://plugins.trac.wordpress.org/browser/akismet/tags/5.0/_inc/akismet-frontend.js
 */
function wpcf7_akismet_posted_data$posted_data ) {
    if ( 
wpcf7_akismet_is_available() ) {
        
$posted_data array_diff_key(
            
$posted_data,
            array(
                
'ak_bib' => '',
                
'ak_bfs' => '',
                
'ak_bkpc' => '',
                
'ak_bkp' => '',
                
'ak_bmc' => '',
                
'ak_bmcc' => '',
                
'ak_bmk' => '',
                
'ak_bck' => '',
                
'ak_bmmc' => '',
                
'ak_btmc' => '',
                
'ak_bsc' => '',
                
'ak_bte' => '',
                
'ak_btec' => '',
                
'ak_bmm' => '',
            )
        );
    }

    return 
$posted_data;
}