1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* FooGallery Thumbnail Resizing class |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
if ( !class_exists( 'FooGallery_Thumbnails' ) ) { |
7
|
|
|
|
8
|
|
|
class FooGallery_Thumbnails { |
9
|
|
|
|
10
|
|
|
function __construct() { |
11
|
|
|
//generate thumbs using WPThumb |
12
|
|
|
add_filter( 'foogallery_attachment_resize_thumbnail', array( $this, 'resize' ), 10, 3 ); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
function resize( $original_image_src, $args, $thumbnail_object ) { |
16
|
|
|
|
17
|
|
|
$arg_defaults = array( |
18
|
|
|
'width' => 0, |
19
|
|
|
'height' => 0, |
20
|
|
|
'crop' => true, |
21
|
|
|
'jpeg_quality' => foogallery_thumbnail_jpeg_quality(), |
22
|
|
|
'thumb_resize_animations' => foogallery_get_setting( 'thumb_resize_animations' ) |
23
|
|
|
); |
24
|
|
|
|
25
|
|
|
$args = wp_parse_args( $args, $arg_defaults ); |
26
|
|
|
|
27
|
|
|
// $width = (int)$args['width']; |
|
|
|
|
28
|
|
|
// $height = (int)$args['height']; |
29
|
|
|
// $crop = (bool)$args['crop']; |
30
|
|
|
// |
31
|
|
|
// //check if we are trying to get back the default thumbnail that we already have |
32
|
|
|
// if ( $thumbnail_object->ID > 0 && $width == get_option( 'thumbnail_size_w' ) && $height == get_option( 'thumbnail_size_h' ) && $crop == get_option( 'thumbnail_crop' ) ) { |
33
|
|
|
// $thumbnail_attributes = wp_get_attachment_image_src( $thumbnail_object->ID ); |
34
|
|
|
// |
35
|
|
|
// return $thumbnail_attributes[0]; |
36
|
|
|
// } |
37
|
|
|
// |
38
|
|
|
// //we need either a width or a height. If nothing is given then default to the thumb width setting in Settings->Media |
39
|
|
|
// if ( 0 == $width && 0 == $height ) { |
40
|
|
|
// $args['width'] = (int)get_option( 'thumbnail_size_w' ); |
41
|
|
|
// } |
42
|
|
|
|
43
|
|
|
if ( $thumbnail_object->ID > 0 ) { |
44
|
|
|
$crop_from_position = get_post_meta( $thumbnail_object->ID, 'wpthumb_crop_pos', true ); |
45
|
|
|
|
46
|
|
|
if ( !empty( $crop_from_position ) ) { |
47
|
|
|
$args['crop_from_position'] = $crop_from_position; |
48
|
|
|
} |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
|
52
|
|
|
return wpthumb( $original_image_src, $args ); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.