GRAYBYTE WORDPRESS FILE MANAGER8006

Server IP : 198.54.121.189 / Your IP : 216.73.216.140
System : Linux premium69.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
PHP Version : 7.4.33
Disable Function : NONE
cURL : ON | WGET : ON | Sudo : OFF | Pkexec : OFF
Directory : /home/giriqfky/trustyourlawyer.com/wp-content/plugins/image-optimization/classes/image/
Upload Files :
Current_dir [ Writeable ] Document_root [ Writeable ]

Command :


Current File : /home/giriqfky/trustyourlawyer.com/wp-content/plugins/image-optimization/classes/image//image.php
<?php

namespace ImageOptimization\Classes\Image;

use ImageOptimization\Classes\Image\Exceptions\Invalid_Image_Exception;
use WP_Post;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

class Image {
	public const SIZE_FULL = 'full';
	private const SUPPORTED_MIME_TYPES = [ 'image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/avif' ];

	// Used for error messages
	private const SUPPORTED_FORMATS = [ 'jpeg', 'png', 'webp', 'gif', 'avif' ];
	private const MIME_TYPES_CANNOT_BE_OPTIMIZED = [ 'image/avif' ];
	private const FORMATS_CANNOT_BE_OPTIMIZED = [ 'avif' ];

	protected int $image_id;
	protected $attachment_object;

	/**
	 * Returns attachment post id.
	 *
	 * @return int
	 */
	public function get_id(): int {
		return $this->image_id;
	}

	/**
	 * Returns file URL for a specific image size.
	 *
	 * @param string $image_size Image size (e. g. 'full', 'thumbnail', etc)
	 * @return string|null
	 */
	public function get_url( string $image_size ): ?string {
		$image_data = wp_get_attachment_image_src( $this->image_id, $image_size );

		if ( empty( $image_data ) ) {
			return null;
		}

		return $image_data[0];
	}

	/**
	 * Returns absolute file path for a specific image size.
	 *
	 * @param string $image_size Image size (e. g. 'full', 'thumbnail', etc)
	 * @return string|null
	 */
	public function get_file_path( string $image_size ): ?string {
		if ( 'full' === $image_size ) {
			$path = get_attached_file( $this->image_id );
			return $path ?? null;
		}

		$path_data = image_get_intermediate_size( $this->image_id, $image_size );

		if ( empty( $path_data ) ) {
			return null;
		}

		return sprintf(
			'%s/%s',
			wp_get_upload_dir()['basedir'],
			$path_data['path']
		);
	}

	public function file_exists( string $image_size ): bool {
		$path = $this->get_file_path( $image_size );

		if ( ! $path ) {
			return false;
		}

		return file_exists( $path );
	}

	/**
	 * Returns true if an image marked as optimized.
	 *
	 * @return bool
	 */
	public function is_optimized(): bool {
		$meta = new Image_Meta( $this->image_id );

		return $meta->get_status() === Image_Status::OPTIMIZED;
	}

	/**
	 * Returns true if an image can be restored from the backups.
	 *
	 * @return bool
	 */
	public function can_be_restored(): bool {
		$meta = new Image_Meta( $this->image_id );

		return (bool) count( $meta->get_image_backup_paths() );
	}

	/**
	 * Returns image's mime type.
	 *
	 * @return string
	 */
	public function get_mime_type(): string {
		return $this->attachment_object->post_mime_type;
	}

	/**
	 * Returns an original attachment WP_Post object.
	 *
	 * @return WP_Post
	 */
	public function get_attachment_object(): WP_Post {
		return $this->attachment_object;
	}

	/**
	 * Updates WP_Post fields of the attachment.
	 *
	 * @return bool True if the post was updated successfully, false otherwise.
	 */
	public function update_attachment( array $update_query ): bool {
		global $wpdb;

		// Must use $wpdb here as `wp_update_post()` doesn't allow to rewrite guid.
		$result = $wpdb->update(
			$wpdb->posts,
			$update_query,
			[ 'ID' => $this->image_id ]
		);

		if ( 0 !== $result ) {
			$this->attachment_object = get_post( $this->image_id );
			return true;
		}

		return false;
	}

	/**
	 * Returns the list of mime types supported by the plugin.
	 *
	 * @return string[]
	 */
	public static function get_supported_mime_types(): array {
		return self::SUPPORTED_MIME_TYPES;
	}

	/**
	 * Returns the list of formats types supported by the plugin.
	 *
	 * @return string[]
	 */
	public static function get_supported_formats(): array {
		return self::SUPPORTED_FORMATS;
	}

	/**
	 * Returns the list of mime types that are supported by the plugin, but cannot be optimized
	 *
	 * @return string[]
	 */
	public static function get_mime_types_cannot_be_optimized(): array {
		return self::MIME_TYPES_CANNOT_BE_OPTIMIZED;
	}

	/**
	 * Returns the list of formats that are supported by the plugin, but cannot be optimized
	 *
	 * @return string[]
	 */
	public static function get_formats_cannot_be_optimized(): array {
		return self::FORMATS_CANNOT_BE_OPTIMIZED;
	}

	/**
	 * @throws Invalid_Image_Exception
	 */
	public function __construct( int $image_id ) {
		$this->image_id = $image_id;
		$this->attachment_object = get_post( $image_id );

		if ( ! $this->attachment_object ) {
			throw new Invalid_Image_Exception( "There is no entity with id '$image_id'" );
		}

		if ( ! wp_attachment_is_image( $this->attachment_object ) ) {
			throw new Invalid_Image_Exception( "Post '$image_id' is not an image" );
		}
	}
}

[ Back ]
Name
Size
Last Modified
Owner / Group
Permissions
Options
..
--
January 01 1970 00:00:00
root / root
0
exceptions
--
July 10 2025 04:32:21
giriqfky / giriqfky
0755
.htaccess
0.41 KB
July 10 2025 04:32:21
giriqfky / giriqfky
0644
image-backup.php
3.99 KB
February 06 2024 19:05:42
giriqfky / giriqfky
0644
image-conversion-option.php
0.313 KB
July 29 2024 16:34:36
giriqfky / giriqfky
0644
image-conversion.php
1.175 KB
July 29 2024 16:34:36
giriqfky / giriqfky
0644
image-db-update.php
0.64 KB
February 06 2024 19:05:42
giriqfky / giriqfky
0644
image-dimensions.php
1.032 KB
August 22 2024 13:32:50
giriqfky / giriqfky
0644
image-meta.php
4.614 KB
April 10 2025 14:45:10
giriqfky / giriqfky
0644
image-optimization-error-type.php
0.423 KB
April 10 2025 14:45:10
giriqfky / giriqfky
0644
image-query-builder.php
2.351 KB
September 24 2024 14:22:20
giriqfky / giriqfky
0644
image-restore.php
3.967 KB
September 24 2024 14:22:20
giriqfky / giriqfky
0644
image-status.php
0.656 KB
February 06 2024 19:05:42
giriqfky / giriqfky
0644
image.php
4.47 KB
April 10 2025 14:45:10
giriqfky / giriqfky
0644
wp-image-meta.php
7.276 KB
February 06 2024 19:05:42
giriqfky / giriqfky
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2025
CONTACT ME
Static GIF