Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
94.29% |
132 / 140 |
|
33.33% |
1 / 3 |
CRAP | |
0.00% |
0 / 1 |
| Jetpack_WordPress_Modal | |
94.29% |
132 / 140 |
|
33.33% |
1 / 3 |
12.03 | |
0.00% |
0 / 1 |
| should_display_modal | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| modal | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
6 | |||
| render_modal | |
100.00% |
132 / 132 |
|
100.00% |
1 / 1 |
6 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * Ask readers where to repost a post: WordPress.com, or their own WordPress site. |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | namespace Automattic\Jetpack\Extensions\Sharing_Button_Block; |
| 9 | |
| 10 | /** |
| 11 | * Class Jetpack_WordPress_Modal |
| 12 | */ |
| 13 | class Jetpack_WordPress_Modal { |
| 14 | /** |
| 15 | * Nonce action shared by both forms. |
| 16 | */ |
| 17 | const NONCE_ACTION = 'jetpack_share_wordpress'; |
| 18 | |
| 19 | /** |
| 20 | * Whether this request is the WordPress button's first click, ?share=wordpress&nb=1. |
| 21 | * |
| 22 | * @return bool |
| 23 | */ |
| 24 | public static function should_display_modal() { |
| 25 | // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Only used to display the modal. |
| 26 | return isset( $_GET['share'] ) |
| 27 | && isset( $_GET['nb'] ) |
| 28 | && 'wordpress' === sanitize_text_field( wp_unslash( $_GET['share'] ) ) // phpcs:ignore WordPress.WP.CapitalPDangit.MisspelledInText |
| 29 | && 1 === (int) $_GET['nb']; |
| 30 | // phpcs:enable |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Hook the modal render into WordPress. |
| 35 | */ |
| 36 | public static function modal() { |
| 37 | if ( ! self::should_display_modal() ) { |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | self::render_modal(); |
| 42 | |
| 43 | die( 0 ); |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Render the modal. |
| 48 | */ |
| 49 | public static function render_modal() { |
| 50 | $nonce = wp_create_nonce( self::NONCE_ACTION ); |
| 51 | // phpcs:disable WordPress.Security.NonceVerification.Missing -- Only posted back here once process_request() has checked the nonce and refused the address. |
| 52 | $refused_site = isset( $_POST['jetpack-wordpress-site'] ) && is_string( $_POST['jetpack-wordpress-site'] ) |
| 53 | ? sanitize_text_field( wp_unslash( $_POST['jetpack-wordpress-site'] ) ) |
| 54 | : null; |
| 55 | // phpcs:enable |
| 56 | ?> |
| 57 | <!doctype html> |
| 58 | <html <?php language_attributes(); ?>> |
| 59 | <head> |
| 60 | <meta charset="<?php bloginfo( 'charset' ); ?>" /> |
| 61 | <meta name="viewport" content="width=device-width, initial-scale=1" /> |
| 62 | <meta name="robots" content="noindex,follow" /> |
| 63 | <meta name="referrer" content="no-referrer"> |
| 64 | <?php rel_canonical(); ?> |
| 65 | <title><?php esc_html_e( 'Repost on WordPress', 'jetpack' ); ?></title> |
| 66 | <?php // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedStylesheet -- This standalone page has no wp_head(). ?> |
| 67 | <link rel="stylesheet" href="https://s1.wp.com/i/fonts/recoleta/css/400.min.css" /> |
| 68 | <style type="text/css"> |
| 69 | .sd-wordpress-modal { |
| 70 | background: #fcfcfc; |
| 71 | color: #2c3338; |
| 72 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif; |
| 73 | margin: 0; |
| 74 | } |
| 75 | |
| 76 | .sd-wordpress-modal__inner { |
| 77 | box-sizing: border-box; |
| 78 | margin: 0 auto; |
| 79 | max-inline-size: 480px; |
| 80 | padding: 32px 16px; |
| 81 | } |
| 82 | |
| 83 | .sd-wordpress-modal__logo { |
| 84 | text-align: center; |
| 85 | } |
| 86 | |
| 87 | .sd-wordpress-modal__logo svg { |
| 88 | block-size: 48px; |
| 89 | fill: #3858e9; |
| 90 | inline-size: 48px; |
| 91 | } |
| 92 | |
| 93 | .sd-wordpress-modal__title { |
| 94 | color: #101517; |
| 95 | font-family: Recoleta, Georgia, "Times New Roman", Times, serif; |
| 96 | font-size: 36px; |
| 97 | font-weight: 400; |
| 98 | line-height: 1.2; |
| 99 | margin: 16px 0 12px; |
| 100 | text-align: center; |
| 101 | } |
| 102 | |
| 103 | .sd-wordpress-modal__description { |
| 104 | font-size: 16px; |
| 105 | line-height: 1.5; |
| 106 | margin: 0 0 32px; |
| 107 | text-align: center; |
| 108 | } |
| 109 | |
| 110 | .sd-wordpress-modal__inner form { |
| 111 | margin: 0; |
| 112 | } |
| 113 | |
| 114 | .sd-wordpress-modal__inner label { |
| 115 | display: block; |
| 116 | font-size: 14px; |
| 117 | font-weight: 500; |
| 118 | margin: 32px 0 8px; |
| 119 | } |
| 120 | |
| 121 | .sd-wordpress-modal__site { |
| 122 | display: flex; |
| 123 | gap: 8px; |
| 124 | } |
| 125 | |
| 126 | .sd-wordpress-modal__inner input { |
| 127 | background: #fff; |
| 128 | border: 1px solid #c3c4c7; |
| 129 | border-radius: 2px; |
| 130 | box-sizing: border-box; |
| 131 | color: #101517; |
| 132 | flex: 1; |
| 133 | font-size: 16px; |
| 134 | min-inline-size: 0; |
| 135 | padding: 11px 12px; |
| 136 | } |
| 137 | |
| 138 | .sd-wordpress-modal__inner button { |
| 139 | background: #3858e9; |
| 140 | border: 1px solid #3858e9; |
| 141 | border-radius: 2px; |
| 142 | color: #fff; |
| 143 | cursor: pointer; |
| 144 | font-size: 16px; |
| 145 | font-weight: 500; |
| 146 | padding: 11px 16px; |
| 147 | } |
| 148 | |
| 149 | .sd-wordpress-modal__inner button:hover { |
| 150 | background: #2145e6; |
| 151 | border-color: #2145e6; |
| 152 | } |
| 153 | |
| 154 | .sd-wordpress-modal__inner .sd-wordpress-modal__wpcom { |
| 155 | inline-size: 100%; |
| 156 | padding-block: 14px; |
| 157 | } |
| 158 | |
| 159 | .sd-wordpress-modal__inner .sd-wordpress-modal__go { |
| 160 | background: #fff; |
| 161 | color: #3858e9; |
| 162 | } |
| 163 | |
| 164 | .sd-wordpress-modal__inner .sd-wordpress-modal__go:hover { |
| 165 | background: #f0f0f1; |
| 166 | color: #2145e6; |
| 167 | } |
| 168 | |
| 169 | .sd-wordpress-modal__help { |
| 170 | color: #646970; |
| 171 | font-size: 13px; |
| 172 | line-height: 1.5; |
| 173 | margin: 8px 0 0; |
| 174 | } |
| 175 | |
| 176 | .sd-wordpress-modal__error { |
| 177 | color: #cc1818; |
| 178 | font-size: 13px; |
| 179 | line-height: 1.5; |
| 180 | margin: 8px 0 0; |
| 181 | } |
| 182 | |
| 183 | .sd-wordpress-modal__inner input[aria-invalid="true"] { |
| 184 | border-color: #cc1818; |
| 185 | } |
| 186 | </style> |
| 187 | </head> |
| 188 | <body class="sd-wordpress-modal"> |
| 189 | <main class="sd-wordpress-modal__inner"> |
| 190 | <div class="sd-wordpress-modal__logo"> |
| 191 | <?php echo get_social_logo( 'wordpress' ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped, WordPress.WP.CapitalPDangit.MisspelledInText -- SVG is safe. ?> |
| 192 | </div> |
| 193 | <h1 class="sd-wordpress-modal__title"><?php esc_html_e( 'Repost this on your WordPress site', 'jetpack' ); ?></h1> |
| 194 | <p class="sd-wordpress-modal__description"><?php esc_html_e( 'Start a new post on your site with this one embedded.', 'jetpack' ); ?></p> |
| 195 | <form method="post"> |
| 196 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>" /> |
| 197 | <input type="hidden" name="jetpack-wordpress-destination" value="wordpress.com" /> |
| 198 | <button type="submit" class="sd-wordpress-modal__wpcom"><?php esc_html_e( 'Continue to WordPress.com', 'jetpack' ); ?></button> |
| 199 | </form> |
| 200 | <form method="post"> |
| 201 | <input type="hidden" name="_wpnonce" value="<?php echo esc_attr( $nonce ); ?>" /> |
| 202 | <input type="hidden" name="jetpack-wordpress-destination" value="site" /> |
| 203 | <label for="jetpack-wordpress-site"><?php esc_html_e( 'Or enter your site address', 'jetpack' ); ?></label> |
| 204 | <div class="sd-wordpress-modal__site"> |
| 205 | <input |
| 206 | required |
| 207 | aria-required="true" |
| 208 | aria-describedby="<?php echo esc_attr( null === $refused_site ? 'jetpack-wordpress-site-help' : 'jetpack-wordpress-site-error jetpack-wordpress-site-help' ); ?>" |
| 209 | aria-invalid="<?php echo esc_attr( null === $refused_site ? 'false' : 'true' ); ?>" |
| 210 | type="text" |
| 211 | inputmode="url" |
| 212 | autocomplete="url" |
| 213 | id="jetpack-wordpress-site" |
| 214 | name="jetpack-wordpress-site" |
| 215 | placeholder="<?php echo esc_attr( 'https://example.com' ); ?>" |
| 216 | value="<?php echo esc_attr( (string) $refused_site ); ?>" |
| 217 | /> |
| 218 | <button type="submit" class="sd-wordpress-modal__go"><?php esc_html_e( 'Go', 'jetpack' ); ?></button> |
| 219 | </div> |
| 220 | <?php if ( null !== $refused_site ) : ?> |
| 221 | <p id="jetpack-wordpress-site-error" class="sd-wordpress-modal__error" role="alert"><?php esc_html_e( 'That doesn’t look like a site address. Check it and try again.', 'jetpack' ); ?></p> |
| 222 | <?php endif; ?> |
| 223 | <p id="jetpack-wordpress-site-help" class="sd-wordpress-modal__help"><?php esc_html_e( 'If WordPress is installed in its own folder, include it, like example.com/wordpress.', 'jetpack' ); ?></p> |
| 224 | </form> |
| 225 | </main> |
| 226 | </body> |
| 227 | </html> |
| 228 | <?php |
| 229 | } |
| 230 | } |