Escaped $end // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ) . '

' . esc_html__( 'Manage Licenses', 'aioseo-pro' ) . ' | ' . esc_html__( 'Purchase one now.', 'aioseo-pro' ) . '

'; } /** * Get the URL to check licenses. * * @since 4.0.0 * * @return string The URL. */ public function getUrl() { if ( defined( 'AIOSEO_LICENSING_URL' ) ) { return AIOSEO_LICENSING_URL; } return $this->baseUrl; } /** * Checks to see if the current license is expired. * * @since 4.0.0 * * @return bool True if expired, false if not. */ public function isExpired() { $networkIsExpired = $this->isNetworkLicensed() && aioseo()->networkLicense->isExpired(); $licenseKey = $this->options->general->licenseKey; if ( empty( $licenseKey ) ) { return $networkIsExpired; } $expired = $this->internalOptions->internal->license->expired || $this->internalOptions->internal->license->expires < time(); if ( $expired ) { return true; } $expires = $this->internalOptions->internal->license->expires; return 0 !== $expires && $expires < time(); } /** * Checks to see if the current license is disabled. * * @return bool True if disabled, false if not. */ public function isDisabled() { $networkIsDisabled = $this->isNetworkLicensed() && aioseo()->networkLicense->isDisabled(); $licenseKey = $this->options->general->licenseKey; if ( empty( $licenseKey ) ) { return $networkIsDisabled; } return $this->internalOptions->internal->license->disabled; } /** * Checks to see if the current license is invalid. * * @since 4.0.0 * * @return bool True if invalid, false if not. */ public function isInvalid() { $networkIsInvalid = $this->isNetworkLicensed() && aioseo()->networkLicense->isInvalid(); $licenseKey = $this->options->general->licenseKey; if ( empty( $licenseKey ) ) { return $networkIsInvalid; } return $this->internalOptions->internal->license->invalid; } /** * Checks to see if the current license is disabled. * * @since 4.0.0 * * @return bool True if disabled, false if not. */ public function isActive() { $networkIsActive = $this->isNetworkLicensed() && aioseo()->networkLicense->isActive(); $licenseKey = $this->options->general->licenseKey; if ( empty( $licenseKey ) ) { return $networkIsActive; } return ! $this->isExpired() && ! $this->isDisabled() && ! $this->isInvalid(); } /** * Gets the license key. * * @since 4.4.3 * * @return string The license key. */ public function getLicenseKey() { if ( $this->isNetworkLicensed() ) { return aioseo()->networkOptions->general->licenseKey; } return aioseo()->options->general->licenseKey; } /** * Get the license level for the activated license. * * @since 4.0.0 * * @return string The license level. */ public function getLicenseLevel() { $networkLicenseLevel = $this->isNetworkLicensed() ? aioseo()->networkLicense->getLicenseLevel() : 'Unknown'; $licenseKey = $this->options->general->licenseKey; if ( empty( $licenseKey ) ) { return $networkLicenseLevel; } return $this->internalOptions->internal->license->level; } /** * Get the license features for the activated license. * * @since 4.2.4 * * @param string $type The feature type. * @return array The license features. */ public function getLicenseFeatures( $type = '' ) { $features = $this->isNetworkLicensed() && empty( $this->options->general->licenseKey ) ? aioseo()->internalNetworkOptions->internal->license->features : $this->internalOptions->internal->license->features; $allFeatures = json_decode( $features, true ) ?: []; if ( ! empty( $type ) ) { $allFeatures = ! empty( $allFeatures[ $type ] ) ? $allFeatures[ $type ] : []; } return $allFeatures; } /** * Get the core feature for the activated license. * * @since 4.2.5 * * @param string $sectionSlug The section name. * @param string $feature The feature name. * @return bool The license has access to a core feature. */ public function hasCoreFeature( $sectionSlug, $feature = '' ) { $coreFeatures = $this->getLicenseFeatures( 'core' ); foreach ( $coreFeatures as $section => $features ) { if ( $sectionSlug !== $section ) { continue; } if ( empty( $feature ) ) { return true; } foreach ( $features as $featureName ) { if ( $featureName === $feature || false !== stripos( $featureName, "$feature:" ) ) { return true; } } } return false; } /** * Returns the value for a core feature. * * @since 4.0.0 * * @param string $sectionSlug The section name. * @param string $feature The feature name. * @return mixed The feature value. */ public function getCoreFeatureValue( $sectionSlug, $feature ) { return $this->getFeatureValue( 'core', $sectionSlug, $feature ); } /** * Get the addon feature for the activated license. * * @since 4.2.4 * * @param string $addonName The addon name. * @param string $feature The feature name. * @return bool The license has access to an addon feature. */ public function hasAddonFeature( $addonName, $feature ) { $addons = $this->getLicenseFeatures( 'addons' ); foreach ( $addons as $addon => $features ) { if ( $addon === $addonName && in_array( $feature, $features, true ) ) { return true; } } return false; } /** * Returns the value for an addon feature. * * @since 4.0.0 * * @param string $sectionSlug The section name. * @param string $feature The feature name. * @return mixed The feature value. */ public function getAddonFeatureValue( $sectionSlug, $feature ) { return $this->getFeatureValue( 'addons', $sectionSlug, $feature ); } /** * Checks whether a given addon can be used with the current license plan. * * @since 4.0.0 * * @param string $addonName The addon name. * @return boolean Whether the addon can be used. */ public function isAddonAllowed( $addonName ) { $addons = $this->isNetworkLicensed() && empty( $this->options->general->licenseKey ) ? aioseo()->internalNetworkOptions->internal->license->addons : $this->internalOptions->internal->license->addons; if ( is_string( $addons ) ) { $addons = json_decode( $addons ); } if ( empty( $addons ) ) { return false; } return in_array( $addonName, $addons, true ); } /** * Checks if the license data needs to be reset. * * @since 4.0.0 * * @return bool True if a reset is needed, false if not. */ private function needsReset() { if ( ! empty( $this->options->general->licenseKey ) ) { return false; } if ( $this->internalOptions->internal->license->level ) { return true; } if ( $this->internalOptions->internal->license->invalid ) { return true; } if ( $this->internalOptions->internal->license->disabled ) { return true; } $expired = $this->internalOptions->internal->license->expired; if ( $expired ) { return true; } $expires = $this->internalOptions->internal->license->expires; return 0 !== $expires; } /** * Send the license request. * * @since 4.2.5 * * @param string $type The type of request, either activate or deactivate. * @param string $licenseKey The license key we are using for this request. * @param array $domains An array of domains to activate or deactivate. * @return object|null The JSON response as an object. */ public function sendLicenseRequest( $type, $licenseKey, $domains ) { $payload = [ 'sku' => 'all-in-one-seo-pack-pro', 'version' => AIOSEO_VERSION, 'license' => $licenseKey, 'domains' => $domains, 'php_version' => PHP_VERSION, 'wp_version' => get_bloginfo( 'version' ) ]; return aioseo()->helpers->sendRequest( $this->getUrl() . $type . '/', $payload ); } /** * Checks if the current site is licensed at the network level. * * @since 4.2.5 * * @return bool True if licensed at the network level and not licensed locally. */ public function isNetworkLicensed() { if ( ! aioseo()->networkLicense ) { return false; } return aioseo()->networkLicense->isActive(); } /** * Returns the value for a feature. * Helper method form getCoreFeatureValue() and getAddonFeatureValue(). * * @since 4.0.0 * * @param string $type The feature type. * @param string $sectionSlug The section name. * @param string $feature The feature name. * @return mixed The feature value. */ private function getFeatureValue( $type, $sectionSlug, $feature ) { $licenseFeatures = $this->getLicenseFeatures( $type ); foreach ( $licenseFeatures as $section => $features ) { if ( $sectionSlug !== $section ) { continue; } foreach ( $features as $featureName ) { if ( $featureName !== $feature && false === stripos( $featureName, "$feature:" ) ) { continue; } $parts = explode( ':', $featureName ); if ( ! isset( $parts[1] ) ) { continue; } return $parts[1]; } } return null; } }