← All changes
|
jetpack_vendor/automattic/jetpack-publicize/src/class-publicize-ui.php
+86
-241
12.7.3
→
16.3
View file →
| @@ -7,11 +7,14 @@ | ||
| 7 | 7 | |
| 8 | 8 | namespace Automattic\Jetpack\Publicize; |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Assets; |
| 11 | +use Automattic\Jetpack\Current_Plan; | |
| 12 | +use Automattic\Jetpack\Publicize\Publicize_Utils as Utils; | |
| 13 | +use Automattic\Jetpack\Status\Host; | |
| 11 | 14 | |
| 12 | 15 | /** |
| 13 | - * Only user facing pieces of Publicize are found here. | |
| 16 | + * Classic editor integration: the Publicize metabox on the post screen, and its assets. | |
| 14 | 17 | */ |
| 15 | 18 | class Publicize_UI { |
| 16 | 19 | /** |
| 17 | 20 | * Contains an instance of class 'Publicize' which loads Keyring, sets up services, etc. |
| @@ -20,9 +23,9 @@ | ||
| 20 | 23 | */ |
| 21 | 24 | public $publicize; |
| 22 | 25 | |
| 23 | 26 | /** |
| 24 | - * URL to Sharing settings page in wordpress.com | |
| 27 | + * URL of the admin page where Publicize connections are managed. | |
| 25 | 28 | * |
| 26 | 29 | * @var string |
| 27 | 30 | */ |
| 28 | 31 | protected $publicize_settings_url = ''; |
| @@ -36,9 +39,9 @@ | ||
| 36 | 39 | $publicize = new Publicize(); |
| 37 | 40 | } |
| 38 | 41 | $this->publicize = $publicize; |
| 39 | 42 | |
| 40 | - add_action( 'init', array( $this, 'init' ) ); | |
| 43 | + add_action( 'admin_init', array( $this, 'init' ) ); | |
| 41 | 44 | } |
| 42 | 45 | |
| 43 | 46 | /** |
| 44 | 47 | * Initialize UI-related functionality. |
| @@ -43,107 +46,23 @@ | ||
| 43 | 46 | /** |
| 44 | 47 | * Initialize UI-related functionality. |
| 45 | 48 | */ |
| 46 | 49 | public function init() { |
| 47 | - $this->publicize_settings_url = $this->publicize->publicize_connections_url(); | |
| 48 | - | |
| 49 | 50 | // Show only to users with the capability required to manage their Publicize connections. |
| 50 | - if ( ! $this->publicize->current_user_can_access_publicize_data() ) { | |
| 51 | + if ( ! Utils::is_publicize_active() || ! $this->publicize->current_user_can_access_publicize_data() ) { | |
| 51 | 52 | return; |
| 52 | 53 | } |
| 53 | 54 | |
| 55 | + $this->publicize_settings_url = $this->publicize->publicize_connections_url(); | |
| 56 | + | |
| 54 | 57 | // Assets (css, js). |
| 55 | - add_action( 'load-settings_page_sharing', array( $this, 'load_assets' ) ); | |
| 56 | 58 | add_action( 'admin_head-post.php', array( $this, 'post_page_metabox_assets' ) ); |
| 57 | 59 | add_action( 'admin_head-post-new.php', array( $this, 'post_page_metabox_assets' ) ); |
| 58 | 60 | |
| 59 | - // Management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen). | |
| 60 | - add_action( 'pre_admin_screen_sharing', array( $this, 'admin_page' ) ); | |
| 61 | 61 | add_action( 'post_submitbox_misc_actions', array( $this, 'post_page_metabox' ) ); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
| 65 | - * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still | |
| 66 | - */ | |
| 67 | - public function sharing_menu() { | |
| 68 | - add_submenu_page( | |
| 69 | - 'options-general.php', | |
| 70 | - esc_html__( 'Sharing Settings', 'jetpack-publicize-pkg' ), | |
| 71 | - esc_html__( 'Sharing', 'jetpack-publicize-pkg' ), | |
| 72 | - 'publish_posts', | |
| 73 | - 'sharing', | |
| 74 | - array( $this, 'wrapper_admin_page' ) | |
| 75 | - ); | |
| 76 | - } | |
| 77 | - | |
| 78 | - /** | |
| 79 | - * Add admin page with wrapper. | |
| 80 | - */ | |
| 81 | - public function wrapper_admin_page() { | |
| 82 | - if ( class_exists( 'Jetpack_Admin_Page' ) ) { | |
| 83 | - \Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ) ); | |
| 84 | - } | |
| 85 | - } | |
| 86 | - | |
| 87 | - /** | |
| 88 | - * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. | |
| 89 | - */ | |
| 90 | - public function management_page() { | |
| 91 | - ?> | |
| 92 | - <div class="wrap"> | |
| 93 | - <div class="icon32" id="icon-options-general"><br /></div> | |
| 94 | - <h1><?php esc_html_e( 'Sharing Settings', 'jetpack-publicize-pkg' ); ?></h1> | |
| 95 | - | |
| 96 | - <?php | |
| 97 | - /** This action is documented in modules/sharedaddy/sharing.php */ | |
| 98 | - do_action( 'pre_admin_screen_sharing' ); | |
| 99 | - ?> | |
| 100 | - </div> | |
| 101 | - <?php | |
| 102 | - } | |
| 103 | - | |
| 104 | - /** | |
| 105 | - * Styling for the sharing screen and popups | |
| 106 | - * JS for the options and switching | |
| 107 | - */ | |
| 108 | - public function load_assets() { | |
| 109 | - if ( class_exists( 'Jetpack_Admin_Page' ) ) { | |
| 110 | - \Jetpack_Admin_Page::load_wrapper_styles(); | |
| 111 | - } | |
| 112 | - } | |
| 113 | - | |
| 114 | - /** | |
| 115 | - * Lists the current user's publicized accounts for the blog | |
| 116 | - * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring | |
| 117 | - */ | |
| 118 | - public function admin_page() { | |
| 119 | - ?> | |
| 120 | - <h2 id="publicize"><?php esc_html_e( 'Jetpack Social', 'jetpack-publicize-pkg' ); ?></h2> | |
| 121 | - <p><?php esc_html_e( 'Connect social media services to automatically share new posts.', 'jetpack-publicize-pkg' ); ?></p> | |
| 122 | - <h4> | |
| 123 | - <?php | |
| 124 | - printf( | |
| 125 | - wp_kses( | |
| 126 | - /* translators: %s is the link to the Publicize page in Calypso */ | |
| 127 | - __( "We've made some updates to Jetpack Social. Please visit the <a href='%s' class='jptracks' data-jptracks-name='legacy_publicize_settings'>WordPress.com sharing page</a> to manage your Jetpack Social connections or use the button below.", 'jetpack-publicize-pkg' ), | |
| 128 | - array( | |
| 129 | - 'a' => array( | |
| 130 | - 'href' => array(), | |
| 131 | - 'class' => array(), | |
| 132 | - 'data-jptracks-name' => array(), | |
| 133 | - ), | |
| 134 | - ) | |
| 135 | - ), | |
| 136 | - esc_url( $this->publicize->publicize_connections_url() ) | |
| 137 | - ); | |
| 138 | - ?> | |
| 139 | - </h4> | |
| 140 | - | |
| 141 | - <a href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" class="button button-primary jptracks" data-jptracks-name='legacy_publicize_settings'><?php esc_html_e( 'Jetpack Social Settings', 'jetpack-publicize-pkg' ); ?></a> | |
| 142 | - <?php | |
| 143 | - } | |
| 144 | - | |
| 145 | - /** | |
| 146 | 65 | * CSS for styling the publicize message box and counter that displays on the post page. |
| 147 | 66 | * There is also some JavaScript for length counting and some basic display effects. |
| 148 | 67 | */ |
| 149 | 68 | public function post_page_metabox_assets() { |
| @@ -152,11 +71,15 @@ | ||
| 152 | 71 | if ( $current_screen && $current_screen->is_block_editor ) { |
| 153 | 72 | return; |
| 154 | 73 | } |
| 155 | 74 | |
| 75 | + $is_atomic_site = ( new Host() )->is_woa_site(); | |
| 76 | + $is_simple_site = ( new Host() )->is_wpcom_simple(); | |
| 77 | + $site_type = $is_atomic_site ? 'atomic' : ( $is_simple_site ? 'simple' : 'jetpack' ); | |
| 78 | + | |
| 156 | 79 | Assets::register_script( |
| 157 | 80 | 'jetpack-social-classic-editor-options', |
| 158 | - '../build/classic-editor-connections.js', | |
| 81 | + '../build/classic-editor.js', | |
| 159 | 82 | __FILE__, |
| 160 | 83 | array( |
| 161 | 84 | 'in_footer' => true, |
| 162 | 85 | 'enqueue' => true, |
| @@ -162,31 +85,36 @@ | ||
| 162 | 85 | 'enqueue' => true, |
| 163 | 86 | 'textdomain' => 'jetpack-publicize-pkg', |
| 164 | 87 | ) |
| 165 | 88 | ); |
| 89 | + | |
| 166 | 90 | wp_add_inline_script( |
| 167 | 91 | 'jetpack-social-classic-editor-options', |
| 168 | 92 | 'var jetpackSocialClassicEditorOptions = ' . wp_json_encode( |
| 169 | 93 | array( |
| 170 | - 'ajaxUrl' => admin_url( 'admin-ajax.php' ), | |
| 171 | 94 | 'connectionsUrl' => esc_url( $this->publicize_settings_url ), |
| 172 | 95 | 'isEnhancedPublishingEnabled' => $this->publicize->has_enhanced_publishing_feature(), |
| 173 | - ) | |
| 96 | + 'resharePath' => '/wpcom/v2/publicize/share-post/{postId}', | |
| 97 | + 'refreshConnections' => '/wpcom/v2/publicize/connections?test_connections=1', | |
| 98 | + 'isReshareSupported' => Current_Plan::supports( 'republicize' ), | |
| 99 | + 'siteType' => $site_type, | |
| 100 | + ), | |
| 101 | + JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP | |
| 174 | 102 | ), |
| 175 | 103 | 'before' |
| 176 | 104 | ); |
| 177 | 105 | |
| 178 | 106 | $default_prefix = $this->publicize->default_prefix; |
| 179 | - $default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) ); | |
| 107 | + $default_prefix = preg_replace( '/%([0-9])\$s/', '" + %\\1$s + "', wp_json_encode( (string) $default_prefix, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) ); | |
| 180 | 108 | |
| 181 | 109 | $default_message = $this->publicize->default_message; |
| 182 | - $default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); | |
| 110 | + $default_message = preg_replace( '/%([0-9])\$s/', '" + %\\1$s + "', wp_json_encode( (string) $default_message, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) ); | |
| 183 | 111 | |
| 184 | 112 | $default_suffix = $this->publicize->default_suffix; |
| 185 | - $default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); | |
| 113 | + $default_suffix = preg_replace( '/%([0-9])\$s/', '" + %\\1$s + "', wp_json_encode( (string) $default_suffix, JSON_UNESCAPED_SLASHES | JSON_HEX_TAG | JSON_HEX_AMP ) ); | |
| 186 | 114 | |
| 187 | - $max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280; | |
| 188 | - $max_length = $max_length - 24; // t.co link, space. | |
| 115 | + $max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280; | |
| 116 | + $max_length -= 24; // t.co link, space. | |
| 189 | 117 | |
| 190 | 118 | ?> |
| 191 | 119 | |
| 192 | 120 | <script type="text/javascript"> |
| @@ -217,9 +145,9 @@ | ||
| 217 | 145 | // Keep the postTitle and the placeholder in sync |
| 218 | 146 | postTitle.on( 'keyup', function( e ) { |
| 219 | 147 | var url = $( '#sample-permalink' ).text(); |
| 220 | 148 | <?php // phpcs:ignore ?> |
| 221 | - var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, 'e.currentTarget.value', 'url' ); printf( $default_suffix, 'url' ); ?>' ) | |
| 149 | + var defaultMessage = $.trim( <?php printf( $default_prefix, 'url' ); ?> + <?php printf( $default_message, 'e.currentTarget.value', 'url' ); ?> + <?php printf( $default_suffix, 'url' ); ?> ) | |
| 222 | 150 | .replace( /<[^>]+>/g,''); |
| 223 | 151 | |
| 224 | 152 | wpasTitle.attr( 'placeholder', defaultMessage ); |
| 225 | 153 | wpasTitle.trigger( 'keyup' ); |
| @@ -354,9 +282,9 @@ | ||
| 354 | 282 | } |
| 355 | 283 | .publicize-external-link__text { |
| 356 | 284 | text-decoration: underline; |
| 357 | 285 | } |
| 358 | -#publicize-title:before { | |
| 286 | +#publicize-title::before { | |
| 359 | 287 | content: "\f237"; |
| 360 | 288 | font: normal 20px/1 dashicons; |
| 361 | 289 | speak: none; |
| 362 | 290 | margin-left: -1px; |
| @@ -380,8 +308,11 @@ | ||
| 380 | 308 | .publicize__notice-warning .dashicons { |
| 381 | 309 | font-size: 16px; |
| 382 | 310 | text-decoration: none; |
| 383 | 311 | } |
| 312 | +.publicize-placeholders-help { | |
| 313 | + margin: 0.5rem 0 1rem; | |
| 314 | +} | |
| 384 | 315 | </style> |
| 385 | 316 | <?php |
| 386 | 317 | } |
| 387 | 318 | |
| @@ -401,26 +332,8 @@ | ||
| 401 | 332 | ); |
| 402 | 333 | } |
| 403 | 334 | |
| 404 | 335 | /** |
| 405 | - * Extracts the connections that require reauthentication, for example, LinkedIn, when it switched v1 to v2 of its API. | |
| 406 | - * | |
| 407 | - * @return array Connections that must be reauthenticated | |
| 408 | - */ | |
| 409 | - public function get_must_reauth_connections() { | |
| 410 | - $must_reauth = array(); | |
| 411 | - $connections = $this->publicize->get_connections( 'linkedin' ); | |
| 412 | - if ( is_array( $connections ) ) { | |
| 413 | - foreach ( $connections as $index => $connection ) { | |
| 414 | - if ( $this->publicize->is_invalid_linkedin_connection( $connection ) ) { | |
| 415 | - $must_reauth[ $index ] = 'LinkedIn'; | |
| 416 | - } | |
| 417 | - } | |
| 418 | - } | |
| 419 | - return $must_reauth; | |
| 420 | - } | |
| 421 | - | |
| 422 | - /** | |
| 423 | 336 | * Controls the metabox that is displayed on the post page |
| 424 | 337 | * Allows the user to customize the message that will be sent out to the social network, as well as pick which |
| 425 | 338 | * networks to publish to. Also displays the character counter and some other information. |
| 426 | 339 | */ |
| @@ -432,14 +345,8 @@ | ||
| 432 | 345 | } |
| 433 | 346 | |
| 434 | 347 | $connections_data = $this->publicize->get_filtered_connection_data(); |
| 435 | 348 | |
| 436 | - $available_services = $this->publicize->get_services( 'all' ); | |
| 437 | - | |
| 438 | - if ( ! is_array( $available_services ) ) { | |
| 439 | - $available_services = array(); | |
| 440 | - } | |
| 441 | - | |
| 442 | 349 | if ( ! is_array( $connections_data ) ) { |
| 443 | 350 | $connections_data = array(); |
| 444 | 351 | } |
| 445 | 352 | ?> |
| @@ -450,40 +357,12 @@ | ||
| 450 | 357 | |
| 451 | 358 | if ( ! empty( $connections_data ) ) : |
| 452 | 359 | $publicize_form = $this->get_metabox_form_connected( $connections_data ); |
| 453 | 360 | |
| 454 | - $must_reauth = $this->get_must_reauth_connections(); | |
| 455 | - if ( ! empty( $must_reauth ) ) { | |
| 456 | - foreach ( $must_reauth as $connection_name ) { | |
| 457 | - ?> | |
| 458 | - <span class="notice-warning publicize__notice-warning"> | |
| 459 | - <?php | |
| 460 | - printf( | |
| 461 | - /* translators: %s is the name of a Jetpack Social service like "LinkedIn" */ | |
| 462 | - esc_html__( | |
| 463 | - 'Your %s connection needs to be reauthenticated to continue working – head to Sharing to take care of it.', | |
| 464 | - 'jetpack-publicize-pkg' | |
| 465 | - ), | |
| 466 | - $connection_name // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped | |
| 467 | - ); | |
| 468 | - ?> | |
| 469 | - <a | |
| 470 | - class="publicize-external-link" | |
| 471 | - href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" | |
| 472 | - target="_blank" | |
| 473 | - > | |
| 474 | - <span class="publicize-external-link__text"><?php esc_html_e( 'Go to Sharing settings', 'jetpack-publicize-pkg' ); ?></span> | |
| 475 | - <span class="dashicons dashicons-external"></span> | |
| 476 | - </a> | |
| 477 | - </span> | |
| 478 | - <?php | |
| 479 | - } | |
| 480 | - } | |
| 481 | - | |
| 482 | 361 | $labels = array(); |
| 483 | 362 | |
| 484 | 363 | foreach ( $connections_data as $connection_data ) { |
| 485 | - if ( ! $connection_data['enabled'] || ( isset( $connection_data['is_healthy'] ) && false === $connection_data['is_healthy'] ) ) { | |
| 364 | + if ( ! $connection_data['enabled'] ) { | |
| 486 | 365 | continue; |
| 487 | 366 | } |
| 488 | 367 | |
| 489 | 368 | $labels[] = sprintf( |
| @@ -494,15 +373,15 @@ | ||
| 494 | 373 | |
| 495 | 374 | ?> |
| 496 | 375 | <?php // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- labels are already escaped above ?> |
| 497 | 376 | <span id="publicize-defaults"><?php echo implode( ', ', $labels ); ?></span> |
| 498 | - <a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack-publicize-pkg' ); ?></a> <a href="<?php echo esc_url( $this->publicize->publicize_connections_url( 'jetpack-social-connections-classic-editor' ) ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Settings', 'jetpack-publicize-pkg' ); ?></a><br /> | |
| 377 | + <a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack-publicize-pkg' ); ?></a> <a href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Settings', 'jetpack-publicize-pkg' ); ?></a><br /> | |
| 499 | 378 | <?php |
| 500 | 379 | else : |
| 501 | - $publicize_form = $this->get_metabox_form_disconnected( $available_services ); | |
| 380 | + $publicize_form = ''; | |
| 502 | 381 | ?> |
| 503 | 382 | <strong><?php esc_html_e( 'Not Connected', 'jetpack-publicize-pkg' ); ?></strong> |
| 504 | - <a href="<?php echo esc_url( $this->publicize->publicize_connections_url( 'jetpack-social-connections-classic-editor' ) ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Settings', 'jetpack-publicize-pkg' ); ?></a><br /> | |
| 383 | + <a href="<?php echo esc_url( $this->publicize->publicize_connections_url() ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'Settings', 'jetpack-publicize-pkg' ); ?></a><br /> | |
| 505 | 384 | <?php |
| 506 | 385 | |
| 507 | 386 | endif; |
| 508 | 387 | ?> |
| @@ -560,12 +439,8 @@ | ||
| 560 | 439 | */ |
| 561 | 440 | private function get_metabox_form_connected( $connections_data ) { |
| 562 | 441 | global $post; |
| 563 | 442 | |
| 564 | - $all_done = $this->publicize->post_is_done_sharing(); | |
| 565 | - $all_connections_done = true; | |
| 566 | - $broken_connections = array(); | |
| 567 | - | |
| 568 | 443 | ob_start(); |
| 569 | 444 | |
| 570 | 445 | ?> |
| 571 | 446 | <div id="publicize-form" class="hide-if-js"> |
| @@ -572,40 +447,25 @@ | ||
| 572 | 447 | <ul> |
| 573 | 448 | <?php |
| 574 | 449 | |
| 575 | 450 | foreach ( $connections_data as $connection_data ) { |
| 576 | - $all_connections_done = $all_connections_done && $connection_data['done']; | |
| 577 | - $connection_healthy = ! isset( $connection_data['is_healthy'] ) || $connection_data['is_healthy']; | |
| 578 | - if ( ! $connection_healthy ) { | |
| 579 | - $broken_connections[] = $connection_data; | |
| 580 | - | |
| 581 | - } | |
| 582 | 451 | ?> |
| 583 | 452 | |
| 584 | 453 | <li> |
| 585 | 454 | <label |
| 586 | - for="wpas-submit-<?php echo esc_attr( $connection_data['id'] ); ?>" | |
| 587 | - <?php echo ! $connection_data['toggleable'] ? 'class="wpas-disabled"' : ''; ?> | |
| 455 | + for="wpas-submit-<?php echo esc_attr( $connection_data['connection_id'] ); ?>" | |
| 588 | 456 | > |
| 589 | 457 | <input |
| 590 | 458 | type="checkbox" |
| 591 | - name="wpas[submit][<?php echo esc_attr( $connection_data['id'] ); ?>]" | |
| 592 | - id="wpas-submit-<?php echo esc_attr( $connection_data['id'] ); ?>" | |
| 459 | + name="wpas[submit][<?php echo esc_attr( $connection_data['connection_id'] ); ?>]" | |
| 460 | + id="wpas-submit-<?php echo esc_attr( $connection_data['connection_id'] ); ?>" | |
| 593 | 461 | class="wpas-submit-<?php echo esc_attr( $connection_data['service_name'] ); ?>" |
| 594 | 462 | value="1" |
| 463 | + data-id="<?php echo esc_attr( $connection_data['connection_id'] ); ?>" | |
| 595 | 464 | <?php |
| 596 | - checked( true, $connection_data['enabled'] && $connection_healthy ); | |
| 597 | - disabled( false, $connection_data['toggleable'] && $connection_healthy ); | |
| 465 | + checked( true, $connection_data['enabled'] ); | |
| 598 | 466 | ?> |
| 599 | 467 | /> |
| 600 | - <?php if ( $connection_data['enabled'] && $connection_healthy && ! $connection_data['toggleable'] ) : // Need to submit a value to force a global connection to POST. ?> | |
| 601 | - <input | |
| 602 | - type="hidden" | |
| 603 | - name="wpas[submit][<?php echo esc_attr( $connection_data['id'] ); ?>]" | |
| 604 | - value="1" | |
| 605 | - /> | |
| 606 | - <?php endif; ?> | |
| 607 | - | |
| 608 | 468 | <?php echo esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ); ?> |
| 609 | 469 | |
| 610 | 470 | </label> |
| 611 | 471 | </li> |
| @@ -616,52 +476,55 @@ | ||
| 616 | 476 | if ( ! $title ) { |
| 617 | 477 | $title = ''; |
| 618 | 478 | } |
| 619 | 479 | |
| 620 | - $all_done = $all_done || $all_connections_done; | |
| 480 | + $is_social_note = 'jetpack-social-note' === get_post_type( $post->ID ); | |
| 621 | 481 | |
| 482 | + $is_post_published = 'publish' === get_post_status( $post->ID ); | |
| 483 | + | |
| 484 | + $templates_enabled = $this->publicize->has_paid_features(); | |
| 485 | + | |
| 486 | + $placeholders = $this->get_message_placeholders(); | |
| 487 | + | |
| 622 | 488 | ?> |
| 623 | 489 | |
| 624 | 490 | </ul> |
| 625 | 491 | |
| 626 | - <label for="wpas-title"><?php esc_html_e( 'Custom Message:', 'jetpack-publicize-pkg' ); ?></label> | |
| 627 | - <span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> | |
| 628 | - <textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo esc_textarea( $title ); ?></textarea> | |
| 629 | - <a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack-publicize-pkg' ); ?></a> | |
| 630 | - <input type="hidden" name="wpas[0]" value="1" /> | |
| 492 | + <?php if ( ! $is_social_note ) : ?> | |
| 493 | + <label for="wpas-title"><?php esc_html_e( 'Custom Message:', 'jetpack-publicize-pkg' ); ?></label> | |
| 494 | + <?php if ( ! $templates_enabled ) : ?> | |
| 495 | + <span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> | |
| 496 | + <?php endif; ?> | |
| 497 | + <textarea name="wpas_title" id="wpas-title"><?php echo esc_textarea( $title ); ?></textarea> | |
| 498 | + <?php if ( $templates_enabled && ! empty( $placeholders ) ) : ?> | |
| 499 | + <details class="publicize-placeholders-help"> | |
| 500 | + <summary><?php esc_html_e( 'Available placeholders', 'jetpack-publicize-pkg' ); ?></summary> | |
| 501 | + <p> | |
| 502 | + <?php esc_html_e( 'Use placeholders to automatically insert post details.', 'jetpack-publicize-pkg' ); ?> | |
| 503 | + </p> | |
| 504 | + <ul> | |
| 505 | + <?php foreach ( $placeholders as $placeholder ) : ?> | |
| 506 | + <li> | |
| 507 | + <code><?php echo esc_html( $placeholder['id'] ); ?></code> | |
| 508 | + — <?php echo esc_html( $placeholder['label'] ); ?> | |
| 509 | + </li> | |
| 510 | + <?php endforeach; ?> | |
| 511 | + </ul> | |
| 512 | + </details> | |
| 513 | + <?php endif; ?> | |
| 514 | + <a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack-publicize-pkg' ); ?></a> | |
| 515 | + <input type="hidden" name="wpas[0]" value="1" /> | |
| 516 | + <?php endif; ?> | |
| 517 | + <?php if ( $is_post_published && Current_Plan::supports( 'republicize' ) ) : ?> | |
| 518 | + <button type="button" class="hide-if-no-js button" id="publicize-share-now"> | |
| 519 | + <?php esc_html_e( 'Share now', 'jetpack-publicize-pkg' ); ?> | |
| 520 | + </button> | |
| 521 | + <span id="publicize-share-now-notice" class="hidden"></span> | |
| 522 | + <?php endif; ?> | |
| 631 | 523 | </div> |
| 632 | 524 | |
| 633 | 525 | <div id="pub-connection-needs-media"></div> |
| 634 | - | |
| 635 | - <?php if ( ! $all_done ) : ?> | |
| 636 | - <?php if ( $broken_connections ) : ?> | |
| 637 | - <div id="pub-connection-tests" class="error below-h2 publicize-token-refresh-message"> | |
| 638 | - <?php | |
| 639 | - printf( | |
| 640 | - wp_kses( | |
| 641 | - /* translators: %s is the link to the connections page in Calypso */ | |
| 642 | - _n( | |
| 643 | - 'One of your social connections is broken. Reconnect it on the <a href="%s" rel="noopener noreferrer" target="_blank">connection management</a> page.', | |
| 644 | - 'Some of your social connections are broken. Reconnect them on the <a href="%s" rel="noopener noreferrer" target="_blank">connection management</a> page.', | |
| 645 | - count( $broken_connections ), | |
| 646 | - 'jetpack-publicize-pkg' | |
| 647 | - ), | |
| 648 | - array( | |
| 649 | - 'a' => array( | |
| 650 | - 'href' => array(), | |
| 651 | - 'target' => array(), | |
| 652 | - 'rel' => array(), | |
| 653 | - ), | |
| 654 | - ) | |
| 655 | - ), | |
| 656 | - esc_url( $this->publicize->publicize_connections_url() ) | |
| 657 | - ); | |
| 658 | - ?> | |
| 659 | - </div> | |
| 660 | - <?php else : ?> | |
| 661 | - <div id="pub-connection-tests"></div> | |
| 662 | - <?php endif; ?> | |
| 663 | - <?php endif; ?> | |
| 526 | + <div id="pub-connection-tests"></div> | |
| 664 | 527 | <?php |
| 665 | 528 | |
| 666 | 529 | return ob_get_clean(); |
| 667 | 530 | } |
| @@ -666,33 +529,15 @@ | ||
| 666 | 529 | return ob_get_clean(); |
| 667 | 530 | } |
| 668 | 531 | |
| 669 | 532 | /** |
| 670 | - * Metabox that is shown when no services are connected. | |
| 533 | + * Get the catalogue of placeholders supported in custom Publicize messages. | |
| 671 | 534 | * |
| 672 | - * @param array $available_services Array of available services for connecting. | |
| 535 | + * Sourced from WPCOM via `Message_Templates_Placeholders` so the metabox | |
| 536 | + * hint can never drift from the resolver in `Template_Parser`. | |
| 537 | + * | |
| 538 | + * @return array<int, array{id: string, label: string}> Ordered list of placeholders. | |
| 673 | 539 | */ |
| 674 | - private function get_metabox_form_disconnected( $available_services ) { | |
| 675 | - ob_start(); | |
| 676 | - ?> | |
| 677 | - <div id="publicize-form" class="hide-if-js"> | |
| 678 | - <div id="add-publicize-check" style="display: none;"></div> | |
| 679 | - | |
| 680 | - <?php esc_html_e( 'Connect to', 'jetpack-publicize-pkg' ); ?>: | |
| 681 | - | |
| 682 | - <ul class="not-connected"> | |
| 683 | - <?php foreach ( $available_services as $service_name => $service ) : ?> | |
| 684 | - <li> | |
| 685 | - <?php /* translators: %s is the name of a Publicize service such as "LinkedIn" */ ?> | |
| 686 | - <a class="pub-service" data-service="<?php echo esc_attr( $service_name ); ?>" title="<?php echo esc_attr( sprintf( __( 'Connect and share your posts on %s', 'jetpack-publicize-pkg' ), $this->publicize->get_service_label( $service_name ) ) ); ?>" rel="noopener noreferrer" target="_blank" href="<?php echo esc_url( $this->publicize->connect_url( $service_name ) ); ?>"> | |
| 687 | - <?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?> | |
| 688 | - </a> | |
| 689 | - </li> | |
| 690 | - <?php endforeach; ?> | |
| 691 | - </ul> | |
| 692 | - <a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack-publicize-pkg' ); ?></a> | |
| 693 | - </div> | |
| 694 | - <?php | |
| 695 | - | |
| 696 | - return ob_get_clean(); | |
| 540 | + private function get_message_placeholders() { | |
| 541 | + return Message_Templates_Placeholders::get_all(); | |
| 697 | 542 | } |
| 698 | 543 | } |