diff options
Diffstat (limited to 'plugins/jetpack/modules/publicize/ui.php')
-rw-r--r-- | plugins/jetpack/modules/publicize/ui.php | 494 |
1 files changed, 263 insertions, 231 deletions
diff --git a/plugins/jetpack/modules/publicize/ui.php b/plugins/jetpack/modules/publicize/ui.php index 5e2e84e7..1cadc21d 100644 --- a/plugins/jetpack/modules/publicize/ui.php +++ b/plugins/jetpack/modules/publicize/ui.php @@ -10,6 +10,8 @@ class Publicize_UI { */ public $publicize; + protected $publicize_settings_url = ''; + /** * Hooks into WordPress to display the various pieces of UI and load our assets */ @@ -22,39 +24,48 @@ class Publicize_UI { } function init() { + $this->publicize_settings_url = apply_filters_deprecated( + 'jetpack_override_publicize_settings_url', + array( admin_url( 'options-general.php?page=sharing' ) ), + '6.7', + false, + __( 'This filter will be removed in a future version of Jetpack', 'jetpack' ) + ); + // Show only to users with the capability required to manage their Publicize connections. - /** - * Filter what user capability is required to use the publicize form on the edit post page. Useful if publish post capability has been removed from role. - * - * @module publicize - * - * @since 4.1.0 - * - * @param string $capability User capability needed to use publicize - */ - $capability = apply_filters( 'jetpack_publicize_capability', 'publish_posts' ); - if ( ! current_user_can( $capability ) ) { + if ( ! $this->publicize->current_user_can_access_publicize_data() ) { return; } // assets (css, js) - add_action( 'load-settings_page_sharing', array( &$this, 'load_assets' ) ); - add_action( 'admin_head-post.php', array( &$this, 'post_page_metabox_assets' ) ); - add_action( 'admin_head-post-new.php', array( &$this, 'post_page_metabox_assets' ) ); + if ( $this->in_jetpack ) { + add_action( 'load-settings_page_sharing', array( $this, 'load_assets' ) ); + } + add_action( 'admin_head-post.php', array( $this, 'post_page_metabox_assets' ) ); + add_action( 'admin_head-post-new.php', array( $this, 'post_page_metabox_assets' ) ); // management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen) - add_action( 'pre_admin_screen_sharing', array( &$this, 'admin_page' ) ); - add_action( 'post_submitbox_misc_actions', array( &$this, 'post_page_metabox' ) ); + add_action( 'pre_admin_screen_sharing', array( $this, 'admin_page' ) ); + add_action( 'post_submitbox_misc_actions', array( $this, 'post_page_metabox' ) ); } /** * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still */ function sharing_menu() { - add_submenu_page( 'options-general.php', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( &$this, 'management_page' ) ); + add_submenu_page( + 'options-general.php', + __( 'Sharing Settings', 'jetpack' ), + __( 'Sharing', 'jetpack' ), + 'publish_posts', + 'sharing', + array( $this, 'wrapper_admin_page' ) + ); } - + function wrapper_admin_page() { + Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ), array( 'is-wide' => true ) ); + } /** * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. */ @@ -72,9 +83,9 @@ class Publicize_UI { } /** - * styling for the sharing screen and popups - * JS for the options and switching - */ + * styling for the sharing screen and popups + * JS for the options and switching + */ function load_assets() { wp_enqueue_script( 'publicize', @@ -85,12 +96,14 @@ class Publicize_UI { array( 'jquery', 'thickbox' ), '20121019' ); - if( is_rtl() ) { + if ( is_rtl() ) { wp_enqueue_style( 'publicize', plugins_url( 'assets/rtl/publicize-rtl.css', __FILE__ ), array(), '20180301' ); } else { wp_enqueue_style( 'publicize', plugins_url( 'assets/publicize.css', __FILE__ ), array(), '20180301' ); } + Jetpack_Admin_Page::load_wrapper_styles(); + wp_enqueue_style( 'social-logos' ); add_thickbox(); } @@ -100,13 +113,14 @@ class Publicize_UI { <p><?php if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - $platform = __( 'WordPress.com', 'jetpack' ); + $platform = 'WordPress.com'; } else { - $platform = __( 'Jetpack', 'jetpack' ); + $platform = 'Jetpack'; } printf( - __( 'You have successfully connected your %1$s account with %2$s.', '1: Service Name (Facebook, Twitter, ...), 2. WordPress.com or Jetpack', 'jetpack' ), + /* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Site type (WordPress.com or Jetpack) */ + __( 'You have successfully connected your %1$s account with %2$s.', 'jetpack' ), Publicize::get_service_label( $service_name ), $platform ); ?></p> @@ -120,10 +134,23 @@ class Publicize_UI { } /** - * Lists the current user's publicized accounts for the blog - * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring - */ + * Lists the current user's publicized accounts for the blog + * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring + */ function admin_page() { + $override_publicize_settings_page = apply_filters_deprecated( + 'jetpack_override_publicize_settings_page', + array( false ), + '6.7', + false, + __( 'This filter will be removed in a future version of Jetpack', 'jetpack' ) + ); + + if ( $override_publicize_settings_page ) { + echo $override_publicize_settings_page; + return; + } + $_blog_id = get_current_blog_id(); ?> @@ -160,38 +187,38 @@ class Publicize_UI { <div class='left'> <?php - foreach ( $services as $name => $service ) : - $connect_url = $this->publicize->connect_url( $name ); + foreach ( $services as $service_name => $service ) : + $connect_url = $this->publicize->connect_url( $service_name ); if ( $service_num == ( round ( ( $total_num_of_services / 2 ), 0 ) ) ) echo "</div><div class='right'>"; $service_num++; ?> <div class="publicize-service-entry" <?php if ( $service_num > 0 ): ?>class="connected"<?php endif; ?> > - <div id="<?php echo esc_attr( $name ); ?>" class="publicize-service-left"> - <a href="<?php echo esc_url( $connect_url ); ?>" id="service-link-<?php echo esc_attr( $name ); ?>" target="_top"><?php echo $this->publicize->get_service_label( $name ); ?></a> + <div id="<?php echo esc_attr( $service_name ); ?>" class="publicize-service-left"> + <a href="<?php echo esc_url( $connect_url ); ?>" id="service-link-<?php echo esc_attr( $service_name ); ?>" target="_top"><?php echo $this->publicize->get_service_label( $service_name ); ?></a> </div> <div class="publicize-service-right"> - <?php if ( $this->publicize->is_enabled( $name ) && $connections = $this->publicize->get_connections( $name ) ) : ?> + <?php if ( $this->publicize->is_enabled( $service_name ) && $connections = $this->publicize->get_connections( $service_name ) ) : ?> <ul> <?php foreach( $connections as $c ) : $id = $this->publicize->get_connection_id( $c ); - $disconnect_url = $this->publicize->disconnect_url( $name, $id ); + $disconnect_url = $this->publicize->disconnect_url( $service_name, $id ); $cmeta = $this->publicize->get_connection_meta( $c ); - $profile_link = $this->publicize->get_profile_link( $name, $c ); - $connection_display = $this->publicize->get_display_name( $name, $c ); + $profile_link = $this->publicize->get_profile_link( $service_name, $c ); + $connection_display = $this->publicize->get_display_name( $service_name, $c ); - $options_nonce = wp_create_nonce( 'options_page_' . $name . '_' . $id ); ?> + $options_nonce = wp_create_nonce( 'options_page_' . $service_name . '_' . $id ); ?> - <?php if ( $this->publicize->show_options_popup( $name, $c ) ): ?> + <?php if ( $this->publicize->show_options_popup( $service_name, $c ) ): ?> <script type="text/javascript"> jQuery(document).ready( function($) { showOptionsPage.call( this, - '<?php echo esc_js( $name ); ?>', + '<?php echo esc_js( $service_name ); ?>', '<?php echo esc_js( $options_nonce ); ?>', '<?php echo esc_js( $id ); ?>' ); @@ -236,11 +263,11 @@ class Publicize_UI { <?php - $connections = $this->publicize->get_connections( $name ); + $connections = $this->publicize->get_connections( $service_name ); if ( empty ( $connections ) ) { ?> - <a id="<?php echo esc_attr( $name ); ?>" class="publicize-add-connection button" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Connect', 'jetpack' ) ); ?></a> + <a id="<?php echo esc_attr( $service_name ); ?>" class="publicize-add-connection button" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Connect', 'jetpack' ) ); ?></a> <?php } else { ?> - <a id="<?php echo esc_attr( $name ); ?>" class="publicize-add-connection button add-new" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Add New', 'jetpack' ) ); ?></a> + <a id="<?php echo esc_attr( $service_name ); ?>" class="publicize-add-connection button add-new" href="<?php echo esc_url( $connect_url ); ?>" target="_top"><?php echo esc_html( __( 'Add New', 'jetpack' ) ); ?></a> <?php } ?> </div> </div> @@ -278,7 +305,11 @@ class Publicize_UI { function broken_connection( $service_name, $id ) { ?> <div id="thickbox-content"> <div class='error'> - <p><?php printf( __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p> + <p><?php printf( + /* translators: %s: Service Name (Facebook, Twitter, ...) */ + __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), + Publicize::get_service_label( $service_name ) + ); ?></p> </div> </div><?php } @@ -306,9 +337,9 @@ class Publicize_UI { } /** - * CSS for styling the publicize message box and counter that displays on the post page. - * There is also some JavaScript for length counting and some basic display effects. - */ + * CSS for styling the publicize message box and counter that displays on the post page. + * There is also some JavaScript for length counting and some basic display effects. + */ function post_page_metabox_assets() { global $post; $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; @@ -320,22 +351,57 @@ class Publicize_UI { $default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) ); $default_suffix = $this->publicize->default_suffix; - $default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); ?> + $default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) ); + + $max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280; + $max_length = $max_length - 24; // t.co link, space + + ?> <script type="text/javascript"> jQuery( function($) { var wpasTitleCounter = $( '#wpas-title-counter' ), wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).length, - wpasTitle = $('#wpas-title').keyup( function() { - var length = wpasTitle.val().length; - wpasTitleCounter.text( length ); - if ( wpasTwitterCheckbox && length > 256 ) { + postTitle = $( '#title' ), + wpasTitle = $( '#wpas-title' ).keyup( function() { + var postTitleVal, + length = wpasTitle.val().length; + + if ( ! length ) { + length = wpasTitle.attr( 'placeholder' ).length; + } + + wpasTitleCounter.text( length ).trigger( 'change' ); + } ), + authClick = false; + + wpasTitleCounter.on( 'change', function( e ) { + if ( wpasTwitterCheckbox && parseInt( $( e.currentTarget ).text(), 10 ) > <?php echo (int) $max_length; ?> ) { wpasTitleCounter.addClass( 'wpas-twitter-length-limit' ); } else { wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' ); } - } ), - authClick = false; + } ); + + // Keep the postTitle and the placeholder in sync + postTitle.on( 'keyup', function( e ) { + var url = $( '#sample-permalink' ).text(); + var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, 'e.currentTarget.value', 'url' ); printf( $default_suffix, 'url' ); ?>' ) + .replace( /<[^>]+>/g,''); + + wpasTitle.attr( 'placeholder', defaultMessage ); + wpasTitle.trigger( 'keyup' ); + } ); + + // set the initial placeholder + postTitle.trigger( 'keyup' ); + + // If a custom message has been provided, open the UI so the author remembers + if ( wpasTitle.val() && ! wpasTitle.prop( 'disabled' ) && wpasTitle.attr( 'placeholder' ) !== wpasTitle.val() ) { + $( '#publicize-form' ).show(); + $( '#publicize-defaults' ).hide(); + $( '#publicize-form-edit' ).hide(); + } $('#publicize-disconnected-form-show').click( function() { $('#publicize-form').slideDown( 'fast' ); @@ -349,20 +415,17 @@ jQuery( function($) { $('#publicize-form-edit').click( function() { $('#publicize-form').slideDown( 'fast', function() { + var selBeg = 0, selEnd = 0; wpasTitle.focus(); - if ( !wpasTitle.text() ) { - var url = $('#shortlink').length ? $('#shortlink').val() : ''; - - var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, '$("#title").val()', 'url' ); printf( $default_suffix, 'url' ); ?>' ); - wpasTitle.append( defaultMessage.replace( /<[^>]+>/g,'') ); + if ( ! wpasTitle.text() ) { + wpasTitle.text( wpasTitle.attr( 'placeholder' ) ); - var selBeg = defaultMessage.indexOf( $("#title").val() ); + selBeg = wpasTitle.text().indexOf( postTitle.val() ); if ( selBeg < 0 ) { selBeg = 0; - selEnd = 0; } else { - selEnd = selBeg + $("#title").val().length; + selEnd = selBeg + postTitle.val().length; } var domObj = wpasTitle.get(0); @@ -375,8 +438,8 @@ jQuery( function($) { r.select(); } } - wpasTitle.keyup(); } ); + $('#publicize-defaults').hide(); $(this).hide(); return false; @@ -450,9 +513,10 @@ jQuery( function($) { // If any of the tests failed, show some stuff var somethingShownAlready = false; + var facebookNotice = false; $.each( response.data, function( index, testResult ) { // find the li for this connection - if ( ! testResult.connectionTestPassed ) { + if ( ! testResult.connectionTestPassed && testResult.userCanRefresh ) { if ( ! somethingShownAlready ) { testsSelector .addClass( 'below-h2' ) @@ -475,6 +539,26 @@ jQuery( function($) { .click( publicizeConnRefreshClick ); } } + + if( ! testResult.connectionTestPassed && ! testResult.userCanRefresh ) { + $( '#wpas-submit-' + testResult.unique_id ).prop( "checked", false ).prop( "disabled", true ); + if ( ! facebookNotice ) { + var message = '<p>' + + testResult.connectionTestMessage + + '</p><p>' + + ' <a class="button" href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank">' + + '<?php echo esc_html( __( 'Update Your Sharing Settings' ,'jetpack' ) ); ?>' + + '</a>' + + '<p>'; + + testsSelector + .addClass( 'below-h2' ) + .addClass( 'error' ) + .addClass( 'publicize-token-refresh-message' ) + .append( message ); + facebookNotice = true; + } + } } ); } @@ -532,6 +616,20 @@ jQuery( function($) { } /** + * @param string $service_label Service's human-readable Label ("Facebook", "Twitter", ...) + * @param string $display_name Connection's human-readable Username ("@jetpack", ...) + * @return string + */ + private function connection_label( $service_label, $display_name ) { + return sprintf( + /* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Username on Service (@jetpack, ...) */ + __( '%1$s: %2$s', 'jetpack' ), + $service_label, + $display_name + ); + } + + /** * Controls the metabox that is displayed on the post page * Allows the user to customize the message that will be sent out to the social network, as well as pick which * networks to publish to. Also displays the character counter and some other information. @@ -543,31 +641,51 @@ jQuery( function($) { return; $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author; - $services = $this->publicize->get_services( 'connected' ); + $connections_data = $this->publicize->get_filtered_connection_data(); + $available_services = $this->publicize->get_services( 'all' ); if ( ! is_array( $available_services ) ) $available_services = array(); - if ( ! is_array( $services ) ) - $services = array(); + if ( ! is_array( $connections_data ) ) + $connections_data = array(); ?> <div id="publicize" class="misc-pub-section misc-pub-section-last"> <span id="publicize-title"> - <?php esc_html_e( 'Publicize:', 'jetpack' ); ?> - <?php if ( 0 < count( $services ) ) : ?> - <?php list( $publicize_form, $active ) = $this->get_metabox_form_connected( $services ); ?> - <span id="publicize-defaults"> - <?php foreach ( $active as $item ) : ?> - <strong><?php echo esc_html( $item ); ?></strong> - <?php endforeach; ?> - </span> - <a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a> <a href="<?php echo esc_url( admin_url( 'options-general.php?page=sharing' ) ); ?>" rel="noopener noreferrer" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br /> - <?php else : ?> - <?php $publicize_form = $this->get_metabox_form_disconnected( $available_services ); ?> + <?php + esc_html_e( 'Publicize:', 'jetpack' ); + + if ( 0 < count( $connections_data ) ) : + $publicize_form = $this->get_metabox_form_connected( $connections_data ); + + $labels = array(); + foreach ( $connections_data as $connection_data ) { + if ( ! $connection_data['enabled'] ) { + continue; + } + + $labels[] = sprintf( + '<strong>%s</strong>', + esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ) + ); + } + + ?> + <span id="publicize-defaults"><?php echo join( ', ', $labels ); ?></span> + <a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a> <a href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br /> + <?php + + else : + $publicize_form = $this->get_metabox_form_disconnected( $available_services ); + + ?> <strong><?php echo __( 'Not Connected', 'jetpack' ); ?></strong> <a href="#" id="publicize-disconnected-form-show"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a><br /> - <?php endif; ?> + <?php + + endif; + ?> </span> <?php /** @@ -584,183 +702,97 @@ jQuery( function($) { </div> <?php // #publicize } - private function get_metabox_form_connected( $services ) { + /** + * Generates HTML content for connections form. + * + * @since 6.7 + * + * @global WP_Post $post The current post instance being published. + * + * @param array $connections_data + * + * @return array { + * Array of content for generating connection form. + * + * @type string HTML content of form + * @type array { + * Array of connection labels for active connections only. + * + * @type string Connection label string. + * } + * } + */ + private function get_metabox_form_connected( $connections_data ) { global $post; - $active = array(); - ob_start(); - ?> <div id="publicize-form" class="hide-if-js"> - <ul> - <?php - // We can set an _all flag to indicate that this post is completely done as - // far as Publicize is concerned. Jetpack uses this approach. All published posts in Jetpack - // have Publicize disabled. - $all_done = get_post_meta( $post->ID, $this->publicize->POST_DONE . 'all', true ) || ( $this->in_jetpack && 'publish' == $post->post_status ); - - // We don't allow Publicizing to the same external id twice, to prevent spam - $service_id_done = (array) get_post_meta( $post->ID, $this->publicize->POST_SERVICE_DONE, true ); - - foreach ( $services as $name => $connections ) { - foreach ( $connections as $connection ) { - $connection_data = ''; - if ( method_exists( $connection, 'get_meta' ) ) - $connection_data = $connection->get_meta( 'connection_data' ); - elseif ( ! empty( $connection['connection_data'] ) ) - $connection_data = $connection['connection_data']; - - /** - * Filter whether a post should be publicized to a given service. - * - * @module publicize - * - * @since 2.0.0 - * - * @param bool true Should the post be publicized to a given service? Default to true. - * @param int $post->ID Post ID. - * @param string $name Service name. - * @param array $connection_data Array of information about all Publicize details for the site. - */ - if ( ! $continue = apply_filters( 'wpas_submit_post?', true, $post->ID, $name, $connection_data ) ) { - continue; - } + $all_done = $this->publicize->post_is_done_sharing(); + $all_connections_done = true; - if ( ! empty( $connection->unique_id ) ) { - $unique_id = $connection->unique_id; - } else if ( ! empty( $connection['connection_data']['token_id'] ) ) { - $unique_id = $connection['connection_data']['token_id']; - } + ob_start(); - // Should we be skipping this one? - $skip = ( - ( - in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) - && - get_post_meta( $post->ID, $this->publicize->POST_SKIP . $unique_id, true ) - ) - || - ( - is_array( $connection ) - && - ( - ( isset( $connection['meta']['external_id'] ) && ! empty( $service_id_done[ $name ][ $connection['meta']['external_id'] ] ) ) - || - // Jetpack's connection data looks a little different. - ( isset( $connection['external_id'] ) && ! empty( $service_id_done[ $name ][ $connection['external_id'] ] ) ) - ) - ) - ); - - // Was this connections (OR, old-format service) already Publicized to? - $done = ( 1 == get_post_meta( $post->ID, $this->publicize->POST_DONE . $unique_id, true ) || 1 == get_post_meta( $post->ID, $this->publicize->POST_DONE . $name, true ) ); // New and old style flags - - // If this one has already been publicized to, don't let it happen again - $disabled = ''; - if ( $done ) { - $disabled = ' disabled="disabled"'; - } + ?> + <div id="publicize-form" class="hide-if-js"> + <ul> + <?php - // If this is a global connection and this user doesn't have enough permissions to modify - // those connections, don't let them change it - $cmeta = $this->publicize->get_connection_meta( $connection ); - $hidden_checkbox = false; - if ( !$done && ( 0 == $cmeta['connection_data']['user_id'] && !current_user_can( $this->publicize->GLOBAL_CAP ) ) ) { - $disabled = ' disabled="disabled"'; - /** - * Filters the checkboxes for global connections with non-prilvedged users. - * - * @module publicize - * - * @since 3.7.0 - * - * @param bool $checked Indicates if this connection should be enabled. Default true. - * @param int $post->ID ID of the current post - * @param string $name Name of the connection (Facebook, Twitter, etc) - * @param array $connection Array of data about the connection. - */ - $hidden_checkbox = apply_filters( 'publicize_checkbox_global_default', true, $post->ID, $name, $connection ); - } + foreach ( $connections_data as $connection_data ) { + $all_connections_done = $all_connections_done && $connection_data['done']; + ?> - // Determine the state of the checkbox (on/off) and allow filtering - $checked = $skip != 1 || $done; - /** - * Filter the checkbox state of each Publicize connection appearing in the post editor. - * - * @module publicize - * - * @since 2.0.1 - * - * @param bool $checked Should the Publicize checkbox be enabled for a given service. - * @param int $post->ID Post ID. - * @param string $name Service name. - * @param array $connection Array of connection details. - */ - $checked = apply_filters( 'publicize_checkbox_default', $checked, $post->ID, $name, $connection ); - - // Force the checkbox to be checked if the post was DONE, regardless of what the filter does - if ( $done ) { - $checked = true; - } + <li> + <label for="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>"> + <input + type="checkbox" + name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]" + id="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>" + class="wpas-submit-<?php echo esc_attr( $connection_data['service_name'] ); ?>" + value="1" + <?php + checked( true, $connection_data['enabled'] ); + disabled( false, $connection_data['toggleable'] ); + ?> + /> + <?php if ( $connection_data['enabled'] && ! $connection_data['toggleable'] ) : // Need to submit a value to force a global connection to POST ?> + <input + type="hidden" + name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]" + value="1" + /> + <?php endif; ?> + + <?php echo esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ); ?> + + </label> + </li> + <?php + } - // This post has been handled, so disable everything - if ( $all_done ) { - $disabled = ' disabled="disabled"'; - } + $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true ); + if ( ! $title ) { + $title = ''; + } - $label = sprintf( - _x( '%1$s: %2$s', 'Service: Account connected as', 'jetpack' ), - esc_html( $this->publicize->get_service_label( $name ) ), - esc_html( $this->publicize->get_display_name( $name, $connection ) ) - ); - if ( !$skip || $done ) { - $active[] = $label; - } - ?> - <li> - <label for="wpas-submit-<?php echo esc_attr( $unique_id ); ?>"> - <input type="checkbox" name="wpas[submit][<?php echo $unique_id; ?>]" id="wpas-submit-<?php echo $unique_id; ?>" class="wpas-submit-<?php echo $name; ?>" value="1" <?php - checked( true, $checked ); - echo $disabled; - ?> /> - <?php - if ( $hidden_checkbox ) { - // Need to submit a value to force a global connection to post - echo '<input type="hidden" name="wpas[submit][' . $unique_id . ']" value="1" />'; - } - echo esc_html( $label ); - ?> - </label> - </li> - <?php - } - } + $all_done = $all_done || $all_connections_done; - if ( $title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true ) ) { - $title = esc_html( $title ); - } else { - $title = ''; - } - ?> + ?> </ul> <label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label> <span id="wpas-title-counter" class="alignright hide-if-no-js">0</span> - - <textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo $title; ?></textarea> - + <textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo esc_textarea( $title ); ?></textarea> <a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a> <input type="hidden" name="wpas[0]" value="1" /> - </div> + <?php if ( ! $all_done ) : ?> <div id="pub-connection-tests"></div> <?php endif; ?> <?php // #publicize-form - return array( ob_get_clean(), $active ); + return ob_get_clean(); } - private function get_metabox_form_disconnected( $available_services ) { ob_start(); ?><div id="publicize-form" class="hide-if-js"> |