Completed
Push — branch-7.0 ( 9628b8...4d6346 )
by Jeremy
34:51 queued 27:00
created

Publicize_UI::post_page_metabox()   C

Complexity

Conditions 12
Paths 41

Size

Total Lines 105

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 12
nc 41
nop 0
dl 0
loc 105
rs 5.5733
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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