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/integrat...
File: class-nextgen.php
<?php
[0] Fix | Delete
/**
[1] Fix | Delete
* NextGen integration: NextGen class
[2] Fix | Delete
*
[3] Fix | Delete
* @package Smush\Core\Integrations
[4] Fix | Delete
* @version 1.0
[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\Integrations;
[12] Fix | Delete
[13] Fix | Delete
use C_Component_Registry;
[14] Fix | Delete
use C_Gallery_Storage;
[15] Fix | Delete
use Exception;
[16] Fix | Delete
use nggdb;
[17] Fix | Delete
use Smush\Core\Core;
[18] Fix | Delete
use Smush\Core\Helper;
[19] Fix | Delete
use stdClass;
[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 NextGen
[29] Fix | Delete
*/
[30] Fix | Delete
class NextGen extends Abstract_Integration {
[31] Fix | Delete
[32] Fix | Delete
/**
[33] Fix | Delete
* Contains the total Stats, for displaying it on bulk page
[34] Fix | Delete
*
[35] Fix | Delete
* @var array $stats
[36] Fix | Delete
*/
[37] Fix | Delete
public $stats = array(
[38] Fix | Delete
'savings_bytes' => 0,
[39] Fix | Delete
'size_before' => 0,
[40] Fix | Delete
'size_after' => 0,
[41] Fix | Delete
'savings_percent' => 0,
[42] Fix | Delete
);
[43] Fix | Delete
[44] Fix | Delete
/**
[45] Fix | Delete
* NextGen admin module.
[46] Fix | Delete
*
[47] Fix | Delete
* @var Nextgen\Admin
[48] Fix | Delete
*/
[49] Fix | Delete
public $ng_admin;
[50] Fix | Delete
[51] Fix | Delete
/**
[52] Fix | Delete
* NextGen stats module.
[53] Fix | Delete
*
[54] Fix | Delete
* @var Nextgen\Stats
[55] Fix | Delete
*/
[56] Fix | Delete
public $ng_stats;
[57] Fix | Delete
[58] Fix | Delete
/**
[59] Fix | Delete
* Nextgen constructor.
[60] Fix | Delete
*/
[61] Fix | Delete
public function __construct() {
[62] Fix | Delete
$this->module = 'nextgen';
[63] Fix | Delete
$this->class = 'pro';
[64] Fix | Delete
$this->enabled = class_exists( '\C_NextGEN_Bootstrap' );
[65] Fix | Delete
[66] Fix | Delete
parent::__construct();
[67] Fix | Delete
[68] Fix | Delete
$is_pro = WP_Smush::is_pro();
[69] Fix | Delete
[70] Fix | Delete
// Hook at the end of setting row to output a error div.
[71] Fix | Delete
add_action( 'smush_setting_column_right_inside', array( $this, 'additional_notice' ) );
[72] Fix | Delete
[73] Fix | Delete
// Do not continue if not PRO member or NextGen plugin not installed.
[74] Fix | Delete
if ( ! $is_pro || ! $this->enabled || ! $this->is_enabled() ) {
[75] Fix | Delete
// Add Pro tag.
[76] Fix | Delete
add_action( 'smush_setting_column_tag', array( $this, 'add_pro_tag' ) );
[77] Fix | Delete
return;
[78] Fix | Delete
}
[79] Fix | Delete
[80] Fix | Delete
$this->add_mixins();
[81] Fix | Delete
[82] Fix | Delete
add_action( 'admin_init', array( $this, 'init_modules' ) );
[83] Fix | Delete
[84] Fix | Delete
/**
[85] Fix | Delete
* ACTIONS
[86] Fix | Delete
*/
[87] Fix | Delete
// Auto Smush image, if enabled, runs after NextGen is finished uploading the image.
[88] Fix | Delete
// Allows to override whether to auto smush NextGen image or not.
[89] Fix | Delete
$auto_smush = apply_filters( 'smush_nextgen_auto', WP_Smush::get_instance()->core()->mod->smush->is_auto_smush_enabled() );
[90] Fix | Delete
if ( $auto_smush ) {
[91] Fix | Delete
add_action( 'ngg_added_new_image', array( $this, 'auto_smush' ) );
[92] Fix | Delete
}
[93] Fix | Delete
[94] Fix | Delete
// Update Total Image count.
[95] Fix | Delete
add_action( 'ngg_added_new_image', array( $this, 'update_stats_image_count' ), 10 );
[96] Fix | Delete
[97] Fix | Delete
/**
[98] Fix | Delete
* AJAX
[99] Fix | Delete
*/
[100] Fix | Delete
// Single Smush/Manual Smush: Handles the Single/Manual smush request for NextGen Gallery.
[101] Fix | Delete
add_action( 'wp_ajax_smush_manual_nextgen', array( $this, 'manual_nextgen' ) );
[102] Fix | Delete
// Restore Image: Handles the single/Manual restore image request for NextGen Gallery.
[103] Fix | Delete
add_action( 'wp_ajax_smush_restore_nextgen_image', array( $this, 'restore_image' ) );
[104] Fix | Delete
// Resmush Image: Handles the single/Manual resmush image request for NextGen Gallery.
[105] Fix | Delete
add_action( 'wp_ajax_smush_resmush_nextgen_image', array( $this, 'resmush_image' ) );
[106] Fix | Delete
// Bulk Smush NextGen images.
[107] Fix | Delete
add_action( 'wp_ajax_wp_smushit_nextgen_bulk', array( $this, 'smush_bulk' ) );
[108] Fix | Delete
}
[109] Fix | Delete
[110] Fix | Delete
/**************************************
[111] Fix | Delete
*
[112] Fix | Delete
* OVERWRITE PARENT CLASS FUNCTIONALITY
[113] Fix | Delete
*/
[114] Fix | Delete
[115] Fix | Delete
/**
[116] Fix | Delete
* Filters the setting variable to add NextGen setting title and description
[117] Fix | Delete
*
[118] Fix | Delete
* @param array $settings Settings.
[119] Fix | Delete
*
[120] Fix | Delete
* @return mixed
[121] Fix | Delete
*/
[122] Fix | Delete
public function register( $settings ) {
[123] Fix | Delete
$settings[ $this->module ] = array(
[124] Fix | Delete
'label' => esc_html__( 'Enable NextGen Gallery integration', 'wp-smushit' ),
[125] Fix | Delete
'short_label' => esc_html__( 'NextGen Gallery', 'wp-smushit' ),
[126] Fix | Delete
'desc' => esc_html__( 'Allow smushing images directly through NextGen Gallery settings.', 'wp-smushit' ),
[127] Fix | Delete
);
[128] Fix | Delete
[129] Fix | Delete
return $settings;
[130] Fix | Delete
}
[131] Fix | Delete
[132] Fix | Delete
/**
[133] Fix | Delete
* Disable module functionality if not PRO.
[134] Fix | Delete
*
[135] Fix | Delete
* @return bool
[136] Fix | Delete
*/
[137] Fix | Delete
public function setting_status() {
[138] Fix | Delete
return ! WP_Smush::is_pro() ? true : ! $this->enabled;
[139] Fix | Delete
}
[140] Fix | Delete
[141] Fix | Delete
/**************************************
[142] Fix | Delete
*
[143] Fix | Delete
* PUBLIC CLASSES
[144] Fix | Delete
*/
[145] Fix | Delete
[146] Fix | Delete
/**
[147] Fix | Delete
* Initialize the stats and admin modules, once admin is ready.
[148] Fix | Delete
*
[149] Fix | Delete
* @since 3.3.0
[150] Fix | Delete
*/
[151] Fix | Delete
public function init_modules() {
[152] Fix | Delete
$this->ng_stats = new NextGen\Stats();
[153] Fix | Delete
$this->ng_admin = new NextGen\Admin( $this->ng_stats );
[154] Fix | Delete
}
[155] Fix | Delete
[156] Fix | Delete
/**
[157] Fix | Delete
* Check if NextGen integration is active.
[158] Fix | Delete
*
[159] Fix | Delete
* @since 2.9.0
[160] Fix | Delete
*
[161] Fix | Delete
* @return bool|mixed
[162] Fix | Delete
*/
[163] Fix | Delete
public function is_enabled() {
[164] Fix | Delete
return $this->settings->get( 'nextgen' );
[165] Fix | Delete
}
[166] Fix | Delete
[167] Fix | Delete
/**
[168] Fix | Delete
* Bulk Smush for Nextgen.
[169] Fix | Delete
*
[170] Fix | Delete
* @throws Exception Exception.
[171] Fix | Delete
*/
[172] Fix | Delete
public function smush_bulk() {
[173] Fix | Delete
$stats = array();
[174] Fix | Delete
[175] Fix | Delete
check_ajax_referer( 'wp-smush-ajax', '_nonce' );
[176] Fix | Delete
[177] Fix | Delete
// Check For permission.
[178] Fix | Delete
if ( ! Helper::is_user_allowed( 'manage_options' ) ) {
[179] Fix | Delete
wp_die( esc_html__( 'Unauthorized', 'wp-smushit' ), 403 );
[180] Fix | Delete
}
[181] Fix | Delete
[182] Fix | Delete
if ( empty( $_GET['attachment_id'] ) ) {
[183] Fix | Delete
wp_send_json_error(
[184] Fix | Delete
array(
[185] Fix | Delete
'error' => 'missing_id',
[186] Fix | Delete
'error_message' => esc_html__( 'No attachment ID was received', 'wp-smushit' ),
[187] Fix | Delete
'file_name' => 'undefined',
[188] Fix | Delete
)
[189] Fix | Delete
);
[190] Fix | Delete
}
[191] Fix | Delete
[192] Fix | Delete
$atchmnt_id = (int) $_GET['attachment_id'];
[193] Fix | Delete
[194] Fix | Delete
$smush = $this->smush_image( $atchmnt_id, '', true );
[195] Fix | Delete
[196] Fix | Delete
if ( is_wp_error( $smush ) ) {
[197] Fix | Delete
$error_message = $smush->get_error_message();
[198] Fix | Delete
[199] Fix | Delete
// Check for timeout error and suggest to filter timeout.
[200] Fix | Delete
if ( strpos( $error_message, 'timed out' ) ) {
[201] Fix | Delete
$error = 'timeout';
[202] Fix | Delete
$error_message = esc_html__( 'Smush request timed out. You can try setting a higher value ( > 60 ) for `WP_SMUSH_TIMEOUT`.', 'wp-smushit' );
[203] Fix | Delete
}
[204] Fix | Delete
[205] Fix | Delete
$error = isset( $error ) ? $error : 'other';
[206] Fix | Delete
$file_name = $this->get_nextgen_image_from_id( $atchmnt_id );
[207] Fix | Delete
[208] Fix | Delete
wp_send_json_error(
[209] Fix | Delete
array(
[210] Fix | Delete
'error' => $error,
[211] Fix | Delete
'stats' => $stats,
[212] Fix | Delete
'error_message' => $error_message,
[213] Fix | Delete
'file_name' => isset( $file_name->filename ) ? $file_name->filename : 'undefined',
[214] Fix | Delete
)
[215] Fix | Delete
);
[216] Fix | Delete
}
[217] Fix | Delete
[218] Fix | Delete
// Check if a re-Smush request, update the re-Smush list.
[219] Fix | Delete
if ( ! empty( $_REQUEST['is_bulk_resmush'] ) ) {
[220] Fix | Delete
$this->ng_stats->get_reoptimize_list()->remove_id( $atchmnt_id );
[221] Fix | Delete
}
[222] Fix | Delete
$stats['is_lossy'] = ! empty( $smush['stats'] ) ? $smush['stats']['lossy'] : 0;
[223] Fix | Delete
[224] Fix | Delete
// Size before and after smush.
[225] Fix | Delete
$stats['size_before'] = ! empty( $smush['stats'] ) ? $smush['stats']['size_before'] : 0;
[226] Fix | Delete
$stats['size_after'] = ! empty( $smush['stats'] ) ? $smush['stats']['size_after'] : 0;
[227] Fix | Delete
[228] Fix | Delete
// Get the re-Smush IDs list.
[229] Fix | Delete
$this->ng_admin->resmush_ids = $this->ng_stats->get_reoptimize_list()->get_ids();
[230] Fix | Delete
$resmush_count = ! empty( $this->ng_admin->resmush_ids ) ? count( $this->ng_admin->resmush_ids ) : 0;
[231] Fix | Delete
$smushed_images = $this->ng_stats->get_ngg_images( 'smushed' );
[232] Fix | Delete
[233] Fix | Delete
// Remove re-Smush IDs from smushed images list.
[234] Fix | Delete
if ( $resmush_count > 0 && is_array( $this->ng_admin->resmush_ids ) ) {
[235] Fix | Delete
foreach ( $smushed_images as $image_k => $image ) {
[236] Fix | Delete
if ( in_array( $image_k, $this->ng_admin->resmush_ids, true ) ) {
[237] Fix | Delete
unset( $smushed_images[ $image_k ] );
[238] Fix | Delete
}
[239] Fix | Delete
}
[240] Fix | Delete
}
[241] Fix | Delete
[242] Fix | Delete
// Get the image count and smushed images count.
[243] Fix | Delete
$image_count = ! empty( $smush ) && ! empty( $smush['sizes'] ) ? count( $smush['sizes'] ) : 0;
[244] Fix | Delete
$smushed_count = is_array( $smushed_images ) ? count( $smushed_images ) : 0;
[245] Fix | Delete
[246] Fix | Delete
$stats['smushed'] = ! empty( $this->ng_admin->resmush_ids ) ? $smushed_count - $resmush_count : $smushed_count;
[247] Fix | Delete
$stats['count'] = $image_count;
[248] Fix | Delete
[249] Fix | Delete
wp_send_json_success(
[250] Fix | Delete
array(
[251] Fix | Delete
'stats' => $stats,
[252] Fix | Delete
)
[253] Fix | Delete
);
[254] Fix | Delete
}
[255] Fix | Delete
[256] Fix | Delete
/**
[257] Fix | Delete
* Show additional notice if the required plugins are not installed.
[258] Fix | Delete
*
[259] Fix | Delete
* @since 2.8.0
[260] Fix | Delete
*
[261] Fix | Delete
* @param string $name Setting name.
[262] Fix | Delete
*/
[263] Fix | Delete
public function additional_notice( $name ) {
[264] Fix | Delete
if ( $this->module === $name && ! $this->enabled ) {
[265] Fix | Delete
?>
[266] Fix | Delete
<div class="sui-toggle-content">
[267] Fix | Delete
<div class="sui-notice">
[268] Fix | Delete
<div class="sui-notice-content">
[269] Fix | Delete
<div class="sui-notice-message">
[270] Fix | Delete
<i class="sui-notice-icon sui-icon-info" aria-hidden="true"></i>
[271] Fix | Delete
<p><?php esc_html_e( 'To use this feature you need to be using NextGen Gallery.', 'wp-smushit' ); ?></p>
[272] Fix | Delete
</div>
[273] Fix | Delete
</div>
[274] Fix | Delete
</div>
[275] Fix | Delete
</div>
[276] Fix | Delete
<?php
[277] Fix | Delete
}
[278] Fix | Delete
}
[279] Fix | Delete
[280] Fix | Delete
/**
[281] Fix | Delete
* Get the NextGen Image object from attachment id
[282] Fix | Delete
*
[283] Fix | Delete
* @param string $pid NextGen Gallery Image ID.
[284] Fix | Delete
*
[285] Fix | Delete
* @return stdClass
[286] Fix | Delete
*/
[287] Fix | Delete
public function get_nextgen_image_from_id( $pid ) {
[288] Fix | Delete
// Registry Object for NextGen Gallery.
[289] Fix | Delete
$registry = C_Component_Registry::get_instance();
[290] Fix | Delete
[291] Fix | Delete
// Gallery Storage Object.
[292] Fix | Delete
$storage = $registry->get_utility( 'I_Gallery_Storage' );
[293] Fix | Delete
[294] Fix | Delete
return $storage->object->_image_mapper->find( $pid );
[295] Fix | Delete
}
[296] Fix | Delete
[297] Fix | Delete
/**
[298] Fix | Delete
* Get image mime type
[299] Fix | Delete
*
[300] Fix | Delete
* @param string $file_path File path.
[301] Fix | Delete
*
[302] Fix | Delete
* @return bool|string
[303] Fix | Delete
*/
[304] Fix | Delete
public function get_file_type( $file_path ) {
[305] Fix | Delete
if ( empty( $file_path ) || ! file_exists( $file_path ) ) {
[306] Fix | Delete
return false;
[307] Fix | Delete
}
[308] Fix | Delete
[309] Fix | Delete
$image_mime = false;
[310] Fix | Delete
[311] Fix | Delete
if ( function_exists( 'exif_imagetype' ) ) {
[312] Fix | Delete
$image_type = exif_imagetype( $file_path );
[313] Fix | Delete
if ( ! empty( $image_type ) ) {
[314] Fix | Delete
$image_mime = image_type_to_mime_type( $image_type );
[315] Fix | Delete
}
[316] Fix | Delete
} else {
[317] Fix | Delete
$image_details = getimagesize( $file_path );
[318] Fix | Delete
$image_mime = ! empty( $image_details ) && is_array( $image_details ) ? $image_details['mime'] : '';
[319] Fix | Delete
}
[320] Fix | Delete
[321] Fix | Delete
return $image_mime;
[322] Fix | Delete
}
[323] Fix | Delete
[324] Fix | Delete
/**
[325] Fix | Delete
* Performs the actual smush process
[326] Fix | Delete
*
[327] Fix | Delete
* @usedby: `manual_nextgen`, `auto_smush`, `smush_bulk`
[328] Fix | Delete
*
[329] Fix | Delete
* @param string $pid NextGen Gallery Image id.
[330] Fix | Delete
* @param string $image Nextgen gallery image object.
[331] Fix | Delete
* @param bool $is_bulk Whether it's called by bulk smush or not.
[332] Fix | Delete
*
[333] Fix | Delete
* @return mixed Stats / Status / Error
[334] Fix | Delete
*/
[335] Fix | Delete
public function smush_image( $pid = '', $image = '', $is_bulk = false ) {
[336] Fix | Delete
// Get image, if we have image id.
[337] Fix | Delete
if ( ! empty( $pid ) ) {
[338] Fix | Delete
$image = $this->get_nextgen_image_from_id( $pid );
[339] Fix | Delete
} elseif ( ! empty( $image ) ) {
[340] Fix | Delete
$pid = $this->get_nextgen_id_from_image( $image );
[341] Fix | Delete
}
[342] Fix | Delete
[343] Fix | Delete
$metadata = ! empty( $image ) ? $image->meta_data : '';
[344] Fix | Delete
[345] Fix | Delete
if ( empty( $metadata ) ) {
[346] Fix | Delete
/**
[347] Fix | Delete
* We use error_msg for single images to append to the div and error_message to
[348] Fix | Delete
* append to bulk smush errors list.
[349] Fix | Delete
*/
[350] Fix | Delete
wp_send_json_error(
[351] Fix | Delete
array(
[352] Fix | Delete
'error' => 'no_metadata',
[353] Fix | Delete
'error_msg' => '<p class="wp-smush-error-message">' . esc_html__( "We couldn't find the metadata for the image, possibly the image has been deleted.", 'wp-smushit' ) . '</p>',
[354] Fix | Delete
'error_message' => esc_html__( "We couldn't find the metadata for the image, possibly the image has been deleted.", 'wp-smushit' ),
[355] Fix | Delete
'file_name' => isset( $image->filename ) ? $image->filename : 'undefined',
[356] Fix | Delete
)
[357] Fix | Delete
);
[358] Fix | Delete
}
[359] Fix | Delete
[360] Fix | Delete
$registry = C_Component_Registry::get_instance();
[361] Fix | Delete
$storage = $registry->get_utility( 'I_Gallery_Storage' );
[362] Fix | Delete
[363] Fix | Delete
// Perform Resizing.
[364] Fix | Delete
$metadata = $this->resize_image( $pid, $image, $metadata, $storage );
[365] Fix | Delete
[366] Fix | Delete
// Store Meta.
[367] Fix | Delete
$image->meta_data = $metadata;
[368] Fix | Delete
nggdb::update_image_meta( $image->pid, $image->meta_data );
[369] Fix | Delete
[370] Fix | Delete
// Smush the main image and its sizes.
[371] Fix | Delete
$smush = $this->resize_from_meta_data( $image );
[372] Fix | Delete
[373] Fix | Delete
$status = '';
[374] Fix | Delete
if ( ! is_wp_error( $smush ) ) {
[375] Fix | Delete
$status = $this->ng_admin->show_stats( $pid, $smush );
[376] Fix | Delete
}
[377] Fix | Delete
[378] Fix | Delete
if ( ! $is_bulk ) {
[379] Fix | Delete
if ( is_wp_error( $smush ) ) {
[380] Fix | Delete
return $smush;
[381] Fix | Delete
}
[382] Fix | Delete
[383] Fix | Delete
return $status;
[384] Fix | Delete
}
[385] Fix | Delete
[386] Fix | Delete
return $smush;
[387] Fix | Delete
}
[388] Fix | Delete
[389] Fix | Delete
/**
[390] Fix | Delete
* Refreshes the total image count from the stats when a new image is added to nextgen gallery
[391] Fix | Delete
* Should be called only if image count need to be updated, use total_count(), otherwise
[392] Fix | Delete
*/
[393] Fix | Delete
public function update_stats_image_count() {
[394] Fix | Delete
NextGen\Stats::total_count( true );
[395] Fix | Delete
}
[396] Fix | Delete
[397] Fix | Delete
/**
[398] Fix | Delete
* Handles the smushing of each image and its registered sizes
[399] Fix | Delete
* Calls the function to update the compression stats
[400] Fix | Delete
*/
[401] Fix | Delete
public function manual_nextgen() {
[402] Fix | Delete
$pid = ! empty( $_GET['attachment_id'] ) ? absint( (int) $_GET['attachment_id'] ) : '';
[403] Fix | Delete
$nonce = ! empty( $_GET['_nonce'] ) ? wp_unslash( $_GET['_nonce'] ) : '';
[404] Fix | Delete
[405] Fix | Delete
// Verify Nonce.
[406] Fix | Delete
if ( ! wp_verify_nonce( $nonce, 'wp_smush_nextgen' ) ) {
[407] Fix | Delete
wp_send_json_error(
[408] Fix | Delete
array(
[409] Fix | Delete
'error' => 'nonce_verification_failed',
[410] Fix | Delete
)
[411] Fix | Delete
);
[412] Fix | Delete
}
[413] Fix | Delete
[414] Fix | Delete
// Check for media upload permission.
[415] Fix | Delete
if ( ! Helper::is_user_allowed( 'upload_files' ) ) {
[416] Fix | Delete
wp_send_json_error(
[417] Fix | Delete
array(
[418] Fix | Delete
'error_msg' => __( "You don't have permission to work with uploaded files.", 'wp-smushit' ),
[419] Fix | Delete
)
[420] Fix | Delete
);
[421] Fix | Delete
}
[422] Fix | Delete
[423] Fix | Delete
if ( empty( $pid ) ) {
[424] Fix | Delete
wp_send_json_error(
[425] Fix | Delete
array(
[426] Fix | Delete
'error_msg' => __( 'No attachment ID was provided.', 'wp-smushit' ),
[427] Fix | Delete
)
[428] Fix | Delete
);
[429] Fix | Delete
}
[430] Fix | Delete
[431] Fix | Delete
$status = $this->smush_image( $pid );
[432] Fix | Delete
[433] Fix | Delete
// Send stats.
[434] Fix | Delete
if ( is_wp_error( $status ) ) {
[435] Fix | Delete
/**
[436] Fix | Delete
* Not used for bulk smush.
[437] Fix | Delete
*
[438] Fix | Delete
* @param WP_Error $smush
[439] Fix | Delete
*/
[440] Fix | Delete
wp_send_json_error( $status->get_error_message() );
[441] Fix | Delete
}
[442] Fix | Delete
[443] Fix | Delete
wp_send_json_success( $status );
[444] Fix | Delete
}
[445] Fix | Delete
[446] Fix | Delete
/**
[447] Fix | Delete
* Process auto smush request for NextGen gallery images.
[448] Fix | Delete
*
[449] Fix | Delete
* @param stdClass $image Image.
[450] Fix | Delete
*/
[451] Fix | Delete
public function auto_smush( $image ) {
[452] Fix | Delete
if ( ! $this->ng_stats || ! $this->ng_admin ) {
[453] Fix | Delete
$this->init_modules();
[454] Fix | Delete
}
[455] Fix | Delete
[456] Fix | Delete
$this->smush_image( '', $image );
[457] Fix | Delete
}
[458] Fix | Delete
[459] Fix | Delete
[460] Fix | Delete
/**
[461] Fix | Delete
* Checks for file backup, if available for any of the size,
[462] Fix | Delete
* Function returns true
[463] Fix | Delete
*
[464] Fix | Delete
* @param string $pid NextGen gallery image ID.
[465] Fix | Delete
* @param array $attachment_data Attachment data.
[466] Fix | Delete
*
[467] Fix | Delete
* @return bool
[468] Fix | Delete
*/
[469] Fix | Delete
public function show_restore_option( $pid, $attachment_data ) {
[470] Fix | Delete
$backup = WP_Smush::get_instance()->core()->mod->backup;
[471] Fix | Delete
[472] Fix | Delete
// Registry Object for NextGen Gallery.
[473] Fix | Delete
$registry = C_Component_Registry::get_instance();
[474] Fix | Delete
[475] Fix | Delete
/**
[476] Fix | Delete
* Gallery Storage Object.
[477] Fix | Delete
*
[478] Fix | Delete
* @var C_Gallery_Storage $storage
[479] Fix | Delete
*/
[480] Fix | Delete
$storage = $registry->get_utility( 'I_Gallery_Storage' );
[481] Fix | Delete
[482] Fix | Delete
$image = $storage->object->_image_mapper->find( $pid );
[483] Fix | Delete
[484] Fix | Delete
// Get image full path.
[485] Fix | Delete
$attachment_file_path = $storage->get_image_abspath( $image, 'full' );
[486] Fix | Delete
[487] Fix | Delete
// Get the backup path.
[488] Fix | Delete
$backup_path = $backup->get_image_backup_path( $attachment_file_path );
[489] Fix | Delete
[490] Fix | Delete
// If one of the backup(Ours/NextGen) exists, show restore option.
[491] Fix | Delete
if ( file_exists( $backup_path ) || file_exists( $attachment_file_path . '_backup' ) ) {
[492] Fix | Delete
return true;
[493] Fix | Delete
}
[494] Fix | Delete
[495] Fix | Delete
// Get Sizes, and check for backup.
[496] Fix | Delete
if ( empty( $attachment_data['sizes'] ) ) {
[497] Fix | Delete
return false;
[498] Fix | Delete
}
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function