Conditions | 19 |
Paths | 4 |
Total Lines | 91 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
25 | function flickr_embed_to_shortcode( $content ) { |
||
26 | if ( ! is_string( $content ) || false === stripos( $content, '/www.flickr.com/apps/video/stewart.swf' ) ) { |
||
27 | return $content; |
||
28 | } |
||
29 | |||
30 | $regexp = '%(<object.*?(?:<(?!/?(?:object|embed)\s+).*?)*?)?<embed((?:\s+\w+="[^"]*")*)\s+src="http(?:\:|�*58;)//www.flickr.com/apps/video/stewart.swf[^"]*"((?:\s+\w+="[^"]*")*)\s*(?:/>|>\s*</embed>)(?(1)\s*</object>)%'; |
||
31 | $regexp_ent = str_replace( |
||
32 | array( |
||
33 | '&#0*58;', |
||
34 | '[^>]*', |
||
35 | '[^<]*', |
||
36 | ), |
||
37 | array( |
||
38 | '&#0*58;|�*58;', |
||
39 | '[^&]*(?:&(?!gt;)[^&]*)*', |
||
40 | '[^&]*(?:&(?!lt;)[^&]*)*', |
||
41 | ), |
||
42 | htmlspecialchars( $regexp, ENT_NOQUOTES ) |
||
43 | ); |
||
44 | |||
45 | foreach ( compact( 'regexp', 'regexp_ent' ) as $reg => $regexp ) { |
||
46 | if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) { |
||
47 | continue; |
||
48 | } |
||
49 | foreach ( $matches as $match ) { |
||
50 | $params = $match[2] . $match[3]; |
||
51 | |||
52 | if ( 'regexp_ent' === $reg ) { |
||
53 | $params = html_entity_decode( $params ); |
||
54 | } |
||
55 | |||
56 | $params = wp_kses_hair( $params, array( 'http' ) ); |
||
57 | if ( |
||
58 | ! isset( $params['type'] ) |
||
59 | || 'application/x-shockwave-flash' !== $params['type']['value'] |
||
60 | || ! isset( $params['flashvars'] ) |
||
61 | ) { |
||
62 | continue; |
||
63 | } |
||
64 | |||
65 | $flashvars = array(); |
||
66 | wp_parse_str( html_entity_decode( $params['flashvars']['value'] ), $flashvars ); |
||
67 | |||
68 | if ( ! isset( $flashvars['photo_id'] ) ) { |
||
69 | continue; |
||
70 | } |
||
71 | |||
72 | $photo_id = preg_replace( '#[^A-Za-z0-9_./@+-]+#', '', $flashvars['photo_id'] ); |
||
73 | |||
74 | if ( ! strlen( $photo_id ) ) { |
||
75 | continue; |
||
76 | } |
||
77 | |||
78 | $code_atts = array( 'video' => $photo_id ); |
||
79 | |||
80 | if ( |
||
81 | isset( $flashvars['flickr_show_info_box'] ) |
||
82 | && 'true' === $flashvars['flickr_show_info_box'] |
||
83 | ) { |
||
84 | $code_atts['show_info'] = 'true'; |
||
85 | } |
||
86 | |||
87 | if ( ! empty( $flashvars['photo_secret'] ) ) { |
||
88 | $photo_secret = preg_replace( '#[^A-Za-z0-9_./@+-]+#', '', $flashvars['photo_secret'] ); |
||
89 | if ( strlen( $photo_secret ) ) { |
||
90 | $code_atts['secret'] = $photo_secret; |
||
91 | } |
||
92 | } |
||
93 | |||
94 | if ( ! empty( $params['width']['value'] ) ) { |
||
95 | $code_atts['w'] = (int) $params['width']['value']; |
||
96 | } |
||
97 | |||
98 | if ( ! empty( $params['height']['value'] ) ) { |
||
99 | $code_atts['h'] = (int) $params['height']['value']; |
||
100 | } |
||
101 | |||
102 | $code = '[flickr'; |
||
103 | foreach ( $code_atts as $k => $v ) { |
||
104 | $code .= " $k=$v"; |
||
105 | } |
||
106 | $code .= ']'; |
||
107 | |||
108 | $content = str_replace( $match[0], $code, $content ); |
||
109 | /** This action is documented in modules/shortcodes/youtube.php */ |
||
110 | do_action( 'jetpack_embed_to_shortcode', 'flickr_video', $flashvars['photo_id'] ); |
||
111 | } |
||
112 | } |
||
113 | |||
114 | return $content; |
||
115 | } |
||
116 | add_filter( 'pre_kses', 'flickr_embed_to_shortcode' ); |
||
246 |