Skip to content
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 detection of containers where we should add data #13446

Merged
merged 5 commits into from
Sep 24, 2019

Conversation

jeherve
Copy link
Member

@jeherve jeherve commented Sep 6, 2019

Fixes #13428

Changes proposed in this Pull Request:

Until now we would rely on 2 str_replace to add Carousel data to div and ul containers in post content.
This worked, but wasn't smart enough to know to ignore specific divs like Columns blocks.

By using DOMDocument, we can go through the post content in a more readable way, to detect gallery blocks as well as regular galleries and images.

Testing instructions:

  • In a new post, insert a variety of blocks:
    • A classic block with a gallery
    • A classic block with a tiled gallery
    • A classic block with a single image (still testing, but I think this may not work, neither with my branch or on the latest stable).
    • An image block (still testing, but I think this may not work, neither with my branch or on the latest stable).
    • A gallery block
    • A Tiled Gallery block
    • A column block with some text
    • A column block with a gallery block in it.
  • Publish your post
  • When moving your mouse over each block, make sure the cursor only becomes a pointer when the element can be expanded to a Carousel modal.

Proposed changelog entry for your changes:

  • Carousel: improve detection of containers where we should add the Carousel modal.

@jeherve jeherve added [Type] Bug When a feature is broken and / or not performing as intended [Feature] Carousel A fullscreen modal appearing when clicking on an image in a gallery or tiled gallery. [Status] In Progress [Status] Needs Testing We need to add this change to the testing call for this month's release labels Sep 6, 2019
@jeherve jeherve added this to the 7.8 milestone Sep 6, 2019
@jeherve jeherve requested a review from a team September 6, 2019 16:55
@jeherve jeherve self-assigned this Sep 6, 2019
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello jeherve! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D32610-code before merging this PR. Thank you!

@jetpackbot
Copy link

jetpackbot commented Sep 6, 2019

Thank you for the great PR description!

When this PR is ready for review, please apply the [Status] Needs Review label. If you are an a11n, please have someone from your team review the code if possible. The Jetpack team will also review this PR and merge it to be included in the next Jetpack release.

Scheduled Jetpack release: October 1, 2019.
Scheduled code freeze: September 24, 2019

Generated by 🚫 dangerJS against 6c293bb

Fixes #13428

Until now we would rely on 2 str_replace to add Carousel data to div and ul containers in post content.
This worked, but wasn't smart enough to know to ignore specific divs like Columns blocks.

By using DOMDocument, we can go through the post content in a more readable way, to detect gallery blocks as well as regular galleries and images.
@jeherve jeherve force-pushed the fix/carousel-on-columns-13428 branch from 474d368 to ebb2a70 Compare September 6, 2019 17:05
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D32610-code has been updated.

kraftbj
kraftbj previously requested changes Sep 6, 2019
modules/carousel/jetpack-carousel.php Show resolved Hide resolved
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D32610-code has been updated.

Copy link
Member

@mdawaffe mdawaffe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it strictly matters for this use case, but we should wrap the DOM usage in:

$old_libxml_disable_entity_loader = libxml_disable_entity_loader( true );
// … DOM use
libxml_disable_entity_loader( $old_libxml_disable_entity_loader );

modules/carousel/jetpack-carousel.php Outdated Show resolved Hide resolved
modules/carousel/jetpack-carousel.php Outdated Show resolved Hide resolved
modules/carousel/jetpack-carousel.php Outdated Show resolved Hide resolved
foreach ( $div_tags as $div_tag ) {
if (
false === strpos( $div_tag->getAttribute( 'class' ), 'wp-block-' )
|| false !== strpos( $div_tag->getAttribute( 'class' ), 'gallery' )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be &&?

As written, we add the attribute to all divs that are not wp-block- divs (including divs with no class at all).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the current behaviour, I didn't want to change that. We currently add the attributes to all divs. With this change, it will be added to all divs, except if they include a class including wp-block-. The second parameter is here to add an additional exception: wp-block- is okay if it's a gallery block, like wp-block-jetpack-tiled-gallery.

Maybe there would be a more readable way to do that? Or should we instead move to more of a whitelist where we don't add the data to all the divs, but only to some specific ones?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd support keeping the behavior the way it is for the sake of the PR, but open an enhancement issue to explore refactoring it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logged in #13499

modules/carousel/jetpack-carousel.php Outdated Show resolved Hide resolved
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D32610-code has been updated.

1 similar comment
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D32610-code has been updated.

@jeherve jeherve force-pushed the fix/carousel-on-columns-13428 branch from 905aac7 to b2a0560 Compare September 9, 2019 06:45
@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D32610-code has been updated.

@matticbot
Copy link
Contributor

jeherve, Your synced wpcom patch D32610-code has been updated.

@jeherve jeherve dismissed mdawaffe’s stale review September 9, 2019 06:50

I've added the libxml_disable_entity_loader check as well 👍

@jeherve jeherve requested a review from kraftbj September 9, 2019 06:51
@jeherve jeherve added [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. and removed [Status] In Progress labels Sep 19, 2019
Copy link
Contributor

@kraftbj kraftbj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some performance testing locally of the the_content filter before and after with a very large post (105k words, ~750k characters). There didn't seem to be a functional difference between them.

@kraftbj kraftbj added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from fellow Jetpack developers. Label will be renamed soon. [Status] Needs Testing We need to add this change to the testing call for this month's release labels Sep 24, 2019
@jeherve jeherve merged commit a7e494e into master Sep 24, 2019
@jeherve jeherve deleted the fix/carousel-on-columns-13428 branch September 24, 2019 07:25
@matticbot matticbot added [Status] Needs Changelog and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Sep 24, 2019
@jeherve jeherve added [Status] Needs Testing We need to add this change to the testing call for this month's release [Status] Has Changelog and removed [Status] Needs Changelog [Status] Needs Testing We need to add this change to the testing call for this month's release labels Sep 24, 2019
jeherve added a commit that referenced this pull request Sep 24, 2019
jeherve added a commit that referenced this pull request Sep 24, 2019
* Changelog: initial set of changes for 7.8

* Changelog: add #13310

* Changelog: add #13103

* Changelog: add #13426

* Changelog: add #13389

* Changelog: add #13449

* Changelog: add #13461

* Changelog: add #13460

* Changelog: add #13441

* Changelog: add #13454

* Changelog: add #13457

* Changelog: add #13425

* Changelog: add #13473

* Changelog: add #13355

* Changelog: add #13451

* Changelog: add #13358

* Changelog: add #13464

* Changelog: add #13416

* Changelog: add #13494

* Changelog: add #13465

* Changelog: add #13424

* Changelog: add #13432

* Changelog: add #13471

* Changelog: add 7.7.2 entry

* Changelog: add #13446

* Add more testing elements
jeherve added a commit that referenced this pull request Sep 24, 2019
* Changelog: initial set of changes for 7.8

* Changelog: add #13310

* Changelog: add #13103

* Changelog: add #13426

* Changelog: add #13389

* Changelog: add #13449

* Changelog: add #13461

* Changelog: add #13460

* Changelog: add #13441

* Changelog: add #13454

* Changelog: add #13457

* Changelog: add #13425

* Changelog: add #13473

* Changelog: add #13355

* Changelog: add #13451

* Changelog: add #13358

* Changelog: add #13464

* Changelog: add #13416

* Changelog: add #13494

* Changelog: add #13465

* Changelog: add #13424

* Changelog: add #13432

* Changelog: add #13471

* Changelog: add 7.7.2 entry

* Changelog: add #13446

* Add more testing elements
jeherve added a commit that referenced this pull request Sep 24, 2019
…uld add data (#13446)

* Carousel: improve detection of containers where we should add data

Fixes #13428

Until now we would rely on 2 str_replace to add Carousel data to div and ul containers in post content.
This worked, but wasn't smart enough to know to ignore specific divs like Columns blocks.

By using DOMDocument, we can go through the post content in a more readable way, to detect gallery blocks as well as regular galleries and images.

* Bail if the server does not support DOMDocument

* Store and return value from libxml_use_internal_errors

See https://github.com/Automattic/jetpack/pull/13446/files#r321866447

Co-Authored-By: Michael D Adams <michael.d.adams@gmail.com>

* No need to escape data key

See https://github.com/Automattic/jetpack/pull/13446/files#r321867238

Co-Authored-By: Michael D Adams <michael.d.adams@gmail.com>

* Wrap DOM usage in libxml_disable_entity_loader

See #13446 (review)
@jeherve
Copy link
Member Author

jeherve commented Sep 24, 2019

Cherry-picked to branch-7.8 in 7e44a01

jeherve added a commit that referenced this pull request Sep 27, 2019
… data (#13446)"

This reverts commit a7e494e.

Following issues with this implementation, let's go back for now and revisit in #13554
jeherve added a commit that referenced this pull request Sep 27, 2019
* Revert "Carousel: improve detection of containers where we should add data (#13446)"

This reverts commit a7e494e.

Following issues with this implementation, let's go back for now and revisit in #13554

* Remove entry from changelog
jeherve added a commit that referenced this pull request Sep 27, 2019
* Revert "Carousel: improve detection of containers where we should add data (#13446)"

This reverts commit a7e494e.

Following issues with this implementation, let's go back for now and revisit in #13554

* Remove entry from changelog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Carousel A fullscreen modal appearing when clicking on an image in a gallery or tiled gallery. Touches WP.com Files [Type] Bug When a feature is broken and / or not performing as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tiled Gallery Block causes pointer cursor on every block that has nesting
5 participants