/
hm-core.classes.php
85 lines (51 loc) · 2.43 KB
/
hm-core.classes.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
<?php
class HM_Feature_Image_Meta_Box {
public $show_view_large_link;
public $link_image_to_gallery_tab;
public $show_watermark_on_thumbnail;
private $post;
function __construct( $show_view_large_link = false, $link_image_to_gallery_tab = false, $show_watermark_on_thumbnail = false ) {
$this->show_view_large_link = $show_view_large_link;
$this->link_image_to_gallery_tab = $link_image_to_gallery_tab;
$this->show_watermark_on_thumbnail = $show_watermark_on_thumbnail;
if ( defined( 'DOING_AJAX' ) && DOING_AJAX && isset( $_POST['action'] ) && ( $_POST['action'] == 'set-post-thumbnail' || $_POST['action'] == 'wpthumb_watermark_save' ) ) {
$this->post = get_post( $_POST['post_id'] );
$this->setup_hooks();
}
}
public function display( $post ) {
$this->post = $post;
$this->setup_hooks();
post_thumbnail_meta_box( $post );
}
function _admin_post_thumbnail_html( $html ) {
$html .= '<span class="hm_view_large_link">' . $this->get_view_large_link() . '</span>';
return $html;
}
function _set_featured_image_link_to_gallery_tab( $html ) {
return str_replace( esc_url( get_upload_iframe_src( 'image' ) ), add_query_arg( 'tab', 'gallery', esc_url( get_upload_iframe_src( 'image' ) ) ), $html );
}
function _show_watermark_on_image_downsize( $return, $id, $size ) {
$options = wpthumb_wm_get_options( $id );
$options['pre_resize'] = true;
if ( is_array( $size) && key( $size ) === 0 ) {
$size = array( 'width' => $size[0], 'height' => $size[1] );
} else {
$size = wp_parse_args( $size );
}
$size['watermark_options'] = $options;
return array( wpthumb( get_attached_file( $id ), $size ) );
}
private function setup_hooks() {
if ( $this->show_watermark_on_thumbnail )
add_filter( 'image_downsize', array( $this, '_show_watermark_on_image_downsize' ), 99, 3 );
if ( $this->link_image_to_gallery_tab )
add_filter( 'admin_post_thumbnail_html', array( $this, '_set_featured_image_link_to_gallery_tab' ) );
if ( $this->show_view_large_link )
add_filter( 'admin_post_thumbnail_html', array( $this, '_admin_post_thumbnail_html' ) );
}
private function get_view_large_link() {
if ( get_post_thumbnail_id( $this->post->ID ) )
return '<a href="' . reset( wp_get_attachment_image_src( get_post_thumbnail_id( $this->post->ID ), 'width=800&height=800&crop=0' ) ) . '" target="_blank">View Large</a>';
}
}