PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.3
Jetpack – WP Security, Backup, Speed, & Growth v6.3
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.3, at modules/shortcodes/slideshare.php

126 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 ), $arguments
48 );
49
50 // check that the Slideshare ID contains letters, numbers and query strings
51 $pattern = '/[^-_a-zA-Z0-9?=&]/';
52 if ( empty( $attr['id'] ) || preg_match( $pattern, $attr['id'] ) ) {
53 return '<!-- SlideShare error: id is missing or has illegal characters -->';
54 }
55
56 // check the width/height
57 $w = $attr['w'];
58 if ( empty( $w ) && ! empty( $content_width ) ) {
59 $w = intval( $content_width );
60 } elseif ( ! ( $w = intval( $w ) ) || $w < 300 || $w > 1600 ) {
61 $w = 425;
62 } else {
63 $w = intval( $w );
64 }
65
66 $h = ceil( $w * 348 / 425 ); // Note: user-supplied height is ignored.
67
68 if ( isset( $attr['pro'] ) && $attr['pro'] ) {
69 $source = 'https://www.slideshare.net/slidesharepro/' . $attr['id'];
70 } else {
71 $source = 'https://www.slideshare.net/slideshow/embed_code/' . $attr['id'];
72 }
73
74 if ( isset( $rel ) ) {
75 $source = add_query_arg( 'rel', intval( $rel ), $source );
76 }
77
78 if ( isset( $startSlide ) ) {
79 $source = add_query_arg( 'startSlide', intval( $startSlide ), $source );
80 }
81
82 $player = sprintf( "<iframe src='%s' width='%d' height='%d'", esc_url( $source ), $w, $h );
83
84 // check the frameborder
85 if ( ! empty( $attr['fb'] ) || '0' === $attr['fb'] ) {
86 $player .= " frameborder='" . intval( $attr['fb'] ) . "'";
87 }
88
89 // check the margin width; if not empty, cast as int
90 if ( ! empty( $attr['mw'] ) || '0' === $attr['mw'] ) {
91 $player .= " marginwidth='" . intval( $attr['mw'] ) . "'";
92 }
93
94 // check the margin height, if not empty, cast as int
95 if ( ! empty( $attr['mh'] ) || '0' === $attr['mh'] ) {
96 $player .= " marginheight='" . intval( $attr['mh'] ) . "'";
97 }
98
99 if ( ! empty( $attr['style'] ) ) {
100 $player .= " style='" . esc_attr( $attr['style'] ) . "'";
101 }
102
103 // check the scrollbar; cast as a lowercase string for comparison
104 if ( ! empty( $attr['sc'] ) ) {
105 $sc = strtolower( $attr['sc'] );
106
107 if ( in_array( $sc, array( 'yes', 'no' ) ) ) {
108 $player .= " scrolling='" . $sc . "'";
109 }
110 }
111
112 $player .= ' allowfullscreen webkitallowfullscreen mozallowfullscreen></iframe>';
113
114 /**
115 * Filter the returned SlideShare shortcode.
116 *
117 * @module shortcodes
118 *
119 * @since 4.7.0
120 *
121 * @param string $player The iframe to return.
122 * @param array $atts The attributes specified in the shortcode.
123 */
124 return apply_filters( 'jetpack_slideshare_shortcode', $player, $atts );
125 }
126