PluginProbe ʕ •ᴥ•ʔ
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments / 4.6.0
SureCart – Ecommerce Made Easy For Selling Physical Products, Digital Downloads, Subscriptions, Donations, & Payments v4.6.0
4.6.2 4.6.1 4.6.0 4.5.1 4.5.0 4.4.2 4.4.1 4.4.0 4.3.3 4.3.2 4.3.1 4.3.0 4.2.3 4.2.2 4.2.1 1.0.3 1.0.4 1.0.5 1.0.6 1.1.0 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 1.1.9 1.10.0 1.10.1 1.10.2 1.10.3 1.10.4 1.11.0 1.11.1 1.11.2 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.7.0 1.7.1 1.7.2 1.8.0 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 2.0.0 2.0.1 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.12.0 2.13.0 2.14.0 2.14.1 2.15.0 2.15.1 2.16.0 2.16.1 2.16.2 2.16.3 2.17.0 2.17.1 2.17.2 2.18.0 2.19.0 2.19.2 2.19.3 2.19.4 2.2.0 2.2.1 2.20.0 2.20.1 2.20.2 2.20.3 2.20.4 2.20.5 2.20.6 2.21.0 2.22.0 2.22.1 2.23.0 2.24.0 2.25.0 2.25.1 2.25.2 2.26.0 2.27.0 2.27.1 2.28.0 2.29.0 2.29.1 2.29.2 2.29.3 2.29.4 2.3.0 2.3.1 2.30.0 2.31.0 2.31.1 2.31.2 2.31.3 2.4.0 2.4.1 2.4.2 2.4.3 2.4.4 2.40.0 2.40.1 2.5.0 2.5.1 2.5.2 2.6.0 2.6.1 2.6.2 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.8.2 2.8.3 2.8.4 2.9.0 3.0.0 3.0.0-RC1 3.0.0-RC2 3.0.0-beta1 3.0.0-beta2 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.1.0 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.10.0 3.10.1 3.11.0 3.12.0 3.13.0 3.13.1 3.13.2 3.13.3 3.13.4 3.14.0 3.15.0 3.15.1 3.15.2 3.15.3 3.15.4 3.15.5 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.16.5 3.16.6 3.16.7 3.16.8 3.17.0 3.17.1 3.17.2 3.17.3 3.17.4 3.17.5 3.17.6 3.18.0 3.19.0 3.19.1 3.19.2 3.2.0 3.2.1 3.2.2 3.20.0 3.20.1 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 trunk 4.1.0 0.2.19.1 4.1.1 1.0.0 4.2.0 1.0.1 1.0.2
surecart / app / src / Controllers / Admin / Tables / ListTable.php
surecart / app / src / Controllers / Admin / Tables Last commit date
HasModeFilter.php 1 year ago ListTable.php 2 weeks ago
ListTable.php
293 lines
1 <?php
2
3 namespace SureCart\Controllers\Admin\Tables;
4
5 use SureCart\Models\Integration;
6 use SureCart\Support\TimeDate;
7
8 // WP_List_Table is not loaded automatically so we need to load it in our application.
9 if ( ! class_exists( 'WP_List_Table' ) ) {
10 require_once ABSPATH . 'wp-admin/includes/class-wp-list-table.php';
11 }
12
13 /**
14 * Base list table class.
15 */
16 abstract class ListTable extends \WP_List_Table {
17 public $checkbox = true;
18
19 /**
20 * Show filters in extra tablenav top
21 *
22 * @param [type] $which
23 * @return void
24 */
25 protected function extra_tablenav( $which ) {
26 if ( 'top' === $which ) {
27 return $this->views();
28 }
29 }
30
31 /**
32 * Define which columns are hidden
33 *
34 * @return Array
35 */
36 public function get_hidden_columns() {
37 return array();
38 }
39
40 /**
41 * Sanitised `?page` query arg.
42 *
43 * @return string
44 */
45 protected function getCurrentPage(): string {
46 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
47 return ! empty( $_GET['page'] ) ? sanitize_key( wp_unslash( $_GET['page'] ) ) : '';
48 }
49
50 /**
51 * Override the parent columns method. Defines the columns to use in your listing table
52 *
53 * @return Array
54 */
55 public function get_columns() {
56 $current_page = $this->getCurrentPage();
57
58 /**
59 * Filters the columns displayed in the Coupons list table.
60 *
61 * @param string[] $coupon_columns An associative array of column headings.
62 */
63 return (array) apply_filters( "manage_{$current_page}_columns", array() );
64 }
65 /**
66 * Handles the default column output.
67 *
68 * @param WP_Post $item The current WP_Post object.
69 * @param string $column_name The current column name.
70 */
71 public function column_default( $item, $column_name ) {
72 $current_page = $this->getCurrentPage();
73 /**
74 * Fires for each custom column of any SureCart List Table.
75 *
76 * The dynamic portion of the hook name, `$current_page`, refers to the page name.
77 *
78 * Possible hook names include:
79 *
80 * - `manage_orders_custom_column`
81 * - `manage_products_custom_column`
82 *
83 * @param string $column_name The name of the column to display.
84 * @param mixed $item The current item's data object.
85 */
86 do_action( "manage_{$current_page}_custom_column", $column_name, $item );
87 }
88
89 /**
90 * Get the archive query status.
91 *
92 * @return boolean|null
93 */
94 public function getArchiveStatus( $default = 'active' ) {
95 $status = sanitize_text_field( wp_unslash( $_GET['status'] ?? $default ) );
96 $archived = false;
97 if ( 'archived' === $status ) {
98 $archived = true;
99 }
100 if ( 'all' === $status ) {
101 $archived = null;
102 }
103
104 return $archived;
105 }
106
107 /**
108 * Handle the date
109 *
110 * @param \SureCart\Models\Model $model Model.
111 *
112 * @return string
113 */
114 public function column_date( $model ) {
115 $created = sprintf(
116 '<time datetime="%1$s" title="%2$s">%3$s</time>',
117 esc_attr( $model->created_at ),
118 esc_html( $model->created_at_date_time ),
119 esc_html( TimeDate::humanTimeDiff( $model->created_at ) )
120 );
121 $updated = sprintf(
122 '%1$s <time datetime="%2$s" title="%3$s">%4$s</time>',
123 __( 'Updated', 'surecart' ),
124 esc_attr( $model->updated_at_date_time ),
125 esc_html( $model->updated_at_date_time ),
126 esc_html( TimeDate::humanTimeDiff( $model->updated_at ) )
127 );
128
129 return $created . '<br /><small style="opacity: 0.75">' . $updated . '</small>';
130 }
131
132 /**
133 * Handle the created column
134 *
135 * @param \SureCart\Models\Model $model Model.
136 *
137 * @return string
138 */
139 public function column_created( $model ) {
140 return esc_attr( $model->created_at_date_time );
141 }
142
143 /**
144 * The mode for the model.
145 *
146 * @param \SureCart\Models\Model $model Model.
147 *
148 * @return string
149 */
150 public function column_mode( $model ) {
151 return empty( $model->live_mode ) ? '<sc-tag type="warning">' . __( 'Test', 'surecart' ) . '</sc-tag>' : '';
152 }
153
154 /**
155 * Show an integrations list based on a product id.
156 *
157 * @param string $args The args.
158 *
159 * @return string
160 */
161 public function productIntegrationsList( $args ) {
162 // parse the args.
163 $args = wp_parse_args(
164 $args,
165 [
166 'product_id' => '',
167 'price_id' => '',
168 'variant_id' => '',
169 ]
170 );
171
172 // get the integration first by product id.
173 $integrations = Integration::where( 'model_id', $args['product_id'] );
174
175 $output = '';
176 $integrations = $integrations->group_by( 'integration_id' )->get();
177 if ( empty( $integrations ) || is_wp_error( $integrations ) ) {
178 return $output;
179 }
180
181 foreach ( $integrations as $integration ) {
182 $provider = (object) apply_filters( "surecart/integrations/providers/find/{$integration->provider}", [] );
183 $item = (object) apply_filters( "surecart/integrations/providers/{$integration->provider}/item", $integration->integration_id );
184 if ( $integration->price_id && $args['price_id'] && $integration->price_id !== $args['price_id'] ) {
185 continue;
186 }
187 if ( $integration->variant_id && $args['variant_id'] && $integration->variant_id !== $args['variant_id'] ) {
188 continue;
189 }
190 if ( ! empty( $item->label ) ) {
191 // Tooltip surfaces both the provider ("Zapier") and the item ("New order → Slack")
192 // so keyboard + screen-reader users aren't limited to the native `title` hover.
193 $tooltip_text = trim(
194 sprintf(
195 '%s%s%s',
196 ! empty( $provider->label ) ? $provider->label : '',
197 ! empty( $provider->label ) && ! empty( $item->label ) ? '' : '',
198 $item->label ?? ''
199 )
200 );
201 ob_start();
202 ?>
203 <sc-tooltip
204 text="<?php echo esc_attr( $tooltip_text ); ?>"
205 type="text"
206 style="display: inline-block; cursor: help; margin: 2px;"
207 >
208 <?php if ( ! empty( $provider->logo ) ) : ?>
209 <img
210 src="<?php echo esc_url( $provider->logo ); ?>"
211 alt="<?php echo esc_attr( $tooltip_text ); ?>"
212 style="width: 20px; height: 20px; display: inline-block; vertical-align: middle;"
213 />
214 <?php else : ?>
215 <span aria-label="<?php echo esc_attr( $tooltip_text ); ?>">
216 <?php echo wp_kses_post( $item->label ); ?>
217 </span>
218 <?php endif; ?>
219 </sc-tooltip>
220 <?php
221 $output .= ob_get_clean();
222 }
223 }
224 return $output;
225 }
226
227 /**
228 * Get the search query from the url args.
229 *
230 * @return string
231 */
232 public function get_search_query() {
233 $search = urldecode( $_GET['s'] ?? '' );
234 return str_replace( [ "\r", "\n" ], '', $search );
235 }
236
237 /**
238 * Get the current orderby value.
239 *
240 * @return string
241 */
242 protected function get_orderby(): string {
243 return isset( $_GET['orderby'] ) ? sanitize_text_field( wp_unslash( $_GET['orderby'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
244 }
245
246 /**
247 * Get the current order value.
248 *
249 * @return string
250 */
251 protected function get_order(): string {
252 $order = isset( $_GET['order'] ) ? sanitize_text_field( wp_unslash( $_GET['order'] ) ) : 'desc'; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
253 return in_array( strtolower( $order ), [ 'asc', 'desc' ], true ) ? strtolower( $order ) : 'desc';
254 }
255
256 /**
257 * Display a search form
258 *
259 * @param string $text The 'submit' button label.
260 * @param string $input_id ID attribute value for the search input field.
261 *
262 * @return void
263 */
264 public function search_form( $text, $input_id ) {
265 ?>
266 <form id="posts-filter" method="get">
267 <?php if ( isset( $_GET['page'] ) ) : ?>
268 <input type="hidden" name="page" value="<?php echo esc_attr( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>">
269 <?php endif; ?>
270 <?php if ( isset( $_GET['status'] ) ) : ?>
271 <input type="hidden" name="status" value="<?php echo esc_attr( $_GET['status'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>">
272 <?php endif; ?>
273 <?php if ( isset( $_GET['live_mode'] ) ) : ?>
274 <input type="hidden" name="live_mode" value="<?php echo esc_attr( $_GET['live_mode'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended ?>">
275 <?php endif; ?>
276 <?php $this->search_box( $text, $input_id ); ?>
277 </form>
278 <?php
279 }
280
281 /**
282 * Get the sort map.
283 *
284 * @return array
285 */
286 public function get_sort_map(): array {
287 return array(
288 'created_at' => 'created_at',
289 'updated_at' => 'updated_at',
290 );
291 }
292 }
293