| 1 |
<?php |
| 2 |
namespace Imagify\Context; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 5 |
|
| 6 |
/** |
| 7 |
* Context class used for the custom folders. |
| 8 |
* |
| 9 |
* @since 1.9 |
| 10 |
* @author Grégory Viguier |
| 11 |
*/ |
| 12 |
class CustomFolders extends AbstractContext { |
| 13 |
use \Imagify\Traits\InstanceGetterTrait; |
| 14 |
|
| 15 |
/** |
| 16 |
* Context "short name". |
| 17 |
* |
| 18 |
* @var string |
| 19 |
* @since 1.9 |
| 20 |
* @access protected |
| 21 |
* @author Grégory Viguier |
| 22 |
*/ |
| 23 |
protected $context = 'custom-folders'; |
| 24 |
|
| 25 |
/** |
| 26 |
* The thumbnail sizes for this context, except the full size. |
| 27 |
* |
| 28 |
* @var array { |
| 29 |
* Data for the currently registered thumbnail sizes. |
| 30 |
* Size names are used as array keys. |
| 31 |
* |
| 32 |
* @type int $width The image width. |
| 33 |
* @type int $height The image height. |
| 34 |
* @type bool $crop True to crop, false to resize. |
| 35 |
* @type string $name The size name. |
| 36 |
* } |
| 37 |
* @since 1.9 |
| 38 |
* @access public |
| 39 |
* @author Grégory Viguier |
| 40 |
*/ |
| 41 |
protected $thumbnail_sizes = []; |
| 42 |
|
| 43 |
/** |
| 44 |
* Get images max width for this context. This is used when resizing. |
| 45 |
* 0 means to not resize. |
| 46 |
* |
| 47 |
* @since 1.9.8 |
| 48 |
* @access public |
| 49 |
* @author Grégory Viguier |
| 50 |
* |
| 51 |
* @return int |
| 52 |
*/ |
| 53 |
public function get_resizing_threshold() { |
| 54 |
return 0; |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Tell if the optimization process is allowed to backup in this context. |
| 59 |
* |
| 60 |
* @since 1.9 |
| 61 |
* @access public |
| 62 |
* @author Grégory Viguier |
| 63 |
* |
| 64 |
* @return bool |
| 65 |
*/ |
| 66 |
public function can_backup() { |
| 67 |
if ( isset( $this->can_backup ) ) { |
| 68 |
return $this->can_backup; |
| 69 |
} |
| 70 |
|
| 71 |
$this->can_backup = get_imagify_option( 'backup' ); |
| 72 |
|
| 73 |
return $this->can_backup; |
| 74 |
} |
| 75 |
|
| 76 |
/** |
| 77 |
* Tell if the optimization process is allowed to keep exif in this context. |
| 78 |
* |
| 79 |
* @since 1.9 |
| 80 |
* @access public |
| 81 |
* @author Grégory Viguier |
| 82 |
* |
| 83 |
* @return bool |
| 84 |
*/ |
| 85 |
public function can_keep_exif() { |
| 86 |
if ( isset( $this->can_keep_exif ) ) { |
| 87 |
return $this->can_keep_exif; |
| 88 |
} |
| 89 |
|
| 90 |
$this->can_keep_exif = get_imagify_option( 'exif' ); |
| 91 |
|
| 92 |
return $this->can_keep_exif; |
| 93 |
} |
| 94 |
|
| 95 |
/** |
| 96 |
* Get user capacity to operate Imagify in this context. |
| 97 |
* |
| 98 |
* @since 1.9 |
| 99 |
* @access public |
| 100 |
* @author Grégory Viguier |
| 101 |
* |
| 102 |
* @param string $describer Capacity describer. Possible values are like 'manage', 'bulk-optimize', 'manual-optimize', 'auto-optimize'. |
| 103 |
* @return string |
| 104 |
*/ |
| 105 |
public function get_capacity( $describer ) { |
| 106 |
switch ( $describer ) { |
| 107 |
case 'manage': |
| 108 |
$capacity = imagify_is_active_for_network() ? 'manage_network_options' : 'manage_options'; |
| 109 |
break; |
| 110 |
|
| 111 |
case 'bulk-optimize': |
| 112 |
case 'optimize': |
| 113 |
case 'restore': |
| 114 |
case 'manual-optimize': |
| 115 |
case 'manual-restore': |
| 116 |
case 'auto-optimize': |
| 117 |
$capacity = is_multisite() ? 'manage_network_options' : 'manage_options'; |
| 118 |
break; |
| 119 |
|
| 120 |
default: |
| 121 |
$capacity = $describer; |
| 122 |
} |
| 123 |
|
| 124 |
return $this->filter_capacity( $capacity, $describer ); |
| 125 |
} |
| 126 |
} |
| 127 |
|