Skip to content
Snippets Groups Projects
Commit e6c5b324 authored by Erick Hitter's avatar Erick Hitter
Browse files

Camouflage attachment URLs

parent ddafdc42
Branches
No related tags found
3 merge requests!6add linting,!5WIP: Add JUnit reporting,!4WIP: Initial release
...@@ -34,7 +34,7 @@ require_once PLUGIN_PATH . '/inc/class-options-page.php'; ...@@ -34,7 +34,7 @@ require_once PLUGIN_PATH . '/inc/class-options-page.php';
/** /**
* URL Building * URL Building
*/ */
require_once PLUGIN_PATH . '/inc/class-urls.php'; require_once PLUGIN_PATH . '/inc/class-url.php';
/** /**
* Rewrite WordPress-generated URLs * Rewrite WordPress-generated URLs
...@@ -60,5 +60,7 @@ function init() { ...@@ -60,5 +60,7 @@ function init() {
if ( is_admin() ) { if ( is_admin() ) {
Options_Page::instance(); Options_Page::instance();
} }
Rewrite_URLs::instance();
} }
add_action( 'init', __NAMESPACE__ . '\init' ); add_action( 'init', __NAMESPACE__ . '\init' );
<?php
/**
* Force Core's image functions to use Camo
*
* @package Camo_Image_Proxy
*/
namespace Camo_Image_Proxy;
/**
* Class Rewrite_URLs
*/
class Rewrite_URLs {
use Singleton;
/**
* Hooks
*/
public function setup() {
add_filter( 'wp_get_attachment_image_src', [ $this, 'encode_image' ] );
}
/**
* Camouflage attachment URL
*
* @param array $image Image data.
* @return array
*/
public function encode_image( array $image ) : array {
$url = URL::instance()->encode( $image[0] );
if ( is_string( $url ) ) {
$image[0] = $url;
}
return $image;
}
}
...@@ -25,7 +25,7 @@ class URL { ...@@ -25,7 +25,7 @@ class URL {
$can_rewrite = true; $can_rewrite = true;
// Validate host. // Validate host.
if ( $this->is_valid_url( $host ) ) { if ( ! $this->is_valid_url( $host ) ) {
$can_rewrite = false; $can_rewrite = false;
} }
...@@ -75,6 +75,14 @@ class URL { ...@@ -75,6 +75,14 @@ class URL {
* @return bool * @return bool
*/ */
private function is_valid_url( string $url ) : bool { private function is_valid_url( string $url ) : bool {
return empty( $url ) || ( ! filter_var( $url, FILTER_VALIDATE_URL ) && ! filter_var( $url, FILTER_VALIDATE_IP ) ); if ( empty( $url ) ) {
return false;
}
if ( false === filter_var( $url, FILTER_VALIDATE_URL ) && false === filter_var( $url, FILTER_VALIDATE_IP ) ) {
return false;
}
return true;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment