|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* Module Name: Shortcode Embeds |
|
5
|
|
|
* Module Description: Embed content from YouTube, Vimeo, SlideShare, and more, no coding necessary. |
|
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
|
|
|
* 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 |
|
13
|
|
|
*/ |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Transforms the $atts array into a string that the old functions expected |
|
17
|
|
|
* |
|
18
|
|
|
* The old way was: |
|
19
|
|
|
* [shortcode a=1&b=2&c=3] or [shortcode=1] |
|
20
|
|
|
* This is parsed as array( a => '1&b=2&c=3' ) and array( 0 => '=1' ), which is useless |
|
21
|
|
|
* |
|
22
|
|
|
* @param Array $params |
|
23
|
|
|
* @param Bool $old_format_support true if [shortcode=foo] format is possible. |
|
24
|
|
|
* @return String $params |
|
25
|
|
|
*/ |
|
26
|
|
|
function shortcode_new_to_old_params( $params, $old_format_support = false ) { |
|
27
|
|
|
$str = ''; |
|
28
|
|
|
|
|
29
|
|
|
if ( $old_format_support && isset( $params[0] ) ) { |
|
30
|
|
|
$str = ltrim( $params[0], '=' ); |
|
31
|
|
|
} elseif ( is_array( $params ) ) { |
|
32
|
|
|
foreach ( array_keys( $params ) as $key ) { |
|
33
|
|
|
if ( ! is_numeric( $key ) ) |
|
34
|
|
|
$str = $key . '=' . $params[$key]; |
|
35
|
|
|
} |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
return str_replace( array( '&', '&' ), '&', $str ); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
View Code Duplication |
function jetpack_load_shortcodes() { |
|
|
|
|
|
|
42
|
|
|
global $wp_version; |
|
43
|
|
|
|
|
44
|
|
|
$shortcode_includes = array(); |
|
45
|
|
|
|
|
46
|
|
|
foreach ( Jetpack::glob_php( dirname( __FILE__ ) . '/shortcodes' ) as $file ) { |
|
47
|
|
|
$shortcode_includes[] = $file; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* This filter allows other plugins to override which shortcodes Jetpack loads. |
|
52
|
|
|
* |
|
53
|
|
|
* @module shortcodes |
|
54
|
|
|
* |
|
55
|
|
|
* @since 2.2.1 |
|
56
|
|
|
* |
|
57
|
|
|
* @param array $shortcode_includes An array of which shortcodes to include. |
|
58
|
|
|
*/ |
|
59
|
|
|
$shortcode_includes = apply_filters( 'jetpack_shortcodes_to_include', $shortcode_includes ); |
|
60
|
|
|
|
|
61
|
|
|
foreach ( $shortcode_includes as $include ) { |
|
62
|
|
|
include $include; |
|
63
|
|
|
} |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* Runs preg_replace so that replacements don't happen within open tags. |
|
68
|
|
|
* Parameters are the same as preg_replace, with an added optional search param for improved performance |
|
69
|
|
|
* |
|
70
|
|
|
* @param String $pattern |
|
71
|
|
|
* @param String $replacement |
|
72
|
|
|
* @param String $content |
|
73
|
|
|
* @param String $search |
|
|
|
|
|
|
74
|
|
|
* @return String $content |
|
75
|
|
|
*/ |
|
76
|
|
View Code Duplication |
function jetpack_preg_replace_outside_tags( $pattern, $replacement, $content, $search = null ) { |
|
|
|
|
|
|
77
|
|
|
if( ! function_exists( 'wp_html_split' ) ) { |
|
78
|
|
|
return $content; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
if ( $search && false === strpos( $content, $search ) ) { |
|
|
|
|
|
|
82
|
|
|
return $content; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$textarr = wp_html_split( $content ); |
|
86
|
|
|
unset( $content ); |
|
87
|
|
|
foreach( $textarr as &$element ) { |
|
88
|
|
|
if ( '' === $element || '<' === $element{0} ) |
|
89
|
|
|
continue; |
|
90
|
|
|
$element = preg_replace( $pattern, $replacement, $element ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
return join( $textarr ); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* Runs preg_replace_callback so that replacements don't happen within open tags. |
|
98
|
|
|
* Parameters are the same as preg_replace, with an added optional search param for improved performance |
|
99
|
|
|
* |
|
100
|
|
|
* @param String $pattern |
|
101
|
|
|
* @param String $replacement |
|
|
|
|
|
|
102
|
|
|
* @param String $content |
|
103
|
|
|
* @param String $search |
|
|
|
|
|
|
104
|
|
|
* @return String $content |
|
105
|
|
|
*/ |
|
106
|
|
View Code Duplication |
function jetpack_preg_replace_callback_outside_tags( $pattern, $callback, $content, $search = null ) { |
|
|
|
|
|
|
107
|
|
|
if( ! function_exists( 'wp_html_split' ) ) { |
|
108
|
|
|
return $content; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
if ( $search && false === strpos( $content, $search ) ) { |
|
|
|
|
|
|
112
|
|
|
return $content; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
$textarr = wp_html_split( $content ); |
|
116
|
|
|
unset( $content ); |
|
117
|
|
|
foreach( $textarr as &$element ) { |
|
118
|
|
|
if ( '' === $element || '<' === $element{0} ) |
|
119
|
|
|
continue; |
|
120
|
|
|
$element = preg_replace_callback( $pattern, $callback, $element ); |
|
121
|
|
|
} |
|
122
|
|
|
|
|
123
|
|
|
return join( $textarr ); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
if ( ! function_exists( 'jetpack_shortcode_get_wpvideo_id' ) ) { |
|
127
|
|
|
function jetpack_shortcode_get_wpvideo_id( $atts ) { |
|
128
|
|
|
if ( isset( $atts[ 0 ] ) ) |
|
129
|
|
|
return $atts[ 0 ]; |
|
130
|
|
|
else |
|
131
|
|
|
return 0; |
|
132
|
|
|
} |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
jetpack_load_shortcodes(); |
|
136
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.