Completed
Push — update/configure-url-to-jetpac... ( b7ff27...e36779 )
by
unknown
06:43
created

Jetpack_Likes::jetpack_likes_configuration_url()   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
 * Module Name: Likes
4
 * Module Description: Give visitors an easy way to show they appreciate your content.
5
 * First Introduced: 2.2
6
 * Sort Order: 23
7
 * Requires Connection: Yes
8
 * Auto Activate: No
9
 * Module Tags: Social
10
 * Feature: Engagement
11
 * Additional Search Queries: like, likes, wordpress.com
12
 */
13
14
Jetpack::dns_prefetch( array(
15
	'//widgets.wp.com',
16
	'//s0.wp.com',
17
	'//0.gravatar.com',
18
	'//1.gravatar.com',
19
	'//2.gravatar.com',
20
) );
21
22
include_once dirname( __FILE__ ) . '/likes/jetpack-likes-master-iframe.php';
23
include_once dirname( __FILE__ ) . '/likes/jetpack-likes-settings.php';
24
25
class Jetpack_Likes {
26
	public static function init() {
27
		static $instance = NULL;
28
29
		if ( ! $instance ) {
30
			$instance = new Jetpack_Likes;
31
		}
32
33
		return $instance;
34
	}
35
36
	function __construct() {
37
		$this->in_jetpack = ( defined( 'IS_WPCOM' ) && IS_WPCOM ) ? false : true;
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...
38
		$this->settings = new Jetpack_Likes_Settings();
0 ignored issues
show
Bug introduced by
The property settings 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
40
		add_action( 'init', array( &$this, 'action_init' ) );
41
		add_action( 'admin_init', array( $this, 'admin_init' ) );
42
43
		if ( $this->in_jetpack ) {
44
			add_action( 'jetpack_activate_module_likes',   array( $this, 'set_social_notifications_like' ) );
45
			add_action( 'jetpack_deactivate_module_likes', array( $this, 'delete_social_notifications_like' ) );
46
47
			Jetpack::enable_module_configurable( __FILE__ );
48
			Jetpack::module_configuration_load( __FILE__, array( $this, 'configuration_redirect' ) );
49
			add_filter( 'jetpack_module_configuration_url_likes', array( $this, 'jetpack_likes_configuration_url' ) );
50
51
			add_action( 'admin_print_scripts-settings_page_sharing', array( &$this, 'load_jp_css' ) );
52
			add_filter( 'sharing_show_buttons_on_row_start', array( $this, 'configuration_target_area' ) );
53
54
			$active = Jetpack::get_active_modules();
55
56 View Code Duplication
			if ( ! in_array( 'sharedaddy', $active ) && ! in_array( 'publicize', $active ) ) {
57
				// we don't have a sharing page yet
58
				add_action( 'admin_menu', array( $this->settings, 'sharing_menu' ) );
59
			}
60
61 View Code Duplication
			if ( in_array( 'publicize', $active ) && ! in_array( 'sharedaddy', $active ) ) {
62
				// we have a sharing page but not the global options area
63
				add_action( 'pre_admin_screen_sharing', array( $this->settings, 'sharing_block' ), 20 );
64
				add_action( 'pre_admin_screen_sharing', array( $this->settings, 'updated_message' ), -10 );
65
			}
66
67 View Code Duplication
			if( ! in_array( 'sharedaddy', $active ) ) {
68
				add_action( 'admin_init', array( $this->settings, 'process_update_requests_if_sharedaddy_not_loaded' ) );
69
				add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_showbuttonon_init' ), 19 );
70
				add_action( 'sharing_admin_update', array( $this->settings, 'admin_settings_showbuttonon_callback' ), 19 );
71
				add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
72
			} else {
73
				add_filter( 'sharing_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
74
				add_action( 'start_sharing_meta_box_content', array( $this->settings, 'meta_box_content' ) );
75
			}
76
		} else { // wpcom
77
			add_action( 'wpmu_new_blog', array( $this, 'enable_comment_likes' ), 10, 1 );
78
			add_action( 'admin_init', array( $this->settings, 'add_meta_box' ) );
79
			add_action( 'end_likes_meta_box_content', array( $this->settings, 'sharing_meta_box_content' ) );
80
			add_filter( 'likes_meta_box_title', array( $this->settings, 'add_likes_to_sharing_meta_box_title' ) );
81
		}
82
83
		add_action( 'admin_init', array( $this, 'admin_discussion_likes_settings_init' ) ); // Likes notifications
84
85
		add_action( 'admin_bar_menu', array( $this, 'admin_bar_likes' ), 60 );
86
87
		add_action( 'wp_enqueue_scripts', array( $this, 'load_styles_register_scripts' ) );
88
89
		add_action( 'save_post', array( $this->settings, 'meta_box_save' ) );
90
		add_action( 'edit_attachment', array( $this->settings, 'meta_box_save' ) );
91
		add_action( 'sharing_global_options', array( $this->settings, 'admin_settings_init' ), 20 );
92
		add_action( 'sharing_admin_update',   array( $this->settings, 'admin_settings_callback' ), 20 );
93
	}
94
95
	/**
96
	 * Set the social_notifications_like option to `on` when the Likes module is activated.
97
	 *
98
	 * @since 3.7.0
99
	 *
100
	 * @return null
101
	 */
102
	function set_social_notifications_like() {
103
		update_option( 'social_notifications_like', 'on' );
104
	}
105
106
	/**
107
	 * Delete the social_notifications_like option that was set to `on` on module activation.
108
	 *
109
	 * @since 3.7.0
110
	 *
111
	 * @return null
112
	 */
113
	function delete_social_notifications_like() {
114
		delete_option( 'social_notifications_like' );
115
	}
116
117
	/**
118
	 * Redirects to the likes section of the sharing page.
119
	 */
120
	function configuration_redirect() {
121
		wp_safe_redirect( admin_url( 'options-general.php?page=sharing#likes' ) );
122
		die();
123
	}
124
125
	/**
126
	 * Overrides default configuration url
127
	 *
128
	 * @uses admin_url
129
	 * @return string module settings URL
130
	 */
131
	function jetpack_likes_configuration_url() {
132
		return admin_url( 'options-general.php?page=sharing#likes' );
133
	}
134
135
	/**
136
	 * Loads Jetpack's CSS on the sharing page so we can use .jetpack-targetable
137
	 */
138
	function load_jp_css() {
139
		// Do we really need `admin_styles`? With the new admin UI, it's breaking some bits.
140
		// Jetpack::init()->admin_styles();
141
	}
142
143
	/**
144
	 * Load scripts and styles for front end.
145
	 * @return null
146
	 */
147
	function load_styles_register_scripts() {
148
		if ( $this->in_jetpack ) {
149
			wp_enqueue_style( 'jetpack_likes', plugins_url( 'likes/style.css', __FILE__ ), array(), JETPACK__VERSION );
150
			$this->register_scripts();
151
		}
152
	}
153
154
155
	/**
156
     * Stub for is_post_likeable, since some wpcom functions call this directly on the class
157
	 * Are likes enabled for this post?
158
     *
159
     * @param int $post_id
160
     * @return bool
161
	 */
162
	static function is_post_likeable( $post_id = 0 ) {
163
		_deprecated_function( __METHOD__, 'jetpack-5.4', 'Jetpack_Likes_Settings()->is_post_likeable' );
164
		$settings = new Jetpack_Likes_Settings();
165
		return $settings->is_post_likeable();
166
	}
167
168
	/**
169
	 * Stub for is_likes_visible, since some themes were calling it directly from this class
170
	 *
171
	 * @deprecated 5.4
172
	 * @return bool
173
	 */
174
	function is_likes_visible() {
175
		_deprecated_function( __METHOD__, 'jetpack-5.4', 'Jetpack_Likes_Settings()->is_likes_visible' );
176
177
		$settings = new Jetpack_Likes_Settings();
178
		return $settings->is_likes_visible();
179
	}
180
181
	/**
182
	 * Adds in the jetpack-targetable class so when we visit sharing#likes our like settings get highlighted by a yellow box
183
	 * @param  string $html row heading for the sharedaddy "which page" setting
184
	 * @return string       html with the jetpack-targetable class and likes id. tbody gets closed after the like settings
185
	 */
186
	function configuration_target_area( $html = '' ) {
187
		$html = "<tbody id='likes' class='jetpack-targetable'>" . $html;
188
		return $html;
189
	}
190
191
	/**
192
	  * Options to be added to the discussion page (see also admin_settings_init, etc below for Sharing settings page)
193
	  */
194
195 View Code Duplication
	function admin_discussion_likes_settings_init() {
196
		// Add a temporary section, until we can move the setting out of there and with the rest of the email notification settings
197
		add_settings_section( 'likes-notifications', __( 'Likes Notifications', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_section' ), 'discussion' );
198
		add_settings_field( 'social-notifications', __( 'Email me whenever', 'jetpack' ), array( $this, 'admin_discussion_likes_settings_field' ), 'discussion', 'likes-notifications' );
199
		// Register the setting
200
		register_setting( 'discussion', 'social_notifications_like', array( $this, 'admin_discussion_likes_settings_validate' ) );
201
	}
202
203
	function admin_discussion_likes_settings_section() {
204
		// Atypical usage here.  We emit jquery to move likes notification checkbox to be with the rest of the email notification settings
205
?>
206
	<script type="text/javascript">
207
	jQuery( function( $ )  {
208
		var table = $( '#social_notifications_like' ).parents( 'table:first' ),
209
			header = table.prevAll( 'h2:first' ),
210
			newParent = $( '#moderation_notify' ).parent( 'label' ).parent();
211
212
		if ( !table.length || !header.length || !newParent.length ) {
213
			return;
214
		}
215
216
		newParent.append( '<br/>' ).append( table.end().parent( 'label' ).siblings().andSelf() );
217
		header.remove();
218
		table.remove();
219
	} );
220
	</script>
221
<?php
222
	}
223
224
	function admin_likes_get_option( $option ) {
225
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
226
			$option_setting = get_blog_option( get_current_blog_id(), $option, 'on' );
227
		} else {
228
			$option_setting = get_option( $option, 'on' );
229
		}
230
231
		return intval( 'on' == $option_setting );
232
	}
233
234
	function admin_discussion_likes_settings_field() {
235
		$like = $this->admin_likes_get_option( 'social_notifications_like' );
236
?>
237
		<label><input type="checkbox" id="social_notifications_like" name="social_notifications_like" value="1" <?php checked( $like ); ?> /> <?php esc_html_e( 'Someone likes one of my posts', 'jetpack' ); ?></label>
238
<?php
239
	}
240
241
	function admin_discussion_likes_settings_validate( $input ) {
242
		// If it's not set (was unchecked during form submission) or was set to off (during option update), return 'off'.
243
		if ( !$input || 'off' == $input )
244
			return 'off';
245
246
		// Otherwise, return 'on'.
247
		return 'on';
248
	}
249
250
	function admin_init() {
251
		add_filter( 'manage_posts_columns', array( $this, 'add_like_count_column' ) );
252
		add_filter( 'manage_pages_columns', array( $this, 'add_like_count_column' ) );
253
		add_action( 'manage_posts_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
254
		add_action( 'manage_pages_custom_column', array( $this, 'likes_edit_column' ), 10, 2 );
255
		add_action( 'admin_print_styles-edit.php', array( $this, 'load_admin_css' ) );
256
		add_action( "admin_print_scripts-edit.php", array( $this, 'enqueue_admin_scripts' ) );
257
	}
258
259
	function action_init() {
260
		if ( is_admin() ) {
261
			return;
262
		}
263
264
		if ( ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) ||
265
			 ( defined( 'APP_REQUEST' ) && APP_REQUEST ) ||
266
			 ( defined( 'REST_API_REQUEST' ) && REST_API_REQUEST ) ||
267
			 ( defined( 'COOKIE_AUTH_REQUEST' ) && COOKIE_AUTH_REQUEST ) ||
268
			 ( defined( 'JABBER_SERVER' ) && JABBER_SERVER ) ) {
269
			return;
270
		}
271
272
		if ( Jetpack_AMP_Support::is_amp_request() ) {
273
			return;
274
		}
275
276
		if ( $this->in_jetpack ) {
277
			add_filter( 'the_content', array( &$this, 'post_likes' ), 30, 1 );
278
			add_filter( 'the_excerpt', array( &$this, 'post_likes' ), 30, 1 );
279
280
		} else {
281
			add_filter( 'post_flair', array( &$this, 'post_likes' ), 30, 1 );
282
			add_filter( 'post_flair_block_css', array( $this, 'post_flair_service_enabled_like' ) );
283
284
			wp_enqueue_script( 'postmessage', '/wp-content/js/postmessage.js', array( 'jquery' ), JETPACK__VERSION, false );
285
			wp_enqueue_script( 'jetpack_resize', '/wp-content/js/jquery/jquery.jetpack-resize.js', array( 'jquery' ), JETPACK__VERSION, false );
286
			wp_enqueue_script( 'jetpack_likes_queuehandler', plugins_url( 'queuehandler.js' , __FILE__ ), array( 'jquery', 'postmessage', 'jetpack_resize' ), JETPACK__VERSION, true );
287
			wp_enqueue_style( 'jetpack_likes', plugins_url( 'jetpack-likes.css', __FILE__ ), array(), JETPACK__VERSION );
288
		}
289
	}
290
291
	/**
292
	* Register scripts
293
	*/
294
	function register_scripts() {
295
		wp_register_script(
296
			'postmessage',
297
			Jetpack::get_file_url_for_environment( '_inc/build/postmessage.min.js', '_inc/postmessage.js' ),
298
			array( 'jquery' ),
299
			JETPACK__VERSION,
300
			false
301
		);
302
		wp_register_script(
303
			'jetpack_resize',
304
			Jetpack::get_file_url_for_environment(
305
				'_inc/build/jquery.jetpack-resize.min.js',
306
				'_inc/jquery.jetpack-resize.js'
307
			),
308
			array( 'jquery' ),
309
			JETPACK__VERSION,
310
			false
311
		);
312
		wp_register_script(
313
			'jetpack_likes_queuehandler',
314
			Jetpack::get_file_url_for_environment(
315
				'_inc/build/likes/queuehandler.min.js',
316
				'modules/likes/queuehandler.js'
317
			),
318
			array( 'jquery', 'postmessage', 'jetpack_resize' ),
319
			JETPACK__VERSION,
320
			true
321
		);
322
	}
323
324
	/**
325
	* Load the CSS needed for the wp-admin area.
326
	*/
327
	function load_admin_css() {
328
	?>
329
		<style type="text/css">
330
			.vers img { display: none; }
331
			.metabox-prefs .vers img { display: inline; }
332
			.fixed .column-likes { width: 5.5em; padding: 8px 0; text-align: left; }
333
			.fixed .column-stats { width: 5em; }
334
			.fixed .column-likes .post-com-count {
335
				-webkit-box-sizing: border-box;
336
				-moz-box-sizing: border-box;
337
				box-sizing: border-box;
338
				display: inline-block;
339
				padding: 0 8px;
340
				height: 2em;
341
				margin-top: 5px;
342
				-webkit-border-radius: 5px;
343
				border-radius: 5px;
344
				background-color: #72777C;
345
				color: #FFF;
346
				font-size: 11px;
347
				line-height: 21px;
348
			}
349
			.fixed .column-likes .post-com-count::after { border: none !important; }
350
			.fixed .column-likes .post-com-count:hover { background-color: #0073AA; }
351
			.fixed .column-likes .vers:before {
352
				font: normal 20px/1 dashicons;
353
				content: '\f155';
354
				speak: none;
355
				-webkit-font-smoothing: antialiased;
356
				-moz-osx-font-smoothing: grayscale;
357
			}
358
			@media screen and (max-width: 782px) {
359
				.fixed .column-likes {
360
					display: none;
361
				}
362
			}
363
		</style>
364
		<?php
365
	}
366
367
	/**
368
	* Load the JS required for loading the like counts.
369
	*/
370
	function enqueue_admin_scripts() {
371
		if ( empty( $_GET['post_type'] ) || 'post' == $_GET['post_type'] || 'page' == $_GET['post_type'] ) {
372
			if ( $this->in_jetpack ) {
373
				wp_enqueue_script(
374
					'likes-post-count',
375
					Jetpack::get_file_url_for_environment(
376
						'_inc/build/likes/post-count.min.js',
377
						'modules/likes/post-count.js'
378
					),
379
					array( 'jquery' ),
380
					JETPACK__VERSION
381
				);
382
				wp_enqueue_script(
383
					'likes-post-count-jetpack',
384
					Jetpack::get_file_url_for_environment(
385
						'_inc/build/likes/post-count-jetpack.min.js',
386
						'modules/likes/post-count-jetpack.js'
387
					),
388
					array( 'likes-post-count' ),
389
					JETPACK__VERSION
390
				);
391
			} else {
392
				wp_enqueue_script( 'jquery.wpcom-proxy-request', "/wp-content/js/jquery/jquery.wpcom-proxy-request.js", array('jquery'), NULL, true );
393
				wp_enqueue_script( 'likes-post-count', plugins_url( 'likes/post-count.js', dirname( __FILE__ ) ), array( 'jquery' ), JETPACK__VERSION );
394
				wp_enqueue_script( 'likes-post-count-wpcom', plugins_url( 'likes/post-count-wpcom.js', dirname( __FILE__ ) ), array( 'likes-post-count', 'jquery.wpcom-proxy-request' ), JETPACK__VERSION );
395
			}
396
		}
397
	}
398
399
	/**
400
	* Add "Likes" column data to the post edit table in wp-admin.
401
	*
402
	* @param string $column_name
403
	* @param int $post_id
404
	*/
405
	function likes_edit_column( $column_name, $post_id ) {
406
		if ( 'likes' == $column_name ) {
407
408
			if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
409
				$blog_id = get_current_blog_id();
410
			} else {
411
				$blog_id = Jetpack_Options::get_option( 'id' );
412
			}
413
414
			$permalink = get_permalink( get_the_ID() ); ?>
415
			<a title="" data-post-id="<?php echo (int) $post_id; ?>" class="post-com-count post-like-count" id="post-like-count-<?php echo (int) $post_id; ?>" data-blog-id="<?php echo (int) $blog_id; ?>" href="<?php echo esc_url( $permalink ); ?>#like-<?php echo (int) $post_id; ?>">
416
				<span class="comment-count">0</span>
417
			</a>
418
			<?php
419
		}
420
	}
421
422
	/**
423
	* Add a "Likes" column header to the post edit table in wp-admin.
424
	*
425
	* @param array $columns
426
	* @return array
427
	*/
428
	function add_like_count_column( $columns ) {
429
		$date = $columns['date'];
430
		unset( $columns['date'] );
431
432
		$columns['likes'] = '<span class="vers"><img title="' . esc_attr__( 'Likes', 'jetpack' ) . '" alt="' . esc_attr__( 'Likes', 'jetpack' ) . '" src="//s0.wordpress.com/i/like-grey-icon.png" /><span class="screen-reader-text">' . __( 'Likes', 'jetpack' ) . '</span></span>';
433
		$columns['date'] = $date;
434
435
		return $columns;
436
	}
437
438
	function post_likes( $content ) {
439
		$post_id = get_the_ID();
440
441
		if ( ! is_numeric( $post_id ) || ! $this->settings->is_likes_visible() )
442
			return $content;
443
444 View Code Duplication
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
445
			$blog_id = get_current_blog_id();
446
			$bloginfo = get_blog_details( (int) $blog_id );
447
			$domain = $bloginfo->domain;
448
		} else {
449
			$blog_id = Jetpack_Options::get_option( 'id' );
450
			$url = home_url();
451
			$url_parts = parse_url( $url );
452
			$domain = $url_parts['host'];
453
		}
454
		// make sure to include the scripts before the iframe otherwise weird things happen
455
		add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
456
457
		/**
458
		* if the same post appears more then once on a page the page goes crazy
459
		* we need a slightly more unique id / name for the widget wrapper.
460
		*/
461
		$uniqid = uniqid();
462
463
		$src = sprintf( 'https://widgets.wp.com/likes/#blog_id=%1$d&amp;post_id=%2$d&amp;origin=%3$s&amp;obj_id=%1$d-%2$d-%4$s', $blog_id, $post_id, $domain, $uniqid );
464
		$name = sprintf( 'like-post-frame-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
465
		$wrapper = sprintf( 'like-post-wrapper-%1$d-%2$d-%3$s', $blog_id, $post_id, $uniqid );
466
		$headline = sprintf(
467
			/** This filter is already documented in modules/sharedaddy/sharing-service.php */
468
			apply_filters( 'jetpack_sharing_headline_html', '<h3 class="sd-title">%s</h3>', esc_html__( 'Like this:', 'jetpack' ), 'likes' ),
469
			esc_html__( 'Like this:', 'jetpack' )
470
		);
471
472
		$html  = "<div class='sharedaddy sd-block sd-like jetpack-likes-widget-wrapper jetpack-likes-widget-unloaded' id='$wrapper' data-src='$src' data-name='$name'>";
473
		$html .= $headline;
474
		$html .= "<div class='likes-widget-placeholder post-likes-widget-placeholder' style='height: 55px;'><span class='button'><span>" . esc_html__( 'Like', 'jetpack' ) . '</span></span> <span class="loading">' . esc_html__( 'Loading...', 'jetpack' ) . '</span></div>';
475
		$html .= "<span class='sd-text-color'></span><a class='sd-link-color'></a>";
476
		$html .= '</div>';
477
478
		// Let's make sure that the script is enqueued
479
		wp_enqueue_script( 'jetpack_likes_queuehandler' );
480
481
		return $content . $html;
482
	}
483
484
	function post_flair_service_enabled_like( $classes ) {
485
		$classes[] = 'sd-like-enabled';
486
		return $classes;
487
	}
488
489
	function is_admin_bar_button_visible() {
490
		global $wp_admin_bar;
491
492
		if ( ! is_object( $wp_admin_bar ) )
493
			return false;
494
495
		if ( ( ! is_singular( 'post' ) && ! is_attachment() && ! is_page() ) )
496
			return false;
497
498
		if ( ! $this->settings->is_likes_visible() )
499
			return false;
500
501
		if ( ! $this->settings->is_post_likeable() )
502
			return false;
503
504
		/**
505
		 * Filters whether the Like button is enabled in the admin bar.
506
		 *
507
		 * @module likes
508
		 *
509
		 * @since 2.2.0
510
		 *
511
		 * @param bool true Should the Like button be visible in the Admin bar. Default to true.
512
		 */
513
		return (bool) apply_filters( 'jetpack_admin_bar_likes_enabled', true );
514
	}
515
516
	function admin_bar_likes() {
517
		global $wp_admin_bar;
518
519
		$post_id = get_the_ID();
520
521
		if ( ! is_numeric( $post_id ) || ! $this->is_admin_bar_button_visible() ) {
522
			return;
523
		}
524
525
		$protocol = 'http';
526
		if ( is_ssl() )
527
			$protocol = 'https';
528
529 View Code Duplication
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
530
			$blog_id = get_current_blog_id();
531
			$bloginfo = get_blog_details( (int) $blog_id );
532
			$domain = $bloginfo->domain;
533
		} else {
534
			$blog_id = Jetpack_Options::get_option( 'id' );
535
			$url = home_url();
536
			$url_parts = parse_url( $url );
537
			$domain = $url_parts['host'];
538
		}
539
		// make sure to include the scripts before the iframe otherwise weird things happen
540
		add_action( 'wp_footer', 'jetpack_likes_master_iframe', 21 );
541
542
		$src = sprintf( 'https://widgets.wp.com/likes/#blog_id=%2$d&amp;post_id=%3$d&amp;origin=%1$s://%4$s', $protocol, $blog_id, $post_id, $domain );
543
544
		$html = "<iframe class='admin-bar-likes-widget jetpack-likes-widget' scrolling='no' frameBorder='0' name='admin-bar-likes-widget' src='$src'></iframe>";
545
546
		$node = array(
547
				'id'   => 'admin-bar-likes-widget',
548
				'meta' => array(
549
							'html' => $html
550
				)
551
		);
552
553
		$wp_admin_bar->add_node( $node );
554
	}
555
}
556
557
Jetpack_Likes::init();
558