PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 2.4.7
Jetpack – WP Security, Backup, Speed, & Growth v2.4.7
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 in Jetpack – WP Security, Backup, Speed, & Growth 2.4.7, at modules/shortcodes/flickr.php

138 lines 5.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://flickr.com/photos/revdancatt/2345938910/]
9 [flickr video=2345938910]
10 [flickr video=2345938910 show_info=true w=400 h=300]
11 [flickr video=2345938910 show_info=true w=400 h=300 secret=846d9c1be9]
12
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 ( false === stripos( $content, '/www.flickr.com/apps/video/stewart.swf' ) )
21 return $content;
22
23 $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>)%';
24 $regexp_ent = str_replace(
25 array(
26 '&amp;#0*58;',
27 '[^&gt;]*',
28 '[^&lt;]*',
29 ),
30 array(
31 '&amp;#0*58;|&#0*58;',
32 '[^&]*(?:&(?!gt;)[^&]*)*',
33 '[^&]*(?:&(?!lt;)[^&]*)*',
34 ),
35 htmlspecialchars( $regexp, ENT_NOQUOTES )
36 );
37
38 foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) {
39 if ( !preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) )
40 continue;
41 foreach ( $matches as $match ) {
42 $params = $match[2] . $match[3];
43
44 if ( 'regexp_ent' == $reg )
45 $params = html_entity_decode( $params );
46
47 $params = wp_kses_hair( $params, array( 'http' ) );
48 if ( ! isset( $params['type'] ) || 'application/x-shockwave-flash' != $params['type']['value'] || ! isset( $params['flashvars'] ) )
49 continue;
50
51 wp_parse_str( html_entity_decode( $params['flashvars']['value'] ), $flashvars );
52
53 if ( ! isset( $flashvars['photo_id'] ) )
54 continue;
55
56 $code_atts = array( 'video' => $flashvars['photo_id'], );
57
58 if ( isset( $flashvars['flickr_show_info_box'] ) && 'true' == $flashvars['flickr_show_info_box'] )
59 $code_atts['show_info'] = 'true';
60
61 if ( ! empty( $flashvars['photo_secret'] ) )
62 $code_atts['secret'] = $flashvars['photo_secret'] ;
63
64 if ( ! empty( $params['width']['value'] ) )
65 $code_atts['w'] = (int) $params['width']['value'];
66
67 if ( ! empty( $params['height']['value'] ) )
68 $code_atts['h'] = (int) $params['height']['value'];
69
70 $code = '[flickr';
71 foreach ( $code_atts as $k => $v )
72 $code .= " $k=$v";
73 $code .= ']';
74
75 $content = str_replace( $match[0], $code, $content );
76 do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $flashvars['photo_id'] );
77 }
78 }
79
80 return $content;
81 }
82 add_filter( 'pre_kses', 'flickr_embed_to_shortcode' );
83
84 function flickr_shortcode_handler( $atts ) {
85 $atts = shortcode_atts( array(
86 'video' => 0,
87 'photo' => 0,
88 'show_info' => 0,
89 'w' => 400,
90 'h' => 300,
91 'secret' => 0,
92 'size' => 0,
93 ), $atts );
94
95 if ( isset( $atts['video'] ) ) {
96 $showing = 'video';
97 $src = $atts['video'];
98 } elseif ( isset( $atts['photo'] ) ) {
99 $showing = 'photo';
100 $src = $atts['photo'];
101 } else {
102 return '';
103 }
104
105 if ( preg_match( "!photos/(([0-9a-zA-Z-_]+)|([0-9]+@N[0-9]+))/([0-9]+)/?$!", $src, $m ) )
106 $atts['photo_id'] = $m[4];
107 else
108 $atts['photo_id'] = $atts['video'];
109
110 if ( $showing == 'video' ) {
111 if ( ! isset( $atts['show_info'] ) || in_array( $atts['show_info'], array('yes', 'true') ) )
112 $atts['show_info'] = 'true';
113 elseif ( in_array( $atts['show_info'], array( 'false', 'no' ) ) )
114 $atts['show_info'] = 'false';
115
116 if ( isset( $atts['secret'] ) )
117 $atts['secret'] = preg_replace( '![^\w]+!i', '', $atts['secret'] );
118
119 return flickr_shortcode_video_markup( $atts );
120 } else {
121 return '';
122 }
123 }
124
125 function flickr_shortcode_video_markup( $atts ) {
126 $atts = array_map( 'esc_attr', $atts );
127
128 $photo_vars = "photo_id=$atts[photo_id]";
129 if ( isset( $atts['secret'] ) )
130 $photo_vars .= "&amp;photo_secret=$atts[secret]";
131
132 return <<<EOD
133 <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>
134 EOD;
135 }
136
137 add_shortcode( 'flickr', 'flickr_shortcode_handler' );
138