/** * External dependencies */ import React from 'react'; import classNames from 'classnames'; /** * WordPress dependencies */ const { __, sprintf } = wp.i18n; /** * Internal dependencies */ import Action from '../../components/sui-box/action'; import BorderFrame from '../../components/border-frame'; import Box from '../../components/sui-box'; import Button from '../../components/sui-button'; import Notice from '../../components/sui-notice'; import Tag from '../../components/sui-tag'; import Tooltip from '../../components/sui-tooltip'; import {createInterpolateElement} from "@wordpress/element"; /** * GzipSummary component. * * @since 2.1.1 */ class GzipSummary extends React.Component { /** * Generate the status tag for Gzip compression, based on the number of active * elements (HTML, JavaScrip, CSS). * * @param {Object} status Gzip compression status object. * @param {boolean} successTag On success show a tick tag. * @return {*} Gzip compression status. */ static getStatus( status, successTag = false ) { let gzipCompression; if ( successTag ) { gzipCompression = ; } const failedGzip = GzipSummary.getFailedItems( status ); if ( 0 < failedGzip.length ) { gzipCompression = ( ); } return gzipCompression; } /** * Get an array of failed items. * * @param {Object} items Gzip compression statues. * @return {Array} Array of items. */ static getFailedItems( items ) { return Object.values( items ).filter( ( item ) => { return ! item || 'privacy' === item; } ); } /** * Check problems that might be related to bad configuration. * * @return {*} Notice. */ checkExternalProblems() { if ( this.props.loading ) { return; } if ( this.props.data.htaccess_writable && ! this.props.data.htaccess_written ) { return; } // There must be another plugin/server config that is setting its own gzip stuff. if ( 3 !== Object.keys( this.props.status ).length || 0 < GzipSummary.getFailedItems( this.props.status ).length ) { const message = (

{ __( 'Gzip is not working properly:', 'wphb' ) }

{ __( 'Your server may not have the "deflate" module enabled (mod_deflate for Apache, ngx_http_gzip_module for NGINX). Contact your host. If deflate is enabled, ask why all .htaccess or nginx.conf compression rules are not being applied. If re-checking and restarting does not resolve, please check with your host or', 'wphb' ) }