PluginProbe
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) / 1.8.11.3
Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) v1.8.11.3
1.8.13.1 1.8.13 1.8.12.3 1.8.12.2 1.8.12.1 1.8.12 1.8.11.3 1.8.11.2 1.8.11.1 1.8.11 1.6.6 1.6.60 1.6.7 1.6.8 1.6.9 1.7.0 1.7.0.1 1.7.0.11 1.7.0.12 1.7.0.14 1.7.0.2 1.7.0.3 1.7.0.5 1.7.0.6 1.7.0.7 All 212 releases
charitable / includes / logger / class-charitable-log-list-table.php

class-charitable-log-list-table.php in Charitable – Donation & Fundraising Platform (Donation Forms, Recurring Donations & Fundraising Campaigns) 1.8.11.3, at includes/logger/class-charitable-log-list-table.php

291 lines 8.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Charitable Log List Table.
4 *
5 * @package Charitable/Classes/Charitable_Log_List_Table
6 * @author David Bisset
7 * @copyright Copyright (c) 2023, WP Charitable LLC
8 * @license http://opensource.org/licenses/gpl-2.0.php GNU Public License
9 * @since 1.8.11
10 */
11
12 if ( ! defined( 'ABSPATH' ) ) {
13 exit;
14 }
15
16 if ( ! class_exists( 'WP_List_Table' ) ) {
17 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
18 }
19
20 if ( ! class_exists( 'Charitable_Log_List_Table' ) ) :
21
22 /**
23 * Charitable_Log_List_Table
24 *
25 * @since 1.8.11
26 */
27 class Charitable_Log_List_Table extends WP_List_Table {
28
29 /**
30 * Total number of records.
31 *
32 * @since 1.8.11
33 *
34 * @var int
35 */
36 private $total_items = 0;
37
38 /**
39 * Constructor.
40 *
41 * @since 1.8.11
42 */
43 public function __construct() {
44 parent::__construct(
45 array(
46 'plural' => esc_html__( 'Logs', 'charitable' ),
47 'singular' => esc_html__( 'Log', 'charitable' ),
48 'ajax' => false,
49 )
50 );
51 }
52
53 /**
54 * Get table columns.
55 *
56 * @since 1.8.11
57 *
58 * @return array
59 */
60 public function get_columns() {
61 return array(
62 'title' => __( 'Title', 'charitable' ),
63 'message' => __( 'Message', 'charitable' ),
64 'types' => __( 'Types', 'charitable' ),
65 'level' => __( 'Level', 'charitable' ),
66 'source' => __( 'Source', 'charitable' ),
67 'date' => __( 'Date', 'charitable' ),
68 );
69 }
70
71 /**
72 * Get sortable columns.
73 *
74 * @since 1.8.11
75 *
76 * @return array
77 */
78 public function get_sortable_columns() {
79 return array(
80 'title' => array( 'title', false ),
81 'level' => array( 'level', false ),
82 'source' => array( 'source', false ),
83 'date' => array( 'create_at', true ),
84 );
85 }
86
87 /**
88 * Prepare items for display.
89 *
90 * @since 1.8.11
91 */
92 public function prepare_items() {
93 $per_page = 20;
94 $page = $this->get_pagenum();
95 $offset = ( $page - 1 ) * $per_page;
96
97 $args = array(
98 'limit' => $per_page,
99 'offset' => $offset,
100 'search' => isset( $_GET['s'] ) ? sanitize_text_field( wp_unslash( $_GET['s'] ) ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
101 'type' => isset( $_GET['log_type'] ) ? sanitize_key( $_GET['log_type'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
102 'level' => isset( $_GET['log_level'] ) ? sanitize_key( $_GET['log_level'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
103 'source' => isset( $_GET['log_source'] ) ? sanitize_key( $_GET['log_source'] ) : '', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
104 'orderby' => isset( $_GET['orderby'] ) ? sanitize_key( $_GET['orderby'] ) : 'id', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
105 'order' => isset( $_GET['order'] ) ? sanitize_key( $_GET['order'] ) : 'DESC', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
106 );
107
108 $query = Charitable_Log::get_instance()->get_query();
109 $result = $query->get( $args );
110
111 $this->items = iterator_to_array( $result['records'] );
112 $this->total_items = $result['total'];
113
114 // Explicitly set column headers — this list table renders on the
115 // Tools page which doesn't have its own WP_Screen, so the
116 // default manage_{screen}_columns filter returns nothing.
117 $this->_column_headers = array(
118 $this->get_columns(),
119 array(),
120 $this->get_sortable_columns(),
121 $this->get_primary_column_name(),
122 );
123
124 $this->set_pagination_args(
125 array(
126 'total_items' => $this->total_items,
127 'per_page' => $per_page,
128 'total_pages' => ceil( $this->total_items / $per_page ),
129 )
130 );
131 }
132
133 /**
134 * Render the title column.
135 *
136 * @since 1.8.11
137 *
138 * @param Charitable_Log_Record $item Current record.
139 * @return string
140 */
141 public function column_title( $item ) {
142 return sprintf(
143 '<a href="#" class="js-charitable-log-link" data-record-id="%d">%s</a>',
144 esc_attr( $item->id ),
145 esc_html( $item->title )
146 );
147 }
148
149 /**
150 * Render the message column (truncated).
151 *
152 * @since 1.8.11
153 *
154 * @param Charitable_Log_Record $item Current record.
155 * @return string
156 */
157 public function column_message( $item ) {
158 $message = wp_strip_all_tags( $item->message );
159
160 if ( strlen( $message ) > 97 ) {
161 $message = substr( $message, 0, 97 ) . '...';
162 }
163
164 return esc_html( $message );
165 }
166
167 /**
168 * Render the types column.
169 *
170 * @since 1.8.11
171 *
172 * @param Charitable_Log_Record $item Current record.
173 * @return string
174 */
175 public function column_types( $item ) {
176 $labels = $item->get_types( 'label' );
177 return esc_html( implode( ', ', $labels ) );
178 }
179
180 /**
181 * Render the level column with color badge.
182 *
183 * @since 1.8.11
184 *
185 * @param Charitable_Log_Record $item Current record.
186 * @return string
187 */
188 public function column_level( $item ) {
189 $levels = Charitable_Log::get_log_levels();
190 $label = isset( $levels[ $item->level ] ) ? $levels[ $item->level ] : $item->level;
191
192 return sprintf(
193 '<span class="charitable-log-level charitable-log-level-%s">%s</span>',
194 esc_attr( $item->level ),
195 esc_html( $label )
196 );
197 }
198
199 /**
200 * Render the source column.
201 *
202 * @since 1.8.11
203 *
204 * @param Charitable_Log_Record $item Current record.
205 * @return string
206 */
207 public function column_source( $item ) {
208 $sources = Charitable_Log::get_sources();
209 return esc_html( isset( $sources[ $item->source ] ) ? $sources[ $item->source ] : $item->source );
210 }
211
212 /**
213 * Render the date column.
214 *
215 * @since 1.8.11
216 *
217 * @param Charitable_Log_Record $item Current record.
218 * @return string
219 */
220 public function column_date( $item ) {
221 return esc_html( $item->get_date( 'short' ) );
222 }
223
224 /**
225 * Default column handler.
226 *
227 * @since 1.8.11
228 *
229 * @param Charitable_Log_Record $item Current record.
230 * @param string $column_name Column name.
231 * @return string
232 */
233 public function column_default( $item, $column_name ) {
234 return isset( $item->$column_name ) ? esc_html( $item->$column_name ) : '';
235 }
236
237 /**
238 * Render extra controls above/below the table (filter dropdowns).
239 *
240 * @since 1.8.11
241 *
242 * @param string $which 'top' or 'bottom'.
243 */
244 public function extra_tablenav( $which ) {
245 if ( 'top' !== $which ) {
246 return;
247 }
248
249 $current_type = isset( $_GET['log_type'] ) ? sanitize_key( $_GET['log_type'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
250 $current_level = isset( $_GET['log_level'] ) ? sanitize_key( $_GET['log_level'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
251 $current_source = isset( $_GET['log_source'] ) ? sanitize_key( $_GET['log_source'] ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
252 ?>
253 <div class="alignleft actions charitable-log-filters">
254 <select name="log_type" id="charitable-log-type-filter">
255 <option value=""><?php esc_html_e( 'All Types', 'charitable' ); ?></option>
256 <?php foreach ( Charitable_Log::get_log_types() as $key => $label ) : ?>
257 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $current_type, $key ); ?>><?php echo esc_html( $label ); ?></option>
258 <?php endforeach; ?>
259 </select>
260
261 <select name="log_level" id="charitable-log-level-filter">
262 <option value=""><?php esc_html_e( 'All Levels', 'charitable' ); ?></option>
263 <?php foreach ( Charitable_Log::get_log_levels() as $key => $label ) : ?>
264 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $current_level, $key ); ?>><?php echo esc_html( $label ); ?></option>
265 <?php endforeach; ?>
266 </select>
267
268 <select name="log_source" id="charitable-log-source-filter">
269 <option value=""><?php esc_html_e( 'All Sources', 'charitable' ); ?></option>
270 <?php foreach ( Charitable_Log::get_sources() as $key => $label ) : ?>
271 <option value="<?php echo esc_attr( $key ); ?>" <?php selected( $current_source, $key ); ?>><?php echo esc_html( $label ); ?></option>
272 <?php endforeach; ?>
273 </select>
274
275 <?php submit_button( __( 'Filter', 'charitable' ), '', 'filter_action', false ); ?>
276 </div>
277 <?php
278 }
279
280 /**
281 * Message to display when there are no items.
282 *
283 * @since 1.8.11
284 */
285 public function no_items() {
286 esc_html_e( 'No log entries found.', 'charitable' );
287 }
288 }
289
290 endif;
291