| @@ -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 |
| @@ -16,8 +16,12 @@ | ||
| 16 | 16 | |
| 17 | 17 | use Automattic\Jetpack\Connection\Manager as Connection_Manager; |
| 18 | 18 | use Automattic\Jetpack\Status\Host; |
| 19 | 19 | |
| 20 | +if ( ! defined( 'ABSPATH' ) ) { | |
| 21 | + exit( 0 ); | |
| 22 | +} | |
| 23 | + | |
| 20 | 24 | if ( ! defined( 'JETPACK_NOTES__CACHE_BUSTER' ) ) { |
| 21 | 25 | define( 'JETPACK_NOTES__CACHE_BUSTER', JETPACK__VERSION . '-' . gmdate( 'oW' ) . '-lite' ); |
| 22 | 26 | } |
| 23 | 27 | |
| @@ -139,9 +143,9 @@ | ||
| 139 | 143 | $script_handles[] = 'wpcom-notes-common'; |
| 140 | 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 ); |
| 141 | 145 | $script_handles[] = 'wpcom-notes-admin-bar'; |
| 142 | 146 | |
| 143 | - $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 ) . ';'; | |
| 144 | 148 | wp_add_inline_script( 'wpcom-notes-admin-bar', $wp_notes_args, 'before' ); |
| 145 | 149 | |
| 146 | 150 | if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) { |
| 147 | 151 | add_filter( |
| @@ -190,19 +194,27 @@ | ||
| 190 | 194 | } |
| 191 | 195 | |
| 192 | 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>'; |
| 193 | 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 | + | |
| 194 | 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 | + | |
| 195 | 207 | $wp_admin_bar->add_menu( |
| 196 | 208 | array( |
| 197 | 209 | 'id' => 'notes', |
| 198 | 210 | 'title' => $title, |
| 199 | 211 | 'meta' => array( |
| 200 | - 'html' => '<div id="wpnt-notes-panel2" class="intrinsic-ignore" style="display:none" lang="' . esc_attr( strtolower( substr( $user_locale, 0, 2 ) ) ) . '" 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, | |
| 201 | 213 | 'class' => 'menupop', |
| 202 | 214 | ), |
| 203 | 215 | 'parent' => 'top-secondary', |
| 204 | - 'href' => 'https://wordpress.com/notifications', | |
| 216 | + 'href' => 'https://wordpress.com/reader/notifications', | |
| 205 | 217 | ) |
| 206 | 218 | ); |
| 207 | 219 | } |
| 208 | 220 | |
| @@ -223,19 +235,21 @@ | ||
| 223 | 235 | * @return void |
| 224 | 236 | */ |
| 225 | 237 | public function print_js() { |
| 226 | 238 | $link_accounts_url = is_user_logged_in() && ! ( new Connection_Manager( 'jetpack' ) )->is_user_connected() ? Jetpack::admin_url() : false; |
| 227 | - ?> | |
| 228 | -<script data-ampdevmode type="text/javascript"> | |
| 229 | -/* <![CDATA[ */ | |
| 230 | - var wpNotesIsJetpackClient = true; | |
| 231 | - var wpNotesIsJetpackClientV2 = true; | |
| 232 | - <?php if ( $link_accounts_url ) : ?> | |
| 233 | - var wpNotesLinkAccountsURL = '<?php echo esc_url( $link_accounts_url ); ?>'; | |
| 234 | -<?php endif; ?> | |
| 235 | -/* ]]> */ | |
| 236 | -</script> | |
| 237 | - <?php | |
| 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 ) . ';'; | |
| 245 | + } | |
| 246 | + wp_print_inline_script_tag( | |
| 247 | + $script_contents, | |
| 248 | + array( | |
| 249 | + 'data-ampdevmode' => true, | |
| 250 | + ) | |
| 251 | + ); | |
| 238 | 252 | } |
| 239 | 253 | |
| 240 | 254 | /** |
| 241 | 255 | * Checks to see if we're in the block editor. |