Completed
Branch ENH/prevent-img-src-check-fata... (8c70e2)
by
unknown
07:36 queued 04:13
created
strategies/display/EE_Admin_File_Uploader_Display_Strategy.strategy.php 2 patches
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -11,82 +11,82 @@
 block discarded – undo
11 11
  */
12 12
 class EE_Admin_File_Uploader_Display_Strategy extends EE_Display_Strategy_Base
13 13
 {
14
-    /**
15
-     * Its important this media only get enqueued AFTER init, but before the footer... where the
16
-     * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine,
17
-     * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error
18
-     * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button
19
-     * to select media).
20
-     * Besides that, no special consideration should be required to make the media uploader appear, besides having
21
-     * this input displayed.
22
-     * @deprecated. enqueue_js should be called automatically now
23
-     */
24
-    public static function enqueue_scripts()
25
-    {
26
-        EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015');
27
-        wp_enqueue_media();
28
-        wp_enqueue_script('media-upload');
29
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
30
-    }
14
+	/**
15
+	 * Its important this media only get enqueued AFTER init, but before the footer... where the
16
+	 * rest of our forms JS gets enqueued. Otherwise the JS gets enqueued fine, and loaded on the page fine,
17
+	 * but when you upload an image it gets uploaded fine to the server, but it doesn't display and reports an error
18
+	 * (also it doesn't show any of the currently existing media in the modal window that pops up when you click the button
19
+	 * to select media).
20
+	 * Besides that, no special consideration should be required to make the media uploader appear, besides having
21
+	 * this input displayed.
22
+	 * @deprecated. enqueue_js should be called automatically now
23
+	 */
24
+	public static function enqueue_scripts()
25
+	{
26
+		EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015');
27
+		wp_enqueue_media();
28
+		wp_enqueue_script('media-upload');
29
+		wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
30
+	}
31 31
 
32
-    /**
33
-     * Enqueues the JS and CSS needed to display this input
34
-     */
35
-    public function enqueue_js()
36
-    {
37
-        wp_enqueue_media();
38
-        wp_enqueue_script('media-upload');
39
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
40
-        parent::enqueue_js();
41
-    }
32
+	/**
33
+	 * Enqueues the JS and CSS needed to display this input
34
+	 */
35
+	public function enqueue_js()
36
+	{
37
+		wp_enqueue_media();
38
+		wp_enqueue_script('media-upload');
39
+		wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
40
+		parent::enqueue_js();
41
+	}
42 42
 
43 43
 
44 44
 
45
-    /**
46
-     *
47
-     * @return string of html to display the field
48
-     */
45
+	/**
46
+	 *
47
+	 * @return string of html to display the field
48
+	 */
49 49
 
50
-    public function display()
51
-    {
52
-        // the actual input
53
-        $input = '<input type="text" size="34" ';
54
-        $input .= 'name="' . $this->_input->html_name() . '" ';
55
-        $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" ';
56
-        $input .= 'value="' . $this->_input->raw_value_in_form() . '" ';
57
-        $input .= $this->_input->other_html_attributes() . '>';
58
-        // image uploader
59
-        $uploader = EEH_HTML::link(
60
-            '#',
61
-            '<img src="' . admin_url('images/media-button-image.gif') . '" >',
62
-            esc_html__('click to add an image', 'event_espresso'),
63
-            '',
64
-            'ee_media_upload button button--secondary'
65
-        );
66
-        // only attempt to show the image if it at least exists
67
-        $image = '';
68
-        if (! empty($this->_input->raw_value()) && $this->src_exists($this->_input->raw_value())) {
69
-            $image = EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image');
70
-        }
71
-        // html string
72
-        return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area');
73
-    }
50
+	public function display()
51
+	{
52
+		// the actual input
53
+		$input = '<input type="text" size="34" ';
54
+		$input .= 'name="' . $this->_input->html_name() . '" ';
55
+		$input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" ';
56
+		$input .= 'value="' . $this->_input->raw_value_in_form() . '" ';
57
+		$input .= $this->_input->other_html_attributes() . '>';
58
+		// image uploader
59
+		$uploader = EEH_HTML::link(
60
+			'#',
61
+			'<img src="' . admin_url('images/media-button-image.gif') . '" >',
62
+			esc_html__('click to add an image', 'event_espresso'),
63
+			'',
64
+			'ee_media_upload button button--secondary'
65
+		);
66
+		// only attempt to show the image if it at least exists
67
+		$image = '';
68
+		if (! empty($this->_input->raw_value()) && $this->src_exists($this->_input->raw_value())) {
69
+			$image = EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image');
70
+		}
71
+		// html string
72
+		return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area');
73
+	}
74 74
 
75 75
 
76 76
 
77
-    /**
78
-     * Asserts an image actually exists as quickly as possible by sending a HEAD
79
-     * request
80
-     * @param string $src
81
-     * @return boolean
82
-     */
83
-    protected function src_exists($src)
84
-    {
85
-        $results = wp_remote_head($src);
86
-        if (is_array($results) && ! $results instanceof WP_Error) {
87
-            return strpos($results['headers']['content-type'], "image") !== false;
88
-        } else {
89
-            return false;
90
-        }
91
-    }
77
+	/**
78
+	 * Asserts an image actually exists as quickly as possible by sending a HEAD
79
+	 * request
80
+	 * @param string $src
81
+	 * @return boolean
82
+	 */
83
+	protected function src_exists($src)
84
+	{
85
+		$results = wp_remote_head($src);
86
+		if (is_array($results) && ! $results instanceof WP_Error) {
87
+			return strpos($results['headers']['content-type'], "image") !== false;
88
+		} else {
89
+			return false;
90
+		}
91
+	}
92 92
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
         EE_Error::doing_it_wrong(__FUNCTION__, esc_html__('EE_Admin_File_Uploader_Display_Strategy::enqueue_scripts() no longer needs to be called in order to display the admin uploader input correctly. This is handled now by EE_Admin_File_Uploader_Display_Strategy::enqueue_js() which is called automatically when enqueueing JS and CSS for the form', 'event_espresso'), '4.9.8.rc.015');
27 27
         wp_enqueue_media();
28 28
         wp_enqueue_script('media-upload');
29
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
29
+        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js');
30 30
     }
31 31
 
32 32
     /**
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     {
37 37
         wp_enqueue_media();
38 38
         wp_enqueue_script('media-upload');
39
-        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL . 'scripts/ee-media-uploader.js');
39
+        wp_enqueue_script('ee-payments', EE_GLOBAL_ASSETS_URL.'scripts/ee-media-uploader.js');
40 40
         parent::enqueue_js();
41 41
     }
42 42
 
@@ -51,25 +51,25 @@  discard block
 block discarded – undo
51 51
     {
52 52
         // the actual input
53 53
         $input = '<input type="text" size="34" ';
54
-        $input .= 'name="' . $this->_input->html_name() . '" ';
55
-        $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url ' . $this->_input->html_class() . '" ' : 'class="large-text ee_media_url" ';
56
-        $input .= 'value="' . $this->_input->raw_value_in_form() . '" ';
57
-        $input .= $this->_input->other_html_attributes() . '>';
54
+        $input .= 'name="'.$this->_input->html_name().'" ';
55
+        $input .= $this->_input->html_class() != '' ? 'class="large-text ee_media_url '.$this->_input->html_class().'" ' : 'class="large-text ee_media_url" ';
56
+        $input .= 'value="'.$this->_input->raw_value_in_form().'" ';
57
+        $input .= $this->_input->other_html_attributes().'>';
58 58
         // image uploader
59 59
         $uploader = EEH_HTML::link(
60 60
             '#',
61
-            '<img src="' . admin_url('images/media-button-image.gif') . '" >',
61
+            '<img src="'.admin_url('images/media-button-image.gif').'" >',
62 62
             esc_html__('click to add an image', 'event_espresso'),
63 63
             '',
64 64
             'ee_media_upload button button--secondary'
65 65
         );
66 66
         // only attempt to show the image if it at least exists
67 67
         $image = '';
68
-        if (! empty($this->_input->raw_value()) && $this->src_exists($this->_input->raw_value())) {
69
-            $image = EEH_HTML::br(2) . EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image');
68
+        if ( ! empty($this->_input->raw_value()) && $this->src_exists($this->_input->raw_value())) {
69
+            $image = EEH_HTML::br(2).EEH_HTML::img($this->_input->raw_value(), esc_html__('logo', 'event_espresso'), '', 'ee_media_image');
70 70
         }
71 71
         // html string
72
-        return EEH_HTML::div($input . EEH_HTML::nbsp() . $uploader . $image, '', 'ee_media_uploader_area');
72
+        return EEH_HTML::div($input.EEH_HTML::nbsp().$uploader.$image, '', 'ee_media_uploader_area');
73 73
     }
74 74
 
75 75
 
Please login to merge, or discard this patch.