HEX
Server: nginx/1.18.0
System: Linux iZj6c1ieg2jrpk1z5tzi19Z 6.3.9-1.el7.elrepo.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Jun 21 22:18:40 EDT 2023 x86_64
User: www (1001)
PHP: 8.2.4
Disabled: passthru,exec,system,putenv,chroot,chgrp,chown,shell_exec,popen,proc_open,pcntl_exec,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,imap_open,apache_setenv
Upload Files
File: /www/wwwroot/www.cytocare.cn/wp-content/plugins/hummingbird-performance/_src/react/modules/gzip.jsx
/**
 * External dependencies
 */
import React from 'react';
import ReactDOM from 'react-dom';
import PropTypes from 'prop-types';

/**
 * WordPress dependencies
 */
import domReady from '@wordpress/dom-ready';

/**
 * Internal dependencies
 */
import '../app.scss';
import HBAPIFetch from '../api';
import { UserContext } from '../context';
import GzipSummary from '../views/gzip/summary';
import GzipConfig from '../views/gzip/configure';

/**
 * GzipPage component.
 *
 * @since 2.1.1
 */
class GzipPage extends React.Component {
	/**
	 * Component constructor.
	 *
	 * @param {Object} props
	 */
	constructor( props ) {
		super( props );

		this.state = {
			api: new HBAPIFetch(),
			isMember: this.props.wphbData.isMember,
			links: this.props.wphbData.links,
			loading: true,
			status: {
				HTML: false,
				JavaScript: false,
				CSS: false,
			},
		};

		this.updateStatus = this.updateStatus.bind( this );
	}

	/**
	 * Invoked immediately after a component is mounted.
	 */
	componentDidMount() {
		this.state.api
			.post( 'gzip_status', 'get' )
			.then( ( response ) => {
				this.setState( {
					loading: false,
					status: response.status,
				} );
			} )
			.catch( ( error ) => window.console.log( error ) );
	}

	/**
	 * Update Gzip compression status.
	 */
	updateStatus() {
		this.setState( { loading: true } );

		this.state.api
			.post( 'gzip_status', 'refresh' )
			.then( ( response ) => {
				this.setState( {
					loading: false,
					status: response.status,
				} );
			} )
			.catch( ( error ) => window.console.log( error ) );
	}

	/**
	 * Enable Gzip compression via .htaccess rules.
	 *
	 * @param {string} action Available actions: add|remove.
	 */
	gzipRules( action = 'add' ) {
		this.setState( { loading: true } );

		this.state.api
			.post( 'gzip_rules', action )
			.then( ( response ) => {
				this.props.wphbData.module.htaccess_written =
					response.htaccess_written; // Overwrite the prop.

				this.setState( {
					loading: false,
					status: response.status,
				} );
			} )
			.catch( ( error ) => window.console.log( error ) );
	}

	/**
	 * Render component.
	 *
	 * @return {*} Gzip page.
	 */
	render() {
		return (
			<UserContext.Provider value={ this.state }>
				<GzipSummary
					data={ this.props.wphbData.module }
					link={ this.state.links }
					loading={ this.state.loading }
					onUpdate={ this.updateStatus }
					status={ this.state.status }
				/>
				<GzipConfig
					data={ this.props.wphbData.module }
					disableGzip={ () => this.gzipRules( 'remove' ) }
					enableGzip={ () => this.gzipRules( 'add' ) }
					loading={ this.state.loading }
					status={ this.state.status }
				/>
			</UserContext.Provider>
		);
	}
}

GzipPage.propTypes = {
	wphbData: PropTypes.object,
};

domReady( function() {
	const gzipPageDiv = document.getElementById( 'wrap-wphb-gzip' );
	if ( gzipPageDiv ) {
		ReactDOM.render(
			/*** @var {object} window.wphb */
			<GzipPage wphbData={ window.wphb } />,
			gzipPageDiv
		);
	}
} );