From eaba5b0b05b84960d85a8ab02a9d2cf8eb3e331a Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Sat, 14 Sep 2019 11:06:23 -0400 Subject: [PATCH 1/5] Pym.js AMP-compatibility --- includes/class-amp-enhancements.php | 71 +++++++++++++++++++++++++++-- includes/class-plugin-manager.php | 8 ++++ includes/util.php | 9 ++++ 3 files changed, 85 insertions(+), 3 deletions(-) diff --git a/includes/class-amp-enhancements.php b/includes/class-amp-enhancements.php index 943793f8fc..217cb7b16f 100644 --- a/includes/class-amp-enhancements.php +++ b/includes/class-amp-enhancements.php @@ -19,15 +19,17 @@ class AMP_Enhancements { */ public static function init() { add_filter( 'do_shortcode_tag', [ __CLASS__, 'documentcloud_iframe_full_height' ], 10, 2 ); + add_filter( 'render_block', [ __CLASS__, 'pymjs_convert_block_to_ampiframe' ], 10, 2 ); + add_filter( 'do_shortcode_tag', [ __CLASS__, 'pymjs_convert_shortcode_to_ampiframe' ], 10, 3 ); } /** * Add an attribute to the iframe instructing AMP that the iframe should be rendered with the "fill" style instead * of the "fixed-height" style. * - * @see https://github.com/ampproject/amp-wp/issues/3142 - * @param string $output HTML output of the shortcode. - * @param string $tag The shortcode currently being processed. + * @see https://github.com/ampproject/amp-wp/issues/3142 + * @param string $output HTML output of the shortcode. + * @param string $tag The shortcode currently being processed. * @return string Modified shortcode output. */ public static function documentcloud_iframe_full_height( $output, $tag ) { @@ -37,5 +39,68 @@ public static function documentcloud_iframe_full_height( $output, $tag ) { return str_replace( '"; + } } AMP_Enhancements::init(); diff --git a/includes/class-plugin-manager.php b/includes/class-plugin-manager.php index 950be937eb..6e6d879c9b 100644 --- a/includes/class-plugin-manager.php +++ b/includes/class-plugin-manager.php @@ -194,6 +194,14 @@ public static function get_managed_plugins() { 'PluginURI' => 'https://www.constantcontact.com', 'Download' => 'wporg', ], + 'pym-shortcode' => [ + 'Name' => 'Pym.js Embeds', + 'Description' => 'A WordPress solution to embed iframes that are responsive horizontally and vertically using the NPR Visuals Team\'s Pym.js.', + 'Author' => 'INN Labs', + 'AuthorURI' => 'http://labs.inn.org/', + 'PluginURI' => 'https://github.com/INN/pym-shortcode', + 'Download' => 'wporg', + ], ]; $default_info = [ diff --git a/includes/util.php b/includes/util.php index 0a2e902a99..9ca246e2df 100644 --- a/includes/util.php +++ b/includes/util.php @@ -527,3 +527,12 @@ function newspack_select_prepare( $arr ) { } return $result; } + +/** + * Check whether the current page is an AMP page. + * + * @return bool True if AMP page. + */ +function newspack_is_amp() { + return function_exists( 'is_amp_endpoint' ) && is_amp_endpoint(); +} From 9cefe4f60edc1b04ef196ab90d2774c26a132274 Mon Sep 17 00:00:00 2001 From: claudiulodro Date: Sun, 15 Sep 2019 11:08:19 -0400 Subject: [PATCH 2/5] Improvements to generated amp-iframe --- includes/class-amp-enhancements.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/includes/class-amp-enhancements.php b/includes/class-amp-enhancements.php index 217cb7b16f..91d55240fc 100644 --- a/includes/class-amp-enhancements.php +++ b/includes/class-amp-enhancements.php @@ -100,7 +100,29 @@ public static function pymjs_convert_shortcode_to_ampiframe( $output, $tag, $att * @return string AMP-iframe HTML. */ protected static function get_pym_ampiframe( $src ) { - return ""; + ob_start(); + ?> + +
' + placeholder + > + +
+
+ Date: Sun, 15 Sep 2019 11:39:33 -0400 Subject: [PATCH 3/5] Style load button on resizing amp-iframe --- includes/class-amp-enhancements.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/includes/class-amp-enhancements.php b/includes/class-amp-enhancements.php index 91d55240fc..bc2663ffc2 100644 --- a/includes/class-amp-enhancements.php +++ b/includes/class-amp-enhancements.php @@ -114,10 +114,11 @@ protected static function get_pym_ampiframe( $src ) {
' + aria-label='' placeholder + style='width:100%; text-align:center; padding-top:50%; background:rgba(0,0,0,.7); color:#FFF; font-weight:bold' > - +
Date: Thu, 5 Mar 2020 10:11:12 -0800 Subject: [PATCH 4/5] Remove Pym.js AMP enhancements, merged upstream --- includes/class-amp-enhancements.php | 106 ---------------------------- includes/util.php | 9 --- 2 files changed, 115 deletions(-) diff --git a/includes/class-amp-enhancements.php b/includes/class-amp-enhancements.php index bc2663ffc2..8a4d991184 100644 --- a/includes/class-amp-enhancements.php +++ b/includes/class-amp-enhancements.php @@ -18,112 +18,6 @@ class AMP_Enhancements { * Initialize hooks and filters. */ public static function init() { - add_filter( 'do_shortcode_tag', [ __CLASS__, 'documentcloud_iframe_full_height' ], 10, 2 ); - add_filter( 'render_block', [ __CLASS__, 'pymjs_convert_block_to_ampiframe' ], 10, 2 ); - add_filter( 'do_shortcode_tag', [ __CLASS__, 'pymjs_convert_shortcode_to_ampiframe' ], 10, 3 ); - } - - /** - * Add an attribute to the iframe instructing AMP that the iframe should be rendered with the "fill" style instead - * of the "fixed-height" style. - * - * @see https://github.com/ampproject/amp-wp/issues/3142 - * @param string $output HTML output of the shortcode. - * @param string $tag The shortcode currently being processed. - * @return string Modified shortcode output. - */ - public static function documentcloud_iframe_full_height( $output, $tag ) { - if ( 'documentcloud' !== $tag ) { - return $output; - } - - return str_replace( ' - -
' - placeholder - style='width:100%; text-align:center; padding-top:50%; background:rgba(0,0,0,.7); color:#FFF; font-weight:bold' - > - -
-
- Date: Thu, 5 Mar 2020 10:13:51 -0800 Subject: [PATCH 5/5] chore: move pym plugin to correct place in list --- includes/class-plugin-manager.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/class-plugin-manager.php b/includes/class-plugin-manager.php index f493aafe5f..d0f5c113f7 100644 --- a/includes/class-plugin-manager.php +++ b/includes/class-plugin-manager.php @@ -296,6 +296,14 @@ public static function get_managed_plugins() { 'PluginURI' => 'https://github.com/xwp/pwa-wp', 'Download' => 'wporg', ], + 'pym-shortcode' => [ + 'Name' => 'Pym.js Embeds', + 'Description' => 'A WordPress solution to embed iframes that are responsive horizontally and vertically using the NPR Visuals Team\'s Pym.js.', + 'Author' => 'INN Labs', + 'AuthorURI' => 'http://labs.inn.org/', + 'PluginURI' => 'https://github.com/INN/pym-shortcode', + 'Download' => 'wporg', + ], 'redirection' => [ 'Name' => 'Redirection', 'Description' => 'Manage all your 301 redirects and monitor 404 errors.', @@ -398,14 +406,6 @@ public static function get_managed_plugins() { 'PluginURI' => 'https://wordpress.org/plugins/wp-user-avatar/', 'Download' => 'wporg', ], - 'pym-shortcode' => [ - 'Name' => 'Pym.js Embeds', - 'Description' => 'A WordPress solution to embed iframes that are responsive horizontally and vertically using the NPR Visuals Team\'s Pym.js.', - 'Author' => 'INN Labs', - 'AuthorURI' => 'http://labs.inn.org/', - 'PluginURI' => 'https://github.com/INN/pym-shortcode', - 'Download' => 'wporg', - ], ]; $default_info = [