r the domain is valid or not. */ private function isValidDomain( $domain ) { // In case there are unicode characters, convert it into // IDNA ASCII URLs if ( function_exists( 'idn_to_ascii' ) ) { $domain = idn_to_ascii( $domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46 ); } if ( ! $domain ) { return false; } $domain = preg_replace( '/^\*\.+/', '', (string) $domain ); return preg_match( '/^(?!\-)(?:[a-z\d\-]{0,62}[a-z\d]\.){1,126}(?!\d+)[a-z\d]{1,63}$/i', (string) $domain ); } /** * Checks if a domain is valid and optionally contains paths at the end. * * @since 4.7.7 * * @param string $domain The domain. * @return bool Whether the domain is valid or not. */ private function isDomainWithPaths( $domain ) { // In case there are unicode characters, convert it into IDNA ASCII URLs. if ( function_exists( 'idn_to_ascii' ) ) { $domain = idn_to_ascii( $domain, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46 ); } if ( ! $domain ) { return false; } $domain = preg_replace( '/^\*\.+/', '', $domain ); return preg_match( '/^(?!\-)(?:[a-z\d\-]{0,62}[a-z\d]\.){1,126}(?!\d+)[a-z\d]{1,63}(\/[a-z\d\-\/]*)?$/i', $domain ); } /** * Returns a single string of all subdomains associated with this domain. * Example 1: www * Example 2: ww2.www * * @since 4.5.9 * * @return array The subdomains associated with this domain. */ public function getSubdomains( $domain ) { // If we can't find a TLD, we won't be able to parse a subdomain. if ( empty( $this->getTld( $domain ) ) ) { return []; } // Return any subdomains as an array. return array_filter( explode( '.', rtrim( strstr( $domain, $this->getTld( $domain ), true ), '.' ) ) ); } /** * Returns the TLD associated with the given domain. * * @since 4.5.9 * * @param string $domain The domain. * @return string The TLD. */ public function getTld( $domain ) { if ( preg_match( '/(?P[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', (string) $domain, $matches ) ) { return $matches['tld']; } return $domain; } /** * Returns a decoded URL string. * * @since 4.6.7 * * @param string $url The URL string. * @return string The decoded URL. */ public function decodeUrl( $url ) { // Check if URL was encoded multiple times. while ( rawurldecode( $url ) !== $url ) { $url = rawurldecode( $url ); } return $url; } /** * Redirects to a specific URL. * * @since 4.8.0 * * @param string $url The URL to redirect to. * @param int $status The status code to use. * @param string $reason The reason for redirecting. * * @return void */ public function redirect( $url, $status = 301, $reason = '' ) { $redirectBy = 'AIOSEO'; if ( ! empty( $reason ) ) { $redirectBy .= ': ' . $reason; } wp_safe_redirect( $url, $status, $redirectBy ); exit; } }