Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/wp-conte.../plugins/wp-smush.../core/modules
File: class-dir.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* Directory Smush: Dir class
[2] Fix | Delete
*
[3] Fix | Delete
* @package Smush\Core\Modules
[4] Fix | Delete
* @since 2.6
[5] Fix | Delete
*
[6] Fix | Delete
* @author Umesh Kumar <umesh@incsub.com>
[7] Fix | Delete
*
[8] Fix | Delete
* @copyright (c) 2016, Incsub (http://incsub.com)
[9] Fix | Delete
*/
[10] Fix | Delete
[11] Fix | Delete
namespace Smush\Core\Modules;
[12] Fix | Delete
[13] Fix | Delete
use Exception;
[14] Fix | Delete
use RecursiveDirectoryIterator;
[15] Fix | Delete
use RecursiveIteratorIterator;
[16] Fix | Delete
use Smush\Core\Core;
[17] Fix | Delete
use Smush\Core\Installer;
[18] Fix | Delete
use Smush\Core\Settings;
[19] Fix | Delete
use Smush\Core\Helper;
[20] Fix | Delete
use WP_Error;
[21] Fix | Delete
use WP_Smush;
[22] Fix | Delete
[23] Fix | Delete
if ( ! defined( 'WPINC' ) ) {
[24] Fix | Delete
die;
[25] Fix | Delete
}
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Class Dir
[29] Fix | Delete
*/
[30] Fix | Delete
class Dir extends Abstract_Module {
[31] Fix | Delete
/**
[32] Fix | Delete
* Contains a list of optimised images.
[33] Fix | Delete
*
[34] Fix | Delete
* @var $optimised_images
[35] Fix | Delete
*/
[36] Fix | Delete
public $optimised_images;
[37] Fix | Delete
[38] Fix | Delete
/**
[39] Fix | Delete
* Flag to check if dir smush table exist.
[40] Fix | Delete
*
[41] Fix | Delete
* @var $table_exist
[42] Fix | Delete
*/
[43] Fix | Delete
public static $table_exist;
[44] Fix | Delete
[45] Fix | Delete
/**
[46] Fix | Delete
* Total Stats for the image optimisation.
[47] Fix | Delete
*
[48] Fix | Delete
* @var $stats
[49] Fix | Delete
*/
[50] Fix | Delete
public $stats;
[51] Fix | Delete
[52] Fix | Delete
/**
[53] Fix | Delete
* Directory scanner.
[54] Fix | Delete
*
[55] Fix | Delete
* @var Helpers\DScanner
[56] Fix | Delete
*/
[57] Fix | Delete
public $scanner;
[58] Fix | Delete
[59] Fix | Delete
/**
[60] Fix | Delete
* Dir constructor.
[61] Fix | Delete
*/
[62] Fix | Delete
public function init() {
[63] Fix | Delete
// We only run in admin.
[64] Fix | Delete
if ( ! is_admin() ) {
[65] Fix | Delete
return;
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Handle Ajax request 'smush_get_directory_list'.
[70] Fix | Delete
*
[71] Fix | Delete
* This needs to be before self::should_continue so that the request from network admin is processed.
[72] Fix | Delete
*/
[73] Fix | Delete
if ( wp_doing_ajax() ) {
[74] Fix | Delete
if ( ! $this->scanner ) {
[75] Fix | Delete
$this->scanner = new Helpers\DScanner();
[76] Fix | Delete
}
[77] Fix | Delete
[78] Fix | Delete
add_action( 'wp_ajax_smush_get_directory_list', array( $this, 'directory_list' ) );
[79] Fix | Delete
[80] Fix | Delete
// Scan the given directory path for the list of images.
[81] Fix | Delete
add_action( 'wp_ajax_image_list', array( $this, 'image_list' ) );
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Scanner ajax actions.
[85] Fix | Delete
*
[86] Fix | Delete
* @since 2.8.1
[87] Fix | Delete
*/
[88] Fix | Delete
add_action( 'wp_ajax_directory_smush_start', array( $this, 'directory_smush_start' ) );
[89] Fix | Delete
add_action( 'wp_ajax_directory_smush_check_step', array( $this, 'directory_smush_check_step' ) );
[90] Fix | Delete
add_action( 'wp_ajax_directory_smush_finish', array( $this, 'directory_smush_finish' ) );
[91] Fix | Delete
add_action( 'wp_ajax_directory_smush_cancel', array( $this, 'directory_smush_cancel' ) );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
add_action( 'current_screen', array( $this, 'initialize' ), 10 );
[95] Fix | Delete
}
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* To get access to get_current_screen(), we need to move this under the current_screen action.
[99] Fix | Delete
*
[100] Fix | Delete
* @since 2.8.0
[101] Fix | Delete
*/
[102] Fix | Delete
public function initialize() {
[103] Fix | Delete
$current_page = '';
[104] Fix | Delete
if ( function_exists( 'get_current_screen' ) ) {
[105] Fix | Delete
$current_screen = get_current_screen();
[106] Fix | Delete
$current_page = ! empty( $current_screen ) ? $current_screen->base : '';
[107] Fix | Delete
}
[108] Fix | Delete
[109] Fix | Delete
if ( false === strpos( $current_page, 'page_smush-directory' ) ) {
[110] Fix | Delete
return;
[111] Fix | Delete
}
[112] Fix | Delete
[113] Fix | Delete
if ( ! self::should_continue() ) {
[114] Fix | Delete
// Remove directory smush from tabs if not required.
[115] Fix | Delete
add_filter( 'smush_setting_tabs', array( $this, 'remove_directory_tab' ) );
[116] Fix | Delete
[117] Fix | Delete
return;
[118] Fix | Delete
}
[119] Fix | Delete
[120] Fix | Delete
if ( ! $this->scanner ) {
[121] Fix | Delete
$this->scanner = new Helpers\DScanner();
[122] Fix | Delete
}
[123] Fix | Delete
[124] Fix | Delete
if ( ! $this->scanner->is_scanning() ) {
[125] Fix | Delete
$this->scanner->reset_scan();
[126] Fix | Delete
}
[127] Fix | Delete
[128] Fix | Delete
// Check and show missing directory smush table error.
[129] Fix | Delete
add_action( 'wp_smush_header_notices', array( $this, 'show_table_error' ) );
[130] Fix | Delete
[131] Fix | Delete
// Check directory smush table after screen is set.
[132] Fix | Delete
add_action( 'current_screen', array( $this, 'check_table' ) );
[133] Fix | Delete
[134] Fix | Delete
// Check to see if the scanner should be running.
[135] Fix | Delete
add_action( 'admin_footer', array( $this, 'check_scan' ) );
[136] Fix | Delete
}
[137] Fix | Delete
[138] Fix | Delete
/**
[139] Fix | Delete
* Do not display Directory smush for subsites.
[140] Fix | Delete
*
[141] Fix | Delete
* @return bool True/False, whether to display the Directory smush or not
[142] Fix | Delete
*/
[143] Fix | Delete
public static function should_continue() {
[144] Fix | Delete
if ( Settings::is_ajax_network_admin() ) {
[145] Fix | Delete
return true;
[146] Fix | Delete
}
[147] Fix | Delete
[148] Fix | Delete
// Do not show directory smush, if not main site in a network.
[149] Fix | Delete
if ( is_multisite() && ( ! is_main_site() || ! is_network_admin() ) ) {
[150] Fix | Delete
return false;
[151] Fix | Delete
}
[152] Fix | Delete
[153] Fix | Delete
return true;
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* Run the scanner on page refresh (if it's running).
[158] Fix | Delete
*
[159] Fix | Delete
* @since 2.8.1
[160] Fix | Delete
*/
[161] Fix | Delete
public function check_scan() {
[162] Fix | Delete
if ( $this->scanner->is_scanning() ) {
[163] Fix | Delete
?>
[164] Fix | Delete
<script>
[165] Fix | Delete
jQuery( document ).ready( function() {
[166] Fix | Delete
jQuery('#wp-smush-progress-dialog').show();
[167] Fix | Delete
window.WP_Smush.directory.scanner.scan();
[168] Fix | Delete
});
[169] Fix | Delete
</script>
[170] Fix | Delete
<?php
[171] Fix | Delete
}
[172] Fix | Delete
}
[173] Fix | Delete
[174] Fix | Delete
/**
[175] Fix | Delete
* Directory Smush: Start smush.
[176] Fix | Delete
*
[177] Fix | Delete
* @since 2.8.1
[178] Fix | Delete
*/
[179] Fix | Delete
public function directory_smush_start() {
[180] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[181] Fix | Delete
// Check for permission.
[182] Fix | Delete
$capability = is_multisite() ? 'manage_network' : 'manage_options';
[183] Fix | Delete
if ( ! Helper::is_user_allowed( $capability ) ) {
[184] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[185] Fix | Delete
}
[186] Fix | Delete
$this->scanner->init_scan();
[187] Fix | Delete
do_action('wp_smush_directory_smush_start');
[188] Fix | Delete
wp_send_json_success();
[189] Fix | Delete
}
[190] Fix | Delete
[191] Fix | Delete
/**
[192] Fix | Delete
* Directory Smush: Smush step.
[193] Fix | Delete
*
[194] Fix | Delete
* @since 2.8.1
[195] Fix | Delete
*/
[196] Fix | Delete
public function directory_smush_check_step() {
[197] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[198] Fix | Delete
[199] Fix | Delete
// Check for permission.
[200] Fix | Delete
$capability = is_multisite() ? 'manage_network' : 'manage_options';
[201] Fix | Delete
if ( ! Helper::is_user_allowed( $capability ) ) {
[202] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
$urls = $this->get_scanned_images();
[206] Fix | Delete
$current_step = isset( $_POST['step'] ) ? absint( $_POST['step'] ) : 0;
[207] Fix | Delete
[208] Fix | Delete
$this->scanner->update_current_step( $current_step );
[209] Fix | Delete
[210] Fix | Delete
if ( isset( $urls[ $current_step ] ) ) {
[211] Fix | Delete
$this->optimise_image( (int) $urls[ $current_step ]['id'] );
[212] Fix | Delete
}
[213] Fix | Delete
[214] Fix | Delete
wp_send_json_success();
[215] Fix | Delete
}
[216] Fix | Delete
[217] Fix | Delete
/**
[218] Fix | Delete
* Directory Smush: Finish smush.
[219] Fix | Delete
*
[220] Fix | Delete
* @since 2.8.1
[221] Fix | Delete
*/
[222] Fix | Delete
public function directory_smush_finish() {
[223] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[224] Fix | Delete
[225] Fix | Delete
// Check for permission.
[226] Fix | Delete
$capability = is_multisite() ? 'manage_network' : 'manage_options';
[227] Fix | Delete
if ( ! Helper::is_user_allowed( $capability ) ) {
[228] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[229] Fix | Delete
}
[230] Fix | Delete
[231] Fix | Delete
$items = isset( $_POST['items'] ) ? absint( $_POST['items'] ) : 0;
[232] Fix | Delete
$failed = isset( $_POST['failed'] ) ? absint( $_POST['failed'] ) : 0;
[233] Fix | Delete
$skipped = isset( $_POST['skipped'] ) ? absint( $_POST['skipped'] ) : 0;
[234] Fix | Delete
[235] Fix | Delete
// If any images failed to smush, store count.
[236] Fix | Delete
if ( $failed > 0 ) {
[237] Fix | Delete
set_transient( 'wp-smush-dir-scan-failed-items', $failed, 60 * 5 ); // 5 minutes max.
[238] Fix | Delete
}
[239] Fix | Delete
[240] Fix | Delete
if ( $skipped > 0 ) {
[241] Fix | Delete
set_transient( 'wp-smush-dir-scan-skipped-items', $skipped, 60 * 5 ); // 5 minutes max.
[242] Fix | Delete
}
[243] Fix | Delete
[244] Fix | Delete
// Store optimized items count.
[245] Fix | Delete
set_transient( 'wp-smush-show-dir-scan-notice', $items, 60 * 5 ); // 5 minutes max.
[246] Fix | Delete
$this->scanner->reset_scan();
[247] Fix | Delete
wp_send_json_success();
[248] Fix | Delete
}
[249] Fix | Delete
[250] Fix | Delete
/**
[251] Fix | Delete
* Directory Smush: Cancel smush.
[252] Fix | Delete
*
[253] Fix | Delete
* @since 2.8.1
[254] Fix | Delete
*/
[255] Fix | Delete
public function directory_smush_cancel() {
[256] Fix | Delete
check_ajax_referer( 'wp-smush-ajax' );
[257] Fix | Delete
// Check for permission.
[258] Fix | Delete
$capability = is_multisite() ? 'manage_network' : 'manage_options';
[259] Fix | Delete
if ( ! Helper::is_user_allowed( $capability ) ) {
[260] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[261] Fix | Delete
}
[262] Fix | Delete
$this->scanner->reset_scan();
[263] Fix | Delete
wp_send_json_success();
[264] Fix | Delete
}
[265] Fix | Delete
[266] Fix | Delete
/**
[267] Fix | Delete
* Handles the ajax request for image optimisation in a folder
[268] Fix | Delete
*
[269] Fix | Delete
* @param int $id Image ID.
[270] Fix | Delete
*/
[271] Fix | Delete
private function optimise_image( $id ) {
[272] Fix | Delete
global $wpdb;
[273] Fix | Delete
[274] Fix | Delete
$error_msg = '';
[275] Fix | Delete
[276] Fix | Delete
// No image ID.
[277] Fix | Delete
if ( $id < 1 ) {
[278] Fix | Delete
$error_msg = esc_html__( 'Incorrect image id', 'wp-smushit' );
[279] Fix | Delete
wp_send_json_error( $error_msg );
[280] Fix | Delete
}
[281] Fix | Delete
[282] Fix | Delete
// Check smush limit for free users.
[283] Fix | Delete
if ( ! WP_Smush::is_pro() ) {
[284] Fix | Delete
// Free version bulk smush, check the transient counter value.
[285] Fix | Delete
$should_continue = Core::check_bulk_limit( false, 'dir_sent_count' );
[286] Fix | Delete
[287] Fix | Delete
// Send a error for the limit.
[288] Fix | Delete
if ( ! $should_continue ) {
[289] Fix | Delete
wp_send_json_error(
[290] Fix | Delete
array(
[291] Fix | Delete
'error' => 'dir_smush_limit_exceeded',
[292] Fix | Delete
'continue' => false,
[293] Fix | Delete
)
[294] Fix | Delete
);
[295] Fix | Delete
}
[296] Fix | Delete
}
[297] Fix | Delete
[298] Fix | Delete
$scanned_images = $this->get_unsmushed_images();
[299] Fix | Delete
$image = $this->get_image( $id, '', $scanned_images );
[300] Fix | Delete
[301] Fix | Delete
if ( empty( $image ) ) {
[302] Fix | Delete
wp_send_json_success( array( 'skipped' => true ) );
[303] Fix | Delete
}
[304] Fix | Delete
[305] Fix | Delete
$path = $image['path'];
[306] Fix | Delete
[307] Fix | Delete
if ( false !== stripos( $path, 'phar://' ) ) {
[308] Fix | Delete
wp_send_json_error(
[309] Fix | Delete
array(
[310] Fix | Delete
'error' => esc_html__( 'Potential Phar PHP Object Injection detected', 'wp-smushit' ),
[311] Fix | Delete
'image' => array(
[312] Fix | Delete
'id' => $id,
[313] Fix | Delete
),
[314] Fix | Delete
)
[315] Fix | Delete
);
[316] Fix | Delete
}
[317] Fix | Delete
[318] Fix | Delete
// We have the image path, optimise.
[319] Fix | Delete
$results = WP_Smush::get_instance()->core()->mod->smush->do_smushit( $path );
[320] Fix | Delete
[321] Fix | Delete
if ( is_wp_error( $results ) ) {
[322] Fix | Delete
/**
[323] Fix | Delete
* Smush results.
[324] Fix | Delete
*
[325] Fix | Delete
* @var WP_Error $results
[326] Fix | Delete
*/
[327] Fix | Delete
$error_msg = $results->get_error_message();
[328] Fix | Delete
} elseif ( empty( $results['data'] ) ) {
[329] Fix | Delete
// If there are no stats.
[330] Fix | Delete
$error_msg = esc_html__( "Image couldn't be optimized", 'wp-smushit' );
[331] Fix | Delete
}
[332] Fix | Delete
[333] Fix | Delete
if ( ! empty( $error_msg ) ) {
[334] Fix | Delete
// Store the error in DB. All good, Update the stats.
[335] Fix | Delete
$wpdb->query(
[336] Fix | Delete
$wpdb->prepare(
[337] Fix | Delete
"UPDATE {$wpdb->base_prefix}smush_dir_images SET error=%s WHERE id=%d LIMIT 1",
[338] Fix | Delete
$error_msg,
[339] Fix | Delete
$id
[340] Fix | Delete
)
[341] Fix | Delete
); // Db call ok; no-cache ok.
[342] Fix | Delete
[343] Fix | Delete
wp_send_json_error(
[344] Fix | Delete
array(
[345] Fix | Delete
'error' => $error_msg,
[346] Fix | Delete
'image' => array(
[347] Fix | Delete
'id' => $id,
[348] Fix | Delete
),
[349] Fix | Delete
)
[350] Fix | Delete
);
[351] Fix | Delete
}
[352] Fix | Delete
[353] Fix | Delete
if ( ! $this->settings ) {
[354] Fix | Delete
$this->settings = Settings::get_instance();
[355] Fix | Delete
}
[356] Fix | Delete
[357] Fix | Delete
// All good, Update the stats.
[358] Fix | Delete
$wpdb->query(
[359] Fix | Delete
$wpdb->prepare(
[360] Fix | Delete
"UPDATE {$wpdb->base_prefix}smush_dir_images SET error=NULL, image_size=%d, file_time=%d, lossy=%d, meta=%d WHERE id=%d LIMIT 1",
[361] Fix | Delete
$results['data']->after_size,
[362] Fix | Delete
filectime( $path ), // Get file time.
[363] Fix | Delete
$this->settings->get( 'lossy' ),
[364] Fix | Delete
$this->settings->get( 'strip_exif' ),
[365] Fix | Delete
$id
[366] Fix | Delete
)
[367] Fix | Delete
); // Db call ok; no-cache ok.
[368] Fix | Delete
[369] Fix | Delete
// Update bulk limit transient.
[370] Fix | Delete
Core::update_smush_count( 'dir_sent_count' );
[371] Fix | Delete
}
[372] Fix | Delete
[373] Fix | Delete
/**
[374] Fix | Delete
* Create the Smush image table to store the paths of scanned images, and stats
[375] Fix | Delete
*/
[376] Fix | Delete
public function create_table() {
[377] Fix | Delete
// If table is already created, returns.
[378] Fix | Delete
if ( self::table_exist() ) {
[379] Fix | Delete
return;
[380] Fix | Delete
}
[381] Fix | Delete
global $wpdb;
[382] Fix | Delete
[383] Fix | Delete
$charset_collate = $wpdb->get_charset_collate();
[384] Fix | Delete
[385] Fix | Delete
/**
[386] Fix | Delete
* Table: wp_smush_dir_images
[387] Fix | Delete
* Columns:
[388] Fix | Delete
* id -> Auto Increment ID
[389] Fix | Delete
* path -> Absolute path to the image file
[390] Fix | Delete
* resize -> Whether the image was resized or not
[391] Fix | Delete
* lossy -> Whether the image was super-smushed/lossy or not
[392] Fix | Delete
* image_size -> Current image size post optimisation
[393] Fix | Delete
* orig_size -> Original image size before optimisation
[394] Fix | Delete
* file_time -> Unix time for the file creation, to match it against the current creation time,
[395] Fix | Delete
* in order to confirm if it is optimised or not
[396] Fix | Delete
* last_scan -> Timestamp, Get images form last scan by latest timestamp
[397] Fix | Delete
* are from latest scan only and not the whole list from db
[398] Fix | Delete
* meta -> For any future use
[399] Fix | Delete
*/
[400] Fix | Delete
$sql = "CREATE TABLE IF NOT EXISTS {$wpdb->base_prefix}smush_dir_images (
[401] Fix | Delete
id mediumint(9) UNSIGNED NOT NULL AUTO_INCREMENT,
[402] Fix | Delete
path text NOT NULL,
[403] Fix | Delete
path_hash CHAR(32),
[404] Fix | Delete
resize varchar(55),
[405] Fix | Delete
lossy varchar(55),
[406] Fix | Delete
error varchar(55) DEFAULT NULL,
[407] Fix | Delete
image_size int(10) unsigned,
[408] Fix | Delete
orig_size int(10) unsigned,
[409] Fix | Delete
file_time int(10) unsigned,
[410] Fix | Delete
last_scan timestamp DEFAULT '0000-00-00 00:00:00',
[411] Fix | Delete
meta text,
[412] Fix | Delete
PRIMARY KEY (id),
[413] Fix | Delete
UNIQUE KEY path_hash (path_hash),
[414] Fix | Delete
KEY image_size (image_size)
[415] Fix | Delete
) $charset_collate;";
[416] Fix | Delete
[417] Fix | Delete
// Include the upgrade library to initialize a table.
[418] Fix | Delete
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
[419] Fix | Delete
/**
[420] Fix | Delete
* PHP 8.1 trigger an error when calling query "DESCRIBE {$table};" if the table doesn't exists.
[421] Fix | Delete
* Since we only create table when it doesn't exists, so don't need to use dbDelta for this case.
[422] Fix | Delete
*/
[423] Fix | Delete
// Hide errors.
[424] Fix | Delete
$wpdb->hide_errors();
[425] Fix | Delete
// Create table.
[426] Fix | Delete
$wpdb->query( $sql );
[427] Fix | Delete
[428] Fix | Delete
// Set flag.
[429] Fix | Delete
self::$table_exist = self::table_exist( true );
[430] Fix | Delete
}
[431] Fix | Delete
[432] Fix | Delete
/**
[433] Fix | Delete
* Get the image ids and path for last scanned images
[434] Fix | Delete
*
[435] Fix | Delete
* @return array Array of last scanned images containing image id and path
[436] Fix | Delete
*/
[437] Fix | Delete
public function get_scanned_images() {
[438] Fix | Delete
global $wpdb;
[439] Fix | Delete
[440] Fix | Delete
$results = $wpdb->get_results( "SELECT id, path, orig_size FROM {$wpdb->base_prefix}smush_dir_images WHERE last_scan = (SELECT MAX(last_scan) FROM {$wpdb->base_prefix}smush_dir_images ) GROUP BY id ORDER BY id", ARRAY_A ); // Db call ok; no-cache ok.
[441] Fix | Delete
[442] Fix | Delete
// Return image ids.
[443] Fix | Delete
if ( is_wp_error( $results ) ) {
[444] Fix | Delete
Helper::logger()->dir()->error( sprintf( 'Query error: %s', $results->get_error_message() ) );
[445] Fix | Delete
$results = array();
[446] Fix | Delete
}
[447] Fix | Delete
[448] Fix | Delete
return $results;
[449] Fix | Delete
}
[450] Fix | Delete
[451] Fix | Delete
/**
[452] Fix | Delete
* Get only images that need compressing.
[453] Fix | Delete
*
[454] Fix | Delete
* @since 3.6.1
[455] Fix | Delete
*
[456] Fix | Delete
* @return array Array of images that require compression.
[457] Fix | Delete
*/
[458] Fix | Delete
public function get_unsmushed_images() {
[459] Fix | Delete
global $wpdb;
[460] Fix | Delete
[461] Fix | Delete
$condition = 'image_size IS NULL';
[462] Fix | Delete
if ( $this->settings->get( 'lossy' ) ) {
[463] Fix | Delete
$condition .= ' OR lossy <> 1';
[464] Fix | Delete
}
[465] Fix | Delete
[466] Fix | Delete
if ( $this->settings->get( 'strip_exif' ) ) {
[467] Fix | Delete
$condition .= ' OR meta <> 1';
[468] Fix | Delete
}
[469] Fix | Delete
[470] Fix | Delete
$results = $wpdb->get_results( "SELECT id, path, orig_size FROM {$wpdb->base_prefix}smush_dir_images WHERE {$condition} && last_scan = (SELECT MAX(last_scan) FROM {$wpdb->base_prefix}smush_dir_images ) GROUP BY id ORDER BY id", ARRAY_A ); // Db call ok; no-cache ok.
[471] Fix | Delete
[472] Fix | Delete
// Return image ids.
[473] Fix | Delete
if ( is_wp_error( $results ) ) {
[474] Fix | Delete
Helper::logger()->dir()->error( sprintf( 'Query error: %s', $results->get_error_message() ) );
[475] Fix | Delete
$results = array();
[476] Fix | Delete
}
[477] Fix | Delete
[478] Fix | Delete
return $results;
[479] Fix | Delete
}
[480] Fix | Delete
[481] Fix | Delete
/**
[482] Fix | Delete
* Get the paths and errors from last scan.
[483] Fix | Delete
*
[484] Fix | Delete
* @since 3.0
[485] Fix | Delete
*
[486] Fix | Delete
* @return array Array of last scanned images
[487] Fix | Delete
*/
[488] Fix | Delete
public function get_image_errors() {
[489] Fix | Delete
global $wpdb;
[490] Fix | Delete
[491] Fix | Delete
return $wpdb->get_results(
[492] Fix | Delete
"SELECT id, path, error
[493] Fix | Delete
FROM {$wpdb->base_prefix}smush_dir_images
[494] Fix | Delete
WHERE error IS NOT NULL
[495] Fix | Delete
AND last_scan = ( SELECT MAX(last_scan) FROM {$wpdb->base_prefix}smush_dir_images )
[496] Fix | Delete
LIMIT 20",
[497] Fix | Delete
ARRAY_A
[498] Fix | Delete
); // Db call ok; no-cache ok.
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function