PluginProbe
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder / 3.6.2
Fluent Forms – Customizable Contact Forms, Survey, Quiz, & Conversational Form Builder v3.6.2
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 3.6.66 All 195 releases
fluentform / app / Modules / Form / AkismetHandler.php

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

84 lines 2.5 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 && ArrayHelper::get($settings, 'misc.akismet_status') == 'yes';
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 ArrayHelper::get($response, 1) == 'true';
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('fluentform_akismet_fields', $info, $data, $form);
79
80 return http_build_query($info);
81
82 }
83
84 }