PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.22
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.22
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 6.22, at classes/models/FrmSpamCheckStopForumSpam.php

112 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 if ( ! $emails ) {
43 return false;
44 }
45
46 unset( $request_data['ip'] );
47 $request_data['email'] = $emails;
48 $response = $this->send_request( $request_data );
49
50 return $this->response_is_spam( $response );
51 }
52
53 /**
54 * Checks if this spam check is enabled.
55 *
56 * @return bool
57 */
58 protected function is_enabled() {
59 $form = FrmForm::getOne( $this->values['form_id'] );
60 return $form && ! empty( $form->options['stopforumspam'] );
61 }
62
63 /**
64 * Sends API request.
65 *
66 * @param array $request_data Request data.
67 * @return string
68 */
69 private function send_request( $request_data ) {
70 /**
71 * Filters the data to be passed to the stopforumspam request URL.
72 *
73 * @since 6.21
74 *
75 * @param array $request_data Request data.
76 * @param array $args Contains `values`.
77 */
78 $request_data = apply_filters( 'frm_stopforumspam_request_data', $request_data, array( 'values' => $this->values ) );
79
80 /**
81 * Filters the stopforumspam API URL.
82 *
83 * @since 6.21
84 *
85 * @param string $api_url API URL.
86 * @param array $args Contains `values`.
87 */
88 $api_url = apply_filters( 'frm_stopforumspam_api_url', 'https://api.stopforumspam.org/api', array( 'values' => $this->values ) );
89
90 $url = add_query_arg( $request_data, $api_url );
91
92 $response = wp_remote_get( $url, array( 'timeout' => 15 ) );
93
94 return wp_remote_retrieve_body( $response );
95 }
96
97 /**
98 * Checks if the response is spam.
99 *
100 * @param string $response Response body.
101 * @return bool
102 */
103 private function response_is_spam( $response ) {
104 if ( ! $response ) {
105 // Request failed or error happened.
106 return false;
107 }
108
109 return false !== strpos( $response, '<appears>yes</appears>' ) || false !== strpos( $response, '<appears>1</appears>' );
110 }
111 }
112