1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Module Name: Shortcode Embeds |
5
|
|
|
* Module Description: Embed media from popular sites without any coding. |
6
|
|
|
* Sort Order: 3 |
7
|
|
|
* First Introduced: 1.1 |
8
|
|
|
* Major Changes In: 1.2 |
9
|
|
|
* Requires Connection: No |
10
|
|
|
* Auto Activate: Yes |
11
|
|
|
* Module Tags: Photos and Videos, Social, Writing, Appearance |
12
|
|
|
* Feature: Writing |
13
|
|
|
* Additional Search Queries: shortcodes, shortcode, embeds, media, bandcamp, blip.tv, dailymotion, facebook, flickr, google calendars, google maps, google+, polldaddy, recipe, recipes, scribd, slideshare, slideshow, slideshows, soundcloud, ted, twitter, vimeo, vine, youtube |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Transforms the $atts array into a string that the old functions expected |
18
|
|
|
* |
19
|
|
|
* The old way was: |
20
|
|
|
* [shortcode a=1&b=2&c=3] or [shortcode=1] |
21
|
|
|
* This is parsed as array( a => '1&b=2&c=3' ) and array( 0 => '=1' ), which is useless |
22
|
|
|
* |
23
|
|
|
* @param Array $params |
24
|
|
|
* @param Bool $old_format_support true if [shortcode=foo] format is possible. |
25
|
|
|
* @return String $params |
26
|
|
|
*/ |
27
|
|
|
function shortcode_new_to_old_params( $params, $old_format_support = false ) { |
28
|
|
|
$str = ''; |
29
|
|
|
|
30
|
|
|
if ( $old_format_support && isset( $params[0] ) ) { |
31
|
|
|
$str = ltrim( $params[0], '=' ); |
32
|
|
|
} elseif ( is_array( $params ) ) { |
33
|
|
|
foreach ( array_keys( $params ) as $key ) { |
34
|
|
|
if ( ! is_numeric( $key ) ) |
35
|
|
|
$str = $key . '=' . $params[$key]; |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return str_replace( array( '&', '&' ), '&', $str ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
function jetpack_load_shortcodes() { |
43
|
|
|
$shortcode_includes = array(); |
44
|
|
|
|
45
|
|
|
foreach ( Jetpack::glob_php( dirname( __FILE__ ) . '/shortcodes' ) as $file ) { |
46
|
|
|
$filename = substr( basename( $file ), 0, -4 ); |
47
|
|
|
|
48
|
|
|
$shortcode_includes[ $filename ] = $file; |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* This filter allows other plugins to override which shortcodes Jetpack loads. |
53
|
|
|
* |
54
|
|
|
* @module shortcodes |
55
|
|
|
* |
56
|
|
|
* @since 2.2.1 |
57
|
|
|
* @since 4.2.0 Added filename without extension as array key. |
58
|
|
|
* |
59
|
|
|
* @param array $shortcode_includes An array of which shortcodes to include. |
60
|
|
|
*/ |
61
|
|
|
$shortcode_includes = apply_filters( 'jetpack_shortcodes_to_include', $shortcode_includes ); |
62
|
|
|
|
63
|
|
|
foreach ( $shortcode_includes as $include ) { |
64
|
|
|
include $include; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Runs preg_replace so that replacements don't happen within open tags. |
70
|
|
|
* Parameters are the same as preg_replace, with an added optional search param for improved performance |
71
|
|
|
* |
72
|
|
|
* @param String $pattern |
73
|
|
|
* @param String $replacement |
74
|
|
|
* @param String $content |
75
|
|
|
* @param String $search |
|
|
|
|
76
|
|
|
* @return String $content |
77
|
|
|
*/ |
78
|
|
View Code Duplication |
function jetpack_preg_replace_outside_tags( $pattern, $replacement, $content, $search = null ) { |
|
|
|
|
79
|
|
|
if( ! function_exists( 'wp_html_split' ) ) { |
80
|
|
|
return $content; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ( $search && false === strpos( $content, $search ) ) { |
|
|
|
|
84
|
|
|
return $content; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$textarr = wp_html_split( $content ); |
88
|
|
|
unset( $content ); |
89
|
|
|
foreach( $textarr as &$element ) { |
90
|
|
|
if ( '' === $element || '<' === $element{0} ) |
91
|
|
|
continue; |
92
|
|
|
$element = preg_replace( $pattern, $replacement, $element ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
return join( $textarr ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* Runs preg_replace_callback so that replacements don't happen within open tags. |
100
|
|
|
* Parameters are the same as preg_replace, with an added optional search param for improved performance |
101
|
|
|
* |
102
|
|
|
* @param String $pattern |
103
|
|
|
* @param String $replacement |
|
|
|
|
104
|
|
|
* @param String $content |
105
|
|
|
* @param String $search |
|
|
|
|
106
|
|
|
* @return String $content |
107
|
|
|
*/ |
108
|
|
View Code Duplication |
function jetpack_preg_replace_callback_outside_tags( $pattern, $callback, $content, $search = null ) { |
|
|
|
|
109
|
|
|
if( ! function_exists( 'wp_html_split' ) ) { |
110
|
|
|
return $content; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
if ( $search && false === strpos( $content, $search ) ) { |
|
|
|
|
114
|
|
|
return $content; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
$textarr = wp_html_split( $content ); |
118
|
|
|
unset( $content ); |
119
|
|
|
foreach( $textarr as &$element ) { |
120
|
|
|
if ( '' === $element || '<' === $element{0} ) |
121
|
|
|
continue; |
122
|
|
|
$element = preg_replace_callback( $pattern, $callback, $element ); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return join( $textarr ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
if ( ! function_exists( 'jetpack_shortcode_get_wpvideo_id' ) ) { |
129
|
|
|
function jetpack_shortcode_get_wpvideo_id( $atts ) { |
130
|
|
|
if ( isset( $atts[ 0 ] ) ) |
131
|
|
|
return $atts[ 0 ]; |
132
|
|
|
else |
133
|
|
|
return 0; |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if ( ! function_exists( 'jetpack_shortcode_get_videopress_id' ) ) { |
138
|
|
|
function jetpack_shortcode_get_videopress_id( $atts ) { |
139
|
|
|
if ( isset( $atts[ 0 ] ) ) |
140
|
|
|
return $atts[ 0 ]; |
141
|
|
|
else |
142
|
|
|
return 0; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
jetpack_load_shortcodes(); |
147
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.