diff options
Diffstat (limited to 'plugins/jetpack/modules/publicize/ui.php')
-rw-r--r-- | plugins/jetpack/modules/publicize/ui.php | 349 |
1 files changed, 95 insertions, 254 deletions
diff --git a/plugins/jetpack/modules/publicize/ui.php b/plugins/jetpack/modules/publicize/ui.php index 1cadc21d..43a6c05f 100644 --- a/plugins/jetpack/modules/publicize/ui.php +++ b/plugins/jetpack/modules/publicize/ui.php @@ -10,6 +10,9 @@ class Publicize_UI { */ public $publicize; + /** + * @var string URL to Sharing settings page in wordpress.com + */ protected $publicize_settings_url = ''; /** @@ -24,13 +27,7 @@ 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' ) - ); + $this->publicize_settings_url = publicize_calypso_url(); // Show only to users with the capability required to manage their Publicize connections. if ( ! $this->publicize->current_user_can_access_publicize_data() ) { @@ -50,13 +47,13 @@ class Publicize_UI { } /** - * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still - */ + * 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' ), + esc_html__( 'Sharing Settings', 'jetpack' ), + esc_html__( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', array( $this, 'wrapper_admin_page' ) @@ -64,20 +61,21 @@ class Publicize_UI { } function wrapper_admin_page() { - Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ), array( 'is-wide' => true ) ); + Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ) ); } + /** - * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. - */ + * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists. + */ function management_page() { ?> <div class="wrap"> <div class="icon32" id="icon-options-general"><br /></div> - <h1><?php _e( 'Sharing Settings', 'jetpack' ); ?></h1> + <h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1> - <?php - /** This action is documented in modules/sharedaddy/sharing.php */ - do_action( 'pre_admin_screen_sharing' ); - ?> + <?php + /** This action is documented in modules/sharedaddy/sharing.php */ + do_action( 'pre_admin_screen_sharing' ); + ?> </div> <?php } @@ -87,50 +85,7 @@ class Publicize_UI { * JS for the options and switching */ function load_assets() { - wp_enqueue_script( - 'publicize', - Jetpack::get_file_url_for_environment( - '_inc/build/publicize/assets/publicize.min.js', - 'modules/publicize/assets/publicize.js' - ), - array( 'jquery', 'thickbox' ), - '20121019' - ); - 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(); - } - - public static function connected_notice( $service_name ) { ?> - <div class='updated'> - <p><?php - - if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { - $platform = 'WordPress.com'; - } else { - $platform = 'Jetpack'; - } - - printf( - /* 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> - </div><?php - } - - public static function denied_notice() { ?> - <div class='updated'> - <p><?php _e ( "You have chosen not to connect your blog. Please click 'accept' when prompted if you wish to connect your accounts.", 'jetpack' ); ?></p> - </div><?php } /** @@ -138,201 +93,21 @@ class Publicize_UI { * 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(); - ?> - - <form action="" id="publicize-form"> - <h2 id="publicize"><?php _e( 'Publicize', 'jetpack' ) ?></h2> - - <?php - if ( ! empty( $_GET['action'] ) && 'deny' == $_GET['action'] ) { - $this->denied_notice(); - } - ?> - - <p> - <?php esc_html_e( 'Connect your blog to popular social networking sites and automatically share new posts with your friends.', 'jetpack' ) ?> - <?php esc_html_e( 'You can make a connection for just yourself or for all users on your blog. Shared connections are marked with the (Shared) text.', 'jetpack' ); ?> - </p> - - <?php - if ( $this->in_jetpack ) { - $doc_link = "http://jetpack.com/support/publicize/"; - } else { - $doc_link = "http://en.support.wordpress.com/publicize/"; - } - ?> - - <p>→ <a href="<?php echo esc_url( $doc_link ); ?>" rel="noopener noreferrer" target="_blank"><?php esc_html_e( 'More information on using Publicize.', 'jetpack' ); ?></a></p> - - <div id="publicize-services-block"> - <?php - $services = $this->publicize->get_services( 'all' ); - $total_num_of_services = count ( $services ); - $service_num = 0;?> - - <div class='left'> - - <?php - 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( $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( $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( $service_name, $id ); - - $cmeta = $this->publicize->get_connection_meta( $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_' . $service_name . '_' . $id ); ?> - - <?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( $service_name ); ?>', - '<?php echo esc_js( $options_nonce ); ?>', - '<?php echo esc_js( $id ); ?>' - ); - } ); - </script> - <?php endif; ?> - - <li class="publicize-connection" data-connection-id="<?php echo esc_attr( $id ); ?>"> - <?php esc_html_e( 'Connected as:', 'jetpack' ); ?> - <?php - if ( !empty( $profile_link ) ) : ?> - <a class="publicize-profile-link" href="<?php echo esc_url( $profile_link ); ?>" target="_top"> - <?php echo esc_html( $connection_display ); ?> - </a><?php - else : - echo esc_html( $connection_display ); - endif; - ?> - - <?php if ( 0 == $cmeta['connection_data']['user_id'] ) : ?> - <small>(<?php esc_html_e( 'Shared', 'jetpack' ); ?>)</small> - - <?php if ( current_user_can( $this->publicize->GLOBAL_CAP ) ) : ?> - <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top">×</a> - <?php endif; ?> - - <?php else : ?> - <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>" target="_top">×</a> - <?php endif; ?> - - <br/> - <div class="pub-connection-test test-in-progress" id="pub-connection-test-<?php echo esc_attr( $id ); ?>" > - </div> - </li> - - <?php - endforeach; - ?> - </ul> - <?php endif; ?> - - - - <?php - $connections = $this->publicize->get_connections( $service_name ); - if ( empty ( $connections ) ) { ?> - <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( $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> - <?php endforeach; ?> - </div> - <script> - (function($){ - $('.pub-disconnect-button').on('click', function(e){ if ( confirm( '<?php echo esc_js( __( 'Are you sure you want to stop Publicizing posts to this connection?', 'jetpack' ) ); ?>' ) ) { - return true; - } else { - e.preventDefault(); - return false; - } - }) - })(jQuery); - </script> - </div> - - <?php wp_nonce_field( "wpas_posts_{$_blog_id}", "_wpas_posts_{$_blog_id}_nonce" ); ?> - <input type="hidden" id="wpas_ajax_blog_id" name="wpas_ajax_blog_id" value="<?php echo $_blog_id; ?>" /> - </form><?php - - } - - public static function global_checkbox( $service_name, $id ) { - global $publicize; - if ( current_user_can( $publicize->GLOBAL_CAP ) ) : ?> - <p> - <input id="globalize_<?php echo $service_name; ?>" type="checkbox" name="global" value="<?php echo wp_create_nonce( 'publicize-globalize-' . $id ) ?>" /> - <label for="globalize_<?php echo $service_name; ?>"><?php _e( 'Make this connection available to all users of this blog?', 'jetpack' ); ?></label> - </p> - <?php endif; - } - - function broken_connection( $service_name, $id ) { ?> - <div id="thickbox-content"> - <div class='error'> - <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 - } - - public static function options_page_other( $service_name ) { - // Nonce check - check_admin_referer( "options_page_{$service_name}_" . $_REQUEST['connection'] ); ?> - <div id="thickbox-content"> - <?php - ob_start(); - Publicize_UI::connected_notice( $service_name ); - $update_notice = ob_get_clean(); - if ( ! empty( $update_notice ) ) - echo $update_notice; + <h2 id="publicize"><?php esc_html_e( 'Publicize', 'jetpack' ) ?></h2> + <p><?php esc_html_e( 'Connect social media services to automatically share new posts.', 'jetpack' ) ?></p> + <h4><?php + printf( + wp_kses( + __( "We've made some updates to Publicize. Please visit the <a href='%s' class='jptracks' data-jptracks-name='legacy_publicize_settings'>WordPress.com sharing page</a> to manage your publicize connections or use the button below.", 'jetpack' ), + array( 'a' => array( 'href' => array(), 'class' => array(), 'data-jptracks-name' => array() ) ) + ), + esc_url( publicize_calypso_url() ) + ); ?> + </h4> - <?php Publicize_UI::global_checkbox( $service_name, $_REQUEST['connection'] ); ?> - - <p style="text-align: center;"> - <input type="submit" value="<?php esc_attr_e( 'OK', 'jetpack' ) ?>" class="button <?php echo $service_name; ?>-options save-options" name="save" data-connection="<?php echo esc_attr( $_REQUEST['connection'] ); ?>" rel="<?php echo wp_create_nonce( 'save_'.$service_name.'_token_' . $_REQUEST['connection'] ) ?>" /> - </p> <br /> - </div> + <a href="<?php echo esc_url( publicize_calypso_url() ); ?>" class="button button-primary jptracks" data-jptracks-name='legacy_publicize_settings'><?php esc_html_e( 'Publicize Settings', 'jetpack' ); ?></a> <?php } @@ -590,6 +365,23 @@ jQuery( function($) { list-style: square; padding-left: 1em; } +.publicize__notice-warning { + display: block; + padding: 7px 10px; + margin: 5px 0; + border-left-width: 4px; + border-left-style: solid; + font-size: 12px; + box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1); +} +.publicize-external-link { + display: block; + text-decoration: none; + margin-top: 8px; +} +.publicize-external-link__text { + text-decoration: underline; +} #publicize-title:before { content: "\f237"; font: normal 20px/1 dashicons; @@ -612,6 +404,10 @@ jQuery( function($) { .wpas-twitter-length-limit { color: red; } +.publicize__notice-warning .dashicons { + font-size: 16px; + text-decoration: none; +} </style><?php } @@ -630,6 +426,24 @@ jQuery( function($) { } /** + * Extracts the connections that require reauthentication, for example, LinkedIn, when it switched v1 to v2 of its API. + * + * @return array Connections that must be reauthenticated + */ + function get_must_reauth_connections() { + $must_reauth = array(); + $connections = $this->publicize->get_connections( 'linkedin' ); + if ( is_array( $connections ) ) { + foreach ( $connections as $index => $connection ) { + if ( $this->publicize->is_invalid_linkedin_connection( $connection ) ) { + $must_reauth[ $index ] = 'LinkedIn'; + } + } + } + return $must_reauth; + } + + /** * 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. @@ -659,6 +473,33 @@ jQuery( function($) { if ( 0 < count( $connections_data ) ) : $publicize_form = $this->get_metabox_form_connected( $connections_data ); + $must_reauth = $this->get_must_reauth_connections(); + if ( ! empty( $must_reauth ) ) { + foreach ( $must_reauth as $connection_name ) { + ?> + <span class="notice-warning publicize__notice-warning"> + <?php + /* translators: %s is the name of a Pubilicize service like "LinkedIn" */ + printf( esc_html__( + 'Your %s connection needs to be reauthenticated to continue working – head to Sharing to take care of it.', + 'jetpack' + ), $connection_name ); + ?> + <a + class="publicize-external-link" + href="<?php echo publicize_calypso_url() ?>" + target="_blank" + > + <span class="publicize-external-link__text"><?php esc_html_e( 'Go to Sharing settings', 'jetpack' ); ?></span> + <span class="dashicons dashicons-external"></span> + </a> + </span> + <?php + } + ?> + <?php + } + $labels = array(); foreach ( $connections_data as $connection_data ) { if ( ! $connection_data['enabled'] ) { |