-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Carousel: improve gallery parsing #13554
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: November 5, 2019. |
I haven't checked, but I think the problems from #13547 (comment) are the same in this PR as they were in the other. |
98db791
to
a1a13e8
Compare
This PR has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation. |
This PR has been marked as stale. This happened because:
No further action is needed. But it's worth checking if this PR has clear testing instructions, is it up to date with master, and it is still valid. Feel free to close this issue if you think it's not valid anymore — if you do, please add a brief explanation. |
- Remove in_gallery; it hasn't been used since #5469 - add comments, docblocks, and fix various PHPCS errors. - use the_content to inspect all posts for galleries In the past we also relied on the gallery_style filter, which while it works, only relies on the gallery's opening div tag. Since we're already examining the post content for gallery blocks, let's extend that to check for old-style galleries as well. - stop saveHTML from adding unneeded doctype and html tags - improve DOM Parsing - Wrap input to `DOMDocument->loadHTML()` in fake root tag. - Specify blog's charset in input to `DOMDocument->loadHTML()`. - filter final output of gallery shortcode to add metadata This replaces the 2 other approaches we had tried: - Before this PR, we relied on the gallery_style filter. This was not ideal as the filter contains only the opening part of the div tag. - Earlier in this PR I tried to rely on the_content, but at that point the gallery shortcode is still just a shortcode, so we can't add metadata yet. - Add first set of unit tests
a1a13e8
to
aad61bd
Compare
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
$html = str_replace( '<ul class="blocks-gallery-grid', '<ul ' . esc_attr( $data_key ) . "='" . wp_json_encode( $data_values ) . "' class=\"blocks-gallery-grid", $html ); | ||
$html = str_replace( '<figure class="wp-block-gallery blocks-gallery-grid', '<figure ' . esc_attr( $data_key ) . "='" . wp_json_encode( $data_values ) . "' class=\"wp-block-gallery blocks-gallery-grid", $html ); | ||
// Do not go any further if DOMDocument is disabled on the server. | ||
if ( ! class_exists( 'DOMDocument' ) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it makes sense to return before foreach
? Maybe even before anything else is checked to save us an autoloader roundtrip.
Great stuff, sorry, couldn't help myself and did a drive-by review. My only other comment about the code is that I like your intention to add more stuff to test with. It would be great to test with some gibberish too, since the HTML can be put through any sort of filter before it gets to the carousel. So that if DOMDocument freaks out, we can fail gracefully. |
Closing this for now, since I haven't been able to work on it in the past few months. |
Fixes #13531
Fixes #13428
Fixes #11191
Fixes #17090
Changes proposed in this Pull Request:
This is still a work in progress. I'd like to add Unit Tests to cover each possible use of Carousel, as detailed in the testing instructions below.
Parsing post content to insert carousel metadata is a bit fragile at the moment. Depending on the format of your images, how they are inserted, and what metadata is available for each image, you may run into several issues, highlighted in the issues above.
This PR introduces a different approach to add the Carousel metadata to the classic galleries (it hooks into the
do_shortcode_tag
filter instead ofgallery_style
).It also takes on @mdawaffe's approach from #13547 to improve our use of
DOMDocument
.It also fixes PHPCS errors to get things to be more readable as I was going through that file.
Jetpack product discussion
Does this pull request change what data or activity we track or use?
Testing instructions: