Plugin Directory

Changeset 1729512


Ignore:
Timestamp:
09/13/2017 05:42:06 PM (8 years ago)
Author:
ivanp
Message:

Iframely WP v0.5.0

Location:
iframely/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • iframely/trunk/iframely.php

    r1645981 r1729512  
    55Description: Iframely for WordPress. Embed anything, with responsive widgets.
    66Author: Itteco Corp.
    7 Version: 0.4.0
     7Version: 0.5.0
    88Author URI: https://iframely.com/?from=wp
    99*/
     
    3030wp_oembed_add_provider( '#https?://iframe\.ly/.+#i', iframely_create_api_link(), true );
    3131
    32 function maybe_remove_wp_self_embeds( $result, $url, $args ) { 
    33        
     32function maybe_remove_wp_self_embeds( $result, $url, $args ) {
     33
    3434    return get_site_option( 'publish_iframely_cards') ? null : $result;
    3535}
     
    4545    }
    4646}
     47
     48# Make compatible with Automatic AMP-WP plugin: https://github.com/Automattic/amp-wp
     49function is_iframely_amp ( $args ) {
     50    return
     51        (is_array($args) && array_key_exists('iframely', $args) && $args['iframely'] == 'amp')
     52        || (is_string($args) && strpos($args, 'iframely=amp') !== false)
     53        || (function_exists('is_amp_endpoint') && is_amp_endpoint());
     54}
     55
     56# Make WP cache &iframe=amp oEmbed requests separately
     57add_filter( 'embed_defaults', 'iframely_amp_embed_defaults' );
     58function iframely_amp_embed_defaults( $args ) {
     59    if (is_iframely_amp($args)) {
     60        // args are included in cache key. Bust it for amp
     61        $args['iframely'] = 'amp';
     62    }
     63    return $args;
     64}
     65
     66add_filter( 'oembed_fetch_url', 'maybe_add_iframe_amp', 10, 3 );
     67function maybe_add_iframe_amp( $provider, $args, $url ) {
     68   
     69    if (is_iframely_amp( $args ) && strpos($provider, '//iframe.ly') !== false) {
     70        $provider = add_query_arg( 'iframe', 'amp', $provider );
     71    }
     72    return $provider;
     73}
     74
     75
     76add_filter( 'embed_oembed_html', 'iframely_filter_oembed_result', 10, 3 );
     77function iframely_filter_oembed_result( $html, $url, $args ) {
     78
     79    if (strpos($html, '<amp-iframe') !== false || strpos($html, '<amp-facebook') !== false ) {       
     80        add_action( 'amp_post_template_head', strpos($html, '<amp-iframe') !== false ? 'iframely_add_amp_iframe_js' : 'iframely_add_amp_facebook_js');
     81        // Avoid corrupted amp-iframe overflow div as a result of wpautop
     82        remove_filter( 'the_content', 'wpautop' );
     83        // Restore wpautop if it was disabled
     84        add_filter( 'the_content', 'iframely_autop_on_amp', 1000);
     85    }
     86    return $html;
     87};
     88
     89add_filter( 'amp_content_embed_handlers', 'maybe_unregister_default_embed_handlers', 10, 2 );
     90function maybe_unregister_default_embed_handlers($embed_handler_classes, $post ) {
     91
     92    if ( get_site_option( 'iframely_disable_default_amp_embeds' ) ) {
     93        unset ($embed_handler_classes ['AMP_Twitter_Embed_Handler']);
     94        unset ($embed_handler_classes ['AMP_Dailymotion_Embed_Handler']);
     95        unset ($embed_handler_classes ['AMP_Facebook_Embed_Handler']);
     96        unset ($embed_handler_classes ['AMP_Instagram_Embed_Handler']);
     97        unset ($embed_handler_classes ['AMP_Vimeo_Embed_Handler']);
     98        unset ($embed_handler_classes ['AMP_YouTube_Embed_Handler']);
     99        unset ($embed_handler_classes ['AMP_Pinterest_Embed_Handler']);
     100    }
     101    return $embed_handler_classes;
     102};
     103
     104
     105function iframely_autop_on_amp( $content ) {
     106
     107    // Logic is taken from wpautop itself re <pre>
     108    if ( strpos($content, '<amp-iframe') !== false ) {
     109        $chunks = explode( '</amp-iframe>', $content );
     110        $content = '';
     111 
     112        foreach ( $chunks as $chunk ) {
     113            $start = strpos($chunk, '<amp-iframe');
     114            // Malformed html?
     115            if ( $start === false ) {
     116                $content .= $chunk;
     117                continue;
     118            }
     119 
     120            $iframe = substr($chunk, $start) . '</amp-iframe>';
     121            $p = wpautop(substr( $chunk, 0, $start));
     122
     123            $content .= $p . $iframe;
     124        }
     125    } else {
     126        $content = wpautop($content);
     127    }
     128
     129    return $content;
     130}
     131
     132function iframely_add_amp_iframe_js( $amp_template ) {
     133    ?>
     134    <script custom-element="amp-iframe" src="https://cdn.ampproject.org/v0/amp-iframe-0.1.js" async></script>
     135    <?php
     136}
     137
     138function iframely_add_amp_facebook_js( $amp_template ) {
     139    ?>
     140    <script custom-element="amp-facebook" src="https://cdn.ampproject.org/v0/amp-facebook-0.1.js" async></script>
     141    <?php
     142}
     143
     144
    47145
    48146# fix cache ttl
     
    69167                $wp_embed->usecache = false;
    70168                delete_post_meta( $post_ID, $cachekey_time);
     169                // delete_post_meta( $post_ID, $cachekey);
    71170                return $iframely_ttl;
    72171            } else {
     
    84183# rewrite oembed discovery
    85184add_filter( 'oembed_endpoint_url', 'publish_embeds_via_iframely', 10, 2) ;
    86 
    87185function publish_embeds_via_iframely($url, $permalink, $format = 'json') {
    88186
     
    227325            iframely_update_option('iframely_api_params', trim($_POST['iframely_api_params']));
    228326            iframely_update_option('iframely_cache_ttl', (isset($_POST['iframely_cache_ttl'])) ? (int)trim($_POST['iframely_cache_ttl']) : 0);
     327            iframely_update_option('iframely_disable_default_amp_embeds', (isset($_POST['iframely_disable_default_amp_embeds'])) ? (int)trim($_POST['iframely_disable_default_amp_embeds']) : 0);
    229328        }
    230329
     
    259358            Although, we should support the same providers and output the same code, just make it responsive.<br>
    260359            Iframely shortcode will still process such URLs regardless of this setting.
     360        </p>
     361        </li>       
     362
     363        <li>
     364            <p><input type="checkbox" name="iframely_disable_default_amp_embeds" value="1" <?php if (get_site_option('iframely_disable_default_amp_embeds')) { ?> checked="checked" <?php } ?> /> For AMP pages, replace default embeds with Iframely.</p>
     365            <p>Iframely works nicely with <a href="https://wordpress.org/plugins/amp/" target="_blank_">AMP WordPress</a> plugin for Google AMP support.
     366            It catches all missing embeds and follow your Iframely settings.<br>
     367            But you can also choose Iframely for all embeds, including default AMP embeds too.<br>
     368            For example, Facebook video will be indeed a nice video without user's text message.
    261369        </p>
    262370        </li>
  • iframely/trunk/readme.txt

    r1645981 r1729512  
    11=== Iframely Responsive Embeds ===
    22Contributors: psergeev, ivanp
    3 Tags: iframely, oembed, embed, responsive, video, youtube, vimeo, instagram, gist, vine, gif, giphy, google maps, facebook, mu, streamable, gfycat, vidme, Reddit, Tableau, spotify, prezi
     3Tags: iframely, oembed, embed, responsive, video, amp, youtube, vimeo, instagram, gist, vine, gif, giphy, google maps, facebook, mu, streamable, gfycat, vidme, Reddit, Tableau, spotify, prezi, apester, qzzr, tidal, mlb,
    44Requires at least: 3.5.1
    5 Tested up to: 4.7.4
     5Tested up to: 4.8.1
    66Stable tag: trunk
    77License: MIT
    88
    99
    10 Iframely converts URLs in your posts into responsive embed widgets for over 2000 domains and summary cards for others.
     10Iframely converts URLs in your posts into responsive embed widgets for over 2000 domains and summary cards for others. Also works with AMP.
    1111
    1212== Description ==
    1313
    1414
    15 [Iframely](https://iframely.com?from=wp) brings you the responsive embeds and support of over 2000 domains. It means the embeds will resize, if possible, if you are on responsive theme.
    16 
    17 
    18 Iframely will detect URLs in your posts and replace it with responsive embed codes. Supports all usual suspects such as YouTube, Vimeo, Instagram, Facebook, Giphy, GfyCat, Imgur, Google +, GitHub Gists, Storify, SlideShare, Streamable, Vidme, Reddit, Dailymotion, Spotify, Tableau, Prezi, well, you know, over two thousand of them and keeps growing. [Test some URLs here](https://iframely.com/embed).
     15[Iframely](https://iframely.com?from=wp) brings you the responsive embeds and support of over 2000 domains. Iframely also works with AMP.
     16
     17
     18Iframely will detect URLs in your posts and replace it with responsive embed codes. Supports all usual suspects such as YouTube, Vimeo, Instagram, Facebook, Giphy, GfyCat, Imgur, Google +, GitHub Gists, Storify, SlideShare, Streamable, Vidme, Reddit, Dailymotion, Spotify, Tableau, Prezi, Apester, QZZR, Tidal, MLB, well, you know, over two thousand of them and keeps growing. [Test some URLs here](https://iframely.com/embed).
    1919
    2020Iframely will also generate and host summary cards for general articles. It includes your own site, and Iframely can replace the default embed cards that your publish via WordPress for other sites to use.
    2121
    22 Iframely is powered by server API. API Key is required. Get one at [iframely.com](https://iframely.com)
     22Iframely is powered by server API. API Key is required. Get one at [iframely.com](https://iframely.com). Get help at support at iframely.com.
    2323
    2424
     
    5858Just choose this option in your settings. It will essentially put Iframely to be the last in the list, be "a catcher", rather then "an interceptor".
    5959
     60= AMP support =
     61
     62Iframely works nicely with [AMP WP plugin](https://wordpress.org/plugins/amp/). It catches all missing embeds and follow your Iframely settings. But you can also opt to have Iframely for all embeds, including default AMP embeds too. For example, Facebook video will be indeed a nice video without user's text message.
    6063
    6164
     
    6366== Installation ==
    6467
    65 The installation is pretty standard:
     68The installation is standard:
    6669
    67701. Upload the package contents to to the `/wp-content/plugins/` directory
     
    8689== Frequently Asked Questions ==
    8790
    88 = Oh, the Facebook! =
    89 
    90 Yes, Iframely knows the embed codes for Facebook posts, photos and videos. However, some of the posts can be private and not accesssible to our parsers. For those, we can not convert the URL into embed code. Also, Facebook events don't have native embed codes and so Iframely doesn't support these too.
    91 
    9291= I thought Iframely would wrap my URL into iframe? =
    9392
     
    9897Well, that's the point of responsive embeds. You don't have to.
    9998
    100 Iframely widgets will take 100% available width. If you need to limit it, just define your CSS styles for `iframely-widget-container`.
    101 
    102 Please, note that not all the embeds codes will be responsive. Some of hosting domains can not be converted responsively. In those cases, Iframely will left-align the embeds. You might want to consider padding and alignment styles, if you don't have generic ones for `iframes` and `images` yet.
     99Iframely widgets will take 100% available width. If you need to customize CSS, add '&omit_css=1' as "Optional API query-string param" on Iframely config page and follow [this guide](https://iframely.com/docs/omit-css).
     100
     101Please, note that not all the embeds codes will be responsive. Embeds from a tiny number of less frequent publishers cannot be converted responsively without ruining their content.
    103102
    104103= Is it compatible with other embeds plugins I have? =
     
    107106* Since default WordPress embeds are not responsive, Iframely can disable the standard code and replaces it with the responsive embeds. Otherwise, you might be wondering why is some widgets are not responsive
    108107* You can conifugure Iframely to only work in its own shortcode, thus leaving other plugins intact.
     108* Iframely plays well with [AMP](https://wordpress.org/plugins/amp/).
    109109
    110110= What about embeds in my previous posts? =
     
    112112Iframely works in native WordPress embeds framework. All your new posts should start seeing responsive widgets. The older posts will be re-cached via WordPress logic itself (usually when you edit and save the post), and should granually get the new embeds code too. However, we do not interfere into this default process and do not re-cache older posts upon install.
    113113
     114To change this logic, define "Cache the embed codes for this number of days" on Iframely options page.
     115
    114116If there's a specific post you'd like to update, just go to Edit and Save it again. It should re-cache it and trigger Iframely.
    115117
     
    122124Iframely will work well with multisite installations. Iframely options page is available for super admins only, and the settings will be the same for all blogs on your WPMU setup.
    123125
     126= Oh, the Facebook! =
     127
     128Yes, Iframely knows the embed codes for Facebook posts, photos and videos. However, some of the posts can be private and not accesssible to our parsers. For those, we can not convert the URL into embed code. Also, Facebook events don't have native embed codes and so Iframely doesn't support these too.
    124129
    125130== Changelog ==
     131
     132= 0.5.0 =
     133
     134Making Iframely to work nicely with [AMP WP plugin](https://wordpress.org/plugins/amp/). Iframely now catches all missing embeds and follow your Iframely settings. But you can also opt to have Iframely for all embeds.
     135
    126136
    127137= 0.4.0 =
Note: See TracChangeset for help on using the changeset viewer.