PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / addons / includes / classes / helpers / class.url.php
robin-image-optimizer / libs / addons / includes / classes / helpers Last commit date
class.url.php 5 months ago
class.url.php
49 lines
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 /**
9 * Class WRIO_Webp_Hash_Src holds hash data about type, source src and normalized src which is mainly used to compare
10 * or replace data.
11 *
12 * @version 1.0
13 */
14 class WRIO_Url {
15 /**
16 * Check whether URI is valid or not.
17 *
18 * @param string $src Image path.
19 * @param bool $decode Whether to decode src.
20 *
21 * @return null|string NULL on failure to get valid uri.
22 */
23 public static function normalize( $src, $decode = true ) {
24 $url_parts = wp_parse_url( $src );
25
26 // Unsupported scheme.
27 if ( isset( $url_parts['scheme'] ) && 'http' !== $url_parts['scheme'] && 'https' !== $url_parts['scheme'] ) {
28 return null;
29 }
30
31 // This is a relative path, try to get the URL.
32 if ( ! isset( $url_parts['host'] ) && ! isset( $url_parts['scheme'] ) ) {
33 $src = site_url( $src );
34 }
35
36 $content_url = content_url();
37 $content_url_http = str_replace( 'https://', 'http://', $content_url );
38 if ( false === strpos( $src, $content_url ) && false === strpos( $src, $content_url_http ) ) {
39 return null;
40 }
41
42 if ( $decode ) {
43 return urldecode( $src );
44 }
45
46 return $src;
47 }
48 }
49