Skip to content

Commit

Permalink
Merge pull request #928 from alleyinteractive/v2.3.2-prep
Browse files Browse the repository at this point in the history
v2.3.2 Prep
  • Loading branch information
kevinfodness authored Mar 14, 2022
2 parents d4cac9e + 4f2bda3 commit ec67f91
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 419 deletions.
2 changes: 1 addition & 1 deletion apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* Plugin Name: Publish to Apple News
* Plugin URI: http://github.com/alleyinteractive/apple-news
* Description: Export and sync posts to Apple format.
* Version: 2.3.1
* Version: 2.3.2
* Author: Alley
* Author URI: https://alley.co
* Text Domain: apple-news
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,11 @@
"phpcbf" : "phpcbf .",
"phpcs" : "phpcs .",
"phpunit" : "phpunit"
},
"config": {
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
4 changes: 2 additions & 2 deletions includes/apple-exporter/builders/class-components.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private function add_pullquote_if_needed( &$components ) {
}

// If none was found, do not add.
if ( ! $components[ $position ]->can_be_anchor_target() ) {
if ( empty( $components[ $position ] ) || ! $components[ $position ]->can_be_anchor_target() ) {
return;
}

Expand Down Expand Up @@ -685,7 +685,7 @@ private function group_body_components( $components ) {

// If the final node has a role of 'body', add 'body-layout-last' layout.
$last = count( $new_components ) - 1;
if ( 'body' === $new_components[ $last ]['role'] ) {
if ( 'body' === $new_components[ $last ]['role'] && 'body-layout' === $new_components[ $last ]['layout'] ) {
$new_components[ $last ]['layout'] = 'body-layout-last';
}

Expand Down
3 changes: 2 additions & 1 deletion includes/apple-exporter/class-exporter-content.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ public function nodes() {
libxml_clear_errors();

// Find the first-level nodes of the body tag.
return $dom->getElementsByTagName( 'body' )->item( 0 )->childNodes;
$body = $dom->getElementsByTagName( 'body' )->item( 0 );
return $body ? $body->childNodes : new \DOMNodeList();
}

}
20 changes: 11 additions & 9 deletions includes/apple-exporter/components/class-embed-generic.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,23 @@ protected function build( $html ) {
}

// Fork for iframe handling vs. not. Non-iframe detection is less straightforward, so it is best-effort.
if ( 'tiktok' === $provider && preg_match( '/<blockquote[^>]+?cite=[\'"]([^\'"]+)/', $html, $matches ) ) {
$url = $matches[1];
if ( 'tiktok' === $provider && preg_match( '/<blockquote[^>]+?cite=(\'|")(.+?)\\1/', $html, $matches ) ) {
$url = $matches[2];
} elseif ( false !== strpos( $html, '<iframe' ) ) {
// Try to get the source URL.
if ( preg_match( '/<iframe[^>]+?src=[\'"]([^\'"]+)/', $html, $matches ) ) {
$url = $matches[1];
if ( preg_match( '/<iframe[^>]+?src=(\'|")(.+?)\\1/', $html, $matches ) ) {
$url = $matches[2];
}

// Try to get the title.
if ( preg_match( '/<iframe[^>]+?title=[\'"]([^\'"]+)/', $html, $matches ) ) {
$title = $matches[1];
if ( preg_match( '/<iframe[^>]+?title=(\'|")(.+?)\\1/', $html, $matches ) ) {
$title = $matches[2];
}
} elseif ( preg_match( '/data-(?:url|href)=[\'"]([^\'"]+)/', $html, $matches ) ) {
$url = $matches[1];
} elseif ( preg_match( '/<a[^>]+?href=[\'"]([^\'"]+)/', $html, $matches ) ) {
} elseif ( preg_match( '/data-(?:url|href)=(\'|")(.+?)\\1/', $html, $matches ) ) {
$url = $matches[2];
} elseif ( preg_match( '/<a[^>]+?href=(\'|")(.+?)\\1/', $html, $matches ) ) {
$url = $matches[2];
} elseif ( preg_match( '/\n(https?:\/\/[^\n]+\n)/', $html, $matches ) ) {
$url = $matches[1];
}

Expand Down
31 changes: 21 additions & 10 deletions includes/apple-exporter/components/class-gallery.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function register_specs() {
* @access protected
*/
protected function build( $html ) {
$container = null;

// Convert the text into a NodeList.
libxml_use_internal_errors( true );
Expand All @@ -82,16 +83,26 @@ protected function build( $html ) {
libxml_clear_errors();
libxml_use_internal_errors( false );

// Negotiate container. This will either be a <ul> or a <div> with a class of "gallery".
$nodes = $dom->getElementsByTagName( 'ul' );
$container = null;
if ( ! empty( $nodes->item( 0 ) ) ) {
$container = $nodes->item( 0 );
} else {
$nodes = $dom->getElementsByTagName( 'div' );
foreach ( $nodes as $node ) {
if ( self::node_has_class( $node, 'gallery' ) ) {
$container = $node;
// See if the gallery is a collection of figures within a figure.
$figures = $dom->getElementsByTagName( 'figure' );
if ( ! empty( $figures->item( 0 ) ) && self::node_has_class( $figures->item( 0 ), 'wp-block-gallery' ) ) {
$container = $figures->item( 0 );
}

// See if the gallery is a UL.
if ( empty( $container ) ) {
$ul = $dom->getElementsByTagName( 'ul' );
if ( ! empty( $ul->item( 0 ) ) ) {
$container = $ul->item( 0 );
}
}

// See if the gallery is a div with a class of "gallery".
if ( empty( $container ) ) {
$divs = $dom->getElementsByTagName( 'div' );
foreach ( $divs as $div ) {
if ( self::node_has_class( $div, 'gallery' ) ) {
$container = $div;
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions includes/class-apple-news.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Apple_News {
* @var string
* @access public
*/
public static $version = '2.3.1';
public static $version = '2.3.2';

/**
* Link to support for the plugin on WordPress.org.
Expand Down Expand Up @@ -436,7 +436,8 @@ public function action_enqueue_block_editor_assets() {

// Get the path to the PHP file containing the dependencies.
$dependency_file = dirname( __DIR__ ) . '/build/pluginSidebar.asset.php';
if ( ! file_exists( $dependency_file ) || 0 !== validate_file( $dependency_file ) ) {
// Validate file is considered successful if it has no issues (0) or is a Windows filepath (2).
if ( ! file_exists( $dependency_file ) || ! in_array( validate_file( $dependency_file ), [ 0, 2 ], true ) ) {
return;
}

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "publish-to-apple-news",
"version": "2.3.1",
"version": "2.3.2",
"license": "GPLv3",
"main": "index.php",
"engines": {
Expand Down
10 changes: 8 additions & 2 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ Contributors: potatomaster, kevinfodness, jomurgel, tylermachado, benpbolton, al
Donate link: https://wordpress.org
Tags: publish, apple, news, iOS
Requires at least: 4.0
Tested up to: 5.8
Tested up to: 5.9
Requires PHP: 5.6
Stable tag: 2.3.1
Stable tag: 2.3.2
License: GPLv3 or later
License URI: https://www.gnu.org/licenses/gpl.html

Expand Down Expand Up @@ -46,6 +46,12 @@ Please visit our [wiki](https://github.com/alleyinteractive/apple-news/wiki) for

== Changelog ==

= 2.3.2 =
* Bugfix: Fixes a bug where the layout body-layout-last is not added to the list of layouts if the body content ends with something other than a paragraph.
* Bugfix: Fixes a bug where galleries were no longer being properly converted to Apple News Format due to a change in gallery markup that was introduced in WordPress 5.8.
* Bugfix: Fixes an issue with enqueueing the Gutenberg PluginSidebar script on Windows webservers.
* Bugfix: Fixes an error in class-components.php if the function is called with an empty list of components.

= 2.3.1 =
* Bugfix: Fixes an issue where images with different URLs but the same filename are bundled with the same name when not using remote images, which can lead to images appearing out of order.

Expand Down
10 changes: 10 additions & 0 deletions tests/apple-exporter/components/test-class-body.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,16 @@ public function test_filter_html( $meta_order, $index ) {
remove_filter( 'apple_news_body_html_enabled', [ $this, 'filter_apple_news_body_html_enabled' ] );
}

/**
* Ensures that the body-layout-last class is properly applied.
*/
public function test_layouts() {
// Create a post with empty body content to force the body-layout-last bug to appear.
$post_id = self::factory()->post->create( [ 'post_content' => '' ] );
$json = $this->get_json_for_post( $post_id );
$this->assertNotEquals( 'body-layout-last', $json['components'][ count( $json['components'] ) - 1 ]['layout'] );
}

/**
* Given an expected result and an actual link, verifies that the link URL is
* correctly processed. Used to ensure that valid link types (not just http/s,
Expand Down
Loading

0 comments on commit ec67f91

Please sign in to comment.