1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
<?php
namespace WPForms\Logger;
/** * Class Log. * * @since 1.6.3 */ class Log {
/** * Repository. * * @since 1.6.3 * * @var \WPForms\Logger\Repository */ private $repository;
/** * List table. * * @since 1.6.3 * * @var \WPForms\Logger\ListTable */ private $list_table;
/** * Register log hooks. * * @since 1.6.3 */ public function hooks() {
$this->repository = new Repository( new RecordQuery() ); add_action( 'shutdown', [ $this->repository, 'save' ] );
add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_styles' ] ); add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] ); add_action( 'wp_ajax_wpforms_get_log_record', [ $this, 'get_record' ] ); }
/** * Enqueue styles. * * @since 1.6.3 */ public function enqueue_styles() {
if ( ! $this->is_logger_page() ) { return; } $min = wpforms_get_min_suffix(); wp_enqueue_style( 'wpforms-tools-logger', WPFORMS_PLUGIN_URL . "assets/css/logger{$min}.css", [], WPFORMS_VERSION, 'all' ); }
/** * Enqueue styles. * * @since 1.6.3 */ public function enqueue_scripts() {
if ( ! $this->is_logger_page() ) { return; } $min = wpforms_get_min_suffix(); wp_enqueue_script( 'wpforms-tools-logger', WPFORMS_PLUGIN_URL . "assets/js/components/admin/logger/logger{$min}.js", [ 'jquery', 'jquery-confirm', 'wp-util' ], WPFORMS_VERSION, true ); }
/** * Get log types. * * @since 1.6.3 * * @return array */ public static function get_log_types() {
return [ 'conditional_logic' => esc_html__( 'Conditional Logic', 'wpforms-lite' ), 'entry' => esc_html__( 'Entries', 'wpforms-lite' ), 'error' => esc_html__( 'Errors', 'wpforms-lite' ), 'payment' => esc_html__( 'Payment', 'wpforms-lite' ), 'provider' => esc_html__( 'Providers', 'wpforms-lite' ), 'spam' => esc_html__( 'Spam', 'wpforms-lite' ), ]; }
/** * Determine if it a Logs page. * * @since 1.6.3 * * @return bool */ private function is_logger_page() {
//phpcs:ignore WordPress.Security.NonceVerification.Recommended return isset( $_GET['page'] ) && 'wpforms-tools' === $_GET['page'] && isset( $_GET['view'] ) && 'logs' === $_GET['view']; }
/** * Create new record. * * @since 1.6.3 * * @param string $title Record title. * @param string $message Record message. * @param array|string $types Array, string, or string separated by commas types. * @param int $form_id Record form ID. * @param int $entry_id Record entry ID. * @param int $user_id Record user ID. */ public function add( $title, $message, $types, $form_id = 0, $entry_id = 0, $user_id = 0 ) {
$this->repository->add( $title, $message, $types, $form_id, $entry_id, $user_id ); }
/** * Create table for logs. * * @since 1.6.3 */ public function create_table() {
$this->repository->create_table(); }
/** * Get ListView. * * @since 1.6.3 * * @return \WPForms\Logger\ListTable */ public function get_list_table() {
if ( ! $this->list_table ) { $this->list_table = new ListTable( $this->repository );
add_action( 'admin_print_scripts', [ $this->list_table, 'popup_template' ] ); }
return $this->list_table; }
/** * Json config for detail information about log record. * * @since 1.6.3 */ public function get_record() {
if ( ! check_ajax_referer( 'wpforms-admin', 'nonce', false ) || ! wpforms_current_user_can() ) { wp_send_json_error( esc_html__( 'You do not have permission.', 'wpforms-lite' ) ); }
$id = filter_input( INPUT_GET, 'recordId', FILTER_VALIDATE_INT );
if ( ! $id ) { wp_send_json_error( esc_html__( 'Record ID doesn\'t found', 'wpforms-lite' ), 404 ); }
$item = $this->repository->record( $id );
wp_send_json_success( [ 'ID' => absint( $item->get_id() ), 'title' => esc_html( $item->get_title() ), 'message' => wp_kses( $item->get_message(), [ 'pre' => [] ] ), 'types' => esc_html( implode( ', ', $item->get_types( 'label' ) ) ), 'create_at' => esc_html( $item->get_date( 'full' ) ), 'form_id' => absint( $item->get_form_id() ), 'entry_id' => absint( $item->get_entry_id() ), 'user_id' => absint( $item->get_user_id() ), 'form_url' => admin_url( sprintf( 'admin.php?page=wpforms-builder&view=fields&form_id=%d', absint( $item->get_form_id() ) ) ), 'entry_url' => admin_url( sprintf( 'admin.php?page=wpforms-entries&view=details&entry_id=%d', absint( $item->get_entry_id() ) ) ), 'user_url' => esc_url( get_edit_user_link( $item->get_user_id() ) ), ] ); } }
|