Completed
Push — add/related-posts-customize ( 4a306a...1c5144 )
by
unknown
43:30 queued 35:07
created

Share_Pinterest::get_external_url()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
abstract class Sharing_Source {
4
	public	  $button_style;
5
	public	  $smart;
6
	protected $open_link_in_new;
7
	protected $id;
8
9
	public function __construct( $id, array $settings ) {
10
		$this->id = $id;
11
		/**
12
		 * Filter the way sharing links open.
13
		 *
14
		 * By default, sharing links open in a new window.
15
		 *
16
		 * @module sharedaddy
17
		 *
18
		 * @since 3.4.0
19
		 *
20
		 * @param bool true Should Sharing links open in a new window. Default to true.
21
		 */
22
		$this->open_link_in_new = apply_filters( 'jetpack_open_sharing_in_new_window', true );
23
24
		if ( isset( $settings['button_style'] ) ) {
25
			$this->button_style = $settings['button_style'];
26
		}
27
28
		if ( isset( $settings['smart'] ) ) {
29
			$this->smart = $settings['smart'];
30
		}
31
	}
32
33
	public function http() {
34
		return is_ssl() ? 'https' : 'http';
35
	}
36
37
	public function get_id() {
38
		return $this->id;
39
	}
40
41
	public function get_class() {
42
		return $this->id;
43
	}
44
45
	public function get_share_url( $post_id ) {
46
		/**
47
		 * Filter the sharing permalink.
48
		 *
49
		 * @module sharedaddy
50
		 *
51
		 * @since 1.2.0
52
		 *
53
		 * @param string get_permalink( $post_id ) Post Permalink.
54
		 * @param int $post_id Post ID.
55
		 * @param int $this->id Sharing ID.
56
		 */
57
		return apply_filters( 'sharing_permalink', get_permalink( $post_id ), $post_id, $this->id );
58
	}
59
60
	public function get_share_title( $post_id ) {
61
		$post = get_post( $post_id );
62
		/**
63
		 * Filter the sharing title.
64
		 *
65
		 * @module sharedaddy
66
		 *
67
		 * @since 2.8.0
68
		 *
69
		 * @param string $post->post_title Post Title.
70
		 * @param int $post_id Post ID.
71
		 * @param int $this->id Sharing ID.
72
		 */
73
		$title = apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id );
74
75
		return html_entity_decode( wp_kses( $title, null ) );
76
	}
77
78
	public function has_custom_button_style() {
79
		return false;
80
	}
81
82
	public function get_link( $url, $text, $title, $query = '', $id = false ) {
83
		$args = func_get_args();
84
		$klasses = array( 'share-' . $this->get_class(), 'sd-button' );
85
86
		if ( 'icon' == $this->button_style || 'icon-text' == $this->button_style ) {
87
			$klasses[] = 'share-icon';
88
		}
89
90
		if ( 'icon' == $this->button_style ) {
91
			$text = $title;
92
			$klasses[] = 'no-text';
93
94
			if ( true == $this->open_link_in_new ) {
95
				$text .= __( ' (Opens in new window)', 'jetpack' );
96
			}
97
		}
98
99
		/**
100
		 * Filter the sharing display ID.
101
		 *
102
		 * @module sharedaddy
103
		 *
104
		 * @since 3.4.0
105
		 *
106
		 * @param int|false $id Sharing ID.
107
		 * @param object $this Sharing service properties.
108
		 * @param array $args Array of sharing service options.
109
		 */
110
		$id = apply_filters( 'jetpack_sharing_display_id', $id, $this, $args );
111
		/**
112
		 * Filter the sharing display link.
113
		 *
114
		 * @module sharedaddy
115
		 *
116
		 * @since 2.8.0
117
		 *
118
		 * @param string $url Post URL.
119
		 * @param object $this Sharing service properties.
120
		 * @param int|false $id Sharing ID.
121
		 * @param array $args Array of sharing service options.
122
		 */
123
		$url = apply_filters( 'sharing_display_link', $url, $this, $id, $args ); // backwards compatibility
124
		/**
125
		 * Filter the sharing display link.
126
		 *
127
		 * @module sharedaddy
128
		 *
129
		 * @since 2.8.0
130
		 *
131
		 * @param string $url Post URL.
132
		 * @param object $this Sharing service properties.
133
		 * @param int|false $id Sharing ID.
134
		 * @param array $args Array of sharing service options.
135
		 */
136
		$url = apply_filters( 'jetpack_sharing_display_link', $url, $this, $id, $args );
137
		/**
138
		 * Filter the sharing display query.
139
		 *
140
		 * @module sharedaddy
141
		 *
142
		 * @since 2.8.0
143
		 *
144
		 * @param string $query Sharing service URL parameter.
145
		 * @param object $this Sharing service properties.
146
		 * @param int|false $id Sharing ID.
147
		 * @param array $args Array of sharing service options.
148
		 */
149
		$query = apply_filters( 'jetpack_sharing_display_query', $query, $this, $id, $args );
150
151
		if ( ! empty( $query ) ) {
152
			if ( false === stripos( $url, '?' ) ) {
153
				$url .= '?' . $query;
154
			} else { 
155
				$url .= '&amp;' . $query;
156
			}
157
		}
158
159
		if ( 'text' == $this->button_style ) {
160
			$klasses[] = 'no-icon';
161
		}
162
163
		/**
164
		 * Filter the sharing display classes.
165
		 *
166
		 * @module sharedaddy
167
		 *
168
		 * @since 3.4.0
169
		 *
170
		 * @param array $klasses Sharing service classes.
171
		 * @param object $this Sharing service properties.
172
		 * @param int|false $id Sharing ID.
173
		 * @param array $args Array of sharing service options.
174
		 */
175
		$klasses = apply_filters( 'jetpack_sharing_display_classes', $klasses, $this, $id, $args );
176
		/**
177
		 * Filter the sharing display title.
178
		 *
179
		 * @module sharedaddy
180
		 *
181
		 * @since 3.4.0
182
		 *
183
		 * @param string $title Sharing service title.
184
		 * @param object $this Sharing service properties.
185
		 * @param int|false $id Sharing ID.
186
		 * @param array $args Array of sharing service options.
187
		 */
188
		$title = apply_filters( 'jetpack_sharing_display_title', $title, $this, $id, $args );
189
		/**
190
		 * Filter the sharing display text.
191
		 *
192
		 * @module sharedaddy
193
		 *
194
		 * @since 3.4.0
195
		 *
196
		 * @param string $text Sharing service text.
197
		 * @param object $this Sharing service properties.
198
		 * @param int|false $id Sharing ID.
199
		 * @param array $args Array of sharing service options.
200
		 */
201
		$text = apply_filters( 'jetpack_sharing_display_text', $text, $this, $id, $args );
202
203
		return sprintf(
204
			'<a rel="nofollow" data-shared="%s" class="%s" href="%s"%s title="%s"><span%s>%s</span></a>',
205
			( $id ? esc_attr( $id ) : '' ),
206
			implode( ' ', $klasses ),
207
			$url,
208
			( true == $this->open_link_in_new ) ? ' target="_blank"' : '',
209
			$title,
210
			( 'icon' == $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '',
211
			$text
212
		);
213
	}
214
215
	/**
216
	 * Get an unfiltered post permalink to use when generating a sharing URL with get_link.
217
	 * Use instead of get_share_url for non-official styles as get_permalink ensures that process_request
218
	 * will be executed more reliably, in the case that the filtered URL uses a service that strips query parameters.
219
	 *
220
	 * @since 3.7.0
221
	 * @param int $post_id Post ID.
222
	 * @uses get_permalink
223
	 * @return string get_permalink( $post_id ) Post permalink.
224
	 */
225
	public function get_process_request_url( $post_id ) {
226
		return get_permalink( $post_id );
227
	}
228
229
	abstract public function get_name();
230
	abstract public function get_display( $post );
231
232
	public function display_header() {
233
	}
234
235
	public function display_footer() {
236
	}
237
238
	public function has_advanced_options() {
239
		return false;
240
	}
241
242
	public function display_preview( $echo = true, $force_smart = false, $button_style = null ) {
243
		$text = '&nbsp;';
244
		$button_style = ( ! empty( $button_style ) ) ? $button_style : $this->button_style;
245
		if ( ! $this->smart && ! $force_smart ) {
246
			if ( $button_style != 'icon' ) {
247
				$text = $this->get_name();
248
			}
249
		}
250
251
		$klasses = array( 'share-' . $this->get_class(), 'sd-button' );
252
253
		if ( $button_style == 'icon' || $button_style == 'icon-text' ) {
254
			$klasses[] = 'share-icon';
255
		}
256
257
		if ( $button_style == 'icon' ) {
258
			$klasses[] = 'no-text';
259
		}
260
261
		if ( $button_style == 'text' ) {
262
			$klasses[] = 'no-icon';
263
		}
264
265
		$link = sprintf(
266
			'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span>%s</span></a>',
267
			implode( ' ', $klasses ),
268
			$this->get_name(),
269
			$text
270
		);
271
272
		$smart = ( $this->smart || $force_smart ) ? 'on' : 'off';
273
		$return = "<div class='option option-smart-$smart'>$link</div>";
274
		if ( $echo ) {
275
			echo $return;
276
		}
277
278
		return $return;
279
	}
280
281 View Code Duplication
	public function get_total( $post = false ) {
282
		global $wpdb, $blog_id;
283
284
		$name = strtolower( $this->get_id() );
285
286
		if ( $post == false ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
287
			// get total number of shares for service
288
			return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) );
289
		}
290
291
		// get total shares for a post
292
		return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s', $blog_id, $post->ID, $name ) );
293
	}
294
295 View Code Duplication
	public function get_posts_total() {
296
		global $wpdb, $blog_id;
297
298
		$totals = array();
299
		$name	= strtolower( $this->get_id() );
300
301
		$my_data = $wpdb->get_results( $wpdb->prepare( 'SELECT post_id as id, SUM( count ) as total FROM sharing_stats WHERE blog_id = %d AND share_service = %s GROUP BY post_id ORDER BY count DESC ', $blog_id, $name ) );
302
303
		if ( ! empty( $my_data ) ) {
304
			foreach ( $my_data as $row ) {
305
				$totals[] = new Sharing_Post_Total( $row->id, $row->total );
306
			}
307
		}
308
309
		usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) );
310
311
		return $totals;
312
	}
313
314
	public function process_request( $post, array $post_data ) {
315
		/**
316
		 * Fires when a post is shared via one of the sharing buttons.
317
		 *
318
		 * @module sharedaddy
319
		 *
320
		 * @since 1.1.0
321
		 *
322
		 * @param array $args Aray of information about the sharing service.
323
		 */
324
		do_action( 'sharing_bump_stats', array( 'service' => $this, 'post' => $post ) );
325
	}
326
327
	public function js_dialog( $name, $params = array() ) {
328
		if ( true !== $this->open_link_in_new ) {
329
			return;
330
		}
331
332
		$defaults = array(
333
			'menubar'	=> 1,
334
			'resizable' => 1,
335
			'width'		=> 600,
336
			'height'	=> 400,
337
		);
338
		$params = array_merge( $defaults, $params );
339
		$opts = array();
340
		foreach ( $params as $key => $val ) {
341
			$opts[] = "$key=$val";
342
		}
343
		$opts = implode( ',', $opts );
344
345
		// Add JS after sharing-js has been enqueued.
346
		wp_add_inline_script( 'sharing-js',
347
			"var windowOpen;
348
			jQuery( document.body ).on( 'click', 'a.share-$name', function() {
349
				// If there's another sharing window open, close it.
350
				if ( 'undefined' !== typeof windowOpen ) {
351
					windowOpen.close();
352
				}
353
				windowOpen = window.open( jQuery( this ).attr( 'href' ), 'wpcom$name', '$opts' );
354
				return false;
355
			});"
356
		);
357
	}
358
}
359
360
abstract class Sharing_Advanced_Source extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
361
	public function has_advanced_options() {
362
		return true;
363
	}
364
365
	abstract public function display_options();
366
	abstract public function update_options( array $data );
367
	abstract public function get_options();
368
}
369
370
371
class Share_Email extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
372
	public $shortname = 'email';
373
	public $genericon = '\f410';
374 View Code Duplication
	public function __construct( $id, array $settings ) {
375
		parent::__construct( $id, $settings );
376
377
		if ( 'official' == $this->button_style ) {
378
			$this->smart = true;
379
		} else { 
380
			$this->smart = false;
381
		}
382
	}
383
384
	public function get_name() {
385
		return _x( 'Email', 'as sharing source', 'jetpack' );
386
	}
387
388
	// Default does nothing
389
	public function process_request( $post, array $post_data ) {
390
		$ajax = false;
391
		if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) {
392
			$ajax = true;
393
		}
394
395
		$source_email = $target_email = $source_name = false;
0 ignored issues
show
Unused Code introduced by
$source_name 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...
396
397
		if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) ) {
398
			$source_email = $post_data['source_email'];
399
		}
400
401
		if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) ) {
402
			$target_email = $post_data['target_email'];
403
		}
404
405
		if ( isset( $post_data['source_name'] ) && strlen( $post_data['source_name'] ) < 200 ) {
406
			$source_name = $post_data['source_name'];
407
		} elseif ( isset( $post_data['source_name'] ) ) {
408
			$source_name = substr( $post_data['source_name'], 0, 200 );
409
		} else {
410
			$source_name = '';
411
		}
412
413
		// Test email
414
		$error = 1;	  // Failure in data
415
		if ( empty( $post_data['source_f_name'] ) && $source_email && $target_email && $source_name ) {
416
			/**
417
			 * Allow plugins to stop the email sharing button from running the shared message through Akismet.
418
			 *
419
			 * @module sharedaddy
420
			 *
421
			 * @since 1.1.0
422
			 *
423
			 * @param bool true Should we check if the message isn't spam?
424
			 * @param object $post Post information.
425
			 * @param array $post_data Information about the shared message.
426
			 */
427
			if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) {
428
				$data = array(
429
					'post'	 => $post,
430
					'source' => $source_email,
431
					'target' => $target_email,
432
					'name'	 => $source_name,
433
				);
434
				// todo: implement an error message when email doesn't get sent.
0 ignored issues
show
Coding Style Best Practice introduced by
Comments for TODO tasks are often forgotten in the code; it might be better to use a dedicated issue tracker.
Loading history...
435
				/**
436
				 * Filter whether an email can be sent from the Email sharing button.
437
				 *
438
				 * @module sharedaddy
439
				 *
440
				 * @since 1.1.0
441
				 *
442
				 * @param array $data Array of information about the shared message.
443
				 */
444
				if ( ( $data = apply_filters( 'sharing_email_can_send', $data ) ) !== false ) {
445
					// Record stats
446
					parent::process_request( $data['post'], $post_data );
447
448
					/**
449
					 * Fires when an email is sent via the Email sharing button.
450
					 *
451
					 * @module sharedaddy
452
					 *
453
					 * @since 1.1.0
454
					 *
455
					 * @param array $data Array of information about the shared message.
456
					 */
457
					do_action( 'sharing_email_send_post', $data );
458
				}
459
460
				// Return a positive regardless of whether the user is subscribed or not
461
				if ( $ajax ) {
462
?>
463
<div class="response">
464
	<div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div>
465
	<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div>
466
	<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div>
467
</div>
468
<?php
469
				} else {
470
					wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email' );
471
				}
472
473
				die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
474
			} else { 
475
				$error = 2;	  // Email check failed
476
			}
477
		}
478
479
		if ( $ajax ) {
480
			echo $error;
481
		} else { 
482
			wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' );
483
		}
484
485
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
486
	}
487
488
	public function get_display( $post ) {
489
		return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Email', 'share to', 'jetpack' ), __( 'Click to email this to a friend', 'jetpack' ), 'share=email' );
490
	}
491
492
	/**
493
	 * Outputs the hidden email dialog
494
	 */
495
	public function display_footer() {
496
		global $current_user;
497
498
		$visible = $status = false;
0 ignored issues
show
Unused Code introduced by
$status 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...
Unused Code introduced by
$visible 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...
499
?>
500
	<div id="sharing_email" style="display: none;">
501
		<form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post">
502
			<label for="target_email"><?php _e( 'Send to Email Address', 'jetpack' ) ?></label>
503
			<input type="email" name="target_email" id="target_email" value="" />
504
505
			<?php if ( is_user_logged_in() ) : ?>
506
				<input type="hidden" name="source_name" value="<?php echo esc_attr( $current_user->display_name ); ?>" />
507
				<input type="hidden" name="source_email" value="<?php echo esc_attr( $current_user->user_email ); ?>" />
508
			<?php else : ?>
509
510
				<label for="source_name"><?php _e( 'Your Name', 'jetpack' ) ?></label>
511
				<input type="text" name="source_name" id="source_name" value="" />
512
513
				<label for="source_email"><?php _e( 'Your Email Address', 'jetpack' ) ?></label>
514
				<input type="email" name="source_email" id="source_email" value="" />
515
516
			<?php endif; ?>
517
			<input type="text" id="jetpack-source_f_name" name="source_f_name" class="input" value="" size="25" autocomplete="off" />
518
			<script>jQuery( document ).ready( function(){ document.getElementById('jetpack-source_f_name').value = '' });</script>
519
			<?php
520
				/**
521
				 * Fires when the Email sharing dialog is loaded.
522
				 *
523
				 * @module sharedaddy
524
				 *
525
				 * @since 1.1.0
526
				 *
527
				 * @param string jetpack Eail sharing source.
528
				 */
529
				do_action( 'sharing_email_dialog', 'jetpack' );
530
			?>
531
532
			<img style="float: right; display: none" class="loading" src="<?php
533
			/** This filter is documented in modules/stats.php */
534
			echo apply_filters( 'jetpack_static_url', plugin_dir_url( __FILE__ ) . 'images/loading.gif' ); ?>" alt="loading" width="16" height="16" />
535
			<input type="submit" value="<?php esc_attr_e( 'Send Email', 'jetpack' ); ?>" class="sharing_send" />
536
			<a rel="nofollow" href="#cancel" class="sharing_cancel"><?php _e( 'Cancel', 'jetpack' ); ?></a>
537
538
			<div class="errors errors-1" style="display: none;">
539
				<?php _e( 'Post was not sent - check your email addresses!', 'jetpack' ); ?>
540
			</div>
541
542
			<div class="errors errors-2" style="display: none;">
543
				<?php _e( 'Email check failed, please try again', 'jetpack' ); ?>
544
			</div>
545
546
			<div class="errors errors-3" style="display: none;">
547
				<?php _e( 'Sorry, your blog cannot share posts by email.', 'jetpack' ); ?>
548
			</div>
549
		</form>
550
	</div>
551
<?php
552
	}
553
}
554
555
class Share_Twitter extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
556
	public $shortname = 'twitter';
557
	public $genericon = '\f202';
558
	// 'https://dev.twitter.com/rest/reference/get/help/configuration' ( 2015/02/06 ) short_url_length is 22, short_url_length_https is 23
559
	public $short_url_length = 24;
560
561 View Code Duplication
	public function __construct( $id, array $settings ) {
562
		parent::__construct( $id, $settings );
563
564
		if ( 'official' == $this->button_style ) {
565
			$this->smart = true;
566
		} else { 
567
			$this->smart = false;
568
		}
569
	}
570
571
	public function get_name() {
572
		return __( 'Twitter', 'jetpack' );
573
	}
574
575
	function sharing_twitter_via( $post ) {
576
		/**
577
		 * Allow third-party plugins to customize the Twitter username used as "twitter:site" Twitter Card Meta Tag.
578
		 *
579
		 * @module sharedaddy
580
		 *
581
		 * @since 3.0.0
582
		 *
583
		 * @param string $string Twitter Username.
584
		 * @param array $args Array of Open Graph Meta Tags and Twitter Cards tags.
585
		 */
586
		$twitter_site_tag_value = apply_filters( 'jetpack_twitter_cards_site_tag', '', array() );
587
588
		/*
589
		 * Hack to remove the unwanted behavior of adding 'via @jetpack' which
590
		 * was introduced with the adding of the Twitter cards.
591
		 * This should be a temporary solution until a better method is setup.
592
		 */
593
		if ( 'jetpack' == $twitter_site_tag_value ) {
594
			$twitter_site_tag_value = '';
595
		}
596
597
		/**
598
		 * Filters the Twitter username used as "via" in the Twitter sharing button.
599
		 *
600
		 * @module sharedaddy
601
		 *
602
		 * @since 1.7.0
603
		 *
604
		 * @param string $twitter_site_tag_value Twitter Username.
605
		 * @param int $post->ID Post ID.
606
		 */
607
		$twitter_site_tag_value = apply_filters( 'jetpack_sharing_twitter_via', $twitter_site_tag_value, $post->ID );
608
609
		// Strip out anything other than a letter, number, or underscore.
610
		// This will prevent the inadvertent inclusion of an extra @, as well as normalizing the handle.
611
		return preg_replace( '/[^\da-z_]+/i', '', $twitter_site_tag_value );
612
	}
613
614
	public function get_related_accounts( $post ) {
615
		/**
616
		 * Filter the list of related Twitter accounts added to the Twitter sharing button.
617
		 *
618
		 * @module sharedaddy
619
		 *
620
		 * @since 1.7.0
621
		 *
622
		 * @param array $args Array of Twitter usernames. Format is 'username' => 'Optional description'
623
		 * @param int $post->ID Post ID.
624
		 */
625
		$related_accounts = apply_filters( 'jetpack_sharing_twitter_related', array(), $post->ID );
626
627
		// Example related string: account1,account2:Account 2 description,account3
628
		$related = array();
629
630
		foreach ( $related_accounts as $related_account_username => $related_account_description ) {
631
			// Join the description onto the end of the username
632
			if ( $related_account_description ) {
633
				$related_account_username .= ':' . $related_account_description;
634
			}
635
636
			$related[] = $related_account_username;
637
		}
638
639
		return implode( ',', $related );
640
	}
641
642
	public function get_display( $post ) {
643
		$via = $this->sharing_twitter_via( $post );
644
645
		if ( $via ) {
646
			$via = 'data-via="' . esc_attr( $via ) . '"';
647
		} else {
648
			$via = '';
649
		}
650
651
		$related = $this->get_related_accounts( $post );
652
		if ( ! empty( $related ) && $related !== $via ) {
653
			$related = 'data-related="' . esc_attr( $related ) . '"';
654
		} else {
655
			$related = '';
656
		}
657
658
		if ( $this->smart ) {
659
			$share_url = $this->get_share_url( $post->ID );
660
			$post_title = $this->get_share_title( $post->ID );
661
			return sprintf(
662
				'<a href="https://twitter.com/share" class="twitter-share-button" data-url="%1$s" data-text="%2$s" %3$s %4$s>Tweet</a>',
663
				esc_url( $share_url ),
664
				esc_attr( $post_title ),
665
				$via,
666
				$related
667
			);
668
		} else {
669
			if (
670
				/**
671
				 * Allow plugins to disable sharing counts for specific sharing services.
672
				 *
673
				 * @module sharedaddy
674
				 *
675
				 * @since 3.0.0
676
				 *
677
				 * @param bool true Should sharing counts be enabled for this specific service. Default to true.
678
				 * @param int $post->ID Post ID.
679
				 * @param string $str Sharing service name.
680
				 */
681
				apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' )
682
			) {
683
				sharing_register_post_for_share_counts( $post->ID );
684
			}
685
			return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Twitter', 'share to', 'jetpack' ), __( 'Click to share on Twitter', 'jetpack' ), 'share=twitter', 'sharing-twitter-' . $post->ID );
686
		}
687
	}
688
689
	public function process_request( $post, array $post_data ) {
690
		$post_title = $this->get_share_title( $post->ID );
691
		$post_link = $this->get_share_url( $post->ID );
692
693
		if ( function_exists( 'mb_stripos' ) ) {
694
			$strlen = 'mb_strlen';
695
			$substr = 'mb_substr';
696
		} else {
697
			$strlen = 'strlen';
698
			$substr = 'substr';
699
		}
700
701
		$via = $this->sharing_twitter_via( $post );
702
		$related = $this->get_related_accounts( $post );
703
		if ( $via ) {
704
			$sig = " via @$via";
705
			if ( $related === $via ) {
706
				$related = false;
707
			}
708
		} else {
709
			$via = false;
710
			$sig = '';
711
		}
712
713
		$suffix_length = $this->short_url_length + $strlen( $sig );
714
		// $sig is handled by twitter in their 'via' argument.
715
		// $post_link is handled by twitter in their 'url' argument.
716
		if ( 140 < $strlen( $post_title ) + $suffix_length ) {
717
			// The -1 is for "\xE2\x80\xA6", a UTF-8 ellipsis.
718
			$text = $substr( $post_title, 0, 140 - $suffix_length - 1 ) . "\xE2\x80\xA6";
719
		} else {
720
			$text = $post_title;
721
		}
722
723
		// Record stats
724
		parent::process_request( $post, $post_data );
725
726
		$url = $post_link;
727
		$twitter_url = add_query_arg(
728
			rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ),
729
			'https://twitter.com/intent/tweet'
730
		);
731
732
		// Redirect to Twitter
733
		wp_redirect( $twitter_url );
734
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
735
	}
736
737
	public function has_custom_button_style() {
738
		return $this->smart;
739
	}
740
741
	public function display_footer() {
742
		if ( $this->smart ) {
743
			?>
744
			<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>
745
			<?php
746
		} else {
747
			$this->js_dialog( $this->shortname, array( 'height' => 350 ) );
748
		}
749
	}
750
}
751
752
753
class Share_Reddit extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
754
	public $shortname = 'reddit';
755
	public $genericon = '\f222';
756 View Code Duplication
	public function __construct( $id, array $settings ) {
757
		parent::__construct( $id, $settings );
758
759
		if ( 'official' == $this->button_style ) {
760
			$this->smart = true;
761
		} else { 
762
			$this->smart = false;
763
		}
764
	}
765
766
	public function get_name() {
767
		return __( 'Reddit', 'jetpack' );
768
	}
769
770
	public function get_display( $post ) {
771
		if ( $this->smart ) {
772
			return '<div class="reddit_button"><iframe src="' . $this->http() . '://www.reddit.com/static/button/button1.html?newwindow=true&width=120&amp;url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&amp;title=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>';
773 View Code Duplication
		} else { 
774
			return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' );
775
		}
776
	}
777
778 View Code Duplication
	public function process_request( $post, array $post_data ) {
779
		$reddit_url = $this->http() . '://reddit.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) );
780
781
		// Record stats
782
		parent::process_request( $post, $post_data );
783
784
		// Redirect to Reddit
785
		wp_redirect( $reddit_url );
786
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
787
	}
788
}
789
790
class Share_LinkedIn extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
791
	public $shortname = 'linkedin';
792
	public $genericon = '\f207';
793 View Code Duplication
	public function __construct( $id, array $settings ) {
794
		parent::__construct( $id, $settings );
795
796
		if ( 'official' == $this->button_style ) {
797
			$this->smart = true;
798
		} else { 
799
			$this->smart = false;
800
		}
801
	}
802
803
	public function get_name() {
804
		return __( 'LinkedIn', 'jetpack' );
805
	}
806
807
	public function has_custom_button_style() {
808
		return $this->smart;
809
	}
810
811
	public function get_display( $post ) {
812
		$display = '';
813
814
		if ( $this->smart ) {
815
			$share_url = $this->get_share_url( $post->ID );
816
			$display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) );
817 View Code Duplication
		} else {
818
			$display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'LinkedIn', 'share to', 'jetpack' ), __( 'Click to share on LinkedIn', 'jetpack' ), 'share=linkedin', 'sharing-linkedin-' . $post->ID );
819
		}
820
821
		/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
822
		if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
823
			sharing_register_post_for_share_counts( $post->ID );
824
		}
825
826
		return $display;
827
	}
828
829 View Code Duplication
	public function process_request( $post, array $post_data ) {
830
831
		$post_link = $this->get_share_url( $post->ID );
832
833
		// Using the same URL as the official button, which is *not* LinkedIn's documented sharing link
834
		// https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false
835
		$linkedin_url = add_query_arg( array(
836
			'url' => rawurlencode( $post_link ),
837
		), 'https://www.linkedin.com/cws/share?token=&isFramed=false' );
838
839
		// Record stats
840
		parent::process_request( $post, $post_data );
841
842
		// Redirect to LinkedIn
843
		wp_redirect( $linkedin_url );
844
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
845
	}
846
847 View Code Duplication
	public function display_footer() {
848
		if ( ! $this->smart ) {
849
			$this->js_dialog( $this->shortname, array( 'width' => 580, 'height' => 450 ) );
850
		} else {
851
			?><script type="text/javascript">
852
			jQuery( document ).ready( function() {
853
				jQuery.getScript( 'https://platform.linkedin.com/in.js?async=true', function success() {
854
					IN.init();
855
				});
856
			});
857
			jQuery( document.body ).on( 'post-load', function() {
858
				if ( typeof IN != 'undefined' )
859
					IN.parse();
860
			});
861
			</script><?php
862
		}
863
	}
864
}
865
866
class Share_Facebook extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
867
	public $shortname = 'facebook';
868
	public $genericon = '\f204';
869
	private $share_type = 'default';
870
871 View Code Duplication
	public function __construct( $id, array $settings ) {
872
		parent::__construct( $id, $settings );
873
874
		if ( isset( $settings['share_type'] ) ) {
875
			$this->share_type = $settings['share_type'];
876
		}
877
878
		if ( 'official' == $this->button_style ) {
879
			$this->smart = true;
880
		} else { 
881
			$this->smart = false;
882
		}
883
	}
884
885
	public function get_name() {
886
		return __( 'Facebook', 'jetpack' );
887
	}
888
889
	public function display_header() {
890
	}
891
892 View Code Duplication
	function guess_locale_from_lang( $lang ) {
893
		if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) {
894
			return 'en_US';
895
		}
896
897
		if ( ! class_exists( 'GP_Locales' ) ) {
898
			if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) {
899
				return false;
900
			}
901
902
			require JETPACK__GLOTPRESS_LOCALES_PATH;
903
		}
904
905
		if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) {
906
			// WP.com: get_locale() returns 'it'
907
			$locale = GP_Locales::by_slug( $lang );
908
		} else {
909
			// Jetpack: get_locale() returns 'it_IT';
910
			$locale = GP_Locales::by_field( 'wp_locale', $lang );
911
		}
912
913
		if ( ! $locale ) {
914
			return false;
915
		}
916
917
		if ( empty( $locale->facebook_locale ) ) {
918
			if ( empty( $locale->wp_locale ) ) {
919
				return false;
920
			} else {
921
				// Facebook SDK is smart enough to fall back to en_US if a
922
				// locale isn't supported. Since supported Facebook locales
923
				// can fall out of sync, we'll attempt to use the known
924
				// wp_locale value and rely on said fallback.
925
				return $locale->wp_locale;
926
			}
927
		}
928
929
		return $locale->facebook_locale;
930
	}
931
932
	public function get_display( $post ) {
933
		if ( $this->smart ) {
934
			$share_url = $this->get_share_url( $post->ID );
935
			$fb_share_html = '<div class="fb-share-button" data-href="' . esc_attr( $share_url ) . '" data-layout="button_count"></div>';
936
			/**
937
			 * Filter the output of the Facebook Sharing button.
938
			 *
939
			 * @module sharedaddy
940
			 *
941
			 * @since 3.6.0
942
			 *
943
			 * @param string $fb_share_html Facebook Sharing button HTML.
944
			 * @param string $share_url URL of the post to share.
945
			 */
946
			return apply_filters( 'jetpack_sharing_facebook_official_button_output', $fb_share_html, $share_url );
947
		}
948
949
		/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
950
		if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) {
951
			sharing_register_post_for_share_counts( $post->ID );
952
		}
953
		return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Facebook', 'share to', 'jetpack' ), __( 'Click to share on Facebook', 'jetpack' ), 'share=facebook', 'sharing-facebook-' . $post->ID );
954
	}
955
956 View Code Duplication
	public function process_request( $post, array $post_data ) {
957
		$fb_url = $this->http() . '://www.facebook.com/sharer.php?u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) );
958
959
		// Record stats
960
		parent::process_request( $post, $post_data );
961
962
		// Redirect to Facebook
963
		wp_redirect( $fb_url );
964
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
965
	}
966
967
	public function display_footer() {
968
		$this->js_dialog( $this->shortname );
969
		if ( $this->smart ) {
970
			$locale = $this->guess_locale_from_lang( get_locale() );
971
			if ( ! $locale ) {
972
				$locale = 'en_US';
973
			}
974
			/**
975
			 * Filter the App ID used in the official Facebook Share button.
976
			 *
977
			 * @since 3.8.0
978
			 *
979
			 * @param int $fb_app_id Facebook App ID. Default to 249643311490 (WordPress.com's App ID).
980
			 */
981
			$fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' );
982
			if ( is_numeric( $fb_app_id ) ) {
983
				$fb_app_id = '&appId=' . $fb_app_id;
984
			} else {
985
				$fb_app_id = '';
986
			}
987
			?><div id="fb-root"></div>
988
			<script>(function(d, s, id) { var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js = d.createElement(s); js.id = id; js.src = 'https://connect.facebook.net/<?php echo $locale; ?>/sdk.js#xfbml=1<?php echo $fb_app_id; ?>&version=v2.3'; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk'));</script>
989
			<script>
990
			jQuery( document.body ).on( 'post-load', function() {
991
				if ( 'undefined' !== typeof FB ) {
992
					FB.XFBML.parse();
993
				}
994
			} );
995
			</script>
996
			<?php
997
		}
998
	}
999
}
1000
1001
class Share_Print extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1002
	public $shortname = 'print';
1003
	public $genericon = '\f469';
1004 View Code Duplication
	public function __construct( $id, array $settings ) {
1005
		parent::__construct( $id, $settings );
1006
1007
		if ( 'official' == $this->button_style ) {
1008
			$this->smart = true;
1009
		} else { 
1010
			$this->smart = false;
1011
		}
1012
	}
1013
1014
	public function get_name() {
1015
		return __( 'Print', 'jetpack' );
1016
	}
1017
1018
	public function get_display( $post ) {
1019
		return $this->get_link( $this->get_process_request_url( $post->ID ) . ( ( is_single() || is_page() ) ? '#print': '' ), _x( 'Print', 'share to', 'jetpack' ), __( 'Click to print', 'jetpack' ) );
1020
	}
1021
}
1022
1023
class Share_PressThis extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1024
	public $shortname = 'pressthis';
1025
	public $genericon = '\f205';
1026 View Code Duplication
	public function __construct( $id, array $settings ) {
1027
		parent::__construct( $id, $settings );
1028
1029
		if ( 'official' == $this->button_style ) {
1030
			$this->smart = true;
1031
		} else { 
1032
			$this->smart = false;
1033
		}
1034
	}
1035
1036
	public function get_name() {
1037
		return __( 'Press This', 'jetpack' );
1038
	}
1039
1040
	public function process_request( $post, array $post_data ) {
1041
		global $current_user;
1042
1043
		$primary_blog = (int) get_user_meta( $current_user->ID, 'primary_blog', true );
1044
		if ( $primary_blog ) {
1045
			$primary_blog_details = get_blog_details( $primary_blog );
1046
		} else {
1047
			$primary_blog_details = false;
1048
		}
1049
1050
		if ( $primary_blog_details ) {
1051
			$blogs = array( $primary_blog_details );
1052
		} elseif ( function_exists( 'get_active_blogs_for_user' ) ) {
1053
			$blogs = get_active_blogs_for_user();
1054
			if ( empty( $blogs ) ) {
1055
				$blogs = get_blogs_of_user( $current_user->ID );
1056
			}
1057
		} else {
1058
			$blogs = get_blogs_of_user( $current_user->ID );
1059
		}
1060
1061
		if ( empty( $blogs ) ) {
1062
			wp_safe_redirect( get_permalink( $post->ID ) );
1063
			die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1064
		}
1065
1066
		$blog = current( $blogs );
1067
1068
		$url = $blog->siteurl . '/wp-admin/press-this.php?u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) );
1069
1070
		if ( isset( $_GET['sel'] ) ) {
1071
			$url .= '&s=' . rawurlencode( $_GET['sel'] );
1072
		}
1073
1074
		// Record stats
1075
		parent::process_request( $post, $post_data );
1076
1077
		// Redirect to Press This
1078
		wp_safe_redirect( $url );
1079
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1080
	}
1081
1082
	public function get_display( $post ) {
1083
		return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Press This', 'share to', 'jetpack' ), __( 'Click to Press This!', 'jetpack' ), 'share=press-this' );
1084
	}
1085
}
1086
1087
class Share_GooglePlus1 extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1088
	public $shortname = 'googleplus1';
1089
	public $genericon = '\f218';
1090
	private $state = false;
1091
1092 View Code Duplication
	public function __construct( $id, array $settings ) {
1093
		parent::__construct( $id, $settings );
1094
1095
		if ( 'official' == $this->button_style ) {
1096
			$this->smart = true;
1097
		} else { 
1098
			$this->smart = false;
1099
		}
1100
	}
1101
1102
	public function get_name() {
1103
		return __( 'Google', 'jetpack' );
1104
	}
1105
1106
	public function has_custom_button_style() {
1107
		return $this->smart;
1108
	}
1109
1110
	public function get_display( $post ) {
1111
1112
		if ( $this->smart ) {
1113
			$share_url = $this->get_share_url( $post->ID );
1114
			return '<div class="googleplus1_button"><div class="g-plus" data-action="share" data-annotation="bubble" data-href="' . esc_url( $share_url ) . '"></div></div>';
1115 View Code Duplication
		} else {
1116
			return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Google', 'share to', 'jetpack' ), __( 'Click to share on Google+', 'jetpack' ), 'share=google-plus-1', 'sharing-google-' . $post->ID );
1117
		}
1118
	}
1119
1120
	public function get_state() {
1121
		return $this->state;
1122
	}
1123
1124
	public function process_request( $post, array $post_data ) {
1125
1126
		if ( isset( $post_data['state'] ) ) {
1127
			$this->state = $post_data['state'];
1128
		}
1129
		// Record stats
1130
		parent::process_request( $post, $post_data );
1131
1132
		// Redirect to Google +'s sharing endpoint
1133
		$url = 'https://plus.google.com/share?url=' . rawurlencode( $this->get_share_url( $post->ID ) );
1134
		wp_redirect( $url );
1135
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1136
	}
1137
1138 View Code Duplication
	public function display_footer() {
1139
		global $post;
1140
1141
		if ( $this->smart ) { ?>
1142
			<script>
1143
			function renderGooglePlus1() {
1144
				if ( 'undefined' === typeof gapi ) {
1145
					return;
1146
				}
1147
1148
				jQuery( '.g-plus' ).each(function() {
1149
					var $button = jQuery( this );
1150
1151
					if ( ! $button.data( 'gplus-rendered' ) ) {
1152
						gapi.plusone.render( this, {
1153
							href: $button.attr( 'data-href' ),
1154
							size: $button.attr( 'data-size' ),
1155
							annotation: $button.attr( 'data-annotation' )
1156
						});
1157
1158
						$button.data( 'gplus-rendered', true );
1159
					}
1160
				});
1161
			}
1162
1163
			(function() {
1164
				var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
1165
				po.src = 'https://apis.google.com/js/plusone.js';
1166
				po.innerHTML = '{"parsetags": "explicit"}';
1167
				po.onload = renderGooglePlus1;
1168
				var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
1169
			})();
1170
1171
			jQuery( document.body ).on( 'post-load', renderGooglePlus1 );
1172
			</script>
1173
			<?php
1174
		} else {
1175
			$this->js_dialog( 'google-plus-1', array( 'width' => 480, 'height' => 550 ) );
1176
		}
1177
	}
1178
1179 View Code Duplication
	public function get_total( $post = false ) {
1180
		global $wpdb, $blog_id;
1181
1182
		$name = strtolower( $this->get_id() );
1183
1184
		if ( $post == false ) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1185
			// get total number of shares for service
1186
			return $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) );
1187
		}
1188
1189
		// get total shares for a post
1190
		return $wpdb->get_var( $wpdb->prepare( 'SELECT count FROM sharing_stats WHERE blog_id = %d AND post_id = %d AND share_service = %s', $blog_id, $post->ID, $name ) );
1191
	}
1192
}
1193
1194
class Share_Custom extends Sharing_Advanced_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1195
	private $name;
1196
	private $icon;
1197
	private $url;
1198
	public $smart = true;
1199
	public $shortname;
1200
1201
	public function get_class() {
1202
		return 'custom share-custom-' . sanitize_html_class( strtolower( $this->name ) );
1203
	}
1204
1205
	public function __construct( $id, array $settings ) {
1206
		parent::__construct( $id, $settings );
1207
1208
		$opts = $this->get_options();
0 ignored issues
show
Unused Code introduced by
$opts 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...
1209
1210
		if ( isset( $settings['name'] ) ) {
1211
			$this->name = $settings['name'];
1212
			$this->shortname = preg_replace( '/[^a-z0-9]*/', '', $settings['name'] );
1213
		}
1214
1215
		if ( isset( $settings['icon'] ) ) {
1216
			$this->icon = $settings['icon'];
1217
1218
			$new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) );
1219
			$i = 0;
1220
			while ( $new_icon != $this->icon ) {
1221
				if ( $i > 5 ) {
1222
					$this->icon = false;
1223
					break;
1224
				} else {
1225
					$this->icon = $new_icon;
1226
					$new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) );
1227
				}
1228
				$i++;
1229
			}
1230
		}
1231
1232
		if ( isset( $settings['url'] ) ) {
1233
			$this->url = $settings['url'];
1234
		}
1235
	}
1236
1237
	public function get_name() {
1238
		return $this->name;
1239
	}
1240
1241
	public function get_display( $post ) {
1242
		$str = $this->get_link( $this->get_process_request_url( $post->ID ), esc_html( $this->name ), sprintf( __( 'Click to share on %s', 'jetpack' ), esc_attr( $this->name ) ), 'share=' . $this->id );
1243
		return str_replace( '<span>', '<span style="' . esc_attr( 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");' ) . '">', $str );
1244
	}
1245
1246
	public function process_request( $post, array $post_data ) {
1247
		$url = str_replace( '&amp;', '&', $this->url );
1248
		$url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url );
1249
		$url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url );
1250
		$url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url );
1251
		$url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url );
1252
		$url = str_replace( '%home_url%', rawurlencode( home_url() ), $url );
1253
		$url = str_replace( '%post_slug%', rawurlencode( $post->post_name ), $url );
1254
1255
		if ( strpos( $url, '%post_tags%' ) !== false ) {
1256
			$tags	= get_the_tags( $post->ID );
1257
			$tagged = '';
1258
1259
			if ( $tags ) {
1260
				foreach ( $tags as $tag ) {
1261
					$tagged[] = rawurlencode( $tag->name );
1262
				}
1263
1264
				$tagged = implode( ',', $tagged );
1265
			}
1266
1267
			$url = str_replace( '%post_tags%', $tagged, $url );
1268
		}
1269
1270
		if ( strpos( $url, '%post_excerpt%' ) !== false ) {
1271
			$url_excerpt = $post->post_excerpt;
1272
			if ( empty( $url_excerpt ) ) {
1273
				$url_excerpt = $post->post_content;
1274
			}
1275
1276
			$url_excerpt = strip_tags( strip_shortcodes( $url_excerpt ) );
1277
			$url_excerpt = wp_html_excerpt( $url_excerpt, 100 );
1278
			$url_excerpt = rtrim( preg_replace( '/[^ .]*$/', '', $url_excerpt ) );
1279
			$url = str_replace( '%post_excerpt%', rawurlencode( $url_excerpt ), $url );
1280
		}
1281
1282
		// Record stats
1283
		parent::process_request( $post, $post_data );
1284
1285
		// Redirect
1286
		wp_redirect( $url );
1287
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1288
	}
1289
1290
	public function display_options() {
1291
?>
1292
<div class="input">
1293
	<table class="form-table">
1294
		<tbody>
1295
			<tr>
1296
				<th scope="row"><?php _e( 'Label', 'jetpack' ); ?></th>
1297
				<td><input type="text" name="name" value="<?php echo esc_attr( $this->name ); ?>" /></td>
1298
			</tr>
1299
1300
			<tr>
1301
				<th scope="row"><?php _e( 'URL', 'jetpack' ); ?></th>
1302
				<td><input type="text" name="url" value="<?php echo esc_attr( $this->url ); ?>" /></td>
1303
			</tr>
1304
1305
			<tr>
1306
				<th scope="row"><?php _e( 'Icon', 'jetpack' ); ?></th>
1307
				<td><input type="text" name="icon" value="<?php echo esc_attr( $this->icon ); ?>" /></td>
1308
			</tr>
1309
1310
			<tr>
1311
				<th scope="row"></th>
1312
				<td>
1313
					<input class="button-secondary" type="submit" value="<?php esc_attr_e( 'Save', 'jetpack' ); ?>" />
1314
					<a href="#" class="remove"><small><?php _e( 'Remove Service', 'jetpack' ); ?></small></a>
1315
				</td>
1316
			</tr>
1317
		</tbody>
1318
	</table>
1319
</div>
1320
<?php
1321
	}
1322
1323
	public function update_options( array $data ) {
1324
		$name  = trim( wp_html_excerpt( wp_kses( stripslashes( $data['name'] ), array() ), 30 ) );
1325
		$url   = trim( esc_url_raw( $data['url'] ) );
1326
		$icon  = trim( esc_url_raw( $data['icon'] ) );
1327
1328
		if ( $name ) {
1329
			$this->name = $name;
1330
		}
1331
1332
		if ( $url ) {
1333
			$this->url	= $url;
1334
		}
1335
1336
		if ( $icon ) {
1337
			$this->icon = $icon;
1338
		}
1339
	}
1340
1341
	public function get_options() {
1342
		return array(
1343
			'name' => $this->name,
1344
			'icon' => $this->icon,
1345
			'url'  => $this->url,
1346
		);
1347
	}
1348
1349
	public function display_preview( $echo = true, $force_smart = false, $button_style = null ) {
1350
		$opts = $this->get_options();
1351
1352
		$text = '&nbsp;';
1353
		if ( ! $this->smart ) {
1354
			if ( $this->button_style != 'icon' ) {
1355
				$text = $this->get_name();
1356
			}
1357
		}
1358
1359
		$klasses = array( 'share-' . $this->shortname );
1360
1361
		if ( $this->button_style == 'icon' || $this->button_style == 'icon-text' ) {
1362
			$klasses[] = 'share-icon';
1363
		}
1364
1365
		if ( $this->button_style == 'icon' ) {
1366
			$text = '';
1367
			$klasses[] = 'no-text';
1368
		}
1369
1370
		if ( $this->button_style == 'text' ) {
1371
			$klasses[] = 'no-icon';
1372
		}
1373
1374
		$link = sprintf(
1375
			'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span style="background-image:url(&quot;%s&quot;) !important;background-position:left center;background-repeat:no-repeat;">%s</span></a>',
1376
			implode( ' ', $klasses ),
1377
			$this->get_name(),
1378
			addcslashes( esc_url_raw( $opts['icon'] ), '"' ),
1379
			$text
1380
		);
1381
		?>
1382
		<div class="option option-smart-off">
1383
		<?php echo $link ; ?>
1384
		</div><?php
1385
	}
1386
}
1387
1388
class Share_Tumblr extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1389
	public $shortname = 'tumblr';
1390
	public $genericon = '\f214';
1391 View Code Duplication
	public function __construct( $id, array $settings ) {
1392
		parent::__construct( $id, $settings );
1393
		if ( 'official' == $this->button_style ) {
1394
			$this->smart = true;
1395
		} else { 
1396
			$this->smart = false;
1397
		}
1398
	}
1399
1400
	public function get_name() {
1401
		return __( 'Tumblr', 'jetpack' );
1402
	}
1403
1404
	public function get_display( $post ) {
1405
		if ( $this->smart ) {
1406
			$target = '';
1407
			if ( true == $this->open_link_in_new ) {
1408
				$target = '_blank';
1409
			}
1410
1411
			return '<a target="' . $target . '" href="https://www.tumblr.com/share/link/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&name=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" title="' . __( 'Share on Tumblr', 'jetpack' ) . '" style="display:inline-block; text-indent:-9999px; overflow:hidden; width:62px; height:20px; background:url(\'https://platform.tumblr.com/v1/share_2.png\') top left no-repeat transparent;">' . __( 'Share on Tumblr', 'jetpack' ) . '</a>';
1412 View Code Duplication
		 } else {
1413
			return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' );
1414
		}
1415
	}
1416
1417 View Code Duplication
	public function process_request( $post, array $post_data ) {
1418
		// Record stats
1419
		parent::process_request( $post, $post_data );
1420
1421
		// Redirect to Tumblr's sharing endpoint (a la their bookmarklet)
1422
		$url = 'https://www.tumblr.com/share?v=3&u=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&t=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '&s=';
1423
		wp_redirect( $url );
1424
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1425
	}
1426
	// http://www.tumblr.com/share?v=3&u=URL&t=TITLE&s=
1427 View Code Duplication
	public function display_footer() {
1428
		if ( $this->smart ) {
1429
			?><script type="text/javascript" src="https://platform.tumblr.com/v1/share.js"></script><?php
1430
		} else {
1431
			$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
1432
		}
1433
	}
1434
}
1435
1436
class Share_Pinterest extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1437
	public $shortname = 'pinterest';
1438
	public $genericon = '\f209';
1439
1440 View Code Duplication
	public function __construct( $id, array $settings ) {
1441
		parent::__construct( $id, $settings );
1442
		if ( 'official' == $this->button_style ) {
1443
			$this->smart = true;
1444
		} else { 
1445
			$this->smart = false;
1446
		}
1447
	}
1448
1449
	public function get_name() {
1450
		return __( 'Pinterest', 'jetpack' );
1451
	}
1452
1453
	public function get_image( $post ) {
1454
		if ( class_exists( 'Jetpack_PostImages' ) ) {
1455
			$image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) );
1456
			if ( ! empty( $image ) ) {
1457
				return $image['src'];
1458
			}
1459
		}
1460
1461
		/**
1462
		 * Filters the default image used by the Pinterest Pin It share button.
1463
		 *
1464
		 * @module sharedaddy
1465
		 *
1466
		 * @since 3.6.0
1467
		 *
1468
		 * @param string $url Default image URL.
1469
		 */
1470
		return apply_filters( 'jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg' );
1471
	}
1472
1473
	public function get_external_url( $post ) {
1474
		$url = 'https://www.pinterest.com/pin/create/button/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&media=' . rawurlencode( $this->get_image( $post ) ) . '&description=' . rawurlencode( $post->post_title );
1475
1476
		/**
1477
		 * Filters the Pinterest share URL used in sharing button output.
1478
		 *
1479
		 * @module sharedaddy
1480
		 *
1481
		 * @since 3.6.0
1482
		 *
1483
		 * @param string $url Pinterest share URL.
1484
		 */
1485
		return apply_filters( 'jetpack_sharing_pinterest_share_url', $url );
1486
	}
1487
1488
	public function get_widget_type() {
1489
		/**
1490
		 * Filters the Pinterest widget type.
1491
		 *
1492
		 * @see https://business.pinterest.com/en/widget-builder
1493
		 *
1494
		 * @module sharedaddy
1495
		 *
1496
		 * @since 3.6.0
1497
		 *
1498
		 * @param string $type Pinterest widget type. Default of 'buttonPin' for single-image selection. 'buttonBookmark' for multi-image modal.
1499
		 */
1500
		return apply_filters( 'jetpack_sharing_pinterest_widget_type', 'buttonPin' );
1501
	}
1502
1503
	public function get_display( $post ) {
1504
		$display = '';
0 ignored issues
show
Unused Code introduced by
$display 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...
1505
1506
		if ( $this->smart ) {
1507
			$display = sprintf(
1508
				'<div class="pinterest_button"><a href="%s" data-pin-do="%s" data-pin-config="beside"><img src="//assets.pinterest.com/images/pidgets/pinit_fg_en_rect_gray_20.png" /></a></div>',
1509
				esc_url( $this->get_external_url( $post ) ),
1510
				esc_attr( $this->get_widget_type() )
1511
			);
1512 View Code Duplication
		} else {
1513
			$display = $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pinterest', 'share to', 'jetpack' ), __( 'Click to share on Pinterest', 'jetpack' ), 'share=pinterest', 'sharing-pinterest-' . $post->ID );
1514
		}
1515
1516
		/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
1517
		if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) {
1518
			sharing_register_post_for_share_counts( $post->ID );
1519
		}
1520
1521
		return $display;
1522
	}
1523
1524
	public function process_request( $post, array $post_data ) {
1525
		// Record stats
1526
		parent::process_request( $post, $post_data );
1527
		// If we're triggering the multi-select panel, then we don't need to redirect to Pinterest
1528
		if ( ! isset( $_GET['js_only'] ) ) {
1529
			$pinterest_url = esc_url_raw( $this->get_external_url( $post ) );
1530
			wp_redirect( $pinterest_url );
1531
		} else {
1532
			echo '// share count bumped';
1533
		}
1534
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1535
	}
1536
1537
	public function display_footer() {
1538
		/**
1539
		 * Filter the Pin it button appearing when hovering over images when using the official button style.
1540
		 *
1541
		 * @module sharedaddy
1542
		 *
1543
		 * @since 3.6.0
1544
		 *
1545
		 * @param bool $jetpack_pinit_over True by default, displays the Pin it button when hovering over images.
1546
		 */
1547
		$jetpack_pinit_over = apply_filters( 'jetpack_pinit_over_button', true );
1548
		?>
1549
		<?php if ( $this->smart ) : ?>
1550
			<script type="text/javascript">
1551
				// Pinterest shared resources
1552
				var s = document.createElement("script");
1553
				s.type = "text/javascript";
1554
				s.async = true;
1555
				<?php if ( $jetpack_pinit_over ) { 
1556
				echo "s.setAttribute('data-pin-hover', true);";
1557
				} ?>
1558
				s.src = window.location.protocol + "//assets.pinterest.com/js/pinit.js";
1559
				var x = document.getElementsByTagName("script")[0];
1560
				x.parentNode.insertBefore(s, x);
1561
				// if 'Pin it' button has 'counts' make container wider
1562
				jQuery(window).load( function(){ jQuery( 'li.share-pinterest a span:visible' ).closest( '.share-pinterest' ).width( '80px' ); } );
1563
			</script>
1564
		<?php elseif ( 'buttonPin' != $this->get_widget_type() ) : ?>
1565
			<script type="text/javascript">
1566
				jQuery(document).ready( function(){
1567
					jQuery('body').on('click', 'a.share-pinterest', function(e){
1568
						e.preventDefault();
1569
						// Load Pinterest Bookmarklet code
1570
						var s = document.createElement("script");
1571
						s.type = "text/javascript";
1572
						s.src = window.location.protocol + "//assets.pinterest.com/js/pinmarklet.js?r=" + ( Math.random() * 99999999 );
1573
						var x = document.getElementsByTagName("script")[0];
1574
						x.parentNode.insertBefore(s, x);
1575
						// Trigger Stats
1576
						var s = document.createElement("script");
1577
						s.type = "text/javascript";
1578
						s.src = this + ( this.toString().indexOf( '?' ) ? '&' : '?' ) + 'js_only=1';
1579
						var x = document.getElementsByTagName("script")[0];
1580
						x.parentNode.insertBefore(s, x);
1581
					});
1582
				});
1583
			</script>
1584
		<?php endif;
1585
	}
1586
}
1587
1588
class Share_Pocket extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1589
	public $shortname = 'pocket';
1590
	public $genericon = '\f224';
1591
1592 View Code Duplication
	public function __construct( $id, array $settings ) {
1593
		parent::__construct( $id, $settings );
1594
1595
		if ( 'official' == $this->button_style ) {
1596
			$this->smart = true;
1597
		} else { 
1598
			$this->smart = false;
1599
		}
1600
	}
1601
1602
	public function get_name() {
1603
		return __( 'Pocket', 'jetpack' );
1604
	}
1605
1606 View Code Duplication
	public function process_request( $post, array $post_data ) {
1607
		// Record stats
1608
		parent::process_request( $post, $post_data );
1609
1610
		$pocket_url = esc_url_raw( 'https://getpocket.com/save/?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) );
1611
		wp_redirect( $pocket_url );
1612
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1613
	}
1614
1615
	public function get_display( $post ) {
1616
		if ( $this->smart ) {
1617
			$post_count = 'horizontal';
1618
1619
			$button = '';
1620
			$button .= '<div class="pocket_button">';
1621
			$button .= sprintf( '<a href="https://getpocket.com/save" class="pocket-btn" data-lang="%s" data-save-url="%s" data-pocket-count="%s" >%s</a>', 'en', esc_attr( $this->get_share_url( $post->ID ) ), $post_count, esc_attr__( 'Pocket', 'jetpack' ) );
1622
			$button .= '</div>';
1623
1624
			return $button;
1625 View Code Duplication
		} else {
1626
			return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' );
1627
		}
1628
1629
	}
1630
1631 View Code Duplication
	function display_footer() {
1632
		if ( $this->smart ) :
1633
		?>
1634
		<script>
1635
		// Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS.
1636
		function jetpack_sharing_pocket_init() {
1637
			jQuery.getScript( 'https://widgets.getpocket.com/v1/j/btn.js?v=1' );
1638
		}
1639
		jQuery( document ).ready( jetpack_sharing_pocket_init );
1640
		jQuery( document.body ).on( 'post-load', jetpack_sharing_pocket_init );
1641
		</script>
1642
		<?php
1643
		else :
1644
			$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
1645
		endif;
1646
1647
	}
1648
1649
}
1650
1651
class Share_Telegram extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1652
	public $shortname = 'telegram';
1653
1654
	public function __construct( $id, array $settings ) {
1655
		parent::__construct( $id, $settings );
1656
	}
1657
1658
	public function get_name() {
1659
		return __( 'Telegram', 'jetpack' );
1660
	}
1661 View Code Duplication
	public function process_request( $post, array $post_data ) {
1662
		// Record stats
1663
		parent::process_request( $post, $post_data );
1664
		$telegram_url = esc_url_raw( 'https://telegram.me/share/url?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&text=' . rawurlencode( $this->get_share_title( $post->ID ) ) );
1665
		wp_redirect( $telegram_url );
1666
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1667
	}
1668
1669
	public function get_display( $post ) {
1670
		return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Click to share on Telegram', 'jetpack' ), 'share=telegram' );
1671
	}
1672
1673
	function display_footer() {
1674
		$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) );
1675
	}
1676
}
1677
1678
class Jetpack_Share_WhatsApp extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1679
	public $shortname = 'jetpack-whatsapp';
1680
1681
	public function __construct( $id, array $settings ) {
1682
		parent::__construct( $id, $settings );
1683
	}
1684
1685
	public function get_name() {
1686
		return __( 'WhatsApp', 'jetpack' );
1687
	}
1688
1689
	public function get_display( $post ) {
1690
		return $this->get_link( 'whatsapp://send?text=' . rawurlencode( $this->get_share_title( $post->ID ) ) . ' ' . rawurlencode( $this->get_share_url( $post->ID ) ), _x( 'WhatsApp', 'share to', 'jetpack' ), __( 'Click to share on WhatsApp', 'jetpack' ) );
1691
	}
1692
}
1693
1694
class Share_Skype extends Sharing_Source {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class should be in its own file to aid autoloaders.

Having each class in a dedicated file usually plays nice with PSR autoloaders and is therefore a well established practice. If you use other autoloaders, you might not want to follow this rule.

Loading history...
1695
	public $shortname = 'skype';
1696
	public $genericon = '\f220';
1697
	private $share_type = 'default';
1698
1699 View Code Duplication
	public function __construct( $id, array $settings ) {
1700
		parent::__construct( $id, $settings );
1701
1702
		if ( isset( $settings['share_type'] ) ) {
1703
			$this->share_type = $settings['share_type'];
1704
		}
1705
1706
		if ( 'official' == $this->button_style ) {
1707
			$this->smart = true;
1708
		} else {
1709
			$this->smart = false;
1710
		}
1711
	}
1712
1713
	public function get_name() {
1714
		return __( 'Skype', 'jetpack' );
1715
	}
1716
1717
	public function get_display( $post ) {
1718
		if ( $this->smart ) {
1719
			$skype_share_html = sprintf(
1720
				'<div class="skype-share" data-href="%1$s" data-lang="%2$s" data-style="small" data-source="jetpack" ></div>',
1721
				esc_attr( $this->get_share_url( $post->ID ) ),
1722
				'en-US'
1723
			);
1724
			return $skype_share_html;
1725
		}
1726
1727
		/** This filter is already documented in modules/sharedaddy/sharing-sources.php */
1728
		if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'skype' ) ) {
1729
			sharing_register_post_for_share_counts( $post->ID );
1730
		}
1731
		return $this->get_link(
1732
			$this->get_process_request_url( $post->ID ), _x( 'Skype', 'share to', 'jetpack' ), __( 'Share on Skype', 'jetpack' ), 'share=skype', 'sharing-skype-' . $post->ID );
1733
	}
1734
1735 View Code Duplication
	public function process_request( $post, array $post_data ) {
1736
		$skype_url = sprintf(
1737
			'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack',
1738
			rawurlencode( $this->get_share_url( $post->ID ) ),
1739
			'en-US'
1740
		);
1741
1742
		// Record stats
1743
		parent::process_request( $post, $post_data );
1744
1745
		// Redirect to Skype
1746
		wp_redirect( $skype_url );
1747
		die();
0 ignored issues
show
Coding Style Compatibility introduced by
The method process_request() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
1748
	}
1749
1750 View Code Duplication
	public function display_footer() {
1751
		if ( $this->smart ) :
1752
		?>
1753
		<script>
1754
		(function(r, d, s) {
1755
			r.loadSkypeWebSdkAsync = r.loadSkypeWebSdkAsync || function(p) {
1756
				var js, sjs = d.getElementsByTagName(s)[0];
1757
				if (d.getElementById(p.id)) { return; }
1758
				js = d.createElement(s);
1759
				js.id = p.id;
1760
				js.src = p.scriptToLoad;
1761
				js.onload = p.callback
1762
				sjs.parentNode.insertBefore(js, sjs);
1763
			};
1764
			var p = {
1765
				scriptToLoad: 'https://swx.cdn.skype.com/shared/v/latest/skypewebsdk.js',
1766
				id: 'skype_web_sdk'
1767
			};
1768
			r.loadSkypeWebSdkAsync(p);
1769
		})(window, document, 'script');
1770
		</script>
1771
		<?php
1772
		else :
1773
			$this->js_dialog( $this->shortname, array( 'width' => 305, 'height' => 665 ) );
1774
		endif;
1775
	}
1776
}
1777