PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 5.2.9
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v5.2.9
6.2.14 6.2.13 6.2.12 6.2.10 6.2.11 6.2.9 6.2.8 6.2.7 6.2.6 6.2.5 6.2.4 6.2.3 6.2.2 3.6.22 3.6.31 3.6.40 3.6.41 3.6.42 3.6.50 3.6.51 3.6.60 3.6.61 3.6.62 3.6.64 3.6.65 All 196 releases
fluentform / app / Modules / Form / AkismetHandler.php

AkismetHandler.php in Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder 5.2.9, at app/Modules/Form/AkismetHandler.php

95 lines 2.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FluentForm\App\Modules\Form;
4
5 use FluentForm\App\Helpers\Helper;
6 use FluentForm\App\Modules\Acl\Acl;
7 use FluentForm\Framework\Helpers\ArrayHelper;
8
9 class AkismetHandler
10 {
11 public static function isEnabled()
12 {
13 if (!self::isPluginEnabled()) {
14 return false;
15 }
16
17 $settings = get_option('_fluentform_global_form_settings');
18 return $settings && 'yes' == ArrayHelper::get($settings, 'misc.akismet_status');
19 }
20
21 public static function isPluginEnabled()
22 {
23 $exists = method_exists('Akismet', 'http_post');
24 if ($exists) {
25 return !!\Akismet::get_api_key();
26 }
27 return false;
28 }
29
30 public static function isSpamSubmission($formData, $form)
31 {
32 global $akismet_api_host, $akismet_api_port;
33 $fields = self::getAkismetFields($formData, $form);
34 $response = \Akismet::http_post($fields, 'comment-check');
35
36 return 'true' == ArrayHelper::get($response, 1);
37 }
38
39 protected static function getAkismetFields($data, $form)
40 {
41 $app = wpFluentForm();
42 $ip = $app->request->getIp();
43
44 $info = [
45 'comment_type' => 'contact-form',
46 'comment_author' => '',
47 'comment_author_email' => '',
48 'comment_content' => '',
49 'contact_form_subject' => $form->title,
50 'comment_author_IP' => $ip,
51 'permalink' => urlencode($data['_wp_http_referer']),
52 'user_ip' => preg_replace('/[^0-9., ]/', '', $ip),
53 'user_agent' => $app->request->header('USER_AGENT'),
54 'blog' => get_option('home'),
55 ];
56
57 $maps = [
58 'input_name' => 'comment_author',
59 'input_email' => 'comment_author_email',
60 'textarea' => 'comment_content',
61 ];
62 $inputs = FormFieldsParser::getInputs($form, ['attributes']);
63
64 foreach ($inputs as $input) {
65 $element = ArrayHelper::get($input, 'element');
66 $key = ArrayHelper::get($input, 'attributes.name');
67 if (isset($maps[$element]) && !$info[$maps[$element]]) {
68 $value = ArrayHelper::get($data, $key);
69 if ($value) {
70 if (is_array($value)) {
71 $value = implode(' ', $value);
72 }
73 $info[$maps[$element]] = $value;
74 }
75 }
76 }
77
78 $info = apply_filters_deprecated(
79 'fluentform_akismet_fields',
80 [
81 $info,
82 $data,
83 $form
84 ],
85 FLUENTFORM_FRAMEWORK_UPGRADE,
86 'fluentform/akismet_fields',
87 'Use fluentform/akismet_fields instead of fluentform_akismet_fields.'
88 );
89
90 $info = apply_filters('fluentform/akismet_fields', $info, $data, $form);
91
92 return http_build_query($info);
93 }
94 }
95