diff --git a/inc/media_offload.php b/inc/media_offload.php index c95b69a6..7ec653d4 100644 --- a/inc/media_offload.php +++ b/inc/media_offload.php @@ -6,6 +6,7 @@ * @author Optimole */ +use OptimoleWP\Offload\Loader; use Optimole\Sdk\Exception\InvalidArgumentException; use Optimole\Sdk\Exception\InvalidUploadApiResponseException; use Optimole\Sdk\Exception\RuntimeException; @@ -186,6 +187,7 @@ public static function instance() { if ( self::$is_legacy_install === null ) { self::$is_legacy_install = get_option( 'optimole_wp_install', 0 ) > 1677171600; } + ( new Loader() )->register_hooks(); } } diff --git a/inc/v2/Offload/ImageEditor.php b/inc/v2/Offload/ImageEditor.php new file mode 100644 index 00000000..6e01991e --- /dev/null +++ b/inc/v2/Offload/ImageEditor.php @@ -0,0 +1,157 @@ +file ) && Optml_Media_Offload::is_uploaded_image( $this->file ) ) { + return true; + } + return false; + } + + /** + * Resizes the image. + * + * For offloaded images, this operation is not performed locally and always returns true. + * + * @param int $max_w Maximum width. + * @param int $max_h Maximum height. + * @param bool $crop Optional. Whether to crop the image. Default false. + * @return bool Always returns true for offloaded images. + */ + public function resize( $max_w, $max_h, $crop = false ) { + return true; + } + + /** + * Resizes the image to multiple sizes. + * + * For offloaded images, this operation is not performed locally and always returns an empty array. + * + * @param array $sizes Array of size arrays. Each size array must include width, height, crop. + * @return array Empty array for offloaded images. + */ + public function multi_resize( $sizes ) { + return []; + } + + /** + * Crops the image. + * + * For offloaded images, this operation is not performed locally and always returns true. + * + * @param int $src_x The start x position to crop from. + * @param int $src_y The start y position to crop from. + * @param int $src_w The width to crop. + * @param int $src_h The height to crop. + * @param int $dst_w Optional. The destination width. + * @param int $dst_h Optional. The destination height. + * @param bool $src_abs Optional. If the source crop points are absolute. + * @return bool Always returns true for offloaded images. + */ + public function crop( $src_x, $src_y, $src_w, $src_h, $dst_w = null, $dst_h = null, $src_abs = false ) { + return true; + } + + /** + * Rotates the image. + * + * For offloaded images, this operation is not performed locally and always returns true. + * + * @param float $angle The angle of rotation. + * @return bool Always returns true for offloaded images. + */ + public function rotate( $angle ) { + return true; + } + + /** + * Flips the image. + * + * For offloaded images, this operation is not performed locally and always returns true. + * + * @param bool $horz Whether to flip horizontally. + * @param bool $vert Whether to flip vertically. + * @return bool Always returns true for offloaded images. + */ + public function flip( $horz, $vert ) { + return true; + } + + /** + * Streams the image to the browser. + * + * For offloaded images, this redirects to the remote image URL. + * + * @param string $mime_type Optional. The MIME type of the image. + */ + public function stream( $mime_type = null ) { + header( 'Location: ' . esc_url( $this->file ) ); + return true; + } +} diff --git a/inc/v2/Offload/Loader.php b/inc/v2/Offload/Loader.php new file mode 100644 index 00000000..3ab08d04 --- /dev/null +++ b/inc/v2/Offload/Loader.php @@ -0,0 +1,44 @@ +