| 1 |
<?php |
| 2 |
/** |
| 3 |
* Handles image optimization and compression. |
| 4 |
* |
| 5 |
* @package WP_Defender\Integrations |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WP_Defender\Integrations; |
| 9 |
|
| 10 |
if ( ! defined( 'ABSPATH' ) ) { |
| 11 |
die; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Smush integration module. |
| 16 |
* |
| 17 |
* @since 2.5.1 |
| 18 |
*/ |
| 19 |
class Smush { |
| 20 |
|
| 21 |
/** |
| 22 |
* Table name. |
| 23 |
* |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
private $table; |
| 27 |
|
| 28 |
/** |
| 29 |
* Constructor for the class. |
| 30 |
* Initializes the table name for the Smush directory images. |
| 31 |
* |
| 32 |
* @return void |
| 33 |
*/ |
| 34 |
public function __construct() { |
| 35 |
global $wpdb; |
| 36 |
$this->table = $wpdb->base_prefix . 'smush_dir_images'; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Check if the table exists |
| 41 |
* |
| 42 |
* @return bool |
| 43 |
*/ |
| 44 |
public function exist_image_table() { |
| 45 |
global $wpdb; |
| 46 |
|
| 47 |
return (bool) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 48 |
$wpdb->prepare( |
| 49 |
'SHOW TABLES LIKE %s', |
| 50 |
$wpdb->esc_like( $this->table ) |
| 51 |
) |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Check optimized image path |
| 57 |
* |
| 58 |
* @param string $path image path. |
| 59 |
* |
| 60 |
* @return bool |
| 61 |
*/ |
| 62 |
public function exist_image_path( $path ) { |
| 63 |
global $wpdb; |
| 64 |
return (bool) $wpdb->get_var( // phpcs:ignore WordPress.DB.DirectDatabaseQuery |
| 65 |
$wpdb->prepare( |
| 66 |
"SELECT id FROM {$this->table} WHERE path = %s", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 67 |
$path |
| 68 |
) |
| 69 |
); |
| 70 |
} |
| 71 |
} |
| 72 |
|