PluginProbe
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity / 3.3.10
Activity Logs, User Activity Tracking, Multisite Activity Log from Logtivity v3.3.10
3.3.10 3.3.9 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 All 68 releases
logtivity / Loggers / Formidable / Logtivity_Formidable.php

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

173 lines 4.3 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, [email protected]
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 unset($e);
115 }
116
117 $log->send();
118 } catch (Throwable $e) {
119 // Keep Formidable submissions working if optional logging metadata fails.
120 unset($e);
121 }
122 }
123
124 private function maybeStoreField($log, $key, $value)
125 {
126 $field = FrmField::getOne( str_replace('-value', '', $key) );
127
128 if (strpos($key, '-value') !== false) {
129 if ($field->type != 'address') {
130 return;
131 }
132 }
133
134 if ($this->shouldStoreField($field->type, $field->field_key, $value)) {
135 $value = $this->maybeLogFormValue($field->type, $value);
136 if ($value) {
137 $log->addMeta($field->name, $value);
138 }
139 }
140 }
141
142 private function shouldStoreField($field_type, $field_key, $value)
143 {
144 if (in_array($field_type, $this->ignoreFieldTypes)) {
145 return false;
146 }
147
148 if (!$value) {
149 return false;
150 }
151
152 return apply_filters('logtivity_should_store_formidable_field_value', true, $field_key, $field_type);
153 }
154
155 private function maybeLogFormValue($field_type, $value)
156 {
157 if (in_array($field_type, $this->hashFieldTypes)) {
158 return '********';
159 }
160
161 if ($field_type == 'address') {
162 if (is_array($value)) {
163 return implode(', ', $value);
164 }
165 return;
166 }
167
168 return $value;
169 }
170 }
171
172 $Logtivity_Formidable = new Logtivity_Formidable;
173