| @@ -1,8 +1,8 @@ | ||
| 1 | 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | 2 | /** |
| 3 | 3 | * Module Name: Notifications |
| 4 | - * Module Description: Receive instant notifications of site comments and likes. | |
| 4 | + * Module Description: Receive real‑time notifications about site activity across your devices. | |
| 5 | 5 | * Sort Order: 13 |
| 6 | 6 | * First Introduced: 1.9 |
| 7 | 7 | * Requires Connection: Yes |
| 8 | 8 | * Requires User Connection: Yes |
| @@ -14,9 +14,14 @@ | ||
| 14 | 14 | * @package automattic/jetpack |
| 15 | 15 | */ |
| 16 | 16 | |
| 17 | 17 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 18 | +use Automattic\Jetpack\Status\Host; | |
| 18 | 19 | |
| 20 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 21 | + exit( 0 ); | |
| 22 | +} | |
| 23 | + | |
| 19 | 24 | if ( ! defined( 'JETPACK_NOTES__CACHE_BUSTER' ) ) { |
| 20 | 25 | define( 'JETPACK_NOTES__CACHE_BUSTER', JETPACK__VERSION . '-' . gmdate( 'oW' ) . '-lite' ); |
| 21 | 26 | } |
| 22 | 27 | |
| @@ -109,9 +114,9 @@ | ||
| 109 | 114 | return; |
| 110 | 115 | } |
| 111 | 116 | $is_rtl = is_rtl(); |
| 112 | 117 | |
| 113 | - if ( Jetpack::is_module_active( 'masterbar' ) ) { | |
| 118 | + if ( ( new Host() )->is_woa_site() ) { | |
| 114 | 119 | /** |
| 115 | 120 | * Can be used to force Notifications to display in RTL style. |
| 116 | 121 | * |
| 117 | 122 | * @module notes |
| @@ -138,9 +143,9 @@ | ||
| 138 | 143 | $script_handles[] = 'wpcom-notes-common'; |
| 139 | 144 | wp_enqueue_script( 'wpcom-notes-admin-bar', $this->wpcom_static_url( '/wp-content/mu-plugins/notes/admin-bar-v2.js' ), array( 'wpcom-notes-common' ), JETPACK_NOTES__CACHE_BUSTER, true ); |
| 140 | 145 | $script_handles[] = 'wpcom-notes-admin-bar'; |
| 141 | 146 | |
| 142 | - $wp_notes_args = 'var wpNotesArgs = ' . wp_json_encode( array( 'cacheBuster' => JETPACK_NOTES__CACHE_BUSTER ) ) . ';'; | |
| 147 | + $wp_notes_args = 'var wpNotesArgs = ' . wp_json_encode( array( 'cacheBuster' => JETPACK_NOTES__CACHE_BUSTER ), JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';'; | |
| 143 | 148 | wp_add_inline_script( 'wpcom-notes-admin-bar', $wp_notes_args, 'before' ); |
| 144 | 149 | |
| 145 | 150 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
| 146 | 151 | add_filter( |
| @@ -172,9 +177,9 @@ | ||
| 172 | 177 | if ( self::is_block_editor() ) { |
| 173 | 178 | return; |
| 174 | 179 | } |
| 175 | 180 | |
| 176 | - $wpcom_locale = get_locale(); | |
| 181 | + $user_locale = get_user_locale(); | |
| 177 | 182 | |
| 178 | 183 | if ( ! class_exists( 'GP_Locales' ) ) { |
| 179 | 184 | if ( defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) && file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
| 180 | 185 | require JETPACK__GLOTPRESS_LOCALES_PATH; |
| @@ -181,27 +186,35 @@ | ||
| 181 | 186 | } |
| 182 | 187 | } |
| 183 | 188 | |
| 184 | 189 | if ( class_exists( 'GP_Locales' ) ) { |
| 185 | - $wpcom_locale_object = GP_Locales::by_field( 'wp_locale', $wpcom_locale ); | |
| 186 | - if ( $wpcom_locale_object instanceof GP_Locale ) { | |
| 187 | - $wpcom_locale = $wpcom_locale_object->slug; | |
| 190 | + $jetpack_locale_object = GP_Locales::by_field( 'slug', $user_locale ); | |
| 191 | + if ( $jetpack_locale_object instanceof GP_Locale ) { | |
| 192 | + $user_locale = $jetpack_locale_object->slug; | |
| 188 | 193 | } |
| 189 | 194 | } |
| 190 | 195 | |
| 191 | 196 | $third_party_cookie_check_iframe = '<span style="display:none;"><iframe class="jetpack-notes-cookie-check" src="https://widgets.wp.com/3rd-party-cookie-check/index.html"></iframe></span>'; |
| 192 | 197 | |
| 198 | + // Opt into the v3 notifications panel/iframe via the `notifications=v3` query parameter. | |
| 199 | + $notifications_version = sanitize_key( wp_unslash( $_GET['notifications'] ?? '' ) ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended | |
| 200 | + $panel_id = 'v3' === $notifications_version ? 'wpnt-notes-panel3' : 'wpnt-notes-panel2'; | |
| 201 | + | |
| 193 | 202 | $title = self::get_notes_markup(); |
| 203 | + | |
| 204 | + // The default fallback is `en_US`. Remove underscore if present, noting that lang codes can be more than three chars. | |
| 205 | + $user_locale = strtolower( explode( '_', $user_locale, 2 )[0] ); | |
| 206 | + | |
| 194 | 207 | $wp_admin_bar->add_menu( |
| 195 | 208 | array( |
| 196 | 209 | 'id' => 'notes', |
| 197 | 210 | 'title' => $title, |
| 198 | 211 | 'meta' => array( |
| 199 | - 'html' => '<div id="wpnt-notes-panel2" class="intrinsic-ignore" style="display:none" lang="' . esc_attr( $wpcom_locale ) . '" dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"><div class="wpnt-notes-panel-header"><span class="wpnt-notes-header">' . __( 'Notifications', 'jetpack' ) . '</span><span class="wpnt-notes-panel-link"></span></div></div>' . $third_party_cookie_check_iframe, | |
| 212 | + 'html' => '<div id="' . esc_attr( $panel_id ) . '" class="intrinsic-ignore" style="display:none" lang="' . esc_attr( $user_locale ) . '" dir="' . ( is_rtl() ? 'rtl' : 'ltr' ) . '"><div class="wpnt-notes-panel-header"><span class="wpnt-notes-header">' . __( 'Notifications', 'jetpack' ) . '</span><span class="wpnt-notes-panel-link"></span></div></div>' . $third_party_cookie_check_iframe, | |
| 200 | 213 | 'class' => 'menupop', |
| 201 | 214 | ), |
| 202 | 215 | 'parent' => 'top-secondary', |
| 203 | - 'href' => 'https://wordpress.com/notifications', | |
| 216 | + 'href' => 'https://wordpress.com/reader/notifications', | |
| 204 | 217 | ) |
| 205 | 218 | ); |
| 206 | 219 | } |
| 207 | 220 | |
| @@ -211,9 +224,9 @@ | ||
| 211 | 224 | * @return string |
| 212 | 225 | */ |
| 213 | 226 | private static function get_notes_markup() { |
| 214 | 227 | return '<span id="wpnt-notes-unread-count" class="wpnt-loading wpn-read"></span> |
| 215 | -<span class="noticon noticon-bell"></span> | |
| 228 | +<span class="noticon noticon-bell ab-icon"></span> | |
| 216 | 229 | <span class="screen-reader-text">' . esc_html__( 'Notifications', 'jetpack' ) . '</span>'; |
| 217 | 230 | } |
| 218 | 231 | |
| 219 | 232 | /** |
| @@ -222,34 +235,21 @@ | ||
| 222 | 235 | * @return void |
| 223 | 236 | */ |
| 224 | 237 | public function print_js() { |
| 225 | 238 | $link_accounts_url = is_user_logged_in() && ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ? Jetpack::admin_url() : false; |
| 226 | - ?> | |
| 227 | -<script data-ampdevmode type="text/javascript"> | |
| 228 | -/* <![CDATA[ */ | |
| 229 | - var wpNotesIsJetpackClient = true; | |
| 230 | - var wpNotesIsJetpackClientV2 = true; | |
| 231 | - <?php if ( $link_accounts_url ) : ?> | |
| 232 | - var wpNotesLinkAccountsURL = '<?php echo esc_url( $link_accounts_url ); ?>'; | |
| 233 | -<?php endif; ?> | |
| 234 | -/* ]]> */ | |
| 235 | - window.addEventListener('message', function ( event ) { | |
| 236 | - // Confirm that the message is from the right origin. | |
| 237 | - if ('https://widgets.wp.com' !== event.origin) { | |
| 238 | - return; | |
| 239 | + $script_contents = <<<'JS' | |
| 240 | +var wpNotesIsJetpackClient = true; | |
| 241 | +var wpNotesIsJetpackClientV2 = true; | |
| 242 | +JS; | |
| 243 | + if ( $link_accounts_url ) { | |
| 244 | + $script_contents .= "\nvar wpNotesLinkAccountsURL = " . wp_json_encode( $link_accounts_url, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) . ';'; | |
| 239 | 245 | } |
| 240 | - // Check whether 3rd Party Cookies are blocked | |
| 241 | - var has3PCBlocked = 'WPCOM:3PC:blocked' === event.data; | |
| 242 | - | |
| 243 | - var tagerElement = document.getElementById('wp-admin-bar-notes'); | |
| 244 | - | |
| 245 | - if ( has3PCBlocked && tagerElement ) { | |
| 246 | - // Hide the notification button/icon | |
| 247 | - tagerElement.style.display = 'none'; | |
| 248 | - } | |
| 249 | - }, false ); | |
| 250 | -</script> | |
| 251 | - <?php | |
| 246 | + wp_print_inline_script_tag( | |
| 247 | + $script_contents, | |
| 248 | + array( | |
| 249 | + 'data-ampdevmode' => true, | |
| 250 | + ) | |
| 251 | + ); | |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | /** |
| 255 | 255 | * Checks to see if we're in the block editor. |