PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / trunk
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity vtrunk
3.3.8 trunk 1.0 1.1.0 1.10.0 1.11.0 1.11.1 1.12.0 1.13.0 1.14.0 1.15.0 1.16.0 1.17.0 1.17.1 1.18.0 1.19.0 1.2.0 1.20.0 1.20.1 1.3.0 1.3.1 1.4.0 1.5.0 1.6.0 1.6.1 All 66 releases
logtivity / Loggers / Formidable / Logtivity_Formidable.php

Logtivity_Formidable.php in Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity trunk, at Loggers/Formidable/Logtivity_Formidable.php

170 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * @package Logtivity
5 * @contact logtivity.io, hello@logtivity.io
6 * @copyright 2024-2026 Logtivity. All rights reserved
7 * @license https://www.gnu.org/licenses/gpl.html GNU/GPL
8 *
9 * This file is part of Logtivity.
10 *
11 * Logtivity is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * Logtivity is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with Logtivity. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25 class Logtivity_Formidable
26 {
27 protected $hashFieldTypes = [
28 'password',
29 'credit_card',
30 ];
31
32 protected $ignoreFieldTypes = [
33 'divider',
34 'end_divider',
35 ];
36
37 public function __construct()
38 {
39 add_action('frm_after_create_entry', [$this, 'entryCreated'], 10, 3);
40 }
41
42 public function entryCreated($entry_id, $form_id, $is_child)
43 {
44 if (apply_filters('logtivity_disable_formidable_logging', false)) {
45 return;
46 }
47
48 try {
49 $entry = FrmEntry::getOne( $entry_id, true );
50
51 $FrmEntryFormatter = new Logtivity_FrmEntryFormatter([
52 'entry' => $entry,
53 'format' => 'array',
54 ]);
55
56 $log = Logtivity::log()
57 ->setAction('Form Submitted')
58 ->setContext($entry->form_name)
59 ->addMeta('Form ID', $form_id)
60 ->addMeta('Entry ID', $entry_id);
61
62 try {
63
64 if (class_exists('FrmProEntriesController')) {
65 if (isset($is_child['is_child']) && $is_child['is_child'] === true) {
66 return;
67 }
68 $entry = FrmProEntriesController::show_entry_shortcode( array( 'id' => $entry_id, 'format' => 'array' ) );
69
70 $seenSubFields = [];
71
72 foreach ($entry as $key => $value) {
73 if (isset($value['form'])) {
74 foreach ($value as $key => $sub_fields) {
75 if ($key != 'form') {
76 foreach ($sub_fields as $key => $value) {
77 $seenSubFields[$key] = $key;
78 $this->maybeStoreField($log, $key, $value);
79 }
80 }
81 }
82 } else {
83 if (isset($seenSubFields[$key])) {
84 unset($seenSubFields[$key]);
85 continue;
86 }
87 $this->maybeStoreField($log, $key, $value);
88 }
89 }
90 } else {
91 foreach ($FrmEntryFormatter->logtivityGetEntryValues() as $key => $field_value) {
92 $field_value->prepare_displayed_value();
93
94 if (
95 $this->shouldStoreField(
96 $field_value->get_field_type(),
97 $field_value->get_field_key(),
98 $field_value->get_displayed_value()
99 )
100 ) {
101 $log->addMeta(
102 $field_value->get_field_label(),
103 $this->maybeLogFormValue(
104 $field_value->get_field_type(),
105 $field_value->get_displayed_value()
106 )
107 );
108 }
109 }
110 }
111
112 } catch (Throwable $e) {
113 // Ignore
114 }
115
116 $log->send();
117 } catch (Throwable $e) {
118 error_log($e);
119 }
120 }
121
122 private function maybeStoreField($log, $key, $value)
123 {
124 $field = FrmField::getOne( str_replace('-value', '', $key) );
125
126 if (strpos($key, '-value') !== false) {
127 if ($field->type != 'address') {
128 return;
129 }
130 }
131
132 if ($this->shouldStoreField($field->type, $field->field_key, $value)) {
133 if ($value = $this->maybeLogFormValue($field->type, $value)) {
134 $log->addMeta($field->name, $value);
135 }
136 }
137 }
138
139 private function shouldStoreField($field_type, $field_key, $value)
140 {
141 if (in_array($field_type, $this->ignoreFieldTypes)) {
142 return false;
143 }
144
145 if (!$value) {
146 return false;
147 }
148
149 return apply_filters('logtivity_should_store_formidable_field_value', true, $field_key, $field_type);
150 }
151
152 private function maybeLogFormValue($field_type, $value)
153 {
154 if (in_array($field_type, $this->hashFieldTypes)) {
155 return '********';
156 }
157
158 if ($field_type == 'address') {
159 if (is_array($value)) {
160 return implode(', ', $value);
161 }
162 return;
163 }
164
165 return $value;
166 }
167 }
168
169 $Logtivity_Formidable = new Logtivity_Formidable;
170