PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / trunk
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More vtrunk
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
formidable / classes / models / FrmSpamCheckStopForumSpam.php

FrmSpamCheckStopForumSpam.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More trunk, at classes/models/FrmSpamCheckStopForumSpam.php

114 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Check spam using stopforumspam API
4 *
5 * @since 6.21
6 *
7 * @package Formidable
8 */
9
10 if ( ! defined( 'ABSPATH' ) ) {
11 die( 'You are not allowed to call this page directly.' );
12 }
13
14 /**
15 * Class FrmSpamCheckStopForumSpam
16 */
17 class FrmSpamCheckStopForumSpam extends FrmSpamCheck {
18
19 /**
20 * Checks spam.
21 *
22 * @return bool
23 */
24 protected function check() {
25 $ip_address = FrmAppHelper::get_ip_address();
26 $whitelist_ip = FrmAntiSpamController::get_allowed_ips();
27 $request_data = array();
28
29 if ( ! in_array( $ip_address, $whitelist_ip, true ) ) {
30 $request_data['ip'] = $ip_address;
31 }
32
33 if ( $request_data ) {
34 $response = $this->send_request( $request_data );
35
36 if ( $this->response_is_spam( $response ) ) {
37 return true;
38 }
39 }
40
41 $emails = FrmAntiSpamController::extract_emails_from_values( $this->values['item_meta'] );
42
43 if ( ! $emails ) {
44 return false;
45 }
46
47 unset( $request_data['ip'] );
48 $request_data['email'] = $emails;
49 $response = $this->send_request( $request_data );
50
51 return $this->response_is_spam( $response );
52 }
53
54 /**
55 * Checks if this spam check is enabled.
56 *
57 * @return bool
58 */
59 protected function is_enabled() {
60 $form = FrmForm::getOne( $this->values['form_id'] );
61 return $form && ! empty( $form->options['stopforumspam'] );
62 }
63
64 /**
65 * Sends API request.
66 *
67 * @param array $request_data Request data.
68 *
69 * @return string
70 */
71 private function send_request( $request_data ) {
72 /**
73 * Filters the data to be passed to the stopforumspam request URL.
74 *
75 * @since 6.21
76 *
77 * @param array $request_data Request data.
78 * @param array $args Contains `values`.
79 */
80 $request_data = apply_filters( 'frm_stopforumspam_request_data', $request_data, array( 'values' => $this->values ) );
81
82 /**
83 * Filters the stopforumspam API URL.
84 *
85 * @since 6.21
86 *
87 * @param string $api_url API URL.
88 * @param array $args Contains `values`.
89 */
90 $api_url = apply_filters( 'frm_stopforumspam_api_url', 'https://api.stopforumspam.org/api', array( 'values' => $this->values ) );
91
92 $url = add_query_arg( $request_data, $api_url );
93 $response = wp_remote_get( $url, array( 'timeout' => 15 ) );
94
95 return wp_remote_retrieve_body( $response );
96 }
97
98 /**
99 * Checks if the response is spam.
100 *
101 * @param string $response Response body.
102 *
103 * @return bool
104 */
105 private function response_is_spam( $response ) {
106 if ( ! $response ) {
107 // Request failed or error happened.
108 return false;
109 }
110
111 return str_contains( $response, '<appears>yes</appears>' ) || str_contains( $response, '<appears>1</appears>' );
112 }
113 }
114