HEX
Server: Apache
System: Linux sg241.singhost.net 2.6.32-896.16.1.lve1.4.51.el6.x86_64 #1 SMP Wed Jan 17 13:19:23 EST 2018 x86_64
User: honghock (909)
PHP: 8.0.30
Disabled: passthru,system,shell_exec,show_source,exec,popen,proc_open
Upload Files
File: /home/honghock/www/wp-content/plugins/broken-link-checker-seo/app/Api/License.php
<?php
namespace AIOSEO\BrokenLinkChecker\Api;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use AIOSEO\BrokenLinkChecker\Models;

/**
 * Handles license update/removal.
 *
 * @since 1.0.0
 */
class License {
	/**
	 * Activates the license key.
	 *
	 * @since 1.0.0
	 *
	 * @param  \WP_REST_Request  $request The REST Request
	 * @return \WP_REST_Response          The response.
	 */
	public static function activate( $request ) {
		$body       = $request->get_json_params();
		$network    = is_multisite() && ! empty( $body['network'] ) ? (bool) $body['network'] : false;
		$licenseKey = ! empty( $body['licenseKey'] ) ? sanitize_text_field( $body['licenseKey'] ) : null;
		if ( empty( $licenseKey ) ) {
			return new \WP_REST_Response( [
				'success' => false,
				'message' => 'No license key given.'
			], 400 );
		}

		$internalOptions = aioseoBrokenLinkChecker()->internalOptions;
		$license         = aioseoBrokenLinkChecker()->license;
		if ( $network ) {
			$internalOptions = aioseoBrokenLinkChecker()->internalNetworkOptions;
			$license         = aioseoBrokenLinkChecker()->networkLicense;
		}

		$internalOptions->internal->license->licenseKey = $licenseKey;
		$activated                                      = $license->activate();

		if ( $activated ) {
			// Force WordPress to check for updates.
			delete_site_transient( 'update_plugins' );

			// Scan for some posts to fill the report.
			aioseoBrokenLinkChecker()->actionScheduler->scheduleAsync( 'aioseo_blc_links_scan' );
		} else {
			$internalOptions->internal->license->licenseKey = null;

			return new \WP_REST_Response( [
				'success' => false
			], 400 );
		}

		aioseoBrokenLinkChecker()->notifications->init();

		return new \WP_REST_Response( [
			'success'       => true,
			'licenseData'   => $internalOptions->internal->license->all(),
			'notifications' => Models\Notification::getNotifications()
		], 200 );
	}

	/**
	 * Deactivates the license key.
	 *
	 * @since 1.0.0
	 *
	 * @param  \WP_REST_Request  $request The REST Request
	 * @return \WP_REST_Response          The response.
	 */
	public static function deactivate( $request ) {
		$body    = $request->get_json_params();
		$network = is_multisite() && ! empty( $body['network'] ) ? (bool) $body['network'] : false;

		$internalOptions = aioseoBrokenLinkChecker()->internalOptions;
		$license         = aioseoBrokenLinkChecker()->license;
		if ( $network ) {
			$internalOptions = aioseoBrokenLinkChecker()->internalNetworkOptions;
			$license         = aioseoBrokenLinkChecker()->networkLicense;
		}

		$deactivated                                    = $license->deactivate();
		$internalOptions->internal->license->licenseKey = null;

		if ( $deactivated ) {
			// Force WordPress to check for updates.
			delete_site_transient( 'update_plugins' );

			$internalOptions->internal->license->reset(
				[
					'expires',
					'expired',
					'invalid',
					'disabled',
					'activationsError',
					'connectionError',
					'requestError',
					'level'
				]
			);
		} else {
			return new \WP_REST_Response( [
				'success' => false
			], 400 );
		}

		aioseoBrokenLinkChecker()->notifications->init();

		return new \WP_REST_Response( [
			'success'       => true,
			'licenseData'   => $internalOptions->internal->license->all(),
			'notifications' => Models\Notification::getNotifications()
		], 200 );
	}
}