PluginProbe ʕ •ᴥ•ʔ
GiveWP – Donation Plugin and Fundraising Platform / 2.7.5
GiveWP – Donation Plugin and Fundraising Platform v2.7.5
4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 2.32.0 2.33.0 2.33.1 2.33.2 2.33.3 2.33.4 2.33.5 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.4.5 2.4.6 2.4.7 2.5.0 2.5.1 2.5.10 2.5.11 2.5.12 2.5.13 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 2.5.7 2.5.8 2.5.9 2.6.0 2.6.1 2.6.2 2.6.3 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.8.0 2.8.1 2.9.0 2.9.1 2.9.2 2.9.3 2.9.4 2.9.5 2.9.6 2.9.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.10.0 3.11.0 3.12.0 3.12.1 3.12.2 3.12.3 3.13.0 3.14.0 3.14.1 3.14.2 3.15.0 3.15.1 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.17.0 3.17.1 3.17.2 3.18.0 3.19.0 3.19.1 3.19.2 3.19.3 3.19.4 3.2.0 3.2.1 3.2.2 3.20.0 3.21.0 3.21.1 3.22.0 3.22.1 3.22.2 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.5.1 3.6.0 3.6.1 3.6.2 3.7.0 3.8.0 3.9.0 4.0.0 4.1.0 4.1.1 4.10.0 4.10.1 4.11.0 4.12.0 4.13.0 4.13.1 4.13.2 4.14.0 4.14.1 4.14.2 4.14.3 4.14.4 4.14.5 4.14.6 4.2.0 4.2.1 4.3.0 4.3.1 4.3.2 4.4.0 4.5.0 4.6.1 4.7.0 4.7.1 4.8.0 4.8.1 4.9.0 trunk 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.10.0 2.10.1 2.10.2 2.10.3 2.10.4 2.11.0 2.11.1 2.11.2 2.11.3 2.12.0 2.12.1 2.12.2 2.12.3 2.13.0 2.13.1 2.13.2 2.13.3 2.13.4 2.14.0 2.15.0 2.16.0 2.16.1 2.17.0 2.17.1 2.17.3 2.18.0 2.18.1 2.19.1 2.19.2 2.19.3 2.19.4 2.19.5 2.19.6 2.19.7 2.19.8 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.20.0 2.20.1 2.20.2 2.21.0 2.21.1 2.21.2 2.21.3 2.21.4 2.22.0 2.22.1 2.22.2 2.22.3 2.23.0 2.23.1 2.23.2 2.24.0 2.24.1 2.24.2 2.25.0 2.25.1 2.25.2 2.25.3 2.26.0 2.27.0 2.27.1 2.27.2 2.27.3 2.28.0 2.29.0 2.29.1 2.29.2
give / includes / admin / tools / logs / class-api-requests-logs-list-table.php
give / includes / admin / tools / logs Last commit date
class-api-requests-logs-list-table.php 6 years ago class-gateway-error-logs-list-table.php 6 years ago class-spam-logs-list-table.php 6 years ago class-update-logs-list-table.php 6 years ago logs.php 6 years ago
class-api-requests-logs-list-table.php
392 lines
1 <?php
2 /**
3 * API Requests Log View Class
4 *
5 * @package Give
6 * @subpackage Admin/Reports
7 * @copyright Copyright (c) 2016, GiveWP
8 * @license https://opensource.org/licenses/gpl-license GNU Public License
9 * @since 1.0
10 */
11
12 // Exit if accessed directly.
13 if ( ! defined( 'ABSPATH' ) ) {
14 exit;
15 }
16
17 // Load WP_List_Table if not loaded
18 if ( ! class_exists( 'WP_List_Table' ) ) {
19 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
20 }
21
22 /**
23 * Give_API_Request_Log_Table List Table Class
24 *
25 * Renders the gateway errors list table
26 *
27 * @since 1.0
28 */
29 class Give_API_Request_Log_Table extends WP_List_Table {
30 /**
31 * Number of items per page
32 *
33 * @var int
34 * @since 1.0
35 */
36 public $per_page = 30;
37
38 /**
39 * Get things started
40 *
41 * @since 1.0
42 * @see WP_List_Table::__construct()
43 */
44 public function __construct() {
45 global $status, $page;
46
47 // Set parent defaults
48 parent::__construct(
49 array(
50 'singular' => give_get_forms_label_singular(), // Singular name of the listed records
51 'plural' => give_get_forms_label_plural(), // Plural name of the listed records
52 'ajax' => false, // Does this table support ajax?
53 )
54 );
55 }
56
57 /**
58 * Show the search field
59 *
60 * @since 1.0
61 * @access public
62 *
63 * @param string $text Label for the search box
64 * @param string $input_id ID of the search box
65 *
66 * @return void
67 */
68 public function search_box( $text, $input_id ) {
69 $input_id = $input_id . '-search-input';
70
71 if ( ! empty( $_REQUEST['orderby'] ) ) {
72 echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
73 }
74 if ( ! empty( $_REQUEST['order'] ) ) {
75 echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
76 }
77 ?>
78 <p class="search-box" role="search">
79 <label class="screen-reader-text" for="<?php echo $input_id; ?>"><?php echo $text; ?>:</label>
80 <input type="search" id="<?php echo $input_id; ?>" name="s" value="<?php _admin_search_query(); ?>"/>
81 <?php submit_button( $text, 'button', false, false, array( 'ID' => 'search-submit' ) ); ?>
82 </p>
83 <?php
84 }
85
86 /**
87 * Retrieve the table columns
88 *
89 * @access public
90 * @since 1.0
91 *
92 * @return array $columns Array of all the list table columns
93 */
94 public function get_columns() {
95 $columns = array(
96 'ID' => __( 'Log ID', 'give' ),
97 'ip' => __( 'Request IP', 'give' ),
98 'date' => __( 'Date', 'give' ),
99 'details' => __( 'Request Details', 'give' ),
100 );
101
102 return $columns;
103 }
104
105 /**
106 * This function renders most of the columns in the list table.
107 *
108 * @access public
109 * @since 1.0
110 *
111 * @param array $item Contains all the data of the discount code
112 * @param string $column_name The name of the column
113 *
114 * @return string Column Name
115 */
116 public function column_default( $item, $column_name ) {
117 switch ( $column_name ) {
118 default:
119 return esc_attr( $item[ $column_name ] );
120 }
121 }
122
123 /**
124 * Output Error Message column
125 *
126 * @access public
127 * @since 1.0
128 *
129 * @param array $item Contains all the data of the log
130 *
131 * @return void
132 */
133 public function column_details( $item ) {
134 echo Give()->tooltips->render_link(
135 array(
136 'label' => __( 'View Request', 'give' ),
137 'tag_content' => '<span class="dashicons dashicons-visibility"></span>',
138 'link' => "#TB_inline?width=640&amp;inlineId=log-details-{$item['ID']}",
139 'attributes' => array(
140 'class' => 'thickbox give-error-log-details-link button button-small',
141 ),
142 )
143 );
144 ?>
145 <div id="log-details-<?php echo $item['ID']; ?>" style="display:none;">
146 <?php
147 // Print API Request.
148 echo sprintf(
149 '<p><strong>%1$s</strong></p><div>%2$s</div>',
150 __( 'API Request:', 'give' ),
151 Give()->logs->logmeta_db->get_meta( $item['ID'], '_give_log_api_query', true )
152 );
153
154 // Print Log Content, if not empty.
155 if ( ! empty( $item['log_content'] ) ) {
156 echo sprintf(
157 '<p><strong>%1$s</strong></p><div>%2$s</div>',
158 __( 'Error', 'give' ),
159 esc_html( $item['log_content'] )
160 );
161 }
162
163 // Print User who requested data using API.
164 echo sprintf(
165 '<p><strong>%1$s</strong></p><div>%2$s</div>',
166 __( 'API User:', 'give' ),
167 Give()->logs->logmeta_db->get_meta( $item['ID'], '_give_log_user', true )
168 );
169
170 // Print the logged key used by API.
171 echo sprintf(
172 '<p><strong>%1$s</strong></p><div>%2$s</div>',
173 __( 'API Key:', 'give' ),
174 Give()->logs->logmeta_db->get_meta( $item['ID'], '_give_log_key', true )
175 );
176
177 // Print the API Request Date.
178 echo sprintf(
179 '<p><strong>%1$s</strong></p><div>%2$s</div>',
180 __( 'Request Date:', 'give' ),
181 $item['log_date']
182 );
183 ?>
184 </div>
185 <?php
186 }
187
188 /**
189 * Retrieves the search query string
190 *
191 * @access public
192 * @since 1.0
193 *
194 * @return string|bool String if search is present, false otherwise
195 */
196 public function get_search() {
197 return ! empty( $_GET['s'] ) ? urldecode( trim( $_GET['s'] ) ) : false;
198 }
199
200
201 /**
202 * Display Tablenav (extended)
203 *
204 * Display the table navigation above or below the table even when no items in the logs, so nav doesn't disappear
205 *
206 * @see : https://github.com/impress-org/give/issues/564
207 *
208 * @since 1.4.1
209 * @access protected
210 *
211 * @param string $which
212 */
213 protected function display_tablenav( $which ) {
214 if ( 'top' === $which ) {
215 wp_nonce_field( 'bulk-' . $this->_args['plural'] );
216 }
217 ?>
218 <div class="tablenav <?php echo esc_attr( $which ); ?>">
219
220 <div class="alignleft actions bulkactions">
221 <?php $this->bulk_actions( $which ); ?>
222 </div>
223 <?php
224 $this->extra_tablenav( $which );
225 $this->pagination( $which );
226 ?>
227
228 <br class="clear"/>
229 </div>
230 <?php
231 }
232
233 /**
234 * Gets the meta query for the log query
235 *
236 * This is used to return log entries that match our search query
237 *
238 * @access public
239 * @since 1.0
240 *
241 * @return array $meta_query
242 */
243 function get_meta_query() {
244
245 $meta_query = array();
246 $search = $this->get_search();
247
248 if ( $search ) {
249 if ( filter_var( $search, FILTER_VALIDATE_IP ) ) {
250
251 // This is an IP address search.
252 $key = '_give_log_request_ip';
253
254 } elseif ( is_email( $search ) ) {
255
256 // This is an email search.
257 $userdata = get_user_by( 'email', $search );
258
259 if ( $userdata ) {
260 $search = $userdata->ID;
261 }
262
263 $key = '_give_log_user';
264
265 } elseif ( 32 === strlen( $search ) ) {
266
267 // Look for an API key.
268 $key = '_give_log_key';
269
270 } elseif ( stristr( $search, 'token:' ) ) {
271
272 // Look for an API token.
273 $search = str_ireplace( 'token:', '', $search );
274 $key = '_give_log_token';
275
276 } else {
277
278 // This is (probably) a user ID search.
279 $userdata = get_userdata( $search );
280
281 if ( $userdata ) {
282 $search = $userdata->ID;
283 }
284
285 $key = '_give_log_user';
286
287 }
288
289 // Setup the meta query.
290 $meta_query[] = array(
291 'key' => $key,
292 'value' => $search,
293 'compare' => '=',
294 );
295 }
296
297 return $meta_query;
298 }
299
300 /**
301 * Retrieve the current page number
302 *
303 * @access public
304 * @since 1.0
305 *
306 * @return int Current page number
307 */
308 public function get_paged() {
309 return isset( $_GET['paged'] ) ? absint( $_GET['paged'] ) : 1;
310 }
311
312 /**
313 * Outputs the log views
314 *
315 * @param string $which Top or Bottom.
316 *
317 * @access public
318 * @since 1.0
319 *
320 * @return void
321 */
322 function bulk_actions( $which = '' ) {
323 give_log_views();
324 }
325
326 /**
327 * Gets the log entries for the current view
328 *
329 * @access public
330 * @since 1.0
331 *
332 * @return array $logs_data Array of all the Log entires
333 */
334 public function get_logs() {
335 $logs_data = array();
336 $paged = $this->get_paged();
337 $log_query = array(
338 'log_type' => 'api_request',
339 'paged' => $paged,
340 'meta_query' => $this->get_meta_query(),
341 'posts_per_page' => $this->per_page,
342 );
343
344 $logs = Give()->logs->get_connected_logs( $log_query );
345
346 if ( $logs ) {
347 foreach ( $logs as $log ) {
348
349 $logs_data[] = array(
350 'ID' => $log->ID,
351 'ip' => Give()->logs->logmeta_db->get_meta( $log->ID, '_give_log_request_ip', true ),
352 'date' => $log->log_date,
353 'log_content' => $log->log_content,
354 'log_date' => $log->log_date,
355 );
356 }
357 }
358
359 return $logs_data;
360 }
361
362 /**
363 * Setup the final data for the table
364 *
365 * @access public
366 * @since 1.0
367 * @uses Give_API_Request_Log_Table::get_columns()
368 * @uses WP_List_Table::get_sortable_columns()
369 * @uses Give_API_Request_Log_Table::get_pagenum()
370 * @uses Give_API_Request_Log_Table::get_logs()
371 * @uses Give_API_Request_Log_Table::get_log_count()
372 *
373 * @return void
374 */
375 public function prepare_items() {
376 $columns = $this->get_columns();
377 $hidden = array(); // No hidden columns
378 $sortable = $this->get_sortable_columns();
379 $this->_column_headers = array( $columns, $hidden, $sortable );
380 $this->items = $this->get_logs();
381 $total_items = Give()->logs->get_log_count( 0, 'api_request', $this->get_meta_query() );
382
383 $this->set_pagination_args(
384 array(
385 'total_items' => $total_items,
386 'per_page' => $this->per_page,
387 'total_pages' => ceil( $total_items / $this->per_page ),
388 )
389 );
390 }
391 }
392