PluginProbe
Vision – Interactive Image Map with Hotspots Builder / 1.9.2
Vision – Interactive Image Map with Hotspots Builder v1.9.2
1.12.2 1.12.1 1.12.0 1.11.0 1.6.0 1.6.1 1.6.2 1.7.1 1.7.2 1.7.3 1.8.1 1.8.2 1.8.3 1.8.4 1.8.5 1.8.6 1.9.0 1.9.1 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 All 33 releases
vision / includes / list-table-items.php

list-table-items.php in Vision – Interactive Image Map with Hotspots Builder 1.9.2, at includes/list-table-items.php

647 lines 25.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 defined('ABSPATH') || exit;
3
4 if(!class_exists('WP_List_Table')) {
5 require_once(ABSPATH . 'wp-admin/includes/class-wp-list-table.php');
6 }
7
8 class Vision_List_Table_Items extends WP_List_Table {
9 private $count_all = 0;
10 private $count_mine = 0;
11 private $count_trash = 0;
12 private $url_preview_base = '';
13
14 function __construct() {
15 parent::__construct([
16 'singular'=> 'vision_item',
17 'plural' => 'vision_items',
18 'ajax' => false
19 ]);
20
21 $this->url_preview_base = '/vision/map/';
22 }
23
24 function handle_row_actions($post, $column_name, $primary) {
25 return '';
26 }
27
28 function joinPaths() {
29 $paths = [];
30
31 foreach(func_get_args() as $arg) {
32 if($arg !== '') {
33 $paths[] = $arg;
34 }
35 }
36
37 return preg_replace('#/+#','/',join('/', $paths));
38 }
39
40 function filesystem_method() {
41 return 'direct';
42 }
43
44 function request_filesystem_credentials() {
45 return true;
46 }
47
48 function getFileSystem() {
49 global $wp_filesystem;
50 $result = true;
51
52 if(!$wp_filesystem) {
53 require_once(ABSPATH . '/wp-admin/includes/file.php');
54
55 add_filter('filesystem_method', [$this, 'filesystem_method']);
56 add_filter('request_filesystem_credentials', [$this, 'request_filesystem_credentials']);
57
58 $credentials = request_filesystem_credentials(site_url(), '', true, false, null);
59
60 $result = WP_Filesystem($credentials);
61
62 remove_filter('filesystem_method', [$this, 'filesystem_method']);
63 remove_filter('request_filesystem_credentials', [$this, 'request_filesystem_credentials']);
64 }
65
66 if($result)
67 return $wp_filesystem;
68 return null;
69 }
70
71 function column_default($item, $column_name){
72 switch($column_name){
73 case 'title':
74 case 'active':
75 case 'shortcode':
76 case 'author':
77 case 'editor':
78 case 'created':
79 case 'modified':
80 case 'id':
81 return $item[$column_name];
82 }
83 }
84
85 function column_cb($item) {
86 return sprintf(
87 '<input type="checkbox" name="%1$s[]" value="%2$s">',
88 esc_attr($this->_args['singular']), // let's simply repurpose the table's singular label
89 esc_attr($item['id']) // the value of the checkbox should be the record's ID
90 );
91 }
92
93 function column_title($item) {
94 $page = sanitize_key(filter_input(INPUT_GET, 'page', FILTER_DEFAULT));
95 $item_status = sanitize_key(filter_input(INPUT_GET, 'item_status', FILTER_DEFAULT));
96
97 if(current_user_can('manage_options') || get_current_user_id()==$item['author']) {
98 $actions = [];
99
100 switch($item_status) {
101 case 'trash': {
102 $args = [
103 'page' => $page,
104 'item_status' => $item_status,
105 'action' => 'restore',
106 'id' => $item['id']
107 ];
108 $url = add_query_arg($args, 'admin.php');
109
110 $actions['restore'] = sprintf(
111 '<a href="%1$s">%2$s</a>',
112 esc_url(wp_nonce_url($url, 'restore_' . $item['id'])),
113 esc_html__('Restore', 'vision')
114 );
115
116 $args = [
117 'page' => $page,
118 'item_status' => $item_status,
119 'action' => 'delete',
120 'id' => $item['id']
121 ];
122 $url = add_query_arg($args, 'admin.php');
123
124 $actions['delete'] = sprintf(
125 '<a href="%1$s">%2$s</a>',
126 esc_url(wp_nonce_url($url, 'delete_' . $item['id'])),
127 esc_html__('Delete Permanently', 'vision')
128 );
129 } break;
130 default: {
131 $args = [
132 'page' => 'vision_item',
133 'item_status' => $item_status,
134 'id' => $item['id']
135 ];
136 $url = add_query_arg($args, 'admin.php');
137
138 $actions['edit'] = sprintf(
139 '<a href="%1$s">%2$s</a>',
140 esc_url($url),
141 esc_html__('Edit', 'vision')
142 );
143
144 $args = [
145 'page' => $page,
146 'item_status' => $item_status,
147 'action' => 'copy',
148 'id' => $item['id']
149 ];
150 $url = add_query_arg($args, 'admin.php');
151
152 $actions['copy'] = sprintf(
153 '<a href="%1$s">%2$s</a>',
154 esc_url(wp_nonce_url($url, 'copy_' . $item['id'])),
155 esc_html__('Duplicate', 'vision')
156 );
157
158 $args = [
159 'page' => $page,
160 'item_status' => $item_status,
161 'action' => 'trash',
162 'id' => $item['id']
163 ];
164 $url = add_query_arg($args, 'admin.php');
165
166 $actions['trash'] = sprintf(
167 '<a href="%1$s">%2$s</a>',
168 esc_url(wp_nonce_url($url, 'trash_' . $item['id'])),
169 esc_html__('Move to Trash', 'vision')
170 );
171
172 $args = [
173 'preview' => true
174 ];
175 $url = add_query_arg($args, $this->url_preview_base . $item['id']);
176
177 $actions['view'] = sprintf(
178 '<a href="%1$s" target="_blank">%2$s</a>',
179 esc_url($url),
180 esc_html__('Preview', 'vision')
181 );
182 } break;
183 }
184
185 return sprintf('<a href="?page=%1$s&id=%2$s" class="row-title">%3$s</a> %4$s',
186 'vision_item',
187 $item['id'],
188 $item['title'],
189 $this->row_actions($actions)
190 );
191 }
192
193 return sprintf('<strong>%1$s</strong>', $item['title']);
194 }
195
196 function column_active($item) {
197 if(current_user_can('manage_options') || get_current_user_id()==$item['author']) {
198 return sprintf(
199 '<div class="vision-toggle vision-%1$s" data-id="%2$s">&nbsp;</div>',
200 ($item['active'] ? 'checked' : 'unchecked'),
201 $item['id']
202 );
203 } else {
204 return sprintf(
205 '<div class="vision-toggle vision-readonly vision-%1$s" data-id="%2$s">&nbsp;</div>',
206 ($item['active'] ? 'checked' : 'unchecked'),
207 $item['id']
208 );
209 }
210 }
211
212 function column_shortcode($item) {
213 return sprintf('<code>[vision id="%1$s"]</code>', $item['id']);
214 }
215
216 function column_author($item) {
217 $page = sanitize_key(filter_input(INPUT_GET, 'page', FILTER_DEFAULT));
218 $args = [
219 'page' => $page,
220 'author' => $item['author']
221 ];
222 $url = add_query_arg($args, 'admin.php');
223
224 return sprintf(
225 '<a href="%1$s">%2$s</a>',
226 esc_url( $url ),
227 get_the_author_meta('display_name', $item['author'])
228 );
229 }
230
231 function column_editor($item) {
232 $page = sanitize_key(filter_input(INPUT_GET, 'page', FILTER_DEFAULT));
233 $args = [
234 'page' => $page,
235 'editor' => $item['editor']
236 ];
237 $url = add_query_arg($args, 'admin.php');
238
239 return sprintf(
240 '<a href="%1$s">%2$s</a>',
241 esc_url( $url ),
242 get_the_author_meta('display_name', $item['editor'])
243 );
244 }
245
246 function column_created( $item ) {
247 $m_time = mysql2date('Y/m/d g:i:s a', $item['created']);
248 $h_time = mysql2date('Y/m/d', $item['created']);
249
250 return sprintf('<abbr title="%1$s">%2$s</abbr>', esc_attr($m_time), esc_html($h_time));
251 }
252
253 function column_modified( $item ) {
254 $m_time = mysql2date('Y/m/d g:i:s a', $item['modified']);
255 $h_time = mysql2date('Y/m/d', $item['modified']);
256
257 return sprintf('<abbr title="%1$s">%2$s</abbr>', esc_attr($m_time), esc_html($h_time));
258 }
259
260 function get_views() {
261 $page = sanitize_key(filter_input(INPUT_GET, 'page', FILTER_DEFAULT));
262 $item_status = sanitize_key(filter_input(INPUT_GET, 'item_status', FILTER_DEFAULT));
263
264 $args_all = ['page' => $page];
265 $args_mine = ['page' => $page, 'item_status' => 'mine'];
266 $args_trash = ['page' => $page, 'item_status' => 'trash'];
267
268 $url_all = add_query_arg($args_all, 'admin.php');
269 $url_mine = add_query_arg($args_mine, 'admin.php');
270 $url_trash = add_query_arg($args_trash, 'admin.php');
271
272 $status_links = [
273 'all' => sprintf('<a href="%1$s" %2$s>%3$s <span class="count">(%4$d)</span></a>', esc_url($url_all), ($item_status ? '' : 'class="current"'), esc_html__('All','vision'), $this->count_all),
274 'mine' => sprintf('<a href="%1$s" %2$s>%3$s <span class="count">(%4$d)</span></a>', esc_url($url_mine), ($item_status == 'mine' ? 'class="current"' : ''), esc_html__('Mine','vision'), $this->count_mine),
275 'trash' => sprintf('<a href="%1$s" %2$s>%3$s <span class="count">(%4$d)</span></a>', esc_url($url_trash), ($item_status == 'trash' ? 'class="current"' : ''), esc_html__('Trash','vision'), $this->count_trash)
276 ];
277
278 return $status_links;
279 }
280
281 function get_columns() {
282 $columns = [
283 'cb' => '<input type="checkbox">',
284 'title' => esc_html__('Title', 'vision'),
285 'active' => esc_html__('Active', 'vision'),
286 'shortcode' => esc_html__('Shortcode', 'vision'),
287 'author' => esc_html__('Author', 'vision'),
288 'editor' => esc_html__('Editor', 'vision'),
289 'created' => esc_html__('Created', 'vision'),
290 'modified' => esc_html__('Modified', 'vision')
291 ];
292 return $columns;
293 }
294
295 function get_sortable_columns() {
296 $columns = [
297 'title' => ['title', false],
298 'active' => ['active', false],
299 'author' => ['author', false],
300 'editor' => ['editor', false],
301 'created' => ['created', false],
302 'modified' => ['modified', false]
303 ];
304 return $columns;
305 }
306
307 function get_bulk_actions() {
308 $item_status = sanitize_key(filter_input(INPUT_GET, 'item_status', FILTER_DEFAULT));
309 $actions = [];
310
311 switch($item_status) {
312 case 'trash': {
313 $actions = [
314 'restore' => esc_html__('Restore', 'vision'),
315 'delete' => esc_html__('Delete Permanently', 'vision')
316 ];
317 } break;
318 default: {
319 $actions = [
320 'copy' => esc_html__('Duplicate', 'vision'),
321 'trash' => esc_html__('Move to Trash', 'vision')
322 ];
323 } break;
324 }
325 return $actions;
326 }
327
328 function process_trash_action($id, $flag) {
329 global $wpdb;
330 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
331 $author = get_current_user_id();
332
333 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
334 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%d", $id);
335 $item = $wpdb->get_row($sql, OBJECT);
336 // phpcs:enable
337
338 if($item && (current_user_can('manage_options') || $author==$item->author)) {
339 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
340 $wpdb->update($table, ['deleted' => $flag], ['id' => $id]);
341 }
342 }
343
344 function process_copy_action($id) {
345 global $wpdb;
346 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
347 $author = get_current_user_id();
348
349 if( VISION_PLUGIN_PLAN == 'lite' ) {
350 // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
351 $count = $wpdb->get_var("SELECT COUNT(*) FROM {$table}");
352
353 if ($count >= 3) {
354 echo '<div class="notice notice-error is-dismissible">';
355 echo '<p>Vision: ' . esc_html__('You can create only 3 maps. If you need more, upgrade to the pro version.', 'vision') . '</p>';
356 echo '</div>';
357 return;
358 }
359 }
360
361 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
362 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%d AND NOT deleted", $id);
363 $item = $wpdb->get_row($sql, OBJECT);
364 // phpcs:enable
365
366 if($item && (current_user_can('manage_options') || $author==$item->author)) {
367 $itemData = unserialize($item->data);
368 $itemData->slug = sanitize_title(($itemData->slug ? $itemData->slug : $itemData->title));
369 $itemData->title = esc_html__('[Duplicate] ', 'vision') . $itemData->title;
370 $itemConfig = unserialize($item->config);
371
372 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
373 $result = $wpdb->insert(
374 $table,
375 [
376 'title' => $itemData->title,
377 'slug' => $itemData->slug,
378 'active' => $itemData->active,
379 'data' => serialize($itemData),
380 'config' => serialize($itemConfig),
381 'author' => $author,
382 'editor' => $author,
383 'created' => current_time('mysql', 1),
384 'modified' => current_time('mysql', 1)
385 ]
386 );
387
388 // [filemanager] create an external file
389 if($result) {
390 if(wp_is_writable(VISION_PLUGIN_UPLOAD_DIR)) {
391 $dir_src_root = $this->joinPaths(VISION_PLUGIN_UPLOAD_DIR, $id);
392 $dir_dst_root = $this->joinPaths(VISION_PLUGIN_UPLOAD_DIR, $wpdb->insert_id);
393 $wp_filesystem = $this->getFileSystem();
394
395 if($wp_filesystem) {
396 if(!$wp_filesystem->is_dir($dir_dst_root)) {
397 $wp_filesystem->mkdir($dir_dst_root);
398 }
399 copy_dir($dir_src_root, $dir_dst_root);
400 }
401 }
402 }
403 }
404 }
405
406 function process_delete_action($id) {
407 global $wpdb;
408 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
409 $author = get_current_user_id();
410
411 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
412 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE id=%d AND deleted", $id);
413 $item = $wpdb->get_row($sql, OBJECT);
414 // phpcs:enable
415
416 if($item && (current_user_can('manage_options') || $author==$item->author) ) {
417 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
418 $result = $wpdb->delete($table, ['id' => $id], ['%d']);
419
420 // [filemanager] delete file
421 if($result) {
422 if (wp_is_writable(VISION_PLUGIN_UPLOAD_DIR)) {
423 $dir_root = $this->joinPaths(VISION_PLUGIN_UPLOAD_DIR, $id);
424 $wp_filesystem = $this->getFileSystem();
425 if ($wp_filesystem) {
426 if ($wp_filesystem->is_dir($dir_root)) {
427 $wp_filesystem->rmdir($dir_root, true);
428 }
429 }
430 }
431 }
432 }
433 }
434
435 function process_actions() {
436 switch($this->current_action()) {
437 case 'trash': {
438 if(isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) {
439 $nonce = sanitize_key(filter_input(INPUT_POST, '_wpnonce', FILTER_DEFAULT));
440 $nonce_key = 'bulk-' . $this->_args['plural'];
441
442 if(wp_verify_nonce($nonce, $nonce_key)) {
443 $items = filter_input(INPUT_POST, $this->_args['singular'], FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY);
444
445 foreach($items as $id) {
446 $this->process_trash_action($id, true);
447 }
448 }
449 } else if(isset($_GET['_wpnonce']) && !empty($_GET['_wpnonce'])) {
450 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
451 $nonce = sanitize_key(filter_input(INPUT_GET, '_wpnonce', FILTER_DEFAULT));
452 $nonce_key = 'trash_' . $id;
453
454 if(wp_verify_nonce($nonce, $nonce_key)) {
455 $this->process_trash_action($id, true);
456 }
457 }
458 } break;
459 case 'restore': {
460 if(isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) {
461 $nonce = sanitize_key(filter_input(INPUT_POST, '_wpnonce', FILTER_DEFAULT));
462 $nonce_key = 'bulk-' . $this->_args['plural'];
463 if(wp_verify_nonce($nonce, $nonce_key)) {
464 $items = filter_input(INPUT_POST, $this->_args['singular'], FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY);
465
466 foreach($items as $id) {
467 $this->process_trash_action($id, false);
468 }
469 }
470 } else if(isset($_GET['_wpnonce']) && !empty($_GET['_wpnonce'])) {
471 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
472 $nonce = sanitize_key(filter_input(INPUT_GET, '_wpnonce', FILTER_DEFAULT));
473 $nonce_key = 'restore_' . $id;
474
475 if(wp_verify_nonce($nonce, $nonce_key)) {
476 $this->process_trash_action($id, false);
477 }
478 }
479 } break;
480 case 'copy': {
481 if(isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) {
482 $nonce = sanitize_key(filter_input(INPUT_POST, '_wpnonce', FILTER_DEFAULT));
483 $nonce_key = 'bulk-' . $this->_args['plural'];
484 if(wp_verify_nonce($nonce, $nonce_key)) {
485 $items = filter_input(INPUT_POST, $this->_args['singular'], FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY);
486
487 foreach($items as $id) {
488 $this->process_copy_action($id);
489 }
490 }
491 } else if(isset($_GET['_wpnonce']) && !empty($_GET['_wpnonce'])) {
492 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
493 $nonce = sanitize_key(filter_input(INPUT_GET, '_wpnonce', FILTER_DEFAULT));
494 $nonce_key = 'copy_' . $id;
495
496 if(wp_verify_nonce($nonce, $nonce_key)) {
497 $this->process_copy_action($id);
498 }
499 }
500 } break;
501 case 'delete': {
502 if(isset($_POST['_wpnonce']) && !empty($_POST['_wpnonce'])) {
503 $nonce = sanitize_key(filter_input(INPUT_POST, '_wpnonce', FILTER_DEFAULT));
504 $nonce_key = 'bulk-' . $this->_args['plural'];
505 if(wp_verify_nonce($nonce, $nonce_key)) {
506 $items = filter_input(INPUT_POST, $this->_args['singular'], FILTER_SANITIZE_NUMBER_INT, FILTER_REQUIRE_ARRAY);
507
508 foreach($items as $id) {
509 $this->process_delete_action($id);
510 }
511 }
512 } else if(isset($_GET['_wpnonce']) && !empty($_GET['_wpnonce'])) {
513 $id = filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
514 $nonce = sanitize_key(filter_input(INPUT_GET, '_wpnonce', FILTER_DEFAULT));
515 $nonce_key = 'delete_' . $id;
516
517 if(wp_verify_nonce($nonce, $nonce_key)) {
518 $this->process_delete_action($id);
519 }
520 }
521 } break;
522 }
523 }
524
525 function prepare_items() {
526 $this->process_actions();
527
528 $columns = $this->get_columns();
529 $sortable = $this->get_sortable_columns();
530 $hidden = [];
531
532 $itemsPerPage = 25;
533 $currentPage = ($this->get_pagenum()-1) * $itemsPerPage;
534
535 $this->_column_headers = [$columns, $hidden, $sortable];
536
537 global $wpdb;
538 $table = $wpdb->prefix . VISION_PLUGIN_NAME;
539
540 $item_status = sanitize_key(filter_input(INPUT_GET, 'item_status', FILTER_DEFAULT));
541
542 // phpcs:disable WordPress.Security.NonceVerification.Recommended, WordPress.Security.NonceVerification.Missing
543 $orderby = (isset($_GET['orderby']) ? strtolower(sanitize_key(filter_input(INPUT_GET, 'orderby', FILTER_DEFAULT))) : 'id');
544 $order = (isset($_GET['order']) ? strtolower(sanitize_key(filter_input(INPUT_GET, 'order', FILTER_DEFAULT))) : 'desc');
545 $author = (isset($_GET['author']) ? filter_input(INPUT_GET, 'author', FILTER_SANITIZE_NUMBER_INT ) : NULL);
546 $editor = (isset($_GET['editor']) ? filter_input(INPUT_GET, 'editor', FILTER_SANITIZE_NUMBER_INT ) : NULL);
547 $search = (isset($_POST['s']) ? '%' . $wpdb->esc_like(sanitize_text_field(filter_input(INPUT_POST, 's', FILTER_DEFAULT))) . '%' : '%');
548 // phpcs:enable
549
550 $current_user = get_current_user_id();
551
552 // check user input
553 $sortable_columns = array_keys($sortable);
554 $orderby = in_array($orderby, $sortable_columns) ? $orderby : 'id';
555
556 $order_values = ['asc', 'desc'];
557 $order = in_array($order, $order_values) ? $order : 'desc';
558
559 $sql = '';
560 $sql_total_items = '';
561 $total_items = 0;
562
563 // database operations
564 if(current_user_can('manage_options')) { // by default, the manage_options permission is only given to 'Super Users' and 'Administrators'
565 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
566 $this->count_all = $wpdb->query("SELECT id FROM {$table} WHERE NOT deleted");
567 $this->count_mine = $wpdb->query($wpdb->prepare("SELECT id FROM {$table} WHERE NOT deleted AND author=%s", $current_user));
568 $this->count_trash = $wpdb->query("SELECT id FROM {$table} WHERE deleted");
569 // phpcs:enable
570
571 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.PreparedSQLPlaceholders.UnquotedComplexPlaceholder
572 switch($item_status) {
573 case 'trash': {
574 if($author) {
575 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $author, $search, $orderby, $order, $currentPage, $itemsPerPage);
576 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND deleted AND IFNULL(title,'') LIKE %s", $author, $search);
577 } else if($editor) {
578 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE editor=%s AND deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $editor, $search, $orderby, $order, $currentPage, $itemsPerPage);
579 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE editor=%s AND deleted AND IFNULL(title,'') LIKE %s", $editor, $search);
580 } else {
581 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $search, $orderby, $order, $currentPage, $itemsPerPage);
582 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE deleted AND IFNULL(title,'') LIKE %s", $search);
583 }
584 } break;
585 case 'mine': {
586 if($author) {
587 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $current_user, $search, $orderby, $order, $currentPage, $itemsPerPage);
588 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $current_user, $search);
589 } else if($editor) {
590 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND editor=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $current_user, $editor, $search, $orderby, $order, $currentPage, $itemsPerPage);
591 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND editor=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $current_user, $editor, $search);
592 } else {
593 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $current_user, $search, $orderby, $order, $currentPage, $itemsPerPage);
594 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $current_user, $search);
595 }
596 } break;
597 default: {
598 if($author) {
599 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $author, $search, $orderby, $order, $currentPage, $itemsPerPage);
600 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $author, $search);
601 } else if($editor) {
602 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE editor=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $editor, $search, $orderby, $order, $currentPage, $itemsPerPage);
603 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE editor=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $editor, $search);
604 } else {
605 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %1s %1s LIMIT %d, %d", $search, $orderby, $order, $currentPage, $itemsPerPage);
606 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE NOT deleted AND IFNULL(title,'') LIKE %s", $search);
607 }
608 } break;
609 }
610 // phpcs:enable
611 } else { // the current user view
612 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
613 $this->count_all = $wpdb->query($wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted", $current_user));
614 $this->count_mine = $wpdb->query($wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted", $current_user));
615 $this->count_trash = $wpdb->query($wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND deleted", $current_user));
616 // phpcs:enable
617
618 // phpcs:disable WordPress.DB.PreparedSQL.InterpolatedNotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
619 switch($item_status) {
620 case 'trash': {
621 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND deleted AND IFNULL(title,'') LIKE %s ORDER BY %s %s LIMIT %d, %d", $current_user, $search, $orderby, $order, $currentPage, $itemsPerPage);
622 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND deleted AND IFNULL(title,'') LIKE %s", $current_user, $search);
623 } break;
624 case 'mine': {
625 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %s %s LIMIT %d, %d", $current_user, $search, $orderby, $order, $currentPage, $itemsPerPage);
626 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $current_user, $search);
627 } break;
628 default: {
629 $sql = $wpdb->prepare("SELECT * FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s ORDER BY %s %s LIMIT %d, %d", $current_user, $search, $orderby, $order, $currentPage, $itemsPerPage);
630 $sql_total_items = $wpdb->prepare("SELECT id FROM {$table} WHERE author=%s AND NOT deleted AND IFNULL(title,'') LIKE %s", $current_user, $search);
631 } break;
632 }
633 // phpcs:enable
634 }
635
636 // phpcs:disable WordPress.DB.PreparedSQL.NotPrepared, WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
637 $this->items = $wpdb->get_results($sql, 'ARRAY_A');
638 $total_items = $wpdb->query($sql_total_items);
639 // phpcs:enable
640
641 $this->set_pagination_args([
642 'total_items' => $total_items,
643 'total_pages' => ceil($total_items / $itemsPerPage)
644 ]);
645 }
646 }
647 ?>