PluginProbe ʕ •ᴥ•ʔ
TinyPNG – JPEG, PNG & WebP image compression / 3.6.13
TinyPNG – JPEG, PNG & WebP image compression v3.6.13
3.7.0 3.6.14 trunk 1.0.0 1.1.0 1.2.0 1.2.1 1.3.0 1.3.1 1.3.2 1.4.0 1.5.0 1.6.0 1.7.0 1.7.1 1.7.2 2.0.0 2.0.1 2.0.2 2.1.0 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.0.0 3.0.1 3.1.0 3.2.0 3.2.1 3.3 3.4 3.4.1 3.4.2 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.5.2 3.6.0 3.6.1 3.6.10 3.6.11 3.6.12 3.6.13 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.6.9
tiny-compress-images / src / compatibility / as3cf / class-tiny-as3cf.php
tiny-compress-images / src / compatibility / as3cf Last commit date
class-tiny-as3cf.php 5 months ago
class-tiny-as3cf.php
87 lines
1 <?php
2
3 /**
4 * Class Tiny_AS3CF
5 * Manages integration with WP Media Offload (aka Amazon S3 and CloudFront).
6 *
7 * Known issues with integration:
8 * - When as3cf removes local files, Tinify can't do compression on files that are
9 * already offloaded. Possible solutions are to download the remote file, compress
10 * We can use `tiny_image_after_compression` to possible remove the file after
11 * compression is done. A lot of functonality for Tinify is based on having the
12 * has to be changed in order to support remote files.
13 */
14 class Tiny_AS3CF {
15
16
17 /**
18 * Tiny_Plugin $settings
19 *
20 * @var Tiny_Settings
21 */
22 private $tiny_settings;
23
24 /**
25 * Checks wether the lite version is active
26 */
27 public static function lite_is_active() {
28 return class_exists( 'Amazon_S3_And_CloudFront' );
29 }
30
31 /**
32 * Checks wether the pro version is active
33 */
34 public static function pro_is_active() {
35 return class_exists( 'Amazon_S3_And_CloudFront_Pro' );
36 }
37
38 public function __construct( $settings ) {
39 $this->tiny_settings = $settings;
40 $this->add_hooks();
41 }
42
43 /**
44 * Will verify if either the Lite or Pro version of AS3CF is active.
45 */
46 public static function is_active() {
47 return Tiny_AS3CF::pro_is_active() || Tiny_AS3CF::lite_is_active();
48 }
49
50 public static function remove_local_files_setting_enabled() {
51 if ( ! Tiny_AS3CF::is_active() ) {
52 return false;
53 }
54 $settings = get_option( 'tantan_wordpress_s3' );
55 if ( ! is_array( $settings ) ) {
56 return false;
57 }
58 return array_key_exists( 'remove-local-file', $settings ) && $settings['remove-local-file'];
59 }
60
61 /**
62 * Registers hooks required for the AS3CF integration.
63 */
64 public function add_hooks() {
65 add_action( 'as3cf_pre_upload_object', array( $this, 'as3cf_before_offload' ), 10, 2 );
66 }
67
68 /**
69 * handler for 'as3cf_pre_upload_object' action
70 *
71 * @see Tiny_Image->compress()
72 *
73 * Will handle file before file is possibly offloaded
74 *
75 * @param Item $as3cf_item
76 * @param array $args
77 */
78 public function as3cf_before_offload( $as3cf_item, $args ) {
79 if ( ! $this->tiny_settings->auto_compress_enabled() ) {
80 return;
81 }
82
83 $tiny_image = new Tiny_Image( $this->tiny_settings, $as3cf_item->source_id() );
84 $result = $tiny_image->compress();
85 }
86 }
87