summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/modules/publicize')
-rw-r--r--plugins/jetpack/modules/publicize/assets/connected.gifbin0 -> 1681 bytes
-rw-r--r--plugins/jetpack/modules/publicize/assets/facebook-logo.pngbin0 -> 37624 bytes
-rw-r--r--plugins/jetpack/modules/publicize/assets/linkedin-logo.pngbin0 -> 6882 bytes
-rw-r--r--plugins/jetpack/modules/publicize/assets/publicize.css175
-rw-r--r--plugins/jetpack/modules/publicize/assets/publicize.js108
-rw-r--r--plugins/jetpack/modules/publicize/assets/rtl/publicize-rtl.css177
-rw-r--r--plugins/jetpack/modules/publicize/assets/spinner.gifbin0 -> 457 bytes
-rw-r--r--plugins/jetpack/modules/publicize/assets/tumblr-logo.pngbin0 -> 9001 bytes
-rw-r--r--plugins/jetpack/modules/publicize/assets/twitter-logo.pngbin0 -> 4623 bytes
-rw-r--r--plugins/jetpack/modules/publicize/assets/yahoo-logo.pngbin0 -> 9675 bytes
-rw-r--r--plugins/jetpack/modules/publicize/publicize-jetpack.php578
-rw-r--r--plugins/jetpack/modules/publicize/publicize.php328
-rw-r--r--plugins/jetpack/modules/publicize/ui.php545
13 files changed, 1911 insertions, 0 deletions
diff --git a/plugins/jetpack/modules/publicize/assets/connected.gif b/plugins/jetpack/modules/publicize/assets/connected.gif
new file mode 100644
index 00000000..24e0c11f
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/connected.gif
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/assets/facebook-logo.png b/plugins/jetpack/modules/publicize/assets/facebook-logo.png
new file mode 100644
index 00000000..b9181cc4
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/facebook-logo.png
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/assets/linkedin-logo.png b/plugins/jetpack/modules/publicize/assets/linkedin-logo.png
new file mode 100644
index 00000000..27018dcd
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/linkedin-logo.png
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/assets/publicize.css b/plugins/jetpack/modules/publicize/assets/publicize.css
new file mode 100644
index 00000000..4065cb01
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/publicize.css
@@ -0,0 +1,175 @@
+div#publicize-services-block {
+ display: inline-block;
+ clear: both;
+ margin-bottom: 25px;
+ background-color: #fff;
+ width: 100%;
+}
+
+/* Add the logos for the Publicize services */
+span.pub-logos {
+ float: left;
+ display: block;
+ width: 130px;
+ height: 75px;
+ margin-top: -18px;
+ margin-left: 5px;
+ vertical-align: top;
+}
+
+span#facebook { background: url( facebook-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#twitter { background: url( twitter-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#yahoo { background: url( yahoo-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#linkedin { background: url( linkedin-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#tumblr { background: url( tumblr-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+
+a.publicize-profile-link, a.publicize-profile-link:visited {
+ text-decoration: none;
+}
+
+a.publicize-profile-link:hover {
+ color: #f1831e;
+}
+
+a.publicize-add-connection, a.publicize-add-connection:visited {
+ display: block;
+ vertical-align: middle;
+ text-decoration: none;
+}
+
+a.publicize-add-connection:hover {
+ color: #f1831e;
+}
+
+div.publicize-service-entry {
+ width: 100%;
+ clear: both;
+ margin-bottom: 10px;
+}
+
+div.publicize-service-left {
+ display: inline-block;
+ width: 150px;
+ vertical-align: top;
+}
+
+div.publicize-service-right {
+ display: inline-block;
+ margin-left: 5px;
+ margin-top: 5px;
+ width: 300px;
+ padding: 10px;
+ background-color: #f1f1f1;
+ -moz-border-radius: 10px;
+ -webkit-border-radius: 10px;
+ border-radius: 10px;
+ border: 1px solid #e5e5e5;
+}
+
+div.publicize-service-right ul {
+ margin-top: 0;
+}
+
+div.publicize-service-right li {
+ list-style-type: none;
+}
+
+.pub-disconnect-button {
+ -webkit-border-image: none;
+ border-bottom-color: #CCC;
+ border-bottom-style: none;
+ border-bottom-width: 0px;
+ border-left-color: #CCC;
+ border-left-style: none;
+ border-left-width: 0px;
+ border-right-color: #CCC;
+ border-right-style: none;
+ border-right-width: 0px;
+ border-top-color: #CCC;
+ border-top-style: none;
+ border-top-width: 0px;
+ color: #CCC;
+ cursor: auto;
+ display: inline;
+ font-family: sans-serif;
+ font-size: 15px;
+ font-style: normal;
+ font-weight: normal;
+ height: auto;
+ line-height: 22px;
+ list-style-image: none;
+ list-style-position: outside;
+ list-style-type: none;
+ margin-bottom: 0px;
+ margin-left: 0px;
+ margin-right: 0px;
+ margin-top: 0px;
+ outline-color: #CCC;
+ outline-style: none;
+ outline-width: 0px;
+ overflow-y: visible;
+ padding-bottom: 0px;
+ padding-left: 0px;
+ padding-right: 0px;
+ padding-top: 0px;
+ position: static;
+ right: auto;
+ text-align: left;
+ text-decoration: none;
+ top: auto;
+ vertical-align: baseline;
+ width: auto;
+ z-index: auto;
+}
+
+.pub-disconnect-button:hover {
+ color: #f1831e;
+}
+
+table#option-profile {
+ padding-bottom: 8px;
+}
+
+table#option-profile td {
+ font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+ vertical-align: middle;
+}
+
+table#option-profile td.radio {
+ padding-right: 20px;
+}
+
+table#option-profile td.thumbnail {
+ padding-right: 20px;
+}
+
+table#option-profile td.details {
+ font-weight: bold; color: #333333
+}
+
+table#option-fb-fanpage td {
+ font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+ vertical-align: middle;
+}
+
+table#option-fb-fanpage td.thumbnail {
+ padding: 5px 20px 5px 20px;
+}
+
+table#option-fb-fanpage td.details {
+ width: 130px;
+ padding-right: 10px;
+}
+
+table#option-fb-fanpage td.details span.name {
+ font-weight: bold; color: #333333;
+}
+
+table#option-fb-fanpage td.details span.category {
+ font-size: 10px; color: #888888;
+}
+
+input.fb-options {
+ font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+ font-size: 12px;
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/publicize/assets/publicize.js b/plugins/jetpack/modules/publicize/assets/publicize.js
new file mode 100644
index 00000000..bb1f8d4c
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/publicize.js
@@ -0,0 +1,108 @@
+var showOptionsPage;
+
+jQuery( function( $ ) {
+
+ showOptionsPage = function( service, nonce, connection, blogId ) {
+ tb_show( null, null, null );
+ $("body").append( "<div id='TB_load'><img src='" + tb_pathToImage + "' /></div>" );
+ $('#TB_load').show();
+
+ var query = '';
+ if ( null != connection ) {
+ query += '&connection=' + encodeURIComponent( connection );
+ }
+ if ( 'undefined' != typeof( blogId ) && null != blogId ) {
+ query += '&blog_id=' + Number( blogId );
+ }
+
+ $.post( ajaxurl, 'action=publicize_' + service + '_options_page&_wpnonce=' + nonce + query, function( response ) {
+ $("#TB_load").remove();
+
+ try {
+ var obj = jQuery.parseJSON( response );
+ if ( null != obj && 'object' == typeof( obj ) ) {
+ if ( obj.hasOwnProperty( 'fb_redirect' ) ) {
+ location.href = obj.fb_redirect + '&redirect_uri=' + encodeURIComponent( location.href );
+ return;
+ }
+ }
+ } catch (err) {
+ // Do nothing and move on
+ }
+
+ if ( response != '' ) {
+ var blogID = $( 'input[name=wpas_ajax_blog_id]' ).val();
+
+ var message = $( '<div id="wpas-ajax-' + blogID + '" class="wrap"></div>' ).append( response );
+ message.append( '<a href="#TB_inline?thickbox&height=420&width=555&inlineId=wpas-ajax-' + blogID + '" id="wpas-click-' + blogID + '" class="new-thickbox" style="display: none;"></a>' );
+ $('#wpas-message').html( message );
+
+
+ tb_init( 'a.new-thickbox' );
+ $('#wpas-click-' + blogID).click();
+
+ var tb_height = parseInt( $('#TB_ajaxContent').css('height') );
+ var content_height = $('#thickbox-content').height();
+ if ( content_height < tb_height ) {
+ var new_height = content_height + 15;
+ $('#TB_ajaxContent').css( 'height', new_height );
+
+ var new_margin = parseInt( $('#TB_window').css( 'margin-top') ) + (tb_height - new_height) / 2 + 'px'
+ $('#TB_window').css( 'margin-top', new_margin);
+ }
+
+ $('.save-options').unbind('click').click( function() {
+ var sel = $( "input[name='option']:checked" );
+ var global = $( "input[name='global']:checked" );
+
+ var connection = $(this).data('connection');
+ var token = encodeURIComponent( sel.val() );
+ var id = encodeURIComponent( sel.attr( 'id' ) );
+ var type = encodeURIComponent( sel.attr( 'data-type' ) );
+ var nonce = $(this).attr('rel');
+ var global_conn = 'off';
+ var global_nonce = '';
+
+ if ( global.length ) {
+ global_conn = 'on';
+ global_nonce = global.val();
+ }
+
+ $.post( ajaxurl, 'action=publicize_'+ service + '_options_save&connection=' + connection + '&selected_id=' + id + '&token=' + token + '&type=' + type + '&_wpnonce=' + nonce + '&global=' + global_conn + '&global_nonce=' + global_nonce, function( response ) {
+ tb_remove();
+ window.location = 'options-general.php?page=sharing';
+ } );
+
+ } );
+ }
+
+ }, 'html' );
+ }
+
+ $( 'body' ).append( '<div id="wpas-message" style="display: none"></div>' );
+ var messageDiv = $( '#wpas-message' );
+
+ $( '.wpas-posts' ).change( function() {
+ var inputs = $(this).parents( 'td:first' ).find( ':input' );
+ var _this = this;
+ var blogID = inputs.filter( '[name=wpas_ajax_blog_id]' ).val();
+
+ $( '#waiting_' + blogID ).show();
+ $.post( ajaxurl, inputs.serialize() + '&action=wpas_post', function( response ) { myblogsResponse.call( _this, blogID, response ) }, 'html' );
+ } );
+
+ $( '.options' ).unbind('click').bind( 'click', function(e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ var service = $(this).attr('class').replace( 'options ', '' );
+
+ var blogId = null;
+ if( 'undefined' != typeof( $(this).attr('id') ) )
+ blogId = parseInt( $(this).attr('id').replace( 'options-', '' ) );
+
+ var nonce = $(this).attr('href').replace( '#nonce=', '' );
+ var connection = $(this).data( 'connection' );
+ showOptionsPage.call( this, service, nonce, connection, blogId );
+ });
+} );
diff --git a/plugins/jetpack/modules/publicize/assets/rtl/publicize-rtl.css b/plugins/jetpack/modules/publicize/assets/rtl/publicize-rtl.css
new file mode 100644
index 00000000..b56ab2fb
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/rtl/publicize-rtl.css
@@ -0,0 +1,177 @@
+/* This file was automatically generated on Dec 18 2012 19:58:18 */
+
+div#publicize-services-block {
+ display: inline-block;
+ clear: both;
+ margin-bottom: 25px;
+ background-color: #fff;
+ width: 100%;
+}
+
+/* Add the logos for the Publicize services */
+span.pub-logos {
+ float: right;
+ display: block;
+ width: 130px;
+ height: 75px;
+ margin-top: -18px;
+ margin-right: 5px;
+ vertical-align: top;
+}
+
+span#facebook { background: url( ../facebook-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#twitter { background: url( ../twitter-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#yahoo { background: url( ../yahoo-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#linkedin { background: url( ../linkedin-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+span#tumblr { background: url( ../tumblr-logo.png ) 50% 19px no-repeat; background-size: 125px 47px; }
+
+a.publicize-profile-link, a.publicize-profile-link:visited {
+ text-decoration: none;
+}
+
+a.publicize-profile-link:hover {
+ color: #f1831e;
+}
+
+a.publicize-add-connection, a.publicize-add-connection:visited {
+ display: block;
+ vertical-align: middle;
+ text-decoration: none;
+}
+
+a.publicize-add-connection:hover {
+ color: #f1831e;
+}
+
+div.publicize-service-entry {
+ width: 100%;
+ clear: both;
+ margin-bottom: 10px;
+}
+
+div.publicize-service-left {
+ display: inline-block;
+ width: 150px;
+ vertical-align: top;
+}
+
+div.publicize-service-right {
+ display: inline-block;
+ margin-right: 5px;
+ margin-top: 5px;
+ width: 300px;
+ padding: 10px;
+ background-color: #f1f1f1;
+ -moz-border-radius: 10px;
+ -webkit-border-radius: 10px;
+ border-radius: 10px;
+ border: 1px solid #e5e5e5;
+}
+
+div.publicize-service-right ul {
+ margin-top: 0;
+}
+
+div.publicize-service-right li {
+ list-style-type: none;
+}
+
+.pub-disconnect-button {
+ -webkit-border-image: none;
+ border-bottom-color: #CCC;
+ border-bottom-style: none;
+ border-bottom-width: 0px;
+ border-right-color: #CCC;
+ border-right-style: none;
+ border-right-width: 0px;
+ border-left-color: #CCC;
+ border-left-style: none;
+ border-left-width: 0px;
+ border-top-color: #CCC;
+ border-top-style: none;
+ border-top-width: 0px;
+ color: #CCC;
+ cursor: auto;
+ display: inline;
+ font-family: sans-serif;
+ font-size: 15px;
+ font-style: normal;
+ font-weight: normal;
+ height: auto;
+ line-height: 22px;
+ list-style-image: none;
+ list-style-position: outside;
+ list-style-type: none;
+ margin-bottom: 0px;
+ margin-right: 0px;
+ margin-left: 0px;
+ margin-top: 0px;
+ outline-color: #CCC;
+ outline-style: none;
+ outline-width: 0px;
+ overflow-y: visible;
+ padding-bottom: 0px;
+ padding-right: 0px;
+ padding-left: 0px;
+ padding-top: 0px;
+ position: static;
+ left: auto;
+ text-align: right;
+ text-decoration: none;
+ top: auto;
+ vertical-align: baseline;
+ width: auto;
+ z-index: auto;
+}
+
+.pub-disconnect-button:hover {
+ color: #f1831e;
+}
+
+table#option-profile {
+ padding-bottom: 8px;
+}
+
+table#option-profile td {
+ font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+ vertical-align: middle;
+}
+
+table#option-profile td.radio {
+ padding-left: 20px;
+}
+
+table#option-profile td.thumbnail {
+ padding-left: 20px;
+}
+
+table#option-profile td.details {
+ font-weight: bold; color: #333333
+}
+
+table#option-fb-fanpage td {
+ font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+ vertical-align: middle;
+}
+
+table#option-fb-fanpage td.thumbnail {
+ padding: 5px 20px 5px 20px;
+}
+
+table#option-fb-fanpage td.details {
+ width: 130px;
+ padding-left: 10px;
+}
+
+table#option-fb-fanpage td.details span.name {
+ font-weight: bold; color: #333333;
+}
+
+table#option-fb-fanpage td.details span.category {
+ font-size: 10px; color: #888888;
+}
+
+input.fb-options {
+ font-family: "Lucida Grande",Verdana,Arial,sans-serif;
+ font-size: 12px;
+} \ No newline at end of file
diff --git a/plugins/jetpack/modules/publicize/assets/spinner.gif b/plugins/jetpack/modules/publicize/assets/spinner.gif
new file mode 100644
index 00000000..6e5bace6
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/spinner.gif
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/assets/tumblr-logo.png b/plugins/jetpack/modules/publicize/assets/tumblr-logo.png
new file mode 100644
index 00000000..1ec62d39
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/tumblr-logo.png
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/assets/twitter-logo.png b/plugins/jetpack/modules/publicize/assets/twitter-logo.png
new file mode 100644
index 00000000..6c7b89b3
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/twitter-logo.png
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/assets/yahoo-logo.png b/plugins/jetpack/modules/publicize/assets/yahoo-logo.png
new file mode 100644
index 00000000..b7ffe2bb
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/assets/yahoo-logo.png
Binary files differ
diff --git a/plugins/jetpack/modules/publicize/publicize-jetpack.php b/plugins/jetpack/modules/publicize/publicize-jetpack.php
new file mode 100644
index 00000000..58e25648
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/publicize-jetpack.php
@@ -0,0 +1,578 @@
+<?php
+
+class Publicize extends Publicize_Base {
+
+ function __construct() {
+ parent::__construct();
+
+ 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_yahoo_options_page', array( $this, 'options_page_yahoo' ) );
+
+ 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( 'wp_ajax_publicize_yahoo_options_save', array( $this, 'options_save_yahoo' ) );
+
+ add_action( 'load-settings_page_sharing', array( $this, 'force_user_connection' ) );
+
+ add_action( 'transition_post_status', array( $this, 'save_publicized' ), 10, 3 );
+ }
+
+ 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' ) );
+
+ 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">
+ <h4>
+ <p><?php printf(
+ esc_html( wptexturize( __( "To use Publicize, you'll need to link your %s account to your WordPress.com account using the button to the right.", '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>
+ </h4>
+ </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>
+ </div>
+ </div>
+ </div>
+ <?php
+ }
+
+ function get_connections( $service_name, $_blog_id = false, $_user_id = false ) {
+ $connections = Jetpack::get_option( 'publicize_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'] || $this->user_id() == $connection['connection_data']['user_id'] ) {
+ $connections_to_return[$id] = $connection;
+ }
+ }
+ }
+ return $connections_to_return;
+ }
+ return false;
+ }
+
+ function get_connection_id( $connection ) {
+ return $connection['connection_data']['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'] ) ) {
+ if ( isset( $_GET['service'] ) )
+ $service_name = $_GET['service'];
+
+ switch ( $_GET['action'] ) {
+ case 'error':
+ add_action( 'pre_admin_screen_sharing', array( $this, 'display_connection_error' ), 9 );
+ break;
+
+ case 'request':
+ check_admin_referer( 'keyring-request', 'kr_nonce' );
+ check_admin_referer( "keyring-request-$service_name", 'nonce' );
+
+ $verification = Jetpack::create_nonce( 'publicize' );
+
+ $stats_options = get_option( 'stats_options' );
+ $wpcom_blog_id = Jetpack::get_option('id');
+ $wpcom_blog_id = !empty( $wpcom_blog_id ) ? $wpcom_blog_id : $stats_options['blog_id'];
+
+ $user = wp_get_current_user();
+ $redirect = $this->api_url( $service_name, urlencode_deep( array(
+ 'action' => 'request',
+ 'redirect_uri' => add_query_arg( array( 'action' => 'done' ), menu_page_url( 'sharing', false ) ),
+ 'for' => 'publicize', // required flag that says this connection is intended for publicize
+ 'siteurl' => site_url(),
+ 'state' => $user->ID,
+ 'blog_id' => $wpcom_blog_id,
+ 'secret_1' => $verification['secret_1'],
+ 'secret_2' => $verification['secret_2'],
+ 'eol' => $verification['eol'],
+ ) ) );
+ wp_redirect( $redirect );
+ exit;
+ break;
+
+ case 'completed':
+ // Jetpack blog requests Publicize Connections via new XML-RPC method
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client();
+ $xml->query( 'jetpack.fetchPublicizeConnections' );
+
+ if ( !$xml->isError() ) {
+ $response = $xml->getResponse();
+ Jetpack::update_option( 'publicize_connections', $response );
+ }
+ break;
+
+ case 'delete':
+ $id = $_GET['id'];
+
+ check_admin_referer( 'keyring-request', 'kr_nonce' );
+ check_admin_referer( "keyring-request-$service_name", 'nonce' );
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client();
+ $xml->query( 'jetpack.deletePublicizeConnection', $id );
+
+ if ( !$xml->isError() ) {
+ $response = $xml->getResponse();
+ Jetpack::update_option( 'publicize_connections', $response );
+ }
+ add_action( 'admin_notices', array( $this, 'display_disconnected' ) );
+ break;
+ }
+ }
+
+ // Errors encountered on WordPress.com's end are passed back as a code
+ if ( isset( $_GET['action'] ) && 'error' == $_GET['action'] ) {
+ // Load Jetpack's styles to handle the box
+ Jetpack::init()->admin_styles();
+ }
+ }
+
+ 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">
+ <h4><?php echo wp_kses( $error, array( 'a' => array( 'href' => true ), 'code' => true, 'strong' => true, 'br' => true, 'b' => true ) ); ?></h4>
+ <?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'] ) {
+ $id = $_REQUEST['connection'];
+
+ if ( !current_user_can( Publicize::GLOBAL_CAP ) )
+ return;
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client();
+ $xml->query( 'jetpack.globalizePublicizeConnection', $id, 'globalize' );
+
+ if ( !$xml->isError() ) {
+ $response = $xml->getResponse();
+ Jetpack::update_option( 'publicize_connections', $response );
+ }
+ }
+ }
+
+ /**
+ * Gets a URL to the public-api actions. Works like WP's admin_url
+ *
+ * @param string $service Shortname of a specific service.
+ * @return URL to specific public-api process
+ */
+ // on WordPress.com this is/calls Keyring::admin_url
+ function api_url( $service = false, $params = array() ) {
+ $url = apply_filters( 'publicize_api_url', 'https://public-api.wordpress.com/connect/?jetpack=publicize' );
+
+ if ( $service )
+ $url = add_query_arg( array( 'service' => $service ), $url );
+
+ if ( count ( $params ) )
+ $url = add_query_arg( $params, $url );
+
+ return $url;
+ }
+
+ function connect_url( $service_name ) {
+ return add_query_arg( array(
+ 'action' => 'request',
+ 'service' => $service_name,
+ 'kr_nonce' => wp_create_nonce( 'keyring-request' ),
+ 'nonce' => wp_create_nonce( "keyring-request-$service_name" ),
+ ), menu_page_url( 'sharing', false ) );
+ }
+
+ function disconnect_url( $service_name, $id ) {
+ return add_query_arg( array (
+ 'action' => 'delete',
+ 'service' => $service_name,
+ 'id' => $id,
+ 'kr_nonce' => wp_create_nonce( 'keyring-request' ),
+ 'nonce' => wp_create_nonce( "keyring-request-$service_name" ),
+ ), menu_page_url( 'sharing', false ) );
+ }
+
+ function get_services( $filter ) {
+ if ( !in_array( $filter, array( 'all', 'connected' ) ) )
+ $filter = 'all';
+
+ $services = array(
+ 'facebook' => array(),
+ 'twitter' => array(),
+ 'linkedin' => array(),
+ 'tumblr' => array(),
+ 'yahoo' => array(),
+ );
+
+ if ( 'all' == $filter ) {
+ return $services;
+ } else {
+ $connected_services = array();
+ foreach ( $services as $service => $empty ) {
+ $connections = $this->get_connections( $service );
+ if ( $connections )
+ $connected_services[$service] = $connections;
+ }
+ return $connected_services;
+ }
+ }
+
+ function get_connection( $service, $id, $_blog_id = false, $_user_id = false ) {
+ // Stub
+ }
+
+ function flag_post_for_publicize( $new_status, $old_status, $post ) {
+ // Stub only. Doesn't need to do anything on Jetpack Client
+ }
+
+ /**
+ * Save a flag locally to indicate that this post has already been Publicized via the selected
+ * connections.
+ */
+ function save_publicized( $new_status, $old_status, $post ) {
+ // Only do this when a post transitions to being published
+ if ( 'publish' == $new_status && 'publish' != $old_status ) {
+ update_post_meta( $post->ID, $this->POST_DONE . 'all', true );
+ }
+ }
+
+ /**
+ * Options Code
+ */
+
+ function options_page_facebook() {
+ $connected_services = Jetpack::get_option( 'publicize_connections' );
+ $connection = $connected_services['facebook'][$_REQUEST['connection']];
+ $options_to_show = $connection['connection_data']['meta']['options_responses'];
+
+ // Nonce check
+ check_admin_referer( 'options_page_facebook_' . $_REQUEST['connection'] );
+
+ $me = $options_to_show[0];
+ $pages = $options_to_show[1]['data'];
+
+ $profile_checked = true;
+ $page_selected = false;
+
+ if ( !empty( $connection['connection_data']['meta']['facebook_page'] ) ) {
+ $found = false;
+ if ( is_array( $pages->data ) ) {
+ foreach ( $pages->data as $page ) {
+ if ( $page->id == $connection['connection_data']['meta']['facebook_page'] ) {
+ $found = true;
+ break;
+ }
+ }
+ }
+
+ if ( $found ) {
+ $profile_checked = false;
+ $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;
+ ?>
+
+ <?php if ( !empty( $me['name'] ) ) : ?>
+ <p><?php printf(
+ esc_html__( 'Publicize to my %s:', 'jetpack' ),
+ '<strong>' . esc_html__( 'Facebook Wall', 'jetpack' ) . '</strong>'
+ ); ?></p>
+ <table id="option-profile">
+ <tbody>
+ <tr>
+ <td class="radio"><input type="radio" name="option" data-type="profile" id="<?php echo esc_attr( $me['id'] ) ?>" value="" <?php checked( $profile_checked, true ); ?> /></td>
+ <td class="thumbnail"><label for="<?php echo esc_attr( $me['id'] ) ?>"><img src="<?php echo esc_url( $me['picture']['data']['url'] ) ?>" width="50" height="50" /></label></td>
+ <td class="details"><label for="<?php echo esc_attr( $me['id'] ) ?>"><?php echo esc_html( $me['name'] ) ?></label></td>
+ </tr>
+ </tbody>
+ </table>
+ <?php endif; ?>
+
+ <?php if ( $pages ) : ?>
+
+ <p><?php printf(
+ esc_html__( 'Publicize to my %s:', 'jetpack' ),
+ '<strong>' . esc_html__( 'Facebook Page', 'jetpack' ) . '</strong>'
+ ); ?></p>
+ <table id="option-fb-fanpage">
+ <tbody>
+
+ <?php foreach ( $pages as $i => $page ) : ?>
+ <?php if ( ! isset( $page['perms'] ) ) { continue; } ?>
+ <?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 endif; ?>
+
+ <?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/>
+ </div>
+
+ <?php
+ }
+
+ function options_save_facebook() {
+ // Nonce check
+ check_admin_referer( 'save_fb_token_' . $_REQUEST['connection'] );
+
+ $id = $_POST['connection'];
+
+ // Check for a numeric page ID
+ $page_id = $_POST['selected_id'];
+ if ( !ctype_digit( $page_id ) )
+ die( 'Security check' );
+
+ if ( isset( $_POST['selected_id'] ) && 'profile' == $_POST['type'] ) {
+ // Publish to User Wall/Profile
+ $options = array(
+ 'facebook_page' => null,
+ 'facebook_profile' => true
+ );
+
+ } else {
+ if ( 'page' != $_POST['type'] || !isset( $_POST['selected_id'] ) ) {
+ return;
+ }
+
+ // Publish to Page
+ $options = array(
+ 'facebook_page' => $page_id,
+ 'facebook_profile' => null
+ );
+ }
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client();
+ $xml->query( 'jetpack.setPublicizeOptions', $id, $options );
+
+ if ( !$xml->isError() ) {
+ $response = $xml->getResponse();
+ Jetpack::update_option( 'publicize_connections', $response );
+ }
+
+ $this->globalization();
+ }
+
+ function options_page_tumblr() {
+ // Nonce check
+ check_admin_referer( 'options_page_tumblr_' . $_REQUEST['connection'] );
+
+ $connected_services = Jetpack::get_option( 'publicize_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 printf(
+ esc_html__( 'Publicize to my %s:', 'jetpack' ),
+ '<strong>' . esc_html__( 'Tumblr blog', 'jetpack' ) . '</strong>'
+ ); ?></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'] );
+
+ $id = $_POST['connection'];
+
+ $options = array( 'tumblr_base_hostname' => $_POST['selected_id'] );
+
+ Jetpack::load_xml_rpc_client();
+ $xml = new Jetpack_IXR_Client();
+ $xml->query( 'jetpack.setPublicizeOptions', $id, $options );
+
+ if ( !$xml->isError() ) {
+ $response = $xml->getResponse();
+ Jetpack::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_page_yahoo() { Publicize_UI::options_page_other( 'yahoo' ); }
+
+ function options_save_twitter() { $this->options_save_other( 'twitter' ); }
+ function options_save_linkedin() { $this->options_save_other( 'linkedin' ); }
+ function options_save_yahoo() { $this->options_save_other( 'yahoo' ); }
+
+ function options_save_other( $service_name ) {
+ // Nonce check
+ check_admin_referer( 'save_' . $service_name . '_token_' . $_REQUEST['connection'] );
+ $this->globalization();
+ }
+
+ // stub
+ function refresh_tokens_message() {
+
+ }
+}
diff --git a/plugins/jetpack/modules/publicize/publicize.php b/plugins/jetpack/modules/publicize/publicize.php
new file mode 100644
index 00000000..16d4541c
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/publicize.php
@@ -0,0 +1,328 @@
+<?php
+
+abstract class Publicize_Base {
+
+ /**
+ * Services that are currently connected to the given user
+ * through publicize.
+ */
+ var $connected_services = array();
+
+ /**
+ * Sservices that are supported by publicize. They don't
+ * neccessarly need to be connected to the current user.
+ */
+ var $services;
+
+ /**
+ * key names for post meta
+ */
+ var $ADMIN_PAGE = 'wpas';
+ var $POST_MESS = '_wpas_mess';
+ var $POST_SKIP = '_wpas_skip_'; // connection id appended to indicate that a connection should NOT be publicized to
+ var $POST_DONE = '_wpas_done_'; // connection id appended to indicate a connection has already been publicized to
+ var $USER_AUTH = 'wpas_authorize';
+ var $USER_OPT = 'wpas_';
+ var $PENDING = '_publicize_pending'; // ready for Publicize to do its thing
+ var $POST_SERVICE_DONE = '_publicize_done_external'; // array of external ids where we've Publicized
+
+ /**
+ * default pieces of the message used in constructing the
+ * content pushed out to other social networks
+ */
+ var $default_prefix = '';
+ var $default_message = '%title%';
+ var $default_suffix = ' %url%';
+
+ /**
+ * What WP capability is require to create/delete global connections?
+ * All users with this cap can unglobalize all other global connections, and globalize any of their own
+ * Globalized connections cannot be unselected by users without this capability when publishing
+ */
+ const GLOBAL_CAP = 'edit_others_posts';
+
+ /**
+ * Sets up the basics of Publicize
+ */
+ function __construct() {
+ $this->default_message = Publicize_Util::build_sprintf( array(
+ apply_filters( 'wpas_default_message', $this->default_message ),
+ 'title',
+ 'url',
+ ) );
+
+ $this->default_prefix = Publicize_Util::build_sprintf( array(
+ apply_filters( 'wpas_default_prefix', $this->default_prefix ),
+ 'url',
+ ) );
+
+ $this->default_suffix = Publicize_Util::build_sprintf( array(
+ apply_filters( 'wpas_default_suffix', $this->default_suffix ),
+ 'url',
+ ) );
+
+
+ // stage 1 and 2 of 3-stage Publicize. Flag for Publicize on creation, save meta,
+ // then check meta and publicze based on that. stage 3 implemented on wpcom
+ add_action( 'transition_post_status', array( $this, 'flag_post_for_publicize' ), 10, 3 );
+ add_action( 'save_post', array( &$this, 'save_meta' ), 20, 2 );
+ }
+
+ /**
+ * Functions to be implemented by the extended class (publicize-wpcom or publicize-jetpack)
+ */
+ abstract function get_connection_id( $connection );
+ abstract function connect_url( $service_name );
+ abstract function disconnect_url( $service_name, $id );
+ abstract function get_connection_meta( $connection );
+ abstract function get_services( $filter );
+ abstract function get_connections( $service, $_blog_id = false, $_user_id = false );
+ abstract function get_connection( $service, $id, $_blog_id = false, $_user_id = false );
+ abstract function flag_post_for_publicize( $new_status, $old_status, $post );
+
+ /**
+ * Shared Functions
+ */
+
+ /**
+ * Returns an external URL to the connection's profile
+ */
+ function get_profile_link( $service_name, $c ) {
+ $cmeta = $this->get_connection_meta( $c );
+
+ if ( isset( $cmeta['connection_data']['meta']['link'] ) ) {
+ return $cmeta['connection_data']['meta']['link'];
+ } elseif ( 'facebook' == $service_name && isset( $cmeta['connection_data']['meta']['facebook_page'] ) ) {
+ return 'http://facebook.com/' . $cmeta['connection_data']['meta']['facebook_page'];
+ } elseif ( 'facebook' == $service_name ) {
+ return 'http://www.facebook.com/' . $cmeta['external_id'];
+ } elseif ( 'tumblr' == $service_name && isset( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) {
+ return 'http://' . $cmeta['connection_data']['meta']['tumblr_base_hostname'];
+ } elseif ( 'twitter' == $service_name ) {
+ return 'http://twitter.com/' . substr( $cmeta['external_display'], 1 ); // Has a leading '@'
+ } else if ( 'yahoo' == $service_name ) {
+ return 'http://profile.yahoo.com/' . $cmeta['external_id'];
+ } else if ( 'linkedin' == $service_name ) {
+ if ( !isset( $cmeta['connection_data']['meta']['profile_url'] ) ) {
+ return false;
+ }
+
+ $profile_url_query = parse_url( $cmeta['connection_data']['meta']['profile_url'], PHP_URL_QUERY );
+ wp_parse_str( $profile_url_query, $profile_url_query_args );
+ if ( !isset( $profile_url_query_args['key'] ) ) {
+ return false;
+ }
+
+ return esc_url_raw( add_query_arg( 'id', urlencode( $profile_url_query_args['key'] ), 'http://www.linkedin.com/profile/view' ) );
+ } else {
+ return false; // no fallback. we just won't link it
+ }
+ }
+
+ /**
+ * Returns a display name for the connection
+ */
+ function get_display_name( $service_name, $c ) {
+ $cmeta = $this->get_connection_meta( $c );
+
+ if ( isset( $cmeta['connection_data']['meta']['display_name'] ) ) {
+ return $cmeta['connection_data']['meta']['display_name'];
+ } elseif ( $service_name == 'tumblr' && isset( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) ) {
+ return $cmeta['connection_data']['meta']['tumblr_base_hostname'];
+ } elseif ( $service_name == 'twitter' ) {
+ return $cmeta['external_display'];
+ } else {
+ $connection_display = $cmeta['external_display'];
+ if ( empty( $connection_display ) )
+ $connection_display = $cmeta['external_name'];
+ return $connection_display;
+ }
+ }
+
+ function get_service_label( $service_name ) {
+ switch ( $service_name ) {
+ case 'yahoo':
+ return 'Yahoo!';
+ break;
+ case 'linkedin':
+ return 'LinkedIn';
+ break;
+ case 'twitter':
+ case 'facebook':
+ case 'tumblr':
+ default:
+ return ucfirst( $service_name );
+ break;
+ }
+ }
+
+ function show_options_popup( $service_name, $c ) {
+ $cmeta = $this->get_connection_meta( $c );
+
+ // always show if no selection has been made for facebook
+ if ( 'facebook' == $service_name && empty( $cmeta['connection_data']['meta']['facebook_profile'] ) && empty( $cmeta['connection_data']['meta']['facebook_page'] ) )
+ return true;
+
+ // always show if no selection has been made for tumblr
+ if ( 'tumblr' == $service_name && empty ( $cmeta['connection_data']['meta']['tumblr_base_hostname'] ) )
+ return true;
+
+ // if we have the specific conncetion info..
+ if ( isset( $_GET['id'] ) ) {
+ if ( $cmeta['connection_data']['id'] == $_GET['id'] )
+ return true;
+ } else {
+ // otherwise, just show if this is the completed step / first load
+ if ( !empty( $_GET['action'] ) && 'completed' == $_GET['action'] && !empty( $_GET['service'] ) && $service_name == $_GET['service'] && ! in_array( $_GET['service'], array( 'facebook', 'tumblr' ) ) )
+ return true;
+ }
+
+ return false;
+ }
+
+ function user_id() {
+ global $current_user;
+ return $current_user->ID;
+ }
+
+ function blog_id() {
+ return get_current_blog_id();
+ }
+
+ /**
+ * Returns true if a user has a connection to a particular service, false otherwise
+ */
+ function is_enabled( $service, $_blog_id = false, $_user_id = false ) {
+ if ( !$_blog_id )
+ $_blog_id = $this->blog_id();
+
+ if ( !$_user_id )
+ $_user_id = $this->user_id();
+
+ $connections = $this->get_connections( $service, $_blog_id, $_user_id );
+ return ( is_array( $connections ) && count( $connections ) > 0 ? true : false );
+ }
+
+ /**
+ * Fires when a post is saved, checks conditions and saves state in postmeta so that it
+ * can be picked up later by @see ::publicize_post()
+ */
+ function save_meta( $post_id, $post ) {
+ $cron_user = null;
+ $submit_post = true;
+
+ // don't do anything if its not actually a post
+ if ( 'post' !== $post->post_type )
+ return;
+
+ // Don't Publicize during certain contexts:
+
+ // - import
+ if ( defined( 'WP_IMPORTING' ) && WP_IMPORTING )
+ $submit_post = false;
+
+ // - on quick edit, autosave, etc but do fire on p2, quickpress, and instapost ajax
+ if (
+ defined( 'DOING_AJAX' )
+ &&
+ DOING_AJAX
+ &&
+ !did_action( 'p2_ajax' )
+ &&
+ !did_action( 'wp_ajax_json_quickpress_post' )
+ &&
+ !did_action( 'wp_ajax_instapost_publish' )
+ &&
+ !did_action( 'wp_ajax_post_reblog' )
+ ) {
+ $submit_post = false;
+ }
+
+ // - bulk edit
+ if ( isset( $_GET['bulk_edit'] ) )
+ $submit_post = false;
+
+ // - API/XML-RPC Test Posts
+ if (
+ (
+ defined( 'XMLRPC_REQUEST' )
+ &&
+ XMLRPC_REQUEST
+ ||
+ defined( 'APP_REQUEST' )
+ &&
+ APP_REQUEST
+ )
+ &&
+ 0 === strpos( $post->post_title, 'Temporary Post Used For Theme Detection' )
+ ) {
+ $submit_post = false;
+ }
+
+ // only work with certain statuses (avoids inherits, auto drafts etc)
+ if ( !in_array( $post->post_status, array( 'publish', 'draft', 'future' ) ) )
+ $submit_post = false;
+
+ // don't publish password protected posts
+ if ( '' !== $post->post_password )
+ $submit_post = false;
+
+ // Did this request happen via wp-admin?
+ $from_web = 'post' == strtolower( $_SERVER['REQUEST_METHOD'] ) && isset( $_POST[$this->ADMIN_PAGE] );
+
+ if ( ( $from_web || defined( 'POST_BY_EMAIL' ) ) && !empty( $_POST['wpas_title'] ) )
+ update_post_meta( $post_id, $this->POST_MESS, trim( stripslashes( $_POST['wpas_title'] ) ) );
+
+ // change current user to provide context for get_services() if we're running during cron
+ if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
+ $cron_user = (int) $GLOBALS['user_ID'];
+ wp_set_current_user( $post->post_author );
+ }
+
+ /**
+ * In this phase, we mark connections that we want to SKIP. When Publicize is actually triggered,
+ * it will Publicize to everything *except* those marked for skipping.
+ */
+ foreach ( (array) $this->get_services( 'connected' ) as $service_name => $connections ) {
+ foreach ( $connections as $connection ) {
+ if ( false == apply_filters( 'wpas_submit_post?', $submit_post, $post_id, $service_name ) ) {
+ delete_post_meta( $post_id, $this->PENDING );
+ continue;
+ }
+
+ 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'];
+
+ // This was a wp-admin request, so we need to check the state of checkboxes
+ if ( $from_web ) {
+ // We *unchecked* this stream from the admin page, or it's set to readonly, or it's a new addition
+ if ( empty( $_POST[$this->ADMIN_PAGE]['submit'][$unique_id] ) ) {
+ // Also make sure that the service-specific input isn't there.
+ // If the user connected to a new service 'in-page' then a hidden field with the service
+ // name is added, so we just assume they wanted to Publicize to that service.
+ if ( empty( $_POST[$this->ADMIN_PAGE]['submit'][$service_name] ) ) {
+ // Nothing seems to be checked, so we're going to mark this one to be skipped
+ update_post_meta( $post_id, $this->POST_SKIP . $unique_id, 1 );
+ continue;
+ }
+ } else {
+ // The checkbox for this connection is explicitly checked -- make sure we DON'T skip it
+ delete_post_meta( $post_id, $this->POST_SKIP . $unique_id );
+ }
+ }
+
+ // Users may hook in here and do anything else they need to after meta is written,
+ // and before the post is processed for Publicize.
+ do_action( 'publicize_save_meta', $submit_post, $post_id, $service_name, $connection );
+ }
+ }
+
+ if ( defined( 'DOING_CRON' ) && DOING_CRON ) {
+ wp_set_current_user( $cron_user );
+ }
+
+ // Next up will be ::publicize_post()
+ }
+}
diff --git a/plugins/jetpack/modules/publicize/ui.php b/plugins/jetpack/modules/publicize/ui.php
new file mode 100644
index 00000000..d9d2b37c
--- /dev/null
+++ b/plugins/jetpack/modules/publicize/ui.php
@@ -0,0 +1,545 @@
+<?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.
+ */
+ var $publicize;
+
+ /**
+ * Hooks into WordPress to display the various pieces of UI and load our assets
+ */
+ function __construct() {
+ global $publicize;
+
+ $this->publicize = $publicize = new Publicize;
+
+ // 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' ) );
+
+ // 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', __( 'Sharing Settings', 'jetpack' ), __( 'Sharing', 'jetpack' ), 'publish_posts', 'sharing', 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>
+ <h2><?php _e( 'Sharing Settings', 'jetpack' ); ?></h2>
+
+ <?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() {
+ wp_enqueue_script(
+ 'publicize',
+ plugins_url( 'assets/publicize.js', __FILE__ ),
+ array( 'jquery', 'thickbox' ),
+ '20121019'
+ );
+
+ wp_enqueue_style(
+ 'publicize',
+ plugins_url( 'assets/publicize.css', __FILE__ ),
+ array(),
+ '20120925'
+ );
+
+ add_thickbox();
+ }
+
+ function connected_notice( $service_name ) { ?>
+ <div class='updated'>
+ <p><?php printf( __( 'You have successfully connected your blog with your %s account.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p>
+ </div><?php
+ }
+
+ /**
+ * 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() {
+ $_blog_id = get_current_blog_id();
+ ?>
+
+ <form action="" id="publicize-form">
+ <h3 id="publicize"><?php _e( 'Publicize', 'jetpack' ) ?></h3>
+ <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.me/support/publicize/";
+ else
+ $doc_link = "http://en.support.wordpress.com/publicize/";
+ ?>
+
+ <p>&rarr; <a href="<?php echo esc_url( $doc_link ); ?>"><?php esc_html_e( 'More information on using Publicize.', 'jetpack' ); ?></a></p>
+
+ <div id="publicize-services-block">
+ <?php
+ foreach ( $this->publicize->get_services( 'all' ) as $name => $service ) :
+ $connect_url = $this->publicize->connect_url( $name );
+ ?>
+ <div class="publicize-service-entry">
+ <div id="<?php echo esc_attr( $name ); ?>" class="publicize-service-left">
+ <a href="<?php echo esc_url( $connect_url ); ?>"><span class="pub-logos" id="<?php echo esc_attr( $name ); ?>">&nbsp;</span></a>
+ </div>
+
+ <div class="publicize-service-right">
+ <?php if ( $this->publicize->is_enabled( $name ) && $connections = $this->publicize->get_connections( $name ) ) : ?>
+ <ul>
+ <?php
+ foreach( $connections as $c ) :
+ $id = $this->publicize->get_connection_id( $c );
+ $disconnect_url = $this->publicize->disconnect_url( $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 );
+
+ $options_nonce = wp_create_nonce( 'options_page_' . $name . '_' . $id ); ?>
+
+ <?php if ( $this->publicize->show_options_popup( $name, $c ) ): ?>
+ <script type="text/javascript">
+ jQuery(document).ready( function($) {
+ showOptionsPage.call(
+ this,
+ '<?php echo esc_js( $name ); ?>',
+ '<?php echo esc_js( $options_nonce ); ?>',
+ '<?php echo esc_js( $id ); ?>'
+ );
+ } );
+ </script>
+ <?php endif; ?>
+
+ <li>
+ <?php
+ if ( !empty( $profile_link ) ) : ?>
+ <a class="publicize-profile-link" href="<?php echo esc_url( $profile_link ); ?>">
+ <?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( Publicize::GLOBAL_CAP ) ) : ?>
+ <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>">×</a>
+ <?php endif; ?>
+
+ <?php else : ?>
+ <a class="pub-disconnect-button" title="<?php esc_html_e( 'Disconnect', 'jetpack' ); ?>" href="<?php echo esc_url( $disconnect_url ); ?>">×</a>
+ <?php endif; ?>
+ </li>
+
+ <?php
+ endforeach;
+ ?>
+ </ul>
+ <?php endif; ?>
+ <a id="<?php echo esc_attr( $name ); ?>" class="publicize-add-connection" href="<?php echo esc_url( $connect_url); ?>"><?php echo esc_html( sprintf( __( 'Add new %s connection.', 'jetpack' ), $this->publicize->get_service_label( $name ) ) ); ?></a>
+ </div>
+ </div>
+ <?php endforeach; ?>
+ </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
+
+ }
+
+ function global_checkbox( $service_name, $id ) {
+ 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( __( 'There was a problem connecting to %s. Please disconnect and try again.', 'jetpack' ), Publicize::get_service_label( $service_name ) ); ?></p>
+ </div>
+ </div><?php
+ }
+
+ 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;
+ ?>
+
+ <?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>
+ <?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 ) ); ?>
+
+<script type="text/javascript">
+jQuery( function($) {
+ var wpasTitleCounter = $( '#wpas-title-counter' ),
+ wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).size(),
+ wpasTitle = $('#wpas-title').keyup( function() {
+ var length = wpasTitle.val().length;
+ wpasTitleCounter.text( length );
+ if ( wpasTwitterCheckbox && length > 140 ) {
+ wpasTitleCounter.addClass( 'wpas-twitter-length-limit' );
+ } else {
+ wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' );
+ }
+ } ),
+ authClick = false;
+
+ $('#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() {
+ wpasTitle.focus();
+ if ( !wpasTitle.text() ) {
+ var url = $('#shortlink').size() ? $('#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,'') );
+
+ var selBeg = defaultMessage.indexOf( $("#title").val() );
+ if ( selBeg < 0 ) {
+ selBeg = 0;
+ selEnd = 0;
+ } else {
+ selEnd = selBeg + $("#title").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();
+ }
+ }
+ wpasTitle.keyup();
+ } );
+ $('#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 } );
+ 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 );
+ } );
+} );
+</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;
+}
+.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;
+}
+</style><?php
+ }
+
+ /**
+ * 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 ( 'post' != $post->post_type )
+ return;
+
+ $user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author;
+ $services = $this->publicize->get_services( 'connected' );
+ $available_services = $this->publicize->get_services( 'all' );
+
+ if ( ! is_array( $available_services ) )
+ $available_services = array();
+
+ if ( ! is_array( $services ) )
+ $services = array();
+
+ $active = array(); ?>
+
+ <div id="publicize" class="misc-pub-section misc-pub-section-last">
+ <?php
+ _e( 'Publicize:', 'jetpack' );
+
+ if ( 0 < count( $services ) ) :
+ 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 ) {
+ if ( !$continue = apply_filters( 'wpas_submit_post?', true, $post->ID, $name ) )
+ continue;
+
+ 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'];
+
+ // Should we be skipping this one?
+ $skip = (
+ 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"';
+
+ // 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( Publicize::GLOBAL_CAP ) ) ) {
+ $disabled = ' disabled="disabled"';
+ $hidden_checkbox = true;
+ }
+
+ // Determine the state of the checkbox (on/off) and allow filtering
+ $checked = $skip != 1 || $done;
+ $checked = apply_filters( 'publicize_checkbox_default', $checked, $post->ID, $name, $connection );
+
+ // This post has been handled, so disable everything
+ if ( $all_done )
+ $disabled = ' disabled="disabled"';
+
+ $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
+ }
+ }
+
+ 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>
+
+ <a href="#" class="hide-if-no-js" id="publicize-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a>
+ <input type="hidden" name="wpas[0]" value="1" />
+
+ </div> <?php // #publicize-form
+
+ $this->publicize->refresh_tokens_message();
+
+ $publicize_form = ob_get_clean();
+ else :
+ echo "&nbsp;" . __( 'Not Connected', 'jetpack' );
+ ob_start();
+ ?>
+
+ <div id="publicize-form" class="hide-if-js">
+ <div id="add-publicize-check" style="display: none;"></div>
+
+ <strong><?php _e( 'Connect to', 'jetpack' ); ?>:</strong>
+
+ <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 ) ) ); ?>" target="_blank" href="<?php echo $this->publicize->connect_url( $service_name ); ?>">
+ <?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?>
+ </a>
+ </li>
+ <?php endforeach; ?>
+ </ul>
+
+ <?php if ( 0 < count( $services ) ) : ?>
+ <a href="#" class="hide-if-no-js" id="publicize-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a>
+ <?php else : ?>
+ <a href="#" class="hide-if-no-js" id="publicize-disconnected-form-hide"><?php _e( 'Hide', 'jetpack' ); ?></a>
+ <?php endif; ?>
+ </div> <?php // #publicize-form
+
+ $publicize_form = ob_get_clean();
+ endif;
+ ?>
+
+ <span id="publicize-defaults"><strong><?php echo join( '</strong>, <strong>', array_map( 'esc_html', $active ) ); ?></strong></span>
+
+ <?php if ( 0 < count( $services ) ) : ?>
+ <a href="#" id="publicize-form-edit"><?php _e( 'Edit', 'jetpack' ); ?></a>&nbsp;<a href="<?php echo admin_url( 'options-general.php?page=sharing' ); ?>" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br />
+ <?php else : ?>
+ <a href="#" id="publicize-disconnected-form-show"><?php _e( 'Show', 'jetpack' ); ?></a><br />
+ <?php endif; ?>
+
+ <?php echo apply_filters( 'publicize_form', $publicize_form ); ?>
+
+ </div> <?php // #publicize
+ }
+
+}