PluginProbe
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin / 1.1.11
OpenStation: Desktop Windows, Dock & Virtual Desktops for WP Admin v1.1.11
1.1.11 1.1.10 1.1.9 1.1.8 1.1.7 1.1.6 1.1.5 1.1.4 1.1.3 1.1.2 1.1.1 1.1.0 1.0.1 1.0.0 0.9.8 0.9.7 0.9.6 0.9.4 0.9.5 0.9.3 0.9.2 0.9.1 0.9.0 0.8.9 0.8.8 All 35 releases
← All changes | includes/desktop-files/favicon.php +39 -39 0.9.8 → 1.1.11 View file →
@@ -1,7 +1,7 @@
1 1 <?php
2 2 /**
3 - * Desktop Mode — Favicon resolver.
3 + * OpenStation — Favicon resolver.
4 4 *
5 5 * Resolves the favicon for an arbitrary http(s) URL, downloads the
6 6 * bytes server-side, and returns a base64 `data:` URI suitable for
7 7 * stuffing into a `placement.meta.iconUrl` so the tile renderer can
@@ -31,13 +31,13 @@
31 31 *
32 32 * Failure at any step returns `null` — the caller treats this as
33 33 * "no favicon, render the dashicons fallback". Never throws.
34 34 *
35 - * Filter the final return value through `desktop_mode_resolve_favicon`
35 + * Filter the final return value through `openstation_resolve_favicon`
36 36 * so plugins can short-circuit (return `null` to force-skip, return
37 37 * a synthetic data URI to override).
38 38 *
39 - * @package WPDesktopMode
39 + * @package OpenStation
40 40 */
41 41
42 42 defined( 'ABSPATH' ) || exit;
43 43
@@ -46,9 +46,9 @@
46 46 * under 4 KB. The 256 KB cap exists to keep `placement.meta` blobs
47 47 * sane and to avoid base64-encoding a multi-megabyte payload that
48 48 * a malicious or sloppy host might serve at `/favicon.ico`.
49 49 */
50 -const DESKTOP_MODE_FAVICON_MAX_BYTES = 256 * 1024;
50 +const OPENSTATION_FAVICON_MAX_BYTES = 256 * 1024;
51 51
52 52 /**
53 53 * Maximum page-HTML download size, in bytes, for the step-1 page
54 54 * fetch. The `<link rel="icon">` tags live in `<head>`, so 1 MB
@@ -54,9 +54,9 @@
54 54 * fetch. The `<link rel="icon">` tags live in `<head>`, so 1 MB
55 55 * is plenty; the cap stops a malicious or sloppy host from
56 56 * streaming an unbounded body into memory before the parser runs.
57 57 */
58 -const DESKTOP_MODE_FAVICON_MAX_PAGE_BYTES = 1024 * 1024;
58 +const OPENSTATION_FAVICON_MAX_PAGE_BYTES = 1024 * 1024;
59 59
60 60 /**
61 61 * Per-request HTTP timeout, in seconds. Two fetches happen worst-
62 62 * case (page + icon) so the user-visible wait caps around 2× this
@@ -62,9 +62,9 @@
62 62 * case (page + icon) so the user-visible wait caps around 2× this
63 63 * value. Tune downward if QA finds the dialog "Create" button
64 64 * sitting too long.
65 65 */
66 -const DESKTOP_MODE_FAVICON_TIMEOUT = 4;
66 +const OPENSTATION_FAVICON_TIMEOUT = 4;
67 67
68 68 /**
69 69 * Resolve a page URL to a base64 data URI of its favicon.
70 70 *
@@ -70,10 +70,10 @@
70 70 *
71 71 * @param string $page_url HTTP(S) URL of the target page.
72 72 * @return string|null Data URI on success; `null` on any failure.
73 73 */
74 -function desktop_mode_resolve_favicon( $page_url ) {
75 - $result = desktop_mode_resolve_favicon_internal( (string) $page_url );
74 +function openstation_resolve_favicon( $page_url ) {
75 + $result = openstation_resolve_favicon_internal( (string) $page_url );
76 76
77 77 /**
78 78 * Filters the favicon data URI before it is returned to the
79 79 * caller. Plugins can override (return a synthetic data URI),
@@ -82,9 +82,9 @@
82 82 * @param string|null $result Base64 data URI, or `null` if
83 83 * the resolver could not produce one.
84 84 * @param string $page_url The page URL that was resolved.
85 85 */
86 - $filtered = apply_filters( 'desktop_mode_resolve_favicon', $result, (string) $page_url );
86 + $filtered = apply_filters( 'openstation_resolve_favicon', $result, (string) $page_url );
87 87
88 88 if ( null === $filtered ) {
89 89 return null;
90 90 }
@@ -91,12 +91,12 @@
91 91 return is_string( $filtered ) ? $filtered : null;
92 92 }
93 93
94 94 /**
95 - * Internal resolver — see {@see desktop_mode_resolve_favicon}.
95 + * Internal resolver — see {@see openstation_resolve_favicon}.
96 96 *
97 97 * Kept separate so the public function is the only place the
98 - * `desktop_mode_resolve_favicon` filter runs (a plugin can't sneak
98 + * `openstation_resolve_favicon` filter runs (a plugin can't sneak
99 99 * its filter past the validation by hooking the internal helper).
100 100 *
101 101 * @internal
102 102 *
@@ -102,9 +102,9 @@
102 102 *
103 103 * @param string $page_url Page URL.
104 104 * @return string|null
105 105 */
106 -function desktop_mode_resolve_favicon_internal( $page_url ) {
106 +function openstation_resolve_favicon_internal( $page_url ) {
107 107 $parts = wp_parse_url( $page_url );
108 108 if ( ! is_array( $parts ) || empty( $parts['host'] ) ) {
109 109 return null;
110 110 }
@@ -112,9 +112,9 @@
112 112 if ( 'http' !== $scheme && 'https' !== $scheme ) {
113 113 return null;
114 114 }
115 115
116 - $page_response = wp_safe_remote_get( $page_url, desktop_mode_favicon_request_args( DESKTOP_MODE_FAVICON_MAX_PAGE_BYTES ) );
116 + $page_response = wp_safe_remote_get( $page_url, openstation_favicon_request_args( OPENSTATION_FAVICON_MAX_PAGE_BYTES ) );
117 117 $page_body = '';
118 118 if ( ! is_wp_error( $page_response ) && 200 === (int) wp_remote_retrieve_response_code( $page_response ) ) {
119 119 $page_body = (string) wp_remote_retrieve_body( $page_response );
120 120 }
@@ -119,15 +119,15 @@
119 119 $page_body = (string) wp_remote_retrieve_body( $page_response );
120 120 }
121 121
122 122 $candidate_url = '' !== $page_body
123 - ? desktop_mode_favicon_extract_link_href( $page_body, $page_url )
123 + ? openstation_favicon_extract_link_href( $page_body, $page_url )
124 124 : '';
125 125 if ( '' === $candidate_url ) {
126 126 $candidate_url = $scheme . '://' . $parts['host'] . ( isset( $parts['port'] ) ? ':' . $parts['port'] : '' ) . '/favicon.ico';
127 127 }
128 128
129 - return desktop_mode_favicon_fetch_as_data_uri( $candidate_url );
129 + return openstation_favicon_fetch_as_data_uri( $candidate_url );
130 130 }
131 131
132 132 /**
133 133 * Common request args for both the page fetch and the icon fetch.
@@ -141,18 +141,18 @@
141 141 *
142 142 * @param int $limit_response_size Maximum response body size, in
143 143 * bytes, enforced by WP_Http while
144 144 * downloading. Default one byte over
145 - * `DESKTOP_MODE_FAVICON_MAX_BYTES`,
145 + * `OPENSTATION_FAVICON_MAX_BYTES`,
146 146 * so the post-fetch size check still
147 147 * rejects truncated over-cap bodies.
148 148 * @return array
149 149 */
150 -function desktop_mode_favicon_request_args( $limit_response_size = DESKTOP_MODE_FAVICON_MAX_BYTES + 1 ) {
150 +function openstation_favicon_request_args( $limit_response_size = OPENSTATION_FAVICON_MAX_BYTES + 1 ) {
151 151 return array(
152 - 'timeout' => DESKTOP_MODE_FAVICON_TIMEOUT,
152 + 'timeout' => OPENSTATION_FAVICON_TIMEOUT,
153 153 'redirection' => 3,
154 - 'user-agent' => 'WP Desktop Mode favicon resolver/1.0',
154 + 'user-agent' => 'WP OpenStation favicon resolver/1.0',
155 155 'limit_response_size' => (int) $limit_response_size,
156 156 'headers' => array(
157 157 'Accept' => 'text/html,application/xhtml+xml,image/*;q=0.9,*/*;q=0.5',
158 158 ),
@@ -170,9 +170,9 @@
170 170 * @param string $html Page body.
171 171 * @param string $base_url URL of the page that produced `$html`.
172 172 * @return string
173 173 */
174 -function desktop_mode_favicon_extract_link_href( $html, $base_url ) {
174 +function openstation_favicon_extract_link_href( $html, $base_url ) {
175 175 $dom = new DOMDocument();
176 176 $prev_errors = libxml_use_internal_errors( true );
177 177 // `LIBXML_NOWARNING | LIBXML_NOERROR` suppresses libxml's stderr
178 178 // chatter on malformed HTML; we already silence libxml errors above.
@@ -191,11 +191,11 @@
191 191 // `apple-touch-icon` images are nicer for retina displays but
192 192 // usually larger than the 256 KB cap so we only fall back to
193 193 // them when nothing else exists.
194 194 $buckets = array(
195 - 'icon' => '',
196 - 'shortcut icon' => '',
197 - 'apple-touch-icon' => '',
195 + 'icon' => '',
196 + 'shortcut icon' => '',
197 + 'apple-touch-icon' => '',
198 198 );
199 199
200 200 foreach ( $links as $link ) {
201 201 if ( ! ( $link instanceof DOMElement ) ) {
@@ -222,9 +222,9 @@
222 222 foreach ( $buckets as $href ) {
223 223 if ( '' === $href ) {
224 224 continue;
225 225 }
226 - $absolute = desktop_mode_favicon_absolutize_url( $href, $base_url );
226 + $absolute = openstation_favicon_absolutize_url( $href, $base_url );
227 227 if ( '' !== $absolute ) {
228 228 return $absolute;
229 229 }
230 230 }
@@ -240,9 +240,9 @@
240 240 * @param string $href Link href (absolute, scheme-relative, or path).
241 241 * @param string $base_url Page URL.
242 242 * @return string
243 243 */
244 -function desktop_mode_favicon_absolutize_url( $href, $base_url ) {
244 +function openstation_favicon_absolutize_url( $href, $base_url ) {
245 245 $href = trim( $href );
246 246 if ( '' === $href ) {
247 247 return '';
248 248 }
@@ -283,13 +283,13 @@
283 283 *
284 284 * @param string $icon_url Absolute http(s) URL of the icon.
285 285 * @return string|null
286 286 */
287 -function desktop_mode_favicon_fetch_as_data_uri( $icon_url ) {
287 +function openstation_favicon_fetch_as_data_uri( $icon_url ) {
288 288 if ( '' === $icon_url || ! preg_match( '#^https?://#i', $icon_url ) ) {
289 289 return null;
290 290 }
291 - $response = wp_safe_remote_get( $icon_url, desktop_mode_favicon_request_args() );
291 + $response = wp_safe_remote_get( $icon_url, openstation_favicon_request_args() );
292 292 if ( is_wp_error( $response ) ) {
293 293 return null;
294 294 }
295 295 if ( 200 !== (int) wp_remote_retrieve_response_code( $response ) ) {
@@ -301,12 +301,12 @@
301 301 if ( 0 !== strpos( $content_type, 'image/' ) ) {
302 302 return null;
303 303 }
304 304 $body = (string) wp_remote_retrieve_body( $response );
305 - if ( '' === $body || strlen( $body ) > DESKTOP_MODE_FAVICON_MAX_BYTES ) {
305 + if ( '' === $body || strlen( $body ) > OPENSTATION_FAVICON_MAX_BYTES ) {
306 306 return null;
307 307 }
308 - $subtype = desktop_mode_favicon_subtype_from_content_type( $content_type );
308 + $subtype = openstation_favicon_subtype_from_content_type( $content_type );
309 309 if ( null === $subtype ) {
310 310 return null;
311 311 }
312 312 // Catch HTML / text bodies served with a lying `Content-Type:
@@ -332,18 +332,18 @@
332 332 * @param string $content_type Lowercased `Content-Type` value
333 333 * (no parameters).
334 334 * @return string|null
335 335 */
336 -function desktop_mode_favicon_subtype_from_content_type( $content_type ) {
336 +function openstation_favicon_subtype_from_content_type( $content_type ) {
337 337 $map = array(
338 - 'image/png' => 'png',
339 - 'image/jpeg' => 'jpeg',
340 - 'image/jpg' => 'jpeg',
341 - 'image/gif' => 'gif',
342 - 'image/webp' => 'webp',
343 - 'image/x-icon' => 'x-icon',
344 - 'image/vnd.microsoft.icon' => 'x-icon',
345 - 'image/ico' => 'x-icon',
346 - 'image/svg+xml' => 'svg+xml',
338 + 'image/png' => 'png',
339 + 'image/jpeg' => 'jpeg',
340 + 'image/jpg' => 'jpeg',
341 + 'image/gif' => 'gif',
342 + 'image/webp' => 'webp',
343 + 'image/x-icon' => 'x-icon',
344 + 'image/vnd.microsoft.icon' => 'x-icon',
345 + 'image/ico' => 'x-icon',
346 + 'image/svg+xml' => 'svg+xml',
347 347 );
348 348 return isset( $map[ $content_type ] ) ? $map[ $content_type ] : null;
349 349 }