<?php
/**
 * Static Scraper API.
 *
 * @package Nisje
 */

$url = filter_input( INPUT_GET, 'url', FILTER_VALIDATE_URL );
if ( $url ) {
	$headers = get_headers( $url, 1 );
	if ( isset( $headers['Content-Type'] ) && strpos( $headers['Content-Type'], 'image/' ) !== false ) {
		$imginfo = @getimagesize( $url ); // phpcs:ignore
		if ( false !== $imginfo && isset( $imginfo['mime'] ) ) {
			header( "Content-type: {$imginfo['mime']}" );
			// phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_read_readfile
			readfile( $url );
		}
	}
}

die();
