css
2 years ago
images
2 years ago
img
2 years ago
js
2 years ago
archiveorg-book.php
5 years ago
archiveorg.php
5 years ago
archives.php
5 years ago
bandcamp.php
3 years ago
brightcove.php
5 years ago
cartodb.php
5 years ago
class.filter-embedded-html-objects.php
2 years ago
codepen.php
5 years ago
crowdsignal.php
2 years ago
dailymotion.php
3 years ago
descript.php
4 years ago
facebook.php
2 years ago
flatio.php
5 years ago
flickr.php
2 years ago
getty.php
2 years ago
gist.php
3 years ago
googleapps.php
2 years ago
googlemaps.php
2 years ago
googleplus.php
5 years ago
gravatar.php
2 years ago
houzz.php
5 years ago
inline-pdfs.php
4 years ago
instagram.php
3 years ago
kickstarter.php
3 years ago
mailchimp.php
3 years ago
medium.php
3 years ago
mixcloud.php
2 years ago
others.php
2 years ago
pinterest.php
2 years ago
presentations.php
2 years ago
quiz.php
4 years ago
recipe.php
2 years ago
scribd.php
5 years ago
sitemap.php
5 years ago
slideshare.php
5 years ago
slideshow.php
2 years ago
smartframe.php
3 years ago
soundcloud.php
3 years ago
spotify.php
2 years ago
ted.php
5 years ago
tweet.php
2 years ago
twitchtv.php
5 years ago
twitter-timeline.php
5 years ago
unavailable.php
3 years ago
untappd-menu.php
3 years ago
upcoming-events.php
3 years ago
ustream.php
5 years ago
videopress.php
4 years ago
vimeo.php
2 years ago
vine.php
5 years ago
vr.php
2 years ago
wordads.php
5 years ago
wufoo.php
3 years ago
youtube.php
1 year ago
smartframe.php
115 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Smartframe.io embed |
| 4 | * |
| 5 | * Example URL: https://mikael-korpela.smartframe.io/p/mantymetsa_1630927773870/7673dc41a775fb845cc26acf24f1fe4?t=rql1c6dbpv2 |
| 6 | * Example embed code: <script src="https://embed.smartframe.io/6ae67829d1264ee0ea6071a788940eae.js" data-image-id="mantymetsa_1630927773870" data-width="100%" data-max-width="1412px"></script> |
| 7 | * |
| 8 | * @package automattic/jetpack |
| 9 | */ |
| 10 | |
| 11 | if ( defined( 'IS_WPCOM' ) && IS_WPCOM ) { |
| 12 | add_action( 'init', 'jetpack_smartframe_enable_embeds' ); |
| 13 | } else { |
| 14 | jetpack_smartframe_enable_embeds(); |
| 15 | } |
| 16 | |
| 17 | /** |
| 18 | * Register smartframe as oembed provider. Add filter to reverse iframes to shortcode. Register [smartframe] shortcode. |
| 19 | * |
| 20 | * @since 10.2.0 |
| 21 | */ |
| 22 | function jetpack_smartframe_enable_embeds() { |
| 23 | // Support their oEmbed Endpoint. |
| 24 | wp_oembed_add_provider( '#https?://(.*?)\.smartframe\.(io|net)/.*#i', 'https://oembed.smartframe.io/', true ); |
| 25 | |
| 26 | // Allow script to be filtered to short code (so direct copy+paste can be done). |
| 27 | add_filter( 'pre_kses', 'jetpack_shortcodereverse_smartframe' ); |
| 28 | |
| 29 | // Actually display the smartframe Embed. |
| 30 | add_shortcode( 'smartframe', 'jetpack_smartframe_shortcode' ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Compose shortcode based on smartframe iframes. |
| 35 | * |
| 36 | * @since 10.2.0 |
| 37 | * |
| 38 | * @param string $content Post content. |
| 39 | * |
| 40 | * @return mixed |
| 41 | */ |
| 42 | function jetpack_shortcodereverse_smartframe( $content ) { |
| 43 | if ( ! is_string( $content ) || false === stripos( $content, 'embed.smartframe' ) ) { |
| 44 | return $content; |
| 45 | } |
| 46 | |
| 47 | // phpcs:ignore WordPress.WP.EnqueuedResources.NonEnqueuedScript |
| 48 | $regexp = '!<script\ssrc="https://embed\.smartframe\.(?:io|net)/(\w+)\.js"\sdata-image-id="(.*?)"(?:\sdata-width="(?:\d+(?:%|px))"\s)?(?:data-max-width="(\d+(%|px)))?"></script>!i'; |
| 49 | $regexp_ent = str_replace( '&#0*58;', '&#0*58;|�*58;', htmlspecialchars( $regexp, ENT_NOQUOTES ) ); |
| 50 | |
| 51 | foreach ( compact( 'regexp', 'regexp_ent' ) as $regexp ) { |
| 52 | if ( ! preg_match_all( $regexp, $content, $matches, PREG_SET_ORDER ) ) { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | foreach ( $matches as $match ) { |
| 57 | // We need at least a script ID and an image ID. |
| 58 | if ( ! isset( $match[1] ) || ! isset( $match[2] ) ) { |
| 59 | continue; |
| 60 | } |
| 61 | $shortcode = sprintf( |
| 62 | '[smartframe script-id="%1$s" image-id="%2$s"%3$s]', |
| 63 | esc_attr( $match[1] ), |
| 64 | esc_attr( $match[2] ), |
| 65 | ! empty( $match[3] ) ? ' max-width="' . esc_attr( $match[3] ) . '"' : '' |
| 66 | ); |
| 67 | $content = str_replace( $match[0], $shortcode, $content ); |
| 68 | } |
| 69 | } |
| 70 | /** This action is documented in modules/widgets/social-media-icons.php */ |
| 71 | do_action( 'jetpack_bump_stats_extras', 'html_to_shortcode', 'smartframe' ); |
| 72 | |
| 73 | return $content; |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Parse shortcode arguments and render its output. |
| 78 | * |
| 79 | * @since 10.2.0 |
| 80 | * |
| 81 | * @param array $atts Shortcode parameters. |
| 82 | * |
| 83 | * @return string |
| 84 | */ |
| 85 | function jetpack_smartframe_shortcode( $atts ) { |
| 86 | if ( ! empty( $atts['image-id'] ) ) { |
| 87 | $image_id = $atts['image-id']; |
| 88 | } else { |
| 89 | return '<!-- Missing smartframe image-id -->'; |
| 90 | } |
| 91 | if ( ! empty( $atts['script-id'] ) ) { |
| 92 | $script_id = $atts['script-id']; |
| 93 | } else { |
| 94 | return '<!-- Missing smartframe script-id -->'; |
| 95 | } |
| 96 | |
| 97 | $params = array( |
| 98 | // ignore width for now, smartframe embed code has it "100%". % isn't allowed in oembed, making it 100px. |
| 99 | // 'width' => isset( $atts['width'] ) ? (int) $atts['width'] : null,. |
| 100 | 'max-width' => isset( $atts['max-width'] ) ? (int) $atts['max-width'] : null, |
| 101 | ); |
| 102 | |
| 103 | $embed_url = sprintf( |
| 104 | 'https://imagecards.smartframe.io/%1$s/%2$s', |
| 105 | esc_attr( $script_id ), |
| 106 | esc_attr( $image_id ) |
| 107 | ); |
| 108 | |
| 109 | // wrap the embed with wp-block-embed__wrapper, otherwise it would be aligned to the very left of the viewport. |
| 110 | return sprintf( |
| 111 | '<div class="wp-block-embed__wrapper">%1$s</div>', |
| 112 | wp_oembed_get( $embed_url, array_filter( $params ) ) |
| 113 | ); |
| 114 | } |
| 115 |