1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* FooGallery Admin Columns class |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
if ( ! class_exists( 'FooGallery_Admin_Columns' ) ) { |
7
|
|
|
|
8
|
|
|
class FooGallery_Admin_Columns { |
9
|
|
|
|
10
|
|
|
private $include_clipboard_script = false; |
11
|
|
|
private $_foogallery = false; |
12
|
|
|
|
13
|
|
|
public function __construct() { |
14
|
|
|
add_filter( 'manage_edit-' . FOOGALLERY_CPT_GALLERY . '_columns', array( $this, 'gallery_custom_columns' ) ); |
15
|
|
|
add_action( 'manage_posts_custom_column', array( $this, 'gallery_custom_column_content' ) ); |
16
|
|
|
add_action( 'admin_footer', array( $this, 'include_clipboard_script' ) ); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function gallery_custom_columns( $columns ) { |
20
|
|
|
return array_slice( $columns, 0, 1, true ) + |
21
|
|
|
array( 'icon' => '' ) + |
22
|
|
|
array_slice( $columns, 1, null, true ) + |
23
|
|
|
array( |
24
|
|
|
FOOGALLERY_CPT_GALLERY . '_template' => __( 'Template', 'foogallery' ), |
25
|
|
|
FOOGALLERY_CPT_GALLERY . '_count' => __( 'Media', 'foogallery' ), |
26
|
|
|
FOOGALLERY_CPT_GALLERY . '_shortcode' => __( 'Shortcode', 'foogallery' ), |
27
|
|
|
FOOGALLERY_CPT_GALLERY . '_usage' => __( 'Usage', 'foogallery' ), |
28
|
|
|
); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
private function get_local_gallery( $post ) { |
32
|
|
|
if ( false === $this->_foogallery ) { |
33
|
|
|
$this->_foogallery = FooGallery::get( $post ); |
|
|
|
|
34
|
|
|
} else if ( $this->_foogallery->ID !== $post->ID) { |
35
|
|
|
$this->_foogallery = FooGallery::get( $post ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
return $this->_foogallery; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function gallery_custom_column_content( $column ) { |
42
|
|
|
global $post; |
43
|
|
|
|
44
|
|
|
switch ( $column ) { |
45
|
|
|
case FOOGALLERY_CPT_GALLERY . '_template': |
46
|
|
|
$gallery = $this->get_local_gallery( $post ); |
47
|
|
|
echo $gallery->gallery_template_name(); |
48
|
|
|
break; |
49
|
|
|
case FOOGALLERY_CPT_GALLERY . '_count': |
50
|
|
|
$gallery = $this->get_local_gallery( $post ); |
51
|
|
|
echo $gallery->image_count(); |
52
|
|
|
break; |
53
|
|
|
case FOOGALLERY_CPT_GALLERY . '_shortcode': |
54
|
|
|
$gallery = $this->get_local_gallery( $post ); |
55
|
|
|
$shortcode = $gallery->shortcode(); |
56
|
|
|
|
57
|
|
|
echo '<input type="text" readonly="readonly" size="' . strlen( $shortcode ) . '" value="' . esc_attr( $shortcode ) . '" class="foogallery-shortcode" />'; |
58
|
|
|
|
59
|
|
|
$this->include_clipboard_script = true; |
60
|
|
|
|
61
|
|
|
break; |
62
|
|
|
case 'icon': |
63
|
|
|
$gallery = $this->get_local_gallery( $post ); |
64
|
|
|
$html_img = foogallery_find_featured_attachment_thumbnail_html( $gallery, array( |
|
|
|
|
65
|
|
|
'width' => 60, |
66
|
|
|
'height' => 60, |
67
|
|
|
'force_use_original_thumb' => true |
68
|
|
|
) ); |
69
|
|
|
if ( $html_img ) { |
70
|
|
|
echo $html_img; |
71
|
|
|
} |
72
|
|
|
break; |
73
|
|
|
case FOOGALLERY_CPT_GALLERY . '_usage': |
74
|
|
|
$gallery = $this->get_local_gallery( $post ); |
75
|
|
|
$posts = $gallery->find_usages(); |
76
|
|
|
if ( $posts && count( $posts ) > 0 ) { |
77
|
|
|
echo '<ul class="ul-disc">'; |
78
|
|
|
foreach ( $posts as $post ) { |
79
|
|
|
echo edit_post_link( $post->post_title, '<li>', '</li>', $post->ID ); |
80
|
|
|
} |
81
|
|
|
echo '</ul>'; |
82
|
|
|
} else { |
83
|
|
|
_e( 'Not used!', 'foogallery' ); |
84
|
|
|
} |
85
|
|
|
break; |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function include_clipboard_script() { |
90
|
|
|
if ( $this->include_clipboard_script ) { ?> |
91
|
|
|
<script> |
92
|
|
|
jQuery(function($) { |
93
|
|
|
$('.foogallery-shortcode').click( function () { |
94
|
|
|
try { |
95
|
|
|
//select the contents |
96
|
|
|
this.select(); |
97
|
|
|
//copy the selection |
98
|
|
|
document.execCommand('copy'); |
99
|
|
|
//show the copied message |
100
|
|
|
$('.foogallery-shortcode-message').remove(); |
101
|
|
|
$(this).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>'); |
102
|
|
|
} catch(err) { |
103
|
|
|
console.log('Oops, unable to copy!'); |
104
|
|
|
} |
105
|
|
|
}); |
106
|
|
|
}); |
107
|
|
|
</script> |
108
|
|
|
<?php |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
} |
112
|
|
|
} |
113
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..