PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 6.9
Jetpack – WP Security, Backup, Speed, & Growth v6.9
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
201 lines 7.0 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 $code_atts = array( 'video' => $flashvars['photo_id'] );
62
63 if ( isset( $flashvars['flickr_show_info_box'] ) && 'true' == $flashvars['flickr_show_info_box'] ) {
64 $code_atts['show_info'] = 'true';
65 }
66
67 if ( ! empty( $flashvars['photo_secret'] ) ) {
68 $code_atts['secret'] = $flashvars['photo_secret'];
69 }
70
71 if ( ! empty( $params['width']['value'] ) ) {
72 $code_atts['w'] = (int) $params['width']['value'];
73 }
74
75 if ( ! empty( $params['height']['value'] ) ) {
76 $code_atts['h'] = (int) $params['height']['value'];
77 }
78
79 $code = '[flickr';
80 foreach ( $code_atts as $k => $v ) {
81 $code .= " $k=$v";
82 }
83 $code .= ']';
84
85 $content = str_replace( $match[0], $code, $content );
86 /** This action is documented in modules/shortcodes/youtube.php */
87 do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $flashvars['photo_id'] );
88 }
89 }
90
91 return $content;
92 }
93
94 add_filter( 'pre_kses', 'flickr_embed_to_shortcode' );
95
96 function flickr_shortcode_handler( $atts ) {
97 $atts = shortcode_atts(
98 array(
99 'video' => 0,
100 'photo' => 0,
101 'show_info' => 0,
102 'w' => 400,
103 'h' => 300,
104 'secret' => 0,
105 ),
106 $atts,
107 'flickr'
108 );
109
110 if ( ! empty( $atts['video'] ) ) {
111 $showing = 'video';
112 $src = $atts['video'];
113 } elseif ( ! empty( $atts['photo'] ) ) {
114 $showing = 'photo';
115 $src = $atts['photo'];
116 } else {
117 return '';
118 }
119
120 if ( is_ssl() ) {
121 $src = str_replace( 'http://', 'https://', $src );
122 }
123
124 if ( 'video' === $showing ) {
125
126 if ( ! is_numeric( $src ) && ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
127 return '';
128 }
129
130 if ( preg_match( '!photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/([0-9]+)/?$!', $src, $m ) ) {
131 $atts['photo_id'] = $m[4];
132 } else {
133 $atts['photo_id'] = $atts['video'];
134 }
135
136 if ( ! isset( $atts['show_info'] ) || in_array( $atts['show_info'], array( 'yes', 'true' ) ) ) {
137 $atts['show_info'] = 'true';
138 } elseif ( in_array( $atts['show_info'], array( 'false', 'no' ) ) ) {
139 $atts['show_info'] = 'false';
140 }
141
142 if ( isset( $atts['secret'] ) ) {
143 $atts['secret'] = preg_replace( '![^\w]+!i', '', $atts['secret'] );
144 }
145
146 return flickr_shortcode_video_markup( $atts );
147 } elseif ( 'photo' == $showing ) {
148
149 if ( ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
150 return '';
151 }
152
153 $src = sprintf( '%s/player/', untrailingslashit( $src ) );
154
155 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'] ) );
156 }
157
158 return false;
159 }
160
161 function flickr_shortcode_video_markup( $atts ) {
162 $atts = array_map( 'esc_attr', $atts );
163 $http = ( is_ssl() ) ? 'https://' : 'http://';
164
165 $photo_vars = "photo_id=$atts[photo_id]";
166 if ( isset( $atts['secret'] ) ) {
167 $photo_vars .= "&amp;photo_secret=$atts[secret]";
168 }
169
170 return <<<EOD
171 <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>
172 EOD;
173 }
174
175 add_shortcode( 'flickr', 'flickr_shortcode_handler' );
176
177 // Override core's Flickr support because Flickr oEmbed doesn't support web embeds
178 wp_embed_register_handler( 'flickr', '#https?://(www\.)?flickr\.com/.*#i', 'jetpack_flickr_oembed_handler' );
179
180 function jetpack_flickr_oembed_handler( $matches, $attr, $url ) {
181 // Legacy slideshow embeds end with /show/
182 // e.g. http://www.flickr.com/photos/yarnaholic/sets/72157615194738969/show/
183 if ( '/show/' !== substr( $url, -strlen( '/show/' ) ) ) {
184 // These lookups need cached, as they don't use WP_Embed (which caches)
185 $cache_key = md5( $url . serialize( $attr ) );
186 $cache_group = 'oembed_flickr';
187
188 $html = wp_cache_get( $cache_key, $cache_group );
189
190 if ( false === $html ) {
191 $html = _wp_oembed_get_object()->get_html( $url, $attr );
192
193 wp_cache_set( $cache_key, $html, $cache_group, 60 * MINUTE_IN_SECONDS );
194 }
195
196 return $html;
197 }
198
199 return flickr_shortcode_handler( array( 'photo' => $url ) );
200 }
201