PluginProbe
WP-Stateless – Google Cloud Storage / 2.1.4
WP-Stateless – Google Cloud Storage v2.1.4
4.4.3 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.3.0 2.3.1 2.3.2 3.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 All 62 releases
wp-stateless / lib / classes / compatibility / dynamic-image-support.php

dynamic-image-support.php in WP-Stateless – Google Cloud Storage 2.1.4, at lib/classes/compatibility/dynamic-image-support.php

84 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: All plugins
4 * Plugin URI:
5 *
6 * Compatibility Description: Upload image thumbnails generated by your theme and
7 * plugins that do not register media objects with the media library.
8 *
9 */
10
11 namespace wpCloud\StatelessMedia {
12
13 if(!class_exists('wpCloud\StatelessMedia\DynamicImageSupport')) {
14
15 class DynamicImageSupport extends ICompatibility {
16 protected $id = 'dynamic-image-support';
17 protected $title = 'Dynamic Image Support';
18 protected $constant = 'WP_STATELESS_MEDIA_ON_FLY';
19 protected $description = 'Upload image thumbnails generated by your theme and plugins that do not register media objects with the media library.';
20 protected $enabled = false;
21
22 public function __construct(){
23 $modules = get_option('stateless-modules', array());
24
25 if (empty($modules[$this->id])) {
26 // Lagecy settings
27 $this->enabled = get_option('sm_on_fly', false);
28 }
29
30 $this->init();
31 }
32
33 public function module_init($sm){
34
35 /**
36 * Handle any other on fly generated media
37 * 7d23984e Anton Korotkov, 2 years ago (February 19th, 2016 9:02am) new options added
38 */
39 add_filter('image_make_intermediate_size', array($this, 'handle_on_fly'));
40 }
41
42 /**
43 * Handle images on fly
44 * f6a7dfd9 Anton Korotkov, 2 years ago (September 29th, 2015 6:09am)
45 * @param $file
46 * @return mixed
47 */
48 public function handle_on_fly( $file ) {
49
50 $client = ud_get_stateless_media()->get_client();
51 $upload_dir = wp_upload_dir();
52
53 $file_path = str_replace(trailingslashit($upload_dir[ 'basedir' ]), '', $file);
54 $file_info = @getimagesize($file);
55 $mimeType = wp_check_filetype($file);
56
57 if ($file_info) {
58 $_metadata = array(
59 'width' => $file_info[0],
60 'height' => $file_info[1],
61 'object-id' => 'unknown', // we really don't know it
62 'source-id' => md5( $file . ud_get_stateless_media()->get( 'sm.bucket' ) ),
63 'file-hash' => md5( $file )
64 );
65 }
66
67 $client->add_media(apply_filters('sm:item:on_fly:before_add', array_filter(array(
68 'name' => $file_path,
69 'absolutePath' => wp_normalize_path($file),
70 'cacheControl' => apply_filters('sm:item:cacheControl', 'public, max-age=36000, must-revalidate', $_metadata),
71 'contentDisposition' => null,
72 'mimeType' => $mimeType['type'],
73 'metadata' => $_metadata
74 ))));
75
76 return $file;
77 }
78
79 }
80
81 }
82
83 }
84