css
1 month ago
images
1 year ago
img
2 months ago
js
7 months ago
archiveorg-book.php
7 months ago
archiveorg.php
1 month ago
archives.php
1 week 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
7 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
1 month 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
2 weeks ago
scribd.php
7 months ago
shortcode-utils.php
7 months ago
sitemap.php
7 months ago
slideshare.php
7 months ago
slideshow.php
2 weeks ago
smartframe.php
7 months ago
soundcloud.php
1 month ago
spotify.php
7 months ago
ted.php
7 months ago
tweet.php
7 months ago
twitchtv.php
2 weeks 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
kickstarter.php
87 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Kickstarter shortcode |
| 4 | * |
| 5 | * Usage: |
| 6 | * [kickstarter url="https://www.kickstarter.com/projects/peaktoplateau/yak-wool-baselayers-from-tibet-to-the-world" width="480" height=""] |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | if ( ! defined( 'ABSPATH' ) ) { |
| 12 | exit( 0 ); |
| 13 | } |
| 14 | |
| 15 | add_shortcode( 'kickstarter', 'jetpack_kickstarter_shortcode' ); |
| 16 | if ( jetpack_shortcodes_should_hook_pre_kses() ) { |
| 17 | add_filter( 'pre_kses', 'jetpack_kickstarter_embed_to_shortcode' ); |
| 18 | } |
| 19 | |
| 20 | /** |
| 21 | * Parse shortcode arguments and render its output. |
| 22 | * |
| 23 | * @since 4.5.0 |
| 24 | * |
| 25 | * @param array $atts Shortcode parameters. |
| 26 | * |
| 27 | * @return string |
| 28 | */ |
| 29 | function jetpack_kickstarter_shortcode( $atts ) { |
| 30 | if ( empty( $atts['url'] ) ) { |
| 31 | return ''; |
| 32 | } |
| 33 | |
| 34 | $url = esc_url_raw( $atts['url'] ); |
| 35 | if ( ! preg_match( '#^(www\.)?kickstarter\.com$#i', wp_parse_url( $url, PHP_URL_HOST ) ) ) { |
| 36 | return '<!-- Invalid Kickstarter URL -->'; |
| 37 | } |
| 38 | |
| 39 | global $wp_embed; |
| 40 | return $wp_embed->shortcode( $atts, $url ); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Converts Kickstarter iframe embeds to a shortcode. |
| 45 | * |
| 46 | * EG: <iframe width="480" height="360" src="http://www.kickstarter.com/projects/deweymac/dewey-mac-kid-detective-book-make-diy-and-stem-spy/widget/video.html" frameborder="0" scrolling="no"> </iframe> |
| 47 | * |
| 48 | * @since 4.5.0 |
| 49 | * |
| 50 | * @param string $content Entry content that possibly includes a Kickstarter embed. |
| 51 | * |
| 52 | * @return string |
| 53 | */ |
| 54 | function jetpack_kickstarter_embed_to_shortcode( $content ) { |
| 55 | if ( ! is_string( $content ) || false === stripos( $content, 'www.kickstarter.com/projects' ) ) { |
| 56 | return $content; |
| 57 | } |
| 58 | |
| 59 | $regexp = '!<iframe((?:\s+\w+=[\'"][^\'"]*[\'"])*)\s+src=[\'"](http://www\.kickstarter\.com/projects/[^/]+/[^/]+)/[^\'"]+[\'"]((?:\s+\w+=[\'"][^\'"]*[\'"])*)>[\s]*</iframe>!i'; |
| 60 | $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); // phpcs:ignore |
| 61 | |
| 62 | foreach ( array( 'regexp', 'regexp_ent' ) as $reg ) { |
| 63 | if ( ! preg_match_all( $$reg, $content, $matches, PREG_SET_ORDER ) ) { |
| 64 | continue; |
| 65 | } |
| 66 | |
| 67 | foreach ( $matches as $match ) { |
| 68 | $url = esc_url( $match[2] ); |
| 69 | |
| 70 | $params = $match[1] . $match[3]; |
| 71 | |
| 72 | if ( 'regexp_ent' === $reg ) { |
| 73 | $params = html_entity_decode( $params, ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML401 ); |
| 74 | } |
| 75 | |
| 76 | $params = wp_kses_hair( $params, array( 'http' ) ); |
| 77 | |
| 78 | $width = isset( $params['width'] ) ? (int) $params['width']['value'] : 0; |
| 79 | |
| 80 | $shortcode = '[kickstarter url=' . $url . ( ( ! empty( $width ) ) ? " width=$width" : '' ) . ']'; |
| 81 | $content = str_replace( $match[0], $shortcode, $content ); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | return $content; |
| 86 | } |
| 87 |