PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / 2.0.6
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF v2.0.6
2.0.6 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 1 month ago
class.url.php
55 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 // Uploads can live outside of the content directory, e.g. a custom UPLOADS base such as "/files".
39 $uploads_url = wp_get_upload_dir()['baseurl'];
40 $uploads_url_http = str_replace( 'https://', 'http://', $uploads_url );
41 if (
42 false === strpos( $src, $content_url ) && false === strpos( $src, $content_url_http )
43 && false === strpos( $src, $uploads_url ) && false === strpos( $src, $uploads_url_http )
44 ) {
45 return null;
46 }
47
48 if ( $decode ) {
49 return urldecode( $src );
50 }
51
52 return $src;
53 }
54 }
55