| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
* Class Optml_Filters. |
| 5 |
* |
| 6 |
* @package \Optml\Inc |
| 7 |
* @author Optimole <friends@optimole.com> |
| 8 |
*/ |
| 9 |
final class Optml_Filters { |
| 10 |
|
| 11 |
/** |
| 12 |
* Generic method to check if the page is allowed to do the action. |
| 13 |
* |
| 14 |
* @param array $flags Flags array. |
| 15 |
* |
| 16 |
* @return bool Should do action on page? |
| 17 |
*/ |
| 18 |
public static function should_do_page( $flags ) { |
| 19 |
if ( ! isset( $_SERVER['REQUEST_URI'] ) ) { |
| 20 |
return true; |
| 21 |
} |
| 22 |
foreach ( $flags as $rule_flag => $status ) { |
| 23 |
if ( strpos( $_SERVER['REQUEST_URI'], $rule_flag ) !== false ) { |
| 24 |
return false; |
| 25 |
} |
| 26 |
if ( $rule_flag === 'home' && ( empty( $_SERVER['REQUEST_URI'] ) || $_SERVER['REQUEST_URI'] === '/' ) ) { |
| 27 |
return false; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Check if image qualifies for processing. |
| 36 |
* |
| 37 |
* @param string $image_url Image url. |
| 38 |
* @param array $flags Flags array. |
| 39 |
* |
| 40 |
* @return bool Should we process the image? |
| 41 |
*/ |
| 42 |
public static function should_do_image( $image_url, $flags ) { |
| 43 |
|
| 44 |
foreach ( $flags as $rule_flag => $status ) { |
| 45 |
if ( strpos( $image_url, $rule_flag ) !== false ) { |
| 46 |
return false; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
return true; |
| 51 |
|
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* |
| 56 |
* Check if the image should be processed based on the extension. |
| 57 |
* |
| 58 |
* @param array $flags Flags array. |
| 59 |
* @param string $ext Extension string. |
| 60 |
* |
| 61 |
* @return bool Should we do the processing? |
| 62 |
*/ |
| 63 |
public static function should_do_extension( $flags, $ext ) { |
| 64 |
foreach ( $flags as $rule_flag => $status ) { |
| 65 |
if ( $rule_flag === $ext ) { |
| 66 |
return false; |
| 67 |
} |
| 68 |
} |
| 69 |
|
| 70 |
return $ext; |
| 71 |
} |
| 72 |
} |
| 73 |
|