Skip to content

Commit

Permalink
Merge pull request #454 from wp-media/branch-1.9.8
Browse files Browse the repository at this point in the history
Imagify 1.9.8
  • Loading branch information
Screenfeed authored Nov 11, 2019
2 parents 4d0ae3c + 5d0cf63 commit b7bd072
Show file tree
Hide file tree
Showing 51 changed files with 1,436 additions and 279 deletions.
2 changes: 1 addition & 1 deletion classes/CDN/PushCDNInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function get_file_url( $file_name = false );
* @access public
* @author Grégory Viguier
*
* @param string $file_name Name of the file. Leave empty for the full size file.
* @param string $file_name Name of the file. Leave empty for the full size file. Use 'original' to get the path to the original file.
* @return string Path to the file.
*/
public function get_file_path( $file_name = false );
Expand Down
12 changes: 1 addition & 11 deletions classes/Context/AbstractContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,6 @@ abstract class AbstractContext implements ContextInterface {
*/
protected $thumbnail_sizes;

/**
* Tell if the optimization process is allowed resize in this context.
*
* @var bool
* @since 1.9
* @access protected
* @author Grégory Viguier
*/
protected $can_resize;

/**
* Tell if the optimization process is allowed to backup in this context.
*
Expand Down Expand Up @@ -167,7 +157,7 @@ public function get_thumbnail_sizes() {
* @return bool
*/
public function can_resize() {
return $this->can_resize;
return $this->get_resizing_threshold() > 0;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions classes/Context/ContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ public function get_allowed_mime_types();
*/
public function get_thumbnail_sizes();

/**
* Get images max width for this context. This is used when resizing.
* 0 means to not resize.
*
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return int
*/
public function get_resizing_threshold();

/**
* Tell if the optimization process is allowed resize in this context.
*
Expand Down
14 changes: 9 additions & 5 deletions classes/Context/CustomFolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ class CustomFolders extends AbstractContext {
protected $thumbnail_sizes = [];

/**
* Tell if the optimization process is allowed resize in this context.
* Get images max width for this context. This is used when resizing.
* 0 means to not resize.
*
* @var bool
* @since 1.9
* @access protected
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return int
*/
protected $can_resize = false;
public function get_resizing_threshold() {
return 0;
}

/**
* Tell if the optimization process is allowed to backup in this context.
Expand Down
11 changes: 6 additions & 5 deletions classes/Context/Noop.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,17 @@ public function get_thumbnail_sizes() {
}

/**
* Tell if the optimization process is allowed resize in this context.
* Get images max width for this context. This is used when resizing.
* 0 means to not resize.
*
* @since 1.9
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return bool
* @return int
*/
public function can_resize() {
return false;
public function get_resizing_threshold() {
return 0;
}

/**
Expand Down
31 changes: 23 additions & 8 deletions classes/Context/WP.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ class WP extends AbstractContext {
*/
protected $context = 'wp';

/**
* Images max width for this context. This is used when resizing.
*
* @var int
* @since 1.9.8
* @access protected
* @author Grégory Viguier
*/
protected $resizing_threshold;

/**
* Get the thumbnail sizes for this context, except the full size.
*
Expand Down Expand Up @@ -50,22 +60,27 @@ public function get_thumbnail_sizes() {
}

/**
* Tell if the optimization process is allowed resize in this context.
* Get images max width for this context. This is used when resizing.
* 0 means to not resize.
*
* @since 1.9
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return bool
* @return int
*/
public function can_resize() {
if ( isset( $this->can_resize ) ) {
return $this->can_resize;
public function get_resizing_threshold() {
if ( isset( $this->resizing_threshold ) ) {
return $this->resizing_threshold;
}

$this->can_resize = get_imagify_option( 'resize_larger' ) && get_imagify_option( 'resize_larger_w' ) > 0;
if ( ! get_imagify_option( 'resize_larger' ) ) {
$this->resizing_threshold = 0;
} else {
$this->resizing_threshold = max( 0, get_imagify_option( 'resize_larger_w' ) );
}

return $this->can_resize;
return $this->resizing_threshold;
}

/**
Expand Down
42 changes: 35 additions & 7 deletions classes/Media/AbstractMedia.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,41 @@ public function get_original_path() {
return false;
}

$backup_path = $this->get_raw_original_path();
$original_path = $this->get_raw_original_path();

if ( ! $backup_path || ! $this->filesystem->exists( $backup_path ) ) {
if ( ! $original_path || ! $this->filesystem->exists( $original_path ) ) {
return false;
}

return $backup_path;
return $original_path;
}


/** ----------------------------------------------------------------------------------------- */
/** FULL SIZE FILE ========================================================================== */
/** ----------------------------------------------------------------------------------------- */

/**
* Get the path to the media’s full size file if the file exists.
*
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return string|bool The file path. False if it doesn't exist.
*/
public function get_fullsize_path() {
if ( ! $this->is_valid() ) {
return false;
}

$original_path = $this->get_raw_fullsize_path();

if ( ! $original_path || ! $this->filesystem->exists( $original_path ) ) {
return false;
}

return $original_path;
}


Expand Down Expand Up @@ -398,7 +426,7 @@ public function update_dimensions() {
return false;
}

$dimensions = $this->filesystem->get_image_size( $this->get_raw_original_path() );
$dimensions = $this->filesystem->get_image_size( $this->get_raw_fullsize_path() );

if ( ! $dimensions ) {
// Could not get the new dimensions.
Expand Down Expand Up @@ -487,7 +515,7 @@ protected function get_file_type() {
return $this->file_type;
}

$path = $this->get_raw_original_path();
$path = $this->get_raw_fullsize_path();

if ( ! $path ) {
return $this->file_type;
Expand All @@ -506,7 +534,7 @@ protected function get_file_type() {
* @see $this->get_media_files()
* @author Grégory Viguier
*
* @param array $files An array with the size names as keys ('full' is used for the original file), and arrays of data as values.
* @param array $files An array with the size names as keys ('full' is used for the full size file), and arrays of data as values.
* @return array
*/
protected function filter_media_files( $files ) {
Expand All @@ -516,7 +544,7 @@ protected function filter_media_files( $files ) {
* @since 1.9
* @author Grégory Viguier
*
* @param array $files An array with the size names as keys ('full' is used for the original file), and arrays of data as values.
* @param array $files An array with the size names as keys ('full' is used for the full size file), and arrays of data as values.
* @param MediaInterface $media This instance.
*/
return (array) apply_filters( 'imagify_media_files', $files, $this );
Expand Down
53 changes: 43 additions & 10 deletions classes/Media/CustomFolders.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
class CustomFolders extends AbstractMedia {
use \Imagify\Traits\MediaRowTrait;
use \Imagify\Deprecated\Traits\Media\CustomFoldersDeprecatedTrait;

/**
* Context (where the media "comes from").
Expand Down Expand Up @@ -90,15 +91,47 @@ public static function constructor_accepts( $id ) {
/** ----------------------------------------------------------------------------------------- */

/**
* Get the original media's URL.
* Get the original media's path.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @return string|bool The file path. False on failure.
*/
public function get_raw_original_path() {
if ( ! $this->is_valid() ) {
return false;
}

if ( $this->get_cdn() ) {
return $this->get_cdn()->get_file_path( 'original' );
}

$row = $this->get_row();

if ( ! $row || empty( $row['path'] ) ) {
return false;
}

return \Imagify_Files_Scan::remove_placeholder( $row['path'] );
}


/** ----------------------------------------------------------------------------------------- */
/** FULL SIZE FILE ========================================================================== */
/** ----------------------------------------------------------------------------------------- */

/**
* Get the URL of the media’s full size file.
*
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return string|bool The file URL. False on failure.
*/
public function get_original_url() {
public function get_fullsize_url() {
if ( ! $this->is_valid() ) {
return false;
}
Expand All @@ -117,15 +150,15 @@ public function get_original_url() {
}

/**
* Get the original media's path.
* Get the path to the media’s full size file, even if the file doesn't exist.
*
* @since 1.9
* @since 1.9.8
* @access public
* @author Grégory Viguier
*
* @return string|bool The file path. False on failure.
*/
public function get_raw_original_path() {
public function get_raw_fullsize_path() {
if ( ! $this->is_valid() ) {
return false;
}
Expand Down Expand Up @@ -224,14 +257,14 @@ public function has_required_media_data() {
}

/**
* Get the list of the files of this media, including the original file.
* Get the list of the files of this media, including the full size file.
*
* @since 1.9
* @access public
* @author Grégory Viguier
*
* @return array {
* An array with the size names as keys ('full' is used for the original file), and arrays of data as values:
* An array with the size names as keys ('full' is used for the full size file), and arrays of data as values:
*
* @type string $size The size name.
* @type string $path Absolute path to the file.
Expand All @@ -246,17 +279,17 @@ public function get_media_files() {
return [];
}

$original_path = $this->get_raw_original_path();
$fullsize_path = $this->get_raw_fullsize_path();

if ( ! $original_path ) {
if ( ! $fullsize_path ) {
return [];
}

$dimensions = $this->get_dimensions();
$sizes = [
'full' => [
'size' => 'full',
'path' => $original_path,
'path' => $fullsize_path,
'width' => $dimensions['width'],
'height' => $dimensions['height'],
'mime-type' => $this->get_mime_type(),
Expand Down
Loading

0 comments on commit b7bd072

Please sign in to comment.