| 4058 | function print_emoji_detection_script() { |
| 4059 | global $wp_version; |
| 4060 | |
| 4061 | $min = SCRIPT_DEBUG ? '' : '.min'; |
| 4062 | |
| 4063 | $settings = array( |
| 4064 | /** |
| 4065 | * Filter the URL where emoji images are hosted. |
| 4066 | * |
| 4067 | * @since 4.2.0 |
| 4068 | * |
| 4069 | * @param string The emoji base URL. |
| 4070 | */ |
| 4071 | 'baseUrl' => apply_filters( 'emoji_url', '//s0.wp.com/wp-content/mu-plugins/emoji/twemoji/72x72' ), |
| 4072 | |
| 4073 | /** |
| 4074 | * Filter the extension of the emoji files. |
| 4075 | * |
| 4076 | * @since 4.2.0 |
| 4077 | * |
| 4078 | * @param string The emoji extension. Default .png. |
| 4079 | */ |
| 4080 | 'ext' => apply_filters( 'emoji_ext', '.png' ), |
| 4081 | 'js' => array( |
| 4082 | 'wpemoji' => includes_url( "js/wp-emoji$min.js" ), |
| 4083 | 'twemoji' => includes_url( "js/twemoji$min.js" ), |
| 4084 | ), |
| 4085 | 'ver' => $wp_version, |
| 4086 | ); |
| 4087 | |
| 4088 | if ( SCRIPT_DEBUG ) { |
| 4089 | ?> |
| 4090 | <script type="text/javascript"> |
| 4091 | ( function( window ) { |
| 4092 | window._wpemojiSettings = <?php echo wp_json_encode( $settings ); ?>; |
| 4093 | /** |
| 4094 | * Detect if the browser supports rendering emoji or flag emoji. Flag emoji are a single glyph |
| 4095 | * made of two characters, so some browsers (notably, Firefox OS X) don't support them. |
| 4096 | * |
| 4097 | * @since 4.2.0 |
| 4098 | * |
| 4099 | * @param type {String} Whether to test for support of "simple" or "flag" emoji. |
| 4100 | * @return {Boolean} True if the browser can render emoji, false if it cannot. |
| 4101 | */ |
| 4102 | browserSupportsEmoji = function( type ) { |
| 4103 | var canvas = document.createElement( 'canvas' ), |
| 4104 | context = canvas.getContext && canvas.getContext( '2d' ); |
| 4105 | |
| 4106 | if ( ! context || ! context.fillText ) { |
| 4107 | return false; |
| 4108 | } |
| 4109 | |
| 4110 | /* |
| 4111 | * Chrome on OS X added native emoji rendering in M41. Unfortunately, |
| 4112 | * it doesn't work when the font is bolder than 500 weight. So, we |
| 4113 | * check for bold rendering support to avoid invisible emoji in Chrome. |
| 4114 | */ |
| 4115 | context.textBaseline = 'top'; |
| 4116 | context.font = '600 32px Arial'; |
| 4117 | |
| 4118 | if ( type === 'flag' ) { |
| 4119 | /* |
| 4120 | * This works because the image will be one of three things: |
| 4121 | * - Two empty squares, if the browser doesn't render emoji |
| 4122 | * - Two squares with 'G' and 'B' in them, if the browser doesn't render flag emoji |
| 4123 | * - The British flag |
| 4124 | * |
| 4125 | * The first two will encode to small images (1-2KB data URLs), the third will encode |
| 4126 | * to a larger image (4-5KB data URL). |
| 4127 | */ |
| 4128 | context.fillText( String.fromCharCode( 55356, 56812, 55356, 56807 ), 0, 0 ); |
| 4129 | return canvas.toDataURL().length > 3000; |
| 4130 | } else { |
| 4131 | /* |
| 4132 | * This creates a smiling emoji, and checks to see if there is any image data in the |
| 4133 | * center pixel. In browsers that don't support emoji, the character will be rendered |
| 4134 | * as an empty square, so the center pixel will be blank. |
| 4135 | */ |
| 4136 | context.fillText( String.fromCharCode( 55357, 56835 ), 0, 0 ); |
| 4137 | return context.getImageData( 16, 16, 1, 1 ).data[0] !== 0; |
| 4138 | } |
| 4139 | } |
| 4140 | |
| 4141 | if ( ! browserSupportsEmoji( 'simple' ) || ! browserSupportsEmoji( 'flag' ) ) { |
| 4142 | var script = document.createElement( 'script' ); |
| 4143 | script.src = window._wpemojiSettings.js.twemoji + '?ver=' + window._wpemojiSettings.ver; |
| 4144 | script.type = 'text/javascript'; |
| 4145 | document.getElementsByTagName( 'head' )[0].appendChild( script ); |
| 4146 | |
| 4147 | waitForTwemoji(); |
| 4148 | } |
| 4149 | |
| 4150 | function waitForTwemoji() { |
| 4151 | if ( ! window.twemoji ) { |
| 4152 | // Still waiting. |
| 4153 | window.setTimeout( waitForTwemoji, 50 ); |
| 4154 | } |
| 4155 | |
| 4156 | var script = document.createElement( 'script' ); |
| 4157 | script.src = window._wpemojiSettings.js.wpemoji + '?ver=' + window._wpemojiSettings.ver; |
| 4158 | script.type = 'text/javascript'; |
| 4159 | document.getElementsByTagName( 'head' )[0].appendChild( script ); |
| 4160 | } |
| 4161 | |
| 4162 | } )( window ); |
| 4163 | </script> |
| 4164 | <?php |
| 4165 | } else { // ! SCRIPT_DEBUG |
| 4166 | ?> |
| 4167 | <script type="text/javascript"> |
| 4168 | // TODO: Minified version of the emoji detection script |
| 4169 | </script> |
| 4170 | <?php |
| 4171 | } |
| 4172 | } |
| 4173 | |