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7 11.7.1 11.7.2 11.7.3 11.8 11.8.3 11.8.4 11.8.5 11.8.6 11.9 11.9.1 11.9.2 11.9.3 12.0 12.0.1 12.0.2 12.1 12.1.1 12.1.2 12.2 12.2.1 12.2.2 12.3 12.3.1 12.4 12.4.1 12.5 12.5.1 12.6 12.6.1 12.6.2 12.6.3 12.7 12.7.1 12.7.2 12.8 12.8.1 12.8.2 12.9 12.9.1 12.9.2 12.9.3 12.9.4 13.0 13.0.1 13.1 13.1.1 13.1.2 13.1.3 13.1.4 13.2 13.2.1 13.2.2 13.2.3 13.3 13.3.1 13.3.2 13.4 13.4.1 13.4.2 13.4.3 13.4.4 13.5 13.5.1 13.6 13.6.1 13.7 13.7.1 13.8 13.8.1 13.8.2 13.9 13.9.1 14.0 14.1 14.2 14.2.1 14.3 14.4 14.4.1 14.5 14.6 14.7 14.8 14.9 14.9.1 15.0 15.0.1 15.0.2 15.1 15.1.1 15.2 15.3 15.3.1 15.4 15.5 15.6 15.7 15.7-a.1 15.7-a.3 15.7-a.5 15.7-a.7 15.7-beta
jetpack / modules / shortcodes / flickr.php
jetpack / modules / shortcodes Last commit date
css 1 month ago images 1 year ago img 1 month ago js 7 months ago archiveorg-book.php 7 months ago archiveorg.php 3 weeks ago archives.php 1 month ago bandcamp.php 7 months ago brightcove.php 6 months ago cartodb.php 7 months ago class.filter-embedded-html-objects.php 7 months ago codepen.php 7 months ago crowdsignal.php 6 months ago dailymotion.php 7 months ago descript.php 7 months ago facebook.php 7 months ago flatio.php 7 months ago flickr.php 6 months ago getty.php 7 months ago gist.php 7 months ago googleapps.php 7 months ago googlemaps.php 1 month ago googleplus.php 7 months ago gravatar.php 7 months ago houzz.php 7 months ago inline-pdfs.php 7 months ago instagram.php 7 months ago kickstarter.php 7 months ago mailchimp.php 3 weeks ago medium.php 7 months ago mixcloud.php 7 months ago others.php 7 months ago pinterest.php 7 months ago presentations.php 7 months ago quiz.php 7 months ago recipe.php 1 week ago scribd.php 7 months ago shortcode-utils.php 7 months ago sitemap.php 7 months ago slideshare.php 7 months ago slideshow.php 1 month ago smartframe.php 7 months ago soundcloud.php 3 weeks ago spotify.php 7 months ago ted.php 7 months ago tweet.php 7 months ago twitchtv.php 1 week ago twitter-timeline.php 7 months ago twitter.php 7 months ago unavailable.php 7 months ago untappd-menu.php 7 months ago upcoming-events.php 7 months ago ustream.php 7 months ago videopress.php 7 months ago vimeo.php 1 month ago vine.php 7 months ago vr.php 1 month ago wufoo.php 7 months ago youtube.php 4 months ago
flickr.php
329 lines
1 <?php
2 /**
3 * Flickr Short Code
4 * Author: kellan
5 * License: BSD/GPL/public domain (take your pick)
6 *
7 * [flickr video=www.flickr.com/photos/kalakeli/49931239842]
8 * [flickr video=49931239842]
9 * [flickr video=49931239842 w=200 h=150]
10 * [flickr video=49931239842 autoplay="yes" controls="no"]
11 * [flickr video=49931239842 autoplay="no" controls="yes" w=200 h=150]
12 *
13 * <div class="flick_video" style="max-width: 100%;width: 500px;height: 300px;"><video src="https://www.flickr.com/photos/kalakeli/49931239842/play/360p/183f75d545/" controls autoplay ></video></div>
14 *
15 * @package automattic/jetpack
16 */
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit( 0 );
20 }
21
22 /**
23 * Transform embed to shortcode on save.
24 *
25 * @param string $content Post content.
26 *
27 * @return string Shortcode or the embed content itself.
28 */
29 function flickr_embed_to_shortcode( $content ) {
30 if ( ! is_string( $content ) ) {
31 return $content;
32 }
33
34 if ( str_contains( $content, '<div class="flickr_video"' ) && str_contains( $content, '<video' ) ) {
35 return jetpack_flickr_video_to_shortcode( $content );
36 } elseif ( preg_match( '/<iframe src="(https?:)?\/\/([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)\/[^\"]+\"/', $content ) ) {
37 return jetpack_flickr_photo_to_shortcode( $content );
38 }
39
40 return $content;
41 }
42
43 /**
44 * Transforms embed to shortcode on save when the photo param is used.
45 * If embed content cannot be transformed to a valid shortcode,
46 * the embed content itself is returned.
47 *
48 * @param string $content Embed output.
49 *
50 * @return string Shortcode or the embed content.
51 */
52 function jetpack_flickr_photo_to_shortcode( $content ) {
53 preg_match( '/<iframe src=\"([^\"]+)\"(\s+height=\"([^\"]*)\")?(\s+width=\"([^\"]*)\")?/', $content, $matches );
54
55 if ( empty( $matches[1] ) ) {
56 return $content;
57 }
58
59 $src = esc_attr( str_replace( 'player/', '', $matches[1] ) );
60 $height = empty( $matches[3] ) ? '' : esc_attr( $matches[3] );
61 $width = empty( $matches[5] ) ? '' : esc_attr( $matches[5] );
62
63 /** This action is documented in modules/shortcodes/youtube.php */
64 do_action( 'jetpack_embed_to_shortcode', 'flickr_photo', $src );
65
66 return '[flickr photo="' . $src . '" w=' . $width . ' h=' . $height . ']';
67 }
68
69 /**
70 * Transforms embed to shortcode on save when the video param is used.
71 * If embed content cannot be transformed to a valid shortcode,
72 * the embed content itself is returned.
73 *
74 * @param string $content Embed output.
75 *
76 * @return string Shortcode or the embed content.
77 */
78 function jetpack_flickr_video_to_shortcode( $content ) {
79 // Get video src.
80 preg_match( '/<video src=\"([^\"]+)\"/', $content, $matches );
81
82 if ( empty( $matches[1] ) ) {
83 return $content;
84 }
85
86 preg_match( '/(https?:)?\/\/([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)\/photos\/([^\/]+)\/\d+\//', $matches[1], $matches );
87
88 $video_src = esc_attr( $matches[0] );
89
90 // Get width and height.
91
92 preg_match( '/style=\"max-width: 100%;(width:\s(\d+)px;)?(height:\s(\d+)px;)?/', $content, $matches );
93
94 $width = empty( $matches[2] ) ? '' : 'w=' . esc_attr( $matches[2] );
95
96 $height = empty( $matches[4] ) ? '' : 'h=' . esc_attr( $matches[4] );
97
98 $controls = str_contains( $content, 'controls' ) ? 'yes' : 'no';
99
100 $autoplay = str_contains( $content, 'autoplay' ) ? 'yes' : 'no';
101
102 /** This action is documented in modules/shortcodes/youtube.php */
103 do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $video_src );
104
105 return '[flickr video="' . $video_src . '" ' . $width . ' ' . $height . ' controls="' . $controls . '" autoplay="' . $autoplay . '"]';
106 }
107
108 if ( jetpack_shortcodes_should_hook_pre_kses() ) {
109 add_filter( 'pre_kses', 'flickr_embed_to_shortcode' );
110 }
111
112 /**
113 * Flickr Shortcode handler.
114 *
115 * @param array $atts Shortcode attributes.
116 *
117 * @return string Shortcode Output.
118 */
119 function flickr_shortcode_handler( $atts ) {
120 $atts = shortcode_atts(
121 array(
122 'video' => 0,
123 'photo' => 0,
124 'w' => '',
125 'h' => '',
126 'controls' => 'yes',
127 'autoplay' => '',
128 ),
129 $atts,
130 'flickr'
131 );
132
133 if ( ! empty( $atts['video'] ) ) {
134 $showing = 'video';
135 $src = $atts['video'];
136 } elseif ( ! empty( $atts['photo'] ) ) {
137 $showing = 'photo';
138 $src = $atts['photo'];
139 } else {
140 return '';
141 }
142
143 $src = str_replace( 'http://', 'https://', $src );
144
145 if ( 'video' === $showing ) {
146
147 $video_id = flick_shortcode_video_id( $src );
148
149 if ( empty( $video_id ) ) {
150 return '';
151 }
152
153 $atts = array_map( 'esc_attr', $atts );
154 return flickr_shortcode_video_markup( $atts, $video_id, $src );
155 } elseif ( 'photo' === $showing ) {
156
157 if ( ! preg_match( '~^(https?:)?//([\da-z\-]+\.)*?((static)?flickr\.com|flic\.kr)/.*~i', $src ) ) {
158 return '';
159 }
160
161 $height = empty( $atts['h'] ) ? 'auto' : esc_attr( $atts['h'] );
162
163 $src = sprintf( '%s/player/', untrailingslashit( $src ) );
164
165 $allow_full_screen = 'allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen';
166
167 if ( class_exists( 'Jetpack_AMP_Support' ) && Jetpack_AMP_Support::is_amp_request() ) {
168 $allow_full_screen = str_replace( ' oallowfullscreen msallowfullscreen', '', $allow_full_screen );
169 }
170
171 return sprintf( '<iframe src="%s" height="%s" width="%s" frameborder="0" %s></iframe>', esc_url( $src ), $height, esc_attr( $atts['w'] ), $allow_full_screen );
172 }
173
174 return false;
175 }
176
177 /**
178 * Return HTML markup for a Flickr embed.
179 *
180 * @param array $atts Shortcode attributes.
181 * @param string $id Video ID.
182 * @param string $video_param video param of the shortcode.
183 *
184 * @return string Shortcode ouput for video.
185 */
186 function flickr_shortcode_video_markup( $atts, $id, $video_param ) {
187
188 $transient_name = "flickr_video_$id";
189 $video_src = get_transient( $transient_name );
190
191 if ( empty( $video_src ) ) {
192 $video_url = '';
193 if ( ! is_numeric( $video_param ) ) {
194 $video_url = $video_param;
195 } else {
196 // Get the URL of the video from the page of the video.
197 $video_page_content = wp_remote_get( "https://flickr.com/photo.gne?id=$video_param" );
198 // Bail if we do not get any info from Flickr.
199 if ( is_wp_error( $video_page_content ) ) {
200 return '';
201 }
202
203 // Extract the URL from the og:url meta tag.
204 preg_match( '/property=\"og:url\"\scontent=\"([^\"]+)\"/', $video_page_content['body'], $matches );
205 if ( empty( $matches[1] ) ) {
206 return '';
207 }
208 $video_url = $matches[1];
209 }
210
211 $provider = 'https://www.flickr.com/services/oembed/';
212 $oembed = _wp_oembed_get_object();
213 $data = (array) $oembed->fetch( $provider, $video_url );
214 if ( empty( $data['html'] ) ) {
215 return '';
216 }
217
218 // Get the embed url.
219 preg_match( '/src=\"([^\"]+)\"/', $data['html'], $matches );
220
221 if ( empty( $matches[1] ) ) {
222 return '';
223 }
224 $embed_url = $matches[1];
225
226 $embed_page = wp_remote_get( $embed_url );
227
228 // Bail if the request returns an error.
229 if ( ! is_array( $embed_page ) ) {
230 return '';
231 }
232
233 // Get the video url from embed html markup.
234
235 preg_match( '/video.+src=\"([^\"]+)\"/', $embed_page['body'], $matches );
236 if ( ! empty( $matches[1] ) ) {
237 $video_src = $matches[1];
238 set_transient( $transient_name, $video_src, 2592000 ); // 30 days transient.
239 }
240 }
241
242 $style = 'max-width: 100%;';
243
244 if ( ! empty( $atts['w'] ) && is_numeric( $atts['w'] ) ) {
245 $style .= sprintf( 'width: %dpx;', $atts['w'] );
246 }
247
248 if ( ! empty( $atts['h'] ) && is_numeric( $atts['h'] ) ) {
249 $style .= sprintf( 'height: %dpx;', $atts['h'] );
250 }
251
252 $controls = 'yes' === $atts['controls'] ? 'controls' : '';
253 $autoplay = 'yes' === $atts['autoplay'] ? 'autoplay' : '';
254
255 return sprintf(
256 '<div class="flick_video" style="%s"><video src="%s" %s %s /></div>',
257 esc_attr( $style ),
258 esc_attr( $video_src ),
259 $controls,
260 $autoplay
261 );
262 }
263
264 /**
265 * Extract the id of the flickr video from the video param.
266 *
267 * @param string $video_param Video parameter of the shortcode.
268 *
269 * @return string|boolean ID of the video or false in case the ID can not be extracted.
270 */
271 function flick_shortcode_video_id( $video_param ) {
272 if ( preg_match( '/^https?:\/\/(www\.)?flickr\.com\/.+/', $video_param ) || preg_match( '/^https?:\/\/flic\.kr\/.+/', $video_param ) ) {
273
274 // Extract the video id from the url.
275 preg_match( '/\d+/', $video_param, $matches );
276
277 if ( empty( $matches ) ) {
278 return false;
279 }
280
281 return $matches[0];
282
283 } elseif ( is_numeric( $video_param ) ) {
284 return $video_param;
285 }
286
287 return false;
288 }
289
290 add_shortcode( 'flickr', 'flickr_shortcode_handler' );
291
292 // Override core's Flickr support because Flickr oEmbed doesn't support web embeds.
293 wp_embed_register_handler( 'flickr', '#https?://(www\.)?flickr\.com/.*#i', 'jetpack_flickr_oembed_handler' );
294
295 /**
296 * Callback to modify output of embedded Vimeo video using Jetpack's shortcode.
297 *
298 * @since 3.9
299 *
300 * @param array $matches Regex partial matches against the URL passed.
301 * @param array $attr Attributes received in embed response.
302 * @param string $url Requested URL to be embedded.
303 *
304 * @return string Return output of Vimeo shortcode with the proper markup.
305 */
306 function jetpack_flickr_oembed_handler( $matches, $attr, $url ) {
307 /*
308 * Legacy slideshow embeds end with /show/
309 * e.g. https://www.flickr.com/photos/yarnaholic/sets/72157615194738969/show/
310 */
311 if ( '/show/' !== substr( $url, -strlen( '/show/' ) ) ) {
312 // These lookups need cached, as they don't use WP_Embed (which caches).
313 $cache_key = md5( $url . wp_json_encode( $attr, JSON_UNESCAPED_SLASHES ) );
314 $cache_group = 'oembed_flickr';
315
316 $html = wp_cache_get( $cache_key, $cache_group );
317
318 if ( false === $html ) {
319 $html = _wp_oembed_get_object()->get_html( $url, $attr );
320
321 wp_cache_set( $cache_key, $html, $cache_group, 60 * MINUTE_IN_SECONDS );
322 }
323
324 return $html;
325 }
326
327 return flickr_shortcode_handler( array( 'photo' => $url ) );
328 }
329