Completed
Push — add/publicize-settings-section ( 3df66b )
by
unknown
36:46 queued 29:59
created

Publicize_UI::wrapper_admin_page()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
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
			__( 'Sharing Settings', 'jetpack' ),
56
			__( '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' ), array( 'is-wide' => true ) );
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 _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
	 * Lists the current user's publicized accounts for the blog
85
	 * looks exactly like Publicize v1 for now, UI and functionality updates will come after the move to keyring
86
	 */
87
	function admin_page() {
88
		?>
89
		<h2 id="publicize"><?php esc_html_e( 'Publicize', 'jetpack' ) ?></h2>
90
		<p><?php esc_html_e( 'Connect social media services to automatically share new posts.', 'jetpack' ) ?></p>
91
		<h4><?php
92
			printf(
93
				wp_kses(
94
					__( "We've recently made some updates to Publicize. Please visit the <a href='%s'>WordPress.com sharing page</a> to manage your publicize connections or use the button below.", 'jetpack' ),
95
					array( 'a' => array( 'href' => array() ) )
96
				),
97
				esc_url( publicize_calypso_url() )
98
			);
99
			?>
100
		</h4>
101
102
		<a href="<?php echo esc_url( publicize_calypso_url() ); ?>" class="button button-primary"><?php esc_html_e( 'Publicize Settings', 'jetpack' ); ?></a>
103
		<?php
104
	}
105
106
	/**
107
	 * CSS for styling the publicize message box and counter that displays on the post page.
108
	 * There is also some JavaScript for length counting and some basic display effects.
109
	 */
110
	function post_page_metabox_assets() {
111
		global $post;
112
		$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...
113
114
		$default_prefix = $this->publicize->default_prefix;
115
		$default_prefix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_prefix ) );
116
117
		$default_message = $this->publicize->default_message;
118
		$default_message = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_message ) );
119
120
		$default_suffix = $this->publicize->default_suffix;
121
		$default_suffix = preg_replace( '/%([0-9])\$s/', "' + %\\1\$s + '", esc_js( $default_suffix ) );
122
123
		$max_length = defined( 'JETPACK_PUBLICIZE_TWITTER_LENGTH' ) ? JETPACK_PUBLICIZE_TWITTER_LENGTH : 280;
124
		$max_length = $max_length - 24; // t.co link, space
125
126
		// for deprecation tooltip
127
		wp_enqueue_style( 'wp-pointer' );
128
		wp_enqueue_script( 'wp-pointer' );
129
130
		$this->google_plus_shut_down_tooltip_script();
131
132
		?>
133
134
<script type="text/javascript">
135
jQuery( function($) {
136
	var wpasTitleCounter    = $( '#wpas-title-counter' ),
137
		wpasTwitterCheckbox = $( '.wpas-submit-twitter' ).length,
138
		postTitle = $( '#title' ),
139
		wpasTitle = $( '#wpas-title' ).keyup( function() {
140
			var postTitleVal,
141
				length = wpasTitle.val().length;
142
143
			if ( ! length ) {
144
				length = wpasTitle.attr( 'placeholder' ).length;
145
			}
146
147
			wpasTitleCounter.text( length ).trigger( 'change' );
148
		} ),
149
		authClick = false;
150
151
	wpasTitleCounter.on( 'change', function( e ) {
152
		if ( wpasTwitterCheckbox && parseInt( $( e.currentTarget ).text(), 10 ) > <?php echo (int) $max_length; ?> ) {
153
			wpasTitleCounter.addClass( 'wpas-twitter-length-limit' );
154
		} else {
155
			wpasTitleCounter.removeClass( 'wpas-twitter-length-limit' );
156
		}
157
	} );
158
159
	// Keep the postTitle and the placeholder in sync
160
	postTitle.on( 'keyup', function( e ) {
161
		var url = $( '#sample-permalink' ).text();
162
		var defaultMessage = $.trim( '<?php printf( $default_prefix, 'url' ); printf( $default_message, 'e.currentTarget.value', 'url' ); printf( $default_suffix, 'url' ); ?>' )
163
			.replace( /<[^>]+>/g,'');
164
165
		wpasTitle.attr( 'placeholder', defaultMessage );
166
		wpasTitle.trigger( 'keyup' );
167
	} );
168
169
	// set the initial placeholder
170
	postTitle.trigger( 'keyup' );
171
172
	// If a custom message has been provided, open the UI so the author remembers
173
	if ( wpasTitle.val() && ! wpasTitle.prop( 'disabled' ) && wpasTitle.attr( 'placeholder' ) !== wpasTitle.val() ) {
174
		$( '#publicize-form' ).show();
175
		$( '#publicize-defaults' ).hide();
176
		$( '#publicize-form-edit' ).hide();
177
	}
178
179
	$('#publicize-disconnected-form-show').click( function() {
180
		$('#publicize-form').slideDown( 'fast' );
181
		$(this).hide();
182
	} );
183
184
	$('#publicize-disconnected-form-hide').click( function() {
185
		$('#publicize-form').slideUp( 'fast' );
186
		$('#publicize-disconnected-form-show').show();
187
	} );
188
189
	$('#publicize-form-edit').click( function() {
190
		$('#publicize-form').slideDown( 'fast', function() {
191
			var selBeg = 0, selEnd = 0;
192
			wpasTitle.focus();
193
194
			if ( ! wpasTitle.text() ) {
195
				wpasTitle.text( wpasTitle.attr( 'placeholder' ) );
196
197
				selBeg = wpasTitle.text().indexOf( postTitle.val() );
198
				if ( selBeg < 0 ) {
199
					selBeg = 0;
200
				} else {
201
					selEnd = selBeg + postTitle.val().length;
202
				}
203
204
				var domObj = wpasTitle.get(0);
205
				if ( domObj.setSelectionRange ) {
206
					domObj.setSelectionRange( selBeg, selEnd );
207
				} else if ( domObj.createTextRange ) {
208
					var r = domObj.createTextRange();
209
					r.moveStart( 'character', selBeg );
210
					r.moveEnd( 'character', selEnd );
211
					r.select();
212
				}
213
			}
214
		} );
215
216
		$('#publicize-defaults').hide();
217
		$(this).hide();
218
		return false;
219
	} );
220
221
	$('#publicize-form-hide').click( function() {
222
		var newList = $.map( $('#publicize-form').slideUp( 'fast' ).find( ':checked' ), function( el ) {
223
			return $.trim( $(el).parent( 'label' ).text() );
224
		} );
225
		$('#publicize-defaults').html( '<strong>' + newList.join( '</strong>, <strong>' ) + '</strong>' ).show();
226
		$('#publicize-form-edit').show();
227
		return false;
228
	} );
229
230
	$('.authorize-link').click( function() {
231
		if ( authClick ) {
232
			return false;
233
		}
234
		authClick = true;
235
		$(this).after( '<img src="images/loading.gif" class="alignleft" style="margin: 0 .5em" />' );
236
		$.ajaxSetup( { async: false } );
237
238
		if ( window.wp && window.wp.autosave ) {
239
			window.wp.autosave.server.triggerSave();
240
		} else {
241
			autosave();
242
		}
243
244
		return true;
245
	} );
246
247
	$( '.pub-service' ).click( function() {
248
		var service = $(this).data( 'service' ),
249
			fakebox = '<input id="wpas-submit-' + service + '" type="hidden" value="1" name="wpas[submit][' + service + ']" />';
250
		$( '#add-publicize-check' ).append( fakebox );
251
	} );
252
253
	publicizeConnTestStart = function() {
254
		$( '#pub-connection-tests' )
255
			.removeClass( 'below-h2' )
256
			.removeClass( 'error' )
257
			.removeClass( 'publicize-token-refresh-message' )
258
			.addClass( 'test-in-progress' )
259
			.html( '' );
260
		$.post( ajaxurl, { action: 'test_publicize_conns' }, publicizeConnTestComplete );
261
	}
262
263
	publicizeConnRefreshClick = function( event ) {
264
		event.preventDefault();
265
		var popupURL = event.currentTarget.href;
266
		var popupTitle = event.currentTarget.title;
267
		// open a popup window
268
		// when it is closed, kick off the tests again
269
		var popupWin = window.open( popupURL, popupTitle, '' );
270
		var popupWinTimer= window.setInterval( function() {
271
			if ( popupWin.closed !== false ) {
272
				window.clearInterval( popupWinTimer );
273
				publicizeConnTestStart();
274
			}
275
		}, 500 );
276
	}
277
278
	publicizeConnTestComplete = function( response ) {
279
		var testsSelector = $( '#pub-connection-tests' );
280
		testsSelector
281
			.removeClass( 'test-in-progress' )
282
			.removeClass( 'below-h2' )
283
			.removeClass( 'error' )
284
			.removeClass( 'publicize-token-refresh-message' )
285
			.html( '' );
286
287
		// If any of the tests failed, show some stuff
288
		var somethingShownAlready = false;
289
		var facebookNotice = false;
290
		$.each( response.data, function( index, testResult ) {
291
			// find the li for this connection
292
			if ( ! testResult.connectionTestPassed && testResult.userCanRefresh ) {
293
				if ( ! somethingShownAlready ) {
294
					testsSelector
295
						.addClass( 'below-h2' )
296
						.addClass( 'error' )
297
						.addClass( 'publicize-token-refresh-message' )
298
						.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>" );
299
					somethingShownAlready = true;
300
				}
301
302
				if ( testResult.userCanRefresh ) {
303
					testsSelector.append( '<p/>' );
304
					$( '<a/>', {
305
						'class'  : 'pub-refresh-button button',
306
						'title'  : testResult.refreshText,
307
						'href'   : testResult.refreshURL,
308
						'text'   : testResult.refreshText,
309
						'target' : '_refresh_' + testResult.serviceName
310
					} )
311
						.appendTo( testsSelector.children().last() )
312
						.click( publicizeConnRefreshClick );
313
				}
314
			}
315
316
			if( ! testResult.connectionTestPassed && ! testResult.userCanRefresh ) {
317
				$( '#wpas-submit-' + testResult.unique_id ).prop( "checked", false ).prop( "disabled", true );
318
				if ( ! facebookNotice ) {
319
					var message = '<p>'
320
						+ testResult.connectionTestMessage
321
						+ '</p><p>'
322
						+ ' <a class="button" href="<?php echo esc_url( $this->publicize_settings_url ); ?>" rel="noopener noreferrer" target="_blank">'
323
						+ '<?php echo esc_html( __( 'Update Your Sharing Settings' ,'jetpack' ) ); ?>'
324
						+ '</a>'
325
						+ '<p>';
326
327
					testsSelector
328
						.addClass( 'below-h2' )
329
						.addClass( 'error' )
330
						.addClass( 'publicize-token-refresh-message' )
331
						.append( message );
332
					facebookNotice = true;
333
				}
334
			}
335
		} );
336
	}
337
338
	$( document ).ready( function() {
339
		// If we have the #pub-connection-tests div present, kick off the connection test
340
		if ( $( '#pub-connection-tests' ).length ) {
341
			publicizeConnTestStart();
342
		}
343
	} );
344
345
} );
346
</script>
347
348
<style type="text/css">
349
#publicize {
350
	line-height: 1.5;
351
}
352
#publicize ul {
353
	margin: 4px 0 4px 6px;
354
}
355
#publicize li {
356
	margin: 0;
357
}
358
#publicize textarea {
359
	margin: 4px 0 0;
360
	width: 100%
361
}
362
#publicize ul.not-connected {
363
	list-style: square;
364
	padding-left: 1em;
365
}
366
.publicize__notice-warning {
367
	display: inline-block;
368
	padding: 7px 10px;
369
	margin: 5px 0;
370
	border-left-width: 4px;
371
	border-left-style: solid;
372
	font-size: 12px;
373
	box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
374
}
375
.publicize__sharing-settings {
376
	display: block;
377
	text-decoration: none;
378
	margin-top: 8px;
379
}
380
.publicize__sharing-settings:after {
381
	content: "\f504";
382
	font: normal 18px/.5em dashicons;
383
	speak: none;
384
	margin-left: 5px;
385
	vertical-align: middle;
386
}
387
#publicize-title:before {
388
	content: "\f237";
389
	font: normal 20px/1 dashicons;
390
	speak: none;
391
	margin-left: -1px;
392
	padding-right: 3px;
393
	vertical-align: top;
394
	-webkit-font-smoothing: antialiased;
395
	color: #82878c;
396
}
397
.post-new-php .authorize-link, .post-php .authorize-link {
398
	line-height: 1.5em;
399
}
400
.post-new-php .authorize-message, .post-php .authorize-message {
401
	margin-bottom: 0;
402
}
403
#poststuff #publicize .updated p {
404
	margin: .5em 0;
405
}
406
.wpas-twitter-length-limit {
407
	color: red;
408
}
409
.publicize-disabled-service-message .dashicons {
410
	font-size: 16px;
411
	text-decoration: none;
412
}
413
</style><?php
414
	}
415
416
	/**
417
	 * @param string $service_label Service's human-readable Label ("Facebook", "Twitter", ...)
418
	 * @param string $display_name Connection's human-readable Username ("@jetpack", ...)
419
	 * @return string
420
	 */
421
	private function connection_label( $service_label, $display_name ) {
422
		return sprintf(
423
			/* translators: %1$s: Service Name (Facebook, Twitter, ...), %2$s: Username on Service (@jetpack, ...) */
424
			__( '%1$s: %2$s', 'jetpack' ),
425
			$service_label,
426
			$display_name
427
		);
428
	}
429
430
	/**
431
	 * Extracts the connections that require reauthentication, for example, LinkedIn, when it switched v1 to v2 of its API.
432
	 *
433
	 * @return array Connections that must be reauthenticated
434
	 */
435
	function get_must_reauth_connections() {
436
		$must_reauth = array();
437
		$connections = $this->publicize->get_connections( 'linkedin' );
438
		if ( is_array( $connections ) ) {
439
			foreach ( $connections as $index => $connection ) {
440
				if ( $this->publicize->is_invalid_linkedin_connection( $connection ) ) {
441
					$must_reauth[ $index ] = 'LinkedIn';
442
				}
443
			}
444
		}
445
		return $must_reauth;
446
	}
447
448
	/**
449
	* Controls the metabox that is displayed on the post page
450
	* Allows the user to customize the message that will be sent out to the social network, as well as pick which
451
	* networks to publish to. Also displays the character counter and some other information.
452
	*/
453
	function post_page_metabox() {
454
		global $post;
455
456
		if ( ! $this->publicize->post_type_is_publicizeable( $post->post_type ) )
457
			return;
458
459
		$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...
460
		$connections_data = $this->publicize->get_filtered_connection_data();
461
462
		$available_services = $this->publicize->get_services( 'all' );
463
464
		if ( ! is_array( $available_services ) )
465
			$available_services = array();
466
467
		if ( ! is_array( $connections_data ) )
468
			$connections_data = array();
469
		?>
470
		<div id="publicize" class="misc-pub-section misc-pub-section-last">
471
			<span id="publicize-title">
472
			<?php
473
				esc_html_e( 'Publicize:', 'jetpack' );
474
475
				if ( 0 < count( $connections_data ) ) :
476
					$publicize_form = $this->get_metabox_form_connected( $connections_data );
477
478
					$must_reauth = $this->get_must_reauth_connections();
479
					if ( ! empty( $must_reauth ) ) {
480
						foreach ( $must_reauth as $connection_name ) {
481
							?>
482
							<span class="notice-warning publicize__notice-warning">
483
				                <?php
484
				                printf( esc_html__(
485
					                'Your %s connection needs to be reauthenticated to continue working – head to Sharing to take care of it.',
486
							'jetpack'
487
				                ), $connection_name );
488
				                ?>
489
								<a
490
										class="publicize__sharing-settings"
491
										href="<?php echo publicize_calypso_url() ?>"
492
								><?php esc_html_e( 'Go to Sharing settings', 'jetpack' ) ?></a>
493
							</span>
494
							<?php
495
						}
496
						?>
497
						<?php
498
					}
499
500
					$labels = array();
501
					$has_google_plus = false;
502
					foreach ( $connections_data as $connection_data ) {
503
						if ( ! $connection_data['enabled'] ) {
504
							continue;
505
						}
506
507
						if ( 'google_plus' === $connection_data['service_name'] ) {
508
							$has_google_plus = true;
509
						}
510
511
						$labels[] = sprintf(
512
							'<strong>%s</strong>',
513
							esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) )
514
						);
515
					}
516
517
				?>
518
					<span id="publicize-defaults"><?php echo join( ', ', $labels ); ?></span>
519
				<?php if ( $has_google_plus ) : ?>
520
					<div class="notice inline notice-warning publicize-disabled-service-message">
521
						<p>
522
							<strong><?php esc_html_e( 'Google+ support is being removed', 'jetpack' ); ?></strong>
523
							<a href="javascript:void(0)" id="jetpack-gplus-deprecated-notice">
524
								<?php esc_html_e( 'Why?', 'jetpack' ); ?>
525
								<span class="dashicons dashicons-info"></span>
526
							</a>
527
						</p>
528
					</div>
529
				<?php endif; ?>
530
					<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 />
531
				<?php
532
533
				else :
534
					$publicize_form = $this->get_metabox_form_disconnected( $available_services );
535
536
				?>
537
					<strong><?php echo __( 'Not Connected', 'jetpack' ); ?></strong>
538
					<a href="#" id="publicize-disconnected-form-show"><?php esc_html_e( 'Edit', 'jetpack' ); ?></a><br />
539
				<?php
540
541
				endif;
542
			?>
543
			</span>
544
			<?php
545
			/**
546
			 * Filter the Publicize details form.
547
			 *
548
			 * @module publicize
549
			 *
550
			 * @since 2.0.0
551
			 *
552
			 * @param string $publicize_form Publicize Details form appearing above Publish button in the editor.
553
			 */
554
			echo apply_filters( 'publicize_form', $publicize_form );
555
			?>
556
		</div> <?php // #publicize
557
	}
558
559
	/**
560
	 * Generates HTML content for connections form.
561
	 *
562
	 * @since 6.7
563
	 *
564
	 * @global WP_Post $post The current post instance being published.
565
	 *
566
	 * @param array $connections_data
567
	 *
568
	 * @return array {
569
	 *     Array of content for generating connection form.
570
	 *
571
	 *     @type string HTML content of form
572
	 *     @type array {
573
	 *     		Array of connection labels for active connections only.
574
	 *
575
	 *          @type string Connection label string.
576
	 *     }
577
	 * }
578
	 */
579
	private function get_metabox_form_connected( $connections_data ) {
580
		global $post;
581
582
		$all_done = $this->publicize->post_is_done_sharing();
583
		$all_connections_done = true;
584
585
		ob_start();
586
587
		?>
588
		<div id="publicize-form" class="hide-if-js">
589
			<ul>
590
		<?php
591
592
		foreach ( $connections_data as $connection_data ) {
593
			$all_connections_done = $all_connections_done && $connection_data['done'];
594
		?>
595
596
				<li>
597
					<label for="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>">
598
						<input
599
							type="checkbox"
600
							name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]"
601
							id="wpas-submit-<?php echo esc_attr( $connection_data['unique_id'] ); ?>"
602
							class="wpas-submit-<?php echo esc_attr( $connection_data['service_name'] ); ?>"
603
							value="1"
604
						<?php
605
							checked( true, $connection_data['enabled'] );
606
							disabled( false, $connection_data['toggleable'] );
607
						?>
608
						/>
609
					<?php if ( $connection_data['enabled'] && ! $connection_data['toggleable'] ) : // Need to submit a value to force a global connection to POST ?>
610
						<input
611
							type="hidden"
612
							name="wpas[submit][<?php echo esc_attr( $connection_data['unique_id'] ); ?>]"
613
							value="1"
614
						/>
615
					<?php endif; ?>
616
617
						<?php echo esc_html( $this->connection_label( $connection_data['service_label'], $connection_data['display_name'] ) ); ?>
618
619
					</label>
620
				</li>
621
		<?php
622
		}
623
624
		$title = get_post_meta( $post->ID, $this->publicize->POST_MESS, true );
625
		if ( ! $title ) {
626
			$title = '';
627
		}
628
629
		$all_done = $all_done || $all_connections_done;
630
631
		?>
632
633
			</ul>
634
635
			<label for="wpas-title"><?php _e( 'Custom Message:', 'jetpack' ); ?></label>
636
			<span id="wpas-title-counter" class="alignright hide-if-no-js">0</span>
637
			<textarea name="wpas_title" id="wpas-title"<?php disabled( $all_done ); ?>><?php echo esc_textarea( $title ); ?></textarea>
638
			<a href="#" class="hide-if-no-js button" id="publicize-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
639
			<input type="hidden" name="wpas[0]" value="1" />
640
		</div>
641
642
		<?php if ( ! $all_done ) : ?>
643
			<div id="pub-connection-tests"></div>
644
		<?php endif; ?>
645
		<?php // #publicize-form
646
647
		return ob_get_clean();
648
	}
649
650
	private function get_metabox_form_disconnected( $available_services ) {
651
		ob_start();
652
		?><div id="publicize-form" class="hide-if-js">
653
			<div id="add-publicize-check" style="display: none;"></div>
654
655
			<?php _e( 'Connect to', 'jetpack' ); ?>:
656
657
			<ul class="not-connected">
658
				<?php foreach ( $available_services as $service_name => $service ) : ?>
659
				<li>
660
					<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 ) ); ?>">
661
						<?php echo esc_html( $this->publicize->get_service_label( $service_name ) ); ?>
662
					</a>
663
				</li>
664
				<?php endforeach; ?>
665
			</ul>
666
			<a href="#" class="hide-if-no-js button" id="publicize-disconnected-form-hide"><?php esc_html_e( 'OK', 'jetpack' ); ?></a>
667
		</div><?php // #publicize-form
668
		return ob_get_clean();
669
	}
670
671
	private function google_plus_shut_down_notice() {
672
		return wp_kses(
673
			sprintf(
674
				/* Translators: placeholder is a link to an announcement post on Google's blog. */
675
				__(
676
					'<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>',
677
					'jetpack'
678
				),
679
				esc_url( 'https://www.blog.google/technology/safety-security/expediting-changes-google-plus/' )
680
			),
681
			array(
682
				'a'  => array(
683
					'href' => true,
684
					'target' => true,
685
				),
686
				'h3' => true,
687
				'p'  => true,
688
			)
689
		);
690
	}
691
692
	private function google_plus_shut_down_tooltip_script() {
693
		$google_plus_exp_msg = $this->google_plus_shut_down_notice();
694
	?>
695
		<script>
696
		// deprecation tooltip
697
		(function($){
698
			var setup = function() {
699
				$('#jetpack-gplus-deprecated-notice').first().pointer(
700
					{
701
						content: decodeURIComponent( "<?php echo rawurlencode( $google_plus_exp_msg ); ?>" ),
702
						position: {
703
							edge: "right",
704
							align: "bottom"
705
						},
706
						pointerClass: "wp-pointer arrow-bottom",
707
						pointerWidth: 420
708
					}
709
				).click( function( e ) {
710
					e.preventDefault();
711
					$( this ).pointer( 'open' );
712
				} );
713
			};
714
			$(document).ready( setup );
715
		})(jQuery);
716
		</script>
717
	<?php
718
	}
719
}
720