is_premium(); $site = aco_fs()->get_site(); } $plan = ( $eligible ? 'pro' : 'free' ); $fingerprint = hash( 'sha256', wp_json_encode( array( self::SCANNER_PROTOCOL, $plan, $installed, ( function_exists( 'home_url' ) ? home_url( '/' ) : '' ), ( $site ? $site->id : null ), ( $site && isset( $site->license_id ) ? $site->license_id : null ), ( $site && isset( $site->plan_id ) ? $site->plan_id : null ), ( $site && isset( $site->trial_plan_id ) ? $site->trial_plan_id : null ), ( $site && isset( $site->trial_ends ) ? $site->trial_ends : null ) ) ) ); $cache = get_option( self::CACHE_KEY, array() ); $verified = is_array( $cache ) && isset( $cache['fingerprint'], $cache['plan'], $cache['expires_at'] ) && hash_equals( $fingerprint, $cache['fingerprint'] ) && $cache['plan'] === $plan && $cache['expires_at'] > time(); return array( 'plan' => $plan, 'eligible' => $eligible, 'installed' => $installed, 'verified' => $verified, 'fingerprint' => $fingerprint, 'pages' => ( $eligible ? self::PREMIUM_PAGES : 5 ), 'sample_default' => ( $eligible ? 10 : 5 ), 'schedules' => ( $eligible ? array('manual', 'daily', 'weekly') : array('manual') ), 'error' => ( is_array( $cache ) && isset( $cache['error'] ) ? $cache['error'] : '' ), 'site' => $site, ); } public static function origin( $url ) { $parts = wp_parse_url( $url ); if ( !$parts || empty( $parts['scheme'] ) || empty( $parts['host'] ) ) { return ''; } $scheme = strtolower( $parts['scheme'] ); $port = ( isset( $parts['port'] ) && !($scheme === 'https' && $parts['port'] === 443 || $scheme === 'http' && $parts['port'] === 80) ? ':' . $parts['port'] : '' ); return $scheme . '://' . strtolower( $parts['host'] ) . $port; } public static function sign_registration( $body, $site ) { if ( !$site || empty( $site->id ) || empty( $site->secret_key ) ) { return new WP_Error('acookies_license_connection_required', __( 'Connect and activate your Premium license in ACookies Account before verifying scanner access.', 'acookies' )); } $timestamp = time(); $message = implode( "\n", array( 'acookies-registration-v1', $body['installationId'], self::origin( $body['siteUrl'] ), $body['pluginVersion'], ( $body['dataProcessingAccepted'] ? 'true' : 'false' ), (string) $site->id, $timestamp ) ); return array( 'installId' => (string) $site->id, 'timestamp' => $timestamp, 'signature' => hash_hmac( 'sha256', $message, $site->secret_key ), ); } }