Completed
Push — add/changelog-71 ( b70f6c...ac535c )
by Jeremy
10:29
created

Publicize_UI::sharing_menu()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
* Only user facing pieces of Publicize are found here.
5
*/
6
class Publicize_UI {
7
8
	/**
9
	* Contains an instance of class 'publicize' which loads Keyring, sets up services, etc.
10
	*/
11
	public $publicize;
12
13
	/**
14
	 * @var string URL to Sharing settings page in wordpress.com
15
	 */
16
	protected $publicize_settings_url = '';
17
18
	/**
19
	* Hooks into WordPress to display the various pieces of UI and load our assets
20
	*/
21
	function __construct() {
22
		global $publicize;
23
24
		$this->publicize = $publicize = new Publicize;
25
26
		add_action( 'init', array( $this, 'init' ) );
27
	}
28
29
	function init() {
30
		$this->publicize_settings_url = publicize_calypso_url();
31
32
		// Show only to users with the capability required to manage their Publicize connections.
33
		if ( ! $this->publicize->current_user_can_access_publicize_data() ) {
34
			return;
35
		}
36
37
		// assets (css, js)
38
		if ( $this->in_jetpack ) {
0 ignored issues
show
Bug introduced by
The property in_jetpack does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
39
			add_action( 'load-settings_page_sharing', array( $this, 'load_assets' ) );
40
		}
41
		add_action( 'admin_head-post.php', array( $this, 'post_page_metabox_assets' ) );
42
		add_action( 'admin_head-post-new.php', array( $this, 'post_page_metabox_assets' ) );
43
44
		// management of publicize (sharing screen, ajax/lightbox popup, and metabox on post screen)
45
		add_action( 'pre_admin_screen_sharing', array( $this, 'admin_page' ) );
46
		add_action( 'post_submitbox_misc_actions', array( $this, 'post_page_metabox' ) );
47
	}
48
49
	/**
50
	 * If the ShareDaddy plugin is not active we need to add the sharing settings page to the menu still
51
	 */
52
	function sharing_menu() {
53
		add_submenu_page(
54
			'options-general.php',
55
			esc_html__( 'Sharing Settings', 'jetpack' ),
56
			esc_html__( 'Sharing', 'jetpack' ),
57
			'publish_posts',
58
			'sharing',
59
			array( $this, 'wrapper_admin_page' )
60
		);
61
	}
62
63
	function wrapper_admin_page() {
64
		Jetpack_Admin_Page::wrap_ui( array( $this, 'management_page' ) );
65
	}
66
67
	/**
68
	 * Management page to load if Sharedaddy is not active so the 'pre_admin_screen_sharing' action exists.
69
	 */
70
	function management_page() { ?>
71
		<div class="wrap">
72
			<div class="icon32" id="icon-options-general"><br /></div>
73
			<h1><?php esc_html_e( 'Sharing Settings', 'jetpack' ); ?></h1>
74
75
			<?php
76
			/** This action is documented in modules/sharedaddy/sharing.php */
77
			do_action( 'pre_admin_screen_sharing' );
78
			?>
79
80
		</div> <?php
81
	}
82
83
	/**
84
	 * styling for the sharing screen and popups
85
	 * JS for the options and switching
86
	 */
87
	function load_assets() {
88
		Jetpack_Admin_Page::load_wrapper_styles();
89
	}
90
91
	/**
92
	 * Lists the current user's publicized accounts for the blog
93
	 * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring
94
	 */
95
	function admin_page() {
96
		?>
97
		<h2 id="publicize"><?php esc_html_e( 'Publicize', 'jetpack' ) ?></h2>
98
		<p><?php esc_html_e( 'Connect social media services to automatically share new posts.', 'jetpack' ) ?></p>
99
		<h4><?php
100
			printf(
101
				wp_kses(
102
					__( "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' ),
103
					array( 'a' => array( 'href' => array(), 'class' => array(), 'data-jptracks-name' => array() ) )
104
				),
105
				esc_url( publicize_calypso_url() )
106
			);
107
			?>
108
		</h4>
109
110
		<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>
111
		<?php
112
	}
113
114
	/**
115
	 * CSS for styling the publicize message box and counter that displays on the post page.
116
	 * There is also some JavaScript for length counting and some basic display effects.
117
	 */
118
	function post_page_metabox_assets() {
119
		global $post;
120
		$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author;
0 ignored issues
show
Unused Code introduced by
$user_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
121
122
		$default_prefix = $this->publicize->default_prefix;
123
		$default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) );
124
125
		$default_message = $this->publicize->default_message;
126
		$default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) );
127
128
		$default_suffix = $this->publicize->default_suffix;
129
		$default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) );
130
131
		$max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280;
132
		$max_length = $max_length - 24; // t.co link, space
133
134
		// for deprecation tooltip
135
		wp_enqueue_style( 'wp-pointer' );
136
		wp_enqueue_script( 'wp-pointer' );
137
138
		$this->google_plus_shut_down_tooltip_script();
139
140
		?>
141
142
<script type="text/javascript">
143
jQuery( function($) {
144
	var wpasTitleCounter    = $( '#wpas-title-counter' ),
145
		wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).length,
146
		postTitle = $( '#title' ),
147
		wpasTitle = $( '#wpas-title' ).keyup( function() {
148
			var postTitleVal,
149
				length = wpasTitle.val().length;
150
151
			if ( ! length ) {
152
				length = wpasTitle.attr( 'placeholder' ).length;
153
			}
154
155
			wpasTitleCounter.text( length ).trigger( 'change' );
156
		} ),
157
		authClick = false;
158
159
	wpasTitleCounter.on( 'change', function( e ) {
160
		if ( wpasTwitterCheckbox && parseInt( $( e.currentTarget ).text(), 10 ) > <?php echo (int) $max_length; ?> ) {
161
			wpasTitleCounter.addClass( 'wpas-twitter-length-limit' );
162
		} else {
163
			wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' );
164
		}
165
	} );
166
167
	// Keep the postTitle and the placeholder in sync
168
	postTitle.on( 'keyup', function( e ) {
169
		var url = $( '#sample-permalink' ).text();
170
		var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, 'e.currentTarget.value', 'url' ); printf( $default_suffix, 'url' ); ?>' )
171
			.replace( /<[^>]+>/g,'');
172
173
		wpasTitle.attr( 'placeholder', defaultMessage );
174
		wpasTitle.trigger( 'keyup' );
175
	} );
176
177
	// set the initial placeholder
178
	postTitle.trigger( 'keyup' );
179
180
	// If a custom message has been provided, open the UI so the author remembers
181
	if ( wpasTitle.val() && ! wpasTitle.prop( 'disabled' ) && wpasTitle.attr( 'placeholder' ) !== wpasTitle.val() ) {
182
		$( '#publicize-form' ).show();
183
		$( '#publicize-defaults' ).hide();
184
		$( '#publicize-form-edit' ).hide();
185
	}
186
187
	$('#publicize-disconnected-form-show').click( function() {
188
		$('#publicize-form').slideDown( 'fast' );
189
		$(this).hide();
190
	} );
191
192
	$('#publicize-disconnected-form-hide').click( function() {
193
		$('#publicize-form').slideUp( 'fast' );
194
		$('#publicize-disconnected-form-show').show();
195
	} );
196
197
	$('#publicize-form-edit').click( function() {
198
		$('#publicize-form').slideDown( 'fast', function() {
199
			var selBeg = 0, selEnd = 0;
200
			wpasTitle.focus();
201
202
			if ( ! wpasTitle.text() ) {
203
				wpasTitle.text( wpasTitle.attr( 'placeholder' ) );
204
205
				selBeg = wpasTitle.text().indexOf( postTitle.val() );
206
				if ( selBeg < 0 ) {
207
					selBeg = 0;
208
				} else {
209
					selEnd = selBeg + postTitle.val().length;
210
				}
211
212
				var domObj = wpasTitle.get(0);
213
				if ( domObj.setSelectionRange ) {
214
					domObj.setSelectionRange( selBeg, selEnd );
215
				} else if ( domObj.createTextRange ) {
216
					var r = domObj.createTextRange();
217
					r.moveStart( 'character', selBeg );
218
					r.moveEnd( 'character', selEnd );
219
					r.select();
220
				}
221
			}
222
		} );
223
224
		$('#publicize-defaults').hide();
225
		$(this).hide();
226
		return false;
227
	} );
228
229
	$('#publicize-form-hide').click( function() {
230
		var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) {
231
			return $.trim( $(el).parent( 'label' ).text() );
232
		} );
233
		$('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show();
234
		$('#publicize-form-edit').show();
235
		return false;
236
	} );
237
238
	$('.authorize-link').click( function() {
239
		if ( authClick ) {
240
			return false;
241
		}
242
		authClick = true;
243
		$(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' );
244
		$.ajaxSetup( { async: false } );
245
246
		if ( window.wp && window.wp.autosave ) {
247
			window.wp.autosave.server.triggerSave();
248
		} else {
249
			autosave();
250
		}
251
252
		return true;
253
	} );
254
255
	$( '.pub-service' ).click( function() {
256
		var service = $(this).data( 'service' ),
257
			fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />';
258
		$( '#add-publicize-check' ).append( fakebox );
259
	} );
260
261
	publicizeConnTestStart = function() {
262
		$( '#pub-connection-tests' )
263
			.removeClass( 'below-h2' )
264
			.removeClass( 'error' )
265
			.removeClass( 'publicize-token-refresh-message' )
266
			.addClass( 'test-in-progress' )
267
			.html( '' );
268
		$.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete );
269
	}
270
271
	publicizeConnRefreshClick = function( event ) {
272
		event.preventDefault();
273
		var popupURL = event.currentTarget.href;
274
		var popupTitle = event.currentTarget.title;
275
		// open a popup window
276
		// when it is closed, kick off the tests again
277
		var popupWin = window.open( popupURL, popupTitle, '' );
278
		var popupWinTimer= window.setInterval( function() {
279
			if ( popupWin.closed !== false ) {
280
				window.clearInterval( popupWinTimer );
281
				publicizeConnTestStart();
282
			}
283
		}, 500 );
284
	}
285
286
	publicizeConnTestComplete = function( response ) {
287
		var testsSelector = $( '#pub-connection-tests' );
288
		testsSelector
289
			.removeClass( 'test-in-progress' )
290
			.removeClass( 'below-h2' )
291
			.removeClass( 'error' )
292
			.removeClass( 'publicize-token-refresh-message' )
293
			.html( '' );
294
295
		// If any of the tests failed, show some stuff
296
		var somethingShownAlready = false;
297
		var facebookNotice = false;
298
		$.each( response.data, function( index, testResult ) {
299
			// find the li for this connection
300
			if ( ! testResult.connectionTestPassed && testResult.userCanRefresh ) {
301
				if ( ! somethingShownAlready ) {
302
					testsSelector
303
						.addClass( 'below-h2' )
304
						.addClass( 'error' )
305
						.addClass( 'publicize-token-refresh-message' )
306
						.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>" );
307
					somethingShownAlready = true;
308
				}
309
310
				if ( testResult.userCanRefresh ) {
311
					testsSelector.append( '<p/>' );
312
					$( '<a/>', {
313
						'class'  : 'pub-refresh-button button',
314
						'title'  : testResult.refreshText,
315
						'href'   : testResult.refreshURL,
316
						'text'   : testResult.refreshText,
317
						'target' : '_refresh_' + testResult.serviceName
318
					} )
319
						.appendTo( testsSelector.children().last() )
320
						.click( publicizeConnRefreshClick );
321
				}
322
			}
323
324
			if( ! testResult.connectionTestPassed && ! testResult.userCanRefresh ) {
325
				$( '#wpas-submit-' + testResult.unique_id ).prop( "checked", false ).prop( "disabled", true );
326
				if ( ! facebookNotice ) {
327
					var message = '<p>'
328
						+ testResult.connectionTestMessage
329
						+ '</p><p>'
330
						+ ' <a class="button" href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank">'
331
						+ '<?php echo esc_html( __( 'Update Your Sharing Settings' ,'jetpack' ) ); ?>'
332
						+ '</a>'
333
						+ '<p>';
334
335
					testsSelector
336
						.addClass( 'below-h2' )
337
						.addClass( 'error' )
338
						.addClass( 'publicize-token-refresh-message' )
339
						.append( message );
340
					facebookNotice = true;
341
				}
342
			}
343
		} );
344
	}
345
346
	$( document ).ready( function() {
347
		// If we have the #pub-connection-tests div present, kick off the connection test
348
		if ( $( '#pub-connection-tests' ).length ) {
349
			publicizeConnTestStart();
350
		}
351
	} );
352
353
} );
354
</script>
355
356
<style type="text/css">
357
#publicize {
358
	line-height: 1.5;
359
}
360
#publicize ul {
361
	margin: 4px 0 4px 6px;
362
}
363
#publicize li {
364
	margin: 0;
365
}
366
#publicize textarea {
367
	margin: 4px 0 0;
368
	width: 100%
369
}
370
#publicize ul.not-connected {
371
	list-style: square;
372
	padding-left: 1em;
373
}
374
.publicize__notice-warning {
375
	display: block;
376
	padding: 7px 10px;
377
	margin: 5px 0;
378
	border-left-width: 4px;
379
	border-left-style: solid;
380
	font-size: 12px;
381
	box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
382
}
383
.publicize-external-link {
384
	display: block;
385
	text-decoration: none;
386
	margin-top: 8px;
387
}
388
.publicize-external-link__text {
389
	text-decoration: underline;
390
}
391
#publicize-title:before {
392
	content: "\f237";
393
	font: normal 20px/1 dashicons;
394
	speak: none;
395
	margin-left: -1px;
396
	padding-right: 3px;
397
	vertical-align: top;
398
	-webkit-font-smoothing: antialiased;
399
	color: #82878c;
400
}
401
.post-new-php .authorize-link, .post-php .authorize-link {
402
	line-height: 1.5em;
403
}
404
.post-new-php .authorize-message, .post-php .authorize-message {
405
	margin-bottom: 0;
406
}
407
#poststuff #publicize .updated p {
408
	margin: .5em 0;
409
}
410
.wpas-twitter-length-limit {
411
	color: red;
412
}
413
.publicize__notice-warning .dashicons {
414
	font-size: 16px;
415
	text-decoration: none;
416
}
417
</style><?php
418
	}
419
420
	/**
421
	 * @param string $service_label Service's human-readable Label ("Facebook", "Twitter", ...)
422
	 * @param string $display_name Connection's human-readable Username ("@jetpack", ...)
423
	 * @return string
424
	 */
425
	private function connection_label( $service_label, $display_name ) {
426
		return sprintf(
427
			/* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Username on Service (@jetpack, ...) */
428
			__( '%1$s: %2$s', 'jetpack' ),
429
			$service_label,
430
			$display_name
431
		);
432
	}
433
434
	/**
435
	 * Extracts the connections that require reauthentication, for example, LinkedIn, when it switched v1 to v2 of its API.
436
	 *
437
	 * @return array Connections that must be reauthenticated
438
	 */
439
	function get_must_reauth_connections() {
440
		$must_reauth = array();
441
		$connections = $this->publicize->get_connections( 'linkedin' );
442
		if ( is_array( $connections ) ) {
443
			foreach ( $connections as $index => $connection ) {
444
				if ( $this->publicize->is_invalid_linkedin_connection( $connection ) ) {
445
					$must_reauth[ $index ] = 'LinkedIn';
446
				}
447
			}
448
		}
449
		return $must_reauth;
450
	}
451
452
	/**
453
	* Controls the metabox that is displayed on the post page
454
	* Allows the user to customize the message that will be sent out to the social network, as well as pick which
455
	* networks to publish to. Also displays the character counter and some other information.
456
	*/
457
	function post_page_metabox() {
458
		global $post;
459
460
		if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) )
461
			return;
462
463
		$user_id = empty( $post->post_author ) ? $GLOBALS['user_ID'] : $post->post_author;
0 ignored issues
show
Unused Code introduced by
$user_id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
464
		$connections_data = $this->publicize->get_filtered_connection_data();
465
466
		$available_services = $this->publicize->get_services( 'all' );
467
468
		if ( ! is_array( $available_services ) )
469
			$available_services = array();
470
471
		if ( ! is_array( $connections_data ) )
472
			$connections_data = array();
473
		?>
474
		<div id="publicize" class="misc-pub-section misc-pub-section-last">
475
			<span id="publicize-title">
476
			<?php
477
				esc_html_e( 'Publicize:', 'jetpack' );
478
479
				if ( 0 < count( $connections_data ) ) :
480
					$publicize_form = $this->get_metabox_form_connected( $connections_data );
481
482
					$must_reauth = $this->get_must_reauth_connections();
483
					if ( ! empty( $must_reauth ) ) {
484
						foreach ( $must_reauth as $connection_name ) {
485
							?>
486
							<span class="notice-warning publicize__notice-warning">
487
								<?php
488
									/* translators: %s is the name of a Pubilicize service like "LinkedIn" */
489
									printf( esc_html__(
490
										'Your %s connection needs to be reauthenticated to continue working – head to Sharing to take care of it.',
491
										'jetpack'
492
									), $connection_name );
493
								?>
494
								<a
495
									class="publicize-external-link"
496
									href="<?php echo publicize_calypso_url() ?>"
497
									target="_blank"
498
								>
499
									<span class="publicize-external-link__text"><?php esc_html_e( 'Go to Sharing settings', 'jetpack' ); ?></span>
500
									<span class="dashicons dashicons-external"></span>
501
								</a>
502
							</span>
503
							<?php
504
						}
505
						?>
506
						<?php
507
					}
508
509
					$labels = array();
510
					$has_google_plus = false;
511
					foreach ( $connections_data as $connection_data ) {
512
						if ( ! $connection_data['enabled'] ) {
513
							continue;
514
						}
515
516
						if ( 'google_plus' === $connection_data['service_name'] ) {
517
							$has_google_plus = true;
518
						}
519
520
						$labels[] = sprintf(
521
							'<strong>%s</strong>',
522
							esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) )
523
						);
524
					}
525
526
				?>
527
				<?php if ( $has_google_plus ) : ?>
528
					<span class="notice-warning publicize__notice-warning">
529
						<?php esc_html_e( 'Google+ support is being removed', 'jetpack' ); ?>
530
						<a
531
							href="javascript:void(0)"
532
							id="jetpack-gplus-deprecated-notice"
533
							class="publicize-external-link"
534
						>
535
							<span class="publicize-external-link__text"><?php esc_html_e( 'Why?', 'jetpack' ); ?></span>
536
							<span class="dashicons dashicons-info"></span>
537
						</a>
538
					</span>
539
				<?php endif; ?>
540
					<span id="publicize-defaults"><?php echo join( ', ', $labels ); ?></span>
541
					<a href="#" id="publicize-form-edit"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a>&nbsp;<a href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank"><?php _e( 'Settings', 'jetpack' ); ?></a><br />
542
				<?php
543
544
				else :
545
					$publicize_form = $this->get_metabox_form_disconnected( $available_services );
546
547
				?>
548
					<strong><?php echo __( 'Not Connected', 'jetpack' ); ?></strong>
549
					<a href="#" id="publicize-disconnected-form-show"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a><br />
550
				<?php
551
552
				endif;
553
			?>
554
			</span>
555
			<?php
556
			/**
557
			 * Filter the Publicize details form.
558
			 *
559
			 * @module publicize
560
			 *
561
			 * @since 2.0.0
562
			 *
563
			 * @param string $publicize_form Publicize Details form appearing above Publish button in the editor.
564
			 */
565
			echo apply_filters( 'publicize_form', $publicize_form );
566
			?>
567
		</div> <?php // #publicize
568
	}
569
570
	/**
571
	 * Generates HTML content for connections form.
572
	 *
573
	 * @since 6.7
574
	 *
575
	 * @global WP_Post $post The current post instance being published.
576
	 *
577
	 * @param array $connections_data
578
	 *
579
	 * @return array {
580
	 *     Array of content for generating connection form.
581
	 *
582
	 *     @type string HTML content of form
583
	 *     @type array {
584
	 *     		Array of connection labels for active connections only.
585
	 *
586
	 *          @type string Connection label string.
587
	 *     }
588
	 * }
589
	 */
590
	private function get_metabox_form_connected( $connections_data ) {
591
		global $post;
592
593
		$all_done = $this->publicize->post_is_done_sharing();
594
		$all_connections_done = true;
595
596
		ob_start();
597
598
		?>
599
		<div id="publicize-form" class="hide-if-js">
600
			<ul>
601
		<?php
602
603
		foreach ( $connections_data as $connection_data ) {
604
			$all_connections_done = $all_connections_done && $connection_data['done'];
605
		?>
606
607
				<li>
608
					<label for="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>">
609
						<input
610
							type="checkbox"
611
							name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]"
612
							id="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>"
613
							class="wpas-submit-<?php echo esc_attr( $connection_data['service_name'] ); ?>"
614
							value="1"
615
						<?php
616
							checked( true, $connection_data['enabled'] );
617
							disabled( false, $connection_data['toggleable'] );
618
						?>
619
						/>
620
					<?php if ( $connection_data['enabled'] && ! $connection_data['toggleable'] ) : // Need to submit a value to force a global connection to POST ?>
621
						<input
622
							type="hidden"
623
							name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]"
624
							value="1"
625
						/>
626
					<?php endif; ?>
627
628
						<?php echo esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ); ?>
629
630
					</label>
631
				</li>
632
		<?php
633
		}
634
635
		$title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true );
636
		if ( ! $title ) {
637
			$title = '';
638
		}
639
640
		$all_done = $all_done || $all_connections_done;
641
642
		?>
643
644
			</ul>
645
646
			<label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label>
647
			<span id="wpas-title-counter" class="alignright hide-if-no-js">0</span>
648
			<textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo esc_textarea( $title ); ?></textarea>
649
			<a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
650
			<input type="hidden" name="wpas[0]" value="1" />
651
		</div>
652
653
		<?php if ( ! $all_done ) : ?>
654
			<div id="pub-connection-tests"></div>
655
		<?php endif; ?>
656
		<?php // #publicize-form
657
658
		return ob_get_clean();
659
	}
660
661
	private function get_metabox_form_disconnected( $available_services ) {
662
		ob_start();
663
		?><div id="publicize-form" class="hide-if-js">
664
			<div id="add-publicize-check" style="display: none;"></div>
665
666
			<?php _e( 'Connect to', 'jetpack' ); ?>:
667
668
			<ul class="not-connected">
669
				<?php foreach ( $available_services as $service_name => $service ) : ?>
670
				<li>
671
					<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 ) ); ?>">
672
						<?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?>
673
					</a>
674
				</li>
675
				<?php endforeach; ?>
676
			</ul>
677
			<a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
678
		</div><?php // #publicize-form
679
		return ob_get_clean();
680
	}
681
682
	private function google_plus_shut_down_notice() {
683
		return wp_kses(
684
			sprintf(
685
				/* Translators: placeholder is a link to an announcement post on Google's blog. */
686
				__(
687
					'<h3>Google+ Support is being removed</h3><p>Google recently <a href="%1$s" target="_blank">announced</a> that Google+ is shutting down in April 2019, and access via third-party tools like Jetpack will cease in March 2019.</p><p>For now, you can still post to Google+ using existing connections, but you cannot add new connections. The ability to post will be removed in early 2019.</p>',
688
					'jetpack'
689
				),
690
				esc_url( 'https://www.blog.google/technology/safety-security/expediting-changes-google-plus/' )
691
			),
692
			array(
693
				'a'  => array(
694
					'href' => true,
695
					'target' => true,
696
				),
697
				'h3' => true,
698
				'p'  => true,
699
			)
700
		);
701
	}
702
703
	private function google_plus_shut_down_tooltip_script() {
704
		$google_plus_exp_msg = $this->google_plus_shut_down_notice();
705
	?>
706
		<script>
707
		// deprecation tooltip
708
		(function($){
709
			var setup = function() {
710
				$('#jetpack-gplus-deprecated-notice').first().pointer(
711
					{
712
						content: decodeURIComponent( "<?php echo rawurlencode( $google_plus_exp_msg ); ?>" ),
713
						position: {
714
							edge: "right",
715
							align: "bottom"
716
						},
717
						pointerClass: "wp-pointer arrow-bottom",
718
						pointerWidth: 420
719
					}
720
				).click( function( e ) {
721
					e.preventDefault();
722
					$( this ).pointer( 'open' );
723
				} );
724
			};
725
			$(document).ready( setup );
726
		})(jQuery);
727
		</script>
728
	<?php
729
	}
730
}
731