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/clone/wp-conte.../plugins/wp-smush.../_src/js/common
File: globalStats.js
/* global WP_Smush */
[0] Fix | Delete
export const UpsellManger = ( () => {
[1] Fix | Delete
return {
[2] Fix | Delete
maybeShowCDNActivationNotice() {
[3] Fix | Delete
if ( ! wp_smush_msgs.smush_cdn_activation_notice ) {
[4] Fix | Delete
return;
[5] Fix | Delete
}
[6] Fix | Delete
WP_Smush.helpers.renderActivationCDNNotice( wp_smush_msgs.smush_cdn_activation_notice );
[7] Fix | Delete
},
[8] Fix | Delete
maybeShowCDNUpsellForPreSiteOnStart() {
[9] Fix | Delete
const upsellCdn = document.querySelector( '.wp-smush-upsell-cdn' );
[10] Fix | Delete
if ( upsellCdn ) {
[11] Fix | Delete
upsellCdn.querySelector( 'p' ).innerHTML = wp_smush_msgs.processing_cdn_for_free;
[12] Fix | Delete
upsellCdn.classList.remove( 'sui-hidden' );
[13] Fix | Delete
}
[14] Fix | Delete
},
[15] Fix | Delete
maybeShowCDNUpsellForPreSiteOnCompleted() {
[16] Fix | Delete
const upsellCdn = document.querySelector( '.wp-smush-upsell-cdn' );
[17] Fix | Delete
if ( upsellCdn ) {
[18] Fix | Delete
upsellCdn.querySelector( 'p' ).innerHTML = wp_smush_msgs.processed_cdn_for_free;
[19] Fix | Delete
upsellCdn.classList.remove( 'sui-hidden' );
[20] Fix | Delete
}
[21] Fix | Delete
}
[22] Fix | Delete
};
[23] Fix | Delete
} )();
[24] Fix | Delete
export const GlobalStats = ( () => {
[25] Fix | Delete
const $ = document.querySelector.bind( document );
[26] Fix | Delete
const summarySmush = $( '.sui-summary-smush-metabox' );
[27] Fix | Delete
if ( ! summarySmush ) {
[28] Fix | Delete
return {};
[29] Fix | Delete
}
[30] Fix | Delete
// Cache initial stats.
[31] Fix | Delete
let boStats = window.wp_smushit_data.bo_stats;
[32] Fix | Delete
let globalStats = {
[33] Fix | Delete
count_images: 0,
[34] Fix | Delete
count_total: 0,
[35] Fix | Delete
count_resize: 0,
[36] Fix | Delete
count_skipped: 0,
[37] Fix | Delete
count_smushed: 0,
[38] Fix | Delete
savings_bytes: 0,
[39] Fix | Delete
savings_resize: 0,
[40] Fix | Delete
size_after: 0,
[41] Fix | Delete
size_before: 0,
[42] Fix | Delete
savings_percent: 0,
[43] Fix | Delete
percent_grade: 'sui-grade-dismissed',
[44] Fix | Delete
percent_metric: 0,
[45] Fix | Delete
percent_optimized: 0,
[46] Fix | Delete
remaining_count: 0,
[47] Fix | Delete
human_bytes: '',
[48] Fix | Delete
savings_conversion_human: '',
[49] Fix | Delete
savings_conversion: 0,
[50] Fix | Delete
};
[51] Fix | Delete
[52] Fix | Delete
const imageScore = $( '#smush-image-score' );
[53] Fix | Delete
const logBulk = $( '.smush-final-log .smush-bulk-errors' );
[54] Fix | Delete
const bulkSmushCountContent = $( '#wp-smush-bulk-content' );
[55] Fix | Delete
let allErrors = {};
[56] Fix | Delete
[57] Fix | Delete
const generateGlobalStatsFromSmushData = ( smushScriptData ) => {
[58] Fix | Delete
window.wp_smushit_data = Object.assign( window.wp_smushit_data, smushScriptData || {} );
[59] Fix | Delete
globalStats = Object.keys( globalStats ).reduce( function( newStats, key ) {
[60] Fix | Delete
if ( key in window.wp_smushit_data ) {
[61] Fix | Delete
newStats[ key ] = window.wp_smushit_data[ key ];
[62] Fix | Delete
}
[63] Fix | Delete
return newStats;
[64] Fix | Delete
}, {} );
[65] Fix | Delete
}
[66] Fix | Delete
[67] Fix | Delete
generateGlobalStatsFromSmushData( window.wp_smushit_data );
[68] Fix | Delete
[69] Fix | Delete
return {
[70] Fix | Delete
isChangedStats( newBoStats ) {
[71] Fix | Delete
const primaryKeys = [ 'total_items', 'processed_items', 'failed_items', 'is_cancelled', 'is_completed', 'is_dead' ];
[72] Fix | Delete
return primaryKeys.some( ( key ) => {
[73] Fix | Delete
return newBoStats[ key ] !== boStats[ key ];
[74] Fix | Delete
} );
[75] Fix | Delete
},
[76] Fix | Delete
setBoStats( newBoStats ) {
[77] Fix | Delete
boStats = Object.assign( boStats, newBoStats || {} );
[78] Fix | Delete
return this;
[79] Fix | Delete
},
[80] Fix | Delete
getBoStats() {
[81] Fix | Delete
return boStats;
[82] Fix | Delete
},
[83] Fix | Delete
setGlobalStats( newGlobalStats ) {
[84] Fix | Delete
globalStats = Object.assign( globalStats, newGlobalStats || {} );
[85] Fix | Delete
return this;
[86] Fix | Delete
},
[87] Fix | Delete
getGlobalStats() {
[88] Fix | Delete
return globalStats;
[89] Fix | Delete
},
[90] Fix | Delete
/**
[91] Fix | Delete
* Circle progress bar.
[92] Fix | Delete
*/
[93] Fix | Delete
renderScoreProgress() {
[94] Fix | Delete
imageScore.className = imageScore.className.replace( /(^|\s)sui-grade-\S+/g, '' );
[95] Fix | Delete
imageScore.classList.add( globalStats.percent_grade );
[96] Fix | Delete
imageScore.dataset.score = globalStats.percent_optimized;
[97] Fix | Delete
imageScore.querySelector( '.sui-circle-score-label' ).innerHTML = globalStats.percent_optimized;
[98] Fix | Delete
[99] Fix | Delete
imageScore
[100] Fix | Delete
.querySelector( 'circle:last-child' )
[101] Fix | Delete
.setAttribute( 'style', '--metric-array:' + ( 2.63893782902 * globalStats.percent_metric ) + ' ' + ( 263.893782902 - globalStats.percent_metric ) );
[102] Fix | Delete
},
[103] Fix | Delete
/**
[104] Fix | Delete
* Summary detail - center meta box.
[105] Fix | Delete
*/
[106] Fix | Delete
renderSummaryDetail() {
[107] Fix | Delete
this.renderTotalStats();
[108] Fix | Delete
this.renderResizedStats();
[109] Fix | Delete
this.renderConversionSavings();
[110] Fix | Delete
},
[111] Fix | Delete
renderTotalStats() {
[112] Fix | Delete
// Total savings.
[113] Fix | Delete
summarySmush.querySelector( '.sui-summary-large.wp-smush-stats-human' ).innerHTML = globalStats.human_bytes;
[114] Fix | Delete
// Update the savings percent.
[115] Fix | Delete
summarySmush.querySelector( '.wp-smush-savings .wp-smush-stats-percent' ).innerHTML = globalStats.savings_percent;
[116] Fix | Delete
// To total smushed images files.
[117] Fix | Delete
summarySmush.querySelector( '.wp-smush-count-total .wp-smush-total-optimised' ).innerHTML = globalStats.count_images;
[118] Fix | Delete
},
[119] Fix | Delete
renderResizedStats() {
[120] Fix | Delete
const resizeCountElement = summarySmush.querySelector( '.wp-smush-count-resize-total' );
[121] Fix | Delete
if ( ! resizeCountElement ) {
[122] Fix | Delete
return;
[123] Fix | Delete
}
[124] Fix | Delete
if ( globalStats.count_resize > 0 ) {
[125] Fix | Delete
resizeCountElement.classList.remove( 'sui-hidden' );
[126] Fix | Delete
} else {
[127] Fix | Delete
resizeCountElement.classList.add( 'sui-hidden' );
[128] Fix | Delete
}
[129] Fix | Delete
resizeCountElement.querySelector( '.wp-smush-total-optimised' ).innerHTML = globalStats.count_resize;
[130] Fix | Delete
},
[131] Fix | Delete
renderConversionSavings() {
[132] Fix | Delete
// PNG2JPG Savings.
[133] Fix | Delete
const conversionSavingsElement = summarySmush.querySelector( '.smush-conversion-savings .wp-smush-stats' );
[134] Fix | Delete
if ( ! conversionSavingsElement ) {
[135] Fix | Delete
return;
[136] Fix | Delete
}
[137] Fix | Delete
conversionSavingsElement.innerHTML = globalStats.savings_conversion_human;
[138] Fix | Delete
if ( globalStats.savings_conversion > 0 ) {
[139] Fix | Delete
conversionSavingsElement.parentElement.classList.remove( 'sui-hidden' );
[140] Fix | Delete
} else {
[141] Fix | Delete
conversionSavingsElement.parentElement.classList.add( 'sui-hidden' );
[142] Fix | Delete
}
[143] Fix | Delete
},
[144] Fix | Delete
renderBoxSummary() {
[145] Fix | Delete
// Circle core progress.
[146] Fix | Delete
this.renderScoreProgress();
[147] Fix | Delete
// Summary detail.
[148] Fix | Delete
this.renderSummaryDetail();
[149] Fix | Delete
},
[150] Fix | Delete
setErrors( newErrors ) {
[151] Fix | Delete
allErrors = newErrors || {};
[152] Fix | Delete
},
[153] Fix | Delete
getErrors() {
[154] Fix | Delete
return allErrors;
[155] Fix | Delete
},
[156] Fix | Delete
renderErrors() {
[157] Fix | Delete
if ( ! Object.keys( allErrors ).length || ! boStats.is_completed ) {
[158] Fix | Delete
return;
[159] Fix | Delete
}
[160] Fix | Delete
const errors = [];
[161] Fix | Delete
const errorKeys = Object.keys( allErrors );
[162] Fix | Delete
// Cache error code to avoid double upsell notice.
[163] Fix | Delete
let showAnimatedUpsell = false;
[164] Fix | Delete
errorKeys.map( ( image_id, index ) => {
[165] Fix | Delete
const upsellErrorCode = allErrors[ image_id ].error_code;
[166] Fix | Delete
if ( index < 5 && 'animated' === upsellErrorCode ) {
[167] Fix | Delete
showAnimatedUpsell = true;
[168] Fix | Delete
}
[169] Fix | Delete
errors.push( WP_Smush.helpers.prepareBulkSmushErrorRow(
[170] Fix | Delete
allErrors[ image_id ].error_message,
[171] Fix | Delete
allErrors[ image_id ].file_name,
[172] Fix | Delete
allErrors[ image_id ].thumbnail,
[173] Fix | Delete
image_id,
[174] Fix | Delete
'media',
[175] Fix | Delete
allErrors[ image_id ].error_code,
[176] Fix | Delete
) );
[177] Fix | Delete
}
[178] Fix | Delete
);
[179] Fix | Delete
logBulk.innerHTML = errors.join( '' );
[180] Fix | Delete
logBulk.parentElement.classList.remove( 'sui-hidden' );
[181] Fix | Delete
logBulk.parentElement.style.display = null;
[182] Fix | Delete
// Show view all.
[183] Fix | Delete
if ( errorKeys.length > 1 ) {
[184] Fix | Delete
$( '.smush-bulk-errors-actions' ).classList.remove( 'sui-hidden' );
[185] Fix | Delete
}
[186] Fix | Delete
[187] Fix | Delete
// Show animated upsell CDN if user disabled CDN and found an animated error in first 5 errors.
[188] Fix | Delete
if ( showAnimatedUpsell ) {
[189] Fix | Delete
UpsellManger.maybeShowCDNActivationNotice();
[190] Fix | Delete
}
[191] Fix | Delete
},
[192] Fix | Delete
resetAndHideBulkErrors() {
[193] Fix | Delete
if ( ! logBulk ) {
[194] Fix | Delete
return;
[195] Fix | Delete
}
[196] Fix | Delete
this.resetErrors();
[197] Fix | Delete
logBulk.parentElement.classList.add( 'sui-hidden' );
[198] Fix | Delete
logBulk.innerHTML = '';
[199] Fix | Delete
},
[200] Fix | Delete
resetErrors() {
[201] Fix | Delete
allErrors = {};
[202] Fix | Delete
},
[203] Fix | Delete
renderStats() {
[204] Fix | Delete
// Render Smush box summary.
[205] Fix | Delete
this.renderBoxSummary();
[206] Fix | Delete
// Render Errors.
[207] Fix | Delete
this.renderErrors();
[208] Fix | Delete
},
[209] Fix | Delete
maybeUpdateBulkSmushCountContent( newContent ) {
[210] Fix | Delete
if ( newContent && bulkSmushCountContent ) {
[211] Fix | Delete
bulkSmushCountContent.innerHTML = newContent;
[212] Fix | Delete
}
[213] Fix | Delete
},
[214] Fix | Delete
updateGlobalStatsFromSmushScriptData( smushScriptData ) {
[215] Fix | Delete
this.maybeUpdateBulkSmushCountContent( smushScriptData?.content );
[216] Fix | Delete
generateGlobalStatsFromSmushData( smushScriptData );
[217] Fix | Delete
return this;
[218] Fix | Delete
},
[219] Fix | Delete
};
[220] Fix | Delete
} )();
[221] Fix | Delete
[222] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function