-
Notifications
You must be signed in to change notification settings - Fork 0
/
main-table.php
97 lines (86 loc) · 2.98 KB
/
main-table.php
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
<?php
if ( !defined( 'ABSPATH' ) )
exit;
if ( !class_exists( 'WP_List_Table' ) )
require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );
class WP_Gallery_To_Photonic_Main_List_Table extends WP_List_Table {
function get_columns(): array {
return [
'title' => 'Title',
'author' => 'Author',
'date' => 'Date',
'shortcode' => 'Shortcode',
];
}
function prepare_items( array $items = [] ): void {
$columns = $this->get_columns();
$hidden = [];
$sortable = [];
$this->_column_headers = [ $columns, $hidden, $sortable, ];
$this->items = $items;
}
function column_title( WP_Post $post ): string {
$edit_url = admin_url( 'post.php?post=' . $post->ID . '&action=edit' );
$view_url = get_the_permalink( $post );
$actions = [
'view' => sprintf( '<a href="%s">View</a>', $view_url ),
];
if ( array_key_exists( 'tab', $_GET ) && $_GET['tab'] === 'ignored' ) {
$include_url = admin_url( 'admin.php?action=g2phot_include&id=' . $post->ID );
$include_url = wp_nonce_url( $include_url, 'g2phot_include_' . $post->ID, 'nonce' );
$actions['include'] = sprintf( '<a href="%s">Include</a>', $include_url );
} else {
$upload_url = admin_url( 'admin.php?page=g2phot&tab=upload&id=' . $post->ID );
$actions['upload'] = sprintf( '<a href="%s">Upload</a>', $upload_url );
$exclude_url = admin_url( 'admin.php?action=g2phot_exclude&id=' . $post->ID );
$exclude_url = wp_nonce_url( $exclude_url, 'g2phot_exclude_' . $post->ID, 'nonce' );
$actions['exclude'] = sprintf( '<a href="%s">Exclude</a>', $exclude_url );
}
ob_start();
?>
<div style="display: flex;">
<div style="flex-shrink: 0; height: 40px; width: 40px; margin-right: 8px;">
<?php
echo get_the_post_thumbnail( $post, 'thumbnail', [
'style' => 'max-height: 100%; height: auto; max-width: 100%; width: auto;',
] );
?>
</div>
<div style="flex-grow: 1;">
<div><strong><a href="<?= $edit_url ?>"><?= esc_html( $post->post_title ) ?></a></strong></div>
<div><?= $this->row_actions( $actions ) ?></div>
</div>
</div>
<?php
return ob_get_clean();
}
function column_date( WP_Post $post ): string {
return esc_html( $post->post_date );
}
function column_author( WP_Post $post ): string {
return esc_html( get_the_author_meta( 'display_name', $post->post_author ) );
}
function column_shortcode( WP_Post $post ): string {
$regex = get_shortcode_regex( [ 'gallery', ] );
$m = NULL;
if ( !has_shortcode( $post->post_content, 'gallery' ) )
return '-';
preg_match_all( '/' . $regex . '/s', $post->post_content, $m, PREG_SET_ORDER );
$ids = [];
if ( !is_null( $m ) ) {
foreach ( $m as $mm ) {
$atts = shortcode_parse_atts( $mm[3] );
if ( !array_key_exists( 'ids', $atts ) )
continue;
$ids[] = count( explode( ',', $atts['ids'] ) );
}
}
if ( empty( $ids ) )
return '-';
$html = '';
if ( count( $ids ) > 1 )
$html .= '<div>' . implode( ' + ', $ids ) . ' =</div>';
$html .= '<div><strong>' . array_sum( $ids ) . '</strong></div>';
return $html;
}
}