| 1 |
<?php |
| 2 |
namespace Imagify\ThirdParty\NGG; |
| 3 |
|
| 4 |
defined( 'ABSPATH' ) || die( 'Cheatin’ uh?' ); |
| 5 |
|
| 6 |
/** |
| 7 |
* Imagify NextGen Gallery class. |
| 8 |
* |
| 9 |
* @since 1.5 |
| 10 |
* @author Jonathan Buttigieg |
| 11 |
*/ |
| 12 |
class Main { |
| 13 |
use \Imagify\Traits\InstanceGetterTrait; |
| 14 |
|
| 15 |
/** |
| 16 |
* Class version. |
| 17 |
* |
| 18 |
* @var string |
| 19 |
*/ |
| 20 |
const VERSION = '1.1'; |
| 21 |
|
| 22 |
/** |
| 23 |
* The constructor. |
| 24 |
* |
| 25 |
* @since 1.5 |
| 26 |
* @since 1.6.5 Doesn't launch the hooks anymore. |
| 27 |
* @since 1.9 Visibility set to public. |
| 28 |
* @access public |
| 29 |
* @author Jonathan Buttigieg |
| 30 |
*/ |
| 31 |
public function __construct() {} |
| 32 |
|
| 33 |
/** |
| 34 |
* Launch the hooks. |
| 35 |
* |
| 36 |
* @since 1.6.5 |
| 37 |
* @access public |
| 38 |
* @author Grégory Viguier |
| 39 |
*/ |
| 40 |
public function init() { |
| 41 |
static $done = false; |
| 42 |
|
| 43 |
if ( $done ) { |
| 44 |
return; |
| 45 |
} |
| 46 |
$done = true; |
| 47 |
|
| 48 |
add_filter( 'imagify_register_context', [ $this, 'register_context' ] ); |
| 49 |
add_filter( 'imagify_context_class_name', [ $this, 'add_context_class_name' ], 10, 2 ); |
| 50 |
add_filter( 'imagify_process_class_name', [ $this, 'add_process_class_name' ], 10, 2 ); |
| 51 |
add_filter( 'imagify_bulk_class_name', [ $this, 'add_bulk_class_name' ], 10, 2 ); |
| 52 |
add_action( 'init', [ $this, 'add_mixin' ] ); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Register the context used for NGG. |
| 57 |
* |
| 58 |
* @since 1.9 |
| 59 |
* @access public |
| 60 |
* @author Grégory Viguier |
| 61 |
* |
| 62 |
* @param array $contexts An array of context names. |
| 63 |
* @return array |
| 64 |
*/ |
| 65 |
public function register_context( $contexts ) { |
| 66 |
$contexts[] = 'ngg'; |
| 67 |
return $contexts; |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Filter the name of the class to use to define a context. |
| 72 |
* |
| 73 |
* @since 1.9 |
| 74 |
* @access public |
| 75 |
* @author Grégory Viguier |
| 76 |
* |
| 77 |
* @param int $class_name The class name. |
| 78 |
* @param string $context The context name. |
| 79 |
* @return string |
| 80 |
*/ |
| 81 |
public function add_context_class_name( $class_name, $context ) { |
| 82 |
if ( 'ngg' === $context ) { |
| 83 |
return '\\Imagify\\ThirdParty\\NGG\\Context\\NGG'; |
| 84 |
} |
| 85 |
|
| 86 |
return $class_name; |
| 87 |
} |
| 88 |
|
| 89 |
/** |
| 90 |
* Filter the name of the class to use for the optimization. |
| 91 |
* |
| 92 |
* @since 1.9 |
| 93 |
* @access public |
| 94 |
* @author Grégory Viguier |
| 95 |
* |
| 96 |
* @param int $class_name The class name. |
| 97 |
* @param string $context The context name. |
| 98 |
* @return string |
| 99 |
*/ |
| 100 |
public function add_process_class_name( $class_name, $context ) { |
| 101 |
if ( 'ngg' === $context ) { |
| 102 |
return '\\Imagify\\ThirdParty\\NGG\\Optimization\\Process\\NGG'; |
| 103 |
} |
| 104 |
|
| 105 |
return $class_name; |
| 106 |
} |
| 107 |
|
| 108 |
/** |
| 109 |
* Filter the name of the class to use for the bulk optimization. |
| 110 |
* |
| 111 |
* @since 1.9 |
| 112 |
* @access public |
| 113 |
* @author Grégory Viguier |
| 114 |
* |
| 115 |
* @param int $class_name The class name. |
| 116 |
* @param string $context The context name. |
| 117 |
* @return string |
| 118 |
*/ |
| 119 |
public function add_bulk_class_name( $class_name, $context ) { |
| 120 |
if ( 'ngg' === $context ) { |
| 121 |
return '\\Imagify\\ThirdParty\\NGG\\Bulk\\NGG'; |
| 122 |
} |
| 123 |
|
| 124 |
return $class_name; |
| 125 |
} |
| 126 |
|
| 127 |
/** |
| 128 |
* Add custom NGG mixin to override its functions. |
| 129 |
* |
| 130 |
* @since 1.5 |
| 131 |
* @access public |
| 132 |
* @author Jonathan Buttigieg |
| 133 |
*/ |
| 134 |
public function add_mixin() { |
| 135 |
\C_Gallery_Storage::get_instance()->get_wrapped_instance()->add_mixin( '\\Imagify\\ThirdParty\\NGG\\NGGStorage' ); |
| 136 |
} |
| 137 |
} |
| 138 |
|