Add upstream
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
if ( ! class_exists( 'Jetpack_Media_Summary' ) ) {
|
||||
if ( defined('IS_WPCOM') && IS_WPCOM ) {
|
||||
include WP_CONTENT_DIR . '/lib/class.wpcom-media-summary.php';
|
||||
} else {
|
||||
jetpack_require_lib( 'class.media-summary' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Better OG Image Tags for Image Post Formats
|
||||
*/
|
||||
function enhanced_og_image( $tags ) {
|
||||
if ( !is_singular() || post_password_required() )
|
||||
return $tags;
|
||||
|
||||
global $post;
|
||||
|
||||
// Always favor featured images.
|
||||
if ( enhanced_og_has_featured_image( $post->ID ) )
|
||||
return $tags;
|
||||
|
||||
$summary = Jetpack_Media_Summary::get( $post->ID );
|
||||
|
||||
if ( 'image' != $summary['type'] )
|
||||
return $tags;
|
||||
|
||||
$tags['og:image'] = $summary['image'];
|
||||
$tags['og:image:secure_url'] = $summary['secure']['image'];
|
||||
|
||||
return $tags;
|
||||
}
|
||||
add_filter( 'jetpack_open_graph_tags', 'enhanced_og_image' );
|
||||
|
||||
/**
|
||||
* Better OG Image Tags for Gallery Post Formats
|
||||
*/
|
||||
function enhanced_og_gallery( $tags ) {
|
||||
if ( !is_singular() || post_password_required() )
|
||||
return $tags;
|
||||
|
||||
global $post;
|
||||
|
||||
// Always favor featured images.
|
||||
if ( enhanced_og_has_featured_image( $post->ID ) )
|
||||
return $tags;
|
||||
|
||||
$summary = Jetpack_Media_Summary::get( $post->ID );
|
||||
|
||||
if ( 'gallery' != $summary['type'] )
|
||||
return $tags;
|
||||
|
||||
if( !isset( $summary['images'] ) || !is_array( $summary['images'] ) || empty( $summary['images'] ) )
|
||||
return $tags;
|
||||
|
||||
$images = $secures = array();
|
||||
foreach ( $summary['images'] as $i => $image ) {
|
||||
$images[] = $image['url'];
|
||||
$secures[] = $summary['secure']['images'][$i]['url'];
|
||||
}
|
||||
|
||||
$tags['og:image'] = $images;
|
||||
$tags['og:image:secure_url'] = $secures;
|
||||
|
||||
return $tags;
|
||||
}
|
||||
add_filter( 'jetpack_open_graph_tags', 'enhanced_og_gallery' );
|
||||
|
||||
/**
|
||||
* Allows VideoPress, YouTube, and Vimeo videos to play inline on Facebook
|
||||
*/
|
||||
function enhanced_og_video( $tags ) {
|
||||
if ( !is_singular() || post_password_required() )
|
||||
return $tags;
|
||||
|
||||
global $post;
|
||||
|
||||
// Always favor featured images.
|
||||
if ( enhanced_og_has_featured_image( $post->ID ) )
|
||||
return $tags;
|
||||
|
||||
$summary = Jetpack_Media_Summary::get( $post->ID );
|
||||
|
||||
if ( 'video' != $summary['type'] ) {
|
||||
if ( $summary['count']['video'] > 0 && $summary['count']['image'] < 1 ) {
|
||||
$tags['og:image'] = $summary['image'];
|
||||
$tags['og:image:secure_url'] = $summary['secure']['image'];
|
||||
}
|
||||
return $tags;
|
||||
}
|
||||
|
||||
$tags['og:image'] = $summary['image'];
|
||||
$tags['og:image:secure_url'] = $summary['secure']['image'];
|
||||
|
||||
// This should be html by default for youtube/vimeo, since we're linking to HTML pages.
|
||||
$tags['og:video:type'] = isset( $summary['video_type'] ) ? $summary['video_type'] : 'text/html';
|
||||
|
||||
$video_url = $summary['video'];
|
||||
$secure_video_url = $summary['secure']['video'];
|
||||
|
||||
if ( preg_match( '/((youtube|vimeo)\.com|youtu.be)/', $video_url ) ) {
|
||||
if ( strstr( $video_url, 'youtube' ) ) {
|
||||
$id = jetpack_get_youtube_id( $video_url );
|
||||
$video_url = 'http://www.youtube.com/embed/' . $id;
|
||||
$secure_video_url = 'https://www.youtube.com/embed/' . $id;
|
||||
} else if ( strstr( $video_url, 'vimeo' ) ) {
|
||||
preg_match( '|vimeo\.com/(\d+)/?$|i', $video_url, $match );
|
||||
$id = (int) $match[1];
|
||||
$video_url = 'http://vimeo.com/moogaloop.swf?clip_id=' . $id;
|
||||
$secure_video_url = 'https://vimeo.com/moogaloop.swf?clip_id=' . $id;
|
||||
}
|
||||
}
|
||||
|
||||
$tags['og:video'] = $video_url;
|
||||
$tags['og:video:secure_url'] = $secure_video_url;
|
||||
|
||||
if ( empty( $post->post_title ) )
|
||||
$tags['og:title'] = sprintf( __( 'Video on %s', 'jetpack' ), get_option( 'blogname' ) );
|
||||
|
||||
return $tags;
|
||||
}
|
||||
add_filter( 'jetpack_open_graph_tags', 'enhanced_og_video' );
|
||||
|
||||
function enhanced_og_has_featured_image( $post_id ) {
|
||||
$featured = Jetpack_PostImages::from_thumbnail( $post_id, 200, 200 );
|
||||
if ( !empty( $featured ) && count( $featured ) > 0 )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -0,0 +1,753 @@
|
||||
<?php
|
||||
|
||||
class Publicize extends Publicize_Base {
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
|
||||
add_filter( 'jetpack_xmlrpc_methods', array( $this, 'register_update_publicize_connections_xmlrpc_method' ) );
|
||||
|
||||
add_action( 'load-settings_page_sharing', array( $this, 'admin_page_load' ), 9 );
|
||||
|
||||
add_action( 'wp_ajax_publicize_tumblr_options_page', array( $this, 'options_page_tumblr' ) );
|
||||
add_action( 'wp_ajax_publicize_facebook_options_page', array( $this, 'options_page_facebook' ) );
|
||||
add_action( 'wp_ajax_publicize_twitter_options_page', array( $this, 'options_page_twitter' ) );
|
||||
add_action( 'wp_ajax_publicize_linkedin_options_page', array( $this, 'options_page_linkedin' ) );
|
||||
|
||||
add_action( 'wp_ajax_publicize_tumblr_options_save', array( $this, 'options_save_tumblr' ) );
|
||||
add_action( 'wp_ajax_publicize_facebook_options_save', array( $this, 'options_save_facebook' ) );
|
||||
add_action( 'wp_ajax_publicize_twitter_options_save', array( $this, 'options_save_twitter' ) );
|
||||
add_action( 'wp_ajax_publicize_linkedin_options_save', array( $this, 'options_save_linkedin' ) );
|
||||
|
||||
add_action( 'load-settings_page_sharing', array( $this, 'force_user_connection' ) );
|
||||
|
||||
add_filter( 'jetpack_published_post_flags', array( $this, 'set_post_flags' ), 10, 2 );
|
||||
|
||||
add_action( 'wp_insert_post', array( $this, 'save_publicized' ), 11, 3 );
|
||||
|
||||
add_filter( 'jetpack_twitter_cards_site_tag', array( $this, 'enhaced_twitter_cards_site_tag' ) );
|
||||
|
||||
add_action( 'publicize_save_meta', array( $this, 'save_publicized_twitter_account' ), 10, 4 );
|
||||
add_action( 'publicize_save_meta', array( $this, 'save_publicized_facebook_account' ), 10, 4 );
|
||||
|
||||
add_action( 'connection_disconnected', array( $this, 'add_disconnect_notice' ) );
|
||||
|
||||
add_filter( 'jetpack_sharing_twitter_via', array( $this, 'get_publicized_twitter_account' ), 10, 2 );
|
||||
|
||||
include_once( JETPACK__PLUGIN_DIR . 'modules/publicize/enhanced-open-graph.php' );
|
||||
|
||||
jetpack_require_lib( 'class.jetpack-keyring-service-helper' );
|
||||
}
|
||||
|
||||
function add_disconnect_notice() {
|
||||
add_action( 'admin_notices', array( $this, 'display_disconnected' ) );
|
||||
}
|
||||
|
||||
function force_user_connection() {
|
||||
global $current_user;
|
||||
$user_token = Jetpack_Data::get_access_token( $current_user->ID );
|
||||
$is_user_connected = $user_token && ! is_wp_error( $user_token );
|
||||
|
||||
// If the user is already connected via Jetpack, then we're good
|
||||
if ( $is_user_connected ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If they're not connected, then remove the Publicize UI and tell them they need to connect first
|
||||
global $publicize_ui;
|
||||
remove_action( 'pre_admin_screen_sharing', array( $publicize_ui, 'admin_page' ) );
|
||||
|
||||
// Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
|
||||
// Jetpack::init()->admin_styles();
|
||||
add_action( 'pre_admin_screen_sharing', array( $this, 'admin_page_warning' ), 1 );
|
||||
}
|
||||
|
||||
function admin_page_warning() {
|
||||
$jetpack = Jetpack::init();
|
||||
$blog_name = get_bloginfo( 'blogname' );
|
||||
if ( empty( $blog_name ) ) {
|
||||
$blog_name = home_url( '/' );
|
||||
}
|
||||
|
||||
?>
|
||||
<div id="message" class="updated jetpack-message jp-connect">
|
||||
<div class="jetpack-wrap-container">
|
||||
<div class="jetpack-text-container">
|
||||
<p><?php printf(
|
||||
/* translators: %s is the name of the blog */
|
||||
esc_html( wptexturize( __( "To use Publicize, you'll need to link your %s account to your WordPress.com account using the link below.", 'jetpack' ) ) ),
|
||||
'<strong>' . esc_html( $blog_name ) . '</strong>'
|
||||
); ?></p>
|
||||
<p><?php echo esc_html( wptexturize( __( "If you don't have a WordPress.com account yet, you can sign up for free in just a few seconds.", 'jetpack' ) ) ); ?></p>
|
||||
</div>
|
||||
<div class="jetpack-install-container">
|
||||
<p class="submit"><a
|
||||
href="<?php echo $jetpack->build_connect_url( false, menu_page_url( 'sharing', false ) ); ?>"
|
||||
class="button-connector"
|
||||
id="wpcom-connect"><?php esc_html_e( 'Link account with WordPress.com', 'jetpack' ); ?></a>
|
||||
</p>
|
||||
<p class="jetpack-install-blurb">
|
||||
<?php jetpack_render_tos_blurb(); ?>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Publicize connection
|
||||
*/
|
||||
function disconnect( $service_name, $connection_id, $_blog_id = false, $_user_id = false, $force_delete = false ) {
|
||||
return Jetpack_Keyring_Service_Helper::disconnect( $service_name, $connection_id, $_blog_id, $_user_id, $force_delete );
|
||||
}
|
||||
|
||||
function receive_updated_publicize_connections( $publicize_connections ) {
|
||||
Jetpack_Options::update_option( 'publicize_connections', $publicize_connections );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function register_update_publicize_connections_xmlrpc_method( $methods ) {
|
||||
return array_merge( $methods, array(
|
||||
'jetpack.updatePublicizeConnections' => array( $this, 'receive_updated_publicize_connections' ),
|
||||
) );
|
||||
}
|
||||
|
||||
function get_all_connections() {
|
||||
$connections = Jetpack_Options::get_option( 'publicize_connections' );
|
||||
if ( isset( $connections['google_plus'] ) ) {
|
||||
unset( $connections['google_plus'] );
|
||||
}
|
||||
return $connections;
|
||||
}
|
||||
|
||||
function get_connections( $service_name, $_blog_id = false, $_user_id = false ) {
|
||||
if ( false === $_user_id ) {
|
||||
$_user_id = $this->user_id();
|
||||
}
|
||||
|
||||
$connections = $this->get_all_connections();
|
||||
$connections_to_return = array();
|
||||
|
||||
if ( ! empty( $connections ) && is_array( $connections ) ) {
|
||||
if ( ! empty( $connections[ $service_name ] ) ) {
|
||||
foreach ( $connections[ $service_name ] as $id => $connection ) {
|
||||
if ( 0 == $connection['connection_data']['user_id'] || $_user_id == $connection['connection_data']['user_id'] ) {
|
||||
$connections_to_return[ $id ] = $connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $connections_to_return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_all_connections_for_user() {
|
||||
$connections = $this->get_all_connections();
|
||||
|
||||
$connections_to_return = array();
|
||||
if ( ! empty( $connections ) ) {
|
||||
foreach ( (array) $connections as $service_name => $connections_for_service ) {
|
||||
foreach ( $connections_for_service as $id => $connection ) {
|
||||
$user_id = intval( $connection['connection_data']['user_id'] );
|
||||
// phpcs:ignore WordPress.PHP.YodaConditions.NotYoda
|
||||
if ( $user_id === 0 || $this->user_id() === $user_id ) {
|
||||
$connections_to_return[ $service_name ][ $id ] = $connection;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $connections_to_return;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_connection_id( $connection ) {
|
||||
return $connection['connection_data']['id'];
|
||||
}
|
||||
|
||||
function get_connection_unique_id( $connection ) {
|
||||
return $connection['connection_data']['token_id'];
|
||||
}
|
||||
|
||||
function get_connection_meta( $connection ) {
|
||||
$connection['user_id'] = $connection['connection_data']['user_id']; // Allows for shared connections
|
||||
return $connection;
|
||||
}
|
||||
|
||||
function admin_page_load() {
|
||||
if ( isset( $_GET['action'] ) && 'error' === $_GET['action'] ) {
|
||||
add_action( 'pre_admin_screen_sharing', array( $this, 'display_connection_error' ), 9 );
|
||||
}
|
||||
}
|
||||
|
||||
function display_connection_error() {
|
||||
$code = false;
|
||||
if ( isset( $_GET['service'] ) ) {
|
||||
$service_name = $_GET['service'];
|
||||
$error = sprintf( __( 'There was a problem connecting to %s to create an authorized connection. Please try again in a moment.', 'jetpack' ), Publicize::get_service_label( $service_name ) );
|
||||
} else {
|
||||
if ( isset( $_GET['publicize_error'] ) ) {
|
||||
$code = strtolower( $_GET['publicize_error'] );
|
||||
switch ( $code ) {
|
||||
case '400':
|
||||
$error = __( 'An invalid request was made. This normally means that something intercepted or corrupted the request from your server to the Jetpack Server. Try again and see if it works this time.', 'jetpack' );
|
||||
break;
|
||||
case 'secret_mismatch':
|
||||
$error = __( 'We could not verify that your server is making an authorized request. Please try again, and make sure there is nothing interfering with requests from your server to the Jetpack Server.', 'jetpack' );
|
||||
break;
|
||||
case 'empty_blog_id':
|
||||
$error = __( 'No blog_id was included in your request. Please try disconnecting Jetpack from WordPress.com and then reconnecting it. Once you have done that, try connecting Publicize again.', 'jetpack' );
|
||||
break;
|
||||
case 'empty_state':
|
||||
$error = sprintf( __( 'No user information was included in your request. Please make sure that your user account has connected to Jetpack. Connect your user account by going to the <a href="%s">Jetpack page</a> within wp-admin.', 'jetpack' ), Jetpack::admin_url() );
|
||||
break;
|
||||
default:
|
||||
$error = __( 'Something which should never happen, happened. Sorry about that. If you try again, maybe it will work.', 'jetpack' );
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$error = __( 'There was a problem connecting with Publicize. Please try again in a moment.', 'jetpack' );
|
||||
}
|
||||
}
|
||||
// Using the same formatting/style as Jetpack::admin_notices() error
|
||||
?>
|
||||
<div id="message" class="jetpack-message jetpack-err">
|
||||
<div class="squeezer">
|
||||
<h2><?php echo wp_kses( $error, array( 'a' => array( 'href' => true ),
|
||||
'code' => true,
|
||||
'strong' => true,
|
||||
'br' => true,
|
||||
'b' => true
|
||||
) ); ?></h2>
|
||||
<?php if ( $code ) : ?>
|
||||
<p><?php printf( __( 'Error code: %s', 'jetpack' ), esc_html( stripslashes( $code ) ) ); ?></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function display_disconnected() {
|
||||
echo "<div class='updated'>\n";
|
||||
echo '<p>' . esc_html( __( 'That connection has been removed.', 'jetpack' ) ) . "</p>\n";
|
||||
echo "</div>\n\n";
|
||||
}
|
||||
|
||||
function globalization() {
|
||||
if ( 'on' == $_REQUEST['global'] ) {
|
||||
$globalize_connection = $_REQUEST['connection'];
|
||||
if ( ! current_user_can( $this->GLOBAL_CAP ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->globalize_connection( $globalize_connection );
|
||||
}
|
||||
}
|
||||
|
||||
function globalize_connection( $connection_id ) {
|
||||
Jetpack::load_xml_rpc_client();
|
||||
$xml = new Jetpack_IXR_Client();
|
||||
$xml->query( 'jetpack.globalizePublicizeConnection', $connection_id, 'globalize' );
|
||||
|
||||
if ( ! $xml->isError() ) {
|
||||
$response = $xml->getResponse();
|
||||
$this->receive_updated_publicize_connections( $response );
|
||||
}
|
||||
}
|
||||
|
||||
function unglobalize_connection( $connection_id ) {
|
||||
Jetpack::load_xml_rpc_client();
|
||||
$xml = new Jetpack_IXR_Client();
|
||||
$xml->query( 'jetpack.globalizePublicizeConnection', $connection_id, 'unglobalize' );
|
||||
|
||||
if ( ! $xml->isError() ) {
|
||||
$response = $xml->getResponse();
|
||||
$this->receive_updated_publicize_connections( $response );
|
||||
}
|
||||
}
|
||||
|
||||
function connect_url( $service_name, $for = 'publicize' ) {
|
||||
return Jetpack_Keyring_Service_Helper::connect_url( $service_name, $for );
|
||||
}
|
||||
|
||||
function refresh_url( $service_name, $for = 'publicize' ) {
|
||||
return Jetpack_Keyring_Service_Helper::refresh_url( $service_name, $for );
|
||||
}
|
||||
|
||||
function disconnect_url( $service_name, $id ) {
|
||||
return Jetpack_Keyring_Service_Helper::disconnect_url( $service_name, $id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get social networks, either all available or only those that the site is connected to.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @since 6.6.0 Removed Path. Service closed October 2018.
|
||||
*
|
||||
* @param string $filter Select the list of services that will be returned. Defaults to 'all', accepts 'connected'.
|
||||
*
|
||||
* @return array List of social networks.
|
||||
*/
|
||||
function get_services( $filter = 'all', $_blog_id = false, $_user_id = false ) {
|
||||
$services = array(
|
||||
'facebook' => array(),
|
||||
'twitter' => array(),
|
||||
'linkedin' => array(),
|
||||
'tumblr' => array(),
|
||||
);
|
||||
|
||||
if ( 'all' == $filter ) {
|
||||
return $services;
|
||||
} else {
|
||||
$connected_services = array();
|
||||
foreach ( $services as $service_name => $empty ) {
|
||||
$connections = $this->get_connections( $service_name, $_blog_id, $_user_id );
|
||||
if ( $connections ) {
|
||||
$connected_services[ $service_name ] = $connections;
|
||||
}
|
||||
}
|
||||
return $connected_services;
|
||||
}
|
||||
}
|
||||
|
||||
function get_connection( $service_name, $id, $_blog_id = false, $_user_id = false ) {
|
||||
// Stub
|
||||
}
|
||||
|
||||
function flag_post_for_publicize( $new_status, $old_status, $post ) {
|
||||
if ( ! $this->post_type_is_publicizeable( $post->post_type ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( 'publish' == $new_status && 'publish' != $old_status ) {
|
||||
/**
|
||||
* Determines whether a post being published gets publicized.
|
||||
*
|
||||
* Side-note: Possibly our most alliterative filter name.
|
||||
*
|
||||
* @module publicize
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @param bool $should_publicize Should the post be publicized? Default to true.
|
||||
* @param WP_POST $post Current Post object.
|
||||
*/
|
||||
$should_publicize = apply_filters( 'publicize_should_publicize_published_post', true, $post );
|
||||
|
||||
if ( $should_publicize ) {
|
||||
update_post_meta( $post->ID, $this->PENDING, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function test_connection( $service_name, $connection ) {
|
||||
|
||||
$id = $this->get_connection_id( $connection );
|
||||
|
||||
Jetpack::load_xml_rpc_client();
|
||||
$xml = new Jetpack_IXR_Client();
|
||||
$xml->query( 'jetpack.testPublicizeConnection', $id );
|
||||
|
||||
// Bail if all is well
|
||||
if ( ! $xml->isError() ) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$xml_response = $xml->getResponse();
|
||||
$connection_test_message = $xml_response['faultString'];
|
||||
|
||||
// Set up refresh if the user can
|
||||
$user_can_refresh = current_user_can( $this->GLOBAL_CAP );
|
||||
if ( $user_can_refresh ) {
|
||||
$nonce = wp_create_nonce( "keyring-request-" . $service_name );
|
||||
$refresh_text = sprintf( _x( 'Refresh connection with %s', 'Refresh connection with {social media service}', 'jetpack' ), $this->get_service_label( $service_name ) );
|
||||
$refresh_url = $this->refresh_url( $service_name );
|
||||
}
|
||||
|
||||
$error_data = array(
|
||||
'user_can_refresh' => $user_can_refresh,
|
||||
'refresh_text' => $refresh_text,
|
||||
'refresh_url' => $refresh_url
|
||||
);
|
||||
|
||||
return new WP_Error( 'pub_conn_test_failed', $connection_test_message, $error_data );
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if post has already been shared by Publicize in the past.
|
||||
*
|
||||
* Jetpack uses two methods:
|
||||
* 1. A POST_DONE . 'all' postmeta flag, or
|
||||
* 2. if the post has already been published.
|
||||
*
|
||||
* @since 6.7.0
|
||||
*
|
||||
* @param integer $post_id Optional. Post ID to query connection status for: will use current post if missing.
|
||||
*
|
||||
* @return bool True if post has already been shared by Publicize, false otherwise.
|
||||
*/
|
||||
public function post_is_done_sharing( $post_id = null ) {
|
||||
// Defaults to current post if $post_id is null.
|
||||
$post = get_post( $post_id );
|
||||
if ( is_null( $post ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return 'publish' == $post->post_status || get_post_meta( $post->ID, $this->POST_DONE . 'all', true );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save a flag locally to indicate that this post has already been Publicized via the selected
|
||||
* connections.
|
||||
*/
|
||||
function save_publicized( $post_ID, $post = null, $update = null ) {
|
||||
if ( is_null( $post ) ) {
|
||||
return;
|
||||
}
|
||||
// Only do this when a post transitions to being published
|
||||
if ( get_post_meta( $post->ID, $this->PENDING ) && $this->post_type_is_publicizeable( $post->post_type ) ) {
|
||||
$connected_services = $this->get_all_connections();
|
||||
if ( ! empty( $connected_services ) ) {
|
||||
/**
|
||||
* Fires when a post is saved that has is marked as pending publicizing
|
||||
*
|
||||
* @since 4.1.0
|
||||
*
|
||||
* @param int The post ID
|
||||
*/
|
||||
do_action_deprecated( 'jetpack_publicize_post', $post->ID, '4.8.0', 'jetpack_published_post_flags' );
|
||||
}
|
||||
delete_post_meta( $post->ID, $this->PENDING );
|
||||
update_post_meta( $post->ID, $this->POST_DONE . 'all', true );
|
||||
}
|
||||
}
|
||||
|
||||
function set_post_flags( $flags, $post ) {
|
||||
$flags['publicize_post'] = false;
|
||||
if ( ! $this->post_type_is_publicizeable( $post->post_type ) ) {
|
||||
return $flags;
|
||||
}
|
||||
/** This filter is already documented in modules/publicize/publicize-jetpack.php */
|
||||
if ( ! apply_filters( 'publicize_should_publicize_published_post', true, $post ) ) {
|
||||
return $flags;
|
||||
}
|
||||
|
||||
$connected_services = $this->get_all_connections();
|
||||
|
||||
if ( empty( $connected_services ) ) {
|
||||
return $flags;
|
||||
}
|
||||
|
||||
$flags['publicize_post'] = true;
|
||||
|
||||
return $flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Options Code
|
||||
*/
|
||||
|
||||
function options_page_facebook() {
|
||||
$connected_services = $this->get_all_connections();
|
||||
$connection = $connected_services['facebook'][ $_REQUEST['connection'] ];
|
||||
$options_to_show = ( ! empty( $connection['connection_data']['meta']['options_responses'] ) ? $connection['connection_data']['meta']['options_responses'] : false );
|
||||
|
||||
// Nonce check
|
||||
check_admin_referer( 'options_page_facebook_' . $_REQUEST['connection'] );
|
||||
|
||||
$pages = ( ! empty( $options_to_show[1]['data'] ) ? $options_to_show[1]['data'] : false );
|
||||
|
||||
$page_selected = false;
|
||||
if ( ! empty( $connection['connection_data']['meta']['facebook_page'] ) ) {
|
||||
$found = false;
|
||||
if ( $pages && isset( $pages->data ) && is_array( $pages->data ) ) {
|
||||
foreach ( $pages->data as $page ) {
|
||||
if ( $page->id == $connection['connection_data']['meta']['facebook_page'] ) {
|
||||
$found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( $found ) {
|
||||
$page_selected = $connection['connection_data']['meta']['facebook_page'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div id="thickbox-content">
|
||||
|
||||
<?php
|
||||
ob_start();
|
||||
Publicize_UI::connected_notice( 'Facebook' );
|
||||
$update_notice = ob_get_clean();
|
||||
|
||||
if ( ! empty( $update_notice ) ) {
|
||||
echo $update_notice;
|
||||
}
|
||||
$page_info_message = sprintf(
|
||||
__( 'Facebook supports Publicize connections to Facebook Pages, but not to Facebook Profiles. <a href="%s">Learn More about Publicize for Facebook</a>', 'jetpack' ),
|
||||
'https://jetpack.com/support/publicize/facebook'
|
||||
);
|
||||
|
||||
if ( $pages ) : ?>
|
||||
<p><?php _e( 'Publicize to my <strong>Facebook Page</strong>:', 'jetpack' ); ?></p>
|
||||
<table id="option-fb-fanpage">
|
||||
<tbody>
|
||||
|
||||
<?php foreach ( $pages as $i => $page ) : ?>
|
||||
<?php if ( ! ( $i % 2 ) ) : ?>
|
||||
<tr>
|
||||
<?php endif; ?>
|
||||
<td class="radio"><input type="radio" name="option" data-type="page"
|
||||
id="<?php echo esc_attr( $page['id'] ) ?>"
|
||||
value="<?php echo esc_attr( $page['id'] ) ?>" <?php checked( $page_selected && $page_selected == $page['id'], true ); ?> />
|
||||
</td>
|
||||
<td class="thumbnail"><label for="<?php echo esc_attr( $page['id'] ) ?>"><img
|
||||
src="<?php echo esc_url( str_replace( '_s', '_q', $page['picture']['data']['url'] ) ) ?>"
|
||||
width="50" height="50"/></label></td>
|
||||
<td class="details">
|
||||
<label for="<?php echo esc_attr( $page['id'] ) ?>">
|
||||
<span class="name"><?php echo esc_html( $page['name'] ) ?></span><br/>
|
||||
<span class="category"><?php echo esc_html( $page['category'] ) ?></span>
|
||||
</label>
|
||||
</td>
|
||||
<?php if ( ( $i % 2 ) || ( $i == count( $pages ) - 1 ) ): ?>
|
||||
</tr>
|
||||
<?php endif; ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<?php Publicize_UI::global_checkbox( 'facebook', $_REQUEST['connection'] ); ?>
|
||||
<p style="text-align: center;">
|
||||
<input type="submit" value="<?php esc_attr_e( 'OK', 'jetpack' ) ?>"
|
||||
class="button fb-options save-options" name="save"
|
||||
data-connection="<?php echo esc_attr( $_REQUEST['connection'] ); ?>"
|
||||
rel="<?php echo wp_create_nonce( 'save_fb_token_' . $_REQUEST['connection'] ) ?>"/>
|
||||
</p><br/>
|
||||
<p><?php echo $page_info_message; ?></p>
|
||||
<?php else: ?>
|
||||
<div>
|
||||
<p><?php echo $page_info_message; ?></p>
|
||||
<p><?php printf( __( '<a class="button" href="%s" target="%s">Create a Facebook page</a> to get started.', 'jetpack' ), 'https://www.facebook.com/pages/creation/', '_blank noopener noreferrer' ); ?></p>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
function options_save_facebook() {
|
||||
// Nonce check
|
||||
check_admin_referer( 'save_fb_token_' . $_REQUEST['connection'] );
|
||||
|
||||
// Check for a numeric page ID
|
||||
$page_id = $_POST['selected_id'];
|
||||
if ( ! ctype_digit( $page_id ) ) {
|
||||
die( 'Security check' );
|
||||
}
|
||||
|
||||
if ( 'page' != $_POST['type'] || ! isset( $_POST['selected_id'] ) ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Publish to Page
|
||||
$options = array(
|
||||
'facebook_page' => $page_id,
|
||||
'facebook_profile' => null
|
||||
);
|
||||
|
||||
$this->set_remote_publicize_options( $_POST['connection'], $options );
|
||||
}
|
||||
|
||||
function options_page_tumblr() {
|
||||
// Nonce check
|
||||
check_admin_referer( 'options_page_tumblr_' . $_REQUEST['connection'] );
|
||||
|
||||
$connected_services = $this->get_all_connections();
|
||||
$connection = $connected_services['tumblr'][ $_POST['connection'] ];
|
||||
$options_to_show = $connection['connection_data']['meta']['options_responses'];
|
||||
$request = $options_to_show[0];
|
||||
|
||||
$blogs = $request['response']['user']['blogs'];
|
||||
|
||||
$blog_selected = false;
|
||||
|
||||
if ( ! empty( $connection['connection_data']['meta']['tumblr_base_hostname'] ) ) {
|
||||
foreach ( $blogs as $blog ) {
|
||||
if ( $connection['connection_data']['meta']['tumblr_base_hostname'] == $this->get_basehostname( $blog['url'] ) ) {
|
||||
$blog_selected = $connection['connection_data']['meta']['tumblr_base_hostname'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Use their Primary blog if they haven't selected one yet
|
||||
if ( ! $blog_selected ) {
|
||||
foreach ( $blogs as $blog ) {
|
||||
if ( $blog['primary'] ) {
|
||||
$blog_selected = $this->get_basehostname( $blog['url'] );
|
||||
}
|
||||
}
|
||||
} ?>
|
||||
|
||||
<div id="thickbox-content">
|
||||
|
||||
<?php
|
||||
ob_start();
|
||||
Publicize_UI::connected_notice( 'Tumblr' );
|
||||
$update_notice = ob_get_clean();
|
||||
|
||||
if ( ! empty( $update_notice ) ) {
|
||||
echo $update_notice;
|
||||
}
|
||||
?>
|
||||
|
||||
<p><?php _e( 'Publicize to my <strong>Tumblr blog</strong>:', 'jetpack' ); ?></p>
|
||||
|
||||
<ul id="option-tumblr-blog">
|
||||
|
||||
<?php
|
||||
foreach ( $blogs as $blog ) {
|
||||
$url = $this->get_basehostname( $blog['url'] ); ?>
|
||||
<li>
|
||||
<input type="radio" name="option" data-type="blog" id="<?php echo esc_attr( $url ) ?>"
|
||||
value="<?php echo esc_attr( $url ) ?>" <?php checked( $blog_selected == $url, true ); ?> />
|
||||
<label for="<?php echo esc_attr( $url ) ?>"><span
|
||||
class="name"><?php echo esc_html( $blog['title'] ) ?></span></label>
|
||||
</li>
|
||||
<?php } ?>
|
||||
|
||||
</ul>
|
||||
|
||||
<?php Publicize_UI::global_checkbox( 'tumblr', $_REQUEST['connection'] ); ?>
|
||||
|
||||
<p style="text-align: center;">
|
||||
<input type="submit" value="<?php esc_attr_e( 'OK', 'jetpack' ) ?>"
|
||||
class="button tumblr-options save-options" name="save"
|
||||
data-connection="<?php echo esc_attr( $_REQUEST['connection'] ); ?>"
|
||||
rel="<?php echo wp_create_nonce( 'save_tumblr_blog_' . $_REQUEST['connection'] ) ?>"/>
|
||||
</p> <br/>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
}
|
||||
|
||||
function get_basehostname( $url ) {
|
||||
return parse_url( $url, PHP_URL_HOST );
|
||||
}
|
||||
|
||||
function options_save_tumblr() {
|
||||
// Nonce check
|
||||
check_admin_referer( 'save_tumblr_blog_' . $_REQUEST['connection'] );
|
||||
$options = array( 'tumblr_base_hostname' => $_POST['selected_id'] );
|
||||
|
||||
$this->set_remote_publicize_options( $_POST['connection'], $options );
|
||||
|
||||
}
|
||||
|
||||
function set_remote_publicize_options( $id, $options ) {
|
||||
Jetpack::load_xml_rpc_client();
|
||||
$xml = new Jetpack_IXR_Client();
|
||||
$xml->query( 'jetpack.setPublicizeOptions', $id, $options );
|
||||
|
||||
if ( ! $xml->isError() ) {
|
||||
$response = $xml->getResponse();
|
||||
Jetpack_Options::update_option( 'publicize_connections', $response );
|
||||
$this->globalization();
|
||||
}
|
||||
}
|
||||
|
||||
function options_page_twitter() {
|
||||
Publicize_UI::options_page_other( 'twitter' );
|
||||
}
|
||||
|
||||
function options_page_linkedin() {
|
||||
Publicize_UI::options_page_other( 'linkedin' );
|
||||
}
|
||||
|
||||
function options_save_twitter() {
|
||||
$this->options_save_other( 'twitter' );
|
||||
}
|
||||
|
||||
function options_save_linkedin() {
|
||||
$this->options_save_other( 'linkedin' );
|
||||
}
|
||||
|
||||
function options_save_other( $service_name ) {
|
||||
// Nonce check
|
||||
check_admin_referer( 'save_' . $service_name . '_token_' . $_REQUEST['connection'] );
|
||||
$this->globalization();
|
||||
}
|
||||
|
||||
/**
|
||||
* If there's only one shared connection to Twitter set it as twitter:site tag.
|
||||
*/
|
||||
function enhaced_twitter_cards_site_tag( $tag ) {
|
||||
$custom_site_tag = get_option( 'jetpack-twitter-cards-site-tag' );
|
||||
if ( ! empty( $custom_site_tag ) ) {
|
||||
return $tag;
|
||||
}
|
||||
if ( ! $this->is_enabled( 'twitter' ) ) {
|
||||
return $tag;
|
||||
}
|
||||
$connections = $this->get_connections( 'twitter' );
|
||||
foreach ( $connections as $connection ) {
|
||||
$connection_meta = $this->get_connection_meta( $connection );
|
||||
if ( 0 == $connection_meta['connection_data']['user_id'] ) {
|
||||
// If the connection is shared
|
||||
return $this->get_display_name( 'twitter', $connection );
|
||||
}
|
||||
}
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
function save_publicized_twitter_account( $submit_post, $post_id, $service_name, $connection ) {
|
||||
if ( 'twitter' == $service_name && $submit_post ) {
|
||||
$connection_meta = $this->get_connection_meta( $connection );
|
||||
$publicize_twitter_user = get_post_meta( $post_id, '_publicize_twitter_user' );
|
||||
if ( empty( $publicize_twitter_user ) || 0 != $connection_meta['connection_data']['user_id'] ) {
|
||||
update_post_meta( $post_id, '_publicize_twitter_user', $this->get_display_name( 'twitter', $connection ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function get_publicized_twitter_account( $account, $post_id ) {
|
||||
if ( ! empty( $account ) ) {
|
||||
return $account;
|
||||
}
|
||||
$account = get_post_meta( $post_id, '_publicize_twitter_user', true );
|
||||
if ( ! empty( $account ) ) {
|
||||
return $account;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the Publicized Facebook account when publishing a post
|
||||
* Use only Personal accounts, not Facebook Pages
|
||||
*/
|
||||
function save_publicized_facebook_account( $submit_post, $post_id, $service_name, $connection ) {
|
||||
$connection_meta = $this->get_connection_meta( $connection );
|
||||
if ( 'facebook' == $service_name && isset( $connection_meta['connection_data']['meta']['facebook_profile'] ) && $submit_post ) {
|
||||
$publicize_facebook_user = get_post_meta( $post_id, '_publicize_facebook_user' );
|
||||
if ( empty( $publicize_facebook_user ) || 0 != $connection_meta['connection_data']['user_id'] ) {
|
||||
$profile_link = $this->get_profile_link( 'facebook', $connection );
|
||||
|
||||
if ( false !== $profile_link ) {
|
||||
update_post_meta( $post_id, '_publicize_facebook_user', $profile_link );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1249
wp-content/plugins/jetpack/modules/publicize/publicize.php
Normal file
1249
wp-content/plugins/jetpack/modules/publicize/publicize.php
Normal file
File diff suppressed because it is too large
Load Diff
657
wp-content/plugins/jetpack/modules/publicize/ui.php
Normal file
657
wp-content/plugins/jetpack/modules/publicize/ui.php
Normal file
@@ -0,0 +1,657 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Only user facing pieces of Publicize are found here.
|
||||
*/
|
||||
class Publicize_UI {
|
||||
|
||||
/**
|
||||
* Contains an instance of class 'publicize' which loads Keyring, sets up services, etc.
|
||||
*/
|
||||
public $publicize;
|
||||
|
||||
/**
|
||||
* @var string URL to Sharing settings page in wordpress.com
|
||||
*/
|
||||
protected $publicize_settings_url = '';
|
||||
|
||||
/**
|
||||
* Hooks into WordPress to display the various pieces of UI and load our assets
|
||||
*/
|
||||
function __construct() {
|
||||
global $publicize;
|
||||
|
||||
$this->publicize = $publicize = new Publicize;
|
||||
|
||||
add_action( 'init', array( $this, 'init' ) );
|
||||
}
|
||||
|
||||
function init() {
|
||||
$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() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// assets (css, js)
|
||||
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' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* 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',
|
||||
esc_html__( 'Sharing Settings', 'jetpack' ),
|
||||
esc_html__( 'Sharing', 'jetpack' ),
|
||||
'publish_posts',
|
||||
'sharing',
|
||||
array( $this, 'wrapper_admin_page' )
|
||||
);
|
||||
}
|
||||
|
||||
function wrapper_admin_page() {
|
||||
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.
|
||||
*/
|
||||
function management_page() { ?>
|
||||
<div class="wrap">
|
||||
<div class="icon32" id="icon-options-general"><br /></div>
|
||||
<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' );
|
||||
?>
|
||||
|
||||
</div> <?php
|
||||
}
|
||||
|
||||
/**
|
||||
* styling for the sharing screen and popups
|
||||
* JS for the options and switching
|
||||
*/
|
||||
function load_assets() {
|
||||
Jetpack_Admin_Page::load_wrapper_styles();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
?>
|
||||
<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>
|
||||
|
||||
<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
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$default_prefix = $this->publicize->default_prefix;
|
||||
$default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) );
|
||||
|
||||
$default_message = $this->publicize->default_message;
|
||||
$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 ) );
|
||||
|
||||
$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,
|
||||
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' );
|
||||
}
|
||||
} );
|
||||
|
||||
// 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' );
|
||||
$(this).hide();
|
||||
} );
|
||||
|
||||
$('#publicize-disconnected-form-hide').click( function() {
|
||||
$('#publicize-form').slideUp( 'fast' );
|
||||
$('#publicize-disconnected-form-show').show();
|
||||
} );
|
||||
|
||||
$('#publicize-form-edit').click( function() {
|
||||
$('#publicize-form').slideDown( 'fast', function() {
|
||||
var selBeg = 0, selEnd = 0;
|
||||
wpasTitle.focus();
|
||||
|
||||
if ( ! wpasTitle.text() ) {
|
||||
wpasTitle.text( wpasTitle.attr( 'placeholder' ) );
|
||||
|
||||
selBeg = wpasTitle.text().indexOf( postTitle.val() );
|
||||
if ( selBeg < 0 ) {
|
||||
selBeg = 0;
|
||||
} else {
|
||||
selEnd = selBeg + postTitle.val().length;
|
||||
}
|
||||
|
||||
var domObj = wpasTitle.get(0);
|
||||
if ( domObj.setSelectionRange ) {
|
||||
domObj.setSelectionRange( selBeg, selEnd );
|
||||
} else if ( domObj.createTextRange ) {
|
||||
var r = domObj.createTextRange();
|
||||
r.moveStart( 'character', selBeg );
|
||||
r.moveEnd( 'character', selEnd );
|
||||
r.select();
|
||||
}
|
||||
}
|
||||
} );
|
||||
|
||||
$('#publicize-defaults').hide();
|
||||
$(this).hide();
|
||||
return false;
|
||||
} );
|
||||
|
||||
$('#publicize-form-hide').click( function() {
|
||||
var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) {
|
||||
return $.trim( $(el).parent( 'label' ).text() );
|
||||
} );
|
||||
$('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show();
|
||||
$('#publicize-form-edit').show();
|
||||
return false;
|
||||
} );
|
||||
|
||||
$('.authorize-link').click( function() {
|
||||
if ( authClick ) {
|
||||
return false;
|
||||
}
|
||||
authClick = true;
|
||||
$(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' );
|
||||
$.ajaxSetup( { async: false } );
|
||||
|
||||
if ( window.wp && window.wp.autosave ) {
|
||||
window.wp.autosave.server.triggerSave();
|
||||
} else {
|
||||
autosave();
|
||||
}
|
||||
|
||||
return true;
|
||||
} );
|
||||
|
||||
$( '.pub-service' ).click( function() {
|
||||
var service = $(this).data( 'service' ),
|
||||
fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />';
|
||||
$( '#add-publicize-check' ).append( fakebox );
|
||||
} );
|
||||
|
||||
publicizeConnTestStart = function() {
|
||||
$( '#pub-connection-tests' )
|
||||
.removeClass( 'below-h2' )
|
||||
.removeClass( 'error' )
|
||||
.removeClass( 'publicize-token-refresh-message' )
|
||||
.addClass( 'test-in-progress' )
|
||||
.html( '' );
|
||||
$.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete );
|
||||
}
|
||||
|
||||
publicizeConnRefreshClick = function( event ) {
|
||||
event.preventDefault();
|
||||
var popupURL = event.currentTarget.href;
|
||||
var popupTitle = event.currentTarget.title;
|
||||
// open a popup window
|
||||
// when it is closed, kick off the tests again
|
||||
var popupWin = window.open( popupURL, popupTitle, '' );
|
||||
var popupWinTimer= window.setInterval( function() {
|
||||
if ( popupWin.closed !== false ) {
|
||||
window.clearInterval( popupWinTimer );
|
||||
publicizeConnTestStart();
|
||||
}
|
||||
}, 500 );
|
||||
}
|
||||
|
||||
publicizeConnTestComplete = function( response ) {
|
||||
var testsSelector = $( '#pub-connection-tests' );
|
||||
testsSelector
|
||||
.removeClass( 'test-in-progress' )
|
||||
.removeClass( 'below-h2' )
|
||||
.removeClass( 'error' )
|
||||
.removeClass( 'publicize-token-refresh-message' )
|
||||
.html( '' );
|
||||
|
||||
// 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 && testResult.userCanRefresh ) {
|
||||
if ( ! somethingShownAlready ) {
|
||||
testsSelector
|
||||
.addClass( 'below-h2' )
|
||||
.addClass( 'error' )
|
||||
.addClass( 'publicize-token-refresh-message' )
|
||||
.append( "<p><?php echo esc_html( __( 'Before you hit Publish, please refresh the following connection(s) to make sure we can Publicize your post:', 'jetpack' ) ); ?></p>" );
|
||||
somethingShownAlready = true;
|
||||
}
|
||||
|
||||
if ( testResult.userCanRefresh ) {
|
||||
testsSelector.append( '<p/>' );
|
||||
$( '<a/>', {
|
||||
'class' : 'pub-refresh-button button',
|
||||
'title' : testResult.refreshText,
|
||||
'href' : testResult.refreshURL,
|
||||
'text' : testResult.refreshText,
|
||||
'target' : '_refresh_' + testResult.serviceName
|
||||
} )
|
||||
.appendTo( testsSelector.children().last() )
|
||||
.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;
|
||||
}
|
||||
}
|
||||
} );
|
||||
}
|
||||
|
||||
$( document ).ready( function() {
|
||||
// If we have the #pub-connection-tests div present, kick off the connection test
|
||||
if ( $( '#pub-connection-tests' ).length ) {
|
||||
publicizeConnTestStart();
|
||||
}
|
||||
} );
|
||||
|
||||
} );
|
||||
</script>
|
||||
|
||||
<style type="text/css">
|
||||
#publicize {
|
||||
line-height: 1.5;
|
||||
}
|
||||
#publicize ul {
|
||||
margin: 4px 0 4px 6px;
|
||||
}
|
||||
#publicize li {
|
||||
margin: 0;
|
||||
}
|
||||
#publicize textarea {
|
||||
margin: 4px 0 0;
|
||||
width: 100%
|
||||
}
|
||||
#publicize ul.not-connected {
|
||||
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;
|
||||
speak: none;
|
||||
margin-left: -1px;
|
||||
padding-right: 3px;
|
||||
vertical-align: top;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
color: #82878c;
|
||||
}
|
||||
.post-new-php .authorize-link, .post-php .authorize-link {
|
||||
line-height: 1.5em;
|
||||
}
|
||||
.post-new-php .authorize-message, .post-php .authorize-message {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
#poststuff #publicize .updated p {
|
||||
margin: .5em 0;
|
||||
}
|
||||
.wpas-twitter-length-limit {
|
||||
color: red;
|
||||
}
|
||||
.publicize__notice-warning .dashicons {
|
||||
font-size: 16px;
|
||||
text-decoration: none;
|
||||
}
|
||||
</style><?php
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
function post_page_metabox() {
|
||||
global $post;
|
||||
|
||||
if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) )
|
||||
return;
|
||||
|
||||
$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author;
|
||||
$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( $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' );
|
||||
|
||||
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'] ) {
|
||||
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;
|
||||
?>
|
||||
</span>
|
||||
<?php
|
||||
/**
|
||||
* Filter the Publicize details form.
|
||||
*
|
||||
* @module publicize
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param string $publicize_form Publicize Details form appearing above Publish button in the editor.
|
||||
*/
|
||||
echo apply_filters( 'publicize_form', $publicize_form );
|
||||
?>
|
||||
</div> <?php // #publicize
|
||||
}
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
$all_done = $this->publicize->post_is_done_sharing();
|
||||
$all_connections_done = true;
|
||||
|
||||
ob_start();
|
||||
|
||||
?>
|
||||
<div id="publicize-form" class="hide-if-js">
|
||||
<ul>
|
||||
<?php
|
||||
|
||||
foreach ( $connections_data as $connection_data ) {
|
||||
$all_connections_done = $all_connections_done && $connection_data['done'];
|
||||
?>
|
||||
|
||||
<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
|
||||
}
|
||||
|
||||
$title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true );
|
||||
if ( ! $title ) {
|
||||
$title = '';
|
||||
}
|
||||
|
||||
$all_done = $all_done || $all_connections_done;
|
||||
|
||||
?>
|
||||
|
||||
</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 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 ob_get_clean();
|
||||
}
|
||||
|
||||
private function get_metabox_form_disconnected( $available_services ) {
|
||||
ob_start();
|
||||
?><div id="publicize-form" class="hide-if-js">
|
||||
<div id="add-publicize-check" style="display: none;"></div>
|
||||
|
||||
<?php _e( 'Connect to', 'jetpack' ); ?>:
|
||||
|
||||
<ul class="not-connected">
|
||||
<?php foreach ( $available_services as $service_name => $service ) : ?>
|
||||
<li>
|
||||
<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' ), $this->publicize->get_service_label( $service_name ) ) ); ?>" rel="noopener noreferrer" target="_blank" href="<?php echo esc_url( $this->publicize->connect_url( $service_name ) ); ?>">
|
||||
<?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
|
||||
</div><?php // #publicize-form
|
||||
return ob_get_clean();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user