PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.7
Jetpack – WP Security, Backup, Speed, & Growth v6.7
16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 All 501 releases
jetpack / modules / shortcodes / slideshare.php

slideshare.php in Jetpack – WP Security, Backup, Speed, & Growth 6.7, at modules/shortcodes/slideshare.php

127 lines 3.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // guarantee use of https
4 wp_oembed_remove_provider( '#https?://(www\.)?slideshare\.net/.*#i' );
5 wp_oembed_add_provider( '#https?://(www\.)?slideshare\.net/.*#i', 'https://www.slideshare.net/api/oembed/2', true );
6
7 /*
8 * Slideshare shortcode format:
9 * Old style (still compatible): [slideshare id=5342235&doc=camprock-101002163655-phpapp01&w=300&h=200]
10 * New style: [slideshare id=5342235&w=300&h=200&fb=0&mw=0&mh=0&sc=no]
11 *
12 * Legend:
13 * id = Document ID provided by Slideshare
14 * w = Width of iFrame (int)
15 * h = Height of iFrame (int)
16 * fb = iFrame frameborder (int)
17 * mw = iFrame marginwidth (int)
18 * mh = iFrame marginheight (int)
19 * sc = iFrame Scrollbar (yes/no)
20 * pro = Slideshare Pro (yes/no)
21 * style = Inline CSS (string)
22 **/
23
24 add_shortcode( 'slideshare', 'slideshare_shortcode' );
25
26 function slideshare_shortcode( $atts ) {
27 global $content_width;
28
29 $params = shortcode_new_to_old_params( $atts );
30 parse_str( $params, $arguments );
31
32 if ( empty( $arguments ) ) {
33 return '<!-- SlideShare error: no arguments -->';
34 }
35
36 $attr = shortcode_atts(
37 array(
38 'id' => '',
39 'w' => '',
40 'h' => '',
41 'fb' => '',
42 'mw' => '',
43 'mh' => '',
44 'sc' => '',
45 'pro' => '',
46 'style' => '',
47 ),
48 $arguments
49 );
50
51 // check that the Slideshare ID contains letters, numbers and query strings
52 $pattern = '/[^-_a-zA-Z0-9?=&]/';
53 if ( empty( $attr['id'] ) || preg_match( $pattern, $attr['id'] ) ) {
54 return '<!-- SlideShare error: id is missing or has illegal characters -->';
55 }
56
57 // check the width/height
58 $w = $attr['w'];
59 if ( empty( $w ) && ! empty( $content_width ) ) {
60 $w = intval( $content_width );
61 } elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) {
62 $w = 425;
63 } else {
64 $w = intval( $w );
65 }
66
67 $h = ceil( $w * 348 / 425 ); // Note: user-supplied height is ignored.
68
69 if ( isset( $attr['pro'] ) && $attr['pro'] ) {
70 $source = 'https://www.slideshare.net/slidesharepro/' . $attr['id'];
71 } else {
72 $source = 'https://www.slideshare.net/slideshow/embed_code/' . $attr['id'];
73 }
74
75 if ( isset( $rel ) ) {
76 $source = add_query_arg( 'rel', intval( $rel ), $source );
77 }
78
79 if ( isset( $startSlide ) ) {
80 $source = add_query_arg( 'startSlide', intval( $startSlide ), $source );
81 }
82
83 $player = sprintf( "<iframe src='%s' width='%d' height='%d'", esc_url( $source ), $w, $h );
84
85 // check the frameborder
86 if ( ! empty( $attr['fb'] ) || '0' === $attr['fb'] ) {
87 $player .= " frameborder='" . intval( $attr['fb'] ) . "'";
88 }
89
90 // check the margin width; if not empty, cast as int
91 if ( ! empty( $attr['mw'] ) || '0' === $attr['mw'] ) {
92 $player .= " marginwidth='" . intval( $attr['mw'] ) . "'";
93 }
94
95 // check the margin height, if not empty, cast as int
96 if ( ! empty( $attr['mh'] ) || '0' === $attr['mh'] ) {
97 $player .= " marginheight='" . intval( $attr['mh'] ) . "'";
98 }
99
100 if ( ! empty( $attr['style'] ) ) {
101 $player .= " style='" . esc_attr( $attr['style'] ) . "'";
102 }
103
104 // check the scrollbar; cast as a lowercase string for comparison
105 if ( ! empty( $attr['sc'] ) ) {
106 $sc = strtolower( $attr['sc'] );
107
108 if ( in_array( $sc, array( 'yes', 'no' ) ) ) {
109 $player .= " scrolling='" . $sc . "'";
110 }
111 }
112
113 $player .= ' allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>';
114
115 /**
116 * Filter the returned SlideShare shortcode.
117 *
118 * @module shortcodes
119 *
120 * @since 4.7.0
121 *
122 * @param string $player The iframe to return.
123 * @param array $atts The attributes specified in the shortcode.
124 */
125 return apply_filters( 'jetpack_slideshare_shortcode', $player, $atts );
126 }
127