PluginProbe
Assistant – Every Day Productivity Apps / 1.5.1
Assistant – Every Day Productivity Apps v1.5.1
1.5.5 trunk 0.1.0 0.2.0 0.2.1 0.2.2 0.3.0 0.3.1 0.4 0.4.1 0.4.2 0.5.0 0.5.1 0.6.0 0.7.0 0.7.0.2 0.7.0.3 0.7.0.4 0.7.0.5 0.7.0.6 0.7.0.7 0.7.0.8 0.7.0.9 0.7.1 1.0 All 71 releases
assistant / backend / src / Hooks / ImageProxy.php

ImageProxy.php in Assistant – Every Day Productivity Apps 1.5.1, at backend/src/Hooks/ImageProxy.php

52 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace FL\Assistant\Hooks;
4
5 class ImageProxy {
6
7 public function __construct() {
8 add_action(
9 'init', function() {
10 if ( ! current_user_can( 'edit_others_posts' ) ) {
11 return;
12 }
13 if ( isset( $_GET['fl_asst_image_proxy'] ) ) {
14 self::render_image();
15 }
16 }
17 );
18 }
19
20 public function render_image() {
21 if ( ! isset( $_GET['fl_asst_image_proxy'] ) && ! isset( $_GET['url'] ) ) {
22 return;
23 }
24
25 $url = esc_url_raw( $_GET['url'] );
26 $url = urldecode( $url );
27
28 if ( 0 !== strpos( $url, 'http' ) ) {
29 return;
30 }
31
32 $response = wp_safe_remote_get( $url );
33
34 if ( is_wp_error( $response ) ) {
35 return;
36 }
37
38 $body = wp_remote_retrieve_body( $response );
39 $headers = wp_remote_retrieve_headers( $response );
40
41 if ( ! isset( $headers['content-type'] ) ) {
42 return;
43 } elseif ( 0 !== strpos( $headers['content-type'], 'image/' ) ) {
44 return;
45 }
46
47 header( 'Content-type: ' . $headers['content-type'] );
48 echo $body;
49 die();
50 }
51 }
52