fix
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class RIO_Attachment_Extra_Data is a DTO model for `attachment` post type used for `extra_data`
|
||||
* property in RIO_Process_Queue.
|
||||
*
|
||||
* @see RIO_Process_Queue::$extra_data for further information
|
||||
*/
|
||||
class RIO_Attachment_Extra_Data extends RIO_Base_Extra_Data {
|
||||
|
||||
protected $error = null;
|
||||
protected $error_msg = null;
|
||||
protected $thumbnails_count = null;
|
||||
protected $original_main_size = null;
|
||||
protected $main_optimized_data = null;
|
||||
protected $thumbnails_optimized_data = null;
|
||||
protected $webp_main_size = null;
|
||||
protected $avif_main_size = null;
|
||||
|
||||
public function get_error() {
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
public function set_error( $error ) {
|
||||
$this->error = $error;
|
||||
}
|
||||
|
||||
public function get_error_msg() {
|
||||
return $this->error_msg;
|
||||
}
|
||||
|
||||
public function set_error_msg( $error_msg ) {
|
||||
$this->error_msg = $error_msg;
|
||||
}
|
||||
|
||||
public function get_thumbnails_count() {
|
||||
return $this->thumbnails_count;
|
||||
}
|
||||
|
||||
public function set_thumbnails_count( $thumbnails_count ) {
|
||||
$this->thumbnails_count = $thumbnails_count;
|
||||
}
|
||||
|
||||
public function get_original_main_size() {
|
||||
return $this->original_main_size;
|
||||
}
|
||||
|
||||
public function set_original_main_size( $original_main_size ) {
|
||||
$this->original_main_size = $original_main_size;
|
||||
}
|
||||
|
||||
public function get_main_optimized_data() {
|
||||
return (array) $this->main_optimized_data;
|
||||
}
|
||||
|
||||
public function set_main_optimized_data( $main_optimized_data ) {
|
||||
$this->main_optimized_data = $main_optimized_data;
|
||||
}
|
||||
|
||||
public function get_thumbnails_optimized_data() {
|
||||
return (array) $this->thumbnails_optimized_data;
|
||||
}
|
||||
|
||||
public function set_thumbnails_optimized_data( $thumbnails_optimized_data ) {
|
||||
$this->thumbnails_optimized_data = $thumbnails_optimized_data;
|
||||
}
|
||||
|
||||
public function get_webp_main_size() {
|
||||
return $this->webp_main_size;
|
||||
}
|
||||
|
||||
public function set_webp_main_size( $webp_main_size ) {
|
||||
$this->webp_main_size = $webp_main_size;
|
||||
}
|
||||
|
||||
public function get_avif_main_size() {
|
||||
return $this->avif_main_size;
|
||||
}
|
||||
|
||||
public function set_avif_main_size( $avif_main_size ) {
|
||||
$this->avif_main_size = $avif_main_size;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class WRIO_Base_Model used as a base class for any database related model.
|
||||
*
|
||||
* Usage example:
|
||||
* ```php
|
||||
* Custom extends RIO_Base_Model {
|
||||
* public $prop;
|
||||
* }
|
||||
*
|
||||
* $model = new Custom(array('prop' => 123)); // or ['prop' => 123]
|
||||
* $model->save();
|
||||
* ```
|
||||
*/
|
||||
class RIO_Base_Active_Record extends RIO_Base_Object {
|
||||
|
||||
/**
|
||||
* Get table name.
|
||||
*
|
||||
* @return string|null
|
||||
*/
|
||||
public static function table_name() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @todo override with activerecord impl
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $value
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public function __set( $name, $value ) {
|
||||
if ( property_exists( $this, $name ) ) {
|
||||
$this->$name = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check whether table has SQL schema or not.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_table_schema() {
|
||||
$schema = static::get_table_schema();
|
||||
|
||||
return ! empty( $schema );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether table has indexes defined.
|
||||
*
|
||||
* Notice: method would check whether model has schema defined first and then indexes.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public static function has_table_indexes() {
|
||||
|
||||
if ( ! static::has_table_schema() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$indexes = static::get_table_indexes();
|
||||
|
||||
return ! empty( $indexes );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get table SQL schema structure.
|
||||
*
|
||||
* @return string|null String when model has database table, null otherwise.
|
||||
*/
|
||||
public static function get_table_schema() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of indexes.
|
||||
*
|
||||
* None associative list of
|
||||
*
|
||||
* @return array Empty array returned in case when no indexes exist on table.
|
||||
*/
|
||||
public static function get_table_indexes() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class RIO_Base_Extra_Data is a base DTO model for `extra_data` property in RIO_Process_Queue.
|
||||
*
|
||||
* @see RIO_Process_Queue::$extra_data for further information
|
||||
*/
|
||||
class RIO_Base_Extra_Data extends RIO_Base_Object {
|
||||
|
||||
/**
|
||||
* @var string Instance of current class.
|
||||
*/
|
||||
protected $class;
|
||||
|
||||
/**
|
||||
* Magic override of to string method to convert
|
||||
*
|
||||
* @return bool|false|mixed|string
|
||||
*/
|
||||
public function __toString() {
|
||||
$props = get_object_vars( $this );
|
||||
// если свойство не установлено, то не сохраняем его
|
||||
foreach ( $props as $prop_name => $prop_value ) {
|
||||
if ( is_null( $prop_value ) ) {
|
||||
unset( $props[ $prop_name ] );
|
||||
}
|
||||
}
|
||||
$props['class'] = get_called_class();
|
||||
|
||||
return wp_json_encode( $props );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get class
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_class() {
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set class
|
||||
*
|
||||
* @param string $class_name Имя класса
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function set_class( $class_name ) {
|
||||
$this->class = $class_name;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class RIO_Base_Helper {
|
||||
/**
|
||||
* Configure passed object.
|
||||
*
|
||||
* @param object $object Object class to configure.
|
||||
* @param array $config Key => value list of props to be set on object.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public static function configure( $object, $config ) {
|
||||
foreach ( $config as $name => $value ) {
|
||||
$object->$name = $value;
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class RIO_Base_Object is a base class that implements property feature.
|
||||
*
|
||||
* It takes advantage of __get() and __set(), see further implementation below in the class.
|
||||
*
|
||||
* When property of the class is being used and it has a getter, it will be used instead of directly accessing it.
|
||||
*
|
||||
* The same logic applies for setter.
|
||||
*
|
||||
* Example:
|
||||
*
|
||||
* ```php
|
||||
* // equivalent to $label = $object->getLabel();
|
||||
* $label = $object->label;
|
||||
* // equivalent to $object->setLabel('abc');
|
||||
* $object->label = 'abc';
|
||||
* ```
|
||||
*/
|
||||
class RIO_Base_Object {
|
||||
|
||||
/**
|
||||
* RIO_Base_Object constructor.
|
||||
*
|
||||
* @param array $config name-value pairs that will be used to initialize the object properties.
|
||||
*/
|
||||
public function __construct( $config = [] ) {
|
||||
|
||||
if ( ! empty( $config ) ) {
|
||||
$this->configure( $config );
|
||||
}
|
||||
|
||||
$this->init();
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate model.
|
||||
*/
|
||||
public function init() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure object.
|
||||
*
|
||||
* @param array $config name-value pairs that will be used to initialize the object properties.
|
||||
*/
|
||||
public function configure( $config ) {
|
||||
RIO_Base_Helper::configure( $this, $config );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of an object property.
|
||||
*
|
||||
* Do not call this method directly as it is a PHP magic method that
|
||||
* will be implicitly called when executing `$value = $object->property;`.
|
||||
*
|
||||
* @param string $name the property name
|
||||
*
|
||||
* @return mixed the property value
|
||||
* @throws Exception if the property is not defined
|
||||
* @see __set()
|
||||
*/
|
||||
public function __get( $name ) {
|
||||
$getter = 'get_' . $name;
|
||||
if ( method_exists( $this, $getter ) ) {
|
||||
return $this->$getter();
|
||||
} elseif ( method_exists( $this, 'set' . $name ) ) {
|
||||
throw new \Exception( 'Getting write-only property: ' . get_class( $this ) . '::' . $name );
|
||||
}
|
||||
throw new Exception( 'Getting unknown property: ' . get_class( $this ) . '::' . $name );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets value of an object property.
|
||||
*
|
||||
* Do not call this method directly as it is a PHP magic method that
|
||||
* will be implicitly called when executing `$object->property = $value;`.
|
||||
*
|
||||
* @param string $name the property name or the event name
|
||||
* @param mixed $value the property value
|
||||
*
|
||||
* @throws Exception if the property is not defined
|
||||
* @see __get()
|
||||
*/
|
||||
public function __set( $name, $value ) {
|
||||
$setter = 'set_' . $name;
|
||||
if ( method_exists( $this, $setter ) ) {
|
||||
$this->$setter( $value );
|
||||
} elseif ( method_exists( $this, 'get' . $name ) ) {
|
||||
throw new \Exception( 'Setting read-only property: ' . get_class( $this ) . '::' . $name );
|
||||
} else {
|
||||
throw new \Exception( 'Setting unknown property: ' . get_class( $this ) . '::' . $name );
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Exit if accessed directly
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Class RIO_Smushit_Extra_Data is a DTO model for saving extra data from post attachments in `extra_data`.
|
||||
*
|
||||
* @see RIO_Process_Queue::$extra_data for further information
|
||||
*/
|
||||
class RIO_Smushit_Extra_Data extends RIO_Attachment_Extra_Data {
|
||||
|
||||
/**
|
||||
* @var int Final size in bytes.
|
||||
*/
|
||||
protected $optimized_size;
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Class RIOP_WebP_Extra_Data.
|
||||
*
|
||||
* @property string $source_src
|
||||
*/
|
||||
class RIOP_WebP_Extra_Data extends RIO_Attachment_Extra_Data {
|
||||
/**
|
||||
* @var null|string E.g. attachment, nextgen, etc
|
||||
*/
|
||||
protected $convert_from = null;
|
||||
|
||||
/**
|
||||
* @var null|string|int
|
||||
*/
|
||||
protected $converted_from_size = null;
|
||||
|
||||
/**
|
||||
* @var string|null Image source src.
|
||||
*/
|
||||
protected $source_src = null;
|
||||
|
||||
/**
|
||||
* @var string|null Image absolute path.
|
||||
*/
|
||||
protected $source_path = null;
|
||||
|
||||
/**
|
||||
* @var string|null Converted WebP image src.
|
||||
*/
|
||||
protected $converted_src = null;
|
||||
|
||||
/**
|
||||
* @var string|null Converted WebP absolute path.
|
||||
*/
|
||||
protected $converted_path = null;
|
||||
|
||||
/**
|
||||
* @var int|null Post ID.
|
||||
*/
|
||||
protected $post_id = null;
|
||||
|
||||
/**
|
||||
* @var int|null thumbnails count.
|
||||
*/
|
||||
protected $thumbnails_count = null;
|
||||
|
||||
/**
|
||||
* @param string $source_src
|
||||
*/
|
||||
public function set_source_src( $source_src ) {
|
||||
$this->source_src = trim( $source_src );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get source property.
|
||||
*
|
||||
* @param bool $decoded Whether to decode src or not.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_source_src( $decoded = true ) {
|
||||
$src = $this->source_src;
|
||||
|
||||
if ( $decoded ) {
|
||||
return urldecode( $src );
|
||||
}
|
||||
|
||||
return $src;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function get_source_path() {
|
||||
return $this->source_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $source_path
|
||||
*/
|
||||
public function set_source_path( $source_path ) {
|
||||
$this->source_path = $source_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return null|string
|
||||
*/
|
||||
public function get_convert_from() {
|
||||
return $this->convert_from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param null|string $convert_from
|
||||
*/
|
||||
public function set_convert_from( $convert_from ) {
|
||||
$this->convert_from = $convert_from;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int|null|string
|
||||
*/
|
||||
public function get_converted_from_size() {
|
||||
return $this->converted_from_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int|null|string $converted_from_size
|
||||
*/
|
||||
public function set_converted_from_size( $converted_from_size ) {
|
||||
$this->converted_from_size = $converted_from_size;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_converted_path() {
|
||||
return $this->converted_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $converted_path
|
||||
*/
|
||||
public function set_converted_path( $converted_path ) {
|
||||
$this->converted_path = $converted_path;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_converted_src() {
|
||||
return $this->converted_src;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $converted_src
|
||||
*/
|
||||
public function set_converted_src( $converted_src ) {
|
||||
$this->converted_src = $converted_src;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function get_post_id() {
|
||||
return $this->post_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $post_id
|
||||
*
|
||||
* @return RIOP_WebP_Extra_Data
|
||||
*/
|
||||
public function set_post_id( $post_id ) {
|
||||
$this->post_id = $post_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function get_original_main_size() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function get_thumbnails_count() {
|
||||
return $this->thumbnails_count;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user