PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.1.4
Jetpack – WP Security, Backup, Speed, & Growth v7.1.4
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 / flickr.php
flickr.php
210 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 Flickr Short Code
5 Author: kellan
6 License: BSD/GPL/public domain (take your pick)
7
8 [flickr video=http://www.flickr.com/photos/chaddles/2402990826]
9 [flickr video=2402990826]
10 [flickr video=2402990826 show_info=no]
11 [flickr video=2402990826 w=200 h=150]
12 [flickr video=2402990826 secret=846d9c1b39]
13 */
14
15 /*
16 * <object type="application/x-shockwave-flash" width="400" height="300" data="http://www.flickr.com/apps/video/stewart.swf?v=71377" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="intl_lang=en-us&photo_secret=846d9c1be9&photo_id=2345938910"></param> <param name="movie" value="http://www.flickr.com/apps/video/stewart.swf?v=71377"></param> <param name="bgcolor" value="#000000"></param> <param name="allowFullScreen" value="true"></param><embed type="application/x-shockwave-flash" src="http://www.flickr.com/apps/video/stewart.swf?v=71377" bgcolor="#000000" allowfullscreen="true" flashvars="intl_lang=en-us&photo_secret=846d9c1be9&photo_id=2345938910" height="300" width="400"></embed></object>
17 */
18
19 function flickr_embed_to_shortcode( $content ) {
20 if ( ! is_string( $content ) || false === stripos( $content, '/www.flickr.com/apps/video/stewart.swf' ) ) {
21 return $content;
22 }
23
24 $regexp = '%(<object.*?(?:<(?!/?(?:object|embed)\s+).*?)*?)?<embed((?:\s+\w+="[^"]*")*)\s+src="http(?:\:|&#0*58;)//www.flickr.com/apps/video/stewart.swf[^"]*"((?:\s+\w+="[^"]*")*)\s*(?:/>|>\s*</embed>)(?(1)\s*</object>)%';
25 $regexp_ent = str_replace(
26 array(
27 '&amp;#0*58;',
28 '[^&gt;]*',
29 '[^&lt;]*',
30 ),
31 array(
32 '&amp;#0*58;|&#0*58;',
33 '[^&]*(?:&(?!gt;)[^&]*)*',
34 '[^&]*(?:&(?!lt;)[^&]*)*',
35 ),
36 htmlspecialchars( $regexp, ENT_NOQUOTES )
37 );
38
39 foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) {
40 if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) {
41 continue;
42 }
43 foreach ( $matches as $match ) {
44 $params = $match[2] . $match[3];
45
46 if ( 'regexp_ent' == $reg ) {
47 $params = html_entity_decode( $params );
48 }
49
50 $params = wp_kses_hair( $params, array( 'http' ) );
51 if ( ! isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] || ! isset( $params['flashvars'] ) ) {
52 continue;
53 }
54
55 wp_parse_str( html_entity_decode( $params['flashvars']['value'] ), $flashvars );
56
57 if ( ! isset( $flashvars['photo_id'] ) ) {
58 continue;
59 }
60
61 $photo_id = preg_replace( '#[^A-Za-z0-9_./@+-]+#', '', $flashvars['photo_id'] );
62
63 if ( ! strlen( $photo_id ) ) {
64 continue;
65 }
66
67 $code_atts = array( 'video' => $photo_id );
68
69 if ( isset( $flashvars['flickr_show_info_box'] ) && 'true' == $flashvars['flickr_show_info_box'] ) {
70 $code_atts['show_info'] = 'true';
71 }
72
73 if ( ! empty( $flashvars['photo_secret'] ) ) {
74 $photo_secret = preg_replace( '#[^A-Za-z0-9_./@+-]+#', '', $flashvars['photo_secret'] );
75 if ( strlen( $photo_secret ) ) {
76 $code_atts['secret'] = $photo_secret;
77 }
78 }
79
80 if ( ! empty( $params['width']['value'] ) ) {
81 $code_atts['w'] = (int) $params['width']['value'];
82 }
83
84 if ( ! empty( $params['height']['value'] ) ) {
85 $code_atts['h'] = (int) $params['height']['value'];
86 }
87
88 $code = '[flickr';
89 foreach ( $code_atts as $k => $v ) {
90 $code .= " $k=$v";
91 }
92 $code .= ']';
93
94 $content = str_replace( $match[0], $code, $content );
95 /** This action is documented in modules/shortcodes/youtube.php */
96 do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $flashvars['photo_id'] );
97 }
98 }
99
100 return $content;
101 }
102
103 add_filter( 'pre_kses', 'flickr_embed_to_shortcode' );
104
105 function flickr_shortcode_handler( $atts ) {
106 $atts = shortcode_atts(
107 array(
108 'video' => 0,
109 'photo' => 0,
110 'show_info' => 0,
111 'w' => 400,
112 'h' => 300,
113 'secret' => 0,
114 ),
115 $atts,
116 'flickr'
117 );
118
119 if ( ! empty( $atts['video'] ) ) {
120 $showing = 'video';
121 $src = $atts['video'];
122 } elseif ( ! empty( $atts['photo'] ) ) {
123 $showing = 'photo';
124 $src = $atts['photo'];
125 } else {
126 return '';
127 }
128
129 if ( is_ssl() ) {
130 $src = str_replace( 'http://', 'https://', $src );
131 }
132
133 if ( 'video' === $showing ) {
134
135 if ( ! is_numeric( $src ) && ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
136 return '';
137 }
138
139 if ( preg_match( '!photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/([0-9]+)/?$!', $src, $m ) ) {
140 $atts['photo_id'] = $m[4];
141 } else {
142 $atts['photo_id'] = $atts['video'];
143 }
144
145 if ( ! isset( $atts['show_info'] ) || in_array( $atts['show_info'], array( 'yes', 'true' ) ) ) {
146 $atts['show_info'] = 'true';
147 } elseif ( in_array( $atts['show_info'], array( 'false', 'no' ) ) ) {
148 $atts['show_info'] = 'false';
149 }
150
151 if ( isset( $atts['secret'] ) ) {
152 $atts['secret'] = preg_replace( '![^\w]+!i', '', $atts['secret'] );
153 }
154
155 return flickr_shortcode_video_markup( $atts );
156 } elseif ( 'photo' == $showing ) {
157
158 if ( ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
159 return '';
160 }
161
162 $src = sprintf( '%s/player/', untrailingslashit( $src ) );
163
164 return sprintf( '<iframe src="%s" height="%s" width="%s" frameborder="0" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>', esc_url( $src ), esc_attr( $atts['h'] ), esc_attr( $atts['w'] ) );
165 }
166
167 return false;
168 }
169
170 function flickr_shortcode_video_markup( $atts ) {
171 $atts = array_map( 'esc_attr', $atts );
172 $http = ( is_ssl() ) ? 'https://' : 'http://';
173
174 $photo_vars = "photo_id=$atts[photo_id]";
175 if ( isset( $atts['secret'] ) ) {
176 $photo_vars .= "&amp;photo_secret=$atts[secret]";
177 }
178
179 return <<<EOD
180 <object type="application/x-shockwave-flash" width="$atts[w]" height="$atts[h]" data="{$http}www.flickr.com/apps/video/stewart.swf?v=1.161" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"> <param name="flashvars" value="$photo_vars&amp;flickr_show_info_box=$atts[show_info]"></param><param name="movie" value="{$http}www.flickr.com/apps/video/stewart.swf?v=1.161"></param><param name="bgcolor" value="#000000"></param><param name="allowFullScreen" value="true"></param><param name="wmode" value="opaque"></param><embed type="application/x-shockwave-flash" src="{$http}www.flickr.com/apps/video/stewart.swf?v=1.161" bgcolor="#000000" allowfullscreen="true" flashvars="$photo_vars&amp;flickr_show_info_box=$atts[show_info]" wmode="opaque" height="$atts[h]" width="$atts[w]"></embed></object>
181 EOD;
182 }
183
184 add_shortcode( 'flickr', 'flickr_shortcode_handler' );
185
186 // Override core's Flickr support because Flickr oEmbed doesn't support web embeds
187 wp_embed_register_handler( 'flickr', '#https?://(www\.)?flickr\.com/.*#i', 'jetpack_flickr_oembed_handler' );
188
189 function jetpack_flickr_oembed_handler( $matches, $attr, $url ) {
190 // Legacy slideshow embeds end with /show/
191 // e.g. http://www.flickr.com/photos/yarnaholic/sets/72157615194738969/show/
192 if ( '/show/' !== substr( $url, -strlen( '/show/' ) ) ) {
193 // These lookups need cached, as they don't use WP_Embed (which caches)
194 $cache_key = md5( $url . serialize( $attr ) );
195 $cache_group = 'oembed_flickr';
196
197 $html = wp_cache_get( $cache_key, $cache_group );
198
199 if ( false === $html ) {
200 $html = _wp_oembed_get_object()->get_html( $url, $attr );
201
202 wp_cache_set( $cache_key, $html, $cache_group, 60 * MINUTE_IN_SECONDS );
203 }
204
205 return $html;
206 }
207
208 return flickr_shortcode_handler( array( 'photo' => $url ) );
209 }
210