Completed
Push — fix/slideshow-dependencies ( a328c8...25d99e )
by
unknown
12:50 queued 06:11
created

Publicize_UI::global_checkbox()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
nc 2
nop 2
dl 0
loc 9
rs 9.9666
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: inline-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__sharing-settings {
384
	display: block;
385
	text-decoration: none;
386
	margin-top: 8px;
387
}
388
.publicize__sharing-settings:after {
389
	content: "\f504";
390
	font: normal 18px/.5em dashicons;
391
	speak: none;
392
	margin-left: 5px;
393
	vertical-align: middle;
394
}
395
#publicize-title:before {
396
	content: "\f237";
397
	font: normal 20px/1 dashicons;
398
	speak: none;
399
	margin-left: -1px;
400
	padding-right: 3px;
401
	vertical-align: top;
402
	-webkit-font-smoothing: antialiased;
403
	color: #82878c;
404
}
405
.post-new-php .authorize-link, .post-php .authorize-link {
406
	line-height: 1.5em;
407
}
408
.post-new-php .authorize-message, .post-php .authorize-message {
409
	margin-bottom: 0;
410
}
411
#poststuff #publicize .updated p {
412
	margin: .5em 0;
413
}
414
.wpas-twitter-length-limit {
415
	color: red;
416
}
417
.publicize-disabled-service-message .dashicons {
418
	font-size: 16px;
419
	text-decoration: none;
420
}
421
</style><?php
422
	}
423
424
	/**
425
	 * @param string $service_label Service's human-readable Label ("Facebook", "Twitter", ...)
426
	 * @param string $display_name Connection's human-readable Username ("@jetpack", ...)
427
	 * @return string
428
	 */
429
	private function connection_label( $service_label, $display_name ) {
430
		return sprintf(
431
			/* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Username on Service (@jetpack, ...) */
432
			__( '%1$s: %2$s', 'jetpack' ),
433
			$service_label,
434
			$display_name
435
		);
436
	}
437
438
	/**
439
	 * Extracts the connections that require reauthentication, for example, LinkedIn, when it switched v1 to v2 of its API.
440
	 *
441
	 * @return array Connections that must be reauthenticated
442
	 */
443
	function get_must_reauth_connections() {
444
		$must_reauth = array();
445
		$connections = $this->publicize->get_connections( 'linkedin' );
446
		if ( is_array( $connections ) ) {
447
			foreach ( $connections as $index => $connection ) {
448
				if ( $this->publicize->is_invalid_linkedin_connection( $connection ) ) {
449
					$must_reauth[ $index ] = 'LinkedIn';
450
				}
451
			}
452
		}
453
		return $must_reauth;
454
	}
455
456
	/**
457
	* Controls the metabox that is displayed on the post page
458
	* Allows the user to customize the message that will be sent out to the social network, as well as pick which
459
	* networks to publish to. Also displays the character counter and some other information.
460
	*/
461
	function post_page_metabox() {
462
		global $post;
463
464
		if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) )
465
			return;
466
467
		$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...
468
		$connections_data = $this->publicize->get_filtered_connection_data();
469
470
		$available_services = $this->publicize->get_services( 'all' );
471
472
		if ( ! is_array( $available_services ) )
473
			$available_services = array();
474
475
		if ( ! is_array( $connections_data ) )
476
			$connections_data = array();
477
		?>
478
		<div id="publicize" class="misc-pub-section misc-pub-section-last">
479
			<span id="publicize-title">
480
			<?php
481
				esc_html_e( 'Publicize:', 'jetpack' );
482
483
				if ( 0 < count( $connections_data ) ) :
484
					$publicize_form = $this->get_metabox_form_connected( $connections_data );
485
486
					$must_reauth = $this->get_must_reauth_connections();
487
					if ( ! empty( $must_reauth ) ) {
488
						foreach ( $must_reauth as $connection_name ) {
489
							?>
490
							<span class="notice-warning publicize__notice-warning">
491
				                <?php
492
				                printf( esc_html__(
493
					                'Your %s connection needs to be reauthenticated to continue working – head to Sharing to take care of it.',
494
							'jetpack'
495
				                ), $connection_name );
496
				                ?>
497
								<a
498
										class="publicize__sharing-settings"
499
										href="<?php echo publicize_calypso_url() ?>"
500
								><?php esc_html_e( 'Go to Sharing settings', 'jetpack' ) ?></a>
501
							</span>
502
							<?php
503
						}
504
						?>
505
						<?php
506
					}
507
508
					$labels = array();
509
					$has_google_plus = false;
510
					foreach ( $connections_data as $connection_data ) {
511
						if ( ! $connection_data['enabled'] ) {
512
							continue;
513
						}
514
515
						if ( 'google_plus' === $connection_data['service_name'] ) {
516
							$has_google_plus = true;
517
						}
518
519
						$labels[] = sprintf(
520
							'<strong>%s</strong>',
521
							esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) )
522
						);
523
					}
524
525
				?>
526
					<span id="publicize-defaults"><?php echo join( ', ', $labels ); ?></span>
527
				<?php if ( $has_google_plus ) : ?>
528
					<div class="notice inline notice-warning publicize-disabled-service-message">
529
						<p>
530
							<strong><?php esc_html_e( 'Google+ support is being removed', 'jetpack' ); ?></strong>
531
							<a href="javascript:void(0)" id="jetpack-gplus-deprecated-notice">
532
								<?php esc_html_e( 'Why?', 'jetpack' ); ?>
533
								<span class="dashicons dashicons-info"></span>
534
							</a>
535
						</p>
536
					</div>
537
				<?php endif; ?>
538
					<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 />
539
				<?php
540
541
				else :
542
					$publicize_form = $this->get_metabox_form_disconnected( $available_services );
543
544
				?>
545
					<strong><?php echo __( 'Not Connected', 'jetpack' ); ?></strong>
546
					<a href="#" id="publicize-disconnected-form-show"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a><br />
547
				<?php
548
549
				endif;
550
			?>
551
			</span>
552
			<?php
553
			/**
554
			 * Filter the Publicize details form.
555
			 *
556
			 * @module publicize
557
			 *
558
			 * @since 2.0.0
559
			 *
560
			 * @param string $publicize_form Publicize Details form appearing above Publish button in the editor.
561
			 */
562
			echo apply_filters( 'publicize_form', $publicize_form );
563
			?>
564
		</div> <?php // #publicize
565
	}
566
567
	/**
568
	 * Generates HTML content for connections form.
569
	 *
570
	 * @since 6.7
571
	 *
572
	 * @global WP_Post $post The current post instance being published.
573
	 *
574
	 * @param array $connections_data
575
	 *
576
	 * @return array {
577
	 *     Array of content for generating connection form.
578
	 *
579
	 *     @type string HTML content of form
580
	 *     @type array {
581
	 *     		Array of connection labels for active connections only.
582
	 *
583
	 *          @type string Connection label string.
584
	 *     }
585
	 * }
586
	 */
587
	private function get_metabox_form_connected( $connections_data ) {
588
		global $post;
589
590
		$all_done = $this->publicize->post_is_done_sharing();
591
		$all_connections_done = true;
592
593
		ob_start();
594
595
		?>
596
		<div id="publicize-form" class="hide-if-js">
597
			<ul>
598
		<?php
599
600
		foreach ( $connections_data as $connection_data ) {
601
			$all_connections_done = $all_connections_done && $connection_data['done'];
602
		?>
603
604
				<li>
605
					<label for="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>">
606
						<input
607
							type="checkbox"
608
							name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]"
609
							id="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>"
610
							class="wpas-submit-<?php echo esc_attr( $connection_data['service_name'] ); ?>"
611
							value="1"
612
						<?php
613
							checked( true, $connection_data['enabled'] );
614
							disabled( false, $connection_data['toggleable'] );
615
						?>
616
						/>
617
					<?php if ( $connection_data['enabled'] && ! $connection_data['toggleable'] ) : // Need to submit a value to force a global connection to POST ?>
618
						<input
619
							type="hidden"
620
							name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]"
621
							value="1"
622
						/>
623
					<?php endif; ?>
624
625
						<?php echo esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ); ?>
626
627
					</label>
628
				</li>
629
		<?php
630
		}
631
632
		$title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true );
633
		if ( ! $title ) {
634
			$title = '';
635
		}
636
637
		$all_done = $all_done || $all_connections_done;
638
639
		?>
640
641
			</ul>
642
643
			<label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label>
644
			<span id="wpas-title-counter" class="alignright hide-if-no-js">0</span>
645
			<textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo esc_textarea( $title ); ?></textarea>
646
			<a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
647
			<input type="hidden" name="wpas[0]" value="1" />
648
		</div>
649
650
		<?php if ( ! $all_done ) : ?>
651
			<div id="pub-connection-tests"></div>
652
		<?php endif; ?>
653
		<?php // #publicize-form
654
655
		return ob_get_clean();
656
	}
657
658
	private function get_metabox_form_disconnected( $available_services ) {
659
		ob_start();
660
		?><div id="publicize-form" class="hide-if-js">
661
			<div id="add-publicize-check" style="display: none;"></div>
662
663
			<?php _e( 'Connect to', 'jetpack' ); ?>:
664
665
			<ul class="not-connected">
666
				<?php foreach ( $available_services as $service_name => $service ) : ?>
667
				<li>
668
					<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 ) ); ?>">
669
						<?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?>
670
					</a>
671
				</li>
672
				<?php endforeach; ?>
673
			</ul>
674
			<a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
675
		</div><?php // #publicize-form
676
		return ob_get_clean();
677
	}
678
679
	private function google_plus_shut_down_notice() {
680
		return wp_kses(
681
			sprintf(
682
				/* Translators: placeholder is a link to an announcement post on Google's blog. */
683
				__(
684
					'<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>',
685
					'jetpack'
686
				),
687
				esc_url( 'https://www.blog.google/technology/safety-security/expediting-changes-google-plus/' )
688
			),
689
			array(
690
				'a'  => array(
691
					'href' => true,
692
					'target' => true,
693
				),
694
				'h3' => true,
695
				'p'  => true,
696
			)
697
		);
698
	}
699
700
	private function google_plus_shut_down_tooltip_script() {
701
		$google_plus_exp_msg = $this->google_plus_shut_down_notice();
702
	?>
703
		<script>
704
		// deprecation tooltip
705
		(function($){
706
			var setup = function() {
707
				$('#jetpack-gplus-deprecated-notice').first().pointer(
708
					{
709
						content: decodeURIComponent( "<?php echo rawurlencode( $google_plus_exp_msg ); ?>" ),
710
						position: {
711
							edge: "right",
712
							align: "bottom"
713
						},
714
						pointerClass: "wp-pointer arrow-bottom",
715
						pointerWidth: 420
716
					}
717
				).click( function( e ) {
718
					e.preventDefault();
719
					$( this ).pointer( 'open' );
720
				} );
721
			};
722
			$(document).ready( setup );
723
		})(jQuery);
724
		</script>
725
	<?php
726
	}
727
}
728