|
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
|
|
|
|
|
12
|
|
|
public function __construct() { |
|
13
|
|
|
add_filter( 'manage_edit-' . FOOGALLERY_CPT_GALLERY . '_columns', array( $this, 'gallery_custom_columns' ) ); |
|
14
|
|
|
add_action( 'manage_posts_custom_column', array( $this, 'gallery_custom_column_content' ) ); |
|
15
|
|
|
add_action( 'admin_footer', array( $this, 'include_clipboard_script' ) ); |
|
16
|
|
|
} |
|
17
|
|
|
|
|
18
|
|
|
public function gallery_custom_columns( $columns ) { |
|
19
|
|
|
return array_slice( $columns, 0, 1, true ) + |
|
20
|
|
|
array( 'icon' => '' ) + |
|
21
|
|
|
array_slice( $columns, 1, null, true ) + |
|
22
|
|
|
array( |
|
23
|
|
|
FOOGALLERY_CPT_GALLERY . '_template' => __( 'Template', 'foogallery' ), |
|
24
|
|
|
FOOGALLERY_CPT_GALLERY . '_count' => __( 'Media', 'foogallery' ), |
|
25
|
|
|
FOOGALLERY_CPT_GALLERY . '_shortcode' => __( 'Shortcode', 'foogallery' ), |
|
26
|
|
|
); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function gallery_custom_column_content( $column ) { |
|
30
|
|
|
global $post; |
|
31
|
|
|
|
|
32
|
|
|
switch ( $column ) { |
|
33
|
|
|
case FOOGALLERY_CPT_GALLERY . '_template': |
|
34
|
|
|
$gallery = FooGallery::get( $post ); |
|
35
|
|
|
echo $gallery->gallery_template_name(); |
|
36
|
|
|
break; |
|
37
|
|
|
case FOOGALLERY_CPT_GALLERY . '_count': |
|
38
|
|
|
$gallery = FooGallery::get( $post ); |
|
39
|
|
|
echo $gallery->image_count(); |
|
40
|
|
|
break; |
|
41
|
|
|
case FOOGALLERY_CPT_GALLERY . '_shortcode': |
|
42
|
|
|
$gallery = FooGallery::get( $post ); |
|
43
|
|
|
$shortcode = $gallery->shortcode(); |
|
44
|
|
|
|
|
45
|
|
|
echo '<input type="text" readonly="readonly" size="' . strlen( $shortcode ) . '" value="' . esc_attr( $shortcode ) . '" class="foogallery-shortcode" />'; |
|
46
|
|
|
|
|
47
|
|
|
$this->include_clipboard_script = true; |
|
48
|
|
|
|
|
49
|
|
|
break; |
|
50
|
|
|
case 'icon': |
|
51
|
|
|
$gallery = FooGallery::get( $post ); |
|
52
|
|
|
$img = $gallery->featured_image_html( array(80, 60), true ); |
|
53
|
|
|
if ( $img ) { |
|
54
|
|
|
echo $img; |
|
55
|
|
|
} |
|
56
|
|
|
break; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function include_clipboard_script() { |
|
61
|
|
|
if ( $this->include_clipboard_script ) { ?> |
|
62
|
|
|
<script> |
|
63
|
|
|
jQuery(function($) { |
|
64
|
|
|
$('.foogallery-shortcode').click( function () { |
|
65
|
|
|
try { |
|
66
|
|
|
//select the contents |
|
67
|
|
|
this.select(); |
|
68
|
|
|
//copy the selection |
|
69
|
|
|
document.execCommand('copy'); |
|
70
|
|
|
//show the copied message |
|
71
|
|
|
$('.foogallery-shortcode-message').remove(); |
|
72
|
|
|
$(this).after('<p class="foogallery-shortcode-message"><?php _e( 'Shortcode copied to clipboard :)','foogallery' ); ?></p>'); |
|
73
|
|
|
} catch(err) { |
|
74
|
|
|
console.log('Oops, unable to copy!'); |
|
75
|
|
|
} |
|
76
|
|
|
}); |
|
77
|
|
|
}); |
|
78
|
|
|
</script> |
|
79
|
|
|
<?php |
|
80
|
|
|
} |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|