Completed
Push — sync/json-endpoints-19apr2017 ( 4d1744 )
by
unknown
64:46 queued 53:25
created

modules/shortcodes/slideshare.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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 ) ) {
0 ignored issues
show
The variable $rel seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
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 View Code Duplication
	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 View Code Duplication
	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 View Code Duplication
	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