< MVP'?< MV`'?p MVh!(q`c MVPP(B`c MV``(BU MV(< R MV* MV@ *-c MV*> MVhDSA +-c MV`+@ MV@p0-pU MV-<E MV`@/=Y MV/< MV//p MVpH/z MV`/.  MV@P/c0 MV/40 MV/4 MV /+B MVX1;Y MV1< MV1+ MV2I MV3I MV4I MVp5I MV`7IE MV`P`;=Y MV`;< MV` ;+@ MVh<pU MV<<E MVx?= MVP?A MV`?AU MV?<B MVA;Y MVA< MVA+p MVPBz@ MVB MVB+E MVpC= MVPCA MV`CA݋ MVCp MVGz MV`G.  MVGc0 MVG4 MVG+ MV@II MV0JIˌ MV KDU MVK<ٌ MVKF MVQIE MVT= MVPTA MV@T 6 MV@`YAU MVT<E MVP\= MV@P\A R MV`\ MV`p\GΌ MVp\H 6 MVp`\AU MV\<E MV^= MVP^A MV`^AU MV^<E MVP_= MV@P_A MV0`_AU MV_< MV`>hDSA L,AhjMAhjMA,AhLAhLAhLApW]ApW]A`.*&&,,,AxY]AY]A0},AY]A},ApW]ApW]AZ]A/$AZ]A,A,A,A/*Z]A[]A,0<,A(A0<,AD,A[]A0},A&|w0},Azw|wL>Nd40e\APu/$A0e\A/$A`e\A89A/$Ae\A$A!/$Ae\A(,AP$A!0<,A(Ae\Ae\Ae\Ae\Ae\A(f\Ae\Ae\Apf\Ae\Ae\Af\Ae\Ae\Ag\Ae\Ae\AHg\Ae\Ae\Ag\Ae\Ae\Ag\Ae\Ae\Afor this URL. Optional. * * @return string */ public function add_cdn_url( $url, $original_url = '' ) { if ( ! empty( $original_url ) ) { if ( $this->cdn->is_excluded( $original_url ) ) { return $url; } } return $this->cdn->rewrite_url( $url ); } /** * Replace CDN URL with site URL on the provided asset URL. * * @since 3.5.3 * * @param string $url URL of the asset. * @param array $zones Array of corresponding zones for the asset. * * @return string */ public function maybe_replace_url( $url, array $zones = [ 'all' ] ) { if ( ! $this->is_allowed() ) { return $url; } $url_parts = get_rocket_parse_url( $url ); if ( empty( $url_parts['host'] ) ) { return $url; } $site_url_parts = get_rocket_parse_url( site_url() ); if ( empty( $site_url_parts['host'] ) ) { return $url; } if ( $url_parts['host'] === $site_url_parts['host'] ) { return $url; } $cdn_urls = $this->cdn->get_cdn_urls( $zones ); if ( empty( $cdn_urls ) ) { return $url; } $cdn_urls = array_map( 'rocket_add_url_protocol', $cdn_urls ); $site_url = $site_url_parts['scheme'] . '://' . $site_url_parts['host']; foreach ( $cdn_urls as $cdn_url ) { if ( false === strpos( $url, $cdn_url ) ) { continue; } return str_replace( $cdn_url, $site_url, $url ); } return $url; } /** * Add a preconnect tag for the CDN. * * @since 3.8.3 * * @param array $urls The initial array of wp_resource_hint urls. * @param string $relation_type The relation type for the hint: eg., 'preconnect', 'prerender', etc. * * @return array The filtered urls. */ public function add_preconnect_cdn( array $urls, string $relation_type ): array { if ( 'preconnect' !== $relation_type || rocket_bypass() || ! $this->is_allowed() || ! $this->is_cdn_enabled() || ! $this->can_insert_resource_hints() ) { return $urls; } $cdn_urls = $this->cdn->get_cdn_urls( [ 'all', 'images', 'css_and_js', 'css', 'js' ] ); if ( empty( $cdn_urls ) ) { return $urls; } foreach ( $cdn_urls as $url ) { $url_parts = get_rocket_parse_url( $url ); if ( empty( $url_parts['scheme'] ) ) { if ( preg_match( '/^(?![\/])(?=[^\.]+\/).+/i', $url ) ) { continue; } $url = '//' . $url; $url_parts = get_rocket_parse_url( $url ); } $domain = empty( $url_parts['scheme'] ) ? '//' . $url_parts['host'] : $url_parts['scheme'] . '://' . $url_parts['host']; // Note: As of 22 Feb, 2021 we cannot add more than one instance of a domain url // on the wp_resource_hint() hook -- wp_resource_hint() will // only actually print the first one. // Ideally, we want both because CSS resources will use the crossorigin version, // But JS resources will not. // Jonathan has submitted a ticket to change this behavior: // @see https://core.trac.wordpress.org/ticket/52465 // Until then, we order these to prefer/print the non-crossorigin version. $urls[] = [ 'href' => $domain ]; $urls[] = [ 'href' => $domain, 'crossorigin' => 'anonymous', ]; } return $urls; } /** * Checks if CDN can be applied * * @since 3.4 * * @return boolean */ private function is_allowed() { if ( rocket_get_constant( 'DONOTROCKETOPTIMIZE' ) ) { return false; } if ( ! $this->is_cdn_enabled() ) { return false; } if ( is_rocket_post_excluded_option( 'cdn' ) ) { return false; } return true; } /** * Checks if the CDN option is enabled * * @since 3.5.5 * * @return bool */ private function is_cdn_enabled() { return (bool) $this->options->get( 'cdn', 0 ); } /** * Check if CDN can insert resource hints into head. * * @return bool */ private function can_insert_resource_hints(): bool { /** * Enable adding resource hints by CDN feature. * * @since 3.19 * * @param bool $can_insert Can cdn insert resource hints or not, default is true. */ return wpm_apply_filters_typed( 'boolean', 'rocket_cdn_insert_resource_hints', true ); } }