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 is_deprecated() { |
34
|
|
|
return false; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function http() { |
38
|
|
|
return is_ssl() ? 'https' : 'http'; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function get_id() { |
42
|
|
|
return $this->id; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function get_class() { |
46
|
|
|
return $this->id; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function get_share_url( $post_id ) { |
50
|
|
|
/** |
51
|
|
|
* Filter the sharing permalink. |
52
|
|
|
* |
53
|
|
|
* @module sharedaddy |
54
|
|
|
* |
55
|
|
|
* @since 1.2.0 |
56
|
|
|
* |
57
|
|
|
* @param string get_permalink( $post_id ) Post Permalink. |
58
|
|
|
* @param int $post_id Post ID. |
59
|
|
|
* @param int $this->id Sharing ID. |
60
|
|
|
*/ |
61
|
|
|
return apply_filters( 'sharing_permalink', get_permalink( $post_id ), $post_id, $this->id ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function get_share_title( $post_id ) { |
65
|
|
|
$post = get_post( $post_id ); |
66
|
|
|
/** |
67
|
|
|
* Filter the sharing title. |
68
|
|
|
* |
69
|
|
|
* @module sharedaddy |
70
|
|
|
* |
71
|
|
|
* @since 2.8.0 |
72
|
|
|
* |
73
|
|
|
* @param string $post->post_title Post Title. |
74
|
|
|
* @param int $post_id Post ID. |
75
|
|
|
* @param int $this->id Sharing ID. |
76
|
|
|
*/ |
77
|
|
|
$title = apply_filters( 'sharing_title', $post->post_title, $post_id, $this->id ); |
78
|
|
|
|
79
|
|
|
return html_entity_decode( wp_kses( $title, null ) ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function has_custom_button_style() { |
83
|
|
|
return false; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function get_link( $url, $text, $title, $query = '', $id = false ) { |
87
|
|
|
$args = func_get_args(); |
88
|
|
|
$klasses = array( 'share-' . $this->get_class(), 'sd-button' ); |
89
|
|
|
|
90
|
|
|
if ( 'icon' == $this->button_style || 'icon-text' == $this->button_style ) { |
91
|
|
|
$klasses[] = 'share-icon'; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
if ( 'icon' == $this->button_style ) { |
95
|
|
|
$text = $title; |
96
|
|
|
$klasses[] = 'no-text'; |
97
|
|
|
|
98
|
|
|
if ( true == $this->open_link_in_new ) { |
99
|
|
|
$text .= __( ' (Opens in new window)', 'jetpack' ); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* Filter the sharing display ID. |
105
|
|
|
* |
106
|
|
|
* @module sharedaddy |
107
|
|
|
* |
108
|
|
|
* @since 3.4.0 |
109
|
|
|
* |
110
|
|
|
* @param int|false $id Sharing ID. |
111
|
|
|
* @param object $this Sharing service properties. |
112
|
|
|
* @param array $args Array of sharing service options. |
113
|
|
|
*/ |
114
|
|
|
$id = apply_filters( 'jetpack_sharing_display_id', $id, $this, $args ); |
115
|
|
|
/** |
116
|
|
|
* Filter the sharing display link. |
117
|
|
|
* |
118
|
|
|
* @module sharedaddy |
119
|
|
|
* |
120
|
|
|
* @since 2.8.0 |
121
|
|
|
* |
122
|
|
|
* @param string $url Post URL. |
123
|
|
|
* @param object $this Sharing service properties. |
124
|
|
|
* @param int|false $id Sharing ID. |
125
|
|
|
* @param array $args Array of sharing service options. |
126
|
|
|
*/ |
127
|
|
|
$url = apply_filters( 'sharing_display_link', $url, $this, $id, $args ); // backwards compatibility |
128
|
|
|
/** |
129
|
|
|
* Filter the sharing display link. |
130
|
|
|
* |
131
|
|
|
* @module sharedaddy |
132
|
|
|
* |
133
|
|
|
* @since 2.8.0 |
134
|
|
|
* |
135
|
|
|
* @param string $url Post URL. |
136
|
|
|
* @param object $this Sharing service properties. |
137
|
|
|
* @param int|false $id Sharing ID. |
138
|
|
|
* @param array $args Array of sharing service options. |
139
|
|
|
*/ |
140
|
|
|
$url = apply_filters( 'jetpack_sharing_display_link', $url, $this, $id, $args ); |
141
|
|
|
/** |
142
|
|
|
* Filter the sharing display query. |
143
|
|
|
* |
144
|
|
|
* @module sharedaddy |
145
|
|
|
* |
146
|
|
|
* @since 2.8.0 |
147
|
|
|
* |
148
|
|
|
* @param string $query Sharing service URL parameter. |
149
|
|
|
* @param object $this Sharing service properties. |
150
|
|
|
* @param int|false $id Sharing ID. |
151
|
|
|
* @param array $args Array of sharing service options. |
152
|
|
|
*/ |
153
|
|
|
$query = apply_filters( 'jetpack_sharing_display_query', $query, $this, $id, $args ); |
154
|
|
|
|
155
|
|
|
if ( ! empty( $query ) ) { |
156
|
|
|
if ( false === stripos( $url, '?' ) ) { |
157
|
|
|
$url .= '?' . $query; |
158
|
|
|
} else { |
159
|
|
|
$url .= '&' . $query; |
160
|
|
|
} |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
if ( 'text' == $this->button_style ) { |
164
|
|
|
$klasses[] = 'no-icon'; |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Filter the sharing display classes. |
169
|
|
|
* |
170
|
|
|
* @module sharedaddy |
171
|
|
|
* |
172
|
|
|
* @since 3.4.0 |
173
|
|
|
* |
174
|
|
|
* @param array $klasses Sharing service classes. |
175
|
|
|
* @param object $this Sharing service properties. |
176
|
|
|
* @param int|false $id Sharing ID. |
177
|
|
|
* @param array $args Array of sharing service options. |
178
|
|
|
*/ |
179
|
|
|
$klasses = apply_filters( 'jetpack_sharing_display_classes', $klasses, $this, $id, $args ); |
180
|
|
|
/** |
181
|
|
|
* Filter the sharing display title. |
182
|
|
|
* |
183
|
|
|
* @module sharedaddy |
184
|
|
|
* |
185
|
|
|
* @since 3.4.0 |
186
|
|
|
* |
187
|
|
|
* @param string $title Sharing service title. |
188
|
|
|
* @param object $this Sharing service properties. |
189
|
|
|
* @param int|false $id Sharing ID. |
190
|
|
|
* @param array $args Array of sharing service options. |
191
|
|
|
*/ |
192
|
|
|
$title = apply_filters( 'jetpack_sharing_display_title', $title, $this, $id, $args ); |
193
|
|
|
/** |
194
|
|
|
* Filter the sharing display text. |
195
|
|
|
* |
196
|
|
|
* @module sharedaddy |
197
|
|
|
* |
198
|
|
|
* @since 3.4.0 |
199
|
|
|
* |
200
|
|
|
* @param string $text Sharing service text. |
201
|
|
|
* @param object $this Sharing service properties. |
202
|
|
|
* @param int|false $id Sharing ID. |
203
|
|
|
* @param array $args Array of sharing service options. |
204
|
|
|
*/ |
205
|
|
|
$text = apply_filters( 'jetpack_sharing_display_text', $text, $this, $id, $args ); |
206
|
|
|
|
207
|
|
|
return sprintf( |
208
|
|
|
'<a rel="nofollow%s" data-shared="%s" class="%s" href="%s"%s title="%s"><span%s>%s</span></a>', |
209
|
|
|
( true == $this->open_link_in_new ) ? ' noopener noreferrer' : '', |
210
|
|
|
( $id ? esc_attr( $id ) : '' ), |
211
|
|
|
implode( ' ', $klasses ), |
212
|
|
|
$url, |
213
|
|
|
( true == $this->open_link_in_new ) ? ' target="_blank"' : '', |
214
|
|
|
$title, |
215
|
|
|
( 'icon' == $this->button_style ) ? '></span><span class="sharing-screen-reader-text"' : '', |
216
|
|
|
$text |
217
|
|
|
); |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Get an unfiltered post permalink to use when generating a sharing URL with get_link. |
222
|
|
|
* Use instead of get_share_url for non-official styles as get_permalink ensures that process_request |
223
|
|
|
* will be executed more reliably, in the case that the filtered URL uses a service that strips query parameters. |
224
|
|
|
* |
225
|
|
|
* @since 3.7.0 |
226
|
|
|
* @param int $post_id Post ID. |
227
|
|
|
* @uses get_permalink |
228
|
|
|
* @return string get_permalink( $post_id ) Post permalink. |
229
|
|
|
*/ |
230
|
|
|
public function get_process_request_url( $post_id ) { |
231
|
|
|
return get_permalink( $post_id ); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
abstract public function get_name(); |
235
|
|
|
abstract public function get_display( $post ); |
236
|
|
|
|
237
|
|
|
public function display_header() { |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
public function display_footer() { |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public function has_advanced_options() { |
244
|
|
|
return false; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { |
248
|
|
|
$text = ' '; |
249
|
|
|
$button_style = ( ! empty( $button_style ) ) ? $button_style : $this->button_style; |
250
|
|
|
if ( ! $this->smart && ! $force_smart ) { |
251
|
|
|
if ( $button_style != 'icon' ) { |
252
|
|
|
$text = $this->get_name(); |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
$klasses = array( 'share-' . $this->get_class(), 'sd-button' ); |
257
|
|
|
|
258
|
|
|
if ( $button_style == 'icon' || $button_style == 'icon-text' ) { |
259
|
|
|
$klasses[] = 'share-icon'; |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
if ( $button_style == 'icon' ) { |
263
|
|
|
$klasses[] = 'no-text'; |
264
|
|
|
} |
265
|
|
|
|
266
|
|
|
if ( $button_style == 'text' ) { |
267
|
|
|
$klasses[] = 'no-icon'; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
$is_deprecated = $this->is_deprecated(); |
271
|
|
|
|
272
|
|
|
$link = sprintf( |
273
|
|
|
'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span>%s</span></a>', |
274
|
|
|
implode( ' ', $klasses ), |
275
|
|
|
esc_attr( |
276
|
|
|
$is_deprecated |
277
|
|
|
? sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $this->get_name() ) |
278
|
|
|
: $this->get_name() |
279
|
|
|
), |
280
|
|
|
esc_html( |
281
|
|
|
$is_deprecated |
282
|
|
|
? sprintf( __( '%1$s has shut down', 'jetpack' ), $this->get_name() ) |
283
|
|
|
: $text |
284
|
|
|
) |
285
|
|
|
); |
286
|
|
|
|
287
|
|
|
$smart = ( $this->smart || $force_smart ) ? 'on' : 'off'; |
288
|
|
|
$return = "<div class='option option-smart-$smart'>$link</div>"; |
289
|
|
|
if ( $echo ) { |
290
|
|
|
echo $return; |
291
|
|
|
} |
292
|
|
|
|
293
|
|
|
return $return; |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
public function get_total( $post = false ) { |
297
|
|
|
global $wpdb, $blog_id; |
298
|
|
|
|
299
|
|
|
$name = strtolower( $this->get_id() ); |
300
|
|
|
|
301
|
|
|
if ( $post == false ) { |
|
|
|
|
302
|
|
|
// get total number of shares for service |
303
|
|
|
return (int) $wpdb->get_var( $wpdb->prepare( 'SELECT SUM( count ) FROM sharing_stats WHERE blog_id = %d AND share_service = %s', $blog_id, $name ) ); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
// get total shares for a post |
307
|
|
|
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 ) ); |
308
|
|
|
} |
309
|
|
|
|
310
|
|
View Code Duplication |
public function get_posts_total() { |
311
|
|
|
global $wpdb, $blog_id; |
312
|
|
|
|
313
|
|
|
$totals = array(); |
314
|
|
|
$name = strtolower( $this->get_id() ); |
315
|
|
|
|
316
|
|
|
$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 ) ); |
317
|
|
|
|
318
|
|
|
if ( ! empty( $my_data ) ) { |
319
|
|
|
foreach ( $my_data as $row ) { |
320
|
|
|
$totals[] = new Sharing_Post_Total( $row->id, $row->total ); |
321
|
|
|
} |
322
|
|
|
} |
323
|
|
|
|
324
|
|
|
usort( $totals, array( 'Sharing_Post_Total', 'cmp' ) ); |
325
|
|
|
|
326
|
|
|
return $totals; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
public function process_request( $post, array $post_data ) { |
330
|
|
|
/** |
331
|
|
|
* Fires when a post is shared via one of the sharing buttons. |
332
|
|
|
* |
333
|
|
|
* @module sharedaddy |
334
|
|
|
* |
335
|
|
|
* @since 1.1.0 |
336
|
|
|
* |
337
|
|
|
* @param array $args Aray of information about the sharing service. |
338
|
|
|
*/ |
339
|
|
|
do_action( 'sharing_bump_stats', array( 'service' => $this, 'post' => $post ) ); |
340
|
|
|
} |
341
|
|
|
|
342
|
|
|
public function js_dialog( $name, $params = array() ) { |
343
|
|
|
if ( true !== $this->open_link_in_new ) { |
344
|
|
|
return; |
345
|
|
|
} |
346
|
|
|
|
347
|
|
|
$defaults = array( |
348
|
|
|
'menubar' => 1, |
349
|
|
|
'resizable' => 1, |
350
|
|
|
'width' => 600, |
351
|
|
|
'height' => 400, |
352
|
|
|
); |
353
|
|
|
$params = array_merge( $defaults, $params ); |
354
|
|
|
$opts = array(); |
355
|
|
|
foreach ( $params as $key => $val ) { |
356
|
|
|
$opts[] = "$key=$val"; |
357
|
|
|
} |
358
|
|
|
$opts = implode( ',', $opts ); |
359
|
|
|
|
360
|
|
|
// Add JS after sharing-js has been enqueued. |
361
|
|
|
wp_add_inline_script( 'sharing-js', |
362
|
|
|
"var windowOpen; |
363
|
|
|
jQuery( document.body ).on( 'click', 'a.share-$name', function() { |
364
|
|
|
// If there's another sharing window open, close it. |
365
|
|
|
if ( 'undefined' !== typeof windowOpen ) { |
366
|
|
|
windowOpen.close(); |
367
|
|
|
} |
368
|
|
|
windowOpen = window.open( jQuery( this ).attr( 'href' ), 'wpcom$name', '$opts' ); |
369
|
|
|
return false; |
370
|
|
|
});" |
371
|
|
|
); |
372
|
|
|
} |
373
|
|
|
} |
374
|
|
|
|
375
|
|
|
abstract class Deprecated_Sharing_Source extends Sharing_Source { |
376
|
|
|
public $button_style = 'text'; |
377
|
|
|
public $smart = false; |
378
|
|
|
protected $open_link_in_new = false; |
379
|
|
|
protected $id; |
380
|
|
|
protected $deprecated = true; |
381
|
|
|
|
382
|
|
|
final public function __construct( $id, array $settings ) { |
383
|
|
|
$this->id = $id; |
384
|
|
|
|
385
|
|
|
if ( isset( $settings['button_style'] ) ) { |
386
|
|
|
$this->button_style = $settings['button_style']; |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
|
390
|
|
|
final public function is_deprecated() { |
391
|
|
|
return true; |
392
|
|
|
} |
393
|
|
|
|
394
|
|
|
final public function get_share_url( $post_id ) { |
395
|
|
|
return get_permalink( $post_id ); |
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
final public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { |
399
|
|
|
return parent::display_preview( $echo, false, $button_style ); |
400
|
|
|
} |
401
|
|
|
|
402
|
|
|
final public function get_total( $post = false ) { |
403
|
|
|
return 0; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
final public function get_posts_total() { |
407
|
|
|
return 0; |
408
|
|
|
} |
409
|
|
|
|
410
|
|
|
final public function process_request( $post, array $post_data ) { |
411
|
|
|
parent::process_request( $post, $post_data ); |
412
|
|
|
} |
413
|
|
|
|
414
|
|
|
final public function get_display( $post ) { |
415
|
|
|
if ( current_user_can( 'manage_options' ) ) { |
416
|
|
|
return $this->display_deprecated( $post ); |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
return ''; |
420
|
|
|
} |
421
|
|
|
|
422
|
|
|
public function display_deprecated( $post ) { |
423
|
|
|
return $this->get_link( |
424
|
|
|
$this->get_share_url( $post->ID ), |
425
|
|
|
sprintf( __( '%1$s has shut down', 'jetpack' ), $this->get_name() ), |
426
|
|
|
sprintf( __( 'The %1$s service has shut down. This sharing button is not displayed to your visitors and should be removed.', 'jetpack' ), $this->get_name() ) |
427
|
|
|
); |
428
|
|
|
} |
429
|
|
|
} |
430
|
|
|
|
431
|
|
|
abstract class Sharing_Advanced_Source extends Sharing_Source { |
432
|
|
|
public function has_advanced_options() { |
433
|
|
|
return true; |
434
|
|
|
} |
435
|
|
|
|
436
|
|
|
abstract public function display_options(); |
437
|
|
|
abstract public function update_options( array $data ); |
438
|
|
|
abstract public function get_options(); |
439
|
|
|
} |
440
|
|
|
|
441
|
|
|
class Share_Email extends Sharing_Source { |
442
|
|
|
public $shortname = 'email'; |
443
|
|
|
public $icon = '\f410'; |
444
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
445
|
|
|
parent::__construct( $id, $settings ); |
446
|
|
|
|
447
|
|
|
if ( 'official' == $this->button_style ) { |
448
|
|
|
$this->smart = true; |
449
|
|
|
} else { |
450
|
|
|
$this->smart = false; |
451
|
|
|
} |
452
|
|
|
} |
453
|
|
|
|
454
|
|
|
public function get_name() { |
455
|
|
|
return _x( 'Email', 'as sharing source', 'jetpack' ); |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
// Default does nothing |
459
|
|
|
public function process_request( $post, array $post_data ) { |
460
|
|
|
$ajax = false; |
461
|
|
|
if ( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) && strtolower( $_SERVER['HTTP_X_REQUESTED_WITH'] ) == 'xmlhttprequest' ) { |
462
|
|
|
$ajax = true; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
$source_email = $target_email = $source_name = false; |
|
|
|
|
466
|
|
|
|
467
|
|
|
if ( isset( $post_data['source_email'] ) && is_email( $post_data['source_email'] ) ) { |
468
|
|
|
$source_email = $post_data['source_email']; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
if ( isset( $post_data['target_email'] ) && is_email( $post_data['target_email'] ) ) { |
472
|
|
|
$target_email = $post_data['target_email']; |
473
|
|
|
} |
474
|
|
|
|
475
|
|
|
if ( isset( $post_data['source_name'] ) && strlen( $post_data['source_name'] ) < 200 ) { |
476
|
|
|
$source_name = $post_data['source_name']; |
477
|
|
|
} elseif ( isset( $post_data['source_name'] ) ) { |
478
|
|
|
$source_name = substr( $post_data['source_name'], 0, 200 ); |
479
|
|
|
} else { |
480
|
|
|
$source_name = ''; |
481
|
|
|
} |
482
|
|
|
|
483
|
|
|
// Test email |
484
|
|
|
$error = 1; // Failure in data |
485
|
|
|
if ( empty( $post_data['source_f_name'] ) && $source_email && $target_email && $source_name ) { |
486
|
|
|
/** |
487
|
|
|
* Allow plugins to stop the email sharing button from running the shared message through Akismet. |
488
|
|
|
* |
489
|
|
|
* @module sharedaddy |
490
|
|
|
* |
491
|
|
|
* @since 1.1.0 |
492
|
|
|
* |
493
|
|
|
* @param bool true Should we check if the message isn't spam? |
494
|
|
|
* @param object $post Post information. |
495
|
|
|
* @param array $post_data Information about the shared message. |
496
|
|
|
*/ |
497
|
|
|
if ( apply_filters( 'sharing_email_check', true, $post, $post_data ) ) { |
498
|
|
|
$data = array( |
499
|
|
|
'post' => $post, |
500
|
|
|
'source' => $source_email, |
501
|
|
|
'target' => $target_email, |
502
|
|
|
'name' => $source_name, |
503
|
|
|
'sharing_source' => $this, |
504
|
|
|
); |
505
|
|
|
// todo: implement an error message when email doesn't get sent. |
506
|
|
|
/** |
507
|
|
|
* Filter whether an email can be sent from the Email sharing button. |
508
|
|
|
* |
509
|
|
|
* @module sharedaddy |
510
|
|
|
* |
511
|
|
|
* @since 1.1.0 |
512
|
|
|
* |
513
|
|
|
* @param array $data Array of information about the shared message. |
514
|
|
|
*/ |
515
|
|
|
if ( ( $data = apply_filters( 'sharing_email_can_send', $data ) ) !== false ) { |
516
|
|
|
// Record stats |
517
|
|
|
parent::process_request( $data['post'], $post_data ); |
518
|
|
|
|
519
|
|
|
/** |
520
|
|
|
* Fires when an email is sent via the Email sharing button. |
521
|
|
|
* |
522
|
|
|
* @module sharedaddy |
523
|
|
|
* |
524
|
|
|
* @since 1.1.0 |
525
|
|
|
* |
526
|
|
|
* @param array $data Array of information about the shared message. |
527
|
|
|
*/ |
528
|
|
|
do_action( 'sharing_email_send_post', $data ); |
529
|
|
|
} |
530
|
|
|
|
531
|
|
|
// Return a positive regardless of whether the user is subscribed or not |
532
|
|
|
if ( $ajax ) { |
533
|
|
|
?> |
534
|
|
|
<div class="response"> |
535
|
|
|
<div class="response-title"><?php _e( 'This post has been shared!', 'jetpack' ); ?></div> |
536
|
|
|
<div class="response-sub"><?php printf( __( 'You have shared this post with %s', 'jetpack' ), esc_html( $target_email ) ); ?></div> |
537
|
|
|
<div class="response-close"><a href="#" class="sharing_cancel"><?php _e( 'Close', 'jetpack' ); ?></a></div> |
538
|
|
|
</div> |
539
|
|
|
<?php |
540
|
|
|
} else { |
541
|
|
|
wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email' ); |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
die(); |
545
|
|
|
} else { |
546
|
|
|
$error = 2; // Email check failed |
547
|
|
|
} |
548
|
|
|
} |
549
|
|
|
|
550
|
|
|
if ( $ajax ) { |
551
|
|
|
echo $error; |
552
|
|
|
} else { |
553
|
|
|
wp_safe_redirect( get_permalink( $post->ID ) . '?shared=email&msg=fail' ); |
554
|
|
|
} |
555
|
|
|
|
556
|
|
|
die(); |
557
|
|
|
} |
558
|
|
|
|
559
|
|
|
public function get_display( $post ) { |
560
|
|
|
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' ); |
561
|
|
|
} |
562
|
|
|
|
563
|
|
|
/** |
564
|
|
|
* Outputs the hidden email dialog |
565
|
|
|
*/ |
566
|
|
|
public function display_footer() { |
567
|
|
|
global $current_user; |
568
|
|
|
|
569
|
|
|
$visible = $status = false; |
|
|
|
|
570
|
|
|
?> |
571
|
|
|
<div id="sharing_email" style="display: none;"> |
572
|
|
|
<form action="<?php echo esc_url( $_SERVER['REQUEST_URI'] ); ?>" method="post"> |
573
|
|
|
<label for="target_email"><?php _e( 'Send to Email Address', 'jetpack' ) ?></label> |
574
|
|
|
<input type="email" name="target_email" id="target_email" value="" /> |
575
|
|
|
|
576
|
|
|
<?php if ( is_user_logged_in() ) : ?> |
577
|
|
|
<input type="hidden" name="source_name" value="<?php echo esc_attr( $current_user->display_name ); ?>" /> |
578
|
|
|
<input type="hidden" name="source_email" value="<?php echo esc_attr( $current_user->user_email ); ?>" /> |
579
|
|
|
<?php else : ?> |
580
|
|
|
|
581
|
|
|
<label for="source_name"><?php _e( 'Your Name', 'jetpack' ) ?></label> |
582
|
|
|
<input type="text" name="source_name" id="source_name" value="" /> |
583
|
|
|
|
584
|
|
|
<label for="source_email"><?php _e( 'Your Email Address', 'jetpack' ) ?></label> |
585
|
|
|
<input type="email" name="source_email" id="source_email" value="" /> |
586
|
|
|
|
587
|
|
|
<?php endif; ?> |
588
|
|
|
<input type="text" id="jetpack-source_f_name" name="source_f_name" class="input" value="" size="25" autocomplete="off" title="<?php esc_attr_e( 'This field is for validation and should not be changed', 'jetpack' ); ?>" /> |
589
|
|
|
<?php |
590
|
|
|
/** |
591
|
|
|
* Fires when the Email sharing dialog is loaded. |
592
|
|
|
* |
593
|
|
|
* @module sharedaddy |
594
|
|
|
* |
595
|
|
|
* @since 1.1.0 |
596
|
|
|
* |
597
|
|
|
* @param string jetpack Eail sharing source. |
598
|
|
|
*/ |
599
|
|
|
do_action( 'sharing_email_dialog', 'jetpack' ); |
600
|
|
|
?> |
601
|
|
|
|
602
|
|
|
<img style="float: right; display: none" class="loading" src="<?php |
603
|
|
|
/** This filter is documented in modules/stats.php */ |
604
|
|
|
echo apply_filters( 'jetpack_static_url', plugin_dir_url( __FILE__ ) . 'images/loading.gif' ); ?>" alt="loading" width="16" height="16" /> |
605
|
|
|
<input type="submit" value="<?php esc_attr_e( 'Send Email', 'jetpack' ); ?>" class="sharing_send" /> |
606
|
|
|
<a rel="nofollow" href="#cancel" class="sharing_cancel" role="button"><?php _e( 'Cancel', 'jetpack' ); ?></a> |
607
|
|
|
|
608
|
|
|
<div class="errors errors-1" style="display: none;"> |
609
|
|
|
<?php _e( 'Post was not sent - check your email addresses!', 'jetpack' ); ?> |
610
|
|
|
</div> |
611
|
|
|
|
612
|
|
|
<div class="errors errors-2" style="display: none;"> |
613
|
|
|
<?php _e( 'Email check failed, please try again', 'jetpack' ); ?> |
614
|
|
|
</div> |
615
|
|
|
|
616
|
|
|
<div class="errors errors-3" style="display: none;"> |
617
|
|
|
<?php _e( 'Sorry, your blog cannot share posts by email.', 'jetpack' ); ?> |
618
|
|
|
</div> |
619
|
|
|
</form> |
620
|
|
|
</div> |
621
|
|
|
<?php |
622
|
|
|
} |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
class Share_Twitter extends Sharing_Source { |
626
|
|
|
public $shortname = 'twitter'; |
627
|
|
|
public $icon = '\f202'; |
628
|
|
|
// 'https://dev.twitter.com/rest/reference/get/help/configuration' ( 2015/02/06 ) short_url_length is 22, short_url_length_https is 23 |
629
|
|
|
public $short_url_length = 24; |
630
|
|
|
|
631
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
632
|
|
|
parent::__construct( $id, $settings ); |
633
|
|
|
|
634
|
|
|
if ( 'official' == $this->button_style ) { |
635
|
|
|
$this->smart = true; |
636
|
|
|
} else { |
637
|
|
|
$this->smart = false; |
638
|
|
|
} |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
public function get_name() { |
642
|
|
|
return __( 'Twitter', 'jetpack' ); |
643
|
|
|
} |
644
|
|
|
|
645
|
|
|
/** |
646
|
|
|
* Determine the Twitter 'via' value for a post. |
647
|
|
|
* |
648
|
|
|
* @param WP_Post|int $post Post object or post ID. |
649
|
|
|
* @return string Twitter handle without the preceding @. |
650
|
|
|
**/ |
651
|
|
|
public static function sharing_twitter_via( $post ) { |
652
|
|
|
$post = get_post( $post ); |
653
|
|
|
/** |
654
|
|
|
* Allow third-party plugins to customize the Twitter username used as "twitter:site" Twitter Card Meta Tag. |
655
|
|
|
* |
656
|
|
|
* @module sharedaddy |
657
|
|
|
* |
658
|
|
|
* @since 3.0.0 |
659
|
|
|
* |
660
|
|
|
* @param string $string Twitter Username. |
661
|
|
|
* @param array $args Array of Open Graph Meta Tags and Twitter Cards tags. |
662
|
|
|
*/ |
663
|
|
|
$twitter_site_tag_value = apply_filters( |
664
|
|
|
'jetpack_twitter_cards_site_tag', |
665
|
|
|
'', |
666
|
|
|
/** This action is documented in modules/sharedaddy/sharing-sources.php */ |
667
|
|
|
array( 'twitter:creator' => apply_filters( 'jetpack_sharing_twitter_via', '', $post->ID ) ) |
668
|
|
|
); |
669
|
|
|
|
670
|
|
|
/* |
671
|
|
|
* Hack to remove the unwanted behavior of adding 'via @jetpack' which |
672
|
|
|
* was introduced with the adding of the Twitter cards. |
673
|
|
|
* This should be a temporary solution until a better method is setup. |
674
|
|
|
*/ |
675
|
|
|
if ( 'jetpack' == $twitter_site_tag_value ) { |
676
|
|
|
$twitter_site_tag_value = ''; |
677
|
|
|
} |
678
|
|
|
|
679
|
|
|
/** |
680
|
|
|
* Filters the Twitter username used as "via" in the Twitter sharing button. |
681
|
|
|
* |
682
|
|
|
* @module sharedaddy |
683
|
|
|
* |
684
|
|
|
* @since 1.7.0 |
685
|
|
|
* |
686
|
|
|
* @param string $twitter_site_tag_value Twitter Username. |
687
|
|
|
* @param int $post->ID Post ID. |
688
|
|
|
*/ |
689
|
|
|
$twitter_site_tag_value = apply_filters( 'jetpack_sharing_twitter_via', $twitter_site_tag_value, $post->ID ); |
690
|
|
|
|
691
|
|
|
// Strip out anything other than a letter, number, or underscore. |
692
|
|
|
// This will prevent the inadvertent inclusion of an extra @, as well as normalizing the handle. |
693
|
|
|
return preg_replace( '/[^\da-z_]+/i', '', $twitter_site_tag_value ); |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* Determine the 'related' Twitter accounts for a post. |
698
|
|
|
* |
699
|
|
|
* @param WP_Post|int $post Post object or post ID. |
700
|
|
|
* @return string Comma-separated list of Twitter handles. |
701
|
|
|
**/ |
702
|
|
|
public static function get_related_accounts( $post ) { |
703
|
|
|
$post = get_post( $post ); |
704
|
|
|
/** |
705
|
|
|
* Filter the list of related Twitter accounts added to the Twitter sharing button. |
706
|
|
|
* |
707
|
|
|
* @module sharedaddy |
708
|
|
|
* |
709
|
|
|
* @since 1.7.0 |
710
|
|
|
* |
711
|
|
|
* @param array $args Array of Twitter usernames. Format is 'username' => 'Optional description' |
712
|
|
|
* @param int $post->ID Post ID. |
713
|
|
|
*/ |
714
|
|
|
$related_accounts = apply_filters( 'jetpack_sharing_twitter_related', array(), $post->ID ); |
715
|
|
|
|
716
|
|
|
// Example related string: account1,account2:Account 2 description,account3 |
717
|
|
|
$related = array(); |
718
|
|
|
|
719
|
|
|
foreach ( $related_accounts as $related_account_username => $related_account_description ) { |
720
|
|
|
// Join the description onto the end of the username |
721
|
|
|
if ( $related_account_description ) { |
722
|
|
|
$related_account_username .= ':' . $related_account_description; |
723
|
|
|
} |
724
|
|
|
|
725
|
|
|
$related[] = $related_account_username; |
726
|
|
|
} |
727
|
|
|
|
728
|
|
|
return implode( ',', $related ); |
729
|
|
|
} |
730
|
|
|
|
731
|
|
|
public function get_display( $post ) { |
732
|
|
|
$via = $this->sharing_twitter_via( $post ); |
733
|
|
|
|
734
|
|
|
if ( $via ) { |
735
|
|
|
$via = 'data-via="' . esc_attr( $via ) . '"'; |
736
|
|
|
} else { |
737
|
|
|
$via = ''; |
738
|
|
|
} |
739
|
|
|
|
740
|
|
|
$related = $this->get_related_accounts( $post ); |
741
|
|
|
if ( ! empty( $related ) && $related !== $via ) { |
742
|
|
|
$related = 'data-related="' . esc_attr( $related ) . '"'; |
743
|
|
|
} else { |
744
|
|
|
$related = ''; |
745
|
|
|
} |
746
|
|
|
|
747
|
|
|
if ( $this->smart ) { |
748
|
|
|
$share_url = $this->get_share_url( $post->ID ); |
749
|
|
|
$post_title = $this->get_share_title( $post->ID ); |
750
|
|
|
return sprintf( |
751
|
|
|
'<a href="https://twitter.com/share" class="twitter-share-button" data-url="%1$s" data-text="%2$s" %3$s %4$s>Tweet</a>', |
752
|
|
|
esc_url( $share_url ), |
753
|
|
|
esc_attr( $post_title ), |
754
|
|
|
$via, |
755
|
|
|
$related |
756
|
|
|
); |
757
|
|
|
} else { |
758
|
|
|
if ( |
759
|
|
|
/** |
760
|
|
|
* Allow plugins to disable sharing counts for specific sharing services. |
761
|
|
|
* |
762
|
|
|
* @module sharedaddy |
763
|
|
|
* |
764
|
|
|
* @since 3.0.0 |
765
|
|
|
* |
766
|
|
|
* @param bool true Should sharing counts be enabled for this specific service. Default to true. |
767
|
|
|
* @param int $post->ID Post ID. |
768
|
|
|
* @param string $str Sharing service name. |
769
|
|
|
*/ |
770
|
|
|
apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'twitter' ) |
771
|
|
|
) { |
772
|
|
|
sharing_register_post_for_share_counts( $post->ID ); |
773
|
|
|
} |
774
|
|
|
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 ); |
775
|
|
|
} |
776
|
|
|
} |
777
|
|
|
|
778
|
|
|
public function process_request( $post, array $post_data ) { |
779
|
|
|
$post_title = $this->get_share_title( $post->ID ); |
780
|
|
|
$post_link = $this->get_share_url( $post->ID ); |
781
|
|
|
|
782
|
|
|
if ( function_exists( 'mb_stripos' ) ) { |
783
|
|
|
$strlen = 'mb_strlen'; |
784
|
|
|
$substr = 'mb_substr'; |
785
|
|
|
} else { |
786
|
|
|
$strlen = 'strlen'; |
787
|
|
|
$substr = 'substr'; |
788
|
|
|
} |
789
|
|
|
|
790
|
|
|
$via = $this->sharing_twitter_via( $post ); |
791
|
|
|
$related = $this->get_related_accounts( $post ); |
792
|
|
|
if ( $via ) { |
793
|
|
|
$sig = " via @$via"; |
794
|
|
|
if ( $related === $via ) { |
795
|
|
|
$related = false; |
796
|
|
|
} |
797
|
|
|
} else { |
798
|
|
|
$via = false; |
799
|
|
|
$sig = ''; |
800
|
|
|
} |
801
|
|
|
|
802
|
|
|
$suffix_length = $this->short_url_length + $strlen( $sig ); |
803
|
|
|
// $sig is handled by twitter in their 'via' argument. |
804
|
|
|
// $post_link is handled by twitter in their 'url' argument. |
805
|
|
|
if ( 280 < $strlen( $post_title ) + $suffix_length ) { |
806
|
|
|
// The -1 is for "\xE2\x80\xA6", a UTF-8 ellipsis. |
807
|
|
|
$text = $substr( $post_title, 0, 280 - $suffix_length - 1 ) . "\xE2\x80\xA6"; |
808
|
|
|
} else { |
809
|
|
|
$text = $post_title; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
// Record stats |
813
|
|
|
parent::process_request( $post, $post_data ); |
814
|
|
|
|
815
|
|
|
$url = $post_link; |
816
|
|
|
$twitter_url = add_query_arg( |
817
|
|
|
rawurlencode_deep( array_filter( compact( 'via', 'related', 'text', 'url' ) ) ), |
818
|
|
|
'https://twitter.com/intent/tweet' |
819
|
|
|
); |
820
|
|
|
|
821
|
|
|
// Redirect to Twitter |
822
|
|
|
wp_redirect( $twitter_url ); |
823
|
|
|
die(); |
824
|
|
|
} |
825
|
|
|
|
826
|
|
|
public function has_custom_button_style() { |
827
|
|
|
return $this->smart; |
828
|
|
|
} |
829
|
|
|
|
830
|
|
|
public function display_footer() { |
831
|
|
|
if ( $this->smart ) { |
832
|
|
|
?> |
833
|
|
|
<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> |
834
|
|
|
<?php |
835
|
|
|
} else { |
836
|
|
|
$this->js_dialog( $this->shortname, array( 'height' => 350 ) ); |
837
|
|
|
} |
838
|
|
|
} |
839
|
|
|
} |
840
|
|
|
|
841
|
|
|
|
842
|
|
|
class Share_Reddit extends Sharing_Source { |
843
|
|
|
public $shortname = 'reddit'; |
844
|
|
|
public $icon = '\f222'; |
845
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
846
|
|
|
parent::__construct( $id, $settings ); |
847
|
|
|
|
848
|
|
|
if ( 'official' == $this->button_style ) { |
849
|
|
|
$this->smart = true; |
850
|
|
|
} else { |
851
|
|
|
$this->smart = false; |
852
|
|
|
} |
853
|
|
|
} |
854
|
|
|
|
855
|
|
|
public function get_name() { |
856
|
|
|
return __( 'Reddit', 'jetpack' ); |
857
|
|
|
} |
858
|
|
|
|
859
|
|
|
public function get_display( $post ) { |
860
|
|
|
if ( $this->smart ) { |
861
|
|
|
return '<div class="reddit_button"><iframe src="' . $this->http() . '://www.reddit.com/static/button/button1.html?newwindow=true&width=120&url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ) . '" height="22" width="120" scrolling="no" frameborder="0"></iframe></div>'; |
862
|
|
View Code Duplication |
} else { |
863
|
|
|
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Reddit', 'share to', 'jetpack' ), __( 'Click to share on Reddit', 'jetpack' ), 'share=reddit' ); |
864
|
|
|
} |
865
|
|
|
} |
866
|
|
|
|
867
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
868
|
|
|
$reddit_url = $this->http() . '://reddit.com/submit?url=' . rawurlencode( $this->get_share_url( $post->ID ) ) . '&title=' . rawurlencode( $this->get_share_title( $post->ID ) ); |
869
|
|
|
|
870
|
|
|
// Record stats |
871
|
|
|
parent::process_request( $post, $post_data ); |
872
|
|
|
|
873
|
|
|
// Redirect to Reddit |
874
|
|
|
wp_redirect( $reddit_url ); |
875
|
|
|
die(); |
876
|
|
|
} |
877
|
|
|
} |
878
|
|
|
|
879
|
|
|
class Share_LinkedIn extends Sharing_Source { |
880
|
|
|
public $shortname = 'linkedin'; |
881
|
|
|
public $icon = '\f207'; |
882
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
883
|
|
|
parent::__construct( $id, $settings ); |
884
|
|
|
|
885
|
|
|
if ( 'official' == $this->button_style ) { |
886
|
|
|
$this->smart = true; |
887
|
|
|
} else { |
888
|
|
|
$this->smart = false; |
889
|
|
|
} |
890
|
|
|
} |
891
|
|
|
|
892
|
|
|
public function get_name() { |
893
|
|
|
return __( 'LinkedIn', 'jetpack' ); |
894
|
|
|
} |
895
|
|
|
|
896
|
|
|
public function has_custom_button_style() { |
897
|
|
|
return $this->smart; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
public function get_display( $post ) { |
901
|
|
|
$display = ''; |
902
|
|
|
|
903
|
|
|
if ( $this->smart ) { |
904
|
|
|
$share_url = $this->get_share_url( $post->ID ); |
905
|
|
|
$display .= sprintf( '<div class="linkedin_button"><script type="in/share" data-url="%s" data-counter="right"></script></div>', esc_url( $share_url ) ); |
906
|
|
View Code Duplication |
} else { |
907
|
|
|
$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 ); |
908
|
|
|
} |
909
|
|
|
|
910
|
|
|
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
911
|
|
|
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { |
912
|
|
|
sharing_register_post_for_share_counts( $post->ID ); |
913
|
|
|
} |
914
|
|
|
|
915
|
|
|
return $display; |
916
|
|
|
} |
917
|
|
|
|
918
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
919
|
|
|
|
920
|
|
|
$post_link = $this->get_share_url( $post->ID ); |
921
|
|
|
|
922
|
|
|
// Using the same URL as the official button, which is *not* LinkedIn's documented sharing link |
923
|
|
|
// https://www.linkedin.com/cws/share?url={url}&token=&isFramed=false |
924
|
|
|
$linkedin_url = add_query_arg( array( |
925
|
|
|
'url' => rawurlencode( $post_link ), |
926
|
|
|
), 'https://www.linkedin.com/cws/share?token=&isFramed=false' ); |
927
|
|
|
|
928
|
|
|
// Record stats |
929
|
|
|
parent::process_request( $post, $post_data ); |
930
|
|
|
|
931
|
|
|
// Redirect to LinkedIn |
932
|
|
|
wp_redirect( $linkedin_url ); |
933
|
|
|
die(); |
934
|
|
|
} |
935
|
|
|
|
936
|
|
View Code Duplication |
public function display_footer() { |
937
|
|
|
if ( ! $this->smart ) { |
938
|
|
|
$this->js_dialog( $this->shortname, array( 'width' => 580, 'height' => 450 ) ); |
939
|
|
|
} else { |
940
|
|
|
?><script type="text/javascript"> |
941
|
|
|
jQuery( document ).ready( function() { |
942
|
|
|
jQuery.getScript( 'https://platform.linkedin.com/in.js?async=true', function success() { |
943
|
|
|
IN.init(); |
944
|
|
|
}); |
945
|
|
|
}); |
946
|
|
|
jQuery( document.body ).on( 'post-load', function() { |
947
|
|
|
if ( typeof IN != 'undefined' ) |
948
|
|
|
IN.parse(); |
949
|
|
|
}); |
950
|
|
|
</script><?php |
951
|
|
|
} |
952
|
|
|
} |
953
|
|
|
} |
954
|
|
|
|
955
|
|
|
class Share_Facebook extends Sharing_Source { |
956
|
|
|
public $shortname = 'facebook'; |
957
|
|
|
public $icon = '\f204'; |
958
|
|
|
private $share_type = 'default'; |
959
|
|
|
|
960
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
961
|
|
|
parent::__construct( $id, $settings ); |
962
|
|
|
|
963
|
|
|
if ( isset( $settings['share_type'] ) ) { |
964
|
|
|
$this->share_type = $settings['share_type']; |
965
|
|
|
} |
966
|
|
|
|
967
|
|
|
if ( 'official' == $this->button_style ) { |
968
|
|
|
$this->smart = true; |
969
|
|
|
} else { |
970
|
|
|
$this->smart = false; |
971
|
|
|
} |
972
|
|
|
} |
973
|
|
|
|
974
|
|
|
public function get_name() { |
975
|
|
|
return __( 'Facebook', 'jetpack' ); |
976
|
|
|
} |
977
|
|
|
|
978
|
|
|
public function display_header() { |
979
|
|
|
} |
980
|
|
|
|
981
|
|
View Code Duplication |
function guess_locale_from_lang( $lang ) { |
982
|
|
|
if ( 'en' == $lang || 'en_US' == $lang || ! $lang ) { |
983
|
|
|
return 'en_US'; |
984
|
|
|
} |
985
|
|
|
|
986
|
|
|
if ( ! class_exists( 'GP_Locales' ) ) { |
987
|
|
|
if ( ! defined( 'JETPACK__GLOTPRESS_LOCALES_PATH' ) || ! file_exists( JETPACK__GLOTPRESS_LOCALES_PATH ) ) { |
988
|
|
|
return false; |
989
|
|
|
} |
990
|
|
|
|
991
|
|
|
require JETPACK__GLOTPRESS_LOCALES_PATH; |
992
|
|
|
} |
993
|
|
|
|
994
|
|
|
if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
995
|
|
|
// WP.com: get_locale() returns 'it' |
996
|
|
|
$locale = GP_Locales::by_slug( $lang ); |
997
|
|
|
} else { |
998
|
|
|
// Jetpack: get_locale() returns 'it_IT'; |
999
|
|
|
$locale = GP_Locales::by_field( 'wp_locale', $lang ); |
1000
|
|
|
} |
1001
|
|
|
|
1002
|
|
|
if ( ! $locale ) { |
1003
|
|
|
return false; |
1004
|
|
|
} |
1005
|
|
|
|
1006
|
|
|
if ( empty( $locale->facebook_locale ) ) { |
1007
|
|
|
if ( empty( $locale->wp_locale ) ) { |
1008
|
|
|
return false; |
1009
|
|
|
} else { |
1010
|
|
|
// Facebook SDK is smart enough to fall back to en_US if a |
1011
|
|
|
// locale isn't supported. Since supported Facebook locales |
1012
|
|
|
// can fall out of sync, we'll attempt to use the known |
1013
|
|
|
// wp_locale value and rely on said fallback. |
1014
|
|
|
return $locale->wp_locale; |
1015
|
|
|
} |
1016
|
|
|
} |
1017
|
|
|
|
1018
|
|
|
return $locale->facebook_locale; |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
public function get_display( $post ) { |
1022
|
|
|
if ( $this->smart ) { |
1023
|
|
|
$share_url = $this->get_share_url( $post->ID ); |
1024
|
|
|
$fb_share_html = '<div class="fb-share-button" data-href="' . esc_attr( $share_url ) . '" data-layout="button_count"></div>'; |
1025
|
|
|
/** |
1026
|
|
|
* Filter the output of the Facebook Sharing button. |
1027
|
|
|
* |
1028
|
|
|
* @module sharedaddy |
1029
|
|
|
* |
1030
|
|
|
* @since 3.6.0 |
1031
|
|
|
* |
1032
|
|
|
* @param string $fb_share_html Facebook Sharing button HTML. |
1033
|
|
|
* @param string $share_url URL of the post to share. |
1034
|
|
|
*/ |
1035
|
|
|
return apply_filters( 'jetpack_sharing_facebook_official_button_output', $fb_share_html, $share_url ); |
1036
|
|
|
} |
1037
|
|
|
|
1038
|
|
|
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
1039
|
|
|
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'facebook' ) ) { |
1040
|
|
|
sharing_register_post_for_share_counts( $post->ID ); |
1041
|
|
|
} |
1042
|
|
|
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 ); |
1043
|
|
|
} |
1044
|
|
|
|
1045
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
1046
|
|
|
$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 ) ); |
1047
|
|
|
|
1048
|
|
|
// Record stats |
1049
|
|
|
parent::process_request( $post, $post_data ); |
1050
|
|
|
|
1051
|
|
|
// Redirect to Facebook |
1052
|
|
|
wp_redirect( $fb_url ); |
1053
|
|
|
die(); |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
public function display_footer() { |
1057
|
|
|
$this->js_dialog( $this->shortname ); |
1058
|
|
|
if ( $this->smart ) { |
1059
|
|
|
$locale = $this->guess_locale_from_lang( get_locale() ); |
1060
|
|
|
if ( ! $locale ) { |
1061
|
|
|
$locale = 'en_US'; |
1062
|
|
|
} |
1063
|
|
|
/** |
1064
|
|
|
* Filter the App ID used in the official Facebook Share button. |
1065
|
|
|
* |
1066
|
|
|
* @since 3.8.0 |
1067
|
|
|
* |
1068
|
|
|
* @param int $fb_app_id Facebook App ID. Default to 249643311490 (WordPress.com's App ID). |
1069
|
|
|
*/ |
1070
|
|
|
$fb_app_id = apply_filters( 'jetpack_sharing_facebook_app_id', '249643311490' ); |
1071
|
|
|
if ( is_numeric( $fb_app_id ) ) { |
1072
|
|
|
$fb_app_id = '&appId=' . $fb_app_id; |
1073
|
|
|
} else { |
1074
|
|
|
$fb_app_id = ''; |
1075
|
|
|
} |
1076
|
|
|
?><div id="fb-root"></div> |
1077
|
|
|
<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> |
1078
|
|
|
<script> |
1079
|
|
|
jQuery( document.body ).on( 'post-load', function() { |
1080
|
|
|
if ( 'undefined' !== typeof FB ) { |
1081
|
|
|
FB.XFBML.parse(); |
1082
|
|
|
} |
1083
|
|
|
} ); |
1084
|
|
|
</script> |
1085
|
|
|
<?php |
1086
|
|
|
} |
1087
|
|
|
} |
1088
|
|
|
} |
1089
|
|
|
|
1090
|
|
|
class Share_Print extends Sharing_Source { |
1091
|
|
|
public $shortname = 'print'; |
1092
|
|
|
public $icon = '\f469'; |
1093
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
1094
|
|
|
parent::__construct( $id, $settings ); |
1095
|
|
|
|
1096
|
|
|
if ( 'official' == $this->button_style ) { |
1097
|
|
|
$this->smart = true; |
1098
|
|
|
} else { |
1099
|
|
|
$this->smart = false; |
1100
|
|
|
} |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
|
|
public function get_name() { |
1104
|
|
|
return __( 'Print', 'jetpack' ); |
1105
|
|
|
} |
1106
|
|
|
|
1107
|
|
|
public function get_display( $post ) { |
1108
|
|
|
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' ) ); |
1109
|
|
|
} |
1110
|
|
|
} |
1111
|
|
|
|
1112
|
|
|
class Share_PressThis extends Sharing_Source { |
1113
|
|
|
public $shortname = 'pressthis'; |
1114
|
|
|
public $icon = '\f205'; |
1115
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
1116
|
|
|
parent::__construct( $id, $settings ); |
1117
|
|
|
|
1118
|
|
|
if ( 'official' == $this->button_style ) { |
1119
|
|
|
$this->smart = true; |
1120
|
|
|
} else { |
1121
|
|
|
$this->smart = false; |
1122
|
|
|
} |
1123
|
|
|
} |
1124
|
|
|
|
1125
|
|
|
public function get_name() { |
1126
|
|
|
return __( 'Press This', 'jetpack' ); |
1127
|
|
|
} |
1128
|
|
|
|
1129
|
|
|
public function process_request( $post, array $post_data ) { |
1130
|
|
|
global $current_user; |
1131
|
|
|
|
1132
|
|
|
$primary_blog = (int) get_user_meta( $current_user->ID, 'primary_blog', true ); |
1133
|
|
|
if ( $primary_blog ) { |
1134
|
|
|
$primary_blog_details = get_blog_details( $primary_blog ); |
1135
|
|
|
} else { |
1136
|
|
|
$primary_blog_details = false; |
1137
|
|
|
} |
1138
|
|
|
|
1139
|
|
|
if ( $primary_blog_details ) { |
1140
|
|
|
$blogs = array( $primary_blog_details ); |
1141
|
|
|
} elseif ( function_exists( 'get_active_blogs_for_user' ) ) { |
1142
|
|
|
$blogs = get_active_blogs_for_user(); |
1143
|
|
|
if ( empty( $blogs ) ) { |
1144
|
|
|
$blogs = get_blogs_of_user( $current_user->ID ); |
1145
|
|
|
} |
1146
|
|
|
} else { |
1147
|
|
|
$blogs = get_blogs_of_user( $current_user->ID ); |
1148
|
|
|
} |
1149
|
|
|
|
1150
|
|
|
if ( empty( $blogs ) ) { |
1151
|
|
|
wp_safe_redirect( get_permalink( $post->ID ) ); |
1152
|
|
|
die(); |
1153
|
|
|
} |
1154
|
|
|
|
1155
|
|
|
$blog = current( $blogs ); |
1156
|
|
|
|
1157
|
|
|
$args = array( |
1158
|
|
|
'u' => rawurlencode( $this->get_share_url( $post->ID ) ), |
1159
|
|
|
); |
1160
|
|
|
|
1161
|
|
|
$args[ 'url-scan-submit' ] = 'Scan'; |
1162
|
|
|
$args[ '_wpnonce' ] = wp_create_nonce( 'scan-site' ); |
1163
|
|
|
|
1164
|
|
|
$url = $blog->siteurl . '/wp-admin/press-this.php'; |
1165
|
|
|
$url = add_query_arg( $args, $url ); |
1166
|
|
|
|
1167
|
|
|
// Record stats |
1168
|
|
|
parent::process_request( $post, $post_data ); |
1169
|
|
|
|
1170
|
|
|
// Redirect to Press This |
1171
|
|
|
wp_redirect( $url ); |
1172
|
|
|
die(); |
1173
|
|
|
} |
1174
|
|
|
|
1175
|
|
|
public function get_display( $post ) { |
1176
|
|
|
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' ); |
1177
|
|
|
} |
1178
|
|
|
} |
1179
|
|
|
|
1180
|
|
|
class Share_GooglePlus1 extends Deprecated_Sharing_Source { |
1181
|
|
|
public $shortname = 'googleplus1'; |
1182
|
|
|
|
1183
|
|
|
public function get_name() { |
1184
|
|
|
return __( 'Google+', 'jetpack' ); |
1185
|
|
|
} |
1186
|
|
|
} |
1187
|
|
|
|
1188
|
|
|
class Share_Custom extends Sharing_Advanced_Source { |
1189
|
|
|
private $name; |
1190
|
|
|
private $icon; |
1191
|
|
|
private $url; |
1192
|
|
|
public $smart = true; |
1193
|
|
|
public $shortname; |
1194
|
|
|
|
1195
|
|
|
public function get_class() { |
1196
|
|
|
return 'custom share-custom-' . sanitize_html_class( strtolower( $this->name ) ); |
1197
|
|
|
} |
1198
|
|
|
|
1199
|
|
|
public function __construct( $id, array $settings ) { |
1200
|
|
|
parent::__construct( $id, $settings ); |
1201
|
|
|
|
1202
|
|
|
$opts = $this->get_options(); |
|
|
|
|
1203
|
|
|
|
1204
|
|
|
if ( isset( $settings['name'] ) ) { |
1205
|
|
|
$this->name = $settings['name']; |
1206
|
|
|
$this->shortname = preg_replace( '/[^a-z0-9]*/', '', $settings['name'] ); |
1207
|
|
|
} |
1208
|
|
|
|
1209
|
|
|
if ( isset( $settings['icon'] ) ) { |
1210
|
|
|
$this->icon = $settings['icon']; |
1211
|
|
|
|
1212
|
|
|
$new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) ); |
1213
|
|
|
$i = 0; |
1214
|
|
|
while ( $new_icon != $this->icon ) { |
1215
|
|
|
if ( $i > 5 ) { |
1216
|
|
|
$this->icon = false; |
1217
|
|
|
break; |
1218
|
|
|
} else { |
1219
|
|
|
$this->icon = $new_icon; |
1220
|
|
|
$new_icon = esc_url_raw( wp_specialchars_decode( $this->icon, ENT_QUOTES ) ); |
1221
|
|
|
} |
1222
|
|
|
$i++; |
1223
|
|
|
} |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
if ( isset( $settings['url'] ) ) { |
1227
|
|
|
$this->url = $settings['url']; |
1228
|
|
|
} |
1229
|
|
|
} |
1230
|
|
|
|
1231
|
|
|
public function get_name() { |
1232
|
|
|
return $this->name; |
1233
|
|
|
} |
1234
|
|
|
|
1235
|
|
|
public function get_display( $post ) { |
1236
|
|
|
$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 ); |
1237
|
|
|
return str_replace( '<span>', '<span style="' . esc_attr( 'background-image:url("' . addcslashes( esc_url_raw( $this->icon ), '"' ) . '");' ) . '">', $str ); |
1238
|
|
|
} |
1239
|
|
|
|
1240
|
|
|
public function process_request( $post, array $post_data ) { |
1241
|
|
|
$url = str_replace( '&', '&', $this->url ); |
1242
|
|
|
$url = str_replace( '%post_id%', rawurlencode( $post->ID ), $url ); |
1243
|
|
|
$url = str_replace( '%post_url%', rawurlencode( $this->get_share_url( $post->ID ) ), $url ); |
1244
|
|
|
$url = str_replace( '%post_full_url%', rawurlencode( get_permalink( $post->ID ) ), $url ); |
1245
|
|
|
$url = str_replace( '%post_title%', rawurlencode( $this->get_share_title( $post->ID ) ), $url ); |
1246
|
|
|
$url = str_replace( '%home_url%', rawurlencode( home_url() ), $url ); |
1247
|
|
|
$url = str_replace( '%post_slug%', rawurlencode( $post->post_name ), $url ); |
1248
|
|
|
|
1249
|
|
|
if ( strpos( $url, '%post_tags%' ) !== false ) { |
1250
|
|
|
$tags = get_the_tags( $post->ID ); |
1251
|
|
|
$tagged = ''; |
1252
|
|
|
|
1253
|
|
|
if ( $tags ) { |
1254
|
|
|
$tagged_raw = array(); |
1255
|
|
|
foreach ( $tags as $tag ) { |
1256
|
|
|
$tagged_raw[] = rawurlencode( $tag->name ); |
1257
|
|
|
} |
1258
|
|
|
|
1259
|
|
|
$tagged = implode( ',', $tagged_raw ); |
1260
|
|
|
} |
1261
|
|
|
|
1262
|
|
|
$url = str_replace( '%post_tags%', $tagged, $url ); |
1263
|
|
|
} |
1264
|
|
|
|
1265
|
|
|
if ( strpos( $url, '%post_excerpt%' ) !== false ) { |
1266
|
|
|
$url_excerpt = $post->post_excerpt; |
1267
|
|
|
if ( empty( $url_excerpt ) ) { |
1268
|
|
|
$url_excerpt = $post->post_content; |
1269
|
|
|
} |
1270
|
|
|
|
1271
|
|
|
$url_excerpt = strip_tags( strip_shortcodes( $url_excerpt ) ); |
1272
|
|
|
$url_excerpt = wp_html_excerpt( $url_excerpt, 100 ); |
1273
|
|
|
$url_excerpt = rtrim( preg_replace( '/[^ .]*$/', '', $url_excerpt ) ); |
1274
|
|
|
$url = str_replace( '%post_excerpt%', rawurlencode( $url_excerpt ), $url ); |
1275
|
|
|
} |
1276
|
|
|
|
1277
|
|
|
// Record stats |
1278
|
|
|
parent::process_request( $post, $post_data ); |
1279
|
|
|
|
1280
|
|
|
// Redirect |
1281
|
|
|
wp_redirect( $url ); |
1282
|
|
|
die(); |
1283
|
|
|
} |
1284
|
|
|
|
1285
|
|
|
public function display_options() { |
1286
|
|
|
?> |
1287
|
|
|
<div class="input"> |
1288
|
|
|
<table class="form-table"> |
1289
|
|
|
<tbody> |
1290
|
|
|
<tr> |
1291
|
|
|
<th scope="row"><?php _e( 'Label', 'jetpack' ); ?></th> |
1292
|
|
|
<td><input type="text" name="name" value="<?php echo esc_attr( $this->name ); ?>" /></td> |
1293
|
|
|
</tr> |
1294
|
|
|
|
1295
|
|
|
<tr> |
1296
|
|
|
<th scope="row"><?php _e( 'URL', 'jetpack' ); ?></th> |
1297
|
|
|
<td><input type="text" name="url" value="<?php echo esc_attr( $this->url ); ?>" /></td> |
1298
|
|
|
</tr> |
1299
|
|
|
|
1300
|
|
|
<tr> |
1301
|
|
|
<th scope="row"><?php _e( 'Icon', 'jetpack' ); ?></th> |
1302
|
|
|
<td><input type="text" name="icon" value="<?php echo esc_attr( $this->icon ); ?>" /></td> |
1303
|
|
|
</tr> |
1304
|
|
|
|
1305
|
|
|
<tr> |
1306
|
|
|
<th scope="row"></th> |
1307
|
|
|
<td> |
1308
|
|
|
<input class="button-secondary" type="submit" value="<?php esc_attr_e( 'Save', 'jetpack' ); ?>" /> |
1309
|
|
|
<a href="#" class="remove"><small><?php _e( 'Remove Service', 'jetpack' ); ?></small></a> |
1310
|
|
|
</td> |
1311
|
|
|
</tr> |
1312
|
|
|
</tbody> |
1313
|
|
|
</table> |
1314
|
|
|
</div> |
1315
|
|
|
<?php |
1316
|
|
|
} |
1317
|
|
|
|
1318
|
|
|
public function update_options( array $data ) { |
1319
|
|
|
$name = trim( wp_html_excerpt( wp_kses( stripslashes( $data['name'] ), array() ), 30 ) ); |
1320
|
|
|
$url = trim( esc_url_raw( $data['url'] ) ); |
1321
|
|
|
$icon = trim( esc_url_raw( $data['icon'] ) ); |
1322
|
|
|
|
1323
|
|
|
if ( $name ) { |
1324
|
|
|
$this->name = $name; |
1325
|
|
|
} |
1326
|
|
|
|
1327
|
|
|
if ( $url ) { |
1328
|
|
|
$this->url = $url; |
1329
|
|
|
} |
1330
|
|
|
|
1331
|
|
|
if ( $icon ) { |
1332
|
|
|
$this->icon = $icon; |
1333
|
|
|
} |
1334
|
|
|
} |
1335
|
|
|
|
1336
|
|
|
public function get_options() { |
1337
|
|
|
return array( |
1338
|
|
|
'name' => $this->name, |
1339
|
|
|
'icon' => $this->icon, |
1340
|
|
|
'url' => $this->url, |
1341
|
|
|
); |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
public function display_preview( $echo = true, $force_smart = false, $button_style = null ) { |
1345
|
|
|
$opts = $this->get_options(); |
1346
|
|
|
|
1347
|
|
|
$text = ' '; |
1348
|
|
|
if ( ! $this->smart ) { |
1349
|
|
|
if ( $this->button_style != 'icon' ) { |
1350
|
|
|
$text = $this->get_name(); |
1351
|
|
|
} |
1352
|
|
|
} |
1353
|
|
|
|
1354
|
|
|
$klasses = array( 'share-' . $this->shortname ); |
1355
|
|
|
|
1356
|
|
|
if ( $this->button_style == 'icon' || $this->button_style == 'icon-text' ) { |
1357
|
|
|
$klasses[] = 'share-icon'; |
1358
|
|
|
} |
1359
|
|
|
|
1360
|
|
|
if ( $this->button_style == 'icon' ) { |
1361
|
|
|
$text = ''; |
1362
|
|
|
$klasses[] = 'no-text'; |
1363
|
|
|
} |
1364
|
|
|
|
1365
|
|
|
if ( $this->button_style == 'text' ) { |
1366
|
|
|
$klasses[] = 'no-icon'; |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
$link = sprintf( |
1370
|
|
|
'<a rel="nofollow" class="%s" href="javascript:void(0)" title="%s"><span style="background-image:url("%s") !important;background-position:left center;background-repeat:no-repeat;">%s</span></a>', |
1371
|
|
|
implode( ' ', $klasses ), |
1372
|
|
|
$this->get_name(), |
1373
|
|
|
addcslashes( esc_url_raw( $opts['icon'] ), '"' ), |
1374
|
|
|
$text |
1375
|
|
|
); |
1376
|
|
|
?> |
1377
|
|
|
<div class="option option-smart-off"> |
1378
|
|
|
<?php echo $link ; ?> |
1379
|
|
|
</div><?php |
1380
|
|
|
} |
1381
|
|
|
} |
1382
|
|
|
|
1383
|
|
|
class Share_Tumblr extends Sharing_Source { |
1384
|
|
|
public $shortname = 'tumblr'; |
1385
|
|
|
public $icon = '\f214'; |
1386
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
1387
|
|
|
parent::__construct( $id, $settings ); |
1388
|
|
|
if ( 'official' == $this->button_style ) { |
1389
|
|
|
$this->smart = true; |
1390
|
|
|
} else { |
1391
|
|
|
$this->smart = false; |
1392
|
|
|
} |
1393
|
|
|
} |
1394
|
|
|
|
1395
|
|
|
public function get_name() { |
1396
|
|
|
return __( 'Tumblr', 'jetpack' ); |
1397
|
|
|
} |
1398
|
|
|
|
1399
|
|
|
public function get_display( $post ) { |
1400
|
|
|
if ( $this->smart ) { |
1401
|
|
|
$target = ''; |
1402
|
|
|
if ( true == $this->open_link_in_new ) { |
1403
|
|
|
$target = '_blank'; |
1404
|
|
|
} |
1405
|
|
|
|
1406
|
|
|
/** |
1407
|
|
|
* If we are looking at a single post, let Tumblr figure out the post type (text, photo, link, quote, chat, or video) |
1408
|
|
|
* based on the content available on the page. |
1409
|
|
|
* If we are not looking at a single post, content from other posts can appear on the page and Tumblr will pick that up. |
1410
|
|
|
* In this case, we want Tumblr to focus on our current post, so we will limit the post type to link, where we can give Tumblr a link to our post. |
1411
|
|
|
*/ |
1412
|
|
|
if ( ! is_single() ) { |
1413
|
|
|
$posttype = 'data-posttype="link"'; |
1414
|
|
|
} else { |
1415
|
|
|
$posttype = ''; |
1416
|
|
|
} |
1417
|
|
|
|
1418
|
|
|
// Documentation: https://www.tumblr.com/docs/en/share_button |
1419
|
|
|
return sprintf( |
1420
|
|
|
'<a class="tumblr-share-button" target="%1$s" href="%2$s" data-title="%3$s" data-content="%4$s" title="%5$s"%6$s>%5$s</a>', |
1421
|
|
|
$target, |
1422
|
|
|
'https://www.tumblr.com/share', |
1423
|
|
|
$this->get_share_title( $post->ID ), |
1424
|
|
|
$this->get_share_url( $post->ID ), |
1425
|
|
|
__( 'Share on Tumblr', 'jetpack' ), |
1426
|
|
|
$posttype |
1427
|
|
|
); |
1428
|
|
View Code Duplication |
} else { |
1429
|
|
|
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Tumblr', 'share to', 'jetpack' ), __( 'Click to share on Tumblr', 'jetpack' ), 'share=tumblr' ); |
1430
|
|
|
} |
1431
|
|
|
} |
1432
|
|
|
|
1433
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
1434
|
|
|
// Record stats |
1435
|
|
|
parent::process_request( $post, $post_data ); |
1436
|
|
|
|
1437
|
|
|
// Redirect to Tumblr's sharing endpoint (a la their bookmarklet) |
1438
|
|
|
$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='; |
1439
|
|
|
wp_redirect( $url ); |
1440
|
|
|
die(); |
1441
|
|
|
} |
1442
|
|
|
|
1443
|
|
View Code Duplication |
public function display_footer() { |
1444
|
|
|
if ( $this->smart ) { |
1445
|
|
|
?><script id="tumblr-js" type="text/javascript" src="https://assets.tumblr.com/share-button.js"></script><?php |
1446
|
|
|
} else { |
1447
|
|
|
$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); |
1448
|
|
|
} |
1449
|
|
|
} |
1450
|
|
|
} |
1451
|
|
|
|
1452
|
|
|
class Share_Pinterest extends Sharing_Source { |
1453
|
|
|
public $shortname = 'pinterest'; |
1454
|
|
|
public $icon = '\f209'; |
1455
|
|
|
|
1456
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
1457
|
|
|
parent::__construct( $id, $settings ); |
1458
|
|
|
if ( 'official' == $this->button_style ) { |
1459
|
|
|
$this->smart = true; |
1460
|
|
|
} else { |
1461
|
|
|
$this->smart = false; |
1462
|
|
|
} |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
public function get_name() { |
1466
|
|
|
return __( 'Pinterest', 'jetpack' ); |
1467
|
|
|
} |
1468
|
|
|
|
1469
|
|
|
public function get_image( $post ) { |
1470
|
|
|
if ( class_exists( 'Jetpack_PostImages' ) ) { |
1471
|
|
|
$image = Jetpack_PostImages::get_image( $post->ID, array( 'fallback_to_avatars' => true ) ); |
1472
|
|
|
if ( ! empty( $image ) ) { |
1473
|
|
|
return $image['src']; |
1474
|
|
|
} |
1475
|
|
|
} |
1476
|
|
|
|
1477
|
|
|
/** |
1478
|
|
|
* Filters the default image used by the Pinterest Pin It share button. |
1479
|
|
|
* |
1480
|
|
|
* @module sharedaddy |
1481
|
|
|
* |
1482
|
|
|
* @since 3.6.0 |
1483
|
|
|
* |
1484
|
|
|
* @param string $url Default image URL. |
1485
|
|
|
*/ |
1486
|
|
|
return apply_filters( 'jetpack_sharing_pinterest_default_image', 'https://s0.wp.com/i/blank.jpg' ); |
1487
|
|
|
} |
1488
|
|
|
|
1489
|
|
|
public function get_external_url( $post ) { |
1490
|
|
|
$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 ); |
1491
|
|
|
|
1492
|
|
|
/** |
1493
|
|
|
* Filters the Pinterest share URL used in sharing button output. |
1494
|
|
|
* |
1495
|
|
|
* @module sharedaddy |
1496
|
|
|
* |
1497
|
|
|
* @since 3.6.0 |
1498
|
|
|
* |
1499
|
|
|
* @param string $url Pinterest share URL. |
1500
|
|
|
*/ |
1501
|
|
|
return apply_filters( 'jetpack_sharing_pinterest_share_url', $url ); |
1502
|
|
|
} |
1503
|
|
|
|
1504
|
|
|
public function get_widget_type() { |
1505
|
|
|
/** |
1506
|
|
|
* Filters the Pinterest widget type. |
1507
|
|
|
* |
1508
|
|
|
* @see https://business.pinterest.com/en/widget-builder |
1509
|
|
|
* |
1510
|
|
|
* @module sharedaddy |
1511
|
|
|
* |
1512
|
|
|
* @since 3.6.0 |
1513
|
|
|
* |
1514
|
|
|
* @param string $type Pinterest widget type. Default of 'buttonPin' for single-image selection. 'buttonBookmark' for multi-image modal. |
1515
|
|
|
*/ |
1516
|
|
|
return apply_filters( 'jetpack_sharing_pinterest_widget_type', 'buttonPin' ); |
1517
|
|
|
} |
1518
|
|
|
|
1519
|
|
|
public function get_display( $post ) { |
1520
|
|
|
$display = ''; |
|
|
|
|
1521
|
|
|
|
1522
|
|
|
if ( $this->smart ) { |
1523
|
|
|
$display = sprintf( |
1524
|
|
|
'<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>', |
1525
|
|
|
esc_url( $this->get_external_url( $post ) ), |
1526
|
|
|
esc_attr( $this->get_widget_type() ) |
1527
|
|
|
); |
1528
|
|
View Code Duplication |
} else { |
1529
|
|
|
$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 ); |
1530
|
|
|
} |
1531
|
|
|
|
1532
|
|
|
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
1533
|
|
|
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'linkedin' ) ) { |
1534
|
|
|
sharing_register_post_for_share_counts( $post->ID ); |
1535
|
|
|
} |
1536
|
|
|
|
1537
|
|
|
return $display; |
1538
|
|
|
} |
1539
|
|
|
|
1540
|
|
|
public function process_request( $post, array $post_data ) { |
1541
|
|
|
// Record stats |
1542
|
|
|
parent::process_request( $post, $post_data ); |
1543
|
|
|
// If we're triggering the multi-select panel, then we don't need to redirect to Pinterest |
1544
|
|
|
if ( ! isset( $_GET['js_only'] ) ) { |
1545
|
|
|
$pinterest_url = esc_url_raw( $this->get_external_url( $post ) ); |
1546
|
|
|
wp_redirect( $pinterest_url ); |
1547
|
|
|
} else { |
1548
|
|
|
echo '// share count bumped'; |
1549
|
|
|
} |
1550
|
|
|
die(); |
1551
|
|
|
} |
1552
|
|
|
|
1553
|
|
|
public function display_footer() { |
1554
|
|
|
/** |
1555
|
|
|
* Filter the Pin it button appearing when hovering over images when using the official button style. |
1556
|
|
|
* |
1557
|
|
|
* @module sharedaddy |
1558
|
|
|
* |
1559
|
|
|
* @since 3.6.0 |
1560
|
|
|
* |
1561
|
|
|
* @param bool $jetpack_pinit_over True by default, displays the Pin it button when hovering over images. |
1562
|
|
|
*/ |
1563
|
|
|
$jetpack_pinit_over = apply_filters( 'jetpack_pinit_over_button', true ); |
1564
|
|
|
?> |
1565
|
|
|
<?php if ( $this->smart ) : ?> |
1566
|
|
|
<script type="text/javascript"> |
1567
|
|
|
// Pinterest shared resources |
1568
|
|
|
var s = document.createElement("script"); |
1569
|
|
|
s.type = "text/javascript"; |
1570
|
|
|
s.async = true; |
1571
|
|
|
<?php if ( $jetpack_pinit_over ) { |
1572
|
|
|
echo "s.setAttribute('data-pin-hover', true);"; |
1573
|
|
|
} ?> |
1574
|
|
|
s.src = window.location.protocol + "//assets.pinterest.com/js/pinit.js"; |
1575
|
|
|
var x = document.getElementsByTagName("script")[0]; |
1576
|
|
|
x.parentNode.insertBefore(s, x); |
1577
|
|
|
// if 'Pin it' button has 'counts' make container wider |
1578
|
|
|
jQuery(window).load( function(){ jQuery( 'li.share-pinterest a span:visible' ).closest( '.share-pinterest' ).width( '80px' ); } ); |
1579
|
|
|
</script> |
1580
|
|
|
<?php elseif ( 'buttonPin' != $this->get_widget_type() ) : ?> |
1581
|
|
|
<script type="text/javascript"> |
1582
|
|
|
jQuery(document).ready( function(){ |
1583
|
|
|
jQuery('body').on('click', 'a.share-pinterest', function(e){ |
1584
|
|
|
e.preventDefault(); |
1585
|
|
|
// Load Pinterest Bookmarklet code |
1586
|
|
|
var s = document.createElement("script"); |
1587
|
|
|
s.type = "text/javascript"; |
1588
|
|
|
s.src = window.location.protocol + "//assets.pinterest.com/js/pinmarklet.js?r=" + ( Math.random() * 99999999 ); |
1589
|
|
|
var x = document.getElementsByTagName("script")[0]; |
1590
|
|
|
x.parentNode.insertBefore(s, x); |
1591
|
|
|
// Trigger Stats |
1592
|
|
|
var s = document.createElement("script"); |
1593
|
|
|
s.type = "text/javascript"; |
1594
|
|
|
s.src = this + ( this.toString().indexOf( '?' ) ? '&' : '?' ) + 'js_only=1'; |
1595
|
|
|
var x = document.getElementsByTagName("script")[0]; |
1596
|
|
|
x.parentNode.insertBefore(s, x); |
1597
|
|
|
}); |
1598
|
|
|
}); |
1599
|
|
|
</script> |
1600
|
|
|
<?php endif; |
1601
|
|
|
} |
1602
|
|
|
} |
1603
|
|
|
|
1604
|
|
|
class Share_Pocket extends Sharing_Source { |
1605
|
|
|
public $shortname = 'pocket'; |
1606
|
|
|
public $icon = '\f224'; |
1607
|
|
|
|
1608
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
1609
|
|
|
parent::__construct( $id, $settings ); |
1610
|
|
|
|
1611
|
|
|
if ( 'official' == $this->button_style ) { |
1612
|
|
|
$this->smart = true; |
1613
|
|
|
} else { |
1614
|
|
|
$this->smart = false; |
1615
|
|
|
} |
1616
|
|
|
} |
1617
|
|
|
|
1618
|
|
|
public function get_name() { |
1619
|
|
|
return __( 'Pocket', 'jetpack' ); |
1620
|
|
|
} |
1621
|
|
|
|
1622
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
1623
|
|
|
// Record stats |
1624
|
|
|
parent::process_request( $post, $post_data ); |
1625
|
|
|
|
1626
|
|
|
$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 ) ) ); |
1627
|
|
|
wp_redirect( $pocket_url ); |
1628
|
|
|
exit; |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
|
|
public function get_display( $post ) { |
1632
|
|
|
if ( $this->smart ) { |
1633
|
|
|
$post_count = 'horizontal'; |
1634
|
|
|
|
1635
|
|
|
$button = ''; |
1636
|
|
|
$button .= '<div class="pocket_button">'; |
1637
|
|
|
$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' ) ); |
1638
|
|
|
$button .= '</div>'; |
1639
|
|
|
|
1640
|
|
|
return $button; |
1641
|
|
View Code Duplication |
} else { |
1642
|
|
|
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Pocket', 'share to', 'jetpack' ), __( 'Click to share on Pocket', 'jetpack' ), 'share=pocket' ); |
1643
|
|
|
} |
1644
|
|
|
|
1645
|
|
|
} |
1646
|
|
|
|
1647
|
|
View Code Duplication |
function display_footer() { |
1648
|
|
|
if ( $this->smart ) : |
1649
|
|
|
?> |
1650
|
|
|
<script> |
1651
|
|
|
// Don't use Pocket's default JS as it we need to force init new Pocket share buttons loaded via JS. |
1652
|
|
|
function jetpack_sharing_pocket_init() { |
1653
|
|
|
jQuery.getScript( 'https://widgets.getpocket.com/v1/j/btn.js?v=1' ); |
1654
|
|
|
} |
1655
|
|
|
jQuery( document ).ready( jetpack_sharing_pocket_init ); |
1656
|
|
|
jQuery( document.body ).on( 'post-load', jetpack_sharing_pocket_init ); |
1657
|
|
|
</script> |
1658
|
|
|
<?php |
1659
|
|
|
else : |
1660
|
|
|
$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); |
1661
|
|
|
endif; |
1662
|
|
|
|
1663
|
|
|
} |
1664
|
|
|
|
1665
|
|
|
} |
1666
|
|
|
|
1667
|
|
|
class Share_Telegram extends Sharing_Source { |
1668
|
|
|
public $shortname = 'telegram'; |
1669
|
|
|
|
1670
|
|
|
public function __construct( $id, array $settings ) { |
1671
|
|
|
parent::__construct( $id, $settings ); |
1672
|
|
|
} |
1673
|
|
|
|
1674
|
|
|
public function get_name() { |
1675
|
|
|
return __( 'Telegram', 'jetpack' ); |
1676
|
|
|
} |
1677
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
1678
|
|
|
// Record stats |
1679
|
|
|
parent::process_request( $post, $post_data ); |
1680
|
|
|
$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 ) ) ); |
1681
|
|
|
wp_redirect( $telegram_url ); |
1682
|
|
|
exit; |
1683
|
|
|
} |
1684
|
|
|
|
1685
|
|
|
public function get_display( $post ) { |
1686
|
|
|
return $this->get_link( $this->get_process_request_url( $post->ID ), _x( 'Telegram', 'share to', 'jetpack' ), __( 'Click to share on Telegram', 'jetpack' ), 'share=telegram' ); |
1687
|
|
|
} |
1688
|
|
|
|
1689
|
|
|
function display_footer() { |
1690
|
|
|
$this->js_dialog( $this->shortname, array( 'width' => 450, 'height' => 450 ) ); |
1691
|
|
|
} |
1692
|
|
|
} |
1693
|
|
|
|
1694
|
|
|
class Jetpack_Share_WhatsApp extends Sharing_Source { |
1695
|
|
|
public $shortname = 'jetpack-whatsapp'; |
1696
|
|
|
|
1697
|
|
|
public function __construct( $id, array $settings ) { |
1698
|
|
|
parent::__construct( $id, $settings ); |
1699
|
|
|
} |
1700
|
|
|
|
1701
|
|
|
public function get_name() { |
1702
|
|
|
return __( 'WhatsApp', 'jetpack' ); |
1703
|
|
|
} |
1704
|
|
|
|
1705
|
|
|
public function get_display( $post ) { |
1706
|
|
|
return $this->get_link( 'https://api.whatsapp.com/send?text=' . rawurlencode( $this->get_share_title( $post->ID ) . ' ' . $this->get_share_url( $post->ID ) ), _x( 'WhatsApp', 'share to', 'jetpack' ), __( 'Click to share on WhatsApp', 'jetpack' ) ); |
1707
|
|
|
} |
1708
|
|
|
} |
1709
|
|
|
|
1710
|
|
|
class Share_Skype extends Sharing_Source { |
1711
|
|
|
public $shortname = 'skype'; |
1712
|
|
|
public $icon = '\f220'; |
1713
|
|
|
private $share_type = 'default'; |
1714
|
|
|
|
1715
|
|
View Code Duplication |
public function __construct( $id, array $settings ) { |
1716
|
|
|
parent::__construct( $id, $settings ); |
1717
|
|
|
|
1718
|
|
|
if ( isset( $settings['share_type'] ) ) { |
1719
|
|
|
$this->share_type = $settings['share_type']; |
1720
|
|
|
} |
1721
|
|
|
|
1722
|
|
|
if ( 'official' == $this->button_style ) { |
1723
|
|
|
$this->smart = true; |
1724
|
|
|
} else { |
1725
|
|
|
$this->smart = false; |
1726
|
|
|
} |
1727
|
|
|
|
1728
|
|
|
} |
1729
|
|
|
|
1730
|
|
|
public function get_name() { |
1731
|
|
|
return __( 'Skype', 'jetpack' ); |
1732
|
|
|
} |
1733
|
|
|
|
1734
|
|
|
public function get_display( $post ) { |
1735
|
|
|
if ( $this->smart ) { |
1736
|
|
|
$skype_share_html = sprintf( |
1737
|
|
|
'<div class="skype-share" data-href="%1$s" data-lang="%2$s" data-style="small" data-source="jetpack" ></div>', |
1738
|
|
|
esc_attr( $this->get_share_url( $post->ID ) ), |
1739
|
|
|
'en-US' |
1740
|
|
|
); |
1741
|
|
|
return $skype_share_html; |
1742
|
|
|
} |
1743
|
|
|
|
1744
|
|
|
/** This filter is already documented in modules/sharedaddy/sharing-sources.php */ |
1745
|
|
|
if ( apply_filters( 'jetpack_register_post_for_share_counts', true, $post->ID, 'skype' ) ) { |
1746
|
|
|
sharing_register_post_for_share_counts( $post->ID ); |
1747
|
|
|
} |
1748
|
|
|
return $this->get_link( |
1749
|
|
|
$this->get_process_request_url( $post->ID ), _x( 'Skype', 'share to', 'jetpack' ), __( 'Click to share on Skype', 'jetpack' ), 'share=skype', 'sharing-skype-' . $post->ID ); |
1750
|
|
|
} |
1751
|
|
|
|
1752
|
|
View Code Duplication |
public function process_request( $post, array $post_data ) { |
1753
|
|
|
$skype_url = sprintf( |
1754
|
|
|
'https://web.skype.com/share?url=%1$s&lang=%2$s=&source=jetpack', |
1755
|
|
|
rawurlencode( $this->get_share_url( $post->ID ) ), |
1756
|
|
|
'en-US' |
1757
|
|
|
); |
1758
|
|
|
|
1759
|
|
|
// Record stats |
1760
|
|
|
parent::process_request( $post, $post_data ); |
1761
|
|
|
|
1762
|
|
|
// Redirect to Skype |
1763
|
|
|
wp_redirect( $skype_url ); |
1764
|
|
|
die(); |
1765
|
|
|
} |
1766
|
|
|
|
1767
|
|
|
public function display_footer() { |
1768
|
|
|
if ( $this->smart ) : |
1769
|
|
|
?> |
1770
|
|
|
<script> |
1771
|
|
|
(function(r, d, s) { |
1772
|
|
|
r.loadSkypeWebSdkAsync = r.loadSkypeWebSdkAsync || function(p) { |
1773
|
|
|
var js, sjs = d.getElementsByTagName(s)[0]; |
1774
|
|
|
if (d.getElementById(p.id)) { return; } |
1775
|
|
|
js = d.createElement(s); |
1776
|
|
|
js.id = p.id; |
1777
|
|
|
js.src = p.scriptToLoad; |
1778
|
|
|
js.onload = p.callback |
1779
|
|
|
sjs.parentNode.insertBefore(js, sjs); |
1780
|
|
|
}; |
1781
|
|
|
var p = { |
1782
|
|
|
scriptToLoad: 'https://swx.cdn.skype.com/shared/v/latest/skypewebsdk.js', |
1783
|
|
|
id: 'skype_web_sdk' |
1784
|
|
|
}; |
1785
|
|
|
r.loadSkypeWebSdkAsync(p); |
1786
|
|
|
})(window, document, 'script'); |
1787
|
|
|
</script> |
1788
|
|
|
<?php |
1789
|
|
|
else : |
1790
|
|
|
$this->js_dialog( $this->shortname, array( 'width' => 305, 'height' => 665 ) ); |
1791
|
|
|
endif; |
1792
|
|
|
} |
1793
|
|
|
} |
1794
|
|
|
|
When comparing two booleans, it is generally considered safer to use the strict comparison operator.